audio: pause/resume-from-statefile bugfixes,
Oops, I broke pause/resuming from a statefile r4514 Everything should be fixed out. Also we now avoid opening the audio device until we have a playable audio_format set. This is a long-standing bug that got exposed more blatantly with the single array. Thanks to MattD in #mpd for reporting my breakage. git-svn-id: https://svn.musicpd.org/mpd/trunk@4516 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
eb537f84f1
commit
468c9900ca
78
src/audio.c
78
src/audio.c
@ -40,7 +40,7 @@
|
|||||||
#define AUDIO_DEVICE_STATE_LEN 19 /* strlen(AUDIO_DEVICE_STATE) */
|
#define AUDIO_DEVICE_STATE_LEN 19 /* strlen(AUDIO_DEVICE_STATE) */
|
||||||
#define AUDIO_BUFFER_SIZE 2*MAXPATHLEN
|
#define AUDIO_BUFFER_SIZE 2*MAXPATHLEN
|
||||||
|
|
||||||
static AudioFormat audio_format;
|
static AudioFormat audio_format = { 0, 0, 0 };
|
||||||
|
|
||||||
static AudioFormat *audio_configFormat = NULL;
|
static AudioFormat *audio_configFormat = NULL;
|
||||||
|
|
||||||
@ -269,6 +269,27 @@ int isCurrentAudioFormat(AudioFormat * audioFormat)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void syncAudioDeviceStates(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!audio_format.channels)
|
||||||
|
return;
|
||||||
|
for (i = audioOutputArraySize; --i >= 0; ) {
|
||||||
|
switch (audioDeviceStates[i]) {
|
||||||
|
case DEVICE_ENABLE:
|
||||||
|
openAudioOutput(&audioOutputArray[i], &audio_format);
|
||||||
|
audioDeviceStates[i] = DEVICE_ON;
|
||||||
|
break;
|
||||||
|
case DEVICE_DISABLE:
|
||||||
|
dropBufferedAudioOutput(&audioOutputArray[i]);
|
||||||
|
closeAudioOutput(&audioOutputArray[i]);
|
||||||
|
audioDeviceStates[i] = DEVICE_OFF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int flushAudioBuffer(void)
|
static int flushAudioBuffer(void)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -277,13 +298,11 @@ static int flushAudioBuffer(void)
|
|||||||
if (audioBufferPos == 0)
|
if (audioBufferPos == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
syncAudioDeviceStates();
|
||||||
|
|
||||||
for (i = audioOutputArraySize; --i >= 0; ) {
|
for (i = audioOutputArraySize; --i >= 0; ) {
|
||||||
switch (audioDeviceStates[i]) {
|
if (audioDeviceStates[i] != DEVICE_ON)
|
||||||
case DEVICE_ENABLE:
|
continue;
|
||||||
openAudioOutput(&audioOutputArray[i], &audio_format);
|
|
||||||
audioDeviceStates[i] = DEVICE_ON;
|
|
||||||
/* fall-through */
|
|
||||||
case DEVICE_ON:
|
|
||||||
err = playAudioOutput(&audioOutputArray[i], audioBuffer,
|
err = playAudioOutput(&audioOutputArray[i], audioBuffer,
|
||||||
audioBufferPos);
|
audioBufferPos);
|
||||||
if (!err)
|
if (!err)
|
||||||
@ -291,14 +310,7 @@ static int flushAudioBuffer(void)
|
|||||||
else if (err < 0)
|
else if (err < 0)
|
||||||
/* device should already be closed if the play
|
/* device should already be closed if the play
|
||||||
* func returned an error */
|
* func returned an error */
|
||||||
audioDeviceStates[i] = DEVICE_OFF;
|
audioDeviceStates[i] = DEVICE_ENABLE;
|
||||||
break;
|
|
||||||
case DEVICE_DISABLE:
|
|
||||||
dropBufferedAudioOutput(&audioOutputArray[i]);
|
|
||||||
closeAudioOutput(&audioOutputArray[i]);
|
|
||||||
audioDeviceStates[i] = DEVICE_OFF;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
audioBufferPos = 0;
|
audioBufferPos = 0;
|
||||||
@ -324,21 +336,11 @@ int openAudioDevice(AudioFormat * audioFormat)
|
|||||||
audioBuffer = realloc(audioBuffer, audioBufferSize);
|
audioBuffer = realloc(audioBuffer, audioBufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syncAudioDeviceStates();
|
||||||
|
|
||||||
for (i = audioOutputArraySize; --i >= 0; ) {
|
for (i = audioOutputArraySize; --i >= 0; ) {
|
||||||
switch (audioDeviceStates[i]) {
|
if (audioOutputArray[i].open)
|
||||||
case DEVICE_ENABLE:
|
|
||||||
openAudioOutput(&audioOutputArray[i], &audio_format);
|
|
||||||
audioDeviceStates[i] = DEVICE_ON;
|
|
||||||
/* fall-through */
|
|
||||||
case DEVICE_ON:
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
|
||||||
case DEVICE_DISABLE:
|
|
||||||
dropBufferedAudioOutput(&audioOutputArray[i]);
|
|
||||||
closeAudioOutput(&audioOutputArray[i]);
|
|
||||||
audioDeviceStates[i] = DEVICE_OFF;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
@ -386,24 +388,12 @@ void dropBufferedAudio(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
syncAudioDeviceStates();
|
||||||
audioBufferPos = 0;
|
audioBufferPos = 0;
|
||||||
|
|
||||||
for (i = audioOutputArraySize; --i >= 0; ) {
|
for (i = audioOutputArraySize; --i >= 0; ) {
|
||||||
switch (audioDeviceStates[i]) {
|
if (audioDeviceStates[i] == DEVICE_ON)
|
||||||
case DEVICE_ON:
|
|
||||||
dropBufferedAudioOutput(&audioOutputArray[i]);
|
dropBufferedAudioOutput(&audioOutputArray[i]);
|
||||||
break;
|
|
||||||
case DEVICE_ENABLE:
|
|
||||||
openAudioOutput(&audioOutputArray[i], &audio_format);
|
|
||||||
audioDeviceStates[i] = DEVICE_ON;
|
|
||||||
/* there's no point in dropping audio for something
|
|
||||||
* we just enabled */
|
|
||||||
break;
|
|
||||||
case DEVICE_DISABLE:
|
|
||||||
dropBufferedAudioOutput(&audioOutputArray[i]);
|
|
||||||
closeAudioOutput(&audioOutputArray[i]);
|
|
||||||
audioDeviceStates[i] = DEVICE_OFF;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,6 +408,8 @@ void closeAudioDevice(void)
|
|||||||
audioBufferSize = 0;
|
audioBufferSize = 0;
|
||||||
|
|
||||||
for (i = audioOutputArraySize; --i >= 0; ) {
|
for (i = audioOutputArraySize; --i >= 0; ) {
|
||||||
|
if (audioDeviceStates[i] == DEVICE_ON)
|
||||||
|
audioDeviceStates[i] = DEVICE_ENABLE;
|
||||||
closeAudioOutput(&audioOutputArray[i]);
|
closeAudioOutput(&audioOutputArray[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user