Enable webrtc-audio-processing by default 78/276878/8 accepted/tizen/unified/20220714.135401 submit/tizen/20220713.013700
authorJaechul Lee <jcsing.lee@samsung.com>
Mon, 27 Jun 2022 08:41:30 +0000 (17:41 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Tue, 12 Jul 2022 02:11:33 +0000 (11:11 +0900)
[Version] 15.0.25
[Issue Type] Improvement

Change-Id: Icb43727592ce90077ed6badf8481680dccc57ef1
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
Makefile.am
packaging/pulseaudio-modules-tizen.spec
src/echo-cancel/module-tizenaudio-echo-cancel.c
src/echo-cancel/processor.c
src/echo-cancel/processor.h

index cd71bb1..3723d0a 100644 (file)
@@ -119,6 +119,9 @@ module_tizenaudio_echo_cancel_la_SOURCES = src/echo-cancel/module-tizenaudio-ech
 module_tizenaudio_echo_cancel_la_LDFLAGS = $(MODULE_LDFLAGS)
 module_tizenaudio_echo_cancel_la_LIBADD = $(MODULE_LIBADD) libprocessor.la
 module_tizenaudio_echo_cancel_la_CFLAGS = $(MODULE_CFLAGS) -DPA_MODULE_NAME=module_tizenaudio_echo_cancel
+if ENABLE_WEBRTC
+module_tizenaudio_echo_cancel_la_CFLAGS += -DSUPPORT_METHOD_WEBRTC
+endif
 
 module_sound_player_la_SOURCES = src/module-sound-player.c
 module_sound_player_la_LDFLAGS = $(MODULE_LDFLAGS)
index ad23656..48a97c9 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          15.0.24
+Version:          15.0.25
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
@@ -24,6 +24,9 @@ BuildRequires:    pkgconfig(libsystemd)
 BuildRequires:    pkgconfig(dns_sd)
 BuildRequires:    pkgconfig(hal-api-audio)
 BuildRequires:    pkgconfig(speexdsp)
+%if "%{tizen_profile_name}" != "tv"
+BuildRequires:    pkgconfig(webrtc-audio-processing)
+%endif
 BuildRequires:    pulseaudio
 BuildRequires:    m4
 Requires(post):   /sbin/ldconfig
@@ -52,6 +55,9 @@ export LD_AS_NEEDED=0
 %reconfigure --prefix=%{_prefix} \
         --disable-static \
         --enable-acm \
+%if "%{tizen_profile_name}" != "tv"
+        --enable-webrtc \
+%endif
 %if "%{tizen_profile_name}" == "tv"
         --enable-vconf-helper
 %endif
index 4b6939b..3442009 100644 (file)
@@ -46,7 +46,7 @@ PA_MODULE_DESCRIPTION("Tizen Audio Echo Cancel");
 PA_MODULE_VERSION(PACKAGE_VERSION);
 PA_MODULE_LOAD_ONCE(true);
 PA_MODULE_USAGE(
-        "method=<name of method using for echo cancellation> ");
+        "method=<name of method using for echo cancellation. [method]=webrtc, adrian, speex, reference copy > ");
 
 #define DEFAULT_PROCESS_MSEC 10
 
