aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-08-01 12:00:17 +0000
committerEric Wong <normalperson@yhbt.net>2006-08-01 12:00:17 +0000
commit468c9900cae45378d6ef4d5709dcf57be8e9fa0d (patch)
tree118849f19a53875bd08a6e5ff4569c7d62ab882a
parenteb537f84f1ebcd508fded4f1a319a0da146a7fc4 (diff)
downloadmpd-468c9900cae45378d6ef4d5709dcf57be8e9fa0d.tar.gz
mpd-468c9900cae45378d6ef4d5709dcf57be8e9fa0d.tar.xz
mpd-468c9900cae45378d6ef4d5709dcf57be8e9fa0d.zip
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
Diffstat (limited to '')
-rw-r--r--src/audio.c82
1 files changed, 37 insertions, 45 deletions
diff --git a/src/audio.c b/src/audio.c
index 63aecb7f4..306f0022d 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -40,7 +40,7 @@
#define AUDIO_DEVICE_STATE_LEN 19 /* strlen(AUDIO_DEVICE_STATE) */
#define AUDIO_BUFFER_SIZE 2*MAXPATHLEN
-static AudioFormat audio_format;
+static AudioFormat audio_format = { 0, 0, 0 };
static AudioFormat *audio_configFormat = NULL;
@@ -269,29 +269,17 @@ int isCurrentAudioFormat(AudioFormat * audioFormat)
return 1;
}
-static int flushAudioBuffer(void)
+static void syncAudioDeviceStates(void)
{
- int ret = -1;
- int i, err;
-
- if (audioBufferPos == 0)
- return 0;
+ 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;
- /* fall-through */
- case DEVICE_ON:
- err = playAudioOutput(&audioOutputArray[i], audioBuffer,
- audioBufferPos);
- if (!err)
- ret = 0;
- else if (err < 0)
- /* device should already be closed if the play
- * func returned an error */
- audioDeviceStates[i] = DEVICE_OFF;
break;
case DEVICE_DISABLE:
dropBufferedAudioOutput(&audioOutputArray[i]);
@@ -300,6 +288,30 @@ static int flushAudioBuffer(void)
break;
}
}
+}
+
+static int flushAudioBuffer(void)
+{
+ int ret = -1;
+ int i, err;
+
+ if (audioBufferPos == 0)
+ return 0;
+
+ syncAudioDeviceStates();
+
+ for (i = audioOutputArraySize; --i >= 0; ) {
+ if (audioDeviceStates[i] != DEVICE_ON)
+ continue;
+ err = playAudioOutput(&audioOutputArray[i], audioBuffer,
+ audioBufferPos);
+ if (!err)
+ ret = 0;
+ else if (err < 0)
+ /* device should already be closed if the play
+ * func returned an error */
+ audioDeviceStates[i] = DEVICE_ENABLE;
+ }
audioBufferPos = 0;
@@ -324,21 +336,11 @@ int openAudioDevice(AudioFormat * audioFormat)
audioBuffer = realloc(audioBuffer, audioBufferSize);
}
+ syncAudioDeviceStates();
+
for (i = audioOutputArraySize; --i >= 0; ) {
- switch (audioDeviceStates[i]) {
- case DEVICE_ENABLE:
- openAudioOutput(&audioOutputArray[i], &audio_format);
- audioDeviceStates[i] = DEVICE_ON;
- /* fall-through */
- case DEVICE_ON:
+ if (audioOutputArray[i].open)
ret = 0;
- break;
- case DEVICE_DISABLE:
- dropBufferedAudioOutput(&audioOutputArray[i]);
- closeAudioOutput(&audioOutputArray[i]);
- audioDeviceStates[i] = DEVICE_OFF;
- break;
- }
}
if (ret == 0)
@@ -386,24 +388,12 @@ void dropBufferedAudio(void)
{
int i;
+ syncAudioDeviceStates();
audioBufferPos = 0;
+
for (i = audioOutputArraySize; --i >= 0; ) {
- switch (audioDeviceStates[i]) {
- case DEVICE_ON:
- 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:
+ if (audioDeviceStates[i] == DEVICE_ON)
dropBufferedAudioOutput(&audioOutputArray[i]);
- closeAudioOutput(&audioOutputArray[i]);
- audioDeviceStates[i] = DEVICE_OFF;
- break;
- }
}
}
@@ -418,6 +408,8 @@ void closeAudioDevice(void)
audioBufferSize = 0;
for (i = audioOutputArraySize; --i >= 0; ) {
+ if (audioDeviceStates[i] == DEVICE_ON)
+ audioDeviceStates[i] = DEVICE_ENABLE;
closeAudioOutput(&audioOutputArray[i]);
}