summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@intel.com>2011-08-23 14:18:22 +0800
committerColin Guthrie <colin@mageia.org>2011-08-29 10:31:46 +0100
commitcef16430d0e307a3978dc6aa9a0d9b6940b0e0fa (patch)
tree4d6cbeb8c15f657608193d68e2ca117fb17a0b6e
parentc862c5caa4d2a63f0a5c5c359b6205e3bad5f78a (diff)
pacat: make pacat respond to cork/uncork events
Pacat remembers the number of cork requests, and then cork/uncork the stream accordingly. With this change, it makes below test script work correctly: pacat -p --property=media.role="music" <long-sound> & sleep 2 pacat -p --property=media.role="phone" <short-sound> wait Initial idea by Lu Guanqun, but modified by Colin Guthrie (so blame me if it's broken)
-rw-r--r--src/utils/pacat.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/utils/pacat.c b/src/utils/pacat.c
index 40418778c..3be1f6c8a 100644
--- a/src/utils/pacat.c
+++ b/src/utils/pacat.c
@@ -91,6 +91,8 @@ static int32_t latency_msec = 0, process_time_msec = 0;
static pa_bool_t raw = TRUE;
static int file_format = -1;
+static uint32_t cork_requests = 0;
+
/* A shortcut for terminating the application */
static void quit(int ret) {
pa_assert(mainloop_api);
@@ -408,6 +410,24 @@ static void stream_event_callback(pa_stream *s, const char *name, pa_proplist *p
t = pa_proplist_to_string_sep(pl, ", ");
pa_log("Got event '%s', properties '%s'", name, t);
+
+ if (pa_streq(name, PA_STREAM_EVENT_REQUEST_CORK)) {
+ if (cork_requests == 0) {
+ pa_log(_("Cork request stack is empty: corking stream"));
+ pa_operation_unref(pa_stream_cork(s, 1, NULL, NULL));
+ }
+ cork_requests++;
+ } else if (pa_streq(name, PA_STREAM_EVENT_REQUEST_UNCORK)) {
+ if (cork_requests == 1) {
+ pa_log(_("Cork request stack is empty: uncorking stream"));
+ pa_operation_unref(pa_stream_cork(s, 0, NULL, NULL));
+ }
+ if (cork_requests == 0)
+ pa_log(_("Warning: Received more uncork requests than cork requests!"));
+ else
+ cork_requests--;
+ }
+
pa_xfree(t);
}