From fb1a35e37d662e76fefd61dc0a6416f778ee0817 Mon Sep 17 00:00:00 2001
From: Simon Morlat <simon.morlat@linphone.org>
Date: Fri, 1 Apr 2011 10:56:35 +0000
Subject: [PATCH] implement echo canceller save and restore

---
 console/linphonec.c    | 26 +++++++++++++-------------
 coreapi/linphonecall.c | 12 ++++++++++++
 coreapi/lpconfig.c     |  2 +-
 mediastreamer2         |  2 +-
 4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/console/linphonec.c b/console/linphonec.c
index c3eb8ace26..de3ce9e44c 100644
--- a/console/linphonec.c
+++ b/console/linphonec.c
@@ -107,7 +107,7 @@ static int copy_file(const char *from, const char *to);
 #endif /*_WIN32_WCE*/
 static int linphonec_parse_cmdline(int argc, char **argv);
 static int linphonec_init(int argc, char **argv);
-static int linphonec_main_loop (LinphoneCore * opm, char * sipAddr);
+static int linphonec_main_loop (LinphoneCore * opm);
 static int linphonec_idle_call (void);
 #ifdef HAVE_READLINE
 static int linphonec_initialize_readline(void);
@@ -161,7 +161,7 @@ static int trace_level = 0;
 static char *logfile_name = NULL;
 static char configfile_name[PATH_MAX];
 static const char *factory_configfile_name=NULL;
-static char *sipAddr = NULL; /* for autocall */
+static char *sip_addr_to_call = NULL; /* for autocall */
 static int window_id = 0; /* 0=standalone window, or window id for embedding video */
 #if !defined(_WIN32_WCE)
 static ortp_pipe_t client_sock=ORTP_PIPE_INVALID;
@@ -630,7 +630,7 @@ main (int argc, char *argv[]) {
 	
 	if (! linphonec_init(argc, argv) ) exit(EXIT_FAILURE);
 
-	linphonec_main_loop (linphonec, sipAddr);
+	linphonec_main_loop (linphonec);
 
 	linphonec_finish(EXIT_SUCCESS);
 
@@ -985,6 +985,14 @@ linphonec_idle_call ()
 		linphone_core_accept_call(opm,NULL);
 		answer_call=FALSE;
 	}
+	/* auto call handling */
+	if (sip_addr_to_call != NULL )
+	{
+		char buf[512];
+		snprintf (buf, sizeof(buf),"call %s", sip_addr_to_call);
+		sip_addr_to_call=NULL;
+		linphonec_parse_command_line(linphonec, buf);
+	}
 
 	if ( auth_stack.nitems )
 	{
@@ -1073,21 +1081,13 @@ static void print_prompt(LinphoneCore *opm){
 }
 
 static int
-linphonec_main_loop (LinphoneCore * opm, char * sipAddr)
+linphonec_main_loop (LinphoneCore * opm)
 {
-	char buf[LINE_MAX_LEN]; /* auto call handling */
 	char *input;
 
 	print_prompt(opm);
 
 
-	/* auto call handling */
-	if (sipAddr != NULL )
-	{
-		snprintf (buf, sizeof(buf),"call %s", sipAddr);
-		linphonec_parse_command_line(linphonec, buf);
-	}
-
 	while (linphonec_running && (input=linphonec_readline(prompt)))
 	{
 		char *iptr; /* input and input pointer */
@@ -1195,7 +1195,7 @@ linphonec_parse_cmdline(int argc, char **argv)
 		{
 			arg_num++;
 			if (arg_num < argc)
-				sipAddr = argv[arg_num];
+				sip_addr_to_call = argv[arg_num];
 		}
                 else if (strncmp ("-a", argv[arg_num], 2) == 0)
                 {
diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c
index c3264d99bb..3640345fa8 100644
--- a/coreapi/linphonecall.c
+++ b/coreapi/linphonecall.c
@@ -649,10 +649,14 @@ void linphone_call_init_media_streams(LinphoneCall *call){
 	audio_stream_enable_gain_control(audiostream,TRUE);
 	if (linphone_core_echo_cancellation_enabled(lc)){
 		int len,delay,framesize;
+		const char *statestr=lp_config_get_string(lc->config,"sound","ec_state",NULL);
 		len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
 		delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
 		framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
 		audio_stream_set_echo_canceller_params(audiostream,len,delay,framesize);
+		if (statestr && audiostream->ec){
+			ms_filter_call_method(audiostream->ec,MS_ECHO_CANCELLER_SET_STATE_STRING,(void*)statestr);
+		}
 	}
 	audio_stream_enable_automatic_gain_control(audiostream,linphone_core_agc_enabled(lc));
 	{
@@ -1009,6 +1013,14 @@ static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
 
 void linphone_call_stop_media_streams(LinphoneCall *call){
 	if (call->audiostream!=NULL) {
+		if (call->audiostream->ec){
+			const char *state_str=NULL;
+			ms_filter_call_method(call->audiostream->ec,MS_ECHO_CANCELLER_GET_STATE_STRING,&state_str);
+			if (state_str){
+				ms_message("Writing echo canceller state, %i bytes",strlen(state_str));
+				lp_config_set_string(call->core->config,"sound","ec_state",state_str);
+			}
+		}
 		linphone_call_log_fill_stats (call->log,call->audiostream);
 		audio_stream_stop(call->audiostream);
 		call->audiostream=NULL;
diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c
index a7dbac214a..ce093cbaf6 100644
--- a/coreapi/lpconfig.c
+++ b/coreapi/lpconfig.c
@@ -22,7 +22,7 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
-#define MAX_LEN 1024
+#define MAX_LEN 32768
 
 #include "linphonecore.h"
 
diff --git a/mediastreamer2 b/mediastreamer2
index 5c2fe94325..66ca17758a 160000
--- a/mediastreamer2
+++ b/mediastreamer2
@@ -1 +1 @@
-Subproject commit 5c2fe943251c5af493d18133251abf91e0ce5e83
+Subproject commit 66ca17758ae34aad009f6f737ffd1fb744525818
-- 
GitLab