aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder_api.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-17 13:11:16 +0100
committerMax Kellermann <max@duempel.org>2009-01-17 13:11:16 +0100
commit356526457c49384d6ff5b652aa0f33dc74d23508 (patch)
treeb6fe57ffde36c366e2c6e3e650300b8e3b6126f8 /src/decoder_api.c
parente726e2a0042f88d84a167bc955fe9d280db82c90 (diff)
downloadmpd-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 'src/decoder_api.c')
-rw-r--r--src/decoder_api.c26
1 files changed, 6 insertions, 20 deletions
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;
}