From d9dfc29b7da2f7ab0867d7e9f3e5befa6b19c668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sat, 8 Dec 2018 11:28:16 -0500 Subject: [PATCH] drop ot::validate_identification_header No more need to extract the header packet. --- src/cli.cc | 5 ++--- src/opus.cc | 14 -------------- src/opustags.h | 9 --------- t/opus.cc | 21 +-------------------- 4 files changed, 3 insertions(+), 46 deletions(-) diff --git a/src/cli.cc b/src/cli.cc index 1fc453a..2b7e115 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -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) diff --git a/src/opus.cc b/src/opus.cc index 972adb0..c2bdb5d 100644 --- a/src/opus.cc +++ b/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. */ diff --git a/src/opustags.h b/src/opustags.h index e5455bd..eefe2f8 100644 --- a/src/opustags.h +++ b/src/opustags.h @@ -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. * diff --git a/t/opus.cc b/t/opus.cc index c185083..23db8be 100644 --- a/t/opus.cc +++ b/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");