preprocess: Support source and source2 both
[platform/core/multimedia/pulseaudio-modules-tizen.git] / src / preprocessor / processor_holder.c
index 046c81f..6f3855e 100644 (file)
@@ -95,10 +95,17 @@ int pa_processor_holder_connect_reference(pa_processor_holder *holder, pa_proces
 }
 
 int pa_processor_holder_push_data(pa_processor_holder *holder, pa_memchunk *chunk) {
+    int ret;
+
     pa_assert(holder);
     pa_assert(chunk);
 
-    return pa_memblockq_push(holder->input, chunk);
+    ret = pa_memblockq_push(holder->input, chunk);
+
+    pa_log_debug("push data to the input queue. chunk length(%zu), memblockq length(%zu)",
+                    chunk->length, pa_memblockq_get_length(holder->input));
+
+    return ret;
 }
 
 int pa_processor_holder_push_reference_data(pa_processor_holder *holder, pa_memchunk *chunk) {
@@ -111,16 +118,22 @@ int pa_processor_holder_push_reference_data(pa_processor_holder *holder, pa_memc
 
 int pa_processor_holder_pull_data(pa_processor_holder *holder, pa_memchunk *chunk) {
     int r;
+    size_t length;
 
     pa_assert(holder);
     pa_assert(chunk);
 
-    if ((r = pa_memblockq_peek(holder->output, chunk)) < 0)
+    length = pa_memblockq_get_length(holder->output);
+
+    if ((r = pa_memblockq_peek_fixed_size(holder->output, length, chunk)) < 0)
         pa_log_error("Failed to get memblock from output memblockq");
 
     /* chunk ref count must be one after dropping */
     pa_memblockq_drop(holder->output, chunk->length);
 
+    pa_log_debug("pull from the output queue. chunk length(%zu), memblockq_length(%zu)",
+                    chunk->length, pa_memblockq_get_length(holder->output));
+
     return r;
 }
 
@@ -142,8 +155,11 @@ int pa_processor_holder_pump(pa_processor_holder *holder) {
         process_size = pa_processor_get_process_bytes(p);
         length = pa_memblockq_get_length(pull_queue);
 
-        if (length < process_size)
+        if (length < process_size) {
+            pa_log_info("processor(%s) needs process_size(%zu) but there are bytes(%zu) in the queue",
+                            pa_processor_method_str(p->method), process_size, length);
             return -PROCESSOR_ERR_BUFFERING;
+        }
 
         while (length >= process_size) {
             ret = pa_memblockq_peek_fixed_size(pull_queue, process_size, &chunk);
@@ -152,6 +168,7 @@ int pa_processor_holder_pump(pa_processor_holder *holder) {
             if ((ret = pa_processor_process(p, &chunk)) < 0) {
                 pa_memblock_unref(chunk.memblock);
                 pa_memblockq_drop(pull_queue, chunk.length);
+                pa_log_error("Failed to process");
                 return ret;
             }
 
@@ -165,11 +182,15 @@ int pa_processor_holder_pump(pa_processor_holder *holder) {
     }
 
     length = pa_memblockq_get_length(pull_queue);
-    if (length > 0) {
-        pa_memblockq_peek_fixed_size(pull_queue, length, &chunk);
-        pa_memblockq_push(holder->output, &chunk);
-        pa_memblock_unref(chunk.memblock);
-        pa_memblockq_drop(pull_queue, chunk.length);
+
+    while (length > 0) {
+        pa_memchunk tchunk;
+
+        pa_memblockq_peek(pull_queue, &tchunk);
+        pa_memblockq_push(holder->output, &tchunk);
+        pa_memblock_unref(tchunk.memblock);
+        pa_memblockq_drop(pull_queue, tchunk.length);
+        length = pa_memblockq_get_length(pull_queue);
     }
 
     return 0;