From 287ad384814351a195696f91e83388c12b265f90 Mon Sep 17 00:00:00 2001 Message-Id: <287ad384814351a195696f91e83388c12b265f90.1714831099.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 14 Mar 2009 09:28:20 +0000 Subject: [PATCH] The command backend now supports the old (suspending) and new (silence) pause behaviors via an option. disorder-playrtp gains --pause-mode t o set this option. Organization: Straylight/Edgeware From: Richard Kettlewell --- clients/playrtp.c | 8 ++++++-- doc/disorder-playrtp.1.in | 9 ++++++++- lib/uaudio-command.c | 12 +++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/clients/playrtp.c b/clients/playrtp.c index d97864b..338cbbf 100644 --- a/clients/playrtp.c +++ b/clients/playrtp.c @@ -217,6 +217,7 @@ static const struct option options[] = { #endif { "dump", required_argument, 0, 'r' }, { "command", required_argument, 0, 'e' }, + { "pause-mode", required_argument, 0, 'P' }, { "socket", required_argument, 0, 's' }, { "config", required_argument, 0, 'C' }, { 0, 0, 0, 0 } @@ -492,7 +493,9 @@ static void help(void) { #if HAVE_COREAUDIO_AUDIOHARDWARE_H " --core-audio, -c Use Core Audio to play audio\n" #endif - " --command, -e COMMAND Pipe audio to command\n" + " --command, -e COMMAND Pipe audio to command.\n" + " --pause-mode, -P silence For -e: pauses send silence (default)\n" + " --pause-mode, -P suspend For -e: pauses suspend writes\n" " --help, -h Display usage message\n" " --version, -V Display version number\n" ); @@ -592,7 +595,7 @@ int main(int argc, char **argv) { mem_init(); if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); backend = uaudio_apis[0]; - while((n = getopt_long(argc, argv, "hVdD:m:b:x:L:R:M:aocC:re:", options, 0)) >= 0) { + while((n = getopt_long(argc, argv, "hVdD:m:b:x:L:R:M:aocC:re:P:", options, 0)) >= 0) { switch(n) { case 'h': help(); case 'V': version("disorder-playrtp"); @@ -616,6 +619,7 @@ int main(int argc, char **argv) { case 's': control_socket = optarg; break; case 'r': dumpfile = optarg; break; case 'e': backend = &uaudio_command; uaudio_set("command", optarg); break; + case 'P': uaudio_set("pause-mode", optarg); break; default: fatal(0, "invalid option"); } } diff --git a/doc/disorder-playrtp.1.in b/doc/disorder-playrtp.1.in index ea4c93f..206be91 100644 --- a/doc/disorder-playrtp.1.in +++ b/doc/disorder-playrtp.1.in @@ -66,7 +66,8 @@ If \fICOMMAND\fR exits it is re-executed; any samples that had been written to the pipe but not processed by the previous instance will be lost. .IP .B \-\-device -is redundant with this option. +is redundant with this option, but you might wan to set +.BR \-\-pause\-mode . .IP As an example, .B "-e \(aqcat > dump\(aq" @@ -75,6 +76,12 @@ You could convert it to another format with, for instance: .IP .B "sox -c2 -traw -r44100 -s -w dump dump.wav" .TP +.B \-\-pause\-mode \fIMODE\fR, \fB-P \fIMODE +Set the pause mode for \fB\-\-command\fR to either \fBsilence\fR (the default), in +which pauses are represented by sending silent samples, or \fBsuspend\fR, in which +writes to the subprocess are suspended, requiring it to infer a pause from flow +control. +.TP .B \-\-config \fIPATH\fR, \fB\-C \fIPATH Set the configuration file. The default is diff --git a/lib/uaudio-command.c b/lib/uaudio-command.c index 096888d..812a3f2 100644 --- a/lib/uaudio-command.c +++ b/lib/uaudio-command.c @@ -44,6 +44,7 @@ static pid_t command_pid; static const char *const command_options[] = { "command", + "pause-mode", NULL }; @@ -115,6 +116,15 @@ static size_t command_play(void *buffer, size_t nsamples) { static void command_start(uaudio_callback *callback, void *userdata) { + const char *pausemode = uaudio_get("pause-mode", "silence"); + unsigned flags = 0; + + if(!strcmp(pausemode, "silence")) + flags |= UAUDIO_THREAD_FAKE_PAUSE; + else if(!strcmp(pausemode, "suspend")) + ; + else + fatal(0, "unknown pause mode '%s'", pausemode); command_open(); uaudio_schedule_init(); uaudio_thread_start(callback, @@ -122,7 +132,7 @@ static void command_start(uaudio_callback *callback, command_play, uaudio_channels, 4096 / uaudio_sample_size, - UAUDIO_THREAD_FAKE_PAUSE); + flags); } static void command_stop(void) { -- [mdw]