aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-24 07:20:36 +0200
committerMax Kellermann <max@duempel.org>2008-09-24 07:20:36 +0200
commit3cae6856b8c6096b3f932a4ab30476a8d1187e58 (patch)
treece4a7dfea71105b723779b08d37108ec3f258bdd /src
parentd32f49a90ba69525884ee6fe4f2055792aa10430 (diff)
downloadmpd-3cae6856b8c6096b3f932a4ab30476a8d1187e58.tar.gz
mpd-3cae6856b8c6096b3f932a4ab30476a8d1187e58.tar.xz
mpd-3cae6856b8c6096b3f932a4ab30476a8d1187e58.zip
output: pass audio_format to plugin.init() and plugin.open()
Pass the globally configured audio_format as a const pointer to plugin.init(). plugin.open() gets a writable pointer which contains the audio_format requested by the plugin. Its initial value is either the configured audio_format or the input file's audio_format.
Diffstat (limited to 'src')
-rw-r--r--src/audioOutputs/audioOutput_alsa.c5
-rw-r--r--src/audioOutputs/audioOutput_ao.c10
-rw-r--r--src/audioOutputs/audioOutput_fifo.c6
-rw-r--r--src/audioOutputs/audioOutput_jack.c26
-rw-r--r--src/audioOutputs/audioOutput_mvp.c5
-rw-r--r--src/audioOutputs/audioOutput_null.c6
-rw-r--r--src/audioOutputs/audioOutput_oss.c5
-rw-r--r--src/audioOutputs/audioOutput_osx.c5
-rw-r--r--src/audioOutputs/audioOutput_pulse.c6
-rw-r--r--src/audioOutputs/audioOutput_shout.c10
-rw-r--r--src/output_api.h7
-rw-r--r--src/output_init.c2
-rw-r--r--src/output_thread.c2
13 files changed, 61 insertions, 34 deletions
diff --git a/src/audioOutputs/audioOutput_alsa.c b/src/audioOutputs/audioOutput_alsa.c
index 995ee3a9a..b2e4b9025 100644
--- a/src/audioOutputs/audioOutput_alsa.c
+++ b/src/audioOutputs/audioOutput_alsa.c
@@ -73,6 +73,7 @@ static void freeAlsaData(AlsaData * ad)
}
static int alsa_initDriver(struct audio_output *audioOutput,
+ mpd_unused const struct audio_format *audio_format,
ConfigParam * param)
{
/* no need for pthread_once thread-safety when reading config */
@@ -136,10 +137,10 @@ static snd_pcm_format_t get_bitformat(const struct audio_format *af)
return SND_PCM_FORMAT_UNKNOWN;
}
-static int alsa_openDevice(struct audio_output *audioOutput)
+static int alsa_openDevice(struct audio_output *audioOutput,
+ struct audio_format *audioFormat)
{
AlsaData *ad = audioOutput->data;
- struct audio_format *audioFormat = &audioOutput->outAudioFormat;
snd_pcm_format_t bitformat;
snd_pcm_hw_params_t *hwparams;
snd_pcm_sw_params_t *swparams;
diff --git a/src/audioOutputs/audioOutput_ao.c b/src/audioOutputs/audioOutput_ao.c
index 1aa57cba2..22a4cb96a 100644
--- a/src/audioOutputs/audioOutput_ao.c
+++ b/src/audioOutputs/audioOutput_ao.c
@@ -55,6 +55,7 @@ static void audioOutputAo_error(void)
}
static int audioOutputAo_initDriver(struct audio_output *audioOutput,
+ mpd_unused const struct audio_format *audio_format,
ConfigParam * param)
{
ao_info *ai;
@@ -174,7 +175,8 @@ static void audioOutputAo_closeDevice(struct audio_output *audioOutput)
audioOutput->open = 0;
}
-static int audioOutputAo_openDevice(struct audio_output *audioOutput)
+static int audioOutputAo_openDevice(struct audio_output *audioOutput,
+ struct audio_format *audio_format)
{
ao_sample_format format;
AoData *ad = (AoData *) audioOutput->data;
@@ -183,10 +185,10 @@ static int audioOutputAo_openDevice(struct audio_output *audioOutput)
audioOutputAo_closeDevice(audioOutput);
}
- format.bits = audioOutput->outAudioFormat.bits;
- format.rate = audioOutput->outAudioFormat.sampleRate;
+ format.bits = audio_format->bits;
+ format.rate = audio_format->sampleRate;
format.byte_format = AO_FMT_NATIVE;
- format.channels = audioOutput->outAudioFormat.channels;
+ format.channels = audio_format->channels;
ad->device = ao_open_live(ad->driverId, &format, ad->options);
diff --git a/src/audioOutputs/audioOutput_fifo.c b/src/audioOutputs/audioOutput_fifo.c
index be40b25e3..a41284a14 100644
--- a/src/audioOutputs/audioOutput_fifo.c
+++ b/src/audioOutputs/audioOutput_fifo.c
@@ -152,6 +152,7 @@ static int openFifo(FifoData *fd)
}
static int fifo_initDriver(struct audio_output *audioOutput,
+ mpd_unused const struct audio_format *audio_format,
ConfigParam *param)
{
FifoData *fd;
@@ -190,14 +191,15 @@ static void fifo_finishDriver(struct audio_output *audioOutput)
freeFifoData(fd);
}
-static int fifo_openDevice(struct audio_output *audioOutput)
+static int fifo_openDevice(struct audio_output *audioOutput,
+ struct audio_format *audio_format)
{
FifoData *fd = (FifoData *)audioOutput->data;
if (fd->timer)
timer_free(fd->timer);
- fd->timer = timer_new(&audioOutput->outAudioFormat);
+ fd->timer = timer_new(audio_format);
audioOutput->open = 1;
diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c
index 04da026f9..99b9cdf8b 100644
--- a/src/audioOutputs/audioOutput_jack.c
+++ b/src/audioOutputs/audioOutput_jack.c
@@ -34,6 +34,9 @@ typedef struct _JackData {
const char *output_ports[2];
int ringbuf_sz;
+ /* for srate() only */
+ struct audio_format *audio_format;
+
/* locks */
pthread_mutex_t play_audio_lock;
pthread_cond_t play_audio;
@@ -117,7 +120,7 @@ static void jack_finishDriver(struct audio_output *audioOutput)
static int srate(mpd_unused jack_nframes_t rate, void *data)
{
JackData *jd = (JackData *) ((struct audio_output *) data)->data;
- struct audio_format *audioFormat = &(((struct audio_output *) data)->outAudioFormat);
+ struct audio_format *audioFormat = jd->audio_format;
audioFormat->sampleRate = (int)jack_get_sample_rate(jd->client);
@@ -179,10 +182,10 @@ static void shutdown_callback(void *arg)
jd->shutdown = 1;
}
-static void set_audioformat(struct audio_output *audioOutput)
+static void set_audioformat(struct audio_output *audioOutput,
+ struct audio_format *audioFormat)
{
JackData *jd = audioOutput->data;
- struct audio_format *audioFormat = &audioOutput->outAudioFormat;
audioFormat->sampleRate = (int) jack_get_sample_rate(jd->client);
DEBUG("samplerate = %d\n", audioFormat->sampleRate);
@@ -198,7 +201,9 @@ static void error_callback(const char *msg)
ERROR("jack: %s\n", msg);
}
-static int jack_initDriver(struct audio_output *audioOutput, ConfigParam *param)
+static int jack_initDriver(struct audio_output *audioOutput,
+ mpd_unused const struct audio_format *audio_format,
+ ConfigParam *param)
{
JackData *jd;
BlockParam *bp;
@@ -264,12 +269,15 @@ static int jack_testDefault(void)
return 0;
}
-static int connect_jack(struct audio_output *audioOutput)
+static int connect_jack(struct audio_output *audioOutput,
+ struct audio_format *audio_format)
{
JackData *jd = audioOutput->data;
const char **jports;
char *port_name;
+ jd->audio_format = audio_format;
+
if ( (jd->client = jack_client_new(jd->name)) == NULL ) {
ERROR("jack server not running?\n");
return -1;
@@ -345,19 +353,21 @@ static int connect_jack(struct audio_output *audioOutput)
return 1;
}
-static int jack_openDevice(struct audio_output *audioOutput)
+static int jack_openDevice(struct audio_output *audioOutput,
+ struct audio_format *audio_format)
{
JackData *jd = audioOutput->data;
assert(jd != NULL);
- if (jd->client == NULL && connect_jack(audioOutput) < 0) {
+ if (jd->client == NULL && connect_jack(audioOutput,
+ audio_format) < 0) {
freeJackClient(jd);
audioOutput->open = 0;
return -1;
}
- set_audioformat(audioOutput);
+ set_audioformat(audioOutput, audio_format);
audioOutput->open = 1;
DEBUG("jack_openDevice (pid=%d)!\n", getpid ());
diff --git a/src/audioOutputs/audioOutput_mvp.c b/src/audioOutputs/audioOutput_mvp.c
index ba41c1703..2b80a3251 100644
--- a/src/audioOutputs/audioOutput_mvp.c
+++ b/src/audioOutputs/audioOutput_mvp.c
@@ -94,6 +94,7 @@ static int mvp_testDefault(void)
}
static int mvp_initDriver(struct audio_output *audioOutput,
+ mpd_unused const struct audio_format *audio_format,
ConfigParam * param)
{
MvpData *md = xmalloc(sizeof(MvpData));
@@ -172,11 +173,11 @@ static int mvp_setPcmParams(MvpData * md, unsigned long rate, int channels,
return 0;
}
-static int mvp_openDevice(struct audio_output *audioOutput)
+static int mvp_openDevice(struct audio_output *audioOutput,
+ struct audio_format *audioFormat)
{
long long int stc = 0;
MvpData *md = audioOutput->data;
- AudioFormat *audioFormat = &audioOutput->outAudioFormat;
int mix[5] = { 0, 2, 7, 1, 0 };
if ((md->fd = open("/dev/adec_pcm", O_RDWR | O_NONBLOCK)) < 0) {
diff --git a/src/audioOutputs/audioOutput_null.c b/src/audioOutputs/audioOutput_null.c
index 28e58d49e..37e0ec0c8 100644
--- a/src/audioOutputs/audioOutput_null.c
+++ b/src/audioOutputs/audioOutput_null.c
@@ -20,15 +20,17 @@
#include "../timer.h"
static int null_initDriver(struct audio_output *audioOutput,
+ mpd_unused const struct audio_format *audio_format,
mpd_unused ConfigParam *param)
{
audioOutput->data = NULL;
return 0;
}
-static int null_openDevice(struct audio_output *audioOutput)
+static int null_openDevice(struct audio_output *audioOutput,
+ struct audio_format *audio_format)
{
- audioOutput->data = timer_new(&audioOutput->outAudioFormat);
+ audioOutput->data = timer_new(audio_format);
audioOutput->open = 1;
return 0;
}
diff --git a/src/audioOutputs/audioOutput_oss.c b/src/audioOutputs/audioOutput_oss.c
index f65312fc9..5f8db8276 100644
--- a/src/audioOutputs/audioOutput_oss.c
+++ b/src/audioOutputs/audioOutput_oss.c
@@ -375,6 +375,7 @@ static int oss_open_default(mpd_unused struct audio_output *ao,
}
static int oss_initDriver(struct audio_output *audioOutput,
+ mpd_unused const struct audio_format *audio_format,
ConfigParam * param)
{
OssData *od = newOssData();
@@ -480,11 +481,11 @@ fail:
return -1;
}
-static int oss_openDevice(struct audio_output *audioOutput)
+static int oss_openDevice(struct audio_output *audioOutput,
+ struct audio_format *audioFormat)
{
int ret;
OssData *od = audioOutput->data;
- struct audio_format *audioFormat = &audioOutput->outAudioFormat;
od->channels = (mpd_sint8)audioFormat->channels;
od->sampleRate = audioFormat->sampleRate;
diff --git a/src/audioOutputs/audioOutput_osx.c b/src/audioOutputs/audioOutput_osx.c
index 2b17666ce..260489caa 100644
--- a/src/audioOutputs/audioOutput_osx.c
+++ b/src/audioOutputs/audioOutput_osx.c
@@ -81,6 +81,7 @@ static int osx_testDefault()
}
static int osx_initDriver(struct audio_output *audioOutput,
+ mpd_unused const struct audio_format *audio_format,
ConfigParam * param)
{
OsxData *od = newOsxData();
@@ -216,13 +217,13 @@ static OSStatus osx_render(void *vdata,
return 0;
}
-static int osx_openDevice(struct audio_output *audioOutput)
+static int osx_openDevice(struct audio_output *audioOutput,
+ struct audio_format *audioFormat)
{
OsxData *od = (OsxData *) audioOutput->data;
ComponentDescription desc;
Component comp;
AURenderCallbackStruct callback;
- AudioFormat *audioFormat = &audioOutput->outAudioFormat;
AudioStreamBasicDescription streamDesc;
desc.componentType = kAudioUnitType_Output;
diff --git a/src/audioOutputs/audioOutput_pulse.c b/src/audioOutputs/audioOutput_pulse.c
index 8e76b7781..3892b5a25 100644
--- a/src/audioOutputs/audioOutput_pulse.c
+++ b/src/audioOutputs/audioOutput_pulse.c
@@ -62,6 +62,7 @@ static void freePulseData(PulseData * pd)
}
static int pulse_initDriver(struct audio_output *audioOutput,
+ mpd_unused const struct audio_format *audio_format,
ConfigParam * param)
{
BlockParam *server = NULL;
@@ -109,17 +110,16 @@ static int pulse_testDefault(void)
return 0;
}
-static int pulse_openDevice(struct audio_output *audioOutput)
+static int pulse_openDevice(struct audio_output *audioOutput,
+ struct audio_format *audioFormat)
{
PulseData *pd;
- struct audio_format *audioFormat;
pa_sample_spec ss;
time_t t;
int error;
t = time(NULL);
pd = audioOutput->data;
- audioFormat = &audioOutput->outAudioFormat;
if (pd->connAttempts != 0 &&
(t - pd->lastAttempt) < CONN_ATTEMPT_INTERVAL)
diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c
index 61657b0aa..835b6022d 100644
--- a/src/audioOutputs/audioOutput_shout.c
+++ b/src/audioOutputs/audioOutput_shout.c
@@ -88,6 +88,7 @@ static void free_shout_data(struct shout_data *sd)
}
static int my_shout_init_driver(struct audio_output *audio_output,
+ const struct audio_format *audio_format,
ConfigParam * param)
{
struct shout_data *sd;
@@ -177,7 +178,9 @@ static int my_shout_init_driver(struct audio_output *audio_output,
}
check_block_param("format");
- sd->audio_format = audio_output->reqAudioFormat;
+
+ assert(audio_format != NULL);
+ sd->audio_format = *audio_format;
block_param = getBlockParam(param, "encoding");
if (block_param) {
@@ -439,7 +442,8 @@ static int open_shout_conn(struct audio_output *audio_output)
return 0;
}
-static int my_shout_open_device(struct audio_output *audio_output)
+static int my_shout_open_device(struct audio_output *audio_output,
+ struct audio_format *audio_format)
{
struct shout_data *sd = (struct shout_data *) audio_output->data;
@@ -449,7 +453,7 @@ static int my_shout_open_device(struct audio_output *audio_output)
if (sd->timer)
timer_free(sd->timer);
- sd->timer = timer_new(&audio_output->outAudioFormat);
+ sd->timer = timer_new(audio_format);
audio_output->open = 1;
diff --git a/src/output_api.h b/src/output_api.h
index bea5c5b4c..8744fa08e 100644
--- a/src/output_api.h
+++ b/src/output_api.h
@@ -38,11 +38,14 @@ struct audio_output_plugin {
int (*test_default_device)(void);
- int (*init)(struct audio_output *ao, ConfigParam *param);
+ int (*init)(struct audio_output *ao,
+ const struct audio_format *audio_format,
+ ConfigParam *param);
void (*finish)(struct audio_output *ao);
- int (*open)(struct audio_output *ao);
+ int (*open)(struct audio_output *ao,
+ struct audio_format *audio_format);
int (*play)(struct audio_output *ao,
const char *playChunk, size_t size);
diff --git a/src/output_init.c b/src/output_init.c
index f57f39336..25883cee1 100644
--- a/src/output_init.c
+++ b/src/output_init.c
@@ -102,7 +102,7 @@ int audio_output_init(struct audio_output *ao, ConfigParam * param)
notify_init(&ao->notify);
ao->command = AO_COMMAND_NONE;
- if (plugin->init(ao, param) != 0)
+ if (plugin->init(ao, format ? &ao->reqAudioFormat : NULL, param) != 0)
return 0;
return 1;
diff --git a/src/output_thread.c b/src/output_thread.c
index eb86f0688..a93f5f64a 100644
--- a/src/output_thread.c
+++ b/src/output_thread.c
@@ -75,7 +75,7 @@ static void *audio_output_task(void *arg)
case AO_COMMAND_OPEN:
assert(!ao->open);
- ao->plugin->open(ao);
+ ao->plugin->open(ao, &ao->outAudioFormat);
ao_command_finished(ao);
break;