Commit 1af59d31 authored by Max Kellermann's avatar Max Kellermann

decoder/opus: add method IsInitialized()

parent 20758cef
...@@ -102,6 +102,13 @@ public: ...@@ -102,6 +102,13 @@ public:
~MPDOpusDecoder(); ~MPDOpusDecoder();
/**
* Has decoder_initialized() been called yet?
*/
bool IsInitialized() const {
return previous_channels != 0;
}
bool ReadNextPage(OggSyncState &oy); bool ReadNextPage(OggSyncState &oy);
DecoderCommand HandlePackets(); DecoderCommand HandlePackets();
...@@ -240,9 +247,9 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet) ...@@ -240,9 +247,9 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
} }
assert(opus_decoder == nullptr); assert(opus_decoder == nullptr);
assert((previous_channels == 0) == (output_buffer == nullptr)); assert(IsInitialized() == (output_buffer != nullptr));
if (previous_channels != 0 && channels != previous_channels) { if (IsInitialized() && channels != previous_channels) {
FormatWarning(opus_domain, FormatWarning(opus_domain,
"Next stream has different channels (%u -> %u)", "Next stream has different channels (%u -> %u)",
previous_channels, channels); previous_channels, channels);
...@@ -263,7 +270,7 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet) ...@@ -263,7 +270,7 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
return DecoderCommand::STOP; return DecoderCommand::STOP;
} }
if (previous_channels != 0) { if (IsInitialized()) {
/* decoder was already initialized by the previous /* decoder was already initialized by the previous
stream; skip the rest of this method */ stream; skip the rest of this method */
LogDebug(opus_domain, "Found another stream"); LogDebug(opus_domain, "Found another stream");
...@@ -293,7 +300,7 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet) ...@@ -293,7 +300,7 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
inline DecoderCommand inline DecoderCommand
MPDOpusDecoder::HandleEOS() MPDOpusDecoder::HandleEOS()
{ {
if (eos_granulepos < 0 && previous_channels != 0) { if (eos_granulepos < 0 && IsInitialized()) {
/* allow chaining of (unseekable) streams */ /* allow chaining of (unseekable) streams */
assert(opus_decoder != nullptr); assert(opus_decoder != nullptr);
assert(output_buffer != nullptr); assert(output_buffer != 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