From 9f59b4e1cd516dbbc8a4978146bc94f2a1ce75eb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 11:27:00 +0000 Subject: add new test "interpol-test" git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1027 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/tests/interpol-test.c (limited to 'src/tests/interpol-test.c') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c new file mode 100644 index 00000000..26a92dbf --- /dev/null +++ b/src/tests/interpol-test.c @@ -0,0 +1,168 @@ +/* $Id$ */ + +/*** + This file is part of polypaudio. + + polypaudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + polypaudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with polypaudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static pa_context *context = NULL; +static pa_stream *stream = NULL; +static pa_mainloop_api *mainloop_api = NULL; + +static void stream_write_cb(pa_stream *p, size_t length, void *userdata) { + + /* Just some silence */ + pa_stream_write(p, pa_xmalloc0(length), length, pa_xfree, 0, PA_SEEK_RELATIVE); +} + +/* This is called whenever the context status changes */ +static void context_state_callback(pa_context *c, void *userdata) { + assert(c); + + switch (pa_context_get_state(c)) { + case PA_CONTEXT_CONNECTING: + case PA_CONTEXT_AUTHORIZING: + case PA_CONTEXT_SETTING_NAME: + break; + + case PA_CONTEXT_READY: { + + static const pa_sample_spec ss = { + .format = PA_SAMPLE_S16LE, + .rate = 44100, + .channels = 1 + }; + + fprintf(stderr, "Connection established.\n"); + + stream = pa_stream_new(c, "interpol-test", &ss, NULL); + assert(stream); + + pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL); + pa_stream_set_write_callback(stream, stream_write_cb, NULL); + + break; + } + + case PA_CONTEXT_TERMINATED: + break; + + case PA_CONTEXT_FAILED: + default: + fprintf(stderr, "Context error: %s\n", pa_strerror(pa_context_errno(c))); + abort(); + } +} + +int main(int argc, char *argv[]) { + pa_threaded_mainloop* m = NULL; + int k, r; + struct timeval start, last_info = { 0, 0 }; + pa_usec_t old_t = 0, old_rtc = 0; + + /* Set up a new main loop */ + m = pa_threaded_mainloop_new(); + assert(m); + + mainloop_api = pa_threaded_mainloop_get_api(m); + + context = pa_context_new(mainloop_api, argv[0]); + assert(context); + + pa_context_set_state_callback(context, context_state_callback, NULL); + + r = pa_context_connect(context, NULL, 0, NULL); + assert(r >= 0); + + pa_gettimeofday(&start); + + pa_threaded_mainloop_start(m); + + for (k = 0; k < 5000; k++) { + int success = 0, changed = 0; + pa_usec_t t, rtc; + struct timeval now, tv; + + pa_threaded_mainloop_lock(m); + + if (stream) { + const pa_timing_info *info; + + if (pa_stream_get_time(stream, &t) >= 0) + success = 1; + + if ((info = pa_stream_get_timing_info(stream))) + if (last_info.tv_usec != info->timestamp.tv_usec || last_info.tv_sec != info->timestamp.tv_sec) { + changed = 1; + last_info = info->timestamp; + } + } + + pa_threaded_mainloop_unlock(m); + + if (success) { + pa_gettimeofday(&now); + + rtc = pa_timeval_diff(&now, &start); + printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, rtc, t, rtc-old_rtc, t-old_t, changed*2000000); + old_t = t; + old_rtc = rtc; + } + + /* Spin loop, eerks but normal usleep is just to badly grained */ + + tv = now; + while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) + pthread_yield(); + } + + if (m) + pa_threaded_mainloop_stop(m); + + if (stream) { + pa_stream_disconnect(stream); + pa_stream_unref(stream); + } + + if (context) { + pa_context_disconnect(context); + pa_context_unref(context); + } + + if (m) + pa_threaded_mainloop_free(m); + + return 0; +} -- cgit From 6eabab6e2b093933bf489e6c94b13433d03584d2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 12:20:10 +0000 Subject: minor cleanups git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1028 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tests/interpol-test.c') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 26a92dbf..fa5fae7d 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -136,12 +136,12 @@ int main(int argc, char *argv[]) { pa_gettimeofday(&now); rtc = pa_timeval_diff(&now, &start); - printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, rtc, t, rtc-old_rtc, t-old_t, changed*2000000); + printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, rtc, t, rtc-old_rtc, t-old_t, changed); old_t = t; old_rtc = rtc; } - /* Spin loop, eerks but normal usleep is just to badly grained */ + /* Spin loop, ugly but normal usleep() is just too badly grained */ tv = now; while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) -- cgit From f44ba092651aa75055e109e04b4164ea92ae7fdc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 19 Jun 2006 21:53:48 +0000 Subject: big s/polyp/pulse/g git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1033 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/tests/interpol-test.c') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index fa5fae7d..7cabc1c9 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -1,20 +1,20 @@ /* $Id$ */ /*** - This file is part of polypaudio. + This file is part of PulseAudio. - polypaudio is free software; you can redistribute it and/or modify + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - polypaudio is distributed in the hope that it will be useful, but + PulseAudio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License - along with polypaudio; if not, write to the Free Software + along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -34,8 +34,8 @@ #include #include -#include -#include +#include +#include static pa_context *context = NULL; static pa_stream *stream = NULL; -- cgit From 6ca46f4d7a9fa57b949e2286d3af1b6e78dce8f5 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 20 Jun 2006 13:49:30 +0000 Subject: Make interpol-test build on Win32 and non-pthread systems. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1043 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/tests/interpol-test.c') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 7cabc1c9..bf7f582c 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -32,7 +32,10 @@ #include #include #include + +#ifdef HAVE_PTHREAD #include +#endif #include #include @@ -145,7 +148,13 @@ int main(int argc, char *argv[]) { tv = now; while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) +#ifdef HAVE_PTHREAD pthread_yield(); +#elif defined(OS_IS_WIN32) + Sleep(0); +#else + ; +#endif } if (m) -- cgit From 1342999b5197adeb76ee9feb41f38dba26a20dbe Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 20 Jun 2006 14:26:52 +0000 Subject: Make sure we do not use pthread_yield() on platforms that do not have them. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1045 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests/interpol-test.c') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index bf7f582c..2df65a45 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -148,7 +148,7 @@ int main(int argc, char *argv[]) { tv = now; while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) -#ifdef HAVE_PTHREAD +#ifdef HAVE_PTHREAD_YIELD pthread_yield(); #elif defined(OS_IS_WIN32) Sleep(0); -- cgit From aec3888ef2deb1dba51922fcf149115acea6476b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 24 Aug 2006 08:57:35 +0000 Subject: Add missing header. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1330 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/tests/interpol-test.c') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 2df65a45..3ec8a18f 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -37,6 +37,10 @@ #include #endif +#ifdef HAVE_WINDOWS_H +#include +#endif + #include #include -- cgit From e00ba020cb712aee50c591fc66c6bc2ab3659deb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Sep 2006 22:38:41 +0000 Subject: remove yet another occurence of pthread_yield() by pa_thread_yield() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1372 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/tests/interpol-test.c') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 3ec8a18f..54bdd775 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -33,17 +33,11 @@ #include #include -#ifdef HAVE_PTHREAD -#include -#endif - -#ifdef HAVE_WINDOWS_H -#include -#endif - #include #include +#include + static pa_context *context = NULL; static pa_stream *stream = NULL; static pa_mainloop_api *mainloop_api = NULL; @@ -152,13 +146,7 @@ int main(int argc, char *argv[]) { tv = now; while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) -#ifdef HAVE_PTHREAD_YIELD - pthread_yield(); -#elif defined(OS_IS_WIN32) - Sleep(0); -#else - ; -#endif + pa_thread_yield(); } if (m) -- cgit From 521daf6f0ac4fa6a2fbfb5d523c0c743342dca2b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 4 Jan 2007 13:43:45 +0000 Subject: Huge trailing whitespace cleanup. Let's keep the tree pure from here on, mmmkay? git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1418 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/tests/interpol-test.c') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 54bdd775..3953043f 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -2,17 +2,17 @@ /*** This file is part of PulseAudio. - + PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + PulseAudio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with PulseAudio; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -57,7 +57,7 @@ static void context_state_callback(pa_context *c, void *userdata) { case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: break; - + case PA_CONTEXT_READY: { static const pa_sample_spec ss = { @@ -65,18 +65,18 @@ static void context_state_callback(pa_context *c, void *userdata) { .rate = 44100, .channels = 1 }; - + fprintf(stderr, "Connection established.\n"); stream = pa_stream_new(c, "interpol-test", &ss, NULL); assert(stream); - + pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL); pa_stream_set_write_callback(stream, stream_write_cb, NULL); - + break; } - + case PA_CONTEXT_TERMINATED: break; @@ -108,19 +108,19 @@ int main(int argc, char *argv[]) { assert(r >= 0); pa_gettimeofday(&start); - + pa_threaded_mainloop_start(m); for (k = 0; k < 5000; k++) { int success = 0, changed = 0; pa_usec_t t, rtc; struct timeval now, tv; - + pa_threaded_mainloop_lock(m); if (stream) { const pa_timing_info *info; - + if (pa_stream_get_time(stream, &t) >= 0) success = 1; @@ -130,9 +130,9 @@ int main(int argc, char *argv[]) { last_info = info->timestamp; } } - + pa_threaded_mainloop_unlock(m); - + if (success) { pa_gettimeofday(&now); @@ -156,7 +156,7 @@ int main(int argc, char *argv[]) { pa_stream_disconnect(stream); pa_stream_unref(stream); } - + if (context) { pa_context_disconnect(context); pa_context_unref(context); @@ -164,6 +164,6 @@ int main(int argc, char *argv[]) { if (m) pa_threaded_mainloop_free(m); - + return 0; } -- cgit From a67c21f093202f142438689d3f7cfbdf4ea82eea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 28 Oct 2007 19:13:50 +0000 Subject: merge 'lennart' branch back into trunk. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/tests/interpol-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tests/interpol-test.c') diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c index 3953043f..85a509d4 100644 --- a/src/tests/interpol-test.c +++ b/src/tests/interpol-test.c @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) { pa_gettimeofday(&now); rtc = pa_timeval_diff(&now, &start); - printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, rtc, t, rtc-old_rtc, t-old_t, changed); + printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, (unsigned long long) rtc, (unsigned long long) t, (unsigned long long) (rtc-old_rtc), (unsigned long long) (t-old_t), changed); old_t = t; old_rtc = rtc; } -- cgit