preprocess: Add prefix NS, AEC to method names 25/295625/6
authorJaechul Lee <jcsing.lee@samsung.com>
Wed, 12 Jul 2023 02:19:05 +0000 (11:19 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Fri, 14 Jul 2023 08:00:28 +0000 (17:00 +0900)
* changed method names
* added srid method
* fixed build warning
* fixed a crash when source-output moves

[Version] 15.0.49
[Issue Type] update

Change-Id: I1ac4128b038a78c42150ede7d49cc553f6684708
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/preprocessor/method_factory.h
src/preprocessor/module-tizenaudio-preprocessor.c
src/preprocessor/processor.c

index 559a438..1012018 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          15.0.48
+Version:          15.0.49
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 96bd030..2b53865 100644 (file)
 #endif
 
 typedef enum {
-    PROCESSOR_METHOD_SPEEX,
-    PROCESSOR_METHOD_WEBRTC,
     PROCESSOR_METHOD_REFERENCE_COPY,
-    PROCESSOR_METHOD_RNNOISE,
-    PROCESSOR_METHOD_NONE_PSE,
+    PROCESSOR_METHOD_AEC_SPEEX,
+    PROCESSOR_METHOD_AEC_WEBRTC,
+    PROCESSOR_METHOD_NS_RNNOISE,
+    PROCESSOR_METHOD_NS_PSE,
+    PROCESSOR_METHOD_NS_SRID,
     PROCESSOR_METHOD_MAX,
 } pa_processor_method_t;
 
index 7c7e8be..7e0e343 100644 (file)
@@ -670,6 +670,9 @@ static pa_hook_result_t source_output_move_start_cb(pa_core *c, pa_source_output
     pa_assert(o);
     pa_assert(u);
 
+    if (!is_preprocessor_marked(o->flags))
+        return PA_HOOK_OK;
+
     if (!proplist_test_tizen_version2(o->source->proplist)) {
         pa_msgobject *msgobject = PA_MSGOBJECT(u->preprocessor);
         pa_assert(msgobject);
@@ -687,6 +690,9 @@ static pa_hook_result_t source_output_move_finish_cb(pa_core *c, pa_source_outpu
     pa_assert(o);
     pa_assert(u);
 
+    if (!is_preprocessor_marked(o->flags))
+        return PA_HOOK_OK;
+
     if (!proplist_test_tizen_version2(o->source->proplist)) {
         pa_msgobject *msgobject = PA_MSGOBJECT(u->preprocessor);
         pa_assert(msgobject);
index 73ac36e..b088965 100644 (file)
@@ -31,6 +31,7 @@
 #include <pulsecore/resampler.h>
 #include <pulsecore/core-util.h>
 
+#include <assert.h>
 #include "processor.h"
 
 #ifdef __DEBUG__
@@ -57,6 +58,29 @@ static void debug_close_file(pa_processor *processor);
 #define debug_close_file(x)
 #endif
 
+struct method_info {
+    audio_effect_method_e audio_effect_method;
+    const char *method_str;
+    bool need_reference;
+};
+
+static struct method_info method_table[] = {
+    [PROCESSOR_METHOD_AEC_SPEEX] =
+        { AUDIO_EFFECT_METHOD_AEC_SPEEX, "aec-speex", true },
+    [PROCESSOR_METHOD_AEC_WEBRTC] =
+        { AUDIO_EFFECT_METHOD_AEC_WEBRTC, "aec-webrtc", true },
+    [PROCESSOR_METHOD_REFERENCE_COPY] =
+        { AUDIO_EFFECT_METHOD_REFCOPY, "reference_copy", true },
+    [PROCESSOR_METHOD_NS_RNNOISE] =
+        { AUDIO_EFFECT_METHOD_NS_RNNOISE, "ns-rnnoise", false },
+    [PROCESSOR_METHOD_NS_PSE] =
+        { AUDIO_EFFECT_METHOD_NS_PSE, "ns-pse", false },
+    [PROCESSOR_METHOD_NS_SRID] =
+        { AUDIO_EFFECT_METHOD_NS_SRID, "ns-srid", false },
+};
+
+static_assert(sizeof(method_table) / sizeof(struct method_info) == PROCESSOR_METHOD_MAX);
+
 static size_t pa_processor_usec_to_frame(pa_usec_t usec, pa_sample_spec *spec) {
     pa_assert(spec);
 
@@ -68,30 +92,14 @@ static pa_usec_t pa_processor_frame_to_usec(size_t frame, pa_sample_spec *spec)
 }
 
 static int pa_processor_convert_method(pa_processor_method_t method, audio_effect_method_e *audio_effect_method) {
-    int ret = 0;
-
-    switch (method) {
-        case PROCESSOR_METHOD_SPEEX:
-            *audio_effect_method = AUDIO_EFFECT_METHOD_AEC_SPEEX;
-            break;
-        case PROCESSOR_METHOD_WEBRTC:
-            *audio_effect_method = AUDIO_EFFECT_METHOD_AEC_WEBRTC;
-            break;
-        case PROCESSOR_METHOD_REFERENCE_COPY:
-            *audio_effect_method = AUDIO_EFFECT_METHOD_AEC_REFCOPY;
-            break;
-        case PROCESSOR_METHOD_RNNOISE:
-            *audio_effect_method = AUDIO_EFFECT_METHOD_NS_RNNOISE;
-            break;
-        case PROCESSOR_METHOD_NONE_PSE:
-            *audio_effect_method = AUDIO_EFFECT_METHOD_NS_PSE;
-            break;
-        default:
-            ret = -1;
-            break;
+    if (method >= PROCESSOR_METHOD_MAX) {
+        pa_log_error("invalid processor method(%d)", method);
+        return -1;
     }
 
-    return ret;
+    *audio_effect_method = method_table[method].audio_effect_method;
+
+    return 0;
 }
 
 static int pa_processor_convert_format(pa_sample_format_t f, audio_effect_format_e *format) {
@@ -257,8 +265,8 @@ int pa_processor_process(pa_processor *processor, pa_memchunk *chunk) {
     ochunk.length = chunk->length;
     ochunk.memblock = pa_memblock_new(processor->core->mempool, ochunk.length);
 
-    recording = (uint8_t *)pa_memblock_acquire_chunk(chunk);
-    output = (uint8_t *)pa_memblock_acquire_chunk(&ochunk);
+    recording = (int8_t *)pa_memblock_acquire_chunk(chunk);
+    output = (int8_t *)pa_memblock_acquire_chunk(&ochunk);
 
     debug_timestamp_begin(processor);
 
@@ -328,48 +336,33 @@ pa_memblockq *pa_processor_get_result_memblockq(pa_processor *processor) {
 }
 
 const char *pa_processor_method_str(pa_processor_method_t method) {
-    static const char *method_table[] = {
-        [PROCESSOR_METHOD_SPEEX] = "speex",
-        [PROCESSOR_METHOD_WEBRTC] = "webrtc",
-        [PROCESSOR_METHOD_REFERENCE_COPY] = "reference_copy",
-        [PROCESSOR_METHOD_RNNOISE] = "rnnoise",
-        [PROCESSOR_METHOD_NONE_PSE] = "none-pse" };
-
     if (method >= PROCESSOR_METHOD_MAX)
         return NULL;
 
-    return method_table[method];
+    return method_table[method].method_str;
 }
 
 int pa_processor_method_enum(const char *method, pa_processor_method_t *m) {
+    int i;
+
     pa_assert(method);
     pa_assert(m);
 
-    if (pa_streq(method, "speex"))
-        *m = PROCESSOR_METHOD_SPEEX;
-    else if (pa_streq(method, "webrtc"))
-        *m = PROCESSOR_METHOD_WEBRTC;
-    else if (pa_streq(method, "reference_copy"))
-        *m = PROCESSOR_METHOD_REFERENCE_COPY;
-    else if (pa_streq(method, "rnnoise"))
-        *m = PROCESSOR_METHOD_RNNOISE;
-    else if (pa_streq(method, "pse"))
-        *m = PROCESSOR_METHOD_NONE_PSE;
-    else
-        return -1;
+    for (i = 0; i < PROCESSOR_METHOD_MAX; i++) {
+        if (pa_streq(method, method_table[i].method_str)) {
+            *m = i;
+            return 0;
+        }
+    }
 
-    return 0;
+    return -1;
 }
 
 bool pa_processor_method_need_reference_structure(pa_processor_method_t m) {
-    if (m == PROCESSOR_METHOD_SPEEX)
-        return true;
-    else if (m == PROCESSOR_METHOD_WEBRTC)
-        return true;
-    else if (m == PROCESSOR_METHOD_REFERENCE_COPY)
-        return true;
-
-    return false;
+    if (m >= PROCESSOR_METHOD_MAX)
+        return false;
+
+    return method_table[m].need_reference;
 }
 
 void pa_processor_attach_reference(pa_processor *processor, pa_processor_reference *reference) {