output: set audio_output->open=1 in audio_output_task()

Since the output plugin returns a value indicating success or error,
we can have the output core code assign the "open" flag.
This commit is contained in:
Max Kellermann 2008-09-24 07:20:36 +02:00
parent 3cae6856b8
commit 2403d32a50
11 changed files with 8 additions and 39 deletions

View File

@ -292,8 +292,6 @@ configure_hw:
ad->sampleSize = audio_format_sample_size(audioFormat) * audioFormat->channels; ad->sampleSize = audio_format_sample_size(audioFormat) * audioFormat->channels;
audioOutput->open = 1;
DEBUG("ALSA device \"%s\" will be playing %i bit, %i channel audio at " DEBUG("ALSA device \"%s\" will be playing %i bit, %i channel audio at "
"%i Hz\n", ad->device, (int)audioFormat->bits, "%i Hz\n", ad->device, (int)audioFormat->bits,
channels, sampleRate); channels, sampleRate);
@ -312,7 +310,6 @@ fail:
if (ad->pcmHandle) if (ad->pcmHandle)
snd_pcm_close(ad->pcmHandle); snd_pcm_close(ad->pcmHandle);
ad->pcmHandle = NULL; ad->pcmHandle = NULL;
audioOutput->open = 0;
return -1; return -1;
} }
@ -372,8 +369,6 @@ static void alsa_closeDevice(struct audio_output *audioOutput)
snd_pcm_close(ad->pcmHandle); snd_pcm_close(ad->pcmHandle);
ad->pcmHandle = NULL; ad->pcmHandle = NULL;
} }
audioOutput->open = 0;
} }
static int alsa_playAudio(struct audio_output *audioOutput, static int alsa_playAudio(struct audio_output *audioOutput,

View File

@ -171,8 +171,6 @@ static void audioOutputAo_closeDevice(struct audio_output *audioOutput)
ao_close(ad->device); ao_close(ad->device);
ad->device = NULL; ad->device = NULL;
} }
audioOutput->open = 0;
} }
static int audioOutputAo_openDevice(struct audio_output *audioOutput, static int audioOutputAo_openDevice(struct audio_output *audioOutput,
@ -195,8 +193,6 @@ static int audioOutputAo_openDevice(struct audio_output *audioOutput,
if (ad->device == NULL) if (ad->device == NULL)
return -1; return -1;
audioOutput->open = 1;
return 0; return 0;
} }

View File

@ -201,8 +201,6 @@ static int fifo_openDevice(struct audio_output *audioOutput,
fd->timer = timer_new(audio_format); fd->timer = timer_new(audio_format);
audioOutput->open = 1;
return 0; return 0;
} }
@ -214,8 +212,6 @@ static void fifo_closeDevice(struct audio_output *audioOutput)
timer_free(fd->timer); timer_free(fd->timer);
fd->timer = NULL; fd->timer = NULL;
} }
audioOutput->open = 0;
} }
static void fifo_dropBufferedAudio(struct audio_output *audioOutput) static void fifo_dropBufferedAudio(struct audio_output *audioOutput)

View File

@ -363,22 +363,19 @@ static int jack_openDevice(struct audio_output *audioOutput,
if (jd->client == NULL && connect_jack(audioOutput, if (jd->client == NULL && connect_jack(audioOutput,
audio_format) < 0) { audio_format) < 0) {
freeJackClient(jd); freeJackClient(jd);
audioOutput->open = 0;
return -1; return -1;
} }
set_audioformat(audioOutput, audio_format); set_audioformat(audioOutput, audio_format);
audioOutput->open = 1;
DEBUG("jack_openDevice (pid=%d)!\n", getpid ()); DEBUG("jack_openDevice (pid=%d)!\n", getpid ());
return 0; return 0;
} }
static void jack_closeDevice(struct audio_output *audioOutput) static void jack_closeDevice(mpd_unused struct audio_output *audioOutput)
{ {
/*jack_finishDriver(audioOutput);*/ /*jack_finishDriver(audioOutput);*/
audioOutput->open = 0;
DEBUG("jack_closeDevice (pid=%d)\n", getpid()); DEBUG("jack_closeDevice (pid=%d)\n", getpid());
} }

View File

@ -208,7 +208,6 @@ static int mvp_openDevice(struct audio_output *audioOutput,
mvp_setPcmParams(md, audioFormat->sampleRate, audioFormat->channels, 1, mvp_setPcmParams(md, audioFormat->sampleRate, audioFormat->channels, 1,
audioFormat->bits); audioFormat->bits);
#endif #endif
audioOutput->open = 1;
return 0; return 0;
} }
@ -218,7 +217,6 @@ static void mvp_closeDevice(struct audio_output *audioOutput)
if (md->fd >= 0) if (md->fd >= 0)
close(md->fd); close(md->fd);
md->fd = -1; md->fd = -1;
audioOutput->open = 0;
} }
static void mvp_dropBufferedAudio(struct audio_output *audioOutput) static void mvp_dropBufferedAudio(struct audio_output *audioOutput)

