Enhance for echo cancel - samsung
authorvivian,zhang <vivian.zhang@intel.com>
Tue, 18 Jun 2013 08:18:58 +0000 (16:18 +0800)
committerJaska Uimonen <jaska.uimonen@intel.com>
Thu, 17 Oct 2013 12:28:35 +0000 (15:28 +0300)
Change-Id: I625ca676228b58b5d53f72b9d14b3e811d212d1e

src/Makefile.am
src/map-file
src/modules/echo-cancel/module-echo-cancel.c
src/pulse/ext-echo-cancel.c [new file with mode: 0644]
src/pulse/ext-echo-cancel.h [new file with mode: 0644]

index d5a9021..3bc22d3 100644 (file)
@@ -747,6 +747,7 @@ pulseinclude_HEADERS = \
                pulse/ext-device-restore.h \
                pulse/ext-stream-restore.h \
                pulse/ext-node-manager.h \
+               pulse/ext-echo-cancel.h \
                pulse/format.h \
                pulse/gccmacro.h \
                pulse/introspect.h \
@@ -793,6 +794,7 @@ libpulse_la_SOURCES = \
                pulse/ext-device-restore.c pulse/ext-device-restore.h \
                pulse/ext-stream-restore.c pulse/ext-stream-restore.h \
                pulse/ext-node-manager.c pulse/ext-node-manager.h \
+               pulse/ext-echo-cancel.c pulse/ext-echo-cancel.h \
                pulse/format.c pulse/format.h \
                pulse/gccmacro.h \
                pulse/internal.h \
@@ -1940,7 +1942,7 @@ module_echo_cancel_la_SOURCES = \
                modules/echo-cancel/null.c \
                modules/echo-cancel/echo-cancel.h
 module_echo_cancel_la_LDFLAGS = $(MODULE_LDFLAGS)
-module_echo_cancel_la_LIBADD = $(MODULE_LIBADD) $(LIBSPEEX_LIBS)
+module_echo_cancel_la_LIBADD = libprotocol-native.la $(MODULE_LIBADD) $(LIBSPEEX_LIBS)
 module_echo_cancel_la_CFLAGS = $(AM_CFLAGS) $(SERVER_CFLAGS) $(LIBSPEEX_CFLAGS)
 if HAVE_ADRIAN_EC
 module_echo_cancel_la_SOURCES += \
index 0d18cb3..77766a3 100644 (file)
@@ -173,6 +173,8 @@ pa_ext_stream_restore_set_subscribe_cb;
 pa_ext_stream_restore_subscribe;
 pa_ext_stream_restore_test;
 pa_ext_stream_restore_write;
+pa_ext_echo_cancel_set_volume;
+pa_ext_echo_cancel_set_device;
 pa_ext_node_manager_test;
 pa_ext_node_manager_read_nodes;
 pa_ext_node_manager_connect_nodes;
index fbdb3b3..20f677d 100644 (file)
@@ -53,6 +53,9 @@
 #include <pulsecore/sample-util.h>
 #include <pulsecore/ltdl-helper.h>
 
+#include <pulsecore/protocol-native.h>
+#include <pulsecore/pstream-util.h>
+
 #include "module-echo-cancel-symdef.h"
 
 PA_MODULE_AUTHOR("Wim Taymans");
@@ -94,6 +97,11 @@ typedef enum {
 #endif
 } pa_echo_canceller_method_t;
 
+enum {
+       AEC_SET_VOLUME,
+       AEC_SET_DEVICE,
+};
+
 #ifdef HAVE_WEBRTC
 #define DEFAULT_ECHO_CANCELLER "webrtc"
 #else
@@ -255,6 +263,8 @@ struct userdata {
     struct {
         pa_cvolume current_volume;
     } thread_info;
+
+    pa_native_protocol *protocol;
 };
 
 static void source_output_snapshot_within_thread(struct userdata *u, struct snapshot *snapshot);
@@ -1602,6 +1612,46 @@ static pa_echo_canceller_method_t get_ec_method_from_string(const char *method)
     return PA_ECHO_CANCELLER_INVALID;
 }
 
