diff options
Diffstat (limited to 'src/audioOutputs')
-rw-r--r-- | src/audioOutputs/audioOutput_ao.c | 2 | ||||
-rw-r--r-- | src/audioOutputs/audioOutput_jack.c | 185 | ||||
-rw-r--r-- | src/audioOutputs/audioOutput_null.c | 5 | ||||
-rw-r--r-- | src/audioOutputs/audioOutput_oss.c | 3 | ||||
-rw-r--r-- | src/audioOutputs/audioOutput_shout.c | 2 |
5 files changed, 104 insertions, 93 deletions
diff --git a/src/audioOutputs/audioOutput_ao.c b/src/audioOutputs/audioOutput_ao.c index 65ffa2c27..e7e201add 100644 --- a/src/audioOutputs/audioOutput_ao.c +++ b/src/audioOutputs/audioOutput_ao.c @@ -158,7 +158,7 @@ static void audioOutputAo_finishDriver(AudioOutput * audioOutput) ao_shutdown(); } -static void audioOutputAo_dropBufferedAudio(AudioOutput * audioOutput) +static void audioOutputAo_dropBufferedAudio(mpd_unused AudioOutput * audioOutput) { /* not supported by libao */ } diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c index ed0bceb46..8818bb739 100644 --- a/src/audioOutputs/audioOutput_jack.c +++ b/src/audioOutputs/audioOutput_jack.c @@ -27,25 +27,19 @@ #include <jack/types.h> #include <jack/ringbuffer.h> -pthread_mutex_t play_audio_lock = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t play_audio = PTHREAD_COND_INITIALIZER; - -/*#include "dmalloc.h"*/ - -#ifdef MIN -# undef MIN -# define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif - -/*#define SAMPLE_SIZE sizeof(jack_default_audio_sample_t);*/ +static const size_t sample_size = sizeof(jack_default_audio_sample_t); +typedef struct _JackData { + /* configuration */ + char *name; + char *output_ports[2]; + int ringbuf_sz; -static char *name = "mpd"; -static char *output_ports[2]; -static int ringbuf_sz = 32768; -size_t sample_size = sizeof(jack_default_audio_sample_t); + /* locks */ + pthread_mutex_t play_audio_lock; + pthread_cond_t play_audio; -typedef struct _JackData { + /* jack library stuff */ jack_port_t *ports[2]; jack_client_t *client; jack_ringbuffer_t *ringbuffer[2]; @@ -60,49 +54,67 @@ static JackData *newJackData(void) JackData *ret; ret = xcalloc(sizeof(JackData), 1); + ret->name = "mpd"; + ret->ringbuf_sz = 32768; + + pthread_mutex_init(&ret->play_audio_lock, NULL); + pthread_cond_init(&ret->play_audio, NULL); + return ret; } -static void freeJackData(AudioOutput *audioOutput) +static void freeJackClient(JackData *jd) { - JackData *jd = audioOutput->data; - if (jd) { - if (jd->ringbuffer[0]) - jack_ringbuffer_free(jd->ringbuffer[0]); - if (jd->ringbuffer[1]) - jack_ringbuffer_free(jd->ringbuffer[1]); - free(jd); - audioOutput->data = NULL; + assert(jd != NULL); + + if (jd->client != NULL) { + jack_deactivate(jd->client); + jack_client_close(jd->client); + jd->client = NULL; + } + + if (jd->ringbuffer[0] != NULL) { + jack_ringbuffer_free(jd->ringbuffer[0]); + jd->ringbuffer[0] = NULL; + } + + if (jd->ringbuffer[1] != NULL) { + jack_ringbuffer_free(jd->ringbuffer[1]); + jd->ringbuffer[1] = NULL; } + + pthread_mutex_destroy(&jd->play_audio_lock); + pthread_cond_destroy(&jd->play_audio); } -static void jack_finishDriver(AudioOutput *audioOutput) +static void freeJackData(AudioOutput *audioOutput) { JackData *jd = audioOutput->data; int i; - if ( jd && jd->client ) { - jack_deactivate(jd->client); - jack_client_close(jd->client); - } - DEBUG("disconnect_jack (pid=%d)\n", getpid ()); + assert(jd != NULL); + + freeJackClient(jd); - if ( strcmp(name, "mpd") ) { - free(name); - name = "mpd"; - } + if (strcmp(jd->name, "mpd") != 0) + free(jd->name); - for ( i = ARRAY_SIZE(output_ports); --i >= 0; ) { - if (!output_ports[i]) - continue; - free(output_ports[i]); - output_ports[i] = NULL; - } + for ( i = ARRAY_SIZE(jd->output_ports); --i >= 0; ) { + if (!jd->output_ports[i]) + continue; + free(jd->output_ports[i]); + } + free(jd); +} + +static void jack_finishDriver(AudioOutput *audioOutput) +{ freeJackData(audioOutput); + DEBUG("disconnect_jack (pid=%d)\n", getpid ()); } -static int srate(jack_nframes_t rate, void *data) +static int srate(mpd_unused jack_nframes_t rate, void *data) { JackData *jd = (JackData *) ((AudioOutput*) data)->data; AudioFormat *audioFormat = &(((AudioOutput*) data)->outAudioFormat); @@ -150,9 +162,9 @@ static int process(jack_nframes_t nframes, void *arg) nframes = 0; } - if (pthread_mutex_trylock (&play_audio_lock) == 0) { - pthread_cond_signal (&play_audio); - pthread_mutex_unlock (&play_audio_lock); + if (pthread_mutex_trylock (&jd->play_audio_lock) == 0) { + pthread_cond_signal (&jd->play_audio); + pthread_mutex_unlock (&jd->play_audio_lock); } } @@ -188,12 +200,14 @@ static void error_callback(const char *msg) static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param) { + JackData *jd; BlockParam *bp; char *endptr; int val; char *cp = NULL; - audioOutput->data = NULL; + audioOutput->data = newJackData(); + jd = audioOutput->data; DEBUG("jack_initDriver (pid=%d)\n", getpid()); if ( ! param ) return 0; @@ -207,18 +221,19 @@ static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param) bp->name, bp->line, bp->value); *cp = '\0'; - output_ports[0] = xstrdup(bp->value); + jd->output_ports[0] = xstrdup(bp->value); *cp++ = ','; if (!*cp) FATAL("expected a second value for '%s' at line %d: " "%s\n", bp->name, bp->line, bp->value); - output_ports[1] = xstrdup(cp); + jd->output_ports[1] = xstrdup(cp); if (strchr(cp,',')) FATAL("Only %d values are supported for '%s' " - "at line %d\n", (int)ARRAY_SIZE(output_ports), + "at line %d\n", + (int)ARRAY_SIZE(jd->output_ports), bp->name, bp->line); } @@ -227,18 +242,18 @@ static int jack_initDriver(AudioOutput *audioOutput, ConfigParam *param) val = strtol(bp->value, &endptr, 10); if ( errno == 0 && endptr != bp->value) { - ringbuf_sz = val < 32768 ? 32768 : val; - DEBUG("ringbuffer_size=%d\n", ringbuf_sz); + jd->ringbuf_sz = val < 32768 ? 32768 : val; + DEBUG("ringbuffer_size=%d\n", jd->ringbuf_sz); } else { FATAL("%s is not a number; ringbuf_size=%d\n", - bp->value, ringbuf_sz); + bp->value, jd->ringbuf_sz); } } if ( (bp = getBlockParam(param, "name")) && (strcmp(bp->value, "mpd") != 0) ) { - name = xstrdup(bp->value); - DEBUG("name=%s\n", name); + jd->name = xstrdup(bp->value); + DEBUG("name=%s\n", jd->name); } return 0; @@ -255,9 +270,8 @@ static int connect_jack(AudioOutput *audioOutput) char **jports; char *port_name; - if ( (jd->client = jack_client_new(name)) == NULL ) { + if ( (jd->client = jack_client_new(jd->name)) == NULL ) { ERROR("jack server not running?\n"); - freeJackData(audioOutput); return -1; } @@ -269,7 +283,6 @@ static int connect_jack(AudioOutput *audioOutput) if ( jack_activate(jd->client) ) { ERROR("cannot activate client\n"); - freeJackData(audioOutput); return -1; } @@ -278,7 +291,6 @@ static int connect_jack(AudioOutput *audioOutput) JackPortIsOutput, 0); if ( !jd->ports[0] ) { ERROR("Cannot register left output port.\n"); - freeJackData(audioOutput); return -1; } @@ -287,44 +299,42 @@ static int connect_jack(AudioOutput *audioOutput) JackPortIsOutput, 0); if ( !jd->ports[1] ) { ERROR("Cannot register right output port.\n"); - freeJackData(audioOutput); return -1; } /* hay que buscar que hay */ - if ( !output_ports[1] + if ( !jd->output_ports[1] && (jports = (char **)jack_get_ports(jd->client, NULL, NULL, JackPortIsPhysical| JackPortIsInput)) ) { - output_ports[0] = jports[0]; - output_ports[1] = jports[1] ? jports[1] : jports[0]; - DEBUG("output_ports: %s %s\n", output_ports[0], output_ports[1]); + jd->output_ports[0] = jports[0]; + jd->output_ports[1] = jports[1] ? jports[1] : jports[0]; + DEBUG("output_ports: %s %s\n", + jd->output_ports[0], jd->output_ports[1]); free(jports); } - if ( output_ports[1] ) { - jd->ringbuffer[0] = jack_ringbuffer_create(ringbuf_sz); - jd->ringbuffer[1] = jack_ringbuffer_create(ringbuf_sz); + if ( jd->output_ports[1] ) { + jd->ringbuffer[0] = jack_ringbuffer_create(jd->ringbuf_sz); + jd->ringbuffer[1] = jack_ringbuffer_create(jd->ringbuf_sz); memset(jd->ringbuffer[0]->buf, 0, jd->ringbuffer[0]->size); memset(jd->ringbuffer[1]->buf, 0, jd->ringbuffer[1]->size); - port_name = xmalloc(sizeof(char)*(7+strlen(name))); + port_name = xmalloc(sizeof(char)*(7+strlen(jd->name))); - sprintf(port_name, "%s:left", name); + sprintf(port_name, "%s:left", jd->name); if ( (jack_connect(jd->client, port_name, - output_ports[0])) != 0 ) { + jd->output_ports[0])) != 0 ) { ERROR("%s is not a valid Jack Client / Port\n", - output_ports[0]); - freeJackData(audioOutput); + jd->output_ports[0]); free(port_name); return -1; } - sprintf(port_name, "%s:right", name); + sprintf(port_name, "%s:right", jd->name); if ( (jack_connect(jd->client, port_name, - output_ports[1])) != 0 ) { + jd->output_ports[1])) != 0 ) { ERROR("%s is not a valid Jack Client / Port\n", - output_ports[1]); - freeJackData(audioOutput); + jd->output_ports[1]); free(port_name); return -1; } @@ -339,16 +349,12 @@ static int jack_openDevice(AudioOutput *audioOutput) { JackData *jd = audioOutput->data; - if ( !jd ) { - DEBUG("connect!\n"); - jd = newJackData(); - audioOutput->data = jd; + assert(jd != NULL); - if (connect_jack(audioOutput) < 0) { - freeJackData(audioOutput); - audioOutput->open = 0; - return -1; - } + if (jd->client == NULL && connect_jack(audioOutput) < 0) { + freeJackClient(jd); + audioOutput->open = 0; + return -1; } set_audioformat(audioOutput); @@ -366,7 +372,7 @@ static void jack_closeDevice(AudioOutput * audioOutput) DEBUG("jack_closeDevice (pid=%d)\n", getpid()); } -static void jack_dropBufferedAudio (AudioOutput * audioOutput) +static void jack_dropBufferedAudio (mpd_unused AudioOutput * audioOutput) { } @@ -384,7 +390,7 @@ static int jack_playAudio(AudioOutput * audioOutput, if ( jd->shutdown ) { ERROR("Refusing to play, because there is no client thread.\n"); - freeJackData(audioOutput); + freeJackClient(jd); audioOutput->open = 0; return 0; } @@ -414,9 +420,10 @@ static int jack_playAudio(AudioOutput * audioOutput, samples=0; } else { - pthread_mutex_lock(&play_audio_lock); - pthread_cond_wait(&play_audio, &play_audio_lock); - pthread_mutex_unlock(&play_audio_lock); + pthread_mutex_lock(&jd->play_audio_lock); + pthread_cond_wait(&jd->play_audio, + &jd->play_audio_lock); + pthread_mutex_unlock(&jd->play_audio_lock); } } diff --git a/src/audioOutputs/audioOutput_null.c b/src/audioOutputs/audioOutput_null.c index 37ff7194a..d63004645 100644 --- a/src/audioOutputs/audioOutput_null.c +++ b/src/audioOutputs/audioOutput_null.c @@ -19,7 +19,8 @@ #include "../audioOutput.h" #include "../timer.h" -static int null_initDriver(AudioOutput *audioOutput, ConfigParam *param) +static int null_initDriver(AudioOutput *audioOutput, + mpd_unused ConfigParam *param) { audioOutput->data = NULL; return 0; @@ -43,7 +44,7 @@ static void null_closeDevice(AudioOutput *audioOutput) } static int null_playAudio(AudioOutput *audioOutput, - const char *playChunk, size_t size) + mpd_unused const char *playChunk, size_t size) { Timer *timer = audioOutput->data; diff --git a/src/audioOutputs/audioOutput_oss.c b/src/audioOutputs/audioOutput_oss.c index 2a6a4876b..2df7d5728 100644 --- a/src/audioOutputs/audioOutput_oss.c +++ b/src/audioOutputs/audioOutput_oss.c @@ -334,7 +334,8 @@ static int oss_testDefault(void) return -1; } -static int oss_open_default(AudioOutput *ao, ConfigParam *param, OssData *od) +static int oss_open_default(mpd_unused AudioOutput *ao, ConfigParam *param, + OssData *od) { int i; int err[ARRAY_SIZE(default_devices)]; diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c index 9ed5b4e7e..49d69eebd 100644 --- a/src/audioOutputs/audioOutput_shout.c +++ b/src/audioOutputs/audioOutput_shout.c @@ -413,6 +413,8 @@ static void copyTagToVorbisComment(ShoutData * sd) case TAG_ITEM_TITLE: addTag(sd, "TITLE", sd->tag->items[i].value); break; + default: + break; } } } |