From 356526457c49384d6ff5b652aa0f33dc74d23508 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 17 Jan 2009 13:11:16 +0100 Subject: 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. --- src/decoder_api.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'src/decoder_api.c') diff --git a/src/decoder_api.c b/src/decoder_api.c index 0ddb4ab90..831fb24b2 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -191,9 +191,7 @@ decoder_data(struct decoder *decoder, float data_time, uint16_t bitRate, struct replay_gain_info *replay_gain_info) { - static char *conv_buffer; - static size_t conv_buffer_size; - char *data; + const char *data = _data; assert(dc.state == DECODE_STATE_DECODE); assert(length % audio_format_frame_size(&dc.in_audio_format) == 0); @@ -224,28 +222,16 @@ decoder_data(struct decoder *decoder, return cmd; } - if (audio_format_equals(&dc.in_audio_format, &dc.out_audio_format)) { - data = _data; - } else { - size_t out_length = - pcm_convert_size(&dc.in_audio_format, length, - &dc.out_audio_format); - if (out_length > conv_buffer_size) { - g_free(conv_buffer); - conv_buffer = g_malloc(out_length); - conv_buffer_size = out_length; - } - - data = conv_buffer; - length = pcm_convert(&dc.in_audio_format, _data, - length, &dc.out_audio_format, - data, &decoder->conv_state); + if (!audio_format_equals(&dc.in_audio_format, &dc.out_audio_format)) { + data = pcm_convert(&decoder->conv_state, + &dc.in_audio_format, data, length, + &dc.out_audio_format, &length); /* 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 (length == 0) + if (data == NULL) return DECODE_COMMAND_NONE; } -- cgit v1.2.3