+static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connection *c, uint32_t tag, pa_tagstruct *t) {
+       uint32_t command;
+       uint32_t value;
+       struct userdata *u = NULL;
+       pa_tagstruct *reply = NULL;
+       pa_assert(p);
+       pa_assert(m);
+       pa_assert(c);
+       pa_assert(t);
+
+       u = m->userdata;
+
+       if (pa_tagstruct_getu32(t, &command) < 0)
+       goto fail;
+
+       reply = pa_tagstruct_new(NULL, 0);
+       pa_tagstruct_putu32(reply, PA_COMMAND_REPLY);
+       pa_tagstruct_putu32(reply, tag);
+
+       switch (command) {
+               case AEC_SET_VOLUME: {
+                       pa_tagstruct_getu32(t,&value);
+                       pa_log_debug("AEC_SET_VOLUME in echo cancel = %d",value);
+               break;
+       }
+               case AEC_SET_DEVICE: {
+                       pa_tagstruct_getu32(t,&value);
+                       pa_log_debug("AEC_SET_DEVICE in echo cancel = %d",value);
+               break;
+       }
+       default:
+               goto fail;
+       }
+       pa_pstream_send_tagstruct(pa_native_connection_get_pstream(c), reply);
+       return 0;
+
+fail:
+       return -1;
+}
+
 /* Common initialisation bits between module-echo-cancel and the standalone
  * test program.
  *
@@ -1992,6 +2042,9 @@ int pa__init(pa_module*m) {
 
     u->thread_info.current_volume = u->source->reference_volume;
 
+    u->protocol = pa_native_protocol_get(m->core);
+    pa_native_protocol_install_ext(u->protocol, m, extension_cb);
+
     pa_sink_put(u->sink);
     pa_source_put(u->source);
 
@@ -2069,6 +2122,11 @@ void pa__done(pa_module*m) {
         pa_xfree(u->ec);
     }
 
+    if (u->protocol) {
+        pa_native_protocol_remove_ext(u->protocol, m);
+        pa_native_protocol_unref(u->protocol);
+    }
+
     if (u->asyncmsgq)
         pa_asyncmsgq_unref(u->asyncmsgq);
 
diff --git a/src/pulse/ext-echo-cancel.c b/src/pulse/ext-echo-cancel.c
new file mode 100644 (file)
index 0000000..9339939
--- /dev/null
@@ -0,0 +1,100 @@
+/***
+  This file is part of PulseAudio.
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio 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 Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pulse/context.h>
+#include <pulse/gccmacro.h>
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/pstream-util.h>
+#include <pulsecore/log.h>
+#include "internal.h"
+#include "operation.h"
+#include "fork-detect.h"
+
+#include "ext-echo-cancel.h"
+
+enum {
+       AEC_SET_VOLUME,
+       AEC_SET_DEVICE,
+};
+
+pa_operation *pa_ext_echo_cancel_set_device (
+                               pa_context *c,
+                               int device,
+                               pa_context_success_cb_t cb,
+                               void *userdata) {
+
+       uint32_t tag;
+       pa_operation *o = NULL;
+       pa_tagstruct *t = NULL;
+
+       pa_assert(c);
+       pa_assert(PA_REFCNT_VALUE(c) >= 1);
+       PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
+       PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+       PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
+
+       o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+       t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
+       pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+       pa_tagstruct_puts(t, "module-echo-cancel");
+       pa_tagstruct_putu32(t, AEC_SET_DEVICE);
+       pa_tagstruct_putu32(t, device);
+
+       pa_pstream_send_tagstruct(c->pstream, t);
+       pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+       return o;
+}
+
+
+pa_operation *pa_ext_echo_cancel_set_volume (
+                               pa_context *c,
+                               int volume,
+                               pa_context_success_cb_t cb,
+                               void *userdata) {
+
+       uint32_t tag;
+       pa_operation *o = NULL;
+       pa_tagstruct *t = NULL;
+
+       pa_assert(c);
+       pa_assert(PA_REFCNT_VALUE(c) >= 1);
+       PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
+       PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+       PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
+
+       o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+       t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
+       pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+       pa_tagstruct_puts(t, "module-echo-cancel");
+       pa_tagstruct_putu32(t, AEC_SET_VOLUME);
+       pa_tagstruct_putu32(t, volume);
+
+       pa_pstream_send_tagstruct(c->pstream, t);
+       pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
+
+       return o;
+}
diff --git a/src/pulse/ext-echo-cancel.h b/src/pulse/ext-echo-cancel.h
new file mode 100644 (file)
index 0000000..12e4eeb
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef foopulseechocancelfoo
+#define foopulseechocancelfoo
+
+/***
+  This file is part of PulseAudio.
+
+  PulseAudio is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License,
+  or (at your option) any later version.
+
+  PulseAudio 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 Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <pulse/context.h>
+#include <pulse/version.h>
+
+/** \file
+ *
+ * Routines for controlling module-echo-cancel
+ */
+
+PA_C_DECL_BEGIN
+
+/** Set volume to AEC module */
+pa_operation *pa_ext_echo_cancel_set_volume (
+        pa_context *c,
+        int volume,
+        pa_context_success_cb_t cb,
+        void *userdata);
+
+pa_operation *pa_ext_echo_cancel_set_device (
+        pa_context *c,
+        int device,
+        pa_context_success_cb_t cb,
+        void *userdata);
+
+
+PA_C_DECL_END
+
+#endif