From 045c1d602dcba57868845ba3270510593c39480f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 15 May 2008 23:34:41 +0000 Subject: merge glitch-free branch back into trunk git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@2445 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/asyncq-test.c | 4 +- src/tests/channelmap-test.c | 2 +- src/tests/cpulimit-test.c | 2 +- src/tests/interpol-test.c | 28 +++++---- src/tests/mainloop-test.c | 2 +- src/tests/mcalign-test.c | 3 +- src/tests/memblockq-test.c | 69 ++++++++++++++--------- src/tests/pacat-simple.c | 2 +- src/tests/parec-simple.c | 2 +- src/tests/proplist-test.c | 13 +++-- src/tests/rtpoll-test.c | 2 +- src/tests/rtstutter.c | 119 +++++++++++++++++++++++++++++++++++++++ src/tests/smoother-test.c | 16 +++--- src/tests/stripnul.c | 72 +++++++++++++++++++++++ src/tests/strlist-test.c | 3 +- src/tests/thread-mainloop-test.c | 2 +- src/tests/voltest.c | 2 +- 17 files changed, 277 insertions(+), 66 deletions(-) create mode 100644 src/tests/rtstutter.c create mode 100644 src/tests/stripnul.c (limited to 'src/tests') diff --git a/src/tests/asyncq-test.c b/src/tests/asyncq-test.c index 09b20047..0e10ed89 100644 --- a/src/tests/asyncq-test.c +++ b/src/tests/asyncq-test.c @@ -44,7 +44,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 +56,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..d26d2cff 100644 --- a/src/tests/channelmap-test.c +++ b/src/tests/channelmap-test.c @@ -4,7 +4,7 @@ #include #include -#include +#include int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { char cm[PA_CHANNEL_MAP_SNPRINT_MAX]; diff --git a/src/tests/cpulimit-test.c b/src/tests/cpulimit-test.c index d582e9c5..4563c0f6 100644 --- a/src/tests/cpulimit-test.c +++ b/src/tests/cpulimit-test.c @@ -30,7 +30,7 @@ #include #include -#include +#include #ifdef TEST2 #include diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 85a509d4..f894d2f3 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -42,10 +42,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 +62,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 +111,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 +122,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/mainloop-test.c b/src/tests/mainloop-test.c index c386251c..79a4aaa0 100644 --- a/src/tests/mainloop-test.c +++ b/src/tests/mainloop-test.c @@ -29,9 +29,9 @@ #include #include +#include #include -#include #ifdef GLIB_MAIN_LOOP diff --git a/src/tests/mcalign-test.c b/src/tests/mcalign-test.c index d1013118..79dd5797 100644 --- a/src/tests/mcalign-test.c +++ b/src/tests/mcalign-test.c @@ -31,9 +31,10 @@ #include #include +#include + #include #include -#include /* A simple program for testing pa_mcalign */ diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c index 25ea399b..3fa8d79f 100644 --- a/src/tests/memblockq-test.c +++ b/src/tests/memblockq-test.c @@ -31,22 +31,48 @@ #include #include +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 +98,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 +112,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 +145,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); - - printf(">"); - - 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_memblock_unref(out.memblock); - pa_memblockq_drop(bq, out.length); - } + pa_memblockq_rewind(bq, 52); - 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/pacat-simple.c b/src/tests/pacat-simple.c index 2da67c1a..c2123b74 100644 --- a/src/tests/pacat-simple.c +++ b/src/tests/pacat-simple.c @@ -31,7 +31,7 @@ #include #include -#include +#include #define BUFSIZE 1024 diff --git a/src/tests/parec-simple.c b/src/tests/parec-simple.c index d7d88360..9c66cc23 100644 --- a/src/tests/parec-simple.c +++ b/src/tests/parec-simple.c @@ -30,7 +30,7 @@ #include #include -#include +#include #define BUFSIZE 1024 diff --git a/src/tests/proplist-test.c b/src/tests/proplist-test.c index b88f4e5e..5f7a78f3 100644 --- a/src/tests/proplist-test.c +++ b/src/tests/proplist-test.c @@ -28,25 +28,26 @@ #include #include #include +#include int main(int argc, char*argv[]) { pa_proplist *a, *b; char *s, *t; a = pa_proplist_new(); - pa_assert_se(pa_proplist_puts(a, PA_PROP_MEDIA_TITLE, "Brandenburgische Konzerte") == 0); - pa_assert_se(pa_proplist_puts(a, PA_PROP_MEDIA_ARTIST, "Johann Sebastian Bach") == 0); + 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_puts(b, PA_PROP_MEDIA_TITLE, "Goldbergvariationen") == 0); - pa_assert_se(pa_proplist_put(b, PA_PROP_MEDIA_ICON, "\0\1\2\3\4\5\6\7", 8) == 0); + pa_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_merge(a, b); + 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_remove(b, PA_PROP_MEDIA_TITLE) == 0); + pa_assert_se(pa_proplist_unset(b, PA_PROP_MEDIA_TITLE) == 0); s = pa_proplist_to_string(a); t = pa_proplist_to_string(b); diff --git a/src/tests/rtpoll-test.c b/src/tests/rtpoll-test.c index e6493771..af942104 100644 --- a/src/tests/rtpoll-test.c +++ b/src/tests/rtpoll-test.c @@ -67,7 +67,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..39dfc5d3 --- /dev/null +++ b/src/tests/rtstutter.c @@ -0,0 +1,119 @@ +/* $Id$ */ + +/*** + 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 +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +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 (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/smoother-test.c b/src/tests/smoother-test.c index 0816e76c..de037724 100644 --- a/src/tests/smoother-test.c +++ b/src/tests/smoother-test.c @@ -47,25 +47,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..2f87e877 --- /dev/null +++ b/src/tests/stripnul.c @@ -0,0 +1,72 @@ +/* $Id$ */ + +/*** + This file is part of PulseAudio. + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include + +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 #include +#include + #include -#include int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char* argv[]) { char *t, *u; diff --git a/src/tests/thread-mainloop-test.c b/src/tests/thread-mainloop-test.c index 558e53a5..ac6d5049 100644 --- a/src/tests/thread-mainloop-test.c +++ b/src/tests/thread-mainloop-test.c @@ -30,8 +30,8 @@ #include #include #include +#include -#include #include static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) { diff --git a/src/tests/voltest.c b/src/tests/voltest.c index dcc1ec51..91752ad9 100644 --- a/src/tests/voltest.c +++ b/src/tests/voltest.c @@ -3,7 +3,7 @@ #include #include -#include +#include int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) { pa_volume_t v; -- cgit