Search code examples
androidsiprtpcodec

How to use G729 of CSipSimple in android


I have got some source of G729 of CSipSimple from here

Now I want to add it in my android application in order to add support for G729 audio codec.

How can I achieve this?


Solution

  • If you're not planing on using pjsip, then, you would need to generate a shared library that you can use from your own project. To do this, I suggest that you create a jni folder and add an Android.mk file similar to:

    LOCAL_PATH := $(call my-dir)
    
    ### Glue for pjsip codec ###
    include $(CLEAR_VARS)
    LOCAL_MODULE := g729_codec
    
    G729_PATH := $(LOCAL_PATH)/../sources
    
    # g729
    LOCAL_C_INCLUDES += $(G729_PATH)/include
    G729_FILES := $(wildcard $(G729_PATH)/src/*.c)
    LOCAL_SRC_FILES += $(G729_FILES:$(LOCAL_PATH)/%=%) 
    
    LOCAL_ALLOW_UNDEFIND_SYMBOLS    := false
    LOCAL_CFLAGS := -frtti -fexceptions
    
    include $(BUILD_SHARED_LIBRARY)
    

    This is just a modification from android_toolchain/Android.mk. You will find all functions needed to properly manage this g729 implementation in file sources/include/g729a.h and a good example about how to use them in file pj_sources/pj_g729.c

    On the other hand, if you're planing to use pjsip, only thing that you should do is to register CSipSimple's implementation as an external codec (Regis has done almost all the work), this is, adding following lines to your project:

    status = pjmedia_codec_g729_init(pjsua_var.med_endpt);
    if (status != PJ_SUCCESS)
    {   
        PJ_LOG(1,(THIS_FILE, "Error: Failed to init G729 codec"));
    }
    

    And use android_toolchain/Android.mk to build a library that you can link with your solution.