From 304449002cbc84fdcf235b5dfaec891278dd7085 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 20 Feb 2006 04:05:16 +0000 Subject: 1) Add flexible seeking support (including absolute) for memory block queues and playback streams 2) Add support to synchronize multiple playback streams 3) add two tests for 1) and 2) 4) s/PA_ERROR/PA_ERR/ 5) s/PA_ERROR_OK/PA_OK/ 6) update simple API to deal properly with new peek/drop recording API 7) add beginnings of proper validity checking on API calls in client libs (needs to be extended) 8) report playback buffer overflows/underflows to the client 9) move client side recording mcalign stuff into the memblockq 10) create typedefs for a bunch of API callback prototypes 11) simplify handling of HUP poll() events Yes, i know, it's usually better to commit a lot of small patches instead of a single big one. In this case however, this would have contradicted the other rule: never commit broken or incomplete stuff. *** This stuff needs a lot of additional testing! *** git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@511 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblockq-test.c | 147 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/tests/memblockq-test.c (limited to 'src/tests/memblockq-test.c') diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c new file mode 100644 index 00000000..b01084da --- /dev/null +++ b/src/tests/memblockq-test.c @@ -0,0 +1,147 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include + +int main(int argc, char *argv[]) { + int ret; + pa_memblockq *bq; + pa_memchunk chunk1, chunk2, chunk3, chunk4; + pa_memblock *silence; + + pa_log_set_maximal_level(PA_LOG_DEBUG); + + silence = pa_memblock_new_fixed("__", 2, 1, NULL); + assert(silence); + + bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, silence, NULL); + assert(bq); + + chunk1.memblock = pa_memblock_new_fixed("AA", 2, 1, NULL); + chunk1.index = 0; + chunk1.length = 2; + assert(chunk1.memblock); + + chunk2.memblock = pa_memblock_new_fixed("TTBB", 4, 1, NULL); + chunk2.index = 2; + chunk2.length = 2; + assert(chunk2.memblock); + + chunk3.memblock = pa_memblock_new_fixed("ZZZZ", 4, 1, NULL); + chunk3.index = 0; + chunk3.length = 4; + assert(chunk3.memblock); + + chunk4.memblock = pa_memblock_new_fixed("KKKKKKKK", 8, 1, NULL); + chunk4.index = 0; + chunk4.length = 8; + assert(chunk4.memblock); + + ret = pa_memblockq_push(bq, &chunk1); + assert(ret == 0); + + ret = pa_memblockq_push(bq, &chunk1); + assert(ret == 0); + + ret = pa_memblockq_push(bq, &chunk2); + assert(ret == 0); + + ret = pa_memblockq_push(bq, &chunk2); + assert(ret == 0); + + pa_memblockq_seek(bq, -6, 0); + ret = pa_memblockq_push(bq, &chunk3); + assert(ret == 0); + + pa_memblockq_seek(bq, -2, 0); + ret = pa_memblockq_push(bq, &chunk3); + assert(ret == 0); + + pa_memblockq_seek(bq, -10, 0); + ret = pa_memblockq_push(bq, &chunk4); + assert(ret == 0); + + pa_memblockq_seek(bq, 10, 0); + + ret = pa_memblockq_push(bq, &chunk1); + assert(ret == 0); + + pa_memblockq_seek(bq, -6, 0); + ret = pa_memblockq_push(bq, &chunk2); + assert(ret == 0); + + /* Test splitting */ + pa_memblockq_seek(bq, -12, 0); + ret = pa_memblockq_push(bq, &chunk1); + assert(ret == 0); + + pa_memblockq_seek(bq, 20, 0); + + /* Test merging */ + ret = pa_memblockq_push(bq, &chunk3); + assert(ret == 0); + pa_memblockq_seek(bq, -2, 0); + + chunk3.index += 2; + chunk3.length -= 2; + + ret = pa_memblockq_push(bq, &chunk3); + assert(ret == 0); + + printf(">"); + + pa_memblockq_shorten(bq, 6); + + for (;;) { + pa_memchunk out; + char *e; + size_t n; + + if (pa_memblockq_peek(bq, &out) < 0) + break; + + for (e = (char*) out.memblock->data + out.index, n = 0; n < out.length; n++) + printf("%c", *e); + + pa_memblock_unref(out.memblock); + pa_memblockq_drop(bq, &out, out.length); + } + + printf("<\n"); + + pa_memblockq_free(bq); + pa_memblock_unref(silence); + pa_memblock_unref(chunk1.memblock); + pa_memblock_unref(chunk2.memblock); + pa_memblock_unref(chunk3.memblock); + pa_memblock_unref(chunk4.memblock); + + return 0; +} -- cgit From e078f084e44de3c4a87bb4fd7a0be9dbda64b604 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 20 Feb 2006 16:09:25 +0000 Subject: explcitily cast strings to make gcc shut up git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@522 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblockq-test.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/tests/memblockq-test.c') diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c index b01084da..e9764627 100644 --- a/src/tests/memblockq-test.c +++ b/src/tests/memblockq-test.c @@ -38,28 +38,28 @@ int main(int argc, char *argv[]) { pa_log_set_maximal_level(PA_LOG_DEBUG); - silence = pa_memblock_new_fixed("__", 2, 1, NULL); + silence = pa_memblock_new_fixed((char*) "__", 2, 1, NULL); assert(silence); bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, silence, NULL); assert(bq); - chunk1.memblock = pa_memblock_new_fixed("AA", 2, 1, NULL); + chunk1.memblock = pa_memblock_new_fixed((char*) "AA", 2, 1, NULL); chunk1.index = 0; chunk1.length = 2; assert(chunk1.memblock); - chunk2.memblock = pa_memblock_new_fixed("TTBB", 4, 1, NULL); + chunk2.memblock = pa_memblock_new_fixed((char*) "TTBB", 4, 1, NULL); chunk2.index = 2; chunk2.length = 2; assert(chunk2.memblock); - chunk3.memblock = pa_memblock_new_fixed("ZZZZ", 4, 1, NULL); + chunk3.memblock = pa_memblock_new_fixed((char*) "ZZZZ", 4, 1, NULL); chunk3.index = 0; chunk3.length = 4; assert(chunk3.memblock); - chunk4.memblock = pa_memblock_new_fixed("KKKKKKKK", 8, 1, NULL); + chunk4.memblock = pa_memblock_new_fixed((char*) "KKKKKKKK", 8, 1, NULL); chunk4.index = 0; chunk4.length = 8; assert(chunk4.memblock); -- cgit From f44ba092651aa75055e109e04b4164ea92ae7fdc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 21:53:48 +0000 Subject: big s/polyp/pulse/g git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1033 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblockq-test.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/tests/memblockq-test.c') diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c index e9764627..af43d06f 100644 --- a/src/tests/memblockq-test.c +++ b/src/tests/memblockq-test.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - polypaudio is distributed in the hope that it will be useful, but + PulseAudio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -27,8 +27,8 @@ #include #include -#include -#include +#include +#include int main(int argc, char *argv[]) { int ret; -- cgit From c3fc2eaa7e44c1d71f53e4f61c874f551a65de3e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 19:56:11 +0000 Subject: update tests for new memory manager git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1267 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblockq-test.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/tests/memblockq-test.c') diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c index af43d06f..1ac4577b 100644 --- a/src/tests/memblockq-test.c +++ b/src/tests/memblockq-test.c @@ -32,34 +32,38 @@ int main(int argc, char *argv[]) { int ret; + + pa_mempool *p; pa_memblockq *bq; pa_memchunk chunk1, chunk2, chunk3, chunk4; pa_memblock *silence; pa_log_set_maximal_level(PA_LOG_DEBUG); + + p = pa_mempool_new(0); - silence = pa_memblock_new_fixed((char*) "__", 2, 1, NULL); + silence = pa_memblock_new_fixed(p, (char*) "__", 2, 1); assert(silence); - bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, silence, NULL); + bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, silence); assert(bq); - chunk1.memblock = pa_memblock_new_fixed((char*) "AA", 2, 1, NULL); + chunk1.memblock = pa_memblock_new_fixed(p, (char*) "AA", 2, 1); chunk1.index = 0; chunk1.length = 2; assert(chunk1.memblock); - chunk2.memblock = pa_memblock_new_fixed((char*) "TTBB", 4, 1, NULL); + chunk2.memblock = pa_memblock_new_fixed(p, (char*) "TTBB", 4, 1); chunk2.index = 2; chunk2.length = 2; assert(chunk2.memblock); - chunk3.memblock = pa_memblock_new_fixed((char*) "ZZZZ", 4, 1, NULL); + chunk3.memblock = pa_memblock_new_fixed(p, (char*) "ZZZZ", 4, 1); chunk3.index = 0; chunk3.length = 4; assert(chunk3.memblock); - chunk4.memblock = pa_memblock_new_fixed((char*) "KKKKKKKK", 8, 1, NULL); + chunk4.memblock = pa_memblock_new_fixed(p, (char*) "KKKKKKKK", 8, 1); chunk4.index = 0; chunk4.length = 8; assert(chunk4.memblock); -- cgit From d210ebbb09daddb2c8c8e8e77243e088b0b19c4d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 26 Sep 2006 23:50:56 +0000 Subject: rework memory block management to be thread-safe and mostly lock-free. pa_memblock is now an opaque structure. Access to its fields is now done through various accessor functions in a thread-safe manner. pa_memblock_acquire() and pa_memblock_release() are now used to access the attached audio data. Why? To allow safe manipulation of the memory pointer maintained by the memory block. Internally _acquire() and _release() maintain a reference counter. Please do not confuse this reference counter whith the one maintained by pa_memblock_ref()/_unref()! As a side effect this patch removes all direct usages of AO_t and replaces it with pa_atomic_xxx based code. This stuff needs some serious testing love. Especially if threads are actively used. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1404 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblockq-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/tests/memblockq-test.c') diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c index 1ac4577b..02848eb2 100644 --- a/src/tests/memblockq-test.c +++ b/src/tests/memblockq-test.c @@ -131,8 +131,10 @@ int main(int argc, char *argv[]) { if (pa_memblockq_peek(bq, &out) < 0) break; - for (e = (char*) out.memblock->data + out.index, n = 0; n < out.length; n++) + p = pa_memblock_acquire(out.memblock); + for (e = (char*) p + out.index, n = 0; n < out.length; n++) printf("%c", *e); + pa_memblock_release(out.memblock); pa_memblock_unref(out.memblock); pa_memblockq_drop(bq, &out, out.length); -- cgit From 8dc62142765249addf131b058c27f931ede1776b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 6 Nov 2006 13:06:01 +0000 Subject: Revert r1404 and keep it on a development branch until it is fully tested. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1409 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblockq-test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/tests/memblockq-test.c') diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c index 02848eb2..1ac4577b 100644 --- a/src/tests/memblockq-test.c +++ b/src/tests/memblockq-test.c @@ -131,10 +131,8 @@ int main(int argc, char *argv[]) { if (pa_memblockq_peek(bq, &out) < 0) break; - p = pa_memblock_acquire(out.memblock); - for (e = (char*) p + out.index, n = 0; n < out.length; n++) + for (e = (char*) out.memblock->data + out.index, n = 0; n < out.length; n++) printf("%c", *e); - pa_memblock_release(out.memblock); pa_memblock_unref(out.memblock); pa_memblockq_drop(bq, &out, out.length); -- cgit From 521daf6f0ac4fa6a2fbfb5d523c0c743342dca2b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 4 Jan 2007 13:43:45 +0000 Subject: Huge trailing whitespace cleanup. Let's keep the tree pure from here on, mmmkay? git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1418 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblockq-test.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/tests/memblockq-test.c') diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c index 1ac4577b..1c0b7fed 100644 --- a/src/tests/memblockq-test.c +++ b/src/tests/memblockq-test.c @@ -2,17 +2,17 @@ /*** This file is part of PulseAudio. - + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + PulseAudio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { pa_log_set_maximal_level(PA_LOG_DEBUG); p = pa_mempool_new(0); - + silence = pa_memblock_new_fixed(p, (char*) "__", 2, 1); assert(silence); @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) { chunk1.index = 0; chunk1.length = 2; assert(chunk1.memblock); - + chunk2.memblock = pa_memblock_new_fixed(p, (char*) "TTBB", 4, 1); chunk2.index = 2; chunk2.length = 2; @@ -70,13 +70,13 @@ int main(int argc, char *argv[]) { ret = pa_memblockq_push(bq, &chunk1); assert(ret == 0); - + ret = pa_memblockq_push(bq, &chunk1); assert(ret == 0); - + ret = pa_memblockq_push(bq, &chunk2); assert(ret == 0); - + ret = pa_memblockq_push(bq, &chunk2); assert(ret == 0); @@ -115,19 +115,19 @@ int main(int argc, char *argv[]) { chunk3.index += 2; chunk3.length -= 2; - + ret = pa_memblockq_push(bq, &chunk3); assert(ret == 0); - + printf(">"); pa_memblockq_shorten(bq, 6); - + for (;;) { pa_memchunk out; char *e; size_t n; - + if (pa_memblockq_peek(bq, &out) < 0) break; @@ -137,15 +137,15 @@ int main(int argc, char *argv[]) { pa_memblock_unref(out.memblock); pa_memblockq_drop(bq, &out, out.length); } - + printf("<\n"); - + pa_memblockq_free(bq); pa_memblock_unref(silence); pa_memblock_unref(chunk1.memblock); pa_memblock_unref(chunk2.memblock); pa_memblock_unref(chunk3.memblock); pa_memblock_unref(chunk4.memblock); - + return 0; } -- cgit From a67c21f093202f142438689d3f7cfbdf4ea82eea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 28 Oct 2007 19:13:50 +0000 Subject: merge 'lennart' branch back into trunk. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblockq-test.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/tests/memblockq-test.c') diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c index 1c0b7fed..25ea399b 100644 --- a/src/tests/memblockq-test.c +++ b/src/tests/memblockq-test.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -48,22 +49,22 @@ int main(int argc, char *argv[]) { bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, silence); assert(bq); - chunk1.memblock = pa_memblock_new_fixed(p, (char*) "AA", 2, 1); + chunk1.memblock = pa_memblock_new_fixed(p, (char*) "11", 2, 1); chunk1.index = 0; chunk1.length = 2; assert(chunk1.memblock); - chunk2.memblock = pa_memblock_new_fixed(p, (char*) "TTBB", 4, 1); + chunk2.memblock = pa_memblock_new_fixed(p, (char*) "XX22", 4, 1); chunk2.index = 2; chunk2.length = 2; assert(chunk2.memblock); - chunk3.memblock = pa_memblock_new_fixed(p, (char*) "ZZZZ", 4, 1); + chunk3.memblock = pa_memblock_new_fixed(p, (char*) "3333", 4, 1); chunk3.index = 0; chunk3.length = 4; assert(chunk3.memblock); - chunk4.memblock = pa_memblock_new_fixed(p, (char*) "KKKKKKKK", 8, 1); + chunk4.memblock = pa_memblock_new_fixed(p, (char*) "44444444", 8, 1); chunk4.index = 0; chunk4.length = 8; assert(chunk4.memblock); @@ -115,13 +116,12 @@ int main(int argc, char *argv[]) { chunk3.index += 2; chunk3.length -= 2; - ret = pa_memblockq_push(bq, &chunk3); assert(ret == 0); - printf(">"); + pa_memblockq_shorten(bq, pa_memblockq_get_length(bq)-2); - pa_memblockq_shorten(bq, 6); + printf(">"); for (;;) { pa_memchunk out; @@ -131,11 +131,13 @@ int main(int argc, char *argv[]) { if (pa_memblockq_peek(bq, &out) < 0) break; - for (e = (char*) out.memblock->data + out.index, n = 0; n < out.length; n++) + p = pa_memblock_acquire(out.memblock); + for (e = (char*) p + out.index, n = 0; n < out.length; n++) printf("%c", *e); + pa_memblock_release(out.memblock); pa_memblock_unref(out.memblock); - pa_memblockq_drop(bq, &out, out.length); + pa_memblockq_drop(bq, out.length); } printf("<\n"); -- cgit