summaryrefslogtreecommitdiffstats
path: root/src/tests/interpol-test.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-02-19 03:59:56 +0100
committerLennart Poettering <lennart@poettering.net>2009-02-19 03:59:56 +0100
commit45218aa2268e9fc231d42d1479adf7685eb3b507 (patch)
treebcc9fde505b4ad87eddd337fa52682ee5c5e8010 /src/tests/interpol-test.c
parent5f5396bb15c6b939ac6a71efa36950817f9e18bf (diff)
make interpol-test useful for recording as well
Diffstat (limited to 'src/tests/interpol-test.c')
-rw-r--r--src/tests/interpol-test.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c
index 9d930774..20d2c230 100644
--- a/src/tests/interpol-test.c
+++ b/src/tests/interpol-test.c
@@ -39,10 +39,23 @@
static pa_context *context = NULL;
static pa_stream *stream = NULL;
static pa_mainloop_api *mainloop_api = NULL;
+static pa_bool_t playback = TRUE;
static void stream_write_cb(pa_stream *p, size_t nbytes, void *userdata) {
/* Just some silence */
- pa_stream_write(p, pa_xmalloc0(nbytes), nbytes, pa_xfree, 0, PA_SEEK_RELATIVE);
+ pa_assert_se(pa_stream_write(p, pa_xmalloc0(nbytes), nbytes, pa_xfree, 0, PA_SEEK_RELATIVE) == 0);
+}
+
+static void stream_read_cb(pa_stream *p, size_t nbytes, void *userdata) {
+ /* We don't care, just drop the data */
+
+ while (pa_stream_readable_size(p) > 0) {
+ const void *d;
+ size_t b;
+
+ pa_assert_se(pa_stream_peek(p, &d, &b) == 0);
+ pa_assert_se(pa_stream_drop(p) == 0);
+ }
}
/* This is called whenever the context status changes */
@@ -68,8 +81,13 @@ static void context_state_callback(pa_context *c, void *userdata) {
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);
+ if (playback) {
+ pa_assert_se(pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL) == 0);
+ pa_stream_set_write_callback(stream, stream_write_cb, NULL);
+ } else {
+ pa_assert_se(pa_stream_connect_record(stream, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE) == 0);
+ pa_stream_set_read_callback(stream, stream_read_cb, NULL);
+ }
break;
}
@@ -90,6 +108,8 @@ int main(int argc, char *argv[]) {
struct timeval start, last_info = { 0, 0 };
pa_usec_t old_t = 0, old_rtc = 0;
+ playback = argc <= 1 || !pa_streq(argv[1], "-r");
+
/* Set up a new main loop */
m = pa_threaded_mainloop_new();
assert(m);
@@ -138,7 +158,14 @@ int main(int argc, char *argv[]) {
if (success) {
rtc = pa_timeval_diff(&now, &start);
- 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);
+ 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;