aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-24 07:25:07 +0200
committerMax Kellermann <max@duempel.org>2008-09-24 07:25:07 +0200
commit9a5b5998832f1f9f6efce99f4abdf00f5fe1dfbb (patch)
tree38c1c1cceff677e7fda2837bc537acfb711130d9 /src
parent2b782b82eaadeff36fa230ce3ac30893eb6581e3 (diff)
downloadmpd-9a5b5998832f1f9f6efce99f4abdf00f5fe1dfbb.tar.gz
mpd-9a5b5998832f1f9f6efce99f4abdf00f5fe1dfbb.tar.xz
mpd-9a5b5998832f1f9f6efce99f4abdf00f5fe1dfbb.zip
output: removed DEVICE_ON, DEVICE_OFF
To check whether a device is really on or off, we should rather check audio_output.open, instead of managing another variable. Wrap audio_output.open in the inline function audio_output_is_open() and use it instead of DEVICE_ON and DEVICE_OFF.
Diffstat (limited to '')
-rw-r--r--src/audio.c43
-rw-r--r--src/output_internal.h6
2 files changed, 20 insertions, 29 deletions
diff --git a/src/audio.c b/src/audio.c
index f027be588..443f5d82d 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -36,9 +36,7 @@ static struct audio_output *audioOutputArray;
static unsigned int audioOutputArraySize;
enum ad_state {
- DEVICE_OFF = 0x00,
DEVICE_ENABLE = 0x01, /* currently off, but to be turned on */
- DEVICE_ON = 0x03,
DEVICE_DISABLE = 0x04 /* currently on, but to be turned off */
};
@@ -227,7 +225,7 @@ static void audio_output_wait_all(void)
int finished = 1;
for (i = 0; i < audioOutputArraySize; ++i)
- if (audioDeviceStates[i] == DEVICE_ON &&
+ if (audio_output_is_open(&audioOutputArray[i]) &&
!audio_output_command_is_finished(&audioOutputArray[i]))
finished = 0;
@@ -249,24 +247,16 @@ static void syncAudioDeviceStates(void)
for (i = 0; i < audioOutputArraySize; ++i) {
audioOutput = &audioOutputArray[i];
switch (audioDeviceStates[i]) {
- case DEVICE_OFF:
- break;
- case DEVICE_ON:
- /* This will reopen only if the audio format changed */
- if (audio_output_open(audioOutput,
- &audio_buffer.format) < 0)
- audioDeviceStates[i] = DEVICE_ENABLE;
- break;
case DEVICE_ENABLE:
- if (audio_output_open(audioOutput,
- &audio_buffer.format) == 0)
- audioDeviceStates[i] = DEVICE_ON;
+ audio_output_open(audioOutput, &audio_buffer.format);
break;
case DEVICE_DISABLE:
+ if (!audio_output_is_open(audioOutput))
+ break;
+
audio_output_cancel(audioOutput);
audio_output_wait(audioOutput);
audio_output_close(audioOutput);
- audioDeviceStates[i] = DEVICE_OFF;
}
}
}
@@ -282,7 +272,7 @@ static int flushAudioBuffer(void)
syncAudioDeviceStates();
for (i = 0; i < audioOutputArraySize; ++i)
- if (audioDeviceStates[i] == DEVICE_ON)
+ if (audio_output_is_open(&audioOutputArray[i]))
audio_output_play(&audioOutputArray[i],
audio_buffer.buffer,
audio_buffer.position);
@@ -293,7 +283,7 @@ static int flushAudioBuffer(void)
for (i = 0; i < audioOutputArraySize; ++i) {
const struct audio_output *ao = &audioOutputArray[i];
- if (audioDeviceStates[i] != DEVICE_ON)
+ if (!audio_output_is_open(ao))
continue;
if (audio_output_command_is_finished(ao)) {
@@ -413,7 +403,7 @@ void dropBufferedAudio(void)
audio_buffer.position = 0;
for (i = 0; i < audioOutputArraySize; ++i) {
- if (audioDeviceStates[i] == DEVICE_ON)
+ if (audio_output_is_open(&audioOutputArray[i]))
audio_output_cancel(&audioOutputArray[i]);
}
@@ -431,11 +421,8 @@ void closeAudioDevice(void)
audio_buffer.size = 0;
}
- for (i = 0; i < audioOutputArraySize; ++i) {
- if (audioDeviceStates[i] == DEVICE_ON)
- audioDeviceStates[i] = DEVICE_ENABLE;
+ for (i = 0; i < audioOutputArraySize; ++i)
audio_output_close(&audioOutputArray[i]);
- }
audioOpened = 0;
}
@@ -445,7 +432,7 @@ void sendMetadataToAudioDevice(const struct tag *tag)
unsigned int i;
for (i = 0; i < audioOutputArraySize; ++i)
- if (audioDeviceStates[i] == DEVICE_ON)
+ if (audio_output_is_open(&audioOutputArray[i]))
audio_output_send_tag(&audioOutputArray[i], tag);
audio_output_wait_all();
@@ -456,8 +443,7 @@ int enableAudioDevice(unsigned int device)
if (device >= audioOutputArraySize)
return -1;
- if (!(audioDeviceStates[device] & 0x01))
- audioDeviceStates[device] = DEVICE_ENABLE;
+ audioDeviceStates[device] = DEVICE_ENABLE;
return 0;
}
@@ -467,8 +453,7 @@ int disableAudioDevice(unsigned int device)
if (device >= audioOutputArraySize)
return -1;
- if (audioDeviceStates[device] & 0x01)
- audioDeviceStates[device] = DEVICE_DISABLE;
+ audioDeviceStates[device] = DEVICE_DISABLE;
return 0;
}
@@ -484,7 +469,7 @@ void printAudioDevices(struct client *client)
"outputenabled: %i\n",
i,
audioOutputArray[i].name,
- audioDeviceStates[i] & 0x01);
+ audioDeviceStates[i]);
}
}
@@ -495,7 +480,7 @@ void saveAudioDevicesState(FILE *fp)
assert(audioOutputArraySize != 0);
for (i = 0; i < audioOutputArraySize; i++) {
fprintf(fp, AUDIO_DEVICE_STATE "%d:%s\n",
- audioDeviceStates[i] & 0x01,
+ audioDeviceStates[i],
audioOutputArray[i].name);
}
}
diff --git a/src/output_internal.h b/src/output_internal.h
index 2455a549a..bb5ee43f5 100644
--- a/src/output_internal.h
+++ b/src/output_internal.h
@@ -110,6 +110,12 @@ struct audio_output {
extern struct notify audio_output_client_notify;
static inline int
+audio_output_is_open(const struct audio_output *ao)
+{
+ return ao->open;
+}
+
+static inline int
audio_output_command_is_finished(const struct audio_output *ao)
{
return ao->command == AO_COMMAND_NONE;