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.
This commit is contained in:
parent
2b782b82ea
commit
9a5b599883
43
src/audio.c
43
src/audio.c
@ -36,9 +36,7 @@ static struct audio_output *audioOutputArray;
|
|||||||
static unsigned int audioOutputArraySize;
|
static unsigned int audioOutputArraySize;
|
||||||
|
|
||||||
enum ad_state {
|
enum ad_state {
|
||||||
DEVICE_OFF = 0x00,
|
|
||||||
DEVICE_ENABLE = 0x01, /* currently off, but to be turned on */
|
DEVICE_ENABLE = 0x01, /* currently off, but to be turned on */
|
||||||
DEVICE_ON = 0x03,
|
|
||||||
DEVICE_DISABLE = 0x04 /* currently on, but to be turned off */
|
DEVICE_DISABLE = 0x04 /* currently on, but to be turned off */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -227,7 +225,7 @@ static void audio_output_wait_all(void)
|
|||||||
int finished = 1;
|
int finished = 1;
|
||||||
|
|
||||||
for (i = 0; i < audioOutputArraySize; ++i)
|
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]))
|
!audio_output_command_is_finished(&audioOutputArray[i]))
|
||||||
finished = 0;
|
finished = 0;
|
||||||
|
|
||||||
@ -249,24 +247,16 @@ static void syncAudioDeviceStates(void)
|
|||||||
for (i = 0; i < audioOutputArraySize; ++i) {
|
for (i = 0; i < audioOutputArraySize; ++i) {
|
||||||
audioOutput = &audioOutputArray[i];
|
audioOutput = &audioOutputArray[i];
|
||||||
switch (audioDeviceStates[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:
|
case DEVICE_ENABLE:
|
||||||
if (audio_output_open(audioOutput,
|
audio_output_open(audioOutput, &audio_buffer.format);
|
||||||
&audio_buffer.format) == 0)
|
|
||||||
audioDeviceStates[i] = DEVICE_ON;
|
|
||||||
break;
|
break;
|
||||||
case DEVICE_DISABLE:
|
case DEVICE_DISABLE:
|
||||||
|
if (!audio_output_is_open(audioOutput))
|
||||||
|
break;
|
||||||
|
|
||||||
audio_output_cancel(audioOutput);
|
audio_output_cancel(audioOutput);
|
||||||
audio_output_wait(audioOutput);
|
audio_output_wait(audioOutput);
|
||||||
audio_output_close(audioOutput);
|
audio_output_close(audioOutput);
|
||||||
audioDeviceStates[i] = DEVICE_OFF;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,7 +272,7 @@ static int flushAudioBuffer(void)
|
|||||||
syncAudioDeviceStates();
|
syncAudioDeviceStates();
|
||||||
|
|
||||||
for (i = 0; i < audioOutputArraySize; ++i)
|
for (i = 0; i < audioOutputArraySize; ++i)
|
||||||
if (audioDeviceStates[i] == DEVICE_ON)
|
if (audio_output_is_open(&audioOutputArray[i]))
|
||||||
audio_output_play(&audioOutputArray[i],
|
audio_output_play(&audioOutputArray[i],
|
||||||
audio_buffer.buffer,
|
audio_buffer.buffer,
|
||||||
audio_buffer.position);
|
audio_buffer.position);
|
||||||
@ -293,7 +283,7 @@ static int flushAudioBuffer(void)
|
|||||||
for (i = 0; i < audioOutputArraySize; ++i) {
|
for (i = 0; i < audioOutputArraySize; ++i) {
|
||||||
const struct audio_output *ao = &audioOutputArray[i];
|
const struct audio_output *ao = &audioOutputArray[i];
|
||||||
|
|
||||||
if (audioDeviceStates[i] != DEVICE_ON)
|
if (!audio_output_is_open(ao))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (audio_output_command_is_finished(ao)) {
|
if (audio_output_command_is_finished(ao)) {
|
||||||
@ -413,7 +403,7 @@ void dropBufferedAudio(void)
|
|||||||
audio_buffer.position = 0;
|
audio_buffer.position = 0;
|
||||||
|
|
||||||
for (i = 0; i < audioOutputArraySize; ++i) {
|
for (i = 0; i < audioOutputArraySize; ++i) {
|
||||||
if (audioDeviceStates[i] == DEVICE_ON)
|
if (audio_output_is_open(&audioOutputArray[i]))
|
||||||
audio_output_cancel(&audioOutputArray[i]);
|
audio_output_cancel(&audioOutputArray[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,11 +421,8 @@ void closeAudioDevice(void)
|
|||||||
audio_buffer.size = 0;
|
audio_buffer.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < audioOutputArraySize; ++i) {
|
for (i = 0; i < audioOutputArraySize; ++i)
|
||||||
if (audioDeviceStates[i] == DEVICE_ON)
|
|
||||||
audioDeviceStates[i] = DEVICE_ENABLE;
|
|
||||||
audio_output_close(&audioOutputArray[i]);
|
audio_output_close(&audioOutputArray[i]);
|
||||||
}
|
|
||||||
|
|
||||||
audioOpened = 0;
|
audioOpened = 0;
|
||||||
}
|
}
|
||||||
@ -445,7 +432,7 @@ void sendMetadataToAudioDevice(const struct tag *tag)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < audioOutputArraySize; ++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_send_tag(&audioOutputArray[i], tag);
|
||||||
|
|
||||||
audio_output_wait_all();
|
audio_output_wait_all();
|
||||||
@ -456,8 +443,7 @@ int enableAudioDevice(unsigned int device)
|
|||||||
if (device >= audioOutputArraySize)
|
if (device >= audioOutputArraySize)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(audioDeviceStates[device] & 0x01))
|
audioDeviceStates[device] = DEVICE_ENABLE;
|
||||||
audioDeviceStates[device] = DEVICE_ENABLE;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -467,8 +453,7 @@ int disableAudioDevice(unsigned int device)
|
|||||||
if (device >= audioOutputArraySize)
|
if (device >= audioOutputArraySize)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (audioDeviceStates[device] & 0x01)
|
audioDeviceStates[device] = DEVICE_DISABLE;
|
||||||
audioDeviceStates[device] = DEVICE_DISABLE;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -484,7 +469,7 @@ void printAudioDevices(struct client *client)
|
|||||||
"outputenabled: %i\n",
|
"outputenabled: %i\n",
|
||||||
i,
|
i,
|
||||||
audioOutputArray[i].name,
|
audioOutputArray[i].name,
|
||||||
audioDeviceStates[i] & 0x01);
|
audioDeviceStates[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,7 +480,7 @@ void saveAudioDevicesState(FILE *fp)
|
|||||||
assert(audioOutputArraySize != 0);
|
assert(audioOutputArraySize != 0);
|
||||||
for (i = 0; i < audioOutputArraySize; i++) {
|
for (i = 0; i < audioOutputArraySize; i++) {
|
||||||
fprintf(fp, AUDIO_DEVICE_STATE "%d:%s\n",
|
fprintf(fp, AUDIO_DEVICE_STATE "%d:%s\n",
|
||||||
audioDeviceStates[i] & 0x01,
|
audioDeviceStates[i],
|
||||||
audioOutputArray[i].name);
|
audioOutputArray[i].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,12 @@ struct audio_output {
|
|||||||
*/
|
*/
|
||||||
extern struct notify audio_output_client_notify;
|
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
|
static inline int
|
||||||
audio_output_command_is_finished(const struct audio_output *ao)
|
audio_output_command_is_finished(const struct audio_output *ao)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user