decoder/OggUtil: pass Reader instance to OggFeed()
This commit is contained in:
parent
f491135318
commit
1c91d19163
@ -33,12 +33,11 @@
|
|||||||
class OggSyncState {
|
class OggSyncState {
|
||||||
ogg_sync_state oy;
|
ogg_sync_state oy;
|
||||||
|
|
||||||
InputStream &is;
|
Reader &reader;
|
||||||
Decoder *const decoder;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OggSyncState(InputStream &_is, Decoder *const _decoder=nullptr)
|
explicit OggSyncState(Reader &_reader)
|
||||||
:is(_is), decoder(_decoder) {
|
:reader(_reader) {
|
||||||
ogg_sync_init(&oy);
|
ogg_sync_init(&oy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,27 +50,27 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Feed(size_t size) {
|
bool Feed(size_t size) {
|
||||||
return OggFeed(oy, decoder, is, size);
|
return OggFeed(oy, reader, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExpectPage(ogg_page &page) {
|
bool ExpectPage(ogg_page &page) {
|
||||||
return OggExpectPage(oy, page, decoder, is);
|
return OggExpectPage(oy, page, reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExpectFirstPage(ogg_stream_state &os) {
|
bool ExpectFirstPage(ogg_stream_state &os) {
|
||||||
return OggExpectFirstPage(oy, os, decoder, is);
|
return OggExpectFirstPage(oy, os, reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExpectPageIn(ogg_stream_state &os) {
|
bool ExpectPageIn(ogg_stream_state &os) {
|
||||||
return OggExpectPageIn(oy, os, decoder, is);
|
return OggExpectPageIn(oy, os, reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExpectPageSeek(ogg_page &page) {
|
bool ExpectPageSeek(ogg_page &page) {
|
||||||
return OggExpectPageSeek(oy, page, decoder, is);
|
return OggExpectPageSeek(oy, page, reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExpectPageSeekIn(ogg_stream_state &os) {
|
bool ExpectPageSeekIn(ogg_stream_state &os) {
|
||||||
return OggExpectPageSeekIn(oy, os, decoder, is);
|
return OggExpectPageSeekIn(oy, os, reader);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,18 +19,16 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "OggUtil.hxx"
|
#include "OggUtil.hxx"
|
||||||
#include "../DecoderAPI.hxx"
|
#include "fs/io/Reader.hxx"
|
||||||
|
|
||||||
bool
|
bool
|
||||||
OggFeed(ogg_sync_state &oy, Decoder *decoder,
|
OggFeed(ogg_sync_state &oy, Reader &reader, size_t size)
|
||||||
InputStream &input_stream, size_t size)
|
|
||||||
{
|
{
|
||||||
char *buffer = ogg_sync_buffer(&oy, size);
|
char *buffer = ogg_sync_buffer(&oy, size);
|
||||||
if (buffer == nullptr)
|
if (buffer == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
size_t nbytes = decoder_read(decoder, input_stream,
|
size_t nbytes = reader.Read(buffer, size);
|
||||||
buffer, size);
|
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -39,25 +37,23 @@ OggFeed(ogg_sync_state &oy, Decoder *decoder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
OggExpectPage(ogg_sync_state &oy, ogg_page &page,
|
OggExpectPage(ogg_sync_state &oy, ogg_page &page, Reader &reader)
|
||||||
Decoder *decoder, InputStream &input_stream)
|
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
int r = ogg_sync_pageout(&oy, &page);
|
int r = ogg_sync_pageout(&oy, &page);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
return r > 0;
|
return r > 0;
|
||||||
|
|
||||||
if (!OggFeed(oy, decoder, input_stream, 1024))
|
if (!OggFeed(oy, reader, 1024))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os,
|
OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader)
|
||||||
Decoder *decoder, InputStream &is)
|
|
||||||
{
|
{
|
||||||
ogg_page page;
|
ogg_page page;
|
||||||
if (!OggExpectPage(oy, page, decoder, is))
|
if (!OggExpectPage(oy, page, reader))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ogg_stream_init(&os, ogg_page_serialno(&page));
|
ogg_stream_init(&os, ogg_page_serialno(&page));
|
||||||
@ -66,11 +62,10 @@ OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
|
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader)
|
||||||
Decoder *decoder, InputStream &is)
|
|
||||||
{
|
{
|
||||||
ogg_page page;
|
ogg_page page;
|
||||||
if (!OggExpectPage(oy, page, decoder, is))
|
if (!OggExpectPage(oy, page, reader))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ogg_stream_pagein(&os, &page);
|
ogg_stream_pagein(&os, &page);
|
||||||
@ -78,8 +73,7 @@ OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page,
|
OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, Reader &reader)
|
||||||
Decoder *decoder, InputStream &input_stream)
|
|
||||||
{
|
{
|
||||||
size_t remaining_skipped = 32768;
|
size_t remaining_skipped = 32768;
|
||||||
|
|
||||||
@ -100,17 +94,16 @@ OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OggFeed(oy, decoder, input_stream, 1024))
|
if (!OggFeed(oy, reader, 1024))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os,
|
OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader)
|
||||||
Decoder *decoder, InputStream &is)
|
|
||||||
{
|
{
|
||||||
ogg_page page;
|
ogg_page page;
|
||||||
if (!OggExpectPageSeek(oy, page, decoder, is))
|
if (!OggExpectPageSeek(oy, page, reader))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ogg_stream_pagein(&os, &page);
|
ogg_stream_pagein(&os, &page);
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
class InputStream;
|
class Reader;
|
||||||
struct Decoder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Feed data from the #InputStream into the #ogg_sync_state.
|
* Feed data from the #InputStream into the #ogg_sync_state.
|
||||||
@ -35,8 +34,7 @@ struct Decoder;
|
|||||||
* @return false on error or end-of-file
|
* @return false on error or end-of-file
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
OggFeed(ogg_sync_state &oy, Decoder *decoder, InputStream &is,
|
OggFeed(ogg_sync_state &oy, Reader &reader, size_t size);
|
||||||
size_t size);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Feed into the #ogg_sync_state until a page gets available. Garbage
|
* 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
|
* @return true if a page is available
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
OggExpectPage(ogg_sync_state &oy, ogg_page &page,
|
OggExpectPage(ogg_sync_state &oy, ogg_page &page, Reader &reader);
|
||||||
Decoder *decoder, InputStream &is);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines OggExpectPage(), ogg_stream_init() and
|
* Combines OggExpectPage(), ogg_stream_init() and
|
||||||
@ -56,8 +53,7 @@ OggExpectPage(ogg_sync_state &oy, ogg_page &page,
|
|||||||
* delivered to it
|
* delivered to it
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os,
|
OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader);
|
||||||
Decoder *decoder, InputStream &is);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines OggExpectPage() and ogg_stream_pagein().
|
* 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
|
* @return true if a page was delivered to the stream
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
|
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader);
|
||||||
Decoder *decoder, InputStream &is);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like OggExpectPage(), but allow skipping garbage (after seeking).
|
* Like OggExpectPage(), but allow skipping garbage (after seeking).
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page,
|
OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, Reader &reader);
|
||||||
Decoder *decoder, InputStream &is);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines OggExpectPageSeek() and ogg_stream_pagein().
|
* 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
|
* @return true if a page was delivered to the stream
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os,
|
OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader);
|
||||||
Decoder *decoder, InputStream &is);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#include "OggFind.hxx"
|
#include "OggFind.hxx"
|
||||||
#include "OggSyncState.hxx"
|
#include "OggSyncState.hxx"
|
||||||
#include "../DecoderAPI.hxx"
|
#include "../DecoderAPI.hxx"
|
||||||
|
#include "decoder/Reader.hxx"
|
||||||
|
#include "input/Reader.hxx"
|
||||||
#include "OggCodec.hxx"
|
#include "OggCodec.hxx"
|
||||||
#include "tag/TagHandler.hxx"
|
#include "tag/TagHandler.hxx"
|
||||||
#include "tag/TagBuilder.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
|
/* create temporary Ogg objects for seeking and parsing the
|
||||||
EOS packet */
|
EOS packet */
|
||||||
OggSyncState oy(is, decoder);
|
DecoderReader reader(decoder, is);
|
||||||
|
OggSyncState oy(reader);
|
||||||
ogg_stream_state os;
|
ogg_stream_state os;
|
||||||
ogg_stream_init(&os, serialno);
|
ogg_stream_init(&os, serialno);
|
||||||
|
|
||||||
@ -406,7 +409,8 @@ mpd_opus_stream_decode(Decoder &decoder,
|
|||||||
input_stream.LockRewind(IgnoreError());
|
input_stream.LockRewind(IgnoreError());
|
||||||
|
|
||||||
MPDOpusDecoder d(decoder, input_stream);
|
MPDOpusDecoder d(decoder, input_stream);
|
||||||
OggSyncState oy(input_stream, &decoder);
|
DecoderReader reader(decoder, input_stream);
|
||||||
|
OggSyncState oy(reader);
|
||||||
|
|
||||||
if (!d.ReadFirstPage(oy))
|
if (!d.ReadFirstPage(oy))
|
||||||
return;
|
return;
|
||||||
@ -434,7 +438,8 @@ static bool
|
|||||||
mpd_opus_scan_stream(InputStream &is,
|
mpd_opus_scan_stream(InputStream &is,
|
||||||
const TagHandler &handler, void *handler_ctx)
|
const TagHandler &handler, void *handler_ctx)
|
||||||
{
|
{
|
||||||
OggSyncState oy(is);
|
InputStreamReader reader(is);
|
||||||
|
OggSyncState oy(reader);
|
||||||
|
|
||||||
ogg_stream_state os;
|
ogg_stream_state os;
|
||||||
if (!oy.ExpectFirstPage(os))
|
if (!oy.ExpectFirstPage(os))
|
||||||
|
Loading…
Reference in New Issue
Block a user