View File

@ -31,7 +31,6 @@ static int null_openDevice(struct audio_output *audioOutput,
struct audio_format *audio_format) struct audio_format *audio_format)
{ {
audioOutput->data = timer_new(audio_format); audioOutput->data = timer_new(audio_format);
audioOutput->open = 1;
return 0; return 0;
} }
@ -41,8 +40,6 @@ static void null_closeDevice(struct audio_output *audioOutput)
timer_free(audioOutput->data); timer_free(audioOutput->data);
audioOutput->data = NULL; audioOutput->data = NULL;
} }
audioOutput->open = 0;
} }
static int null_playAudio(struct audio_output *audioOutput, static int null_playAudio(struct audio_output *audioOutput,

View File

@ -471,13 +471,10 @@ static int oss_open(struct audio_output *audioOutput)
goto fail; goto fail;
} }
audioOutput->open = 1;
return 0; return 0;
fail: fail:
oss_close(od); oss_close(od);
audioOutput->open = 0;
return -1; return -1;
} }
@ -509,8 +506,6 @@ static void oss_closeDevice(struct audio_output *audioOutput)
OssData *od = audioOutput->data; OssData *od = audioOutput->data;
oss_close(od); oss_close(od);
audioOutput->open = 0;
} }
static void oss_dropBufferedAudio(struct audio_output *audioOutput) static void oss_dropBufferedAudio(struct audio_output *audioOutput)

View File

@ -132,8 +132,6 @@ static void osx_closeDevice(struct audio_output *audioOutput)
CloseComponent(od->au); CloseComponent(od->au);
AudioUnitUninitialize(od->au); AudioUnitUninitialize(od->au);
audioOutput->open = 0;
} }
static OSStatus osx_render(void *vdata, static OSStatus osx_render(void *vdata,
@ -292,8 +290,6 @@ static int osx_openDevice(struct audio_output *audioOutput,
od->pos = 0; od->pos = 0;
od->len = 0; od->len = 0;
audioOutput->open = 1;
return 0; return 0;
} }

View File

@ -149,7 +149,6 @@ static int pulse_openDevice(struct audio_output *audioOutput,
} }
pd->connAttempts = 0; pd->connAttempts = 0;
audioOutput->open = 1;
DEBUG("PulseAudio output \"%s\" connected and playing %i bit, %i " DEBUG("PulseAudio output \"%s\" connected and playing %i bit, %i "
"channel audio at %i Hz\n", audioOutput->name, audioFormat->bits, "channel audio at %i Hz\n", audioOutput->name, audioFormat->bits,
@ -178,8 +177,6 @@ static void pulse_closeDevice(struct audio_output *audioOutput)
pa_simple_drain(pd->s, NULL); pa_simple_drain(pd->s, NULL);
pa_simple_free(pd->s); pa_simple_free(pd->s);
} }
audioOutput->open = 0;
} }
static int pulse_playAudio(struct audio_output *audioOutput, static int pulse_playAudio(struct audio_output *audioOutput,

View File

@ -358,8 +358,6 @@ static void my_shout_close_device(struct audio_output *audio_output)
timer_free(sd->timer); timer_free(sd->timer);
sd->timer = NULL; sd->timer = NULL;
} }
audio_output->open = 0;
} }
static int shout_connect(struct shout_data *sd) static int shout_connect(struct shout_data *sd)
@ -455,8 +453,6 @@ static int my_shout_open_device(struct audio_output *audio_output,
sd->timer = timer_new(audio_format); sd->timer = timer_new(audio_format);
audio_output->open = 1;
return 0; return 0;
} }

View File

@ -75,13 +75,19 @@ static void *audio_output_task(void *arg)
case AO_COMMAND_OPEN: case AO_COMMAND_OPEN:
assert(!ao->open); assert(!ao->open);
ao->plugin->open(ao, &ao->outAudioFormat); ao->result = ao->plugin->open(ao, &ao->outAudioFormat);
assert(!ao->open);
if (ao->result == 0)
ao->open = 1;
ao_command_finished(ao); ao_command_finished(ao);
break; break;
case AO_COMMAND_CLOSE: case AO_COMMAND_CLOSE:
assert(ao->open); assert(ao->open);
ao->plugin->close(ao); ao->plugin->close(ao);
ao->open = 0;
ao_command_finished(ao); ao_command_finished(ao);
break; break;