summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/asyncmsgq-test.c108
-rw-r--r--src/tests/asyncq-test.c85
-rw-r--r--src/tests/channelmap-test.c17
-rw-r--r--src/tests/close-test.c20
-rw-r--r--src/tests/cpulimit-test.c18
-rw-r--r--src/tests/envelope-test.c246
-rw-r--r--src/tests/flist-test.c12
-rw-r--r--src/tests/get-binary-name-test.c8
-rw-r--r--src/tests/hook-list-test.c18
-rw-r--r--src/tests/interpol-test.c60
-rw-r--r--src/tests/ipacl-test.c16
-rw-r--r--src/tests/mainloop-test.c12
-rw-r--r--src/tests/mcalign-test.c17
-rw-r--r--src/tests/memblock-test.c92
-rw-r--r--src/tests/memblockq-test.c103
-rw-r--r--src/tests/mix-test.c259
-rw-r--r--src/tests/pacat-simple.c20
-rw-r--r--src/tests/parec-simple.c14
-rw-r--r--src/tests/proplist-test.c60
-rw-r--r--src/tests/queue-test.c67
-rw-r--r--src/tests/remix-test.c89
-rw-r--r--src/tests/resampler-test.c252
-rw-r--r--src/tests/rtpoll-test.c91
-rw-r--r--src/tests/rtstutter.c117
-rw-r--r--src/tests/sig2str-test.c37
-rw-r--r--src/tests/smoother-test.c78
-rw-r--r--src/tests/stripnul.c70
-rw-r--r--src/tests/strlist-test.c9
-rw-r--r--src/tests/sync-playback.c30
-rw-r--r--src/tests/thread-mainloop-test.c31
-rw-r--r--src/tests/thread-test.c40
-rw-r--r--src/tests/utf8-test.c6
-rw-r--r--src/tests/voltest.c6
33 files changed, 1840 insertions, 268 deletions
diff --git a/src/tests/asyncmsgq-test.c b/src/tests/asyncmsgq-test.c
new file mode 100644
index 00000000..08ad3dd4
--- /dev/null
+++ b/src/tests/asyncmsgq-test.c
@@ -0,0 +1,108 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <pulse/util.h>
+#include <pulse/xmalloc.h>
+#include <pulsecore/asyncmsgq.h>
+#include <pulsecore/thread.h>
+#include <pulsecore/log.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
+
+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..4e8a1207
--- /dev/null
+++ b/src/tests/asyncq-test.c
@@ -0,0 +1,85 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <pulse/util.h>
+#include <pulse/xmalloc.h>
+#include <pulsecore/asyncq.h>
+#include <pulsecore/thread.h>
+#include <pulsecore/log.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
+
+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), TRUE);
+ 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, TRUE);
+
+ 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/channelmap-test.c b/src/tests/channelmap-test.c
index 124ce576..9c234602 100644
--- a/src/tests/channelmap-test.c
+++ b/src/tests/channelmap-test.c
@@ -1,33 +1,34 @@
-/* $Id$ */
-
#include <stdio.h>
#include <assert.h>
#include <pulse/channelmap.h>
-#include <pulsecore/gccmacro.h>
+#include <pulse/gccmacro.h>
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, 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_init_extend(&map, 14, 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/close-test.c b/src/tests/close-test.c
new file mode 100644
index 00000000..7a6fec57
--- /dev/null
+++ b/src/tests/close-test.c
@@ -0,0 +1,20 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <pulsecore/core-util.h>
+
+int main(int argc, char *argv[]) {
+
+ open("/dev/null", O_RDONLY);
+ open("/dev/null", O_RDONLY);
+ open("/dev/null", O_RDONLY);
+ open("/dev/null", O_RDONLY);
+
+ pa_close_all(5, -1);
+
+ return 0;
+}
diff --git a/src/tests/cpulimit-test.c b/src/tests/cpulimit-test.c
index 2302a26d..b7145e8a 100644
--- a/src/tests/cpulimit-test.c
+++ b/src/tests/cpulimit-test.c
@@ -1,18 +1,16 @@
-/* $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
@@ -30,7 +28,7 @@
#include <signal.h>
#include <pulse/mainloop.h>
-#include <pulsecore/gccmacro.h>
+#include <pulse/gccmacro.h>
#ifdef TEST2
#include <pulse/mainloop-signal.h>
@@ -47,7 +45,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 +57,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 +75,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 +84,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/envelope-test.c b/src/tests/envelope-test.c
new file mode 100644
index 00000000..9f914553
--- /dev/null
+++ b/src/tests/envelope-test.c
@@ -0,0 +1,246 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <pulse/sample.h>
+#include <pulse/volume.h>
+#include <pulse/timeval.h>
+
+#include <pulsecore/envelope.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/endianmacros.h>
+#include <pulsecore/memblock.h>
+#include <pulsecore/sample-util.h>
+
+#include <liboil/liboil.h>
+
+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;
+}
diff --git a/src/tests/flist-test.c b/src/tests/flist-test.c
index 06d68311..b2c648da 100644
--- a/src/tests/flist-test.c
+++ b/src/tests/flist-test.c
@@ -1,18 +1,16 @@
-/* $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
@@ -41,7 +39,7 @@ static int quit = 0;
static void spin(void) {
int k;
-
+
/* Spin a little */
k = rand() % 10000;
for (; k > 0; k--)
@@ -100,6 +98,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..7c7a8996 100644
--- a/src/tests/get-binary-name-test.c
+++ b/src/tests/get-binary-name-test.c
@@ -1,18 +1,16 @@
-/* $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
diff --git a/src/tests/hook-list-test.c b/src/tests/hook-list-test.c
index d68d1b7d..60b965cd 100644
--- a/src/tests/hook-list-test.c
+++ b/src/tests/hook-list-test.c
@@ -1,14 +1,16 @@
-/* $Id$ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <pulsecore/hook-list.h>
#include <pulsecore/log.h>
-static pa_hook_result_t func1(const char*hook_data, const char*call_data, const char*slot_data) {
+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*hook_data, const char*call_data, const char*slot_data) {
+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;
}
@@ -19,10 +21,10 @@ int main(int argc, char *argv[]) {
pa_hook_init(&hook, (void*) "hook");
- 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_connect(&hook, PA_HOOK_LATE, (pa_hook_cb_t) func1, (void*) "slot1");
+ slot = pa_hook_connect(&hook, PA_HOOK_NORMAL, (pa_hook_cb_t) func2, (void*) "slot2");
+ pa_hook_connect(&hook, PA_HOOK_NORMAL, (pa_hook_cb_t) func1, (void*) "slot3");
+
pa_hook_fire(&hook, (void*) "call1");
pa_hook_slot_free(slot);
@@ -30,6 +32,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..9d930774 100644
--- a/src/tests/interpol-test.c
+++ b/src/tests/interpol-test.c
@@ -1,18 +1,16 @@
-/* $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
@@ -42,10 +40,9 @@ 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) {
-
+static void stream_write_cb(pa_stream *p, size_t nbytes, void *userdata) {
/* Just some silence */
- pa_stream_write(p, pa_xmalloc0(length), length, pa_xfree, 0, PA_SEEK_RELATIVE);
+ pa_stream_write(p, pa_xmalloc0(nbytes), nbytes, pa_xfree, 0, PA_SEEK_RELATIVE);
}
/* This is called whenever the context status changes */
@@ -57,26 +54,26 @@ 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 = {
.format = PA_SAMPLE_S16LE,
.rate = 44100,
- .channels = 1
+ .channels = 2
};
-
+
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,36 +105,41 @@ 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_bool_t success = FALSE, changed = FALSE;
pa_usec_t t, rtc;
struct timeval now, tv;
-
+ pa_bool_t playing = FALSE;
+
pa_threaded_mainloop_lock(m);
if (stream) {
const pa_timing_info *info;
-
+
if (pa_stream_get_time(stream, &t) >= 0)
- success = 1;
+ success = TRUE;
- 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;
+ if ((info = pa_stream_get_timing_info(stream))) {
+ if (memcmp(&last_info, &info->timestamp, sizeof(struct timeval))) {
+ changed = TRUE;
last_info = info->timestamp;
}
+ if (info->playing)
+ playing = TRUE;
+ }
}
-
+
pa_threaded_mainloop_unlock(m);
-
- if (success) {
- pa_gettimeofday(&now);
+ pa_gettimeofday(&now);
+
+ if (success) {
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\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, playing);
+ fflush(stdout);
old_t = t;
old_rtc = rtc;
}
@@ -156,7 +158,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 +166,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..bcdd469a 100644
--- a/src/tests/ipacl-test.c
+++ b/src/tests/ipacl-test.c
@@ -1,5 +1,3 @@
-/* $Id$ */
-
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -37,13 +35,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 +64,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 +84,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 +94,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 +129,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..9fa2e466 100644
--- a/src/tests/mainloop-test.c
+++ b/src/tests/mainloop-test.c
@@ -1,18 +1,16 @@
-/* $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
@@ -29,9 +27,9 @@
#include <assert.h>
#include <pulse/timeval.h>
+#include <pulse/gccmacro.h>
#include <pulsecore/core-util.h>
-#include <pulsecore/gccmacro.h>
#ifdef GLIB_MAIN_LOOP
@@ -121,6 +119,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 1584256c..9e358359 100644
--- a/src/tests/mcalign-test.c
+++ b/src/tests/mcalign-test.c
@@ -1,18 +1,16 @@
-/* $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.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
@@ -31,9 +29,10 @@
#include <stdlib.h>
#include <time.h>
+#include <pulse/gccmacro.h>
+
#include <pulsecore/core-util.h>
#include <pulsecore/mcalign.h>
-#include <pulsecore/gccmacro.h>
/* A simple program for testing pa_mcalign */
@@ -45,7 +44,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));
@@ -66,13 +65,15 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
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);
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);
diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c
index c2dd2efa..6da1b1e9 100644
--- a/src/tests/memblock-test.c
+++ b/src/tests/memblock-test.c
@@ -1,18 +1,16 @@
-/* $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
@@ -23,11 +21,11 @@
#include <config.h>
#endif
-#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <pulsecore/memblock.h>
+#include <pulsecore/macro.h>
#include <pulse/xmalloc.h>
static void release_cb(pa_memimport *i, uint32_t block_id, void *userdata) {
@@ -46,24 +44,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[]) {
@@ -79,7 +77,7 @@ int main(int argc, char *argv[]) {
char *x;
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);
@@ -87,20 +85,20 @@ 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);
-
+
+ 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));
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));
x = pa_memblock_acquire(blocks[2]);
snprintf(x, pa_memblock_get_length(blocks[2]), "%s", txt);
- pa_memblock_release(blocks[1]);
+ pa_memblock_release(blocks[2]);
blocks[3] = pa_memblock_new_malloced(pool_a, pa_xstrdup(txt), sizeof(txt));
blocks[4] = NULL;
@@ -109,35 +107,35 @@ 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);
+ pa_assert(mb_c);
x = pa_memblock_acquire(mb_c);
printf("1 data=%s\n", x);
pa_memblock_release(mb_c);
@@ -145,23 +143,23 @@ 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);
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);
-
+
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 02848eb2..7bf992a1 100644
--- a/src/tests/memblockq-test.c
+++ b/src/tests/memblockq-test.c
@@ -1,18 +1,16 @@
-/* $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
@@ -26,58 +24,85 @@
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
+#include <signal.h>
#include <pulsecore/memblockq.h>
#include <pulsecore/log.h>
+static void dump(pa_memblockq *bq) {
+ printf(">");
+
+ for (;;) {
+ pa_memchunk out;
+ char *e;
+ size_t n;
+ void *q;
+
+ if (pa_memblockq_peek(bq, &out) < 0)
+ break;
+
+ q = pa_memblock_acquire(out.memblock);
+ for (e = (char*) q + 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.length);
+ }
+
+ printf("<\n");
+}
+
int main(int argc, char *argv[]) {
int ret;
pa_mempool *p;
pa_memblockq *bq;
pa_memchunk chunk1, chunk2, chunk3, chunk4;
- pa_memblock *silence;
+ pa_memchunk silence;
pa_log_set_maximal_level(PA_LOG_DEBUG);
p = pa_mempool_new(0);
-
- silence = pa_memblock_new_fixed(p, (char*) "__", 2, 1);
- assert(silence);
- bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, silence);
+ silence.memblock = pa_memblock_new_fixed(p, (char*) "__", 2, 1);
+ assert(silence.memblock);
+ silence.index = 0;
+ silence.length = pa_memblock_get_length(silence.memblock);
+
+ bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, 40, &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);
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);
+
+ ret = pa_memblockq_push(bq, &chunk3);
+ assert(ret == 0);
+
+ ret = pa_memblockq_push(bq, &chunk4);
assert(ret == 0);
pa_memblockq_seek(bq, -6, 0);
@@ -85,7 +110,7 @@ int main(int argc, char *argv[]) {
assert(ret == 0);
pa_memblockq_seek(bq, -2, 0);
- ret = pa_memblockq_push(bq, &chunk3);
+ ret = pa_memblockq_push(bq, &chunk1);
assert(ret == 0);
pa_memblockq_seek(bq, -10, 0);
@@ -115,39 +140,25 @@ 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;
+ pa_memblockq_seek(bq, 30, PA_SEEK_RELATIVE);
- 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);
+ dump(bq);
+
+ pa_memblockq_rewind(bq, 52);
+
+ dump(bq);
- 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(silence.memblock);
pa_memblock_unref(chunk1.memblock);
pa_memblock_unref(chunk2.memblock);
pa_memblock_unref(chunk3.memblock);
pa_memblock_unref(chunk4.memblock);
-
+
+ pa_mempool_free(p);
+
return 0;
}
diff --git a/src/tests/mix-test.c b/src/tests/mix-test.c
new file mode 100644
index 00000000..f3f6f829
--- /dev/null
+++ b/src/tests/mix-test.c
@@ -0,0 +1,259 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <stdio.h>
+
+#include <pulse/sample.h>
+#include <pulse/volume.h>
+
+#include <pulsecore/resampler.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/endianmacros.h>
+#include <pulsecore/memblock.h>
+#include <pulsecore/sample-util.h>
+
+#include <liboil/liboil.h>
+
+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;
+}
diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c
index 364e1ad6..b26e4b68 100644
--- a/src/tests/pacat-simple.c
+++ b/src/tests/pacat-simple.c
@@ -1,18 +1,16 @@
-/* $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
@@ -31,7 +29,7 @@
#include <pulse/simple.h>
#include <pulse/error.h>
-#include <pulsecore/gccmacro.h>
+#include <pulse/gccmacro.h>
#define BUFSIZE 1024
@@ -43,7 +41,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 +59,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 +88,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 +112,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..6c0d529b 100644
--- a/src/tests/parec-simple.c
+++ b/src/tests/parec-simple.c
@@ -1,18 +1,16 @@
-/* $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
@@ -30,7 +28,7 @@
#include <pulse/simple.h>
#include <pulse/error.h>
-#include <pulsecore/gccmacro.h>
+#include <pulse/gccmacro.h>
#define BUFSIZE 1024
@@ -46,7 +44,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 +93,6 @@ finish:
if (s)
pa_simple_free(s);
-
+
return ret;
}
diff --git a/src/tests/proplist-test.c b/src/tests/proplist-test.c
new file mode 100644
index 00000000..20041af6
--- /dev/null
+++ b/src/tests/proplist-test.c
@@ -0,0 +1,60 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <stdio.h>
+
+#include <pulse/proplist.h>
+#include <pulse/xmalloc.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/core-util.h>
+
+int main(int argc, char*argv[]) {
+ pa_proplist *a, *b;
+ char *s, *t;
+
+ a = pa_proplist_new();
+ pa_assert_se(pa_proplist_sets(a, PA_PROP_MEDIA_TITLE, "Brandenburgische Konzerte") == 0);
+ pa_assert_se(pa_proplist_sets(a, PA_PROP_MEDIA_ARTIST, "Johann Sebastian Bach") == 0);
+
+ b = pa_proplist_new();
+ pa_assert_se(pa_proplist_sets(b, PA_PROP_MEDIA_TITLE, "Goldbergvariationen") == 0);
+ pa_assert_se(pa_proplist_set(b, PA_PROP_MEDIA_ICON, "\0\1\2\3\4\5\6\7", 8) == 0);
+
+ pa_proplist_update(a, PA_UPDATE_MERGE, 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_unset(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;
+}
diff --git a/src/tests/queue-test.c b/src/tests/queue-test.c
new file mode 100644
index 00000000..105f094a
--- /dev/null
+++ b/src/tests/queue-test.c
@@ -0,0 +1,67 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <pulse/util.h>
+#include <pulse/xmalloc.h>
+#include <pulsecore/queue.h>
+#include <pulsecore/log.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
+
+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/remix-test.c b/src/tests/remix-test.c
new file mode 100644
index 00000000..4777c150
--- /dev/null
+++ b/src/tests/remix-test.c
@@ -0,0 +1,89 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <stdio.h>
+
+#include <pulse/sample.h>
+#include <pulse/volume.h>
+
+#include <pulsecore/resampler.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/endianmacros.h>
+#include <pulsecore/memblock.h>
+#include <pulsecore/sample-util.h>
+
+#include <liboil/liboil.h>
+
+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
new file mode 100644
index 00000000..1a20be2c
--- /dev/null
+++ b/src/tests/resampler-test.c
@@ -0,0 +1,252 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <stdio.h>
+
+#include <pulse/sample.h>
+#include <pulse/volume.h>
+
+#include <pulsecore/resampler.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/endianmacros.h>
+#include <pulsecore/memblock.h>
+#include <pulsecore/sample-util.h>
+
+#include <liboil/liboil.h>
+
+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.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_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, 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, 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);
+ 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..953fd61d
--- /dev/null
+++ b/src/tests/rtpoll-test.c
@@ -0,0 +1,91 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <signal.h>
+#include <poll.h>
+
+#include <pulsecore/log.h>
+#include <pulsecore/rtpoll.h>
+#include <pulsecore/rtsig.h>
+
+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;
+
+#ifdef SIGRTMIN
+ pa_rtsig_configure(SIGRTMIN+10, SIGRTMAX);
+#endif
+
+ 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_relative(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/rtstutter.c b/src/tests/rtstutter.c
new file mode 100644
index 00000000..91e85c36
--- /dev/null
+++ b/src/tests/rtstutter.c
@@ -0,0 +1,117 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2008 Lennart Poettering
+
+ 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 <config.h>
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <sched.h>
+#include <inttypes.h>
+#include <string.h>
+#include <pthread.h>
+
+#include <pulse/timeval.h>
+#include <pulse/gccmacro.h>
+
+#include <pulsecore/log.h>
+#include <pulsecore/macro.h>
+
+static int msec_lower, msec_upper;
+
+static void* work(void *p) PA_GCC_NORETURN;
+
+static void* work(void *p) {
+ cpu_set_t mask;
+ struct sched_param param;
+
+ pa_log_notice("CPU%i: Created thread.", PA_PTR_TO_INT(p));
+
+ memset(&param, 0, sizeof(param));
+ param.sched_priority = 12;
+ pa_assert_se(pthread_setschedparam(pthread_self(), SCHED_FIFO, &param) == 0);
+
+ CPU_ZERO(&mask);
+ CPU_SET(PA_PTR_TO_INT(p), &mask);
+ pa_assert_se(pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) == 0);
+
+ for (;;) {
+ struct timespec now, end;
+ uint64_t nsec;
+
+ pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_INT(p));
+ sleep(1);
+
+ pa_assert_se(clock_gettime(CLOCK_REALTIME, &end) == 0);
+
+ nsec =
+ (uint64_t) ((((double) rand())*(msec_upper-msec_lower)*PA_NSEC_PER_MSEC)/RAND_MAX) +
+ (uint64_t) (msec_lower*PA_NSEC_PER_MSEC);
+
+ pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_INT(p), (int) (nsec/PA_NSEC_PER_MSEC));
+
+ end.tv_sec += nsec / PA_NSEC_PER_SEC;
+ end.tv_nsec += nsec % PA_NSEC_PER_SEC;
+
+ while ((pa_usec_t) end.tv_nsec > PA_NSEC_PER_SEC) {
+ end.tv_sec++;
+ end.tv_nsec -= PA_NSEC_PER_SEC;
+ }
+
+ do {
+ pa_assert_se(clock_gettime(CLOCK_REALTIME, &now) == 0);
+ } while (now.tv_sec < end.tv_sec ||
+ (now.tv_sec == end.tv_sec && now.tv_nsec < end.tv_nsec));
+ }
+}
+
+int main(int argc, char*argv[]) {
+ int n;
+
+ srand(time(NULL));
+
+ if (argc >= 3) {
+ msec_lower = atoi(argv[1]);
+ msec_upper = atoi(argv[2]);
+ } else if (argc >= 2) {
+ msec_lower = 0;
+ msec_upper = atoi(argv[1]);
+ } else {
+ msec_lower = 0;
+ msec_upper = 1000;
+ }
+
+ pa_assert(msec_upper > 0);
+ pa_assert(msec_upper >= msec_lower);
+
+ pa_log_notice("Creating random latencies in the range of %ims to %ims.", msec_lower, msec_upper);
+
+ for (n = 1; n < sysconf(_SC_NPROCESSORS_CONF); n++) {
+ pthread_t t;
+ pa_assert_se(pthread_create(&t, NULL, work, PA_INT_TO_PTR(n)) == 0);
+ }
+
+ work(PA_INT_TO_PTR(0));
+
+ return 0;
+}
diff --git a/src/tests/sig2str-test.c b/src/tests/sig2str-test.c
new file mode 100644
index 00000000..d64a8902
--- /dev/null
+++ b/src/tests/sig2str-test.c
@@ -0,0 +1,37 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <signal.h>
+#include <stdio.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/core-util.h>
+
+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..b78f3c91
--- /dev/null
+++ b/src/tests/smoother-test.c
@@ -0,0 +1,78 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <pulsecore/time-smoother.h>
+#include <pulse/timeval.h>
+
+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); u+= 2) {
+
+ msec[u] = m+1 + (rand() % 100) - 50;
+ msec[u+1] = m + (rand() % 2000) - 1000;
+
+ m += rand() % 100;
+
+ if (msec[u] < 0)
+ msec[u] = 0;
+
+ if (msec[u+1] < 0)
+ msec[u+1] = 0;
+ }
+
+ s = pa_smoother_new(700*PA_USEC_PER_MSEC, 2000*PA_USEC_PER_MSEC, TRUE, 6);
+
+ for (x = 0, u = 0; x < PA_USEC_PER_SEC * 10; x += PA_USEC_PER_MSEC) {
+
+ while (u < PA_ELEMENTSOF(msec) && (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", (unsigned long long) (x/PA_USEC_PER_MSEC), (unsigned long long) (pa_smoother_get(s, x)/PA_USEC_PER_MSEC));
+ }
+
+ pa_smoother_free(s);
+
+ return 0;
+}
diff --git a/src/tests/stripnul.c b/src/tests/stripnul.c
new file mode 100644
index 00000000..0ab06776
--- /dev/null
+++ b/src/tests/stripnul.c
@@ -0,0 +1,70 @@
+/***
+ 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 <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include <pulse/xmalloc.h>
+#include <pulsecore/macro.h>
+
+int main(int argc, char *argv[]) {
+ FILE *i, *o;
+ size_t granularity;
+ pa_bool_t found;
+ uint8_t *zero;
+
+ pa_assert_se(argc >= 2);
+ pa_assert_se((granularity = atoi(argv[1])) >= 1);
+ pa_assert_se((i = (argc >= 3) ? fopen(argv[2], "r") : stdin));
+ pa_assert_se((o = (argc >= 4) ? fopen(argv[3], "w") : stdout));
+
+ zero = pa_xmalloc0(granularity);
+
+ for (;;) {
+ uint8_t buffer[16*1024], *p;
+ size_t k;
+
+ k = fread(buffer, granularity, sizeof(buffer)/granularity, i);
+
+ if (k <= 0)
+ break;
+
+ if (found)
+ pa_assert_se(fwrite(buffer, granularity, k, o) == k);
+ else {
+ for (p = buffer; (p-buffer)/granularity < k; p += granularity)
+ if (memcmp(p, zero, granularity)) {
+ size_t left;
+ found = TRUE;
+ left = k - (p-buffer)/granularity;
+ pa_assert_se(fwrite(p, granularity, left, o) == left);
+ break;
+ }
+ }
+ }
+
+ fflush(o);
+
+ return 0;
+}
diff --git a/src/tests/strlist-test.c b/src/tests/strlist-test.c
index 4262a001..2bd1645c 100644
--- a/src/tests/strlist-test.c
+++ b/src/tests/strlist-test.c
@@ -1,8 +1,9 @@
#include <stdio.h>
#include <pulse/xmalloc.h>
+#include <pulse/gccmacro.h>
+
#include <pulsecore/strlist.h>
-#include <pulsecore/gccmacro.h>
int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char* argv[]) {
char *t, *u;
@@ -16,7 +17,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 +30,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..7ab3a25c 100644
--- a/src/tests/sync-playback.c
+++ b/src/tests/sync-playback.c
@@ -1,18 +1,16 @@
-/* $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
@@ -67,7 +65,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 +87,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 +119,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 +129,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 +161,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 +185,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..7a62f85a 100644
--- a/src/tests/thread-mainloop-test.c
+++ b/src/tests/thread-mainloop-test.c
@@ -1,18 +1,16 @@
-/* $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
@@ -23,18 +21,19 @@
#include <config.h>
#endif
-#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <pulse/timeval.h>
#include <pulse/util.h>
-
-#include <pulsecore/gccmacro.h>
#include <pulse/thread-mainloop.h>
+#include <pulse/gccmacro.h>
+
+#include <pulsecore/macro.h>
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,27 +44,27 @@ 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);
-
+
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..f29b5e71 100644
--- a/src/tests/thread-test.c
+++ b/src/tests/thread-test.c
@@ -1,18 +1,16 @@
-/* $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
@@ -42,13 +40,13 @@ 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);
pa_log("thread_func() for %s starting...", (char*) pa_tls_get(tls));
-
+
pa_mutex_lock(mutex);
for (;;) {
@@ -57,13 +55,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);
}
@@ -72,21 +70,21 @@ 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);
-
+
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 +95,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);
+
+ mutex = pa_mutex_new(FALSE, FALSE);
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 +124,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..f1708ad4 100644
--- a/src/tests/utf8-test.c
+++ b/src/tests/utf8-test.c
@@ -1,5 +1,3 @@
-/* $Id$ */
-
#include <stdio.h>
#include <assert.h>
@@ -8,13 +6,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..d2c0ff69 100644
--- a/src/tests/voltest.c
+++ b/src/tests/voltest.c
@@ -1,9 +1,7 @@
-/* $Id$ */
-
#include <stdio.h>
#include <pulse/volume.h>
-#include <pulsecore/gccmacro.h>
+#include <pulse/gccmacro.h>
int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
pa_volume_t v;
@@ -12,7 +10,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));