[pulseaudio-discuss] [PATCH] echo-cancel: Fix memblockq length check.

Tanu Kaskinen tanu.kaskinen at digia.com
Wed Apr 25 00:51:38 PDT 2012


In addition to changing "plen > u->blocksize" to "plen >=
u->blocksize", I also removed one of the duplicated ifs.
---

I changed the comparison operator only because it *looked*
wrong, and there was no comment explaining why it's done
like it's done. So Arun really should check this patch.

 src/modules/echo-cancel/module-echo-cancel.c |   86 +++++++++++++-------------
 1 file changed, 42 insertions(+), 44 deletions(-)

diff --git a/src/modules/echo-cancel/module-echo-cancel.c b/src/modules/echo-cancel/module-echo-cancel.c
index eb3c031..161f9d3 100644
--- a/src/modules/echo-cancel/module-echo-cancel.c
+++ b/src/modules/echo-cancel/module-echo-cancel.c
@@ -806,51 +806,49 @@ static void do_push(struct userdata *u) {
         /* take fixed block from recorded samples */
         pa_memblockq_peek_fixed_size(u->source_memblockq, u->blocksize, &rchunk);
 
-        if (plen > u->blocksize) {
-            if (plen > u->blocksize) {
-                /* take fixed block from played samples */
-                pa_memblockq_peek_fixed_size(u->sink_memblockq, u->blocksize, &pchunk);
-
-                rdata = pa_memblock_acquire(rchunk.memblock);
-                rdata += rchunk.index;
-                pdata = pa_memblock_acquire(pchunk.memblock);
-                pdata += pchunk.index;
-
-                cchunk.index = 0;
-                cchunk.length = u->blocksize;
-                cchunk.memblock = pa_memblock_new(u->source->core->mempool, cchunk.length);
-                cdata = pa_memblock_acquire(cchunk.memblock);
-
-                if (u->save_aec) {
-                    if (u->captured_file)
-                        unused = fwrite(rdata, 1, u->blocksize, u->captured_file);
-                    if (u->played_file)
-                        unused = fwrite(pdata, 1, u->blocksize, u->played_file);
-                }
-
-                /* perform echo cancellation */
-                u->ec->run(u->ec, rdata, pdata, cdata);
-
-                if (u->save_aec) {
-                    if (u->canceled_file)
-                        unused = fwrite(cdata, 1, u->blocksize, u->canceled_file);
-                }
-
-                pa_memblock_release(cchunk.memblock);
-                pa_memblock_release(pchunk.memblock);
-                pa_memblock_release(rchunk.memblock);
-
-                /* drop consumed sink samples */
-                pa_memblockq_drop(u->sink_memblockq, u->blocksize);
-                pa_memblock_unref(pchunk.memblock);
-
-                pa_memblock_unref(rchunk.memblock);
-                /* the filtered samples now become the samples from our
-                 * source */
-                rchunk = cchunk;
-
-                plen -= u->blocksize;
+        if (plen >= u->blocksize) {
+            /* take fixed block from played samples */
+            pa_memblockq_peek_fixed_size(u->sink_memblockq, u->blocksize, &pchunk);
+
+            rdata = pa_memblock_acquire(rchunk.memblock);
+            rdata += rchunk.index;
+            pdata = pa_memblock_acquire(pchunk.memblock);
+            pdata += pchunk.index;
+
+            cchunk.index = 0;
+            cchunk.length = u->blocksize;
+            cchunk.memblock = pa_memblock_new(u->source->core->mempool, cchunk.length);
+            cdata = pa_memblock_acquire(cchunk.memblock);
+
+            if (u->save_aec) {
+                if (u->captured_file)
+                    unused = fwrite(rdata, 1, u->blocksize, u->captured_file);
+                if (u->played_file)
+                    unused = fwrite(pdata, 1, u->blocksize, u->played_file);
             }
+
+            /* perform echo cancellation */
+            u->ec->run(u->ec, rdata, pdata, cdata);
+
+            if (u->save_aec) {
+                if (u->canceled_file)
+                    unused = fwrite(cdata, 1, u->blocksize, u->canceled_file);
+            }
+
+            pa_memblock_release(cchunk.memblock);
+            pa_memblock_release(pchunk.memblock);
+            pa_memblock_release(rchunk.memblock);
+
+            /* drop consumed sink samples */
+            pa_memblockq_drop(u->sink_memblockq, u->blocksize);
+            pa_memblock_unref(pchunk.memblock);
+
+            pa_memblock_unref(rchunk.memblock);
+            /* the filtered samples now become the samples from our
+             * source */
+            rchunk = cchunk;
+
+            plen -= u->blocksize;
         }
 
         /* forward the (echo-canceled) data to the virtual source */
-- 
1.7.10



More information about the pulseaudio-discuss mailing list