From e9f51778ef4784ae42ff8d13b7d0f3ccfc49bead Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 17 Oct 2006 03:16:11 +0000 Subject: an attempted fix for bug 1368 - don't close and reopen an audioOutput when it has a fixed output format, and closing and reopening the device is unneccessary when the input audio format changes git-svn-id: https://svn.musicpd.org/mpd/trunk@4908 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/audioOutput.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/audioOutput.c b/src/audioOutput.c index f4750b8df..111531ba7 100644 --- a/src/audioOutput.c +++ b/src/audioOutput.c @@ -155,33 +155,38 @@ int initAudioOutput(AudioOutput *ao, ConfigParam * param) int openAudioOutput(AudioOutput * audioOutput, AudioFormat * audioFormat) { - int ret; + int ret = 0; - if (audioOutput->open) { - if (cmpAudioFormat(audioFormat, &audioOutput->inAudioFormat) - == 0) { + if (audioOutput->open) + { + if (0==cmpAudioFormat(audioFormat, &audioOutput->inAudioFormat)) + { return 0; } - closeAudioOutput(audioOutput); } copyAudioFormat(&audioOutput->inAudioFormat, audioFormat); - if (audioOutput->convertAudioFormat) { + if (audioOutput->convertAudioFormat) + { copyAudioFormat(&audioOutput->outAudioFormat, &audioOutput->reqAudioFormat); - } else { + } + else + { copyAudioFormat(&audioOutput->outAudioFormat, &audioOutput->inAudioFormat); + if (audioOutput->open) closeAudioOutput(audioOutput); } - ret = audioOutput->openDeviceFunc(audioOutput); + if (!audioOutput->open) + { + ret = audioOutput->openDeviceFunc(audioOutput); + } - if (cmpAudioFormat(&audioOutput->inAudioFormat, - &audioOutput->outAudioFormat) == 0) { - audioOutput->sameInAndOutFormats = 1; - } else - audioOutput->sameInAndOutFormats = 0; + audioOutput->sameInAndOutFormats = + !cmpAudioFormat(&audioOutput->inAudioFormat, + &audioOutput->outAudioFormat); return ret; } @@ -190,11 +195,10 @@ static void convertAudioFormat(AudioOutput * audioOutput, char **chunkArgPtr, int *sizeArgPtr) { int size = - pcm_sizeOfOutputBufferForAudioFormatConversion(& - (audioOutput-> - inAudioFormat), -*sizeArgPtr, -&(audioOutput->outAudioFormat)); + pcm_sizeOfOutputBufferForAudioFormatConversion( + &(audioOutput->inAudioFormat), + *sizeArgPtr, + &(audioOutput->outAudioFormat)); if (size > audioOutput->convBufferLen) { audioOutput->convBuffer = @@ -202,8 +206,10 @@ static void convertAudioFormat(AudioOutput * audioOutput, char **chunkArgPtr, audioOutput->convBufferLen = size; } - pcm_convertAudioFormat(&(audioOutput->inAudioFormat), *chunkArgPtr, - *sizeArgPtr, &(audioOutput->outAudioFormat), + pcm_convertAudioFormat(&(audioOutput->inAudioFormat), + *chunkArgPtr, + *sizeArgPtr, + &(audioOutput->outAudioFormat), audioOutput->convBuffer); *sizeArgPtr = size; -- cgit v1.2.3