mirror of
https://github.com/fmang/opustags.git
synced 2025-01-15 12:43:17 +01:00
Move the page counting logic in the Ogg reader
This commit is contained in:
parent
6758ae23ff
commit
b8f2518ef5
10
src/cli.cc
10
src/cli.cc
@ -357,16 +357,14 @@ static void process(ot::ogg_reader& reader, ot::ogg_writer* writer, const ot::op
|
||||
{
|
||||
bool focused = false; /*< the stream on which we operate is defined */
|
||||
int focused_serialno; /*< when focused, the serialno of the focused stream */
|
||||
int absolute_page_no = -1; /*< page number in the physical stream, not logical */
|
||||
for (;;) {
|
||||
ot::status rc = reader.next_page();
|
||||
if (rc == ot::st::end_of_stream)
|
||||
break;
|
||||
else if (rc == ot::st::bad_stream && absolute_page_no == -1)
|
||||
else if (rc == ot::st::bad_stream && reader.absolute_page_no == (size_t) -1)
|
||||
throw ot::status {ot::st::bad_stream, "Input is not a valid Ogg file."};
|
||||
else if (rc != ot::st::ok)
|
||||
throw rc;
|
||||
++absolute_page_no;
|
||||
auto serialno = ogg_page_serialno(&reader.page);
|
||||
auto pageno = ogg_page_pageno(&reader.page);
|
||||
if (!focused) {
|
||||
@ -376,7 +374,7 @@ static void process(ot::ogg_reader& reader, ot::ogg_writer* writer, const ot::op
|
||||
/** \todo Support mixed streams. */
|
||||
throw ot::status {ot::st::error, "Muxed streams are not supported yet."};
|
||||
}
|
||||
if (absolute_page_no == 0) { // Identification header
|
||||
if (reader.absolute_page_no == 0) { // Identification header
|
||||
if (!ot::is_opus_stream(reader.page))
|
||||
throw ot::status {ot::st::error, "Not an Opus stream."};
|
||||
if (writer) {
|
||||
@ -384,7 +382,7 @@ static void process(ot::ogg_reader& reader, ot::ogg_writer* writer, const ot::op
|
||||
if (rc != ot::st::ok)
|
||||
throw rc;
|
||||
}
|
||||
} else if (absolute_page_no == 1) { // Comment header
|
||||
} else if (reader.absolute_page_no == 1) { // Comment header
|
||||
ot::opus_tags tags;
|
||||
rc = reader.process_header_packet(
|
||||
[&tags](ogg_packet& p) { return ot::parse_tags(p, tags); });
|
||||
@ -409,7 +407,7 @@ static void process(ot::ogg_reader& reader, ot::ogg_writer* writer, const ot::op
|
||||
throw rc;
|
||||
}
|
||||
}
|
||||
if (absolute_page_no < 1)
|
||||
if (reader.absolute_page_no < 1)
|
||||
throw ot::status {ot::st::error, "Expected at least 2 Ogg pages."};
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ ot::status ot::ogg_reader::next_page()
|
||||
if (ogg_sync_wrote(&sync, len) != 0)
|
||||
return {st::libogg_error, "ogg_sync_wrote failed."};
|
||||
}
|
||||
++absolute_page_no;
|
||||
return st::ok;
|
||||
}
|
||||
|
||||
|
@ -258,6 +258,12 @@ struct ogg_reader {
|
||||
* to ogg_sync_pageout, wrapped by #read_page.
|
||||
*/
|
||||
ogg_page page;
|
||||
/**
|
||||
* Page number in the physical stream of the last read page, disregarding multiplexed
|
||||
* streams. The first page number is 0. When no page has been read, its value is
|
||||
* (size_t) -1.
|
||||
*/
|
||||
size_t absolute_page_no = -1;
|
||||
/**
|
||||
* The file is our source of binary data. It is not integrated to libogg, so we need to
|
||||
* handle it ourselves.
|
||||
|
Loading…
x
Reference in New Issue
Block a user