pcm/PcmConvert: eliminate Open() and Close()

Let the constructor and destructor do this.  This means that all users
have to be converted to allocate PcmConvert dynamically.
This commit is contained in:
Max Kellermann
2019-04-04 20:55:39 +02:00
parent 00b04468dc
commit e78d825059
9 changed files with 53 additions and 99 deletions

View File

@@ -37,15 +37,16 @@
#include <string.h>
#include <math.h>
DecoderBridge::DecoderBridge(DecoderControl &_dc, bool _initial_seek_pending,
std::unique_ptr<Tag> _tag) noexcept
:dc(_dc),
initial_seek_pending(_initial_seek_pending),
song_tag(std::move(_tag)) {}
DecoderBridge::~DecoderBridge()
{
/* caller must flush the chunk */
assert(current_chunk == nullptr);
if (convert != nullptr) {
convert->Close();
delete convert;
}
}
bool
@@ -255,11 +256,9 @@ DecoderBridge::Ready(const AudioFormat audio_format,
FormatDebug(decoder_domain, "converting to %s",
ToString(dc.out_audio_format).c_str());
convert = new PcmConvert();
try {
convert->Open(dc.in_audio_format,
dc.out_audio_format);
convert = std::make_unique<PcmConvert>(dc.in_audio_format,
dc.out_audio_format);
} catch (...) {
error = std::current_exception();
}

View File

@@ -44,7 +44,7 @@ public:
* For converting input data to the configured audio format.
* nullptr means no conversion necessary.
*/
PcmConvert *convert = nullptr;
std::unique_ptr<PcmConvert> convert;
/**
* The time stamp of the next data chunk, in seconds.
@@ -107,10 +107,7 @@ public:
std::exception_ptr error;
DecoderBridge(DecoderControl &_dc, bool _initial_seek_pending,
std::unique_ptr<Tag> _tag)
:dc(_dc),
initial_seek_pending(_initial_seek_pending),
song_tag(std::move(_tag)) {}
std::unique_ptr<Tag> _tag) noexcept;
~DecoderBridge();