From aca1c4001def39641e8662848bb70f8b54b394da Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Wed, 25 Apr 2012 10:51:38 +0300 Subject: echo-cancel: Fix memblockq length check. In addition to changing "plen > u->blocksize" to "plen >= u->blocksize", I also removed one of the duplicated ifs. --- 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 5ca5d1e2..297f19ee 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 */ -- cgit v1.2.3