decoder/mad: merge DecodeNextFrame() and DecodeNextFrameHeader()

This commit is contained in:
Max Kellermann 2019-08-03 12:55:56 +02:00
parent 52bb03e136
commit c764b70b3a

View File

@ -154,8 +154,7 @@ private:
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;
MadDecoderAction DecodeNextFrameHeader(Tag *tag) noexcept; MadDecoderAction DecodeNextFrame(bool skip, Tag *tag) noexcept;
MadDecoderAction DecodeNextFrame() noexcept;
gcc_pure gcc_pure
offset_type ThisFrameOffset() const noexcept; offset_type ThisFrameOffset() const noexcept;
@ -396,7 +395,7 @@ RecoverFrameError(const struct mad_stream &stream) noexcept
} }
MadDecoderAction MadDecoderAction
MadDecoder::DecodeNextFrameHeader(Tag *tag) noexcept MadDecoder::DecodeNextFrame(bool skip, Tag *tag) noexcept
{ {
if ((stream.buffer == nullptr || stream.error == MAD_ERROR_BUFLEN) && if ((stream.buffer == nullptr || stream.error == MAD_ERROR_BUFLEN) &&
!FillBuffer()) !FillBuffer())
@ -433,13 +432,7 @@ MadDecoder::DecodeNextFrameHeader(Tag *tag) noexcept
return MadDecoderAction::SKIP; return MadDecoderAction::SKIP;
} }
return MadDecoderAction::OK; if (!skip && mad_frame_decode(&frame, &stream))
}
MadDecoderAction
MadDecoder::DecodeNextFrame() noexcept
{
if (mad_frame_decode(&frame, &stream))
return RecoverFrameError(stream); return RecoverFrameError(stream);
return MadDecoderAction::OK; return MadDecoderAction::OK;
@ -704,20 +697,20 @@ MadDecoder::DecodeFirstFrame(Tag *tag) noexcept
struct xing xing; struct xing xing;
while (true) { while (true) {
MadDecoderAction ret; const auto action = DecodeNextFrame(false, tag);
do { switch (action) {
ret = DecodeNextFrameHeader(tag); case MadDecoderAction::SKIP:
} while (ret == MadDecoderAction::CONT); case MadDecoderAction::CONT:
if (ret == MadDecoderAction::BREAK) continue;
return false;
if (ret == MadDecoderAction::SKIP) continue;
do { case MadDecoderAction::BREAK:
ret = DecodeNextFrame();
} while (ret == MadDecoderAction::CONT);
if (ret == MadDecoderAction::BREAK)
return false; return false;
if (ret == MadDecoderAction::OK) break;
case MadDecoderAction::OK:
break;
}
break;
} }
struct mad_bitptr ptr = stream.anc_ptr; struct mad_bitptr ptr = stream.anc_ptr;
@ -941,32 +934,26 @@ inline bool
MadDecoder::LoadNextFrame() noexcept MadDecoder::LoadNextFrame() noexcept
{ {
while (true) { while (true) {
MadDecoderAction ret;
do {
Tag tag; Tag tag;
ret = DecodeNextFrameHeader(&tag); const auto action =
DecodeNextFrame(mute_frame != MadDecoderMuteFrame::NONE,
&tag);
if (!tag.IsEmpty()) if (!tag.IsEmpty())
client->SubmitTag(input_stream, client->SubmitTag(input_stream, std::move(tag));
std::move(tag));
} while (ret == MadDecoderAction::CONT); switch (action) {
if (ret == MadDecoderAction::BREAK) case MadDecoderAction::SKIP:
case MadDecoderAction::CONT:
continue;
case MadDecoderAction::BREAK:
return false; return false;
const bool skip = ret == MadDecoderAction::SKIP; case MadDecoderAction::OK:
if (mute_frame == MadDecoderMuteFrame::NONE) {
do {
ret = DecodeNextFrame();
} while (ret == MadDecoderAction::CONT);
if (ret == MadDecoderAction::BREAK)
return false;
}
if (!skip && ret == MadDecoderAction::OK)
return true; return true;
} }
}
} }
inline bool inline bool