diff options
author | Max Kellermann <max@duempel.org> | 2013-11-13 19:10:43 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-11-13 19:16:31 +0100 |
commit | f1ca61d7d7fac7a0a93daa244bf86c2ae7ebabd7 (patch) | |
tree | 974778506726772914bf9fa64b18f533a557ecd5 /src/DecoderAPI.cxx | |
parent | a80b5cf19b8d2dda6db15444cd11aa9494546380 (diff) | |
download | mpd-f1ca61d7d7fac7a0a93daa244bf86c2ae7ebabd7.tar.gz mpd-f1ca61d7d7fac7a0a93daa244bf86c2ae7ebabd7.tar.xz mpd-f1ca61d7d7fac7a0a93daa244bf86c2ae7ebabd7.zip |
DecoderInternal: allocate PcmConvert dynamically
Reduce header dependencies and allow it to be nullptr to disable it.
Diffstat (limited to 'src/DecoderAPI.cxx')
-rw-r--r-- | src/DecoderAPI.cxx | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx index 81d56fb06..a59999bb3 100644 --- a/src/DecoderAPI.cxx +++ b/src/DecoderAPI.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "DecoderAPI.hxx" #include "DecoderError.hxx" +#include "pcm/PcmConvert.hxx" #include "AudioConfig.hxx" #include "ReplayGainConfig.hxx" #include "MusicChunk.hxx" @@ -47,6 +48,7 @@ decoder_initialized(Decoder &decoder, assert(dc.state == DecoderState::START); assert(dc.pipe != nullptr); + assert(decoder.convert == nullptr); assert(decoder.stream_tag == nullptr); assert(decoder.decoder_tag == nullptr); assert(!decoder.seeking); @@ -59,19 +61,22 @@ decoder_initialized(Decoder &decoder, dc.seekable = seekable; dc.total_time = total_time; - dc.Lock(); - dc.state = DecoderState::DECODE; - dc.client_cond.signal(); - dc.Unlock(); - FormatDebug(decoder_domain, "audio_format=%s, seekable=%s", audio_format_to_string(dc.in_audio_format, &af_string), seekable ? "true" : "false"); - if (dc.in_audio_format != dc.out_audio_format) + if (dc.in_audio_format != dc.out_audio_format) { FormatDebug(decoder_domain, "converting to %s", audio_format_to_string(dc.out_audio_format, &af_string)); + + decoder.convert = new PcmConvert(); + } + + dc.Lock(); + dc.state = DecoderState::DECODE; + dc.client_cond.signal(); + dc.Unlock(); } /** @@ -388,13 +393,15 @@ decoder_data(Decoder &decoder, return cmd; } - if (dc.in_audio_format != dc.out_audio_format) { + if (decoder.convert != nullptr) { + assert(dc.in_audio_format != dc.out_audio_format); + Error error; - data = decoder.conv_state.Convert(dc.in_audio_format, - data, length, - dc.out_audio_format, - &length, - error); + data = decoder.convert->Convert(dc.in_audio_format, + data, length, + dc.out_audio_format, + &length, + error); if (data == nullptr) { /* the PCM conversion has failed - stop playback, since we have no better way to @@ -402,6 +409,8 @@ decoder_data(Decoder &decoder, LogError(error); return DecoderCommand::STOP; } + } else { + assert(dc.in_audio_format == dc.out_audio_format); } while (length > 0) { |