From c7d93b363aca846639a30469310ee3b9945cfd78 Mon Sep 17 00:00:00 2001 From: James Laird Date: Thu, 20 Jun 2013 01:51:25 +1000 Subject: [PATCH] Revert "Fix pulse audio output driver in daemon mode." This reverts commit 8045e00d4f3d694cff99c30e3a5cd63eca3b4e5c. Now, pulseaudio can be initialised at startup, thus detecting connection errors early. Conflicts: audio_pulse.c --- audio_pulse.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/audio_pulse.c b/audio_pulse.c index 0fb06248..4698752e 100644 --- a/audio_pulse.c +++ b/audio_pulse.c @@ -35,9 +35,6 @@ static pa_simple *pa_dev = NULL; static int pa_error; -static const char *pa_server = NULL; -static const char *pa_sink = NULL; -static const char *pa_appname = NULL; static void help(void) { printf(" -a server set the server name\n" @@ -48,8 +45,10 @@ static void help(void) { } static int init(int argc, char **argv) { - pa_appname = config.apname; - + char *pa_server = NULL; + char *pa_sink = NULL; + char *pa_appname = config.apname; + optind = 1; // optind=0 is equivalent to optind=1 plus special behaviour argv--; // so we shift the arguments to satisfy getopt() argc++; @@ -77,16 +76,9 @@ static int init(int argc, char **argv) { if (optind < argc) die("Invalid audio argument: %s", argv[optind]); - return 0; -} - -static void deinit(void) { -} - -static void start(int sample_rate) { - const pa_sample_spec ss = { + static const pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, - .rate = sample_rate, + .rate = 44100, .channels = 2 }; @@ -100,20 +92,29 @@ static void start(int sample_rate) { if (!pa_dev) die("Could not connect to pulseaudio server: %s", pa_strerror(pa_error)); + + return 0; +} + +static void deinit(void) { + if (pa_dev) + pa_simple_free(pa_dev); + pa_dev = NULL; +} + +static void start(int sample_rate) { + if (sample_rate != 44100) + die("unexpected sample rate!"); } static void play(short buf[], int samples) { if( pa_simple_write(pa_dev, (char *)buf, (size_t)samples * 4, &pa_error) < 0 ) - warn("pa_simple_write() failed: %s\n", pa_strerror(pa_error)); + fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(pa_error)); } static void stop(void) { if (pa_simple_drain(pa_dev, &pa_error) < 0) - warn("pa_simple_drain() failed: %s\n", pa_strerror(pa_error)); - - if (pa_dev) - pa_simple_free(pa_dev); - pa_dev = NULL; + fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", pa_strerror(pa_error)); } audio_output audio_pulse = {