decoder/OpusHead: return pre-skip

This commit is contained in:
Max Kellermann 2020-07-01 17:48:44 +02:00
parent 472881cb95
commit a99b4abae8
3 changed files with 11 additions and 5 deletions

View File

@ -136,8 +136,8 @@ MPDOpusDecoder::OnOggBeginning(const ogg_packet &packet)
if (opus_decoder != nullptr || !IsOpusHead(packet)) if (opus_decoder != nullptr || !IsOpusHead(packet))
throw std::runtime_error("BOS packet must be OpusHead"); throw std::runtime_error("BOS packet must be OpusHead");
unsigned channels; unsigned channels, pre_skip;
if (!ScanOpusHeader(packet.packet, packet.bytes, channels) || if (!ScanOpusHeader(packet.packet, packet.bytes, channels, pre_skip) ||
!audio_valid_channel_count(channels)) !audio_valid_channel_count(channels))
throw std::runtime_error("Malformed BOS packet"); throw std::runtime_error("Malformed BOS packet");
@ -305,10 +305,12 @@ ReadAndParseOpusHead(OggSyncState &sync, OggStreamState &stream,
unsigned &channels) unsigned &channels)
{ {
ogg_packet packet; ogg_packet packet;
unsigned pre_skip;
return OggReadPacket(sync, stream, packet) && packet.b_o_s && return OggReadPacket(sync, stream, packet) && packet.b_o_s &&
IsOpusHead(packet) && IsOpusHead(packet) &&
ScanOpusHeader(packet.packet, packet.bytes, channels) && ScanOpusHeader(packet.packet, packet.bytes, channels,
pre_skip) &&
audio_valid_channel_count(channels); audio_valid_channel_count(channels);
} }

View File

@ -18,6 +18,7 @@
*/ */
#include "OpusHead.hxx" #include "OpusHead.hxx"
#include "util/ByteOrder.hxx"
#include <stdint.h> #include <stdint.h>
@ -31,12 +32,14 @@ struct OpusHead {
}; };
bool 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; const OpusHead *h = (const OpusHead *)data;
if (size < 19 || (h->version & 0xf0) != 0) if (size < 19 || (h->version & 0xf0) != 0)
return false; return false;
channels_r = h->channels; channels_r = h->channels;
pre_skip_r = FromLE16(h->pre_skip);
return true; return true;
} }

View File

@ -23,6 +23,7 @@
#include <stddef.h> #include <stddef.h>
bool 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 #endif