diff --git a/src/decoder/plugins/OpusDecoderPlugin.cxx b/src/decoder/plugins/OpusDecoderPlugin.cxx index 3b3c312af..8a262b901 100644 --- a/src/decoder/plugins/OpusDecoderPlugin.cxx +++ b/src/decoder/plugins/OpusDecoderPlugin.cxx @@ -136,8 +136,8 @@ MPDOpusDecoder::OnOggBeginning(const ogg_packet &packet) if (opus_decoder != nullptr || !IsOpusHead(packet)) throw std::runtime_error("BOS packet must be OpusHead"); - unsigned channels; - if (!ScanOpusHeader(packet.packet, packet.bytes, channels) || + unsigned channels, pre_skip; + if (!ScanOpusHeader(packet.packet, packet.bytes, channels, pre_skip) || !audio_valid_channel_count(channels)) throw std::runtime_error("Malformed BOS packet"); @@ -305,10 +305,12 @@ ReadAndParseOpusHead(OggSyncState &sync, OggStreamState &stream, unsigned &channels) { ogg_packet packet; + unsigned pre_skip; return OggReadPacket(sync, stream, packet) && packet.b_o_s && IsOpusHead(packet) && - ScanOpusHeader(packet.packet, packet.bytes, channels) && + ScanOpusHeader(packet.packet, packet.bytes, channels, + pre_skip) && audio_valid_channel_count(channels); } diff --git a/src/decoder/plugins/OpusHead.cxx b/src/decoder/plugins/OpusHead.cxx index 2c7555c79..30d959f04 100644 --- a/src/decoder/plugins/OpusHead.cxx +++ b/src/decoder/plugins/OpusHead.cxx @@ -18,6 +18,7 @@ */ #include "OpusHead.hxx" +#include "util/ByteOrder.hxx" #include @@ -31,12 +32,14 @@ struct OpusHead { }; bool -ScanOpusHeader(const void *data, size_t size, unsigned &channels_r) +ScanOpusHeader(const void *data, size_t size, unsigned &channels_r, + unsigned &pre_skip_r) { const OpusHead *h = (const OpusHead *)data; if (size < 19 || (h->version & 0xf0) != 0) return false; channels_r = h->channels; + pre_skip_r = FromLE16(h->pre_skip); return true; } diff --git a/src/decoder/plugins/OpusHead.hxx b/src/decoder/plugins/OpusHead.hxx index 5bec73208..39b5f832a 100644 --- a/src/decoder/plugins/OpusHead.hxx +++ b/src/decoder/plugins/OpusHead.hxx @@ -23,6 +23,7 @@ #include bool -ScanOpusHeader(const void *data, size_t size, unsigned &channels_r); +ScanOpusHeader(const void *data, size_t size, unsigned &channels_r, + unsigned &pre_skip_r); #endif