diff options
author | Max Kellermann <max@duempel.org> | 2013-01-08 01:22:11 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-08 01:22:11 +0100 |
commit | 61e7e531c2e05133f3f01aa559e4b6137f47f4a2 (patch) | |
tree | e7df4b713f05d6e3a2fa145374709a8fcb290163 /src | |
parent | ceb652915fece074301fba6ad7e21768248d93bc (diff) | |
download | mpd-61e7e531c2e05133f3f01aa559e4b6137f47f4a2.tar.gz mpd-61e7e531c2e05133f3f01aa559e4b6137f47f4a2.tar.xz mpd-61e7e531c2e05133f3f01aa559e4b6137f47f4a2.zip |
decoder/Opus: move page reader into the decoder class
Diffstat (limited to 'src')
-rw-r--r-- | src/decoder/OpusDecoderPlugin.cxx | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx index 33bf90fec..c4d6c2d12 100644 --- a/src/decoder/OpusDecoderPlugin.cxx +++ b/src/decoder/OpusDecoderPlugin.cxx @@ -84,7 +84,9 @@ public: :decoder(_decoder), input_stream(_input_stream) {} ~MPDOpusDecoder(); - enum decoder_command HandlePage(ogg_page &page); + bool ReadFirstPage(ogg_sync_state &oy); + bool ReadNextPage(ogg_sync_state &oy); + enum decoder_command HandlePackets(); enum decoder_command HandlePacket(const ogg_packet &packet); enum decoder_command HandleBOS(const ogg_packet &packet); @@ -103,19 +105,33 @@ MPDOpusDecoder::~MPDOpusDecoder() ogg_stream_clear(&os); } -inline enum decoder_command -MPDOpusDecoder::HandlePage(ogg_page &page) +inline bool +MPDOpusDecoder::ReadFirstPage(ogg_sync_state &oy) { + assert(!os_initialized); + + if (!OggExpectFirstPage(oy, os, decoder, input_stream)) + return false; + + os_initialized = true; + return true; +} + +inline bool +MPDOpusDecoder::ReadNextPage(ogg_sync_state &oy) +{ + assert(os_initialized); + + ogg_page page; + if (!OggExpectPage(oy, page, decoder, input_stream)) + return false; + const auto page_serialno = ogg_page_serialno(&page); - if (!os_initialized) { - os_initialized = true; - ogg_stream_init(&os, page_serialno); - } else if (page_serialno != os.serialno) + if (page_serialno != os.serialno) ogg_stream_reset_serialno(&os, page_serialno); ogg_stream_pagein(&os, &page); - - return HandlePackets(); + return true; } inline enum decoder_command @@ -256,14 +272,19 @@ mpd_opus_stream_decode(struct decoder *decoder, ogg_sync_state oy; ogg_sync_init(&oy); + if (!d.ReadFirstPage(oy)) { + ogg_sync_clear(&oy); + return; + } + while (true) { - ogg_page page; - if (!OggExpectPage(oy, page, decoder, input_stream)) + enum decoder_command cmd = d.HandlePackets(); + if (cmd != DECODE_COMMAND_NONE) break; - enum decoder_command cmd = d.HandlePage(page); - if (cmd != DECODE_COMMAND_NONE) + if (!d.ReadNextPage(oy)) break; + } ogg_sync_clear(&oy); |