Test Script

Sunday, March 23, 2014

Building A VoIP Application In Android : Part 1

So you want to build a VoIP application and have no idea where to get started? Well, you have come to the right place. This tutorial will attempt to help you get started with building a VoIP application on Android, by no means is this tutorial an exhaustive end to end guide but rather a simple starting point to build upon. So lets get started.



There are quite a lot of libraries out there which help you build a VoIP application. Today in this tutorial I will be using PJSIP as our preferred choice. With the latest 2.2 version of PJSIP, it now supports object oriented programming. Sounds simple enough ? Well, its not. Building the library from the source files is a big pain and took me hours to finally get it done.  I have integrated OpenSSL in it as well for TLS support.

Building PJSIP :

Requirements :


1. Java, JDK.
2. Android SDK & Android NDK
3. SWIG
4.Pyparcer

SWIG provides glue/bindings between the C/C++ library and Java code by generating wrappers

Pyparcer is a python parser tool which is used by swig internally to parse the interface file before generating the bindings needed for the app, so make sure you have pyparcer installed before hand. We never use it directly but Swig invokes it automatically.
Steps:
1. Getting the latest PJSIP source code from their repository
2. This guide will assume the path of the downloaded PJSIP src code to be pjsip/src
3. Create a new config_site.h file under pjsip/src/pjlib/include/pj with the following text
#define PJ_CONFIG_ANDROID 1
#define PJ_AUTOCONF 1
#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_HAS_SSL_SOCK 1
#include <pj/ config_site_sample.h>
4. Set the path to your Android NDK in the PATH variable

5. Ideally you should compile OpenSSL and integrate it with PJSIP, but I couldn't get it work. So I have used a port of OpenSSL for Android.

6. Build the above project using ndk-build command

7. Now go to pjsip/src folder and run the following command
./configure-android --with-ssl=/path/to/compiled-openssl-folder

8. If that was successful, run the following command
make dep && make clean && make

9. That should have built the needed lib files with OpenSSL support enabled

10. Now navigate to pjsip/src/pjsip-apps/src/swig folder

11. Add SWIG path to your PATH variable

12. Run the following command
make

If everything went well, you should now see a pjsua2.so file under pjsip/src/pjsip-apps/src/swig/java/android/libs/ folder.

That's all that is to be done to build PJSIP for Android. You should now be able to call the native library functions from your Java code. In Part 2 of the tutorial we will have a look at how to start using the compiled library from a demo Android app and basic functions of the PJSIP library. Hope you liked this tutorial, feel free to leave your comments below.

And yes, you should soon see a great VoIP application from me on the Playstore !

1 comment:

  1. I am stuck at 6. Build the above project using ndk-build command:
    Android NDK: Could not find application project directory !
    Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
    /opt/android-ndk/build/core/build-local.mk:151: *** Android NDK: Aborting .

    In which folder do I have to run ndk-build, and are there any additional options to be provided?

    ReplyDelete

UA-42774700-1 Twitter Bird Gadget