diff options
author | Max Kellermann <max@duempel.org> | 2009-01-17 13:11:16 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-17 13:11:16 +0100 |
commit | 356526457c49384d6ff5b652aa0f33dc74d23508 (patch) | |
tree | b6fe57ffde36c366e2c6e3e650300b8e3b6126f8 /src/output | |
parent | e726e2a0042f88d84a167bc955fe9d280db82c90 (diff) | |
download | mpd-356526457c49384d6ff5b652aa0f33dc74d23508.tar.gz mpd-356526457c49384d6ff5b652aa0f33dc74d23508.tar.xz mpd-356526457c49384d6ff5b652aa0f33dc74d23508.zip |
pcm_convert: return PCM buffer from pcm_convert()
Removed yet another superfluous buffer layer: return the PCM buffer
from pcm_convert() instead of copying PCM data into the
caller-supplied buffer.
Diffstat (limited to '')
-rw-r--r-- | src/output_control.c | 2 | ||||
-rw-r--r-- | src/output_init.c | 3 | ||||
-rw-r--r-- | src/output_internal.h | 2 | ||||
-rw-r--r-- | src/output_thread.c | 29 |
4 files changed, 4 insertions, 32 deletions
diff --git a/src/output_control.c b/src/output_control.c index 503001470..db3ab5622 100644 --- a/src/output_control.c +++ b/src/output_control.c @@ -142,8 +142,6 @@ void audio_output_finish(struct audio_output *audioOutput) if (audioOutput->plugin->finish) audioOutput->plugin->finish(audioOutput->data); - if (audioOutput->convBuffer) - free(audioOutput->convBuffer); notify_deinit(&audioOutput->notify); } diff --git a/src/output_init.c b/src/output_init.c index 8423e4bbb..bf92cc852 100644 --- a/src/output_init.c +++ b/src/output_init.c @@ -90,9 +90,6 @@ int audio_output_init(struct audio_output *ao, ConfigParam * param) ao->open = false; ao->reopen_after = 0; - ao->convBuffer = NULL; - ao->convBufferLen = 0; - pcm_convert_init(&ao->convState); if (format) { diff --git a/src/output_internal.h b/src/output_internal.h index 17209dd5a..dc363a6b9 100644 --- a/src/output_internal.h +++ b/src/output_internal.h @@ -79,8 +79,6 @@ struct audio_output { struct audio_format reqAudioFormat; struct pcm_convert_state convState; - char *convBuffer; - size_t convBufferLen; /** * The thread handle, or NULL if the output thread isn't diff --git a/src/output_thread.c b/src/output_thread.c index 3d5fe57d6..66f66e88c 100644 --- a/src/output_thread.c +++ b/src/output_thread.c @@ -38,29 +38,6 @@ static void ao_command_finished(struct audio_output *ao) notify_signal(&audio_output_client_notify); } -static void convertAudioFormat(struct audio_output *audioOutput, - const char **chunkArgPtr, size_t *sizeArgPtr) -{ - size_t size = pcm_convert_size(&(audioOutput->inAudioFormat), - *sizeArgPtr, - &(audioOutput->outAudioFormat)); - - if (size > audioOutput->convBufferLen) { - if (audioOutput->convBuffer != NULL) - free(audioOutput->convBuffer); - audioOutput->convBuffer = g_malloc(size); - audioOutput->convBufferLen = size; - } - - *sizeArgPtr = pcm_convert(&(audioOutput->inAudioFormat), - *chunkArgPtr, *sizeArgPtr, - &(audioOutput->outAudioFormat), - audioOutput->convBuffer, - &audioOutput->convState); - - *chunkArgPtr = audioOutput->convBuffer; -} - static void ao_play(struct audio_output *ao) { const char *data = ao->args.play.data; @@ -70,13 +47,15 @@ static void ao_play(struct audio_output *ao) assert(size > 0); if (!audio_format_equals(&ao->inAudioFormat, &ao->outAudioFormat)) { - convertAudioFormat(ao, &data, &size); + data = pcm_convert(&ao->convState, + &ao->inAudioFormat, data, size, + &ao->outAudioFormat, &size); /* under certain circumstances, pcm_convert() may return an empty buffer - this condition should be investigated further, but for now, do this check as a workaround: */ - if (size == 0) + if (data == NULL) return; } |