decoder/mad: move code to methods RunDecoder(), RunScan()
This commit is contained in:
parent
a0a74951b8
commit
d39d2874b4
@ -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,51 +956,64 @@ 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 void
|
||||||
|
mad_decode(DecoderClient &client, InputStream &input_stream)
|
||||||
|
{
|
||||||
|
MadDecoder data(&client, input_stream);
|
||||||
|
data.RunDecoder();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
MadDecoder::RunScan(TagHandler &handler) noexcept
|
||||||
|
{
|
||||||
|
if (!DecodeFirstFrame(nullptr))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!total_time.IsNegative())
|
||||||
|
handler.OnDuration(SongTime(total_time));
|
||||||
|
|
||||||
|
try {
|
||||||
|
handler.OnAudioFormat(CheckAudioFormat(frame.header.samplerate,
|
||||||
|
SampleFormat::S24_P32,
|
||||||
|
MAD_NCHANNELS(&frame.header)));
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
mad_decoder_scan_stream(InputStream &is, TagHandler &handler) noexcept
|
mad_decoder_scan_stream(InputStream &is, TagHandler &handler) noexcept
|
||||||
{
|
{
|
||||||
MadDecoder data(nullptr, is);
|
MadDecoder data(nullptr, is);
|
||||||
if (!data.DecodeFirstFrame(nullptr))
|
return data.RunScan(handler);
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!data.total_time.IsNegative())
|
|
||||||
handler.OnDuration(SongTime(data.total_time));
|
|
||||||
|
|
||||||
try {
|
|
||||||
handler.OnAudioFormat(CheckAudioFormat(data.frame.header.samplerate,
|
|
||||||
SampleFormat::S24_P32,
|
|
||||||
MAD_NCHANNELS(&data.frame.header)));
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *const mad_suffixes[] = { "mp3", "mp2", nullptr };
|
static const char *const mad_suffixes[] = { "mp3", "mp2", nullptr };
|
||||||
|
Loading…
Reference in New Issue
Block a user