diff options
author | Max Kellermann <max@musicpd.org> | 2019-08-03 07:49:41 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-08-03 07:49:41 +0200 |
commit | d39d2874b4642f55f9fd0c959d34eb15fe8ee972 (patch) | |
tree | f5a725740f0395634fd1072faf1fcb5e72e7e46e | |
parent | a0a74951b87402aefd15c5d93d51e5912372962f (diff) |
decoder/mad: move code to methods RunDecoder(), RunScan()
-rw-r--r-- | src/decoder/plugins/MadDecoderPlugin.cxx | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/decoder/plugins/MadDecoderPlugin.cxx b/src/decoder/plugins/MadDecoderPlugin.cxx index 509fb1381..f30c3d7ae 100644 --- a/src/decoder/plugins/MadDecoderPlugin.cxx +++ b/src/decoder/plugins/MadDecoderPlugin.cxx @@ -139,6 +139,9 @@ struct MadDecoder { MadDecoder(DecoderClient *client, InputStream &input_stream) noexcept; ~MadDecoder() noexcept; + void RunDecoder() noexcept; + bool RunScan(TagHandler &handler) noexcept; + bool Seek(long offset) noexcept; bool FillBuffer() noexcept; void ParseId3(size_t tagsize, Tag *tag) noexcept; @@ -953,53 +956,66 @@ MadDecoder::Read() noexcept } } -static void -mad_decode(DecoderClient &client, InputStream &input_stream) +inline void +MadDecoder::RunDecoder() noexcept { - MadDecoder data(&client, input_stream); + assert(client != nullptr); Tag tag; - if (!data.DecodeFirstFrame(&tag)) { - if (client.GetCommand() == DecoderCommand::NONE) + if (!DecodeFirstFrame(&tag)) { + if (client->GetCommand() == DecoderCommand::NONE) LogError(mad_domain, "input does not appear to be a mp3 bit stream"); return; } - data.AllocateBuffers(); + AllocateBuffers(); - client.Ready(CheckAudioFormat(data.frame.header.samplerate, - SampleFormat::S24_P32, - MAD_NCHANNELS(&data.frame.header)), - input_stream.IsSeekable(), - data.total_time); + client->Ready(CheckAudioFormat(frame.header.samplerate, + SampleFormat::S24_P32, + MAD_NCHANNELS(&frame.header)), + input_stream.IsSeekable(), + total_time); if (!tag.IsEmpty()) - client.SubmitTag(input_stream, std::move(tag)); + client->SubmitTag(input_stream, std::move(tag)); - while (data.Read()) {} + while (Read()) {} } -static bool -mad_decoder_scan_stream(InputStream &is, TagHandler &handler) noexcept +static void +mad_decode(DecoderClient &client, InputStream &input_stream) { - MadDecoder data(nullptr, is); - if (!data.DecodeFirstFrame(nullptr)) + MadDecoder data(&client, input_stream); + data.RunDecoder(); +} + +inline bool +MadDecoder::RunScan(TagHandler &handler) noexcept +{ + if (!DecodeFirstFrame(nullptr)) return false; - if (!data.total_time.IsNegative()) - handler.OnDuration(SongTime(data.total_time)); + if (!total_time.IsNegative()) + handler.OnDuration(SongTime(total_time)); try { - handler.OnAudioFormat(CheckAudioFormat(data.frame.header.samplerate, + handler.OnAudioFormat(CheckAudioFormat(frame.header.samplerate, SampleFormat::S24_P32, - MAD_NCHANNELS(&data.frame.header))); + MAD_NCHANNELS(&frame.header))); } catch (...) { } return true; } +static bool +mad_decoder_scan_stream(InputStream &is, TagHandler &handler) noexcept +{ + MadDecoder data(nullptr, is); + return data.RunScan(handler); +} + static const char *const mad_suffixes[] = { "mp3", "mp2", nullptr }; static const char *const mad_mime_types[] = { "audio/mpeg", nullptr }; |