This is a little toy/educational project I've worked on recently, to see how hard would it be to add VoIP functionality to Android phones. It is based on the PJSIP SIP stack and provides a very simple JNI layer implementing barely enough functions to do something useful with it from Java (I'm aware of the pjsip-jni project, but it seemed like an overkill for my purposes).
As a follow-up to this project, I wrote up a JNI Examples for Android document, which contains detailed explanations and an example of building a native library for Android, and calling it from Java.
adb
from Android SDK, or by pointing your phone's browser to this file, after verifying
PGP signature. Necessary patches and build instructions
for it are provided below. Note that it is more a proof-of-concept implementation than
something usable, meaning that it is a bug-ridden, often-crashing, pre-alpha-quality
application, so if you decide to install
and use it, you are doing so completely at your own risk.
It supports registration with the SIP provider and can optionally use an outbound proxy, enabling you to place calls from behind a fully-symmetric NAT (by virtue of magic provided by PSJIP). From testing on my local wireless network I've learned that Android G1 provides fairly decent sound quality (both recording and playback) with SPEEX codec at 8kHz sampling rate and one audio channel (these settings are currently hardcoded in the JNI library), however I had to turn off echo cancelling completely, as it eats too much CPU (for same reason the device cannot do any kind of on-the-fly resampling). When calling remote sites the sound quality deteriorates somewhat, but I haven't tested the effect of different codecs and various knobs PJSIP offers, so it might be that it still can be improved. In the currently released version of Android software interaction with the audio layer is only possible by passing buffers corresponding to roughly 150ms of sound around, and this contributes to overall latency. Things are likely to improve in the upcoming Cupcake release, but it will require some minor porting, and I did not investigate it in much detail.
How to build
- Download Android 1.1r1 SDK
and set up the build environment as described on this page. Verify that your environment works
by trying to build some sample applications included with the SDK.
- Set up the build environment, check out the Android source code as described at
the Android Get source page, and build it (instructions
are available on that page as well). You want to check out the branch matching the
downloaded SDK, so use
-b
option to initialize the repository:
repo init -u git://android.git.kernel.org/platform/manifest.git -b release-1.0
The directory where Android source has been checked out to and built in will be referred to
as ${ANDROID_DIR}
in the rest of the document.
- Download and unpack PJSIP from
PJSIP download page. I've used version
1.0.2. The
directory where PJSIP is unpacked will be referred to as
${PJSIP_DIR}
in the rest of the document.
- Download and apply the patch for PJSIP:
cd ${PJSIP_DIR} && patch -p1 < /path/to/pjsip.patch
-
Download and unpack the VoiDroid source. The directory
where this source is unpacked will be referred to as
${VOIDROID_DIR}
in the rest
of the document.
-
Download the build-voidroid script and run it to build the
VoiDroid package:
build-voidroid --android-dir ${ANDROID_DIR} --pjsip-dir ${PJSIP_DIR} --voidroid-dir ${VOIDROID_DIR}
-
Install the package onto the device:
${SDK_DIR}/tools/adb install -r ${VOIDROID_DIR}/bin/VoiDroid-debug.apk
-
If something does not work, debug as necessary until it works :-).
Support and contact
As I mentioned above, this was something of an educational project, and it was fun while it lasted.
I'm not really interested in working on it anymore, but hope that it might be useful for someone who
wants to build VoIP applications for Android. If you are such person, feel free to take the code
and run with it (and I would appreciate information about your project), that's what open source is all about,
after all. Personally, I'm not willing to fix bugs, add new features or provide any other kind of
support. If you still think that you have something to tell me, feel free to email me at
jurij at wooyd dot org, but please don't be disappointed if you don't receive any reply.
September 27, 2009