From cd009860b2e01ecd1948b603bc5f5fe358089cc4 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Fri, 18 Jun 2010 10:56:51 +0200 Subject: [PATCH] add codec management to java api --- build/android/Android.mk | 1 - coreapi/linphonecore.c | 24 ++++++++++ coreapi/linphonecore.h | 8 ++++ coreapi/linphonecore_jni.cc | 45 +++++++++++++++++++ .../org/linphone/core/LinphoneCore.java | 11 +++++ .../linphone/core/LinphoneProxyConfig.java | 3 ++ .../common/org/linphone/core/PayloadType.java | 23 ++++++++++ mediastreamer2 | 2 +- 8 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 java/common/org/linphone/core/PayloadType.java diff --git a/build/android/Android.mk b/build/android/Android.mk index 50ad5bef2..e402eca74 100755 --- a/build/android/Android.mk +++ b/build/android/Android.mk @@ -71,7 +71,6 @@ LOCAL_C_INCLUDES += \ LOCAL_LDLIBS += -llog LOCAL_STATIC_LIBRARIES := \ - libmsandroidsnd \ libmediastreamer2 \ libortp \ libspeex \ diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 75bfee8ab..4ae24d0e9 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -3777,3 +3777,27 @@ void linphone_core_destroy(LinphoneCore *lc){ ms_free(lc); } +static PayloadType* find_payload_type_from_list(const char* type, int rate,const MSList* from) { + const MSList *elem; + for(elem=from;elem!=NULL;elem=elem->next){ + PayloadType *pt=(PayloadType*)elem->data; + if ((strcmp((char*)type, payload_type_get_mime(pt)) == 0) && rate==pt->clock_rate) { + return pt; + } + } + return NULL; +} + +PayloadType* linphone_core_find_payload_type(LinphoneCore* lc, const char* type, int rate) { + PayloadType* result = find_payload_type_from_list(type, rate, linphone_core_get_audio_codecs(lc)); + if (result) { + return result; + } else { + result = find_payload_type_from_list(type, rate, linphone_core_get_video_codecs(lc)); + if (result) { + return result; + } + } + //not found + return NULL; +} diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index b780956ff..87305e449 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -573,6 +573,14 @@ bool_t linphone_core_payload_type_enabled(LinphoneCore *lc, PayloadType *pt); int linphone_core_enable_payload_type(LinphoneCore *lc, PayloadType *pt, bool_t enable); +/* + * get payload type from mime type an clock rate + * @ingroup media_parameters + * iterates both audio an video + * return NULL if not found + */ +PayloadType* linphone_core_find_payload_type(LinphoneCore* lc, const char* type, int rate) ; + const char *linphone_core_get_payload_type_description(LinphoneCore *lc, PayloadType *pt); bool_t linphone_core_check_payload_type_usability(LinphoneCore *lc, PayloadType *pt); diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 7efc94ff5..6d868675a 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -337,6 +337,23 @@ extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv* ,jlong lc) { return linphone_core_is_mic_muted((LinphoneCore*)lc); } +extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv* env + ,jobject thiz + ,jlong lc + ,jstring jmime + ,jint rate) { + const char* mime = env->GetStringUTFChars(jmime, NULL); + jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate); + env->ReleaseStringUTFChars(jmime, mime); + return result; +} +extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv* env + ,jobject thiz + ,jlong lc + ,jlong pt + ,jboolean enable) { + return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable); +} @@ -377,6 +394,20 @@ extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEn return NULL; } } +extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) { + const char* route = env->GetStringUTFChars(jroute, NULL); + int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route); + env->ReleaseStringUTFChars(jroute, route); + return err; +} +extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) { + const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg); + if (route) { + return env->NewStringUTF(route); + } else { + return NULL; + } +} extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) { linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister); @@ -553,3 +584,17 @@ extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv ,jlong ptr) { return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE; } + +extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv* env + ,jobject thiz + ,jlong ptr) { + + PayloadType* pt = (PayloadType*)ptr; + char* value = ms_strdup_printf("[%s] clock [%s], bitrate [%s]" + ,payload_type_get_mime(pt) + ,payload_type_get_rate(pt) + ,payload_type_get_bitrate(pt)); + jstring jvalue =env->NewStringUTF(value); + ms_free(value); + return jvalue; +} diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index 3b34ec7d7..bd153c74a 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -185,4 +185,15 @@ public interface LinphoneCore { * */ public void clearCallLogs(); + + + /*** + * get payload type from mime type an clock rate + * + * return null if not found + */ + public PayloadType findPayloadType(String mime,int clockRate); + + public void enablePayloadType(PayloadType pt, boolean enable) throws LinphoneCoreException; + } diff --git a/java/common/org/linphone/core/LinphoneProxyConfig.java b/java/common/org/linphone/core/LinphoneProxyConfig.java index e705ab8fb..236bded39 100644 --- a/java/common/org/linphone/core/LinphoneProxyConfig.java +++ b/java/common/org/linphone/core/LinphoneProxyConfig.java @@ -72,4 +72,7 @@ public interface LinphoneProxyConfig { public String getProxy(); public boolean registerEnabled(); public boolean isRegistered(); + public void setRoute(String routeUri) throws LinphoneCoreException; + public String getRoute(); + } diff --git a/java/common/org/linphone/core/PayloadType.java b/java/common/org/linphone/core/PayloadType.java new file mode 100644 index 000000000..59a64699b --- /dev/null +++ b/java/common/org/linphone/core/PayloadType.java @@ -0,0 +1,23 @@ +/* +PayloadType.java +Copyright (C) 2010 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +package org.linphone.core; + +public interface PayloadType { + +} diff --git a/mediastreamer2 b/mediastreamer2 index a6484a846..55d14a76f 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit a6484a8463b62a60d03ef8358b2e305408f3b011 +Subproject commit 55d14a76fa81b5941aec6cd272b3b69688e54e56