diff options
Diffstat (limited to 'src/tests')
33 files changed, 601 insertions, 120 deletions
diff --git a/src/tests/asyncmsgq-test.c b/src/tests/asyncmsgq-test.c index 380c5e7f..08ad3dd4 100644 --- a/src/tests/asyncmsgq-test.c +++ b/src/tests/asyncmsgq-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/asyncq-test.c b/src/tests/asyncq-test.c index 09b20047..4e8a1207 100644 --- a/src/tests/asyncq-test.c +++ b/src/tests/asyncq-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -44,7 +42,7 @@ static void producer(void *_q) { pa_asyncq_push(q, PA_UINT_TO_PTR(i+1), 1); } - pa_asyncq_push(q, PA_UINT_TO_PTR(-1), 1); + pa_asyncq_push(q, PA_UINT_TO_PTR(-1), TRUE); printf("pushed end\n"); } @@ -56,7 +54,7 @@ static void consumer(void *_q) { sleep(1); for (i = 0;; i++) { - p = pa_asyncq_pop(q, 1); + p = pa_asyncq_pop(q, TRUE); if (p == PA_UINT_TO_PTR(-1)) break; diff --git a/src/tests/channelmap-test.c b/src/tests/channelmap-test.c index 98f36b61..9c234602 100644 --- a/src/tests/channelmap-test.c +++ b/src/tests/channelmap-test.c @@ -1,10 +1,8 @@ -/* $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]; @@ -22,12 +20,15 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { 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 d582e9c5..b7145e8a 100644 --- a/src/tests/cpulimit-test.c +++ b/src/tests/cpulimit-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -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> 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 7e54454e..b2c648da 100644 --- a/src/tests/flist-test.c +++ b/src/tests/flist-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/get-binary-name-test.c b/src/tests/get-binary-name-test.c index 29ebbe22..7c7a8996 100644 --- a/src/tests/get-binary-name-test.c +++ b/src/tests/get-binary-name-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/hook-list-test.c b/src/tests/hook-list-test.c index 8628f521..60b965cd 100644 --- a/src/tests/hook-list-test.c +++ b/src/tests/hook-list-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -7,12 +5,12 @@ #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; } @@ -23,9 +21,9 @@ 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"); diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 85a509d4..9d930774 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -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 */ @@ -63,7 +60,7 @@ static void context_state_callback(pa_context *c, void *userdata) { static const pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, .rate = 44100, - .channels = 1 + .channels = 2 }; fprintf(stderr, "Connection established.\n"); @@ -112,9 +109,10 @@ int main(int argc, char *argv[]) { 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); @@ -122,22 +120,26 @@ int main(int argc, char *argv[]) { 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, (unsigned long long) rtc, (unsigned long long) t, (unsigned long long) (rtc-old_rtc), (unsigned long long) (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; } diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c index d1bcb3e3..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 diff --git a/src/tests/mainloop-test.c b/src/tests/mainloop-test.c index c386251c..9fa2e466 100644 --- a/src/tests/mainloop-test.c +++ b/src/tests/mainloop-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -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 diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index d1013118..9e358359 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -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 */ diff --git a/src/tests/memblock-test.c b/src/tests/memblock-test.c index 2b9d3401..6da1b1e9 100644 --- a/src/tests/memblock-test.c +++ b/src/tests/memblock-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c index 25ea399b..7bf992a1 100644 --- a/src/tests/memblockq-test.c +++ b/src/tests/memblockq-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -31,22 +29,48 @@ #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); + 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, silence); + bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, 40, &silence); assert(bq); chunk1.memblock = pa_memblock_new_fixed(p, (char*) "11", 2, 1); @@ -72,13 +96,13 @@ int main(int argc, char *argv[]) { ret = pa_memblockq_push(bq, &chunk1); assert(ret == 0); - ret = pa_memblockq_push(bq, &chunk1); + 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, &chunk2); + ret = pa_memblockq_push(bq, &chunk4); assert(ret == 0); pa_memblockq_seek(bq, -6, 0); @@ -86,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); @@ -119,35 +143,22 @@ int main(int argc, char *argv[]) { ret = pa_memblockq_push(bq, &chunk3); assert(ret == 0); - pa_memblockq_shorten(bq, pa_memblockq_get_length(bq)-2); + pa_memblockq_seek(bq, 30, PA_SEEK_RELATIVE); - printf(">"); + dump(bq); - for (;;) { - pa_memchunk out; - char *e; - size_t n; + pa_memblockq_rewind(bq, 52); - 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++) - printf("%c", *e); - pa_memblock_release(out.memblock); - - pa_memblock_unref(out.memblock); - pa_memblockq_drop(bq, out.length); - } - - printf("<\n"); + dump(bq); 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 index d07b1b0c..f3f6f829 100644 --- a/src/tests/mix-test.c +++ b/src/tests/mix-test.c @@ -1,5 +1,3 @@ -/* $Id: resampler-test.c 2037 2007-11-09 02:45:07Z lennart $ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/pacat-simple.c b/src/tests/pacat-simple.c index 2da67c1a..b26e4b68 100644 --- a/src/tests/pacat-simple.c +++ b/src/tests/pacat-simple.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -31,7 +29,7 @@ #include <pulse/simple.h> #include <pulse/error.h> -#include <pulsecore/gccmacro.h> +#include <pulse/gccmacro.h> #define BUFSIZE 1024 diff --git a/src/tests/parec-simple.c b/src/tests/parec-simple.c index d7d88360..6c0d529b 100644 --- a/src/tests/parec-simple.c +++ b/src/tests/parec-simple.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -30,7 +28,7 @@ #include <pulse/simple.h> #include <pulse/error.h> -#include <pulsecore/gccmacro.h> +#include <pulse/gccmacro.h> #define BUFSIZE 1024 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 index b357ab10..105f094a 100644 --- a/src/tests/queue-test.c +++ b/src/tests/queue-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/remix-test.c b/src/tests/remix-test.c index d2fa6943..4777c150 100644 --- a/src/tests/remix-test.c +++ b/src/tests/remix-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/resampler-test.c b/src/tests/resampler-test.c index 820a0c1e..1a20be2c 100644 --- a/src/tests/resampler-test.c +++ b/src/tests/resampler-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/rtpoll-test.c b/src/tests/rtpoll-test.c index e6493771..953fd61d 100644 --- a/src/tests/rtpoll-test.c +++ b/src/tests/rtpoll-test.c @@ -1,5 +1,3 @@ -/* $Id: thread-test.c 1621 2007-08-10 22:00:22Z lennart $ */ - /*** This file is part of PulseAudio. @@ -67,7 +65,7 @@ int main(int argc, char *argv[]) { pa_rtpoll_item_set_before_callback(w, worker); pa_rtpoll_install(p); - pa_rtpoll_set_timer_periodic(p, 10000000); /* 10 s */ + pa_rtpoll_set_timer_relative(p, 10000000); /* 10 s */ pa_rtpoll_run(p, 1); 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(¶m, 0, sizeof(param)); + param.sched_priority = 12; + pa_assert_se(pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) == 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 index 52cb9db4..d64a8902 100644 --- a/src/tests/sig2str-test.c +++ b/src/tests/sig2str-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/smoother-test.c b/src/tests/smoother-test.c index 0816e76c..b78f3c91 100644 --- a/src/tests/smoother-test.c +++ b/src/tests/smoother-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -47,25 +45,25 @@ int main(int argc, char*argv[]) { srand(0); - for (m = 0, u = 0; u < PA_ELEMENTSOF(msec)-2; u+= 2) { + for (m = 0, u = 0; u < PA_ELEMENTSOF(msec); u+= 2) { - msec[u] = m+1; - msec[u+1] = m + rand() % 2000 - 1000; + 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; } - 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); + 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 (msec[u] > 0 && (pa_usec_t) msec[u]*PA_USEC_PER_MSEC < x) { + 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; 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 47770b5d..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; diff --git a/src/tests/sync-playback.c b/src/tests/sync-playback.c index 63510eb6..7ab3a25c 100644 --- a/src/tests/sync-playback.c +++ b/src/tests/sync-playback.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 558e53a5..7a62f85a 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -30,8 +28,8 @@ #include <pulse/timeval.h> #include <pulse/util.h> #include <pulse/thread-mainloop.h> +#include <pulse/gccmacro.h> -#include <pulsecore/gccmacro.h> #include <pulsecore/macro.h> static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { diff --git a/src/tests/thread-test.c b/src/tests/thread-test.c index 72dde6cb..f29b5e71 100644 --- a/src/tests/thread-test.c +++ b/src/tests/thread-test.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. diff --git a/src/tests/utf8-test.c b/src/tests/utf8-test.c index b9594dcc..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> diff --git a/src/tests/voltest.c b/src/tests/voltest.c index dcc1ec51..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; |