DecoderInternal: allocate PcmConvert dynamically
Reduce header dependencies and allow it to be nullptr to disable it.
This commit is contained in:
parent
a80b5cf19b
commit
f1ca61d7d7
|
@ -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) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "config.h"
|
||||
#include "DecoderInternal.hxx"
|
||||
#include "DecoderControl.hxx"
|
||||
#include "pcm/PcmConvert.hxx"
|
||||
#include "MusicPipe.hxx"
|
||||
#include "MusicBuffer.hxx"
|
||||
#include "MusicChunk.hxx"
|
||||
|
@ -32,6 +33,7 @@ Decoder::~Decoder()
|
|||
/* caller must flush the chunk */
|
||||
assert(chunk == nullptr);
|
||||
|
||||
delete convert;
|
||||
delete song_tag;
|
||||
delete stream_tag;
|
||||
delete decoder_tag;
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
#define MPD_DECODER_INTERNAL_HXX
|
||||
|
||||
#include "DecoderCommand.hxx"
|
||||
#include "pcm/PcmConvert.hxx"
|
||||
#include "ReplayGainInfo.hxx"
|
||||
|
||||
class PcmConvert;
|
||||
struct DecoderControl;
|
||||
struct InputStream;
|
||||
struct Tag;
|
||||
|
@ -31,7 +31,11 @@ struct Tag;
|
|||
struct Decoder {
|
||||
DecoderControl &dc;
|
||||
|
||||
PcmConvert conv_state;
|
||||
/**
|
||||
* For converting input data to the configured audio format.
|
||||
* nullptr means no conversion necessary.
|
||||
*/
|
||||
PcmConvert *convert;
|
||||
|
||||
/**
|
||||
* The time stamp of the next data chunk, in seconds.
|
||||
|
@ -85,6 +89,7 @@ struct Decoder {
|
|||
|
||||
Decoder(DecoderControl &_dc, bool _initial_seek_pending, Tag *_tag)
|
||||
:dc(_dc),
|
||||
convert(nullptr),
|
||||
timestamp(0),
|
||||
initial_seek_pending(_initial_seek_pending),
|
||||
initial_seek_running(false),
|
||||
|
|
Loading…
Reference in New Issue