]> sjero.net Git - linphone/commitdiff
add ec calibrator to Android
authorJehan Monnier <jehan.monnier@linphone.org>
Tue, 25 Jan 2011 14:44:32 +0000 (15:44 +0100)
committerJehan Monnier <jehan.monnier@linphone.org>
Tue, 25 Jan 2011 14:44:32 +0000 (15:44 +0100)
12 files changed:
build/android/Android.mk
coreapi/ec-calibrator.c
coreapi/help/java/org/linphone/core/tutorials/TutorialBuddyStatus.java
coreapi/help/java/org/linphone/core/tutorials/TutorialChatRoom.java
coreapi/help/java/org/linphone/core/tutorials/TutorialHelloWorld.java
coreapi/help/java/org/linphone/core/tutorials/TutorialRegistration.java
coreapi/linphonecore_jni.cc
coreapi/linphonecore_utils.h
coreapi/private.h
java/common/org/linphone/core/LinphoneCore.java
java/common/org/linphone/core/LinphoneCoreListener.java
mediastreamer2

index 05e13ded30f293da2fd0828cbc9b317336d71e1d..a292a0ec084256a9dcdddabb7b2ad2ae16a84c17 100755 (executable)
@@ -46,7 +46,8 @@ LOCAL_SRC_FILES = \
        sal_eXosip2_sdp.c \
        offeranswer.c \
        callbacks.c \
-       linphonecall.c
+       linphonecall.c \
+       ec-calibrator.c
 
 LOCAL_CFLAGS += \
        -D_BYTE_ORDER=_LITTLE_ENDIAN \
