Commit d39d2874 authored by Max Kellermann's avatar Max Kellermann

decoder/mad: move code to methods RunDecoder(), RunScan()

parent a0a74951
...@@ -139,6 +139,9 @@ struct MadDecoder { ...@@ -139,6 +139,9 @@ struct MadDecoder {
MadDecoder(DecoderClient *client, InputStream &input_stream) noexcept; MadDecoder(DecoderClient *client, InputStream &input_stream) noexcept;
~MadDecoder() noexcept; ~MadDecoder() noexcept;
void RunDecoder() noexcept;
bool RunScan(TagHandler &handler) noexcept;
bool Seek(long offset) noexcept; bool Seek(long offset) noexcept;
bool FillBuffer() noexcept; bool FillBuffer() noexcept;
void ParseId3(size_t tagsize, Tag *tag) noexcept; void ParseId3(size_t tagsize, Tag *tag) noexcept;
...@@ -953,53 +956,66 @@ MadDecoder::Read() noexcept ...@@ -953,53 +956,66 @@ MadDecoder::Read() noexcept
} }
} }
static void inline void
mad_decode(DecoderClient &client, InputStream &input_stream) MadDecoder::RunDecoder() noexcept
{ {
MadDecoder data(&client, input_stream); assert(client != nullptr);
Tag tag; Tag tag;
if (!data.DecodeFirstFrame(&tag)) { if (!DecodeFirstFrame(&tag)) {
if (client.GetCommand() == DecoderCommand::NONE) if (client->GetCommand() == DecoderCommand::NONE)
LogError(mad_domain, LogError(mad_domain,
"input does not appear to be a mp3 bit stream"); "input does not appear to be a mp3 bit stream");
return; return;
} }
data.AllocateBuffers(); AllocateBuffers();
client.Ready(CheckAudioFormat(data.frame.header.samplerate, client->Ready(CheckAudioFormat(frame.header.samplerate,
SampleFormat::S24_P32, SampleFormat::S24_P32,
MAD_NCHANNELS(&data.frame.header)), MAD_NCHANNELS(&frame.header)),
input_stream.IsSeekable(), input_stream.IsSeekable(),
data.total_time); total_time);
if (!tag.IsEmpty()) if (!tag.IsEmpty())
client.SubmitTag(input_stream, std::move(tag)); client->SubmitTag(input_stream, std::move(tag));
while (data.Read()) {} while (Read()) {}
} }
static bool static void
mad_decoder_scan_stream(InputStream &is, TagHandler &handler) noexcept mad_decode(DecoderClient &client, InputStream &input_stream)
{ {
MadDecoder data(nullptr, is); MadDecoder data(&client, input_stream);
if (!data.DecodeFirstFrame(nullptr)) data.RunDecoder();
}
inline bool
MadDecoder::RunScan(TagHandler &handler) noexcept
{
if (!DecodeFirstFrame(nullptr))
return false; return false;
if (!data.total_time.IsNegative()) if (!total_time.IsNegative())
handler.OnDuration(SongTime(data.total_time)); handler.OnDuration(SongTime(total_time));
try { try {
handler.OnAudioFormat(CheckAudioFormat(data.frame.header.samplerate, handler.OnAudioFormat(CheckAudioFormat(frame.header.samplerate,
SampleFormat::S24_P32, SampleFormat::S24_P32,
MAD_NCHANNELS(&data.frame.header))); MAD_NCHANNELS(&frame.header)));
} catch (...) { } catch (...) {
} }
return true; 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_suffixes[] = { "mp3", "mp2", nullptr };
static const char *const mad_mime_types[] = { "audio/mpeg", nullptr }; static const char *const mad_mime_types[] = { "audio/mpeg", nullptr };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment