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

@@ -18,17 +18,21 @@
*/
#include "DecoderClient.hxx"
#include "pcm/PcmConvert.hxx"
#include "input/InputStream.hxx"
#include "util/ConstBuffer.hxx"
ChromaprintDecoderClient::ChromaprintDecoderClient() = default;
ChromaprintDecoderClient::~ChromaprintDecoderClient() noexcept = default;
void
ChromaprintDecoderClient::PrintResult()
{
if (!ready)
throw std::runtime_error("Decoding failed");
if (need_convert) {
auto flushed = convert.Flush();
if (convert) {
auto flushed = convert->Flush();
auto data = ConstBuffer<int16_t>::FromVoid(flushed);
chromaprint.Feed(data.data, data.size);
}
@@ -48,8 +52,8 @@ ChromaprintDecoderClient::Ready(AudioFormat audio_format, bool, SignedSongTime)
const AudioFormat src_audio_format = audio_format;
audio_format.format = SampleFormat::S16;
convert.Open(src_audio_format, audio_format);
need_convert = true;
convert = std::make_unique<PcmConvert>(src_audio_format,
audio_format);
}
chromaprint.Start(audio_format.sample_rate, audio_format.channels);
@@ -70,8 +74,8 @@ ChromaprintDecoderClient::SubmitData(InputStream *,
ConstBuffer<void> src{_data, length};
ConstBuffer<int16_t> data;
if (need_convert) {
auto result = convert.Convert(src);
if (convert) {
auto result = convert->Convert(src);
data = ConstBuffer<int16_t>::FromVoid(result);
} else
data = ConstBuffer<int16_t>::FromVoid(src);

View File

@@ -22,17 +22,18 @@
#include "Context.hxx"
#include "decoder/Client.hxx"
#include "pcm/PcmConvert.hxx"
#include "thread/Mutex.hxx"
#include <memory>
#include <stdint.h>
class PcmConvert;
class ChromaprintDecoderClient : public DecoderClient {
bool ready = false;
bool need_convert = false;
PcmConvert convert;
std::unique_ptr<PcmConvert> convert;
Chromaprint::Context chromaprint;
@@ -41,10 +42,8 @@ class ChromaprintDecoderClient : public DecoderClient {
public:
Mutex mutex;
~ChromaprintDecoderClient() noexcept {
if (need_convert)
convert.Close();
}
ChromaprintDecoderClient();
~ChromaprintDecoderClient() noexcept;
void PrintResult();