index 5d0851add4801b582e1d404cf50c1b5b1e7a640b..df56ff686d1304967d52c3af4e6556f6bb1de1af 100644 (file)
@@ -39,10 +39,15 @@ static void ecc_init_filters(EcCalibrator *ecc){
 
        ecc->play=ms_filter_new(MS_FILE_PLAYER_ID);
        ecc->gen=ms_filter_new(MS_DTMF_GEN_ID);
+       ecc->resampler=ms_filter_new(MS_RESAMPLE_ID);
        ecc->sndwrite=ms_snd_card_create_writer(ecc->capt_card);
 
        ms_filter_link(ecc->play,0,ecc->gen,0);
-       ms_filter_link(ecc->gen,0,ecc->sndwrite,0);
+       ms_filter_link(ecc->gen,0,ecc->resampler,0);
+       ms_filter_link(ecc->resampler,0,ecc->sndwrite,0);
+       unsigned int rate;
+       ms_filter_call_method(ecc->sndwrite,MS_FILTER_GET_SAMPLE_RATE,&rate);
+       ms_filter_call_method(ecc->resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&rate);
 
        ms_ticker_attach(ecc->ticker,ecc->play);
        ms_ticker_attach(ecc->ticker,ecc->sndread);
@@ -53,7 +58,8 @@ static void ecc_deinit_filters(EcCalibrator *ecc){
        ms_ticker_detach(ecc->ticker,ecc->sndread);
 
        ms_filter_unlink(ecc->play,0,ecc->gen,0);
-       ms_filter_unlink(ecc->gen,0,ecc->sndwrite,0);
+       ms_filter_unlink(ecc->gen,0,ecc->resampler,0);
+       ms_filter_unlink(ecc->resampler,0,ecc->sndwrite,0);
 
        ms_filter_unlink(ecc->sndread,0,ecc->det,0);
        ms_filter_unlink(ecc->det,0,ecc->rec,0);
@@ -63,6 +69,7 @@ static void ecc_deinit_filters(EcCalibrator *ecc){
        ms_filter_destroy(ecc->rec);
        ms_filter_destroy(ecc->play);
        ms_filter_destroy(ecc->gen);
+       ms_filter_destroy(ecc->resampler);
        ms_filter_destroy(ecc->sndwrite);
 
        ms_ticker_destroy(ecc->ticker);
@@ -138,6 +145,7 @@ static void  * ecc_thread(void *p){
        ecc_init_filters(ecc);
        ecc_play_tones(ecc);
        ecc_deinit_filters(ecc);
+       ms_thread_exit(NULL);
        return NULL;
 }
 
index 79f541ac5eddc52a387bef8f8c4f8de1041f0ecb..d5351d99c4e0a2e37046ccbf69b1ba0b7dd7fed9 100644 (file)
@@ -22,6 +22,7 @@ import org.linphone.core.LinphoneAddress;
 import org.linphone.core.LinphoneCall;
 import org.linphone.core.LinphoneChatRoom;
 import org.linphone.core.LinphoneCore;
+import org.linphone.core.LinphoneCore.EcCalibratorStatus;
 import org.linphone.core.LinphoneCoreException;
 import org.linphone.core.LinphoneCoreFactory;
 import org.linphone.core.LinphoneCoreListener;
@@ -95,7 +96,7 @@ public class TutorialBuddyStatus implements LinphoneCoreListener {
        public void globalState(LinphoneCore lc, GlobalState state, String message) {}
        public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {}
        public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg) {}
-
+       public void ecCalibrationStatus(LinphoneCore lc, EcCalibratorStatus status,int delay_ms, Object data) {}
 
 
 
@@ -229,4 +230,6 @@ public class TutorialBuddyStatus implements LinphoneCoreListener {
                TutorialNotifier.notify(s);
        }
 
+
+
 }
index 8b8fd341bd7d990956fb3a976864267e3e4cfdf1..9309779bfd7eb3943fd56c861c8bec9f4616a38d 100644 (file)
@@ -22,6 +22,7 @@ import org.linphone.core.LinphoneAddress;
 import org.linphone.core.LinphoneCall;
 import org.linphone.core.LinphoneChatRoom;
 import org.linphone.core.LinphoneCore;
+import org.linphone.core.LinphoneCore.EcCalibratorStatus;
 import org.linphone.core.LinphoneCoreException;
 import org.linphone.core.LinphoneCoreFactory;
 import org.linphone.core.LinphoneCoreListener;
@@ -73,7 +74,7 @@ public class TutorialChatRoom implements LinphoneCoreListener {
        public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {}
        public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
        public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg){}
-
+       public void ecCalibrationStatus(LinphoneCore lc, EcCalibratorStatus status,int delay_ms, Object data) {}
        
        
        public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {
@@ -144,4 +145,5 @@ public class TutorialChatRoom implements LinphoneCoreListener {
                TutorialNotifier.notify(s);
        }
 
+
 }
index 12451c940ace3ff750c5312eb120ec686ef1a08d..d9fdd4f41e22ed722183b9c9689db4d49248815f 100644 (file)
@@ -22,6 +22,7 @@ import org.linphone.core.LinphoneAddress;
 import org.linphone.core.LinphoneCall;
 import org.linphone.core.LinphoneChatRoom;
 import org.linphone.core.LinphoneCore;
+import org.linphone.core.LinphoneCore.EcCalibratorStatus;
 import org.linphone.core.LinphoneCoreException;
 import org.linphone.core.LinphoneCoreFactory;
 import org.linphone.core.LinphoneCoreListener;
@@ -67,7 +68,7 @@ public class TutorialHelloWorld implements LinphoneCoreListener {
        public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,String url) {}
        public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
        public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {}
-
+       public void ecCalibrationStatus(LinphoneCore lc, EcCalibratorStatus status,int delay_ms, Object data) {}
        /*
         * Call state notification listener
         */
@@ -153,4 +154,5 @@ public class TutorialHelloWorld implements LinphoneCoreListener {
                TutorialNotifier.notify(s);
        }
 
+
 }
index 9fbcb25c7aa4646b7992e13d54ef1c2eefd37460..c00ff9b73729613763f98f932becb892a784de07 100644 (file)
@@ -22,6 +22,7 @@ import org.linphone.core.LinphoneAddress;
 import org.linphone.core.LinphoneCall;
 import org.linphone.core.LinphoneChatRoom;
 import org.linphone.core.LinphoneCore;
+import org.linphone.core.LinphoneCore.EcCalibratorStatus;
 import org.linphone.core.LinphoneCoreException;
 import org.linphone.core.LinphoneCoreFactory;
 import org.linphone.core.LinphoneCoreListener;
@@ -78,7 +79,7 @@ public class TutorialRegistration implements LinphoneCoreListener {
        public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {}
        public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from, String message) {}
        public void callState(LinphoneCore lc, LinphoneCall call, State cstate, String msg) {}
-
+       public void ecCalibrationStatus(LinphoneCore lc, EcCalibratorStatus status,int delay_ms, Object data) {}
 
        public static void main(String[] args) {
                // Check tutorial was called with the right number of arguments
@@ -184,4 +185,6 @@ public class TutorialRegistration implements LinphoneCoreListener {
                TutorialNotifier.notify(s);
        }
 
+
+
 }
index 93ea0012e47f1ed681db748861a97ecde156fdee..f8b246ace08ebdabcbcf4f34ebbd8f0d149232f6 100644 (file)
@@ -17,7 +17,8 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 #include <jni.h>
-#include "linphonecore.h"
+#include "linphonecore_utils.h"
+
 #include "mediastreamer2/msjava.h"
 
 #ifdef ANDROID
@@ -100,7 +101,10 @@ public:
                callStateId = env->GetMethodID(listernerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
                callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
                callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
-
+               /*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/
+               ecCalibrationStatusId = env->GetMethodID(listernerClass,"ecCalibrationStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;ILjava/lang/Object;)V");
+               ecCalibratorStatusClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$EcCalibratorStatus"));
+               ecCalibratorStatusFromIntId = env->GetStaticMethodID(ecCalibratorStatusClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;");
                /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
                newSubscriptionRequestId = env->GetMethodID(listernerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
 
@@ -165,6 +169,10 @@ public:
        jmethodID callStateId;
        jmethodID callStateFromIntId;
 
+       jclass ecCalibratorStatusClass;
+       jmethodID ecCalibrationStatusId;
+       jmethodID ecCalibratorStatusFromIntId;
+
        jclass proxyClass;
        jmethodID proxyCtrId;
 
@@ -290,6 +298,26 @@ public:
                                                        ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
                                                        ,message ? env->NewStringUTF(message) : NULL);
        }
+       static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
+               JNIEnv *env = 0;
+               jint result = jvm->AttachCurrentThread(&env,NULL);
+               if (result != 0) {
+                       ms_error("cannot attach VM\n");
+                       return;
+               }
+               LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
+               env->CallVoidMethod(lcData->listener
+                                                       ,lcData->ecCalibrationStatusId
+                                                       ,lcData->core
+                                                       ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
+                                                       ,delay_ms
+                                                       ,data ? data : NULL);
+               if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
+                       //final state, releasing global ref
+                       env->DeleteGlobalRef((jobject)data);
+               }
+
+       }
 
 
 };
@@ -627,6 +655,18 @@ extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(J
        return linphone_core_keep_alive_enabled((LinphoneCore*)lc);
 
 }
+extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
+                                                                                                                                                               ,jobject  thiz
+                                                                                                                                                               ,jlong lc
+                                                                                                                                                               ,jobject data) {
+       return linphone_core_start_echo_calibration((LinphoneCore*)lc
+                                                                                                       , LinphoneCoreData::ecCalibrationStatus
+                                                                                                       , data?env->NewGlobalRef(data):NULL);
+
+}
+
+
+
 //ProxyConfig
 
 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
index b2ede96496cbd0186cc660ca4f0be41e8935caec..f003c4080e4ab10c3ba8d7d799c060a94d807782 100644 (file)
@@ -25,6 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #else
 #include "linphone/linphonecore.h"
 #endif
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 typedef struct _LsdPlayer LsdPlayer;
 typedef struct _LinphoneSoundDaemon LinphoneSoundDaemon;
@@ -65,5 +68,7 @@ typedef void (*LinphoneEcCalibrationCallback)(LinphoneCore *lc, LinphoneEcCalibr
  * Start an echo calibration of the sound devices, in order to find adequate settings for the echo canceller automatically.
 **/
 int linphone_core_start_echo_calibration(LinphoneCore *lc, LinphoneEcCalibrationCallback cb, void *cb_data);
-
+#ifdef __cplusplus
+}
+#endif
 #endif
index a960acbd8130adb94a28cb811fd5734d7a82a2d1..87605b15c0c2f596a045f1441d128cfb7f17b0e1 100644 (file)
@@ -457,7 +457,7 @@ struct _EcCalibrator{
        ms_thread_t thread;
        MSSndCard *play_card,*capt_card;
        MSFilter *sndread,*det,*rec;
-       MSFilter *play, *gen, *sndwrite;
+       MSFilter *play, *gen, *sndwrite,*resampler;
        MSTicker *ticker;
        LinphoneEcCalibrationCallback cb;
        void *cb_data;
index e0e0d4ba8da0508bc16dbbb3395e9fa003c536d0..e98165fc10820a8146a85694747036def339ec2d 100644 (file)
@@ -179,6 +179,50 @@ public interface LinphoneCore {
                        return mStringValue;
                }               
        }
+       /**
+        *      EC Calibrator Status
+.
+        *
+        */
+       static public class EcCalibratorStatus {
+
+               static private Vector values = new Vector();
+               /**
+                * Calibration in progress
+                */
+               static public EcCalibratorStatus InProgress = new EcCalibratorStatus(0,"InProgress");       
+               /**
+                * Calibration done
+                */
+               static public EcCalibratorStatus Done  = new EcCalibratorStatus(1,"Done");
+               /**
+                * Calibration in progress
+                */
+               static public EcCalibratorStatus Failed = new EcCalibratorStatus(2,"Failed");
+
+               private final int mValue;
+               private final String mStringValue;
+
+               private EcCalibratorStatus(int value,String stringValue) {
+                       mValue = value;
+                       values.addElement(this);
+                       mStringValue=stringValue;
+               }
+               public static EcCalibratorStatus fromInt(int value) {
+
+                       for (int i=0; i<values.size();i++) {
+                               EcCalibratorStatus status = (EcCalibratorStatus) values.elementAt(i);
+                               if (status.mValue == value) return status;
+                       }
+                       throw new RuntimeException("status not found ["+value+"]");
+               }
+               public String toString() {
+                       return mStringValue;
+               }
+               public int value(){
+                       return mValue;
+               }
+       }
        /**
         * clear all added proxy configs
         */
@@ -497,4 +541,11 @@ public interface LinphoneCore {
         * @return true if enable
         */
        boolean isKeepAliveEnabled();
+       /**
+        * Start an echo calibration of the sound devices, in order to find adequate settings for the echo canceler automatically.
+        * status is notified to {@link LinphoneCoreListener#ecCalibrationStatus(EcCalibratorStatus, int, Object)}
+        * @param User object
+        * @throws LinphoneCoreException if operation is still in progress;
+       **/
+       void startEchoCalibration(Object data) throws LinphoneCoreException;
 }
index daf256662dd562c8801b15e9b97f93e96f100544..ddd58a3ac3de8266da21d5740a14cc5756d199af 100644 (file)
@@ -78,5 +78,14 @@ public interface LinphoneCoreListener {
                 * @param message       incoming message
                 */
                public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);
+               /**
+                * Invoked when echo cancalation calibration is completed
+                * @param lc LinphoneCore
+                * @param status 
+                * @param delay_ms echo delay
+                * @param data
+                */
+                void ecCalibrationStatus(LinphoneCore lc,LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);
+               
 }
 
index 434b627405d46c50cb109c001e44891551d0efab..a4f5a5bcf16ec4deec210bbd021952495a14d055 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 434b627405d46c50cb109c001e44891551d0efab
+Subproject commit a4f5a5bcf16ec4deec210bbd021952495a14d055