mirror of
https://github.com/fmang/opustags.git
synced 2025-01-15 20:53:16 +01:00
drop ot::validate_identification_header
No more need to extract the header packet.
This commit is contained in:
parent
23049a7ff6
commit
d9dfc29b7d
@ -195,9 +195,8 @@ static ot::status process(ot::ogg_reader& reader, ot::ogg_writer* writer, const
|
||||
auto serialno = ogg_page_serialno(&reader.page);
|
||||
auto pageno = ogg_page_pageno(&reader.page);
|
||||
if (absolute_page_no == 0) { // Identification header
|
||||
rc = reader.read_header_packet(ot::validate_identification_header);
|
||||
if (rc != ot::st::ok)
|
||||
return rc;
|
||||
if (!ot::is_opus_stream(reader.page))
|
||||
return {ot::st::error, "Not an Opus stream."};
|
||||
if (writer) {
|
||||
rc = writer->write_page(reader.page);
|
||||
if (rc != ot::st::ok)
|
||||
|
14
src/opus.cc
14
src/opus.cc
@ -32,20 +32,6 @@
|
||||
#define le32toh(x) OSSwapLittleToHostInt32(x)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \todo Validate more properties of the packet, like the sequence number.
|
||||
*/
|
||||
ot::status ot::validate_identification_header(const ogg_packet& packet)
|
||||
{
|
||||
if (packet.bytes < 8)
|
||||
return {ot::st::cut_magic_number,
|
||||
"Identification header too short for the magic number"};
|
||||
if (memcmp(packet.packet, "OpusHead", 8) != 0)
|
||||
return {ot::st::bad_magic_number,
|
||||
"Identification header did not start with OpusHead"};
|
||||
return ot::st::ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* \todo See if the packet's data could be casted more nicely into a string.
|
||||
*/
|
||||
|
@ -303,15 +303,6 @@ struct opus_tags {
|
||||
std::string extra_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Validate the content of the first packet of an Ogg stream to ensure it's a valid OpusHead.
|
||||
*
|
||||
* Returns #ot::status::ok on success, #ot::status::bad_identification_header on error.
|
||||
*
|
||||
* \todo Replace with a function "identify_stream(ogg_page&)" in module ogg.
|
||||
*/
|
||||
status validate_identification_header(const ogg_packet& packet);
|
||||
|
||||
/**
|
||||
* Read the given OpusTags packet and extract its content into an opus_tags object.
|
||||
*
|
||||
|
21
t/opus.cc
21
t/opus.cc
@ -5,24 +5,6 @@
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
static void check_identification()
|
||||
{
|
||||
ogg_packet packet {};
|
||||
packet.packet = (unsigned char*) "OpusHead..";
|
||||
packet.bytes = 10;
|
||||
if (ot::validate_identification_header(packet) != ot::st::ok)
|
||||
throw failure("did not accept a good OpusHead");
|
||||
|
||||
packet.bytes = 7;
|
||||
if (ot::validate_identification_header(packet) != ot::st::cut_magic_number)
|
||||
throw failure("accepted an OpusHead that is too short");
|
||||
|
||||
packet.packet = (unsigned char*) "NotOpusHead";
|
||||
packet.bytes = 11;
|
||||
if (ot::validate_identification_header(packet) != ot::st::bad_magic_number)
|
||||
throw failure("did not report the right status for a bad OpusHead");
|
||||
}
|
||||
|
||||
static const char standard_OpusTags[] =
|
||||
"OpusTags"
|
||||
"\x14\x00\x00\x00" "opustags test packet"
|
||||
@ -156,8 +138,7 @@ static void recode_padding()
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "1..5\n";
|
||||
run(check_identification, "check the OpusHead packet");
|
||||
std::cout << "1..4\n";
|
||||
run(parse_standard, "parse a standard OpusTags packet");
|
||||
run(parse_corrupted, "correctly reject invalid packets");
|
||||
run(recode_standard, "recode a standard OpusTags packet");
|
||||
|
Loading…
x
Reference in New Issue
Block a user