Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

sip - How to use pjsip on android device in order to have G.729 codec functionality

I want to use G.729 audio codec on my android application. I have did a lot research on this and came to know that pjsip is most promising solution for this. But I have not much idea about all this. can someone provide me complete steps for using pjsip in existing android application and how can i include support of G729 codec via pjsip.

Any help will be appreciated.

EDIT :

Here is my android.mk file. I want to know that,have i did this right? and how to use those C functions in my java code???

include $(CLEAR_VARS)
LOCAL_MODULE := pjsua-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := $(MY_PJLIB_PATH)/libpjsua-arm-unknown-linux-androideabi.a

 PJSIP_LIBS := $(addprefix pjsip_libs/, 
 libg7221codec-arm-unknown-linux-androideabi.a 
 libg7221codec-i686-apple-darwin9.a 
 libgsmcodec-arm-unknown-linux-androideabi.a 
 libgsmcodec-i686-apple-darwin9.a 
 libilbccodec-arm-unknown-linux-androideabi.a 
 libmilenage-arm-unknown-linux-androideabi.a 
 libmilenage-i686-apple-darwin9.a 
 libpj-arm-unknown-linux-androideabi.a 
 libpj-i686-apple-darwin9.a 
 libpjlib-util-arm-unknown-linux-androideabi.a 
 libpjlib-util-i686-apple-darwin9.a 
 libpjmedia-audiodev-i686-apple-darwin9.a 
 libpjmedia-codec-i686-apple-darwin9.a 
 libpjmedia-i686-apple-darwin9.a 
 libpjmedia-videodev-i686-apple-darwin9.a 
 libpjnath-arm-unknown-linux-androideabi.a 
 libpjnath-i686-apple-darwin9.a 
 libpjsdp-i686-apple-darwin9.a 
 libpjsip-i686-apple-darwin9.a 
 libpjsip-simple-i686-apple-darwin9.a 
 libpjsip-ua-i686-apple-darwin9.a 
 libpjsua-i686-apple-darwin9.a 
 libportaudio-i686-apple-darwin9.a 
 libresample-arm-unknown-linux-androideabi.a 
 libresample-i686-apple-darwin9.a 
 libspeex-arm-unknown-linux-androideabi.a 
 libsrtp-arm-unknown-linux-androideabi.a 
 libsrtp-i686-apple-darwin9.a )

 LOCAL_STATIC_LIBRARIES := $(PJSIP_LIBS) 
 include $(PREBUILT_STATIC_LIBRARY)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First step is build pjsip source code for Android (steps for Ubuntu Linux):

  1. Set ANDROID_NDK_ROOT environment variable to your NDK's root folder.
  2. Go to pjsip 2.x folder and create pjlib/include/pj/config_site.h including config_site_sample.h (#include <pj/config_site_sample.h>)
  3. Run ./configure-android
  4. Run make clean && make depend && make

After these steps, you will have several static libraries in several folders. I suggest to group them in a same folder (better in your project) by:

mkdir <your_project_path>/pjsip_libs
find . -name *.a | xargs -I % cp % <your_project_path>/pjsip_libs/

Once you've all libraries, you need to add those libraries into your project's Android.mk file, this is done by including a new module section per library. This module section should be something like:

include $(CLEAR_VARS)
LOCAL_MODULE := pjsua-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := $(MY_PJLIB_PATH)/libpjsua-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)

And, in the section you're actually building your JNI project's source code, add all modules to your static library references:

 LOCAL_STATIC_LIBRARIES := pjsua-arm-unknown-linux-androideabi ...

This will include pjsip references into your JNI library. Now, you need to configure a pjsip UA instance.

You've a explanation about init and start pjsip's UA (pjsua) in pjsip/include/pjsua-lib/pjsua.h but main steps to follow are:

  1. Create a UA instance with pjsua_create
  2. Create a worker thread with pj_thread_create
  3. Set default configuration for UA instance:

    pjsua_config cfg; pjsua_logging_config log_cfg; pjsua_media_config media_cfg;

    pj_cli_cfg_default(&app_config.cli_cfg.cfg); pjsua_logging_config_default(&log_cfg); pjsua_media_config_default(&media_cfg);

  4. Init the stack with pjsua_init

  5. Start the stack with pjsua_start

From here, you've plenty of configuration options (log, media, transport, etc.)

You can find a basic PJSIP tutorial here and, inside pjsip's source root path, you've a basic (but complete enough for a basic SIP usage) at: pjsip-apps/src/samples/simple_pjsua.c

Edit: When building android project in pjsip-apps, you can face a problem because pjsua-app is not generated by default on the general build (more specifically, pjsua: target is not included on all: target at pjsip-apps/build/Makefile). To fix this just go to pjsip-apps/build and run:

make pjsua

This would create proper object files at: pjsip-apps/build/output/pjsua-arm-unknown-linux-androideabi/ (needed when building android sample).

Once you've all corresponding object files, you can run ndk-build again at pjsip-apps/src/pjsua/android


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...