1

Adding custom function to new linphone SDK.

As the developers guided i built liblinphone android sdk by adding small function to bellesip C code . Also added related entry to linphonecore_jni.cc and built linphone-android-sdk. On documentation page it said that wrapper will be generated automatically for native functions . But After building AAR and added that to the linphone project I can not see my method in Core methods . I tried both -DENABLE_JAVA_WRAPPER=NO and -DENABLE_JAVA_WRAPPER=YES.

I tried adding

JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCoreImpl_setCutomFunction(JNIEnv *env, jobject thiz, jlong lc, jint tik, jint tik_size) {
    settiks(tiks, tik_size);

}linphonecore_jni

I expected that I can call native method in linphone java code . All methods are populating except my custom method in core. Is there any additional step apart from adding linphonesdk AAR library file to linphone project .

Oo.oO
  • 12,464
  • 3
  • 23
  • 45
Srav
  • 69
  • 1
  • 10

3 Answers3

0

To be able to auto generate JNI wrapper for the C function you have to include it in linphone project and not belle-sip .

make sure it is correctly documented following doxygen standard in a header file of linphone library.

0

I think we should use the new wrapper as Linphone developers' recommendation.

All files like Core.java, linphone_jni.cc... will be automatically generated when building linphonesdk. Generating rules are defined by .mustache files as I understand.

The old files like linphonecore_jni.cc, LinphoneCore.java are not used any more. Maybe you are modifying these old files.

In older to your new methods are generated into Core.java, linphone_jni.cc... you have to add them in the right .c and .h files, with the right format and annotations.

For example: I want to add below method in Core.java:

Call inviteAddressToConferenceWithParams(Address var1, CallParams var2);

mapping with the method

JNIEXPORT jobject JNICALL Java_org_linphone_core_CoreImpl_createConferenceWithParams(JNIEnv *env, jobject thiz, jlong ptr, jobject params)

in linphone_jni.cc

All I have to do is add in linphone/include/linphone/core.h:

/**
 * Some texts
 *
 * @param[in] lc #LinphoneCore object
 * @param[in] addr The destination of the call (sip address).
 * @param[in] params Call parameters
 * @return A #LinphoneCall object or NULL in case of failure
 * @ingroup call_control */
LINPHONE_PUBLIC LinphoneCall * linphone_core_invite_address_to_conference_with_params(LinphoneCore *lc, const LinphoneAddress *addr, LinphoneCallParams *params);

And in linphonecore.c:

LinphoneCall * linphone_core_invite_address_to_conference_with_params(LinphoneCore *lc, const LinphoneAddress *addr, LinphoneCallParams *params) {
    // Add your code here
    return /* return what you want */;
}

Then build the linphonesdk by:

cmake --build .

After that, all the related code in Core.java, linphone_jni.cc will be generated. Pay attention to the annotations. Without them, the code will not generated.

0

I am showing an example to add new function in Call.Java in .aar file, as the linphonecore_jni.cc file is no more used in new version of Linphone.

Open below file:

liblinphone/include/linphone/api/c-call.h

add new function declaration:

/**
 * Enables or disable echo cancellation for this call
 * @param call the #LinphoneCall object @notnil
 * @param enable wether to enable some functionality or not.
**/
LINPHONE_PUBLIC void linphone_call_testfunction(LinphoneCall *call, bool_t enable);

Now Open below file:

liblinphone/src/c-wrapper/api/c-call.cpp

Add new function definition in the file:

bool_t linphone_call_testfunction (const LinphoneCall *call, bool_t enable) {
        return Call::toCpp(call)->testFunction();
}

Now it will genrate build/WORK/android-armv7/Build/linphone/wrappers/java/src/linphone_jni.cc with below function:

JNIEXPORT jboolean JNICALL Java_org_linphone_core_CallImpl_testfunction(JNIEnv *env, jobject thiz, jlong ptr, jboolean enable) {
        LinphoneCall *cptr = (LinphoneCall*)ptr;

        if (cptr == nullptr) {
                bctbx_error("Java_org_linphone_core_CallImpl_testfunction's LinphoneCall C ptr is null!");
                return 0;
        }

        jboolean jni_result = (jboolean)linphone_call_testfunction(cptr, (bool_t)enable));
        return jni_result;
}

And now make sure, one more file generated build/WORK/android-armv7/Build/linphone/wrappers/java/java/org/linphone/core/Call.java with function declaration:

public boolean testfunction();

Now to call this function in Java code, copy latest .aar file to linphone-android project in android studio. Right click on the project->Reload from Disk then try to access the function. This procedure worked for me perfectly.

Shiv Buyya
  • 3,770
  • 2
  • 30
  • 25