@@ -69,7 +69,7 @@ struct userdata {
     bool enable;
     uint32_t n_source_output;
 
-    char *default_method;
+    char *force_method;
 
     pa_thread *thread;
     pa_thread_mq thread_mq;
@@ -93,7 +93,6 @@ PA_DEFINE_PRIVATE_CLASS(pa_echo_cancel, pa_msgobject);
 #define PA_ECHO_CANCEL(o) (pa_echo_cancel_cast(o))
 
 #define MEMBLOCKQ_MAXLENGTH (16 * 1024 * 1024)
-#define DEFAULT_AEC_METHOD "speex"
 
 static const char* const valid_modargs[] = {
     "method",
@@ -119,7 +118,7 @@ static int proplist_get_fragment_size_usec(pa_proplist *p, pa_sample_spec *sampl
     return 0;
 }
 
-static int proplist_get_method(pa_proplist *p, const char *default_method, pa_processor_method_t *method) {
+static int proplist_get_method(pa_proplist *p, pa_processor_method_t *method) {
     const char *m;
 
     pa_assert(p);
@@ -128,7 +127,7 @@ static int proplist_get_method(pa_proplist *p, const char *default_method, pa_pr
     if (!(m = pa_proplist_gets(p, PA_PROP_MEDIA_ECHO_CANCEL_METHOD)))
         return -1;
 
-    *method = pa_processor_get_method(m, default_method);
+    *method = pa_processor_get_method(m);
 
     return 0;
 }
@@ -367,14 +366,17 @@ static int process_msg(
 static pa_hook_result_t source_output_new_cb(pa_core *c, pa_source_output_new_data *data, void *userdata) {
     struct userdata *u = (struct userdata *)userdata;
     pa_processor_method_t method;
+    const char *m;
 
     pa_assert(c);
     pa_assert(u);
     pa_assert(data);
 
-    if (proplist_get_method(data->proplist, u->default_method, &method) < 0)
+    if (!(m = pa_proplist_gets(data->proplist, PA_PROP_MEDIA_ECHO_CANCEL_METHOD)))
         return PA_HOOK_OK;
 
+    method = pa_processor_get_method(m);
+
     /* TODO: source-output can be moved */
     data->flags |= PA_SOURCE_OUTPUT_DONT_MOVE;
     data->flags |= PA_SOURCE_OUTPUT_ECHO_CANCEL;
@@ -432,9 +434,13 @@ static pa_hook_result_t source_output_put_cb(pa_core *c, pa_source_output *o, vo
         goto fail;
     }
 
-    if (proplist_get_method(o->proplist, u->default_method, &method) < 0) {
-        pa_log_error("Failed to get method");
-        goto fail;
+    if (u->force_method) {
+        method = pa_processor_get_method(u->force_method);
+    } else {
+        if (proplist_get_method(o->proplist, &method) < 0) {
+            pa_log_error("Failed to get method");
+            goto fail;
+        }
     }
 
     u->source = o->source;
@@ -624,7 +630,7 @@ int pa__init(pa_module *m) {
     m->userdata = u = pa_xnew0(struct userdata, 1);
     u->core = m->core;
     u->m = m;
-    u->default_method = pa_xstrdup(pa_modargs_get_value(ma, "method", DEFAULT_AEC_METHOD));
+    u->force_method = pa_xstrdup(pa_modargs_get_value(ma, "method", NULL));
 
     u->echo_cancel = pa_msgobject_new(pa_echo_cancel);
     u->echo_cancel->parent.process_msg = process_msg;
@@ -741,7 +747,8 @@ void pa__done(pa_module *m) {
 
     pa_thread_mq_done(&u->thread_mq);
 
-    pa_xfree(u->default_method);
+    pa_xfree(u->force_method);
+
     pa_xfree(u);
 }
 
index dbce5fa..c77f088 100644 (file)
@@ -471,33 +471,32 @@ int pa_processor_free(pa_processor *processor) {
     return 0;
 }
 
-pa_processor_method_t pa_processor_get_method(const char *request_method, const char *default_method) {
-    const char *selected;
+const char *pa_processor_method_to_string(pa_processor_method_t method) {
+    if (method >= PA_PROCESSOR_METHOD_MAX)
+        return NULL;
 
-    if (!request_method || !default_method)
-        return PA_PROCESSOR_SPEEX;
+    return method_table[method].name;
+}
 
-    selected = pa_streq(request_method, "default") ? default_method : request_method;
+pa_processor_method_t pa_processor_get_method(const char *request_method) {
+    pa_processor_method_t method;
 
-    if (pa_streq(selected, "speex"))
-        return PA_PROCESSOR_SPEEX;
-    else if (pa_streq(selected, "adrian"))
-        return PA_PROCESSOR_ADRIAN;
+    if (pa_streq(request_method, "speex"))
+        method = PA_PROCESSOR_SPEEX;
+    else if (pa_streq(request_method, "adrian"))
+        method = PA_PROCESSOR_ADRIAN;
 #ifdef SUPPORT_METHOD_WEBRTC
-    else if (pa_streq(selected, "webrtc"))
-        return PA_PROCESSOR_WEBRTC;
+    else if (pa_streq(request_method, "webrtc"))
+        method = PA_PROCESSOR_WEBRTC;
 #endif
-    else if (pa_streq(selected, "reference_copy"))
-        return PA_PROCESSOR_REFERENCE_COPY;
+    else if (pa_streq(request_method, "reference_copy"))
+        method = PA_PROCESSOR_REFERENCE_COPY;
     else
-        return PA_PROCESSOR_SPEEX;
-}
-
-const char *pa_processor_method_to_string(pa_processor_method_t method) {
-    if (method >= PA_PROCESSOR_METHOD_MAX)
-        return NULL;
+        /* request_method could be had 'default' */
+        method = PA_PROCESSOR_METHOD_DEFAULT;
 
-    return method_table[method].name;
+    pa_log_info("processing method is selected. request_method(%s), method_to_string(%s)",
+                request_method, pa_processor_method_to_string(method));
 }
 
 #ifdef __DEBUG__
index ea07143..ea14a69 100644 (file)
@@ -38,6 +38,11 @@ typedef enum {
     PA_PROCESSOR_WEBRTC,
 #endif
     PA_PROCESSOR_REFERENCE_COPY,
+#ifdef SUPPORT_METHOD_WEBRTC
+    PA_PROCESSOR_METHOD_DEFAULT = PA_PROCESSOR_WEBRTC,
+#else
+    PA_PROCESSOR_METHOD_DEFAULT = PA_PROCESSOR_SPEEX,
+#endif
     PA_PROCESSOR_METHOD_MAX,
 } pa_processor_method_t;
 
@@ -58,7 +63,7 @@ int pa_processor_process(pa_processor *processor, pa_memchunk *rec, pa_memchunk
 int pa_processor_push_reference(pa_processor *processor, pa_memchunk *chunk);
 void pa_processor_flush(pa_processor *processor);
 int pa_processor_free(pa_processor *processor);
-pa_processor_method_t pa_processor_get_method(const char *requset_method, const char *default_method);
+pa_processor_method_t pa_processor_get_method(const char *requset_method);
 const char *pa_processor_method_to_string(pa_processor_method_t method);
 
 #endif