preprocessor: Add prebuffering for a input memblock 48/300248/4
authorJaechul Lee <jcsing.lee@samsung.com>
Thu, 19 Oct 2023 07:42:33 +0000 (16:42 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Mon, 23 Oct 2023 02:20:32 +0000 (11:20 +0900)
a reference plabyack devices sometimes pushes its data irregularly.
So, the source tries to gather more buffers to prevent reference underrun situations.

In case of SlimFit with this patch, It works better than before.

[Version] 15.0.61
[Issue Type] Update

Change-Id: Iae9208006d896350305c6c3d66854fa12cb5b69e
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/preprocessor/processor.c
src/preprocessor/processor_holder.c
src/preprocessor/processor_reference.c

index 9d9c2db..cb49294 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          15.0.60
+Version:          15.0.61
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index 8e072f3..e44e870 100644 (file)
@@ -263,8 +263,10 @@ int pa_processor_process(pa_processor *processor, pa_memchunk *chunk) {
     pa_assert(chunk);
 
     if (processor->reference) {
-        if (pa_processor_reference_pull(processor->reference, &rchunk) < 0)
-            pa_log_warn("Failed to get memblock from reference memblockq. It will be used silence chunk");
+        if (pa_processor_reference_pull(processor->reference, &rchunk) < 0) {
+            pa_log_warn("Failed to get memblock from reference memblockq.");
+            return -1;
+        }
 
         reference = pa_memblock_acquire_chunk(&rchunk);
     }
index eb7d2a4..31f4a7d 100644 (file)
@@ -34,6 +34,7 @@
 #include "processor_holder.h"
 
 #define MEMBLOCKQ_MAXLENGTH (16*1024*1024)
+#define DEFAULT_PREBUFFER_MSEC (300)
 
 pa_processor_holder *pa_processor_holder_new(pa_core *core, pa_sample_spec *ss) {
     pa_processor_holder *holder;
@@ -50,7 +51,7 @@ pa_processor_holder *pa_processor_holder_new(pa_core *core, pa_sample_spec *ss)
                                         MEMBLOCKQ_MAXLENGTH,
                                         0,
                                         ss,
-                                        0,
+                                        pa_usec_to_bytes(DEFAULT_PREBUFFER_MSEC * PA_USEC_PER_MSEC, ss),
                                         0,
                                         0,
                                         &silence);
@@ -151,6 +152,12 @@ int pa_processor_holder_pump(pa_processor_holder *holder) {
 
     pull_queue = holder->input;
 
+    if (!pa_memblockq_is_readable(pull_queue)) {
+        pa_log_info ("prebuffering for preprocessing. input_queue length(%zu)",
+                        pa_memblockq_get_length(pull_queue));
+        return -PROCESSOR_ERR_BUFFERING;
+    }
+
     PA_IDXSET_FOREACH(p, holder->processors, idx) {
         process_size = pa_processor_get_process_bytes(p);
         length = pa_memblockq_get_length(pull_queue);
index 01655ed..0b0ece0 100644 (file)
@@ -50,7 +50,7 @@ pa_processor_reference *pa_processor_reference_new_custom(pa_core *core,
                                                             pa_sample_spec *request_ss,
                                                             pa_usec_t process_usec,
                                                             pa_processor_reference_method_t method) {
-    pa_processor_reference *reference;
+    pa_processor_reference *reference = NULL;
 
     pa_assert(core);
     pa_assert(sink_ss);
@@ -67,7 +67,7 @@ pa_processor_reference *pa_processor_reference_new_custom(pa_core *core,
         reference->interface = pa_processor_reference_method_create(method);
         if (!reference->interface) {
             pa_log_error("Failed to create reference interface");
-            return NULL;
+            goto fail;
         }
 
         pa_assert(reference->interface->create);
@@ -75,13 +75,17 @@ pa_processor_reference *pa_processor_reference_new_custom(pa_core *core,
         pa_assert(reference->interface->destroy);
 
         if (!(reference->priv = reference->interface->create(request_ss))) {
-            pa_processor_reference_free(reference);
             pa_log_error("Failed to create custom reference");
-            return NULL;
+            goto fail;
         }
     }
 
     return reference;
+
+fail:
+    pa_processor_reference_free(reference);
+
+    return NULL;
 }
 
 pa_processor_reference *pa_processor_reference_new(pa_core *core,
@@ -129,7 +133,8 @@ pa_processor_reference *pa_processor_reference_new(pa_core *core,
         pa_log_info("resampler was created for reference");
     }
 
-    pa_log_info("Created reference memblockq rate(%d), channels(%d)", request_ss->rate, request_ss->channels);
+    pa_log_info("Created reference memblockq rate(%d), channels(%d), process_bytes(%zu)",
+            request_ss->rate, request_ss->channels, reference->process_bytes);
 
     return reference;
 
@@ -303,11 +308,15 @@ size_t pa_processor_reference_process_usec_to_bytes(pa_processor_reference *refe
 }
 
 char *pa_processor_reference_dump_index(pa_processor_reference *reference) {
+    int64_t windex, rindex;
+
     pa_assert(reference);
 
-    return pa_sprintf_malloc("windex:rindex(%" PRId64 ":%" PRId64 ")",
-                                pa_memblockq_get_write_index(reference->memblockq),
-                                pa_memblockq_get_read_index(reference->memblockq));
+    windex = pa_memblockq_get_write_index(reference->memblockq);
+    rindex = pa_memblockq_get_read_index(reference->memblockq);
+
+    return pa_sprintf_malloc("windex:rindex(%" PRId64 ":%" PRId64 ") diff(%" PRId64 ")",
+                                windex, rindex, windex - rindex);
 }
 
 pa_sink *pa_processor_reference_get_sink(pa_processor_reference *reference) {