From e205b25d65ccb380fa158711e24d55b6de5d9bc1 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 16 Feb 2006 19:19:58 +0000 Subject: Reorganised the source tree. We now have src/ with a couple of subdirs: * daemon/ - Contains the files specific to the polypaudio daemon. * modules/ - All loadable modules. * polyp/ - Files that are part of the public, application interface or are only used in libpolyp. * polypcore/ - All other shared files. * tests/ - Test programs. * utils/ - Utility programs. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@487 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/cpulimit-test.c | 92 +++++++++++++++++++++++++++++ src/tests/mainloop-test.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++ src/tests/mcalign-test.c | 96 ++++++++++++++++++++++++++++++ src/tests/pacat-simple.c | 101 ++++++++++++++++++++++++++++++++ src/tests/parec-simple.c | 100 +++++++++++++++++++++++++++++++ src/tests/strlist-test.c | 42 +++++++++++++ src/tests/voltest.c | 20 +++++++ 7 files changed, 597 insertions(+) create mode 100644 src/tests/cpulimit-test.c create mode 100644 src/tests/mainloop-test.c create mode 100644 src/tests/mcalign-test.c create mode 100644 src/tests/pacat-simple.c create mode 100644 src/tests/parec-simple.c create mode 100644 src/tests/strlist-test.c create mode 100644 src/tests/voltest.c (limited to 'src/tests') diff --git a/src/tests/cpulimit-test.c b/src/tests/cpulimit-test.c new file mode 100644 index 00000000..97a8a0dd --- /dev/null +++ b/src/tests/cpulimit-test.c @@ -0,0 +1,92 @@ +/* $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 + +#include "../daemon/cpulimit.h" +#include +#include + +#ifdef TEST2 +#include +#endif + +/* A simple example for testing the cpulimit subsystem */ + +static time_t start; + +#ifdef TEST2 + +static void func(pa_mainloop_api *m, PA_GCC_UNUSED pa_signal_event *e, PA_GCC_UNUSED int sig, PA_GCC_UNUSED void *userdata) { + time_t now; + time(&now); + + if ((now - start) >= 30) { + m->quit(m, 1); + fprintf(stderr, "Test failed\n"); + } else + raise(SIGUSR1); +} + +#endif + +int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { + pa_mainloop *m; + + m = pa_mainloop_new(); + assert(m); + + pa_cpu_limit_init(pa_mainloop_get_api(m)); + + time(&start); + +#ifdef TEST2 + pa_signal_init(pa_mainloop_get_api(m)); + pa_signal_new(SIGUSR1, func, NULL); + raise(SIGUSR1); + pa_mainloop_run(m, NULL); + pa_signal_done(); +#else + for (;;) { + time_t now; + time(&now); + + if ((now - start) >= 30) { + fprintf(stderr, "Test failed\n"); + break; + } + } +#endif + + pa_cpu_limit_done(); + + pa_mainloop_free(m); + + return 0; +} diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c new file mode 100644 index 00000000..f62c9693 --- /dev/null +++ b/src/tests/mainloop-test.c @@ -0,0 +1,146 @@ +/* $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 +#include + +#ifdef GLIB_MAIN_LOOP + +#include +#include + +static GMainLoop* glib_main_loop = NULL; + +#if GLIB_MAJOR_VERSION >= 2 +#define GLIB20 +#else +#undef GLIB20 +#endif + + +#else /* GLIB_MAIN_LOOP */ +#include +#endif /* GLIB_MAIN_LOOP */ + +static pa_defer_event *de; + +static void iocb(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) { + unsigned char c; + read(fd, &c, sizeof(c)); + fprintf(stderr, "IO EVENT: %c\n", c < 32 ? '.' : c); + a->defer_enable(de, 1); +} + +static void dcb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) { + fprintf(stderr, "DEFER EVENT\n"); + a->defer_enable(e, 0); +} + +static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { + fprintf(stderr, "TIME EVENT\n"); + +#if defined(GLIB_MAIN_LOOP) && defined(GLIB20) + g_main_loop_quit(glib_main_loop); +#elif defined(GLIB_MAIN_LOOP) + g_main_quit(glib_main_loop); +#else + a->quit(a, 0); +#endif +} + +int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { + pa_mainloop_api *a; + pa_io_event *ioe; + pa_time_event *te; + struct timeval tv; + +#ifdef GLIB_MAIN_LOOP + pa_glib_mainloop *g; + +#ifdef GLIB20 + glib_main_loop = g_main_loop_new(NULL, FALSE); + assert(glib_main_loop); + + g = pa_glib_mainloop_new(NULL); +#else /* GLIB20 */ + glib_main_loop = g_main_new(FALSE); + assert(glib_main_loop); + + g = pa_glib_mainloop_new(); +#endif /* GLIB20 */ + assert(g); + + a = pa_glib_mainloop_get_api(g); + assert(a); +#else /* GLIB_MAIN_LOOP */ + pa_mainloop *m; + + m = pa_mainloop_new(); + assert(m); + + a = pa_mainloop_get_api(m); + assert(a); +#endif /* GLIB_MAIN_LOOP */ + + ioe = a->io_new(a, 0, PA_IO_EVENT_INPUT, iocb, NULL); + assert(ioe); + + de = a->defer_new(a, dcb, NULL); + assert(de); + + pa_gettimeofday(&tv); + tv.tv_sec += 10; + te = a->time_new(a, &tv, tcb, NULL); + +#if defined(GLIB_MAIN_LOOP) && defined(GLIB20) + g_main_loop_run(glib_main_loop); +#elif defined(GLIB_MAIN_LOOP) + g_main_run(glib_main_loop); +#else + pa_mainloop_run(m, NULL); +#endif + + a->time_free(te); + a->defer_free(de); + a->io_free(ioe); + +#ifdef GLIB_MAIN_LOOP + pa_glib_mainloop_free(g); +#ifdef GLIB20 + g_main_loop_unref(glib_main_loop); +#else + g_main_destroy(glib_main_loop); +#endif +#else + pa_mainloop_free(m); +#endif + + return 0; +} diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c new file mode 100644 index 00000000..861c38c1 --- /dev/null +++ b/src/tests/mcalign-test.c @@ -0,0 +1,96 @@ +/* $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.1 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 + Lesser 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 +#include +#include + +#include +#include +#include + +/* A simple program for testing pa_mcalign */ + +int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { + pa_mcalign *a = pa_mcalign_new(11, NULL); + pa_memchunk c; + + pa_memchunk_reset(&c); + + srand(time(NULL)); + + for (;;) { + ssize_t r; + size_t l; + + if (!c.memblock) { + c.memblock = pa_memblock_new(2048, NULL); + c.index = c.length = 0; + } + + assert(c.index < c.memblock->length); + + l = c.memblock->length - c.index; + + l = l <= 1 ? l : rand() % (l-1) +1 ; + + if ((r = read(STDIN_FILENO, (uint8_t*) c.memblock->data + c.index, l)) <= 0) { + fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF"); + break; + } + + c.length = r; + pa_mcalign_push(a, &c); + fprintf(stderr, "Read %d bytes\n", r); + + c.index += r; + + if (c.index >= c.memblock->length) { + pa_memblock_unref(c.memblock); + pa_memchunk_reset(&c); + } + + for (;;) { + pa_memchunk t; + + if (pa_mcalign_pop(a, &t) < 0) + break; + + pa_loop_write(STDOUT_FILENO, (uint8_t*) t.memblock->data + t.index, t.length); + fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length); + + pa_memblock_unref(t.memblock); + } + } + + pa_mcalign_free(a); + + if (c.memblock) + pa_memblock_unref(c.memblock); +} diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c new file mode 100644 index 00000000..8b3a7b22 --- /dev/null +++ b/src/tests/pacat-simple.c @@ -0,0 +1,101 @@ +/* $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 +#include +#include + +#define BUFSIZE 1024 + +int main(PA_GCC_UNUSED int argc, char*argv[]) { + + /* The Sample format to use */ + static const pa_sample_spec ss = { + .format = PA_SAMPLE_S16LE, + .rate = 44100, + .channels = 2 + }; + + pa_simple *s = NULL; + int ret = 1; + int error; + + /* Create a new playback stream */ + if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, &error))) { + fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); + goto finish; + } + + for (;;) { + uint8_t buf[BUFSIZE]; + ssize_t r; + +#if 0 + pa_usec_t latency; + + if ((latency = pa_simple_get_playback_latency(s, &error)) == (pa_usec_t) -1) { + fprintf(stderr, __FILE__": pa_simple_get_playback_latency() failed: %s\n", pa_strerror(error)); + goto finish; + } + + fprintf(stderr, "%0.0f usec \r", (float)latency); +#endif + + /* Read some data ... */ + if ((r = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) { + if (r == 0) /* EOF */ + break; + + fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno)); + goto finish; + } + + /* ... and play it */ + if (pa_simple_write(s, buf, r, &error) < 0) { + fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error)); + goto finish; + } + } + + /* Make sure that every single sample was played */ + if (pa_simple_drain(s, &error) < 0) { + fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", pa_strerror(error)); + goto finish; + } + + ret = 0; + +finish: + + if (s) + pa_simple_free(s); + + return ret; +} diff --git a/src/tests/parec-simple.c b/src/tests/parec-simple.c new file mode 100644 index 00000000..10eaea8d --- /dev/null +++ b/src/tests/parec-simple.c @@ -0,0 +1,100 @@ +/* $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 +#include +#include + +#define BUFSIZE 1024 + +/* A simple routine calling UNIX write() in a loop */ +static ssize_t loop_write(int fd, const void*data, size_t size) { + ssize_t ret = 0; + + while (size > 0) { + ssize_t r; + + if ((r = write(fd, data, size)) < 0) + return r; + + if (r == 0) + break; + + ret += r; + data = (const uint8_t*) data + r; + size -= r; + } + + return ret; +} + +int main(PA_GCC_UNUSED int argc, char*argv[]) { + /* The sample type to use */ + static const pa_sample_spec ss = { + .format = PA_SAMPLE_S16LE, + .rate = 44100, + .channels = 2 + }; + pa_simple *s = NULL; + int ret = 1; + int error; + + /* Create the recording stream */ + if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, &error))) { + fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); + goto finish; + } + + for (;;) { + uint8_t buf[BUFSIZE]; + ssize_t r; + + /* Record some data ... */ + if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) { + fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error)); + goto finish; + } + + /* And write it to STDOUT */ + if ((r = loop_write(STDOUT_FILENO, buf, sizeof(buf))) <= 0) { + fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno)); + goto finish; + } + } + + ret = 0; + +finish: + + if (s) + pa_simple_free(s); + + return ret; +} diff --git a/src/tests/strlist-test.c b/src/tests/strlist-test.c new file mode 100644 index 00000000..14543112 --- /dev/null +++ b/src/tests/strlist-test.c @@ -0,0 +1,42 @@ +#include + +#include +#include +#include + +int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char* argv[]) { + char *t, *u; + pa_strlist *l = NULL; + + l = pa_strlist_prepend(l, "e"); + l = pa_strlist_prepend(l, "d"); + l = pa_strlist_prepend(l, "c"); + l = pa_strlist_prepend(l, "b"); + l = pa_strlist_prepend(l, "a"); + + t = pa_strlist_tostring(l); + pa_strlist_free(l); + + fprintf(stderr, "1: %s\n", t); + + l = pa_strlist_parse(t); + pa_xfree(t); + + t = pa_strlist_tostring(l); + fprintf(stderr, "2: %s\n", t); + pa_xfree(t); + + l = pa_strlist_pop(l, &u); + fprintf(stderr, "3: %s\n", u); + pa_xfree(u); + + l = pa_strlist_remove(l, "c"); + + t = pa_strlist_tostring(l); + fprintf(stderr, "4: %s\n", t); + pa_xfree(t); + + pa_strlist_free(l); + + return 0; +} diff --git a/src/tests/voltest.c b/src/tests/voltest.c new file mode 100644 index 00000000..58f1da00 --- /dev/null +++ b/src/tests/voltest.c @@ -0,0 +1,20 @@ +/* $Id$ */ + +#include + +#include +#include + +int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { + pa_volume_t v; + + for (v = PA_VOLUME_MUTED; v <= PA_VOLUME_NORM*2; v += 256) { + + double dB = pa_sw_volume_to_dB(v); + double f = pa_sw_volume_to_linear(v); + + printf("Volume: %3i; percent: %i%%; decibel %0.2f; linear = %0.2f; volume(decibel): %3i; volume(linear): %3i\n", + v, (v*100)/PA_VOLUME_NORM, dB, f, pa_sw_volume_from_dB(dB), pa_sw_volume_from_linear(f)); + + } +} -- cgit From 4ad2926eba724771ef29f5aae3757a588bf8818e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Feb 2006 22:11:35 +0000 Subject: add a bunch of simple Makefile in the subdirs, just to make compilation with emacs easier they are not intended to be distributed or anything. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@490 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/Makefile | 1 + 1 file changed, 1 insertion(+) create mode 120000 src/tests/Makefile (limited to 'src/tests') diff --git a/src/tests/Makefile b/src/tests/Makefile new file mode 120000 index 00000000..cd2a5c9a --- /dev/null +++ b/src/tests/Makefile @@ -0,0 +1 @@ +../polyp/Makefile \ No newline at end of file -- cgit From 22c8cebb858012e4e9c551bb54456237e7597697 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Feb 2006 22:43:59 +0000 Subject: drop polyplib- prefix from client library files git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@492 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/pacat-simple.c | 4 ++-- src/tests/parec-simple.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/tests') diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c index 8b3a7b22..0382ec06 100644 --- a/src/tests/pacat-simple.c +++ b/src/tests/pacat-simple.c @@ -28,8 +28,8 @@ #include #include -#include -#include +#include +#include #include #define BUFSIZE 1024 diff --git a/src/tests/parec-simple.c b/src/tests/parec-simple.c index 10eaea8d..fc2314ac 100644 --- a/src/tests/parec-simple.c +++ b/src/tests/parec-simple.c @@ -28,8 +28,8 @@ #include #include -#include -#include +#include +#include #include #define BUFSIZE 1024 -- cgit From 5eda18bf608a325c136a450e58fa154eb0b270f4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 17 Feb 2006 12:10:58 +0000 Subject: Cleaned up the includes after the restructuring. Indicate which headers are public and which are internal through <> vs "". git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@500 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/cpulimit-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/cpulimit-test.c b/src/tests/cpulimit-test.c index 97a8a0dd..b51014c8 100644 --- a/src/tests/cpulimit-test.c +++ b/src/tests/cpulimit-test.c @@ -29,7 +29,6 @@ #include #include -#include "../daemon/cpulimit.h" #include #include @@ -37,6 +36,8 @@ #include #endif +#include "../daemon/cpulimit.h" + /* A simple example for testing the cpulimit subsystem */ static time_t start; -- cgit 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 ++++++++++++++++++++++++++++++++++ src/tests/sync-playback.c | 192 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 339 insertions(+) create mode 100644 src/tests/memblockq-test.c create mode 100644 src/tests/sync-playback.c (limited to 'src/tests') 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; +} diff --git a/src/tests/sync-playback.c b/src/tests/sync-playback.c new file mode 100644 index 00000000..5df790c9 --- /dev/null +++ b/src/tests/sync-playback.c @@ -0,0 +1,192 @@ +/* $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 +#include +#include +#include +#include + +#include +#include + +#define NSTREAMS 4 +#define SINE_HZ 440 +#define SAMPLE_HZ 8000 + +static pa_context *context = NULL; +static pa_stream *streams[NSTREAMS]; +static pa_mainloop_api *mainloop_api = NULL; + +static float data[SAMPLE_HZ]; /* one second space */ + +static int n_streams_ready = 0; + +static const pa_sample_spec sample_spec = { + .format = PA_SAMPLE_FLOAT32, + .rate = SAMPLE_HZ, + .channels = 1 +}; + +static const pa_buffer_attr buffer_attr = { + .maxlength = SAMPLE_HZ*sizeof(float)*NSTREAMS, /* exactly space for the entire play time */ + .tlength = 0, + .prebuf = 0, /* Setting prebuf to 0 guarantees us the the streams will run synchronously, no matter what */ + .minreq = 0 +}; + +static void nop_free_cb(void *p) {} + +static void underflow_cb(struct pa_stream *s, void *userdata) { + int i = (int) userdata; + + fprintf(stderr, "Stream %i finished\n", i); + + if (++n_streams_ready >= 2*NSTREAMS) { + fprintf(stderr, "We're done\n"); + mainloop_api->quit(mainloop_api, 0); + } +} + +/* This routine is called whenever the stream state changes */ +static void stream_state_callback(pa_stream *s, void *userdata) { + assert(s); + + switch (pa_stream_get_state(s)) { + case PA_STREAM_UNCONNECTED: + case PA_STREAM_CREATING: + case PA_STREAM_TERMINATED: + break; + + case PA_STREAM_READY: { + + int r, i = (int) userdata; + + fprintf(stderr, "Writing data to stream %i.\n", i); + + r = pa_stream_write(s, data, sizeof(data), nop_free_cb, sizeof(data) * i, PA_SEEK_ABSOLUTE); + assert(r == 0); + + /* Be notified when this stream is drained */ + pa_stream_set_underflow_callback(s, underflow_cb, userdata); + + /* All streams have been set up, let's go! */ + if (++n_streams_ready >= NSTREAMS) { + fprintf(stderr, "Uncorking\n"); + pa_operation_unref(pa_stream_cork(s, 0, NULL, NULL)); + } + + break; + } + + default: + case PA_STREAM_FAILED: + fprintf(stderr, "Stream error: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s)))); + abort(); + } +} + +/* This is called whenever the context status changes */ +static void context_state_callback(pa_context *c, void *userdata) { + assert(c); + + switch (pa_context_get_state(c)) { + case PA_CONTEXT_CONNECTING: + case PA_CONTEXT_AUTHORIZING: + case PA_CONTEXT_SETTING_NAME: + break; + + case PA_CONTEXT_READY: { + + int i; + fprintf(stderr, "Connection established.\n"); + + for (i = 0; i < NSTREAMS; i++) { + char name[64]; + + fprintf(stderr, "Creating stream %i\n", i); + + snprintf(name, sizeof(name), "stream #%i", i); + + streams[i] = pa_stream_new(c, name, &sample_spec, NULL); + assert(streams[i]); + pa_stream_set_state_callback(streams[i], stream_state_callback, (void*) i); + pa_stream_connect_playback(streams[i], NULL, &buffer_attr, PA_STREAM_START_CORKED, NULL, i == 0 ? NULL : streams[0]); + } + + break; + } + + case PA_CONTEXT_TERMINATED: + mainloop_api->quit(mainloop_api, 0); + break; + + case PA_CONTEXT_FAILED: + default: + fprintf(stderr, "Context error: %s\n", pa_strerror(pa_context_errno(c))); + abort(); + } +} + +int main(int argc, char *argv[]) { + pa_mainloop* m = NULL; + int i, ret = 0; + + for (i = 0; i < SAMPLE_HZ; i++) + data[i] = (float) sin(((double) i/SAMPLE_HZ)*2*M_PI*SINE_HZ)/2; + + for (i = 0; i < NSTREAMS; i++) + streams[i] = NULL; + + /* Set up a new main loop */ + m = pa_mainloop_new(); + assert(m); + + mainloop_api = pa_mainloop_get_api(m); + + context = pa_context_new(mainloop_api, argv[0]); + assert(context); + + pa_context_set_state_callback(context, context_state_callback, NULL); + + pa_context_connect(context, NULL, 1, NULL); + + if (pa_mainloop_run(m, &ret) < 0) + fprintf(stderr, "pa_mainloop_run() failed.\n"); + + pa_context_unref(context); + + for (i = 0; i < NSTREAMS; i++) + if (streams[i]) + pa_stream_unref(streams[i]); + + pa_mainloop_free(m); + + return ret; +} -- 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') 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 0858ef9bed00bf9cd14062e3980e495a01dafa66 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 20 Feb 2006 23:30:53 +0000 Subject: fix yet another pa_context_connect() occurance with regards to the flags parameter git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@535 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/sync-playback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/sync-playback.c b/src/tests/sync-playback.c index 5df790c9..4ac65c2f 100644 --- a/src/tests/sync-playback.c +++ b/src/tests/sync-playback.c @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) { pa_context_set_state_callback(context, context_state_callback, NULL); - pa_context_connect(context, NULL, 1, NULL); + pa_context_connect(context, NULL, 0, NULL); if (pa_mainloop_run(m, &ret) < 0) fprintf(stderr, "pa_mainloop_run() failed.\n"); -- cgit From 1bb14c3a1df2a9114a892df9bff10b6a2efc3388 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 27 Feb 2006 09:09:15 +0000 Subject: 64-bit fixes. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@611 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/sync-playback.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tests') diff --git a/src/tests/sync-playback.c b/src/tests/sync-playback.c index 4ac65c2f..d675e01c 100644 --- a/src/tests/sync-playback.c +++ b/src/tests/sync-playback.c @@ -64,7 +64,7 @@ static const pa_buffer_attr buffer_attr = { static void nop_free_cb(void *p) {} static void underflow_cb(struct pa_stream *s, void *userdata) { - int i = (int) userdata; + int i = (int) (long) userdata; fprintf(stderr, "Stream %i finished\n", i); @@ -86,7 +86,7 @@ static void stream_state_callback(pa_stream *s, void *userdata) { case PA_STREAM_READY: { - int r, i = (int) userdata; + int r, i = (int) (long) userdata; fprintf(stderr, "Writing data to stream %i.\n", i); @@ -136,7 +136,7 @@ static void context_state_callback(pa_context *c, void *userdata) { streams[i] = pa_stream_new(c, name, &sample_spec, NULL); assert(streams[i]); - pa_stream_set_state_callback(streams[i], stream_state_callback, (void*) i); + pa_stream_set_state_callback(streams[i], stream_state_callback, (void*) (long) i); pa_stream_connect_playback(streams[i], NULL, &buffer_attr, PA_STREAM_START_CORKED, NULL, i == 0 ? NULL : streams[0]); } -- cgit From 45baa6958edccddd7264b11b8d48b5aec69418bf Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Sat, 4 Mar 2006 17:31:23 +0000 Subject: Fix warning caused by missing return in main(). git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@624 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/mcalign-test.c | 2 ++ src/tests/voltest.c | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src/tests') diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index 861c38c1..eab5dc88 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -93,4 +93,6 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { if (c.memblock) pa_memblock_unref(c.memblock); + + return 0; } diff --git a/src/tests/voltest.c b/src/tests/voltest.c index 58f1da00..4db8ef28 100644 --- a/src/tests/voltest.c +++ b/src/tests/voltest.c @@ -17,4 +17,6 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { v, (v*100)/PA_VOLUME_NORM, dB, f, pa_sw_volume_from_dB(dB), pa_sw_volume_from_linear(f)); } + + return 0; } -- cgit From acb96c96fde93dcd87c6509e7c64b403caa44f30 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 31 Mar 2006 08:54:24 +0000 Subject: Fix some warnings caused by size_t having varying size. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@641 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/mcalign-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index eab5dc88..2728def2 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -67,7 +67,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { c.length = r; pa_mcalign_push(a, &c); - fprintf(stderr, "Read %d bytes\n", r); + fprintf(stderr, "Read %ld bytes\n", (long)r); c.index += r; -- cgit From 5f7cc0c870ebe77dd457209503f75d65b35b8014 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 26 Apr 2006 14:34:45 +0000 Subject: add new test 'channelmap-test' git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@800 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/channelmap-test.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/tests/channelmap-test.c (limited to 'src/tests') diff --git a/src/tests/channelmap-test.c b/src/tests/channelmap-test.c new file mode 100644 index 00000000..522c136f --- /dev/null +++ b/src/tests/channelmap-test.c @@ -0,0 +1,25 @@ +/* $Id$ */ + +#include +#include + +#include +#include + +int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { + char cm[PA_CHANNEL_MAP_SNPRINT_MAX]; + pa_channel_map map, map2; + + pa_channel_map_init_auto(&map, 5); + + fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map)); + + pa_channel_map_parse(&map2, cm); + + assert(pa_channel_map_equal(&map, &map2)); + + pa_channel_map_parse(&map2, "left,test"); + + + return 0; +} -- cgit From 9e60bad5c3cb938b250e04e2048fdc46353c5719 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 30 Apr 2006 23:34:17 +0000 Subject: add new threaded main loop implementation (with test/example) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@823 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/thread-mainloop-test.c | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/tests/thread-mainloop-test.c (limited to 'src/tests') diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c new file mode 100644 index 00000000..8232c4a3 --- /dev/null +++ b/src/tests/thread-mainloop-test.c @@ -0,0 +1,73 @@ +/* $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 +#include +#include + +static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { + fprintf(stderr, "TIME EVENT\n"); + pa_threaded_mainloop_signal(userdata); +} + +int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { + pa_mainloop_api *a; + pa_threaded_mainloop *m; + struct timeval tv; + + m = pa_threaded_mainloop_new(); + assert(m); + a = pa_threaded_mainloop_get_api(m); + assert(a); + + pa_threaded_mainloop_start(m); + + pa_threaded_mainloop_lock(m); + + pa_gettimeofday(&tv); + tv.tv_sec += 5; + a->time_new(a, &tv, tcb, m); + + fprintf(stderr, "waiting 5s (signal)\n"); + pa_threaded_mainloop_wait(m); + fprintf(stderr, "wait completed\n"); + + pa_threaded_mainloop_unlock(m); + + fprintf(stderr, "waiting 5s (sleep)\n"); + sleep(5); + + fprintf(stderr, "shutting down\n"); + + pa_threaded_mainloop_stop(m); + + pa_threaded_mainloop_free(m); + return 0; +} -- cgit From 5f9bbf005a81a0f7d009e3fad3f6a4e8d4c5e6bb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 6 May 2006 20:56:43 +0000 Subject: add support for reading audio data from a file instead of plain STDIN in pacat-simple.c git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@830 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/pacat-simple.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/tests') diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c index 0382ec06..6a75c790 100644 --- a/src/tests/pacat-simple.c +++ b/src/tests/pacat-simple.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,23 @@ int main(PA_GCC_UNUSED int argc, char*argv[]) { int ret = 1; int error; + /* replace STDIN with the specified file if needed */ + if (argc > 1) { + int fd; + + if ((fd = open(argv[1], O_RDONLY)) < 0) { + fprintf(stderr, __FILE__": open() failed: %s\n", strerror(errno)); + goto finish; + } + + if (dup2(fd, STDIN_FILENO) < 0) { + fprintf(stderr, __FILE__": dup2() failed: %s\n", strerror(errno)); + goto finish; + } + + close(fd); + } + /* Create a new playback stream */ if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); -- cgit From 4b4c8fd15293a332d3200f70d2244b0c1ed80874 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 6 May 2006 20:58:02 +0000 Subject: * optionally, make pa_threaded_mainloop_signal() wait until the main thread took over control * more header file comments git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@831 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/thread-mainloop-test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/tests') diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 8232c4a3..24e18b37 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -33,8 +33,9 @@ #include static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { - fprintf(stderr, "TIME EVENT\n"); - pa_threaded_mainloop_signal(userdata); + fprintf(stderr, "TIME EVENT START\n"); + pa_threaded_mainloop_signal(userdata, 1); + fprintf(stderr, "TIME EVENT END\n"); } int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { -- cgit From 06e1867307777ffa8686762ff3e42143d88b46ed Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 9 May 2006 08:38:37 +0000 Subject: Use pa_msleep() to get platform independence. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@833 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/thread-mainloop-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 24e18b37..1434deb9 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -63,7 +63,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { pa_threaded_mainloop_unlock(m); fprintf(stderr, "waiting 5s (sleep)\n"); - sleep(5); + pa_msleep(5000); fprintf(stderr, "shutting down\n"); -- cgit From e929aabc032ee91705acc8571f09affe41e297ae Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 11 May 2006 13:01:24 +0000 Subject: split of signal releasing into its own function and name it pa_threaded_mainloop_accept() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@844 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/thread-mainloop-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 1434deb9..8ca3f92f 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -59,7 +59,9 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { fprintf(stderr, "waiting 5s (signal)\n"); pa_threaded_mainloop_wait(m); fprintf(stderr, "wait completed\n"); - + pa_threaded_mainloop_accept(m); + fprintf(stderr, "signal accepted\n"); + pa_threaded_mainloop_unlock(m); fprintf(stderr, "waiting 5s (sleep)\n"); -- cgit From 53595938d003411e6992e10b6a5c5e51b2a15d4f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 May 2006 00:46:03 +0000 Subject: add new test programme utf8-test.c git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@880 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/utf8-test.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/tests/utf8-test.c (limited to 'src/tests') diff --git a/src/tests/utf8-test.c b/src/tests/utf8-test.c new file mode 100644 index 00000000..c8b2fabb --- /dev/null +++ b/src/tests/utf8-test.c @@ -0,0 +1,26 @@ +/* $Id$ */ + +#include +#include + +#include +#include + +int main(int argc, char *argv[]) { + char *c; + + assert(pa_utf8_valid("hallo")); + assert(pa_utf8_valid("hallo\n")); + assert(!pa_utf8_valid("hüpfburg\n")); + assert(pa_utf8_valid("hallo\n")); + assert(pa_utf8_valid("hüpfburg\n")); + + printf("LATIN1: %s\n", c = pa_utf8_filter("hüpfburg")); + pa_xfree(c); + printf("UTF8: %sx\n", c = pa_utf8_filter("hüpfburg")); + pa_xfree(c); + printf("LATIN1: %sx\n", c = pa_utf8_filter("üxknärzmörzeltörszß³§dsjkfh")); + pa_xfree(c); + + return 0; +} -- cgit From 4b6ab291a787ff597c938842b569a35434ab11d8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 May 2006 23:47:38 +0000 Subject: * modify pa_channel_map_init_auto() to take an extra argument specifying the standard to use (ALSA, AIFF, ...) * add some more validity checks to pa_source_new(),pa_sink_new(),pa_sink_input_new(),pa_source_output_new() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@888 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/channelmap-test.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/channelmap-test.c b/src/tests/channelmap-test.c index 522c136f..c6644229 100644 --- a/src/tests/channelmap-test.c +++ b/src/tests/channelmap-test.c @@ -10,10 +10,18 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { char cm[PA_CHANNEL_MAP_SNPRINT_MAX]; pa_channel_map map, map2; - pa_channel_map_init_auto(&map, 5); + pa_channel_map_init_auto(&map, 6, PA_CHANNEL_MAP_AIFF); fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map)); + pa_channel_map_init_auto(&map, 6, PA_CHANNEL_MAP_AUX); + + fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map)); + + pa_channel_map_init_auto(&map, 6, PA_CHANNEL_MAP_ALSA); + + fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map)); + pa_channel_map_parse(&map2, cm); assert(pa_channel_map_equal(&map, &map2)); -- cgit From d9cc2cfcb97c1b0449bcbfb6ab0301a58d77bd55 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 17 May 2006 16:34:18 +0000 Subject: Move xmalloc to the public side (libpolyp). git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@908 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/strlist-test.c | 2 +- src/tests/utf8-test.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tests') diff --git a/src/tests/strlist-test.c b/src/tests/strlist-test.c index 14543112..415c94e6 100644 --- a/src/tests/strlist-test.c +++ b/src/tests/strlist-test.c @@ -1,7 +1,7 @@ #include +#include #include -#include #include int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char* argv[]) { diff --git a/src/tests/utf8-test.c b/src/tests/utf8-test.c index c8b2fabb..57f445c7 100644 --- a/src/tests/utf8-test.c +++ b/src/tests/utf8-test.c @@ -3,8 +3,8 @@ #include #include +#include #include -#include int main(int argc, char *argv[]) { char *c; -- cgit From 7ca25e58e99abb3d640b6012d7cbfc9bc9087849 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 17 May 2006 17:30:49 +0000 Subject: Move utf8 to the public part (libpolyp). git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@909 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/utf8-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/utf8-test.c b/src/tests/utf8-test.c index 57f445c7..2c21613e 100644 --- a/src/tests/utf8-test.c +++ b/src/tests/utf8-test.c @@ -3,8 +3,8 @@ #include #include +#include #include -#include int main(int argc, char *argv[]) { char *c; -- cgit From ee35a063b2c10564d43a611fcf6ada398851b1d6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 18:52:34 +0000 Subject: add new channel map argument to pa_simple_new() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@911 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/pacat-simple.c | 2 +- src/tests/parec-simple.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tests') diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c index 6a75c790..544c31e3 100644 --- a/src/tests/pacat-simple.c +++ b/src/tests/pacat-simple.c @@ -66,7 +66,7 @@ int main(PA_GCC_UNUSED int argc, char*argv[]) { } /* Create a new playback stream */ - if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, &error))) { + if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); goto finish; } diff --git a/src/tests/parec-simple.c b/src/tests/parec-simple.c index fc2314ac..4463d549 100644 --- a/src/tests/parec-simple.c +++ b/src/tests/parec-simple.c @@ -67,7 +67,7 @@ int main(PA_GCC_UNUSED int argc, char*argv[]) { int error; /* Create the recording stream */ - if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, &error))) { + if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); goto finish; } -- cgit From 53a285e75616281bcdd8b1dcf0e3b7ba59257516 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 20:44:55 +0000 Subject: fix include line for "core-util.h" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@923 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/mainloop-test.c | 2 +- src/tests/mcalign-test.c | 2 +- src/tests/thread-mainloop-test.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tests') diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c index f62c9693..30088483 100644 --- a/src/tests/mainloop-test.c +++ b/src/tests/mainloop-test.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include #ifdef GLIB_MAIN_LOOP diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index 2728def2..765dcf94 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 8ca3f92f..676b8d37 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -29,7 +29,7 @@ #include #include -#include +#include #include static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { -- cgit From 0796ead0db250f6a46a7531c9db471592ed6e129 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 18 May 2006 06:45:43 +0000 Subject: Move timeval calculation functions into their own file. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@926 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/mainloop-test.c | 2 ++ src/tests/thread-mainloop-test.c | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src/tests') diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c index 30088483..2936420c 100644 --- a/src/tests/mainloop-test.c +++ b/src/tests/mainloop-test.c @@ -28,6 +28,8 @@ #include #include +#include + #include #include diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 676b8d37..70144431 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -28,6 +28,8 @@ #include #include +#include + #include #include #include -- cgit From 24a781992bad4d66bb7bc3a2d1deeba7e959dbb1 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 18 May 2006 07:04:41 +0000 Subject: Don't include util.h from core-util.h as it is not needed by many users. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@929 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/thread-mainloop-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 70144431..aef3aff0 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -29,9 +29,9 @@ #include #include +#include #include -#include #include static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { -- cgit From cc61b57a325ee688b74ca2cbd5e281e7f76b71c0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 20 May 2006 14:59:02 +0000 Subject: rename pa_simple_get_playback_latency() to pa_simple_get_latency() and allow its usage on capture streams git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@939 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/pacat-simple.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tests') diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c index 544c31e3..9d8cc921 100644 --- a/src/tests/pacat-simple.c +++ b/src/tests/pacat-simple.c @@ -78,8 +78,8 @@ int main(PA_GCC_UNUSED int argc, char*argv[]) { #if 0 pa_usec_t latency; - if ((latency = pa_simple_get_playback_latency(s, &error)) == (pa_usec_t) -1) { - fprintf(stderr, __FILE__": pa_simple_get_playback_latency() failed: %s\n", pa_strerror(error)); + if ((latency = pa_simple_get_latency(s, &error)) == (pa_usec_t) -1) { + fprintf(stderr, __FILE__": pa_simple_get_latency() failed: %s\n", pa_strerror(error)); goto finish; } -- cgit From 9f59b4e1cd516dbbc8a4978146bc94f2a1ce75eb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 11:27:00 +0000 Subject: add new test "interpol-test" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1027 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/tests/interpol-test.c (limited to 'src/tests') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c new file mode 100644 index 00000000..26a92dbf --- /dev/null +++ b/src/tests/interpol-test.c @@ -0,0 +1,168 @@ +/* $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 +#include +#include +#include +#include +#include + +#include +#include + +static pa_context *context = NULL; +static pa_stream *stream = NULL; +static pa_mainloop_api *mainloop_api = NULL; + +static void stream_write_cb(pa_stream *p, size_t length, void *userdata) { + + /* Just some silence */ + pa_stream_write(p, pa_xmalloc0(length), length, pa_xfree, 0, PA_SEEK_RELATIVE); +} + +/* This is called whenever the context status changes */ +static void context_state_callback(pa_context *c, void *userdata) { + assert(c); + + switch (pa_context_get_state(c)) { + case PA_CONTEXT_CONNECTING: + case PA_CONTEXT_AUTHORIZING: + case PA_CONTEXT_SETTING_NAME: + break; + + case PA_CONTEXT_READY: { + + static const pa_sample_spec ss = { + .format = PA_SAMPLE_S16LE, + .rate = 44100, + .channels = 1 + }; + + fprintf(stderr, "Connection established.\n"); + + stream = pa_stream_new(c, "interpol-test", &ss, NULL); + assert(stream); + + pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL); + pa_stream_set_write_callback(stream, stream_write_cb, NULL); + + break; + } + + case PA_CONTEXT_TERMINATED: + break; + + case PA_CONTEXT_FAILED: + default: + fprintf(stderr, "Context error: %s\n", pa_strerror(pa_context_errno(c))); + abort(); + } +} + +int main(int argc, char *argv[]) { + pa_threaded_mainloop* m = NULL; + int k, r; + struct timeval start, last_info = { 0, 0 }; + pa_usec_t old_t = 0, old_rtc = 0; + + /* Set up a new main loop */ + m = pa_threaded_mainloop_new(); + assert(m); + + mainloop_api = pa_threaded_mainloop_get_api(m); + + context = pa_context_new(mainloop_api, argv[0]); + assert(context); + + pa_context_set_state_callback(context, context_state_callback, NULL); + + r = pa_context_connect(context, NULL, 0, NULL); + assert(r >= 0); + + pa_gettimeofday(&start); + + pa_threaded_mainloop_start(m); + + for (k = 0; k < 5000; k++) { + int success = 0, changed = 0; + pa_usec_t t, rtc; + struct timeval now, tv; + + pa_threaded_mainloop_lock(m); + + if (stream) { + const pa_timing_info *info; + + if (pa_stream_get_time(stream, &t) >= 0) + success = 1; + + if ((info = pa_stream_get_timing_info(stream))) + if (last_info.tv_usec != info->timestamp.tv_usec || last_info.tv_sec != info->timestamp.tv_sec) { + changed = 1; + last_info = info->timestamp; + } + } + + pa_threaded_mainloop_unlock(m); + + if (success) { + pa_gettimeofday(&now); + + rtc = pa_timeval_diff(&now, &start); + printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, rtc, t, rtc-old_rtc, t-old_t, changed*2000000); + old_t = t; + old_rtc = rtc; + } + + /* Spin loop, eerks but normal usleep is just to badly grained */ + + tv = now; + while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) + pthread_yield(); + } + + if (m) + pa_threaded_mainloop_stop(m); + + if (stream) { + pa_stream_disconnect(stream); + pa_stream_unref(stream); + } + + if (context) { + pa_context_disconnect(context); + pa_context_unref(context); + } + + if (m) + pa_threaded_mainloop_free(m); + + return 0; +} -- cgit From 6eabab6e2b093933bf489e6c94b13433d03584d2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 12:20:10 +0000 Subject: minor cleanups git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1028 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tests') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 26a92dbf..fa5fae7d 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -136,12 +136,12 @@ int main(int argc, char *argv[]) { pa_gettimeofday(&now); rtc = pa_timeval_diff(&now, &start); - printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, rtc, t, rtc-old_rtc, t-old_t, changed*2000000); + printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, rtc, t, rtc-old_rtc, t-old_t, changed); old_t = t; old_rtc = rtc; } - /* Spin loop, eerks but normal usleep is just to badly grained */ + /* Spin loop, ugly but normal usleep() is just too badly grained */ tv = now; while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) -- 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/Makefile | 2 +- src/tests/channelmap-test.c | 4 ++-- src/tests/cpulimit-test.c | 14 +++++++------- src/tests/interpol-test.c | 12 ++++++------ src/tests/mainloop-test.c | 18 +++++++++--------- src/tests/mcalign-test.c | 14 +++++++------- src/tests/memblockq-test.c | 12 ++++++------ src/tests/pacat-simple.c | 14 +++++++------- src/tests/parec-simple.c | 14 +++++++------- src/tests/strlist-test.c | 6 +++--- src/tests/sync-playback.c | 12 ++++++------ src/tests/thread-mainloop-test.c | 16 ++++++++-------- src/tests/utf8-test.c | 4 ++-- src/tests/voltest.c | 4 ++-- 14 files changed, 73 insertions(+), 73 deletions(-) (limited to 'src/tests') diff --git a/src/tests/Makefile b/src/tests/Makefile index cd2a5c9a..c110232d 120000 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -1 +1 @@ -../polyp/Makefile \ No newline at end of file +../pulse/Makefile \ No newline at end of file diff --git a/src/tests/channelmap-test.c b/src/tests/channelmap-test.c index c6644229..124ce576 100644 --- a/src/tests/channelmap-test.c +++ b/src/tests/channelmap-test.c @@ -3,8 +3,8 @@ #include #include -#include -#include +#include +#include int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { char cm[PA_CHANNEL_MAP_SNPRINT_MAX]; diff --git a/src/tests/cpulimit-test.c b/src/tests/cpulimit-test.c index b51014c8..2302a26d 100644 --- a/src/tests/cpulimit-test.c +++ b/src/tests/cpulimit-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 + License along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -29,11 +29,11 @@ #include #include -#include -#include +#include +#include #ifdef TEST2 -#include +#include #endif #include "../daemon/cpulimit.h" diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index fa5fae7d..7cabc1c9 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-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. ***/ @@ -34,8 +34,8 @@ #include #include -#include -#include +#include +#include static pa_context *context = NULL; static pa_stream *stream = NULL; diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c index 2936420c..671adeff 100644 --- a/src/tests/mainloop-test.c +++ b/src/tests/mainloop-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. ***/ @@ -28,15 +28,15 @@ #include #include -#include +#include -#include -#include +#include +#include #ifdef GLIB_MAIN_LOOP #include -#include +#include static GMainLoop* glib_main_loop = NULL; @@ -48,7 +48,7 @@ static GMainLoop* glib_main_loop = NULL; #else /* GLIB_MAIN_LOOP */ -#include +#include #endif /* GLIB_MAIN_LOOP */ static pa_defer_event *de; diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index 765dcf94..ccb0613e 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-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.1 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 Lesser 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 + License along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -31,9 +31,9 @@ #include #include -#include -#include -#include +#include +#include +#include /* A simple program for testing pa_mcalign */ 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; diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c index 9d8cc921..364e1ad6 100644 --- a/src/tests/pacat-simple.c +++ b/src/tests/pacat-simple.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. ***/ @@ -29,9 +29,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define BUFSIZE 1024 diff --git a/src/tests/parec-simple.c b/src/tests/parec-simple.c index 4463d549..45a52288 100644 --- a/src/tests/parec-simple.c +++ b/src/tests/parec-simple.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. ***/ @@ -28,9 +28,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define BUFSIZE 1024 diff --git a/src/tests/strlist-test.c b/src/tests/strlist-test.c index 415c94e6..4262a001 100644 --- a/src/tests/strlist-test.c +++ b/src/tests/strlist-test.c @@ -1,8 +1,8 @@ #include -#include -#include -#include +#include +#include +#include int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char* argv[]) { char *t, *u; diff --git a/src/tests/sync-playback.c b/src/tests/sync-playback.c index d675e01c..39c6aac4 100644 --- a/src/tests/sync-playback.c +++ b/src/tests/sync-playback.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. ***/ @@ -33,8 +33,8 @@ #include #include -#include -#include +#include +#include #define NSTREAMS 4 #define SINE_HZ 440 diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index aef3aff0..bf3d4cd2 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-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. ***/ @@ -28,11 +28,11 @@ #include #include -#include -#include +#include +#include -#include -#include +#include +#include static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { fprintf(stderr, "TIME EVENT START\n"); diff --git a/src/tests/utf8-test.c b/src/tests/utf8-test.c index 2c21613e..2e9f128a 100644 --- a/src/tests/utf8-test.c +++ b/src/tests/utf8-test.c @@ -3,8 +3,8 @@ #include #include -#include -#include +#include +#include int main(int argc, char *argv[]) { char *c; diff --git a/src/tests/voltest.c b/src/tests/voltest.c index 4db8ef28..3de884af 100644 --- a/src/tests/voltest.c +++ b/src/tests/voltest.c @@ -2,8 +2,8 @@ #include -#include -#include +#include +#include int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { pa_volume_t v; -- cgit From 6ca46f4d7a9fa57b949e2286d3af1b6e78dce8f5 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 20 Jun 2006 13:49:30 +0000 Subject: Make interpol-test build on Win32 and non-pthread systems. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1043 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/tests') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 7cabc1c9..bf7f582c 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -32,7 +32,10 @@ #include #include #include + +#ifdef HAVE_PTHREAD #include +#endif #include #include @@ -145,7 +148,13 @@ int main(int argc, char *argv[]) { tv = now; while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) +#ifdef HAVE_PTHREAD pthread_yield(); +#elif defined(OS_IS_WIN32) + Sleep(0); +#else + ; +#endif } if (m) -- cgit From 1342999b5197adeb76ee9feb41f38dba26a20dbe Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 20 Jun 2006 14:26:52 +0000 Subject: Make sure we do not use pthread_yield() on platforms that do not have them. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1045 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index bf7f582c..2df65a45 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -148,7 +148,7 @@ int main(int argc, char *argv[]) { tv = now; while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) -#ifdef HAVE_PTHREAD +#ifdef HAVE_PTHREAD_YIELD pthread_yield(); #elif defined(OS_IS_WIN32) Sleep(0); -- cgit From 883ce83f92c408c77bf1a50952893ee5af3f0acc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 14 Jul 2006 00:19:09 +0000 Subject: add new test get-binary-name-test for testing pa_get_binary_name() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1079 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/get-binary-name-test.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/tests/get-binary-name-test.c (limited to 'src/tests') diff --git a/src/tests/get-binary-name-test.c b/src/tests/get-binary-name-test.c new file mode 100644 index 00000000..0cea2b6d --- /dev/null +++ b/src/tests/get-binary-name-test.c @@ -0,0 +1,36 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include + +int main(int argc, char *argv[]) { + char exename[PATH_MAX]; + + printf("%s\n", pa_get_binary_name(exename, sizeof(exename))); + return 0; +} -- cgit From 860be2e70b33ff5eeb9130f80c4b1c096a2a8f27 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 14 Jul 2006 22:42:01 +0000 Subject: try to use send(,,MSG_NOSIGNAL) instead of write() wherever possible (which will allow us to drop the SIGPIPE check). Cache the results of the last write()/send() to make sure that we do not issue more than necessary system calls. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1083 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/mcalign-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index ccb0613e..7a68e6de 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -82,7 +82,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { if (pa_mcalign_pop(a, &t) < 0) break; - pa_loop_write(STDOUT_FILENO, (uint8_t*) t.memblock->data + t.index, t.length); + pa_loop_write(STDOUT_FILENO, (uint8_t*) t.memblock->data + t.index, t.length, NULL); fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length); pa_memblock_unref(t.memblock); -- cgit From 9db70682d68cc4fef9314677b6427582e5d5c8f2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Jul 2006 19:53:29 +0000 Subject: remove glib 1.2 adapter. It started to bitrot and wasn't used by anything anyway. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1104 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/mainloop-test.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'src/tests') diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c index 671adeff..b06d0ed1 100644 --- a/src/tests/mainloop-test.c +++ b/src/tests/mainloop-test.c @@ -40,13 +40,6 @@ static GMainLoop* glib_main_loop = NULL; -#if GLIB_MAJOR_VERSION >= 2 -#define GLIB20 -#else -#undef GLIB20 -#endif - - #else /* GLIB_MAIN_LOOP */ #include #endif /* GLIB_MAIN_LOOP */ @@ -68,10 +61,8 @@ static void dcb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) { static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { fprintf(stderr, "TIME EVENT\n"); -#if defined(GLIB_MAIN_LOOP) && defined(GLIB20) +#if defined(GLIB_MAIN_LOOP) g_main_loop_quit(glib_main_loop); -#elif defined(GLIB_MAIN_LOOP) - g_main_quit(glib_main_loop); #else a->quit(a, 0); #endif @@ -86,17 +77,10 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { #ifdef GLIB_MAIN_LOOP pa_glib_mainloop *g; -#ifdef GLIB20 glib_main_loop = g_main_loop_new(NULL, FALSE); assert(glib_main_loop); g = pa_glib_mainloop_new(NULL); -#else /* GLIB20 */ - glib_main_loop = g_main_new(FALSE); - assert(glib_main_loop); - - g = pa_glib_mainloop_new(); -#endif /* GLIB20 */ assert(g); a = pa_glib_mainloop_get_api(g); @@ -121,10 +105,8 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { tv.tv_sec += 10; te = a->time_new(a, &tv, tcb, NULL); -#if defined(GLIB_MAIN_LOOP) && defined(GLIB20) +#if defined(GLIB_MAIN_LOOP) g_main_loop_run(glib_main_loop); -#elif defined(GLIB_MAIN_LOOP) - g_main_run(glib_main_loop); #else pa_mainloop_run(m, NULL); #endif @@ -135,11 +117,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { #ifdef GLIB_MAIN_LOOP pa_glib_mainloop_free(g); -#ifdef GLIB20 g_main_loop_unref(glib_main_loop); -#else - g_main_destroy(glib_main_loop); -#endif #else pa_mainloop_free(m); #endif -- cgit From 30ada90fd2bce05097a85da86a10ffb52c2ffd35 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 20 Jul 2006 16:48:26 +0000 Subject: add IP address ACL subsystem git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1123 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/ipacl-test.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/tests/ipacl-test.c (limited to 'src/tests') diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c new file mode 100644 index 00000000..b98151ee --- /dev/null +++ b/src/tests/ipacl-test.c @@ -0,0 +1,117 @@ +/* $Id$ */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +int main(int argc, char *argv[]) { + struct sockaddr_in sa; + struct sockaddr_in6 sa6; + int fd; + int r; + pa_ip_acl *acl; + + fd = socket(PF_INET, SOCK_STREAM, 0); + assert(fd >= 0); + + sa.sin_family = AF_INET; + sa.sin_port = htons(22); + sa.sin_addr.s_addr = inet_addr("127.0.0.1"); + + r = connect(fd, (struct sockaddr*) &sa, sizeof(sa)); + assert(r >= 0); + + acl = pa_ip_acl_new("127.0.0.1"); + assert(acl); + printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("127.0.0.2/0"); + assert(acl); + printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("127.0.0.1/32"); + assert(acl); + printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("127.0.0.1/7"); + assert(acl); + printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("127.0.0.2"); + assert(acl); + printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("127.0.0.0/8;0.0.0.0/32"); + assert(acl); + printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("128.0.0.2/9"); + assert(acl); + printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("::1/9"); + assert(acl); + printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + close(fd); + + fd = socket(PF_INET6, SOCK_STREAM, 0); + assert(fd >= 0); + + memset(&sa6, 0, sizeof(sa6)); + sa6.sin6_family = AF_INET6; + sa6.sin6_port = htons(22); + inet_pton(AF_INET6, "::1", &sa6.sin6_addr); + + r = connect(fd, (struct sockaddr*) &sa6, sizeof(sa6)); + assert(r >= 0); + + acl = pa_ip_acl_new("::1"); + assert(acl); + printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("::1/9"); + assert(acl); + printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("::/0"); + assert(acl); + printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("::2/128"); + assert(acl); + printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("::2/127"); + assert(acl); + printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + acl = pa_ip_acl_new("::2/126"); + assert(acl); + printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); + pa_ip_acl_free(acl); + + close(fd); + + return 0; +} -- cgit From 6ad1f33c3fdad0c9cbf78f722223b29fe3160ec6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 20 Jul 2006 22:58:37 +0000 Subject: even more FreeBSD portability (thanks Flameeyes, again!) git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1131 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/ipacl-test.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/tests') diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c index b98151ee..8819a6a0 100644 --- a/src/tests/ipacl-test.c +++ b/src/tests/ipacl-test.c @@ -1,7 +1,9 @@ /* $Id$ */ +#include #include #include +#include #include #include #include -- cgit From 09e01afa1fa27b5148fa8eb7dc35bfd04cc3de68 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 20 Jul 2006 23:21:57 +0000 Subject: Get ACL:s to work on Win32. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1134 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/ipacl-test.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/tests') diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c index 8819a6a0..2566b038 100644 --- a/src/tests/ipacl-test.c +++ b/src/tests/ipacl-test.c @@ -1,15 +1,32 @@ /* $Id$ */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include +#include +#include +#include +#include + +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_NETINET_IN_H #include +#endif +#ifdef HAVE_NETINET_IN_SYSTM_H #include +#endif +#ifdef HAVE_NETINET_IP_H #include -#include -#include +#endif +#ifdef HAVE_ARPA_INET_H #include -#include -#include +#endif + +#include "../pulsecore/winsock.h" #include -- cgit From 80d73dd21b0af1970ec3cedfe1490acc39f7c221 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 12 Aug 2006 23:35:44 +0000 Subject: implement typeafe hook chain git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1231 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/hook-list-test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/tests/hook-list-test.c (limited to 'src/tests') diff --git a/src/tests/hook-list-test.c b/src/tests/hook-list-test.c new file mode 100644 index 00000000..ee0b54f9 --- /dev/null +++ b/src/tests/hook-list-test.c @@ -0,0 +1,38 @@ +/* $Id$ */ + +#include +#include + +PA_HOOK_DECLARE(test, const char *, const char*); +PA_HOOK_IMPLEMENT(test, const char *, const char *); + +static pa_hook_result_t func1(const char*a, const char*b, void *userdata) { + pa_log("#1 a=%s b=%s userdata=%s", a, b, (char*) userdata); + return PA_HOOK_OK; +} + +static pa_hook_result_t func2(const char*a, const char*b, void *userdata) { + pa_log("#2 a=%s b=%s userdata=%s", a, b, (char*) userdata); + return PA_HOOK_OK; +} + +int main(int argc, char *argv[]) { + void *u; + + PA_HOOK_HEAD(test, test); + + PA_HOOK_HEAD_INIT(test, test); + + PA_HOOK_APPEND(test, test, func1, (void*) "1-1"); + PA_HOOK_APPEND(test, test, func2, u = (void*) "2"); + PA_HOOK_APPEND(test, test, func1, (void*) "1-2"); + + + PA_HOOK_EXECUTE(test, test, "arg1", "arg2"); + + PA_HOOK_REMOVE(test, test, func2, u); + + PA_HOOK_FREE(test, test); + + return 0; +} -- cgit From 2622b0ca9eae2ffb18caed2b54b4e25325bed702 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 12 Aug 2006 23:55:48 +0000 Subject: update hook list test git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1233 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/hook-list-test.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/tests') diff --git a/src/tests/hook-list-test.c b/src/tests/hook-list-test.c index ee0b54f9..b0ea5997 100644 --- a/src/tests/hook-list-test.c +++ b/src/tests/hook-list-test.c @@ -4,7 +4,6 @@ #include PA_HOOK_DECLARE(test, const char *, const char*); -PA_HOOK_IMPLEMENT(test, const char *, const char *); static pa_hook_result_t func1(const char*a, const char*b, void *userdata) { pa_log("#1 a=%s b=%s userdata=%s", a, b, (char*) userdata); @@ -27,7 +26,6 @@ int main(int argc, char *argv[]) { PA_HOOK_APPEND(test, test, func2, u = (void*) "2"); PA_HOOK_APPEND(test, test, func1, (void*) "1-2"); - PA_HOOK_EXECUTE(test, test, "arg1", "arg2"); PA_HOOK_REMOVE(test, test, func2, u); -- cgit From 281125c72767713d6294ac7094f3bf7bde47a1e3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 13 Aug 2006 01:43:34 +0000 Subject: rework hook list stuff again, and replace macros with real functins. We loose type safety but things are much cleaner now git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1234 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/hook-list-test.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/tests') diff --git a/src/tests/hook-list-test.c b/src/tests/hook-list-test.c index b0ea5997..0d811a1e 100644 --- a/src/tests/hook-list-test.c +++ b/src/tests/hook-list-test.c @@ -3,34 +3,30 @@ #include #include -PA_HOOK_DECLARE(test, const char *, const char*); - -static pa_hook_result_t func1(const char*a, const char*b, void *userdata) { - pa_log("#1 a=%s b=%s userdata=%s", a, b, (char*) userdata); +static pa_hook_result_t func1(const char*a, void *userdata) { + pa_log("#1 arg=%s userdata=%s", a, (char*) userdata); return PA_HOOK_OK; } -static pa_hook_result_t func2(const char*a, const char*b, void *userdata) { - pa_log("#2 a=%s b=%s userdata=%s", a, b, (char*) userdata); +static pa_hook_result_t func2(const char*a, void *userdata) { + pa_log("#2 arg=%s userdata=%s", a, (char*) userdata); return PA_HOOK_OK; } int main(int argc, char *argv[]) { - void *u; - - PA_HOOK_HEAD(test, test); - - PA_HOOK_HEAD_INIT(test, test); + pa_hook hook; + pa_hook_slot *slot; - PA_HOOK_APPEND(test, test, func1, (void*) "1-1"); - PA_HOOK_APPEND(test, test, func2, u = (void*) "2"); - PA_HOOK_APPEND(test, test, func1, (void*) "1-2"); + pa_hook_init(&hook); - PA_HOOK_EXECUTE(test, test, "arg1", "arg2"); - - PA_HOOK_REMOVE(test, test, func2, u); + pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "1-1"); + slot = pa_hook_connect(&hook, (pa_hook_cb_t) func2, (void*) "2-1"); + pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "1-2"); + + pa_hook_fire(&hook, (void*) "arg2"); - PA_HOOK_FREE(test, test); + pa_hook_slot_free(slot); + pa_hook_free(&hook); return 0; } -- cgit From db3f561ec4d6fe7b6deedff45802a5efd3ba4013 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 13 Aug 2006 16:13:36 +0000 Subject: rework hook list stuff once again: change the callback prototype to recieve three data pointers: one to the data for the hook, once for the slot and once for the call git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1235 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/hook-list-test.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/tests') diff --git a/src/tests/hook-list-test.c b/src/tests/hook-list-test.c index 0d811a1e..d68d1b7d 100644 --- a/src/tests/hook-list-test.c +++ b/src/tests/hook-list-test.c @@ -3,13 +3,13 @@ #include #include -static pa_hook_result_t func1(const char*a, void *userdata) { - pa_log("#1 arg=%s userdata=%s", a, (char*) userdata); +static pa_hook_result_t func1(const char*hook_data, const char*call_data, const char*slot_data) { + pa_log("(func1) hook=%s call=%s slot=%s", hook_data, call_data, slot_data); return PA_HOOK_OK; } -static pa_hook_result_t func2(const char*a, void *userdata) { - pa_log("#2 arg=%s userdata=%s", a, (char*) userdata); +static pa_hook_result_t func2(const char*hook_data, const char*call_data, const char*slot_data) { + pa_log("(func2) hook=%s call=%s slot=%s", hook_data, call_data, slot_data); return PA_HOOK_OK; } @@ -17,15 +17,18 @@ int main(int argc, char *argv[]) { pa_hook hook; pa_hook_slot *slot; - pa_hook_init(&hook); + pa_hook_init(&hook, (void*) "hook"); - pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "1-1"); - slot = pa_hook_connect(&hook, (pa_hook_cb_t) func2, (void*) "2-1"); - pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "1-2"); + pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "slot1"); + slot = pa_hook_connect(&hook, (pa_hook_cb_t) func2, (void*) "slot2"); + pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "slot3"); - pa_hook_fire(&hook, (void*) "arg2"); + pa_hook_fire(&hook, (void*) "call1"); pa_hook_slot_free(slot); + + pa_hook_fire(&hook, (void*) "call2"); + pa_hook_free(&hook); return 0; -- 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/mcalign-test.c | 11 +++++++++-- src/tests/memblockq-test.c | 16 ++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/tests') diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index 7a68e6de..35691698 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -38,9 +38,14 @@ /* A simple program for testing pa_mcalign */ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { - pa_mcalign *a = pa_mcalign_new(11, NULL); + pa_mempool *p; + pa_mcalign *a; pa_memchunk c; + p = pa_mempool_new(0); + + a = pa_mcalign_new(11); + pa_memchunk_reset(&c); srand(time(NULL)); @@ -50,7 +55,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { size_t l; if (!c.memblock) { - c.memblock = pa_memblock_new(2048, NULL); + c.memblock = pa_memblock_new(p, 2048); c.index = c.length = 0; } @@ -94,5 +99,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { if (c.memblock) pa_memblock_unref(c.memblock); + pa_mempool_free(p); + return 0; } 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 35caf0c4eaedbf8553c1fe59e7d3e3438e59a7d9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 18 Aug 2006 19:56:51 +0000 Subject: add new test memblock-test for testing SHM import/export git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1268 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblock-test.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 src/tests/memblock-test.c (limited to 'src/tests') diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c new file mode 100644 index 00000000..11198ae6 --- /dev/null +++ b/src/tests/memblock-test.c @@ -0,0 +1,164 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include + +static void release_cb(pa_memimport *i, uint32_t block_id, void *userdata) { + printf("%s: Imported block %u is released.\n", (char*) userdata, block_id); +} + +static void revoke_cb(pa_memexport *e, uint32_t block_id, void *userdata) { + printf("%s: Exported block %u is revoked.\n", (char*) userdata, block_id); +} + +static void print_stats(pa_mempool *p, const char *text) { + const pa_mempool_stat*s = pa_mempool_get_stat(p); + + printf("%s = {\n" + "n_allocated = %u\n" + "n_accumulated = %u\n" + "n_imported = %u\n" + "n_exported = %u\n" + "allocated_size = %lu\n" + "accumulated_size = %lu\n" + "imported_size = %lu\n" + "exported_size = %lu\n" + "n_too_large_for_pool = %u\n" + "n_pool_full = %u\n" + "}\n", + text, + s->n_allocated, + s->n_accumulated, + s->n_imported, + s->n_exported, + (unsigned long) s->allocated_size, + (unsigned long) s->accumulated_size, + (unsigned long) s->imported_size, + (unsigned long) s->exported_size, + s->n_too_large_for_pool, + s->n_pool_full); +} + +int main(int argc, char *argv[]) { + pa_mempool *pool_a, *pool_b, *pool_c; + unsigned id_a, id_b, id_c; + pa_memexport *export_a, *export_b; + pa_memimport *import_b, *import_c; + pa_memblock *mb_a, *mb_b, *mb_c; + int r, i; + pa_memblock* blocks[5]; + uint32_t id, shm_id; + size_t offset, size; + + const char txt[] = "This is a test!"; + + pool_a = pa_mempool_new(1); + pool_b = pa_mempool_new(1); + pool_c = pa_mempool_new(1); + + pa_mempool_get_shm_id(pool_a, &id_a); + pa_mempool_get_shm_id(pool_b, &id_b); + pa_mempool_get_shm_id(pool_c, &id_c); + + assert(pool_a && pool_b && pool_c); + + blocks[0] = pa_memblock_new_fixed(pool_a, (void*) txt, sizeof(txt), 1); + blocks[1] = pa_memblock_new(pool_a, sizeof(txt)); + snprintf(blocks[1]->data, blocks[1]->length, "%s", txt); + blocks[2] = pa_memblock_new_pool(pool_a, sizeof(txt)); + snprintf(blocks[2]->data, blocks[2]->length, "%s", txt); + blocks[3] = pa_memblock_new_malloced(pool_a, pa_xstrdup(txt), sizeof(txt)); + blocks[4] = NULL; + + for (i = 0; blocks[i]; i++) { + printf("Memory block %u\n", i); + + mb_a = blocks[i]; + assert(mb_a); + + export_a = pa_memexport_new(pool_a, revoke_cb, (void*) "A"); + export_b = pa_memexport_new(pool_b, revoke_cb, (void*) "B"); + + assert(export_a && export_b); + + import_b = pa_memimport_new(pool_b, release_cb, (void*) "B"); + import_c = pa_memimport_new(pool_c, release_cb, (void*) "C"); + + assert(import_b && import_c); + + r = pa_memexport_put(export_a, mb_a, &id, &shm_id, &offset, &size); + assert(r >= 0); + assert(shm_id == id_a); + + printf("A: Memory block exported as %u\n", id); + + mb_b = pa_memimport_get(import_b, id, shm_id, offset, size); + assert(mb_b); + r = pa_memexport_put(export_b, mb_b, &id, &shm_id, &offset, &size); + assert(r >= 0); + assert(shm_id == id_a || shm_id == id_b); + pa_memblock_unref(mb_b); + + printf("B: Memory block exported as %u\n", id); + + mb_c = pa_memimport_get(import_c, id, shm_id, offset, size); + assert(mb_c); + printf("1 data=%s\n", (char*) mb_c->data); + + print_stats(pool_a, "A"); + print_stats(pool_b, "B"); + print_stats(pool_c, "C"); + + pa_memexport_free(export_b); + printf("2 data=%s\n", (char*) mb_c->data); + pa_memblock_unref(mb_c); + + pa_memimport_free(import_b); + + pa_memblock_unref(mb_a); + + pa_memimport_free(import_c); + pa_memexport_free(export_a); + } + + printf("vaccuuming...\n"); + + pa_mempool_vacuum(pool_a); + pa_mempool_vacuum(pool_b); + pa_mempool_vacuum(pool_c); + + printf("vaccuuming done...\n"); + + pa_mempool_free(pool_a); + pa_mempool_free(pool_b); + pa_mempool_free(pool_c); + + return 0; +} -- cgit From aec3888ef2deb1dba51922fcf149115acea6476b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 24 Aug 2006 08:57:35 +0000 Subject: Add missing header. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1330 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/tests') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 2df65a45..3ec8a18f 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -37,6 +37,10 @@ #include #endif +#ifdef HAVE_WINDOWS_H +#include +#endif + #include #include -- cgit From 5264d235d25f04d3cd5796e751a66cb92453be73 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 29 Aug 2006 02:01:39 +0000 Subject: make pa_mempool_stat thread-safe/lock-free git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1343 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblock-test.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/tests') diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c index 11198ae6..ef2e0ad7 100644 --- a/src/tests/memblock-test.c +++ b/src/tests/memblock-test.c @@ -54,16 +54,16 @@ static void print_stats(pa_mempool *p, const char *text) { "n_pool_full = %u\n" "}\n", text, - s->n_allocated, - s->n_accumulated, - s->n_imported, - s->n_exported, - (unsigned long) s->allocated_size, - (unsigned long) s->accumulated_size, - (unsigned long) s->imported_size, - (unsigned long) s->exported_size, - s->n_too_large_for_pool, - s->n_pool_full); + (unsigned) AO_load_acquire_read((AO_t*) &s->n_allocated), + (unsigned) AO_load_acquire_read((AO_t*) &s->n_accumulated), + (unsigned) AO_load_acquire_read((AO_t*) &s->n_imported), + (unsigned) AO_load_acquire_read((AO_t*) &s->n_exported), + (unsigned long) AO_load_acquire_read((AO_t*) &s->allocated_size), + (unsigned long) AO_load_acquire_read((AO_t*) &s->accumulated_size), + (unsigned long) AO_load_acquire_read((AO_t*) &s->imported_size), + (unsigned long) AO_load_acquire_read((AO_t*) &s->exported_size), + (unsigned) AO_load_acquire_read((AO_t*) &s->n_too_large_for_pool), + (unsigned) AO_load_acquire_read((AO_t*) &s->n_pool_full)); } int main(int argc, char *argv[]) { -- cgit From b2c341f935bd54eb1b7f80a297e72bf0e6c6dc83 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 29 Aug 2006 19:51:14 +0000 Subject: add a threading primitive API git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1344 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/thread-test.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/tests/thread-test.c (limited to 'src/tests') diff --git a/src/tests/thread-test.c b/src/tests/thread-test.c new file mode 100644 index 00000000..a93ac1e4 --- /dev/null +++ b/src/tests/thread-test.c @@ -0,0 +1,135 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include +#include +#include + +static pa_mutex *mutex = NULL; +static pa_cond *cond1 = NULL, *cond2 = NULL; +static pa_tls *tls = NULL; + +static int magic_number = 0; + +#define THREADS_MAX 20 + +static void thread_func(void *data) { + pa_tls_set(tls, data); + + pa_log("thread_func() for %s starting...", (char*) pa_tls_get(tls)); + + pa_mutex_lock(mutex); + + for (;;) { + int k, n; + + pa_log("%s waiting ...", (char*) pa_tls_get(tls)); + + for (;;) { + + if (magic_number < 0) + goto quit; + + if (magic_number != 0) + break; + + pa_cond_wait(cond1, mutex); + } + + k = magic_number; + magic_number = 0; + + pa_mutex_unlock(mutex); + + pa_cond_signal(cond2, 0); + + pa_log("%s got number %i", (char*) pa_tls_get(tls), k); + + /* Spin! */ + for (n = 0; n < k; n++) + sched_yield(); + + pa_mutex_lock(mutex); + } + +quit: + + pa_mutex_unlock(mutex); + + pa_log("thread_func() for %s done...", (char*) pa_tls_get(tls)); +} + +int main(int argc, char *argv[]) { + int i, k; + pa_thread* t[THREADS_MAX]; + + mutex = pa_mutex_new(0); + cond1 = pa_cond_new(); + cond2 = pa_cond_new(); + tls = pa_tls_new(pa_xfree); + + for (i = 0; i < THREADS_MAX; i++) { + t[i] = pa_thread_new(thread_func, pa_sprintf_malloc("Thread #%i", i+1)); + assert(t[i]); + } + + pa_mutex_lock(mutex); + + pa_log("loop-init"); + + for (k = 0; k < 100; k++) { + assert(magic_number == 0); + + + magic_number = (int) rand() % 0x10000; + + pa_log("iteration %i (%i)", k, magic_number); + + pa_cond_signal(cond1, 0); + + pa_cond_wait(cond2, mutex); + } + + pa_log("loop-exit"); + + magic_number = -1; + pa_cond_signal(cond1, 1); + + pa_mutex_unlock(mutex); + + for (i = 0; i < THREADS_MAX; i++) + pa_thread_free(t[i]); + + pa_mutex_free(mutex); + pa_cond_free(cond1); + pa_cond_free(cond2); + pa_tls_free(tls); + + return 0; +} -- cgit From 6e9706bcbcc0c5743d21ed48bd6e6485e4ee5203 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 31 Aug 2006 16:13:07 +0000 Subject: Also wrap yield functionality so that it can be platform independent. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1353 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/thread-test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/tests') diff --git a/src/tests/thread-test.c b/src/tests/thread-test.c index a93ac1e4..120d2554 100644 --- a/src/tests/thread-test.c +++ b/src/tests/thread-test.c @@ -23,8 +23,6 @@ #include #endif -#include - #include #include #include @@ -73,7 +71,7 @@ static void thread_func(void *data) { /* Spin! */ for (n = 0; n < k; n++) - sched_yield(); + pa_thread_yield(); pa_mutex_lock(mutex); } -- cgit From 3be920d9aec656e7e34672558e85ba025a4059d0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Sep 2006 22:04:33 +0000 Subject: fix pa_thread_is_running() for foreign threads; fix a memory leak for foreign threads git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1370 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/thread-test.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/tests') diff --git a/src/tests/thread-test.c b/src/tests/thread-test.c index 120d2554..9e8afd9b 100644 --- a/src/tests/thread-test.c +++ b/src/tests/thread-test.c @@ -87,6 +87,8 @@ int main(int argc, char *argv[]) { int i, k; pa_thread* t[THREADS_MAX]; + assert(pa_thread_is_running(pa_thread_self())); + mutex = pa_mutex_new(0); cond1 = pa_cond_new(); cond2 = pa_cond_new(); -- cgit From e00ba020cb712aee50c591fc66c6bc2ab3659deb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Sep 2006 22:38:41 +0000 Subject: remove yet another occurence of pthread_yield() by pa_thread_yield() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1372 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/tests') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 3ec8a18f..54bdd775 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -33,17 +33,11 @@ #include #include -#ifdef HAVE_PTHREAD -#include -#endif - -#ifdef HAVE_WINDOWS_H -#include -#endif - #include #include +#include + static pa_context *context = NULL; static pa_stream *stream = NULL; static pa_mainloop_api *mainloop_api = NULL; @@ -152,13 +146,7 @@ int main(int argc, char *argv[]) { tv = now; while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) -#ifdef HAVE_PTHREAD_YIELD - pthread_yield(); -#elif defined(OS_IS_WIN32) - Sleep(0); -#else - ; -#endif + pa_thread_yield(); } if (m) -- cgit From b93fedd49c95675ed8ce089b94b2b3bcfd903565 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 9 Sep 2006 21:09:55 +0000 Subject: add a test program for the free list git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1383 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/flist-test.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/tests/flist-test.c (limited to 'src/tests') diff --git a/src/tests/flist-test.c b/src/tests/flist-test.c new file mode 100644 index 00000000..b0404449 --- /dev/null +++ b/src/tests/flist-test.c @@ -0,0 +1,104 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include + +#define THREADS_MAX 20 + +static pa_flist *flist; +static int quit = 0; + +static void spin(void) { + int k; + + /* Spin a little */ + k = rand() % 10000; + for (; k > 0; k--) + pa_thread_yield(); +} + +static void thread_func(void *data) { + char *s = data; + int n = 0; + int b = 1; + + while (!quit) { + char *text, *t; + + /* Allocate some memory, if possible take it from the flist */ + if (b && (text = pa_flist_pop(flist))) + pa_log("%s: popped '%s'", s, text); + else { + text = pa_sprintf_malloc("Block %i, allocated by %s", n++, s); + pa_log("%s: allocated '%s'", s, text); + } + + b = !b; + + spin(); + + /* Give it back to the flist if possible */ + if (pa_flist_push(flist, text) < 0) { + pa_log("%s: failed to push back '%s'", s, text); + pa_xfree(text); + } else + pa_log("%s: pushed", s); + + spin(); + } + + if (pa_flist_push(flist, s) < 0) + pa_xfree(s); +} + +int main(int argc, char* argv[]) { + pa_thread *threads[THREADS_MAX]; + int i; + + flist = pa_flist_new(0); + + for (i = 0; i < THREADS_MAX; i++) { + threads[i] = pa_thread_new(thread_func, pa_sprintf_malloc("Thread #%i", i+1)); + assert(threads[i]); + } + + sleep(60); + quit = 1; + + for (i = 0; i < THREADS_MAX; i++) + pa_thread_free(threads[i]); + + pa_flist_free(flist, pa_xfree); + + return 0; +} -- cgit From 3ae98db1aa01cfe68ed55f303fecf9c9bbcb4438 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 9 Sep 2006 23:54:56 +0000 Subject: add pa_once testing code git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1388 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/thread-test.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/tests') diff --git a/src/tests/thread-test.c b/src/tests/thread-test.c index 9e8afd9b..9559cdbb 100644 --- a/src/tests/thread-test.c +++ b/src/tests/thread-test.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,12 @@ static int magic_number = 0; #define THREADS_MAX 20 +static void once_func(void) { + pa_log("once!"); +} + +static pa_once_t once = PA_ONCE_INIT; + static void thread_func(void *data) { pa_tls_set(tls, data); @@ -65,6 +72,8 @@ static void thread_func(void *data) { pa_mutex_unlock(mutex); + pa_once(&once, once_func); + pa_cond_signal(cond2, 0); pa_log("%s got number %i", (char*) pa_tls_get(tls), k); -- cgit From a85b3e2dd49adc5addab25e5ceeb8eb56e283e48 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 11 Sep 2006 07:54:41 +0000 Subject: Use platform independent sleep. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1394 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/flist-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/flist-test.c b/src/tests/flist-test.c index b0404449..abc0659d 100644 --- a/src/tests/flist-test.c +++ b/src/tests/flist-test.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -92,7 +93,7 @@ int main(int argc, char* argv[]) { assert(threads[i]); } - sleep(60); + pa_msleep(60000); quit = 1; for (i = 0; i < THREADS_MAX; i++) -- 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/flist-test.c | 2 +- src/tests/mcalign-test.c | 19 ++++++++++++------- src/tests/memblock-test.c | 20 ++++++++++++++++---- src/tests/memblockq-test.c | 4 +++- 4 files changed, 32 insertions(+), 13 deletions(-) (limited to 'src/tests') diff --git a/src/tests/flist-test.c b/src/tests/flist-test.c index abc0659d..06d68311 100644 --- a/src/tests/flist-test.c +++ b/src/tests/flist-test.c @@ -54,7 +54,7 @@ static void thread_func(void *data) { int b = 1; while (!quit) { - char *text, *t; + char *text; /* Allocate some memory, if possible take it from the flist */ if (b && (text = pa_flist_pop(flist))) diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index 35691698..1584256c 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -59,24 +59,27 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { c.index = c.length = 0; } - assert(c.index < c.memblock->length); + assert(c.index < pa_memblock_get_length(c.memblock)); - l = c.memblock->length - c.index; + l = pa_memblock_get_length(c.memblock) - c.index; l = l <= 1 ? l : rand() % (l-1) +1 ; - - if ((r = read(STDIN_FILENO, (uint8_t*) c.memblock->data + c.index, l)) <= 0) { + + p = pa_memblock_acquire(c.memblock); + if ((r = read(STDIN_FILENO, (uint8_t*) p + c.index, l)) <= 0) { + pa_memblock_release(c.memblock); fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF"); break; } - + pa_memblock_release(c.memblock); + c.length = r; pa_mcalign_push(a, &c); fprintf(stderr, "Read %ld bytes\n", (long)r); c.index += r; - if (c.index >= c.memblock->length) { + if (c.index >= pa_memblock_get_length(c.memblock)) { pa_memblock_unref(c.memblock); pa_memchunk_reset(&c); } @@ -87,7 +90,9 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { if (pa_mcalign_pop(a, &t) < 0) break; - pa_loop_write(STDOUT_FILENO, (uint8_t*) t.memblock->data + t.index, t.length, NULL); + p = pa_memblock_acquire(t.memblock); + pa_loop_write(STDOUT_FILENO, (uint8_t*) p + t.index, t.length, NULL); + pa_memblock_release(t.memblock); fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length); pa_memblock_unref(t.memblock); diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c index ef2e0ad7..c2dd2efa 100644 --- a/src/tests/memblock-test.c +++ b/src/tests/memblock-test.c @@ -76,6 +76,7 @@ int main(int argc, char *argv[]) { pa_memblock* blocks[5]; uint32_t id, shm_id; size_t offset, size; + char *x; const char txt[] = "This is a test!"; @@ -90,10 +91,17 @@ int main(int argc, char *argv[]) { assert(pool_a && pool_b && pool_c); blocks[0] = pa_memblock_new_fixed(pool_a, (void*) txt, sizeof(txt), 1); + blocks[1] = pa_memblock_new(pool_a, sizeof(txt)); - snprintf(blocks[1]->data, blocks[1]->length, "%s", txt); + x = pa_memblock_acquire(blocks[1]); + snprintf(x, pa_memblock_get_length(blocks[1]), "%s", txt); + pa_memblock_release(blocks[1]); + blocks[2] = pa_memblock_new_pool(pool_a, sizeof(txt)); - snprintf(blocks[2]->data, blocks[2]->length, "%s", txt); + x = pa_memblock_acquire(blocks[2]); + snprintf(x, pa_memblock_get_length(blocks[2]), "%s", txt); + pa_memblock_release(blocks[1]); + blocks[3] = pa_memblock_new_malloced(pool_a, pa_xstrdup(txt), sizeof(txt)); blocks[4] = NULL; @@ -130,14 +138,18 @@ int main(int argc, char *argv[]) { mb_c = pa_memimport_get(import_c, id, shm_id, offset, size); assert(mb_c); - printf("1 data=%s\n", (char*) mb_c->data); + x = pa_memblock_acquire(mb_c); + printf("1 data=%s\n", x); + pa_memblock_release(mb_c); print_stats(pool_a, "A"); print_stats(pool_b, "B"); print_stats(pool_c, "C"); pa_memexport_free(export_b); - printf("2 data=%s\n", (char*) mb_c->data); + x = pa_memblock_acquire(mb_c); + printf("2 data=%s\n", x); + pa_memblock_release(mb_c); pa_memblock_unref(mb_c); pa_memimport_free(import_b); 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/flist-test.c | 2 +- src/tests/mcalign-test.c | 19 +++++++------------ src/tests/memblock-test.c | 20 ++++---------------- src/tests/memblockq-test.c | 4 +--- 4 files changed, 13 insertions(+), 32 deletions(-) (limited to 'src/tests') diff --git a/src/tests/flist-test.c b/src/tests/flist-test.c index 06d68311..abc0659d 100644 --- a/src/tests/flist-test.c +++ b/src/tests/flist-test.c @@ -54,7 +54,7 @@ static void thread_func(void *data) { int b = 1; while (!quit) { - char *text; + char *text, *t; /* Allocate some memory, if possible take it from the flist */ if (b && (text = pa_flist_pop(flist))) diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index 1584256c..35691698 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -59,27 +59,24 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { c.index = c.length = 0; } - assert(c.index < pa_memblock_get_length(c.memblock)); + assert(c.index < c.memblock->length); - l = pa_memblock_get_length(c.memblock) - c.index; + l = c.memblock->length - c.index; l = l <= 1 ? l : rand() % (l-1) +1 ; - - p = pa_memblock_acquire(c.memblock); - if ((r = read(STDIN_FILENO, (uint8_t*) p + c.index, l)) <= 0) { - pa_memblock_release(c.memblock); + + if ((r = read(STDIN_FILENO, (uint8_t*) c.memblock->data + c.index, l)) <= 0) { fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF"); break; } - pa_memblock_release(c.memblock); - + c.length = r; pa_mcalign_push(a, &c); fprintf(stderr, "Read %ld bytes\n", (long)r); c.index += r; - if (c.index >= pa_memblock_get_length(c.memblock)) { + if (c.index >= c.memblock->length) { pa_memblock_unref(c.memblock); pa_memchunk_reset(&c); } @@ -90,9 +87,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { if (pa_mcalign_pop(a, &t) < 0) break; - p = pa_memblock_acquire(t.memblock); - pa_loop_write(STDOUT_FILENO, (uint8_t*) p + t.index, t.length, NULL); - pa_memblock_release(t.memblock); + pa_loop_write(STDOUT_FILENO, (uint8_t*) t.memblock->data + t.index, t.length, NULL); fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length); pa_memblock_unref(t.memblock); diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c index c2dd2efa..ef2e0ad7 100644 --- a/src/tests/memblock-test.c +++ b/src/tests/memblock-test.c @@ -76,7 +76,6 @@ int main(int argc, char *argv[]) { pa_memblock* blocks[5]; uint32_t id, shm_id; size_t offset, size; - char *x; const char txt[] = "This is a test!"; @@ -91,17 +90,10 @@ int main(int argc, char *argv[]) { assert(pool_a && pool_b && pool_c); blocks[0] = pa_memblock_new_fixed(pool_a, (void*) txt, sizeof(txt), 1); - blocks[1] = pa_memblock_new(pool_a, sizeof(txt)); - x = pa_memblock_acquire(blocks[1]); - snprintf(x, pa_memblock_get_length(blocks[1]), "%s", txt); - pa_memblock_release(blocks[1]); - + snprintf(blocks[1]->data, blocks[1]->length, "%s", txt); blocks[2] = pa_memblock_new_pool(pool_a, sizeof(txt)); - x = pa_memblock_acquire(blocks[2]); - snprintf(x, pa_memblock_get_length(blocks[2]), "%s", txt); - pa_memblock_release(blocks[1]); - + snprintf(blocks[2]->data, blocks[2]->length, "%s", txt); blocks[3] = pa_memblock_new_malloced(pool_a, pa_xstrdup(txt), sizeof(txt)); blocks[4] = NULL; @@ -138,18 +130,14 @@ int main(int argc, char *argv[]) { mb_c = pa_memimport_get(import_c, id, shm_id, offset, size); assert(mb_c); - x = pa_memblock_acquire(mb_c); - printf("1 data=%s\n", x); - pa_memblock_release(mb_c); + printf("1 data=%s\n", (char*) mb_c->data); print_stats(pool_a, "A"); print_stats(pool_b, "B"); print_stats(pool_c, "C"); pa_memexport_free(export_b); - x = pa_memblock_acquire(mb_c); - printf("2 data=%s\n", x); - pa_memblock_release(mb_c); + printf("2 data=%s\n", (char*) mb_c->data); pa_memblock_unref(mb_c); pa_memimport_free(import_b); 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/channelmap-test.c | 10 +++++----- src/tests/cpulimit-test.c | 14 +++++++------- src/tests/flist-test.c | 10 +++++----- src/tests/get-binary-name-test.c | 6 +++--- src/tests/hook-list-test.c | 4 ++-- src/tests/interpol-test.c | 30 +++++++++++++++--------------- src/tests/ipacl-test.c | 14 +++++++------- src/tests/mainloop-test.c | 8 ++++---- src/tests/mcalign-test.c | 10 +++++----- src/tests/memblock-test.c | 36 ++++++++++++++++++------------------ src/tests/memblockq-test.c | 30 +++++++++++++++--------------- src/tests/pacat-simple.c | 16 ++++++++-------- src/tests/parec-simple.c | 10 +++++----- src/tests/strlist-test.c | 6 +++--- src/tests/sync-playback.c | 28 ++++++++++++++-------------- src/tests/thread-mainloop-test.c | 14 +++++++------- src/tests/thread-test.c | 32 ++++++++++++++++---------------- src/tests/utf8-test.c | 4 ++-- src/tests/voltest.c | 2 +- 19 files changed, 142 insertions(+), 142 deletions(-) (limited to 'src/tests') diff --git a/src/tests/channelmap-test.c b/src/tests/channelmap-test.c index 124ce576..98f36b61 100644 --- a/src/tests/channelmap-test.c +++ b/src/tests/channelmap-test.c @@ -11,23 +11,23 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { pa_channel_map map, map2; pa_channel_map_init_auto(&map, 6, PA_CHANNEL_MAP_AIFF); - + fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map)); pa_channel_map_init_auto(&map, 6, PA_CHANNEL_MAP_AUX); - + fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map)); pa_channel_map_init_auto(&map, 6, PA_CHANNEL_MAP_ALSA); - + fprintf(stderr, "map: <%s>\n", pa_channel_map_snprint(cm, sizeof(cm), &map)); - + pa_channel_map_parse(&map2, cm); assert(pa_channel_map_equal(&map, &map2)); pa_channel_map_parse(&map2, "left,test"); - + return 0; } diff --git a/src/tests/cpulimit-test.c b/src/tests/cpulimit-test.c index 2302a26d..d582e9c5 100644 --- a/src/tests/cpulimit-test.c +++ b/src/tests/cpulimit-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 @@ -47,7 +47,7 @@ static time_t start; static void func(pa_mainloop_api *m, PA_GCC_UNUSED pa_signal_event *e, PA_GCC_UNUSED int sig, PA_GCC_UNUSED void *userdata) { time_t now; time(&now); - + if ((now - start) >= 30) { m->quit(m, 1); fprintf(stderr, "Test failed\n"); @@ -59,7 +59,7 @@ static void func(pa_mainloop_api *m, PA_GCC_UNUSED pa_signal_event *e, PA_GCC_UN int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { pa_mainloop *m; - + m = pa_mainloop_new(); assert(m); @@ -77,7 +77,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { for (;;) { time_t now; time(&now); - + if ((now - start) >= 30) { fprintf(stderr, "Test failed\n"); break; @@ -86,7 +86,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { #endif pa_cpu_limit_done(); - + pa_mainloop_free(m); return 0; diff --git a/src/tests/flist-test.c b/src/tests/flist-test.c index abc0659d..17ba55c1 100644 --- a/src/tests/flist-test.c +++ b/src/tests/flist-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 @@ static int quit = 0; static void spin(void) { int k; - + /* Spin a little */ k = rand() % 10000; for (; k > 0; k--) @@ -100,6 +100,6 @@ int main(int argc, char* argv[]) { pa_thread_free(threads[i]); pa_flist_free(flist, pa_xfree); - + return 0; } diff --git a/src/tests/get-binary-name-test.c b/src/tests/get-binary-name-test.c index 0cea2b6d..29ebbe22 100644 --- a/src/tests/get-binary-name-test.c +++ b/src/tests/get-binary-name-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 diff --git a/src/tests/hook-list-test.c b/src/tests/hook-list-test.c index d68d1b7d..6879eae5 100644 --- a/src/tests/hook-list-test.c +++ b/src/tests/hook-list-test.c @@ -22,7 +22,7 @@ int main(int argc, char *argv[]) { pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "slot1"); slot = pa_hook_connect(&hook, (pa_hook_cb_t) func2, (void*) "slot2"); pa_hook_connect(&hook, (pa_hook_cb_t) func1, (void*) "slot3"); - + pa_hook_fire(&hook, (void*) "call1"); pa_hook_slot_free(slot); @@ -30,6 +30,6 @@ int main(int argc, char *argv[]) { pa_hook_fire(&hook, (void*) "call2"); pa_hook_free(&hook); - + return 0; } diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 54bdd775..3953043f 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-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 @@ -57,7 +57,7 @@ static void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: break; - + case PA_CONTEXT_READY: { static const pa_sample_spec ss = { @@ -65,18 +65,18 @@ static void context_state_callback(pa_context *c, void *userdata) { .rate = 44100, .channels = 1 }; - + fprintf(stderr, "Connection established.\n"); stream = pa_stream_new(c, "interpol-test", &ss, NULL); assert(stream); - + pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL); pa_stream_set_write_callback(stream, stream_write_cb, NULL); - + break; } - + case PA_CONTEXT_TERMINATED: break; @@ -108,19 +108,19 @@ int main(int argc, char *argv[]) { assert(r >= 0); pa_gettimeofday(&start); - + pa_threaded_mainloop_start(m); for (k = 0; k < 5000; k++) { int success = 0, changed = 0; pa_usec_t t, rtc; struct timeval now, tv; - + pa_threaded_mainloop_lock(m); if (stream) { const pa_timing_info *info; - + if (pa_stream_get_time(stream, &t) >= 0) success = 1; @@ -130,9 +130,9 @@ int main(int argc, char *argv[]) { last_info = info->timestamp; } } - + pa_threaded_mainloop_unlock(m); - + if (success) { pa_gettimeofday(&now); @@ -156,7 +156,7 @@ int main(int argc, char *argv[]) { pa_stream_disconnect(stream); pa_stream_unref(stream); } - + if (context) { pa_context_disconnect(context); pa_context_unref(context); @@ -164,6 +164,6 @@ int main(int argc, char *argv[]) { if (m) pa_threaded_mainloop_free(m); - + return 0; } diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c index 2566b038..d1bcb3e3 100644 --- a/src/tests/ipacl-test.c +++ b/src/tests/ipacl-test.c @@ -37,13 +37,13 @@ int main(int argc, char *argv[]) { int r; pa_ip_acl *acl; - fd = socket(PF_INET, SOCK_STREAM, 0); + fd = socket(PF_INET, SOCK_STREAM, 0); assert(fd >= 0); - + sa.sin_family = AF_INET; sa.sin_port = htons(22); sa.sin_addr.s_addr = inet_addr("127.0.0.1"); - + r = connect(fd, (struct sockaddr*) &sa, sizeof(sa)); assert(r >= 0); @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) { assert(acl); printf("result=%u (should be 1)\n", pa_ip_acl_check(acl, fd)); pa_ip_acl_free(acl); - + acl = pa_ip_acl_new("127.0.0.2"); assert(acl); printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd)); @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) { assert(acl); printf("result=%u (should be 0)\n", pa_ip_acl_check(acl, fd)); pa_ip_acl_free(acl); - + close(fd); fd = socket(PF_INET6, SOCK_STREAM, 0); @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) { sa6.sin6_family = AF_INET6; sa6.sin6_port = htons(22); inet_pton(AF_INET6, "::1", &sa6.sin6_addr); - + r = connect(fd, (struct sockaddr*) &sa6, sizeof(sa6)); assert(r >= 0); @@ -131,6 +131,6 @@ int main(int argc, char *argv[]) { pa_ip_acl_free(acl); close(fd); - + return 0; } diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c index b06d0ed1..c386251c 100644 --- a/src/tests/mainloop-test.c +++ b/src/tests/mainloop-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 @@ -121,6 +121,6 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { #else pa_mainloop_free(m); #endif - + return 0; } diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index 35691698..db76712b 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-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.1 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 Lesser 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 @@ -45,7 +45,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { p = pa_mempool_new(0); a = pa_mcalign_new(11); - + pa_memchunk_reset(&c); srand(time(NULL)); @@ -64,7 +64,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { l = c.memblock->length - c.index; l = l <= 1 ? l : rand() % (l-1) +1 ; - + if ((r = read(STDIN_FILENO, (uint8_t*) c.memblock->data + c.index, l)) <= 0) { fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF"); break; diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c index ef2e0ad7..13bfdf0d 100644 --- a/src/tests/memblock-test.c +++ b/src/tests/memblock-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 @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) { size_t offset, size; const char txt[] = "This is a test!"; - + pool_a = pa_mempool_new(1); pool_b = pa_mempool_new(1); pool_c = pa_mempool_new(1); @@ -86,9 +86,9 @@ int main(int argc, char *argv[]) { pa_mempool_get_shm_id(pool_a, &id_a); pa_mempool_get_shm_id(pool_b, &id_b); pa_mempool_get_shm_id(pool_c, &id_c); - + assert(pool_a && pool_b && pool_c); - + blocks[0] = pa_memblock_new_fixed(pool_a, (void*) txt, sizeof(txt), 1); blocks[1] = pa_memblock_new(pool_a, sizeof(txt)); snprintf(blocks[1]->data, blocks[1]->length, "%s", txt); @@ -102,23 +102,23 @@ int main(int argc, char *argv[]) { mb_a = blocks[i]; assert(mb_a); - + export_a = pa_memexport_new(pool_a, revoke_cb, (void*) "A"); export_b = pa_memexport_new(pool_b, revoke_cb, (void*) "B"); - + assert(export_a && export_b); - + import_b = pa_memimport_new(pool_b, release_cb, (void*) "B"); import_c = pa_memimport_new(pool_c, release_cb, (void*) "C"); - + assert(import_b && import_c); - + r = pa_memexport_put(export_a, mb_a, &id, &shm_id, &offset, &size); assert(r >= 0); assert(shm_id == id_a); printf("A: Memory block exported as %u\n", id); - + mb_b = pa_memimport_get(import_b, id, shm_id, offset, size); assert(mb_b); r = pa_memexport_put(export_b, mb_b, &id, &shm_id, &offset, &size); @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) { pa_memblock_unref(mb_b); printf("B: Memory block exported as %u\n", id); - + mb_c = pa_memimport_get(import_c, id, shm_id, offset, size); assert(mb_c); printf("1 data=%s\n", (char*) mb_c->data); @@ -135,21 +135,21 @@ int main(int argc, char *argv[]) { print_stats(pool_a, "A"); print_stats(pool_b, "B"); print_stats(pool_c, "C"); - + pa_memexport_free(export_b); printf("2 data=%s\n", (char*) mb_c->data); pa_memblock_unref(mb_c); - + pa_memimport_free(import_b); - + pa_memblock_unref(mb_a); - + pa_memimport_free(import_c); pa_memexport_free(export_a); } printf("vaccuuming...\n"); - + pa_mempool_vacuum(pool_a); pa_mempool_vacuum(pool_b); pa_mempool_vacuum(pool_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; } diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c index 364e1ad6..2da67c1a 100644 --- a/src/tests/pacat-simple.c +++ b/src/tests/pacat-simple.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 @@ -43,7 +43,7 @@ int main(PA_GCC_UNUSED int argc, char*argv[]) { .rate = 44100, .channels = 2 }; - + pa_simple *s = NULL; int ret = 1; int error; @@ -61,10 +61,10 @@ int main(PA_GCC_UNUSED int argc, char*argv[]) { fprintf(stderr, __FILE__": dup2() failed: %s\n", strerror(errno)); goto finish; } - + close(fd); } - + /* Create a new playback stream */ if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); @@ -90,7 +90,7 @@ int main(PA_GCC_UNUSED int argc, char*argv[]) { if ((r = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) { if (r == 0) /* EOF */ break; - + fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno)); goto finish; } @@ -114,6 +114,6 @@ finish: if (s) pa_simple_free(s); - + return ret; } diff --git a/src/tests/parec-simple.c b/src/tests/parec-simple.c index 45a52288..d7d88360 100644 --- a/src/tests/parec-simple.c +++ b/src/tests/parec-simple.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 @@ -46,7 +46,7 @@ static ssize_t loop_write(int fd, const void*data, size_t size) { if (r == 0) break; - + ret += r; data = (const uint8_t*) data + r; size -= r; @@ -95,6 +95,6 @@ finish: if (s) pa_simple_free(s); - + return ret; } diff --git a/src/tests/strlist-test.c b/src/tests/strlist-test.c index 4262a001..47770b5d 100644 --- a/src/tests/strlist-test.c +++ b/src/tests/strlist-test.c @@ -16,7 +16,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char* argv[]) { t = pa_strlist_tostring(l); pa_strlist_free(l); - + fprintf(stderr, "1: %s\n", t); l = pa_strlist_parse(t); @@ -29,9 +29,9 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char* argv[]) { l = pa_strlist_pop(l, &u); fprintf(stderr, "3: %s\n", u); pa_xfree(u); - + l = pa_strlist_remove(l, "c"); - + t = pa_strlist_tostring(l); fprintf(stderr, "4: %s\n", t); pa_xfree(t); diff --git a/src/tests/sync-playback.c b/src/tests/sync-playback.c index 39c6aac4..63510eb6 100644 --- a/src/tests/sync-playback.c +++ b/src/tests/sync-playback.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 @@ -67,7 +67,7 @@ static void underflow_cb(struct pa_stream *s, void *userdata) { int i = (int) (long) userdata; fprintf(stderr, "Stream %i finished\n", i); - + if (++n_streams_ready >= 2*NSTREAMS) { fprintf(stderr, "We're done\n"); mainloop_api->quit(mainloop_api, 0); @@ -89,19 +89,19 @@ static void stream_state_callback(pa_stream *s, void *userdata) { int r, i = (int) (long) userdata; fprintf(stderr, "Writing data to stream %i.\n", i); - + r = pa_stream_write(s, data, sizeof(data), nop_free_cb, sizeof(data) * i, PA_SEEK_ABSOLUTE); assert(r == 0); /* Be notified when this stream is drained */ pa_stream_set_underflow_callback(s, underflow_cb, userdata); - + /* All streams have been set up, let's go! */ if (++n_streams_ready >= NSTREAMS) { fprintf(stderr, "Uncorking\n"); pa_operation_unref(pa_stream_cork(s, 0, NULL, NULL)); } - + break; } @@ -121,7 +121,7 @@ static void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: break; - + case PA_CONTEXT_READY: { int i; @@ -131,18 +131,18 @@ static void context_state_callback(pa_context *c, void *userdata) { char name[64]; fprintf(stderr, "Creating stream %i\n", i); - + snprintf(name, sizeof(name), "stream #%i", i); - + streams[i] = pa_stream_new(c, name, &sample_spec, NULL); assert(streams[i]); pa_stream_set_state_callback(streams[i], stream_state_callback, (void*) (long) i); pa_stream_connect_playback(streams[i], NULL, &buffer_attr, PA_STREAM_START_CORKED, NULL, i == 0 ? NULL : streams[0]); } - + break; } - + case PA_CONTEXT_TERMINATED: mainloop_api->quit(mainloop_api, 0); break; @@ -163,7 +163,7 @@ int main(int argc, char *argv[]) { for (i = 0; i < NSTREAMS; i++) streams[i] = NULL; - + /* Set up a new main loop */ m = pa_mainloop_new(); assert(m); @@ -187,6 +187,6 @@ int main(int argc, char *argv[]) { pa_stream_unref(streams[i]); pa_mainloop_free(m); - + return ret; } diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index bf3d4cd2..9d0e5de1 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-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 @@ -53,19 +53,19 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { pa_threaded_mainloop_start(m); pa_threaded_mainloop_lock(m); - + pa_gettimeofday(&tv); tv.tv_sec += 5; a->time_new(a, &tv, tcb, m); - + fprintf(stderr, "waiting 5s (signal)\n"); pa_threaded_mainloop_wait(m); fprintf(stderr, "wait completed\n"); pa_threaded_mainloop_accept(m); fprintf(stderr, "signal accepted\n"); - + pa_threaded_mainloop_unlock(m); - + fprintf(stderr, "waiting 5s (sleep)\n"); pa_msleep(5000); diff --git a/src/tests/thread-test.c b/src/tests/thread-test.c index 9559cdbb..2153c985 100644 --- a/src/tests/thread-test.c +++ b/src/tests/thread-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 @@ -48,7 +48,7 @@ static void thread_func(void *data) { pa_tls_set(tls, data); pa_log("thread_func() for %s starting...", (char*) pa_tls_get(tls)); - + pa_mutex_lock(mutex); for (;;) { @@ -57,13 +57,13 @@ static void thread_func(void *data) { pa_log("%s waiting ...", (char*) pa_tls_get(tls)); for (;;) { - + if (magic_number < 0) goto quit; if (magic_number != 0) break; - + pa_cond_wait(cond1, mutex); } @@ -75,18 +75,18 @@ static void thread_func(void *data) { pa_once(&once, once_func); pa_cond_signal(cond2, 0); - + pa_log("%s got number %i", (char*) pa_tls_get(tls), k); - + /* Spin! */ for (n = 0; n < k; n++) pa_thread_yield(); - + pa_mutex_lock(mutex); } quit: - + pa_mutex_unlock(mutex); pa_log("thread_func() for %s done...", (char*) pa_tls_get(tls)); @@ -97,25 +97,25 @@ int main(int argc, char *argv[]) { pa_thread* t[THREADS_MAX]; assert(pa_thread_is_running(pa_thread_self())); - + mutex = pa_mutex_new(0); cond1 = pa_cond_new(); cond2 = pa_cond_new(); tls = pa_tls_new(pa_xfree); - + for (i = 0; i < THREADS_MAX; i++) { t[i] = pa_thread_new(thread_func, pa_sprintf_malloc("Thread #%i", i+1)); assert(t[i]); } pa_mutex_lock(mutex); - + pa_log("loop-init"); for (k = 0; k < 100; k++) { assert(magic_number == 0); - + magic_number = (int) rand() % 0x10000; pa_log("iteration %i (%i)", k, magic_number); @@ -126,10 +126,10 @@ int main(int argc, char *argv[]) { } pa_log("loop-exit"); - + magic_number = -1; pa_cond_signal(cond1, 1); - + pa_mutex_unlock(mutex); for (i = 0; i < THREADS_MAX; i++) diff --git a/src/tests/utf8-test.c b/src/tests/utf8-test.c index 2e9f128a..b9594dcc 100644 --- a/src/tests/utf8-test.c +++ b/src/tests/utf8-test.c @@ -8,13 +8,13 @@ int main(int argc, char *argv[]) { char *c; - + assert(pa_utf8_valid("hallo")); assert(pa_utf8_valid("hallo\n")); assert(!pa_utf8_valid("hüpfburg\n")); assert(pa_utf8_valid("hallo\n")); assert(pa_utf8_valid("hüpfburg\n")); - + printf("LATIN1: %s\n", c = pa_utf8_filter("hüpfburg")); pa_xfree(c); printf("UTF8: %sx\n", c = pa_utf8_filter("hüpfburg")); diff --git a/src/tests/voltest.c b/src/tests/voltest.c index 3de884af..dcc1ec51 100644 --- a/src/tests/voltest.c +++ b/src/tests/voltest.c @@ -12,7 +12,7 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { double dB = pa_sw_volume_to_dB(v); double f = pa_sw_volume_to_linear(v); - + printf("Volume: %3i; percent: %i%%; decibel %0.2f; linear = %0.2f; volume(decibel): %3i; volume(linear): %3i\n", v, (v*100)/PA_VOLUME_NORM, dB, f, pa_sw_volume_from_dB(dB), pa_sw_volume_from_linear(f)); -- cgit From e41b91eec984c2ff61222d56872e9c3966a87375 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 22 May 2007 23:37:27 +0000 Subject: drop unused variable git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1439 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/flist-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests') diff --git a/src/tests/flist-test.c b/src/tests/flist-test.c index 17ba55c1..7e54454e 100644 --- a/src/tests/flist-test.c +++ b/src/tests/flist-test.c @@ -54,7 +54,7 @@ static void thread_func(void *data) { int b = 1; while (!quit) { - char *text, *t; + char *text; /* Allocate some memory, if possible take it from the flist */ if (b && (text = pa_flist_pop(flist))) -- cgit From 918cacb4f4efa80a0bc4b7183da1e9c1cb10ed9c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 27 May 2007 20:38:14 +0000 Subject: Replace AO_xxx usage with pa_atomic_xxx and friends wherever it makes sense git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1459 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/memblock-test.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/tests') diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c index 13bfdf0d..8d25ba38 100644 --- a/src/tests/memblock-test.c +++ b/src/tests/memblock-test.c @@ -46,24 +46,24 @@ static void print_stats(pa_mempool *p, const char *text) { "n_accumulated = %u\n" "n_imported = %u\n" "n_exported = %u\n" - "allocated_size = %lu\n" - "accumulated_size = %lu\n" - "imported_size = %lu\n" - "exported_size = %lu\n" + "allocated_size = %u\n" + "accumulated_size = %u\n" + "imported_size = %u\n" + "exported_size = %u\n" "n_too_large_for_pool = %u\n" "n_pool_full = %u\n" "}\n", text, - (unsigned) AO_load_acquire_read((AO_t*) &s->n_allocated), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_accumulated), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_imported), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_exported), - (unsigned long) AO_load_acquire_read((AO_t*) &s->allocated_size), - (unsigned long) AO_load_acquire_read((AO_t*) &s->accumulated_size), - (unsigned long) AO_load_acquire_read((AO_t*) &s->imported_size), - (unsigned long) AO_load_acquire_read((AO_t*) &s->exported_size), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_too_large_for_pool), - (unsigned) AO_load_acquire_read((AO_t*) &s->n_pool_full)); + (unsigned) pa_atomic_load(&s->n_allocated), + (unsigned) pa_atomic_load(&s->n_accumulated), + (unsigned) pa_atomic_load(&s->n_imported), + (unsigned) pa_atomic_load(&s->n_exported), + (unsigned) pa_atomic_load(&s->allocated_size), + (unsigned) pa_atomic_load(&s->accumulated_size), + (unsigned) pa_atomic_load(&s->imported_size), + (unsigned) pa_atomic_load(&s->exported_size), + (unsigned) pa_atomic_load(&s->n_too_large_for_pool), + (unsigned) pa_atomic_load(&s->n_pool_full)); } int main(int argc, char *argv[]) { -- 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/asyncmsgq-test.c | 110 +++++++++++++++++++ src/tests/asyncq-test.c | 87 +++++++++++++++ src/tests/hook-list-test.c | 4 + src/tests/interpol-test.c | 2 +- src/tests/mcalign-test.c | 17 ++- src/tests/memblock-test.c | 42 +++++--- src/tests/memblockq-test.c | 20 ++-- src/tests/queue-test.c | 69 ++++++++++++ src/tests/resampler-test.c | 227 +++++++++++++++++++++++++++++++++++++++ src/tests/rtpoll-test.c | 91 ++++++++++++++++ src/tests/sig2str-test.c | 39 +++++++ src/tests/smoother-test.c | 80 ++++++++++++++ src/tests/thread-mainloop-test.c | 13 +-- src/tests/thread-test.c | 6 +- 14 files changed, 768 insertions(+), 39 deletions(-) create mode 100644 src/tests/asyncmsgq-test.c create mode 100644 src/tests/asyncq-test.c create mode 100644 src/tests/queue-test.c create mode 100644 src/tests/resampler-test.c create mode 100644 src/tests/rtpoll-test.c create mode 100644 src/tests/sig2str-test.c create mode 100644 src/tests/smoother-test.c (limited to 'src/tests') diff --git a/src/tests/asyncmsgq-test.c b/src/tests/asyncmsgq-test.c new file mode 100644 index 00000000..380c5e7f --- /dev/null +++ b/src/tests/asyncmsgq-test.c @@ -0,0 +1,110 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +enum { + OPERATION_A, + OPERATION_B, + OPERATION_C, + QUIT +}; + +static void the_thread(void *_q) { + pa_asyncmsgq *q = _q; + int quit = 0; + + do { + int code = 0; + + pa_assert_se(pa_asyncmsgq_get(q, NULL, &code, NULL, NULL, NULL, 1) == 0); + + switch (code) { + + case OPERATION_A: + printf("Operation A\n"); + break; + + case OPERATION_B: + printf("Operation B\n"); + break; + + case OPERATION_C: + printf("Operation C\n"); + break; + + case QUIT: + printf("quit\n"); + quit = 1; + break; + } + + pa_asyncmsgq_done(q, 0); + + } while (!quit); +} + +int main(int argc, char *argv[]) { + pa_asyncmsgq *q; + pa_thread *t; + + pa_assert_se(q = pa_asyncmsgq_new(0)); + + pa_assert_se(t = pa_thread_new(the_thread, q)); + + printf("Operation A post\n"); + pa_asyncmsgq_post(q, NULL, OPERATION_A, NULL, 0, NULL, NULL); + + pa_thread_yield(); + + printf("Operation B post\n"); + pa_asyncmsgq_post(q, NULL, OPERATION_B, NULL, 0, NULL, NULL); + + pa_thread_yield(); + + printf("Operation C send\n"); + pa_asyncmsgq_send(q, NULL, OPERATION_C, NULL, 0, NULL); + + pa_thread_yield(); + + printf("Quit post\n"); + pa_asyncmsgq_post(q, NULL, QUIT, NULL, 0, NULL, NULL); + + pa_thread_free(t); + + pa_asyncmsgq_unref(q); + + return 0; +} diff --git a/src/tests/asyncq-test.c b/src/tests/asyncq-test.c new file mode 100644 index 00000000..09b20047 --- /dev/null +++ b/src/tests/asyncq-test.c @@ -0,0 +1,87 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +static void producer(void *_q) { + pa_asyncq *q = _q; + int i; + + for (i = 0; i < 1000; i++) { + printf("pushing %i\n", i); + pa_asyncq_push(q, PA_UINT_TO_PTR(i+1), 1); + } + + pa_asyncq_push(q, PA_UINT_TO_PTR(-1), 1); + printf("pushed end\n"); +} + +static void consumer(void *_q) { + pa_asyncq *q = _q; + void *p; + int i; + + sleep(1); + + for (i = 0;; i++) { + p = pa_asyncq_pop(q, 1); + + if (p == PA_UINT_TO_PTR(-1)) + break; + + pa_assert(p == PA_UINT_TO_PTR(i+1)); + + printf("popped %i\n", i); + } + + printf("popped end\n"); +} + +int main(int argc, char *argv[]) { + pa_asyncq *q; + pa_thread *t1, *t2; + + pa_assert_se(q = pa_asyncq_new(0)); + + pa_assert_se(t1 = pa_thread_new(producer, q)); + pa_assert_se(t2 = pa_thread_new(consumer, q)); + + pa_thread_free(t1); + pa_thread_free(t2); + + pa_asyncq_free(q, NULL); + + return 0; +} diff --git a/src/tests/hook-list-test.c b/src/tests/hook-list-test.c index 6879eae5..8628f521 100644 --- a/src/tests/hook-list-test.c +++ b/src/tests/hook-list-test.c @@ -1,5 +1,9 @@ /* $Id$ */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 3953043f..85a509d4 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) { pa_gettimeofday(&now); rtc = pa_timeval_diff(&now, &start); - printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, rtc, t, rtc-old_rtc, t-old_t, changed); + printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, (unsigned long long) rtc, (unsigned long long) t, (unsigned long long) (rtc-old_rtc), (unsigned long long) (t-old_t), changed); old_t = t; old_rtc = rtc; } diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index db76712b..d1013118 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -59,24 +59,29 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { c.index = c.length = 0; } - assert(c.index < c.memblock->length); + assert(c.index < pa_memblock_get_length(c.memblock)); - l = c.memblock->length - c.index; + l = pa_memblock_get_length(c.memblock) - c.index; l = l <= 1 ? l : rand() % (l-1) +1 ; - if ((r = read(STDIN_FILENO, (uint8_t*) c.memblock->data + c.index, l)) <= 0) { + p = pa_memblock_acquire(c.memblock); + + if ((r = read(STDIN_FILENO, (uint8_t*) p + c.index, l)) <= 0) { + pa_memblock_release(c.memblock); fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF"); break; } + pa_memblock_release(c.memblock); + c.length = r; pa_mcalign_push(a, &c); fprintf(stderr, "Read %ld bytes\n", (long)r); c.index += r; - if (c.index >= c.memblock->length) { + if (c.index >= pa_memblock_get_length(c.memblock)) { pa_memblock_unref(c.memblock); pa_memchunk_reset(&c); } @@ -87,7 +92,9 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { if (pa_mcalign_pop(a, &t) < 0) break; - pa_loop_write(STDOUT_FILENO, (uint8_t*) t.memblock->data + t.index, t.length, NULL); + p = pa_memblock_acquire(t.memblock); + pa_loop_write(STDOUT_FILENO, (uint8_t*) p + t.index, t.length, NULL); + pa_memblock_release(t.memblock); fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length); pa_memblock_unref(t.memblock); diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c index 8d25ba38..2b9d3401 100644 --- a/src/tests/memblock-test.c +++ b/src/tests/memblock-test.c @@ -23,11 +23,11 @@ #include #endif -#include #include #include #include +#include #include static void release_cb(pa_memimport *i, uint32_t block_id, void *userdata) { @@ -76,6 +76,7 @@ int main(int argc, char *argv[]) { pa_memblock* blocks[5]; uint32_t id, shm_id; size_t offset, size; + char *x; const char txt[] = "This is a test!"; @@ -87,13 +88,20 @@ int main(int argc, char *argv[]) { pa_mempool_get_shm_id(pool_b, &id_b); pa_mempool_get_shm_id(pool_c, &id_c); - assert(pool_a && pool_b && pool_c); + pa_assert(pool_a && pool_b && pool_c); blocks[0] = pa_memblock_new_fixed(pool_a, (void*) txt, sizeof(txt), 1); + blocks[1] = pa_memblock_new(pool_a, sizeof(txt)); - snprintf(blocks[1]->data, blocks[1]->length, "%s", txt); + x = pa_memblock_acquire(blocks[1]); + snprintf(x, pa_memblock_get_length(blocks[1]), "%s", txt); + pa_memblock_release(blocks[1]); + blocks[2] = pa_memblock_new_pool(pool_a, sizeof(txt)); - snprintf(blocks[2]->data, blocks[2]->length, "%s", txt); + x = pa_memblock_acquire(blocks[2]); + snprintf(x, pa_memblock_get_length(blocks[2]), "%s", txt); + pa_memblock_release(blocks[2]); + blocks[3] = pa_memblock_new_malloced(pool_a, pa_xstrdup(txt), sizeof(txt)); blocks[4] = NULL; @@ -101,43 +109,47 @@ int main(int argc, char *argv[]) { printf("Memory block %u\n", i); mb_a = blocks[i]; - assert(mb_a); + pa_assert(mb_a); export_a = pa_memexport_new(pool_a, revoke_cb, (void*) "A"); export_b = pa_memexport_new(pool_b, revoke_cb, (void*) "B"); - assert(export_a && export_b); + pa_assert(export_a && export_b); import_b = pa_memimport_new(pool_b, release_cb, (void*) "B"); import_c = pa_memimport_new(pool_c, release_cb, (void*) "C"); - assert(import_b && import_c); + pa_assert(import_b && import_c); r = pa_memexport_put(export_a, mb_a, &id, &shm_id, &offset, &size); - assert(r >= 0); - assert(shm_id == id_a); + pa_assert(r >= 0); + pa_assert(shm_id == id_a); printf("A: Memory block exported as %u\n", id); mb_b = pa_memimport_get(import_b, id, shm_id, offset, size); - assert(mb_b); + pa_assert(mb_b); r = pa_memexport_put(export_b, mb_b, &id, &shm_id, &offset, &size); - assert(r >= 0); - assert(shm_id == id_a || shm_id == id_b); + pa_assert(r >= 0); + pa_assert(shm_id == id_a || shm_id == id_b); pa_memblock_unref(mb_b); printf("B: Memory block exported as %u\n", id); mb_c = pa_memimport_get(import_c, id, shm_id, offset, size); - assert(mb_c); - printf("1 data=%s\n", (char*) mb_c->data); + pa_assert(mb_c); + x = pa_memblock_acquire(mb_c); + printf("1 data=%s\n", x); + pa_memblock_release(mb_c); print_stats(pool_a, "A"); print_stats(pool_b, "B"); print_stats(pool_c, "C"); pa_memexport_free(export_b); - printf("2 data=%s\n", (char*) mb_c->data); + x = pa_memblock_acquire(mb_c); + printf("2 data=%s\n", x); + pa_memblock_release(mb_c); pa_memblock_unref(mb_c); pa_memimport_free(import_b); 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"); diff --git a/src/tests/queue-test.c b/src/tests/queue-test.c new file mode 100644 index 00000000..b357ab10 --- /dev/null +++ b/src/tests/queue-test.c @@ -0,0 +1,69 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + pa_queue *q; + + pa_assert_se(q = pa_queue_new()); + + pa_assert(pa_queue_is_empty(q)); + + pa_queue_push(q, (void*) "eins"); + pa_log("%s\n", (char*) pa_queue_pop(q)); + + pa_assert(pa_queue_is_empty(q)); + + pa_queue_push(q, (void*) "zwei"); + pa_queue_push(q, (void*) "drei"); + pa_queue_push(q, (void*) "vier"); + + pa_log("%s\n", (char*) pa_queue_pop(q)); + pa_log("%s\n", (char*) pa_queue_pop(q)); + + pa_queue_push(q, (void*) "fuenf"); + + pa_log("%s\n", (char*) pa_queue_pop(q)); + pa_log("%s\n", (char*) pa_queue_pop(q)); + + pa_assert(pa_queue_is_empty(q)); + + pa_queue_push(q, (void*) "sechs"); + pa_queue_push(q, (void*) "sieben"); + + pa_queue_free(q, NULL, NULL); + + return 0; +} diff --git a/src/tests/resampler-test.c b/src/tests/resampler-test.c new file mode 100644 index 00000000..3b4a7386 --- /dev/null +++ b/src/tests/resampler-test.c @@ -0,0 +1,227 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +static float swap_float(float a) { + uint32_t *b = (uint32_t*) &a; + *b = PA_UINT32_SWAP(*b); + return a; +} + +static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) { + void *d; + unsigned i; + + d = pa_memblock_acquire(chunk->memblock); + + switch (ss->format) { + + case PA_SAMPLE_U8: + case PA_SAMPLE_ULAW: + case PA_SAMPLE_ALAW: { + uint8_t *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) + printf("0x%02x ", *(u++)); + + break; + } + + case PA_SAMPLE_S16NE: + case PA_SAMPLE_S16RE: { + uint16_t *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) + printf("0x%04x ", *(u++)); + + break; + } + + case PA_SAMPLE_FLOAT32NE: + case PA_SAMPLE_FLOAT32RE: { + float *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) { + printf("%1.3g ", ss->format == PA_SAMPLE_FLOAT32NE ? *u : swap_float(*u)); + u++; + } + + break; + } + + default: + pa_assert_not_reached(); + } + + printf("\n"); + + pa_memblock_release(chunk->memblock); +} + +static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) { + pa_memblock *r; + void *d; + unsigned i; + + pa_assert_se(r = pa_memblock_new(pool, pa_frame_size(ss) * 10)); + d = pa_memblock_acquire(r); + + switch (ss->format) { + + case PA_SAMPLE_U8: + case PA_SAMPLE_ULAW: + case PA_SAMPLE_ALAW: { + uint8_t *u = d; + + u[0] = 0x00; + u[1] = 0xFF; + u[2] = 0x7F; + u[3] = 0x80; + u[4] = 0x9f; + u[5] = 0x3f; + u[6] = 0x1; + u[7] = 0xF0; + u[8] = 0x20; + u[9] = 0x21; + break; + } + + case PA_SAMPLE_S16NE: + case PA_SAMPLE_S16RE: { + uint16_t *u = d; + + u[0] = 0x0000; + u[1] = 0xFFFF; + u[2] = 0x7FFF; + u[3] = 0x8000; + u[4] = 0x9fff; + u[5] = 0x3fff; + u[6] = 0x1; + u[7] = 0xF000; + u[8] = 0x20; + u[9] = 0x21; + break; + } + + case PA_SAMPLE_FLOAT32NE: + case PA_SAMPLE_FLOAT32RE: { + float *u = d; + + u[0] = 0.0; + u[1] = -1.0; + u[2] = 1.0; + u[3] = 4711; + u[4] = 0.222; + u[5] = 0.33; + u[6] = -.3; + u[7] = 99; + u[8] = -0.555; + u[9] = -.123; + + if (ss->format == PA_SAMPLE_FLOAT32RE) + for (i = 0; i < 10; i++) + u[i] = swap_float(u[i]); + + break; + } + + default: + pa_assert_not_reached(); + } + + pa_memblock_release(r); + + return r; +} + +int main(int argc, char *argv[]) { + pa_mempool *pool; + pa_sample_spec a, b; + pa_cvolume v; + + oil_init(); + pa_log_set_maximal_level(PA_LOG_DEBUG); + + pa_assert_se(pool = pa_mempool_new(FALSE)); + + a.channels = b.channels = 1; + a.rate = b.rate = 44100; + + v.channels = a.channels; + v.values[0] = pa_sw_volume_from_linear(0.5); + + for (a.format = 0; a.format < PA_SAMPLE_MAX; a.format ++) { + for (b.format = 0; b.format < PA_SAMPLE_MAX; b.format ++) { + + pa_resampler *forth, *back; + pa_memchunk i, j, k; + + printf("=== %s -> %s -> %s -> /2\n", + pa_sample_format_to_string(a.format), + pa_sample_format_to_string(b.format), + pa_sample_format_to_string(a.format)); + + pa_assert_se(forth = pa_resampler_new(pool, &a, NULL, &b, NULL, PA_RESAMPLER_AUTO, FALSE)); + pa_assert_se(back = pa_resampler_new(pool, &b, NULL, &a, NULL, PA_RESAMPLER_AUTO, FALSE)); + + i.memblock = generate_block(pool, &a); + i.length = pa_memblock_get_length(i.memblock); + i.index = 0; + pa_resampler_run(forth, &i, &j); + pa_resampler_run(back, &j, &k); + + dump_block(&a, &i); + dump_block(&b, &j); + dump_block(&a, &k); + + pa_memblock_unref(j.memblock); + pa_memblock_unref(k.memblock); + + pa_volume_memchunk(&i, &a, &v); + dump_block(&a, &i); + + pa_memblock_unref(i.memblock); + + pa_resampler_free(forth); + pa_resampler_free(back); + } + } + + pa_mempool_free(pool); + + return 0; +} diff --git a/src/tests/rtpoll-test.c b/src/tests/rtpoll-test.c new file mode 100644 index 00000000..3ab992a1 --- /dev/null +++ b/src/tests/rtpoll-test.c @@ -0,0 +1,91 @@ +/* $Id: thread-test.c 1621 2007-08-10 22:00:22Z lennart $ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include +#include + +static int before(pa_rtpoll_item *i) { + pa_log("before"); + return 0; +} + +static void after(pa_rtpoll_item *i) { + pa_log("after"); +} + +static int worker(pa_rtpoll_item *w) { + pa_log("worker"); + return 0; +} + +int main(int argc, char *argv[]) { + pa_rtpoll *p; + pa_rtpoll_item *i, *w; + struct pollfd *pollfd; + + pa_rtsig_configure(SIGRTMIN+10, SIGRTMAX); + + p = pa_rtpoll_new(); + + i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1); + pa_rtpoll_item_set_before_callback(i, before); + pa_rtpoll_item_set_after_callback(i, after); + + pollfd = pa_rtpoll_item_get_pollfd(i, NULL); + pollfd->fd = 0; + pollfd->events = POLLIN; + + w = pa_rtpoll_item_new(p, PA_RTPOLL_NORMAL, 0); + pa_rtpoll_item_set_before_callback(w, worker); + + pa_rtpoll_install(p); + pa_rtpoll_set_timer_periodic(p, 10000000); /* 10 s */ + + pa_rtpoll_run(p, 1); + + pa_rtpoll_item_free(i); + + i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1); + pa_rtpoll_item_set_before_callback(i, before); + pa_rtpoll_item_set_after_callback(i, after); + + pollfd = pa_rtpoll_item_get_pollfd(i, NULL); + pollfd->fd = 0; + pollfd->events = POLLIN; + + pa_rtpoll_run(p, 1); + + pa_rtpoll_item_free(i); + + pa_rtpoll_item_free(w); + + pa_rtpoll_free(p); + + return 0; +} diff --git a/src/tests/sig2str-test.c b/src/tests/sig2str-test.c new file mode 100644 index 00000000..52cb9db4 --- /dev/null +++ b/src/tests/sig2str-test.c @@ -0,0 +1,39 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include + +int main(int argc, char *argv[]) { + int sig; + + for (sig = -1; sig <= NSIG; sig++) + printf("%i = %s\n", sig, pa_sig2str(sig)); + + return 0; +} diff --git a/src/tests/smoother-test.c b/src/tests/smoother-test.c new file mode 100644 index 00000000..caa7df70 --- /dev/null +++ b/src/tests/smoother-test.c @@ -0,0 +1,80 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include + +int main(int argc, char*argv[]) { + pa_usec_t x; + unsigned u = 0; + pa_smoother *s; + int m; + +/* unsigned msec[] = { */ +/* 200, 200, */ +/* 300, 320, */ +/* 400, 400, */ +/* 500, 480, */ +/* 0, 0 */ +/* }; */ + + int msec[200]; + + srand(0); + + for (m = 0, u = 0; u < PA_ELEMENTSOF(msec)-2; u+= 2) { + + msec[u] = m+1; + msec[u+1] = m + rand() % 2000 - 1000; + + m += rand() % 100; + + if (msec[u+1] < 0) + msec[u+1] = 0; + } + + msec[PA_ELEMENTSOF(msec)-2] = 0; + msec[PA_ELEMENTSOF(msec)-1] = 0; + + s = pa_smoother_new(1000*PA_USEC_PER_MSEC, 2000*PA_USEC_PER_MSEC, TRUE); + + for (x = 0, u = 0; x < PA_USEC_PER_SEC * 10; x += PA_USEC_PER_MSEC) { + + while (msec[u] > 0 && (pa_usec_t) msec[u]*PA_USEC_PER_MSEC < x) { + pa_smoother_put(s, msec[u]*PA_USEC_PER_MSEC, msec[u+1]*PA_USEC_PER_MSEC); + printf("%i\t\t%i\n", msec[u], msec[u+1]); + u += 2; + } + + printf("%llu\t%llu\n", x/PA_USEC_PER_MSEC, pa_smoother_get(s, x)/PA_USEC_PER_MSEC); + } + + pa_smoother_free(s); + + return 0; +} diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 9d0e5de1..558e53a5 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -23,18 +23,19 @@ #include #endif -#include #include #include #include #include #include +#include #include -#include +#include static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { + pa_assert_se(pa_threaded_mainloop_in_thread(userdata)); fprintf(stderr, "TIME EVENT START\n"); pa_threaded_mainloop_signal(userdata, 1); fprintf(stderr, "TIME EVENT END\n"); @@ -45,15 +46,15 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { pa_threaded_mainloop *m; struct timeval tv; - m = pa_threaded_mainloop_new(); - assert(m); - a = pa_threaded_mainloop_get_api(m); - assert(a); + pa_assert_se(m = pa_threaded_mainloop_new()); + pa_assert_se(a = pa_threaded_mainloop_get_api(m)); pa_threaded_mainloop_start(m); pa_threaded_mainloop_lock(m); + pa_assert_se(!pa_threaded_mainloop_in_thread(m)); + pa_gettimeofday(&tv); tv.tv_sec += 5; a->time_new(a, &tv, tcb, m); diff --git a/src/tests/thread-test.c b/src/tests/thread-test.c index 2153c985..72dde6cb 100644 --- a/src/tests/thread-test.c +++ b/src/tests/thread-test.c @@ -42,7 +42,7 @@ static void once_func(void) { pa_log("once!"); } -static pa_once_t once = PA_ONCE_INIT; +static pa_once once = PA_ONCE_INIT; static void thread_func(void *data) { pa_tls_set(tls, data); @@ -72,7 +72,7 @@ static void thread_func(void *data) { pa_mutex_unlock(mutex); - pa_once(&once, once_func); + pa_run_once(&once, once_func); pa_cond_signal(cond2, 0); @@ -98,7 +98,7 @@ int main(int argc, char *argv[]) { assert(pa_thread_is_running(pa_thread_self())); - mutex = pa_mutex_new(0); + mutex = pa_mutex_new(FALSE, FALSE); cond1 = pa_cond_new(); cond2 = pa_cond_new(); tls = pa_tls_new(pa_xfree); -- cgit From 7e0f547f2fd8ddfae1d807334dbc3428a3dfe374 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Nov 2007 02:45:07 +0000 Subject: add support for 32bit integer samples git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2037 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/resampler-test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/tests') diff --git a/src/tests/resampler-test.c b/src/tests/resampler-test.c index 3b4a7386..5295995b 100644 --- a/src/tests/resampler-test.c +++ b/src/tests/resampler-test.c @@ -71,6 +71,16 @@ static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) { break; } + case PA_SAMPLE_S32NE: + case PA_SAMPLE_S32RE: { + uint32_t *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) + printf("0x%08x ", *(u++)); + + break; + } + case PA_SAMPLE_FLOAT32NE: case PA_SAMPLE_FLOAT32RE: { float *u = d; @@ -137,6 +147,23 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) { break; } + case PA_SAMPLE_S32NE: + case PA_SAMPLE_S32RE: { + uint32_t *u = d; + + u[0] = 0x00000001; + u[1] = 0xFFFF0002; + u[2] = 0x7FFF0003; + u[3] = 0x80000004; + u[4] = 0x9fff0005; + u[5] = 0x3fff0006; + u[6] = 0x10007; + u[7] = 0xF0000008; + u[8] = 0x200009; + u[9] = 0x21000A; + break; + } + case PA_SAMPLE_FLOAT32NE: case PA_SAMPLE_FLOAT32RE: { float *u = d; -- cgit From b0a68fd09ff6fa62accdc29307c5f445cc054a94 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 9 Nov 2007 17:11:45 +0000 Subject: optimize mixing code a bit. Add mixers for S32LE, S32BE, ULAW, ALAW and FLOAT32BE. Add volume adjusters for FLOAT32BE, ALAW, ULAW. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2041 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/mix-test.c | 261 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 src/tests/mix-test.c (limited to 'src/tests') diff --git a/src/tests/mix-test.c b/src/tests/mix-test.c new file mode 100644 index 00000000..d07b1b0c --- /dev/null +++ b/src/tests/mix-test.c @@ -0,0 +1,261 @@ +/* $Id: resampler-test.c 2037 2007-11-09 02:45:07Z lennart $ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +static float swap_float(float a) { + uint32_t *b = (uint32_t*) &a; + *b = PA_UINT32_SWAP(*b); + return a; +} + +static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) { + void *d; + unsigned i; + + d = pa_memblock_acquire(chunk->memblock); + + switch (ss->format) { + + case PA_SAMPLE_U8: + case PA_SAMPLE_ULAW: + case PA_SAMPLE_ALAW: { + uint8_t *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) + printf("0x%02x ", *(u++)); + + break; + } + + case PA_SAMPLE_S16NE: + case PA_SAMPLE_S16RE: { + uint16_t *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) + printf("0x%04x ", *(u++)); + + break; + } + + case PA_SAMPLE_S32NE: + case PA_SAMPLE_S32RE: { + uint32_t *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) + printf("0x%08x ", *(u++)); + + break; + } + + case PA_SAMPLE_FLOAT32NE: + case PA_SAMPLE_FLOAT32RE: { + float *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) { + printf("%1.5f ", ss->format == PA_SAMPLE_FLOAT32NE ? *u : swap_float(*u)); + u++; + } + + break; + } + + default: + pa_assert_not_reached(); + } + + printf("\n"); + + pa_memblock_release(chunk->memblock); +} + +static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) { + pa_memblock *r; + void *d; + unsigned i; + + pa_assert_se(r = pa_memblock_new(pool, pa_frame_size(ss) * 10)); + d = pa_memblock_acquire(r); + + switch (ss->format) { + + case PA_SAMPLE_U8: + case PA_SAMPLE_ULAW: + case PA_SAMPLE_ALAW: { + uint8_t *u = d; + + u[0] = 0x00; + u[1] = 0xFF; + u[2] = 0x7F; + u[3] = 0x80; + u[4] = 0x9f; + u[5] = 0x3f; + u[6] = 0x1; + u[7] = 0xF0; + u[8] = 0x20; + u[9] = 0x21; + break; + } + + case PA_SAMPLE_S16NE: + case PA_SAMPLE_S16RE: { + uint16_t *u = d; + + u[0] = 0x0000; + u[1] = 0xFFFF; + u[2] = 0x7FFF; + u[3] = 0x8000; + u[4] = 0x9fff; + u[5] = 0x3fff; + u[6] = 0x1; + u[7] = 0xF000; + u[8] = 0x20; + u[9] = 0x21; + break; + } + + case PA_SAMPLE_S32NE: + case PA_SAMPLE_S32RE: { + uint32_t *u = d; + + u[0] = 0x00000001; + u[1] = 0xFFFF0002; + u[2] = 0x7FFF0003; + u[3] = 0x80000004; + u[4] = 0x9fff0005; + u[5] = 0x3fff0006; + u[6] = 0x10007; + u[7] = 0xF0000008; + u[8] = 0x200009; + u[9] = 0x21000A; + break; + } + + case PA_SAMPLE_FLOAT32NE: + case PA_SAMPLE_FLOAT32RE: { + float *u = d; + + u[0] = 0.0; + u[1] = -1.0; + u[2] = 1.0; + u[3] = 4711; + u[4] = 0.222; + u[5] = 0.33; + u[6] = -.3; + u[7] = 99; + u[8] = -0.555; + u[9] = -.123; + + if (ss->format == PA_SAMPLE_FLOAT32RE) + for (i = 0; i < 10; i++) + u[i] = swap_float(u[i]); + + break; + } + + default: + pa_assert_not_reached(); + } + + pa_memblock_release(r); + + return r; +} + +int main(int argc, char *argv[]) { + pa_mempool *pool; + pa_sample_spec a; + pa_cvolume v; + + oil_init(); + pa_log_set_maximal_level(PA_LOG_DEBUG); + + pa_assert_se(pool = pa_mempool_new(FALSE)); + + a.channels = 1; + a.rate = 44100; + + v.channels = a.channels; + v.values[0] = pa_sw_volume_from_linear(0.9); + + for (a.format = 0; a.format < PA_SAMPLE_MAX; a.format ++) { + pa_memchunk i, j, k; + pa_mix_info m[2]; + void *ptr; + + printf("=== mixing: %s\n", pa_sample_format_to_string(a.format)); + + /* Generate block */ + i.memblock = generate_block(pool, &a); + i.length = pa_memblock_get_length(i.memblock); + i.index = 0; + + /* Make a copy */ + j = i; + pa_memblock_ref(j.memblock); + pa_memchunk_make_writable(&j, 0); + + /* Adjust volume of the copy */ + pa_volume_memchunk(&j, &a, &v); + + m[0].chunk = i; + m[0].volume.values[0] = PA_VOLUME_NORM; + m[0].volume.channels = a.channels; + m[1].chunk = j; + m[1].volume.values[0] = PA_VOLUME_NORM; + m[1].volume.channels = a.channels; + + k.memblock = pa_memblock_new(pool, i.length); + k.length = i.length; + k.index = 0; + + ptr = (uint8_t*) pa_memblock_acquire(k.memblock) + k.index; + pa_mix(m, 2, ptr, k.length, &a, NULL, FALSE); + pa_memblock_release(k.memblock); + + dump_block(&a, &i); + dump_block(&a, &j); + dump_block(&a, &k); + + pa_memblock_unref(i.memblock); + pa_memblock_unref(j.memblock); + pa_memblock_unref(k.memblock); + } + + pa_mempool_free(pool); + + return 0; +} -- cgit From f873a2a22441d5eaacc5cbb502cbde829ee30a73 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 11 Nov 2007 02:30:59 +0000 Subject: add a simple fully-automatic fully-linearupmixer/downmixer and enable it by default git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2044 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/remix-test.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ src/tests/resampler-test.c | 4 +- 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/tests/remix-test.c (limited to 'src/tests') diff --git a/src/tests/remix-test.c b/src/tests/remix-test.c new file mode 100644 index 00000000..d2fa6943 --- /dev/null +++ b/src/tests/remix-test.c @@ -0,0 +1,91 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +int main(int argc, char *argv[]) { + + static const pa_channel_map maps[] = { + { 1, { PA_CHANNEL_POSITION_MONO } }, + { 2, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } }, + { 3, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_CENTER } }, + { 3, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_LFE } }, + { 3, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_CENTER } }, + { 4, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_CENTER, PA_CHANNEL_POSITION_LFE } }, + { 4, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_CENTER, PA_CHANNEL_POSITION_REAR_CENTER } }, + { 4, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT } }, + { 5, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT, PA_CHANNEL_POSITION_CENTER } }, + { 5, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT, PA_CHANNEL_POSITION_LFE } }, + { 6, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT, PA_CHANNEL_POSITION_LFE, PA_CHANNEL_POSITION_CENTER } }, + { 8, { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT, PA_CHANNEL_POSITION_REAR_LEFT, PA_CHANNEL_POSITION_REAR_RIGHT, PA_CHANNEL_POSITION_LFE, PA_CHANNEL_POSITION_CENTER, PA_CHANNEL_POSITION_SIDE_LEFT, PA_CHANNEL_POSITION_SIDE_RIGHT } }, + { 0, { 0 } } + }; + + unsigned i, j; + pa_mempool *pool; + + oil_init(); + pa_log_set_maximal_level(PA_LOG_DEBUG); + + pa_assert_se(pool = pa_mempool_new(FALSE)); + + for (i = 0; maps[i].channels > 0; i++) + for (j = 0; maps[j].channels > 0; j++) { + char a[PA_CHANNEL_MAP_SNPRINT_MAX], b[PA_CHANNEL_MAP_SNPRINT_MAX]; + pa_resampler *r; + pa_sample_spec ss1, ss2; + + pa_log_info("Converting from '%s' to '%s'.\n", pa_channel_map_snprint(a, sizeof(a), &maps[i]), pa_channel_map_snprint(b, sizeof(b), &maps[j])); + + ss1.channels = maps[i].channels; + ss2.channels = maps[j].channels; + + ss1.rate = ss2.rate = 44100; + ss1.format = ss2.format = PA_SAMPLE_S16NE; + + r = pa_resampler_new(pool, &ss1, &maps[i], &ss2, &maps[j], PA_RESAMPLER_AUTO, 0); + + /* We don't really care for the resampler. We just want to + * see the remixing debug output. */ + + pa_resampler_free(r); + } + + + pa_mempool_free(pool); + + return 0; +} diff --git a/src/tests/resampler-test.c b/src/tests/resampler-test.c index 5295995b..820a0c1e 100644 --- a/src/tests/resampler-test.c +++ b/src/tests/resampler-test.c @@ -222,8 +222,8 @@ int main(int argc, char *argv[]) { pa_sample_format_to_string(b.format), pa_sample_format_to_string(a.format)); - pa_assert_se(forth = pa_resampler_new(pool, &a, NULL, &b, NULL, PA_RESAMPLER_AUTO, FALSE)); - pa_assert_se(back = pa_resampler_new(pool, &b, NULL, &a, NULL, PA_RESAMPLER_AUTO, FALSE)); + pa_assert_se(forth = pa_resampler_new(pool, &a, NULL, &b, NULL, PA_RESAMPLER_AUTO, 0)); + pa_assert_se(back = pa_resampler_new(pool, &b, NULL, &a, NULL, PA_RESAMPLER_AUTO, 0)); i.memblock = generate_block(pool, &a); i.length = pa_memblock_get_length(i.memblock); -- cgit From 95a98fe6f2002c9dd448b70bb6944541b5616df3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 24 Nov 2007 16:26:49 +0000 Subject: Add new subsystem for applying envelopes (such as volume ramps) to audio signals git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2082 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/envelope-test.c | 248 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 src/tests/envelope-test.c (limited to 'src/tests') diff --git a/src/tests/envelope-test.c b/src/tests/envelope-test.c new file mode 100644 index 00000000..240747d7 --- /dev/null +++ b/src/tests/envelope-test.c @@ -0,0 +1,248 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +const pa_envelope_def ramp_down = { + .n_points = 2, + .points_x = { 100*PA_USEC_PER_MSEC, 300*PA_USEC_PER_MSEC }, + .points_y = { + .f = { 1.0, 0.2 }, + .i = { 0x10000, 0x10000/5 } + } +}; + +const pa_envelope_def ramp_up = { + .n_points = 2, + .points_x = { 100*PA_USEC_PER_MSEC, 300*PA_USEC_PER_MSEC }, + .points_y = { + .f = { 0.2, 1.0 }, + .i = { 0x10000/5, 0x10000 } + } +}; + +const pa_envelope_def ramp_down2 = { + .n_points = 2, + .points_x = { 50*PA_USEC_PER_MSEC, 900*PA_USEC_PER_MSEC }, + .points_y = { + .f = { 0.8, 0.7 }, + .i = { 0x10000*4/5, 0x10000*7/10 } + } +}; + +const pa_envelope_def ramp_up2 = { + .n_points = 2, + .points_x = { 50*PA_USEC_PER_MSEC, 900*PA_USEC_PER_MSEC }, + .points_y = { + .f = { 0.7, 0.9 }, + .i = { 0x10000*7/10, 0x10000*9/10 } + } +}; + +static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) { + void *d; + unsigned i; + + static unsigned j = 0; + + d = pa_memblock_acquire(chunk->memblock); + + switch (ss->format) { + + case PA_SAMPLE_U8: + case PA_SAMPLE_ULAW: + case PA_SAMPLE_ALAW: { + uint8_t *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) + printf("0x%02x ", *(u++)); + + break; + } + + case PA_SAMPLE_S16NE: + case PA_SAMPLE_S16RE: { + int16_t *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) + printf("%i\t%i\n", j++, *(u++)); + + break; + } + + case PA_SAMPLE_S32NE: + case PA_SAMPLE_S32RE: { + int32_t *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) + printf("%i\t%i\n", j++, *(u++)); + + break; + } + + case PA_SAMPLE_FLOAT32NE: + case PA_SAMPLE_FLOAT32RE: { + float *u = d; + + for (i = 0; i < chunk->length / pa_frame_size(ss); i++) { + printf("%i\t%1.3g\n", j++, PA_MAYBE_FLOAT32_SWAP(ss->format == PA_SAMPLE_FLOAT32RE, *u)); + u++; + } + + break; + } + + default: + pa_assert_not_reached(); + } + + printf("\n"); + + pa_memblock_release(chunk->memblock); +} + +static pa_memblock * generate_block(pa_mempool *pool, const pa_sample_spec *ss) { + pa_memblock *block; + void *d; + unsigned n_samples; + + block = pa_memblock_new(pool, pa_bytes_per_second(ss)); + n_samples = pa_memblock_get_length(block) / pa_sample_size(ss); + + d = pa_memblock_acquire(block); + + switch (ss->format) { + + case PA_SAMPLE_S16NE: + case PA_SAMPLE_S16RE: { + int16_t *i; + + for (i = d; n_samples > 0; n_samples--, i++) + *i = 0x7FFF; + + break; + } + + case PA_SAMPLE_S32NE: + case PA_SAMPLE_S32RE: { + int32_t *i; + + for (i = d; n_samples > 0; n_samples--, i++) + *i = 0x7FFFFFFF; + + break; + } + + case PA_SAMPLE_FLOAT32RE: + case PA_SAMPLE_FLOAT32NE: { + float *f; + + for (f = d; n_samples > 0; n_samples--, f++) + *f = PA_MAYBE_FLOAT32_SWAP(ss->format == PA_SAMPLE_FLOAT32RE, 1.0); + + break; + } + + default: + pa_assert_not_reached(); + } + + pa_memblock_release(block); + return block; +} + +int main(int argc, char *argv[]) { + pa_mempool *pool; + pa_memblock *block; + pa_memchunk chunk; + pa_envelope *envelope; + pa_envelope_item *item1, *item2; + + const pa_sample_spec ss = { + .format = PA_SAMPLE_S16NE, + .channels = 1, + .rate = 200 + }; + + const pa_cvolume v = { + .channels = 1, + .values = { PA_VOLUME_NORM, PA_VOLUME_NORM/2 } + }; + + oil_init(); + pa_log_set_maximal_level(PA_LOG_DEBUG); + + pa_assert_se(pool = pa_mempool_new(FALSE)); + pa_assert_se(envelope = pa_envelope_new(&ss)); + + block = generate_block(pool, &ss); + + chunk.memblock = pa_memblock_ref(block); + chunk.length = pa_memblock_get_length(block); + chunk.index = 0; + + pa_volume_memchunk(&chunk, &ss, &v); + + item1 = pa_envelope_add(envelope, &ramp_down); + item2 = pa_envelope_add(envelope, &ramp_down2); + pa_envelope_apply(envelope, &chunk); + dump_block(&ss, &chunk); + + pa_memblock_unref(chunk.memblock); + + chunk.memblock = pa_memblock_ref(block); + chunk.length = pa_memblock_get_length(block); + chunk.index = 0; + + item1 = pa_envelope_replace(envelope, item1, &ramp_up); + item2 = pa_envelope_replace(envelope, item2, &ramp_up2); + pa_envelope_apply(envelope, &chunk); + dump_block(&ss, &chunk); + + pa_memblock_unref(chunk.memblock); + + pa_envelope_remove(envelope, item1); + pa_envelope_remove(envelope, item2); + pa_envelope_free(envelope); + + pa_memblock_unref(block); + + pa_mempool_free(pool); + + return 0; +} -- cgit From 63c616eeccdea593a1c8dc65405e02c2a71038fe Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 23 Dec 2007 20:12:37 +0000 Subject: add new property list implementation git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2085 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/proplist-test.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/tests/proplist-test.c (limited to 'src/tests') diff --git a/src/tests/proplist-test.c b/src/tests/proplist-test.c new file mode 100644 index 00000000..b88f4e5e --- /dev/null +++ b/src/tests/proplist-test.c @@ -0,0 +1,61 @@ +/* $Id$ */ + +/*** + 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 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include + +int main(int argc, char*argv[]) { + pa_proplist *a, *b; + char *s, *t; + + a = pa_proplist_new(); + pa_assert_se(pa_proplist_puts(a, PA_PROP_MEDIA_TITLE, "Brandenburgische Konzerte") == 0); + pa_assert_se(pa_proplist_puts(a, PA_PROP_MEDIA_ARTIST, "Johann Sebastian Bach") == 0); + + b = pa_proplist_new(); + pa_assert_se(pa_proplist_puts(b, PA_PROP_MEDIA_TITLE, "Goldbergvariationen") == 0); + pa_assert_se(pa_proplist_put(b, PA_PROP_MEDIA_ICON, "\0\1\2\3\4\5\6\7", 8) == 0); + + pa_proplist_merge(a, b); + + pa_assert_se(!pa_proplist_gets(a, PA_PROP_MEDIA_ICON)); + + printf("%s\n", pa_strnull(pa_proplist_gets(a, PA_PROP_MEDIA_TITLE))); + pa_assert_se(pa_proplist_remove(b, PA_PROP_MEDIA_TITLE) == 0); + + s = pa_proplist_to_string(a); + t = pa_proplist_to_string(b); + printf("---\n%s---\n%s", s, t); + pa_xfree(s); + pa_xfree(t); + + pa_proplist_free(a); + pa_proplist_free(b); + + return 0; +} -- cgit From 9774cc79651d96df77f13338464d3e2b35d6dabc Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Fri, 4 Jan 2008 14:52:44 +0000 Subject: Add forgotted #ifdef __linux__ and only use SIGRTMIN if it is defined. Fixes compilation on non-linux platforms like GNU/kFreeBSD. Thanks to Aurelien Jarno for the patch git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2095 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/rtpoll-test.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/tests') diff --git a/src/tests/rtpoll-test.c b/src/tests/rtpoll-test.c index 3ab992a1..e6493771 100644 --- a/src/tests/rtpoll-test.c +++ b/src/tests/rtpoll-test.c @@ -49,7 +49,9 @@ int main(int argc, char *argv[]) { pa_rtpoll_item *i, *w; struct pollfd *pollfd; +#ifdef SIGRTMIN pa_rtsig_configure(SIGRTMIN+10, SIGRTMAX); +#endif p = pa_rtpoll_new(); -- cgit