diff --git a/src/decoder/plugins/OggSyncState.hxx b/src/decoder/plugins/OggSyncState.hxx index 478021475..60379f8c6 100644 --- a/src/decoder/plugins/OggSyncState.hxx +++ b/src/decoder/plugins/OggSyncState.hxx @@ -33,12 +33,11 @@ class OggSyncState { ogg_sync_state oy; - InputStream &is; - Decoder *const decoder; + Reader &reader; public: - OggSyncState(InputStream &_is, Decoder *const _decoder=nullptr) - :is(_is), decoder(_decoder) { + explicit OggSyncState(Reader &_reader) + :reader(_reader) { ogg_sync_init(&oy); } @@ -51,27 +50,27 @@ public: } bool Feed(size_t size) { - return OggFeed(oy, decoder, is, size); + return OggFeed(oy, reader, size); } bool ExpectPage(ogg_page &page) { - return OggExpectPage(oy, page, decoder, is); + return OggExpectPage(oy, page, reader); } bool ExpectFirstPage(ogg_stream_state &os) { - return OggExpectFirstPage(oy, os, decoder, is); + return OggExpectFirstPage(oy, os, reader); } bool ExpectPageIn(ogg_stream_state &os) { - return OggExpectPageIn(oy, os, decoder, is); + return OggExpectPageIn(oy, os, reader); } bool ExpectPageSeek(ogg_page &page) { - return OggExpectPageSeek(oy, page, decoder, is); + return OggExpectPageSeek(oy, page, reader); } bool ExpectPageSeekIn(ogg_stream_state &os) { - return OggExpectPageSeekIn(oy, os, decoder, is); + return OggExpectPageSeekIn(oy, os, reader); } }; diff --git a/src/decoder/plugins/OggUtil.cxx b/src/decoder/plugins/OggUtil.cxx index d72412024..a5bf3976c 100644 --- a/src/decoder/plugins/OggUtil.cxx +++ b/src/decoder/plugins/OggUtil.cxx @@ -19,18 +19,16 @@ #include "config.h" #include "OggUtil.hxx" -#include "../DecoderAPI.hxx" +#include "fs/io/Reader.hxx" bool -OggFeed(ogg_sync_state &oy, Decoder *decoder, - InputStream &input_stream, size_t size) +OggFeed(ogg_sync_state &oy, Reader &reader, size_t size) { char *buffer = ogg_sync_buffer(&oy, size); if (buffer == nullptr) return false; - size_t nbytes = decoder_read(decoder, input_stream, - buffer, size); + size_t nbytes = reader.Read(buffer, size); if (nbytes == 0) return false; @@ -39,25 +37,23 @@ OggFeed(ogg_sync_state &oy, Decoder *decoder, } bool -OggExpectPage(ogg_sync_state &oy, ogg_page &page, - Decoder *decoder, InputStream &input_stream) +OggExpectPage(ogg_sync_state &oy, ogg_page &page, Reader &reader) { while (true) { int r = ogg_sync_pageout(&oy, &page); if (r != 0) return r > 0; - if (!OggFeed(oy, decoder, input_stream, 1024)) + if (!OggFeed(oy, reader, 1024)) return false; } } bool -OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, InputStream &is) +OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader) { ogg_page page; - if (!OggExpectPage(oy, page, decoder, is)) + if (!OggExpectPage(oy, page, reader)) return false; ogg_stream_init(&os, ogg_page_serialno(&page)); @@ -66,11 +62,10 @@ OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, } bool -OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, InputStream &is) +OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader) { ogg_page page; - if (!OggExpectPage(oy, page, decoder, is)) + if (!OggExpectPage(oy, page, reader)) return false; ogg_stream_pagein(&os, &page); @@ -78,8 +73,7 @@ OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, } bool -OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, - Decoder *decoder, InputStream &input_stream) +OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, Reader &reader) { size_t remaining_skipped = 32768; @@ -100,17 +94,16 @@ OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, continue; } - if (!OggFeed(oy, decoder, input_stream, 1024)) + if (!OggFeed(oy, reader, 1024)) return false; } } bool -OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, InputStream &is) +OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader) { ogg_page page; - if (!OggExpectPageSeek(oy, page, decoder, is)) + if (!OggExpectPageSeek(oy, page, reader)) return false; ogg_stream_pagein(&os, &page); diff --git a/src/decoder/plugins/OggUtil.hxx b/src/decoder/plugins/OggUtil.hxx index 887a34f01..6fb477acb 100644 --- a/src/decoder/plugins/OggUtil.hxx +++ b/src/decoder/plugins/OggUtil.hxx @@ -26,8 +26,7 @@ #include -class InputStream; -struct Decoder; +class Reader; /** * Feed data from the #InputStream into the #ogg_sync_state. @@ -35,8 +34,7 @@ struct Decoder; * @return false on error or end-of-file */ bool -OggFeed(ogg_sync_state &oy, Decoder *decoder, InputStream &is, - size_t size); +OggFeed(ogg_sync_state &oy, Reader &reader, size_t size); /** * Feed into the #ogg_sync_state until a page gets available. Garbage @@ -45,8 +43,7 @@ OggFeed(ogg_sync_state &oy, Decoder *decoder, InputStream &is, * @return true if a page is available */ bool -OggExpectPage(ogg_sync_state &oy, ogg_page &page, - Decoder *decoder, InputStream &is); +OggExpectPage(ogg_sync_state &oy, ogg_page &page, Reader &reader); /** * Combines OggExpectPage(), ogg_stream_init() and @@ -56,8 +53,7 @@ OggExpectPage(ogg_sync_state &oy, ogg_page &page, * delivered to it */ bool -OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, InputStream &is); +OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader); /** * Combines OggExpectPage() and ogg_stream_pagein(). @@ -65,15 +61,13 @@ OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, * @return true if a page was delivered to the stream */ bool -OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, InputStream &is); +OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader); /** * Like OggExpectPage(), but allow skipping garbage (after seeking). */ bool -OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, - Decoder *decoder, InputStream &is); +OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, Reader &reader); /** * Combines OggExpectPageSeek() and ogg_stream_pagein(). @@ -81,7 +75,6 @@ OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, * @return true if a page was delivered to the stream */ bool -OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, - Decoder *decoder, InputStream &is); +OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader); #endif diff --git a/src/decoder/plugins/OpusDecoderPlugin.cxx b/src/decoder/plugins/OpusDecoderPlugin.cxx index df16eae37..aeffeb488 100644 --- a/src/decoder/plugins/OpusDecoderPlugin.cxx +++ b/src/decoder/plugins/OpusDecoderPlugin.cxx @@ -25,6 +25,8 @@ #include "OggFind.hxx" #include "OggSyncState.hxx" #include "../DecoderAPI.hxx" +#include "decoder/Reader.hxx" +#include "input/Reader.hxx" #include "OggCodec.hxx" #include "tag/TagHandler.hxx" #include "tag/TagBuilder.hxx" @@ -205,7 +207,8 @@ LoadEOSPacket(InputStream &is, Decoder *decoder, int serialno, /* create temporary Ogg objects for seeking and parsing the EOS packet */ - OggSyncState oy(is, decoder); + DecoderReader reader(decoder, is); + OggSyncState oy(reader); ogg_stream_state os; ogg_stream_init(&os, serialno); @@ -406,7 +409,8 @@ mpd_opus_stream_decode(Decoder &decoder, input_stream.LockRewind(IgnoreError()); MPDOpusDecoder d(decoder, input_stream); - OggSyncState oy(input_stream, &decoder); + DecoderReader reader(decoder, input_stream); + OggSyncState oy(reader); if (!d.ReadFirstPage(oy)) return; @@ -434,7 +438,8 @@ static bool mpd_opus_scan_stream(InputStream &is, const TagHandler &handler, void *handler_ctx) { - OggSyncState oy(is); + InputStreamReader reader(is); + OggSyncState oy(reader); ogg_stream_state os; if (!oy.ExpectFirstPage(os))