73 if (*ptr >= end || val > INT_MAX - 254)
101 pkt->
code = (i ) & 0x3;
102 pkt->
stereo = (i >> 2) & 0x1;
103 pkt->
config = (i >> 3) & 0x1F;
106 if (pkt->
code >= 2 && buf_size < 2)
115 if (self_delimiting) {
117 if (len < 0 || len > end - ptr)
120 buf_size = end -
buf;
123 frame_bytes = end - ptr;
134 if (self_delimiting) {
136 if (len < 0 || 2 * len > end - ptr)
139 buf_size = end -
buf;
142 frame_bytes = end - ptr;
160 if (self_delimiting) {
162 if (len < 0 || len + frame_bytes > end - ptr)
164 end = ptr + frame_bytes +
len;
165 buf_size = end -
buf;
182 padding = (i >> 6) & 0x01;
183 pkt->
vbr = (i >> 7) & 0x01;
205 total_bytes += frame_bytes;
208 if (self_delimiting) {
210 if (len < 0 || len + total_bytes + padding > end - ptr)
212 end = ptr + total_bytes + len + padding;
213 buf_size = end -
buf;
216 frame_bytes = end - ptr - padding;
217 if (total_bytes > frame_bytes)
226 if (self_delimiting) {
228 if (frame_bytes < 0 || pkt->frame_count * frame_bytes + padding > end - ptr)
230 end = ptr + pkt->
frame_count * frame_bytes + padding;
231 buf_size = end -
buf;
233 frame_bytes = end - ptr - padding;
261 }
else if (pkt->
config < 16) {
275 memset(pkt, 0,
sizeof(*pkt));
292 static const uint8_t default_channel_map[2] = { 0, 1 };
298 int version, channels, map_type, streams, stereo_streams, i, j;
304 "Multichannel configuration without extradata.\n");
314 if (extradata_size < 19) {
320 version = extradata[8];
338 map_type = extradata[18];
342 "Channel mapping 0 is only specified for up to 2 channels\n");
347 stereo_streams = channels - 1;
348 channel_map = default_channel_map;
349 }
else if (map_type == 1 || map_type == 255) {
350 if (extradata_size < 21 + channels) {
356 streams = extradata[19];
357 stereo_streams = extradata[20];
358 if (!streams || stereo_streams > streams ||
359 streams + stereo_streams > 255) {
361 "Invalid stream/stereo stream count: %d/%d\n", streams, stereo_streams);
368 "Channel mapping 1 is only specified for up to 8 channels\n");
376 channel_map = extradata + 21;
386 for (i = 0; i < channels; i++) {
388 uint8_t idx = channel_map[channel_reorder(channels, i)];
393 }
else if (idx >= streams + stereo_streams) {
395 "Invalid channel map for output channel %d: %d\n", i, idx);
401 for (j = 0; j < i; j++)
402 if (channel_map[channel_reorder(channels, j)] == idx) {
408 if (idx < 2 * stereo_streams) {
int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, int self_delimiting)
Parse Opus packet info from raw packet data.
static int channel_reorder_vorbis(int nb_channels, int channel_idx)
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int frame_count
frame count
static int channel_reorder_unknown(int nb_channels, int channel_idx)
#define AV_CH_LAYOUT_STEREO
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
const int * channel_map
channel index (or -1 if muted channel) map
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static av_cold int end(AVCodecContext *avctx)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
ChannelMap * channel_maps
static const uint8_t opus_default_extradata[30]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint64_t channel_layout
Audio channel layout.
int frame_size[MAX_FRAMES]
frame sizes
int frame_duration
frame duration, in samples @ 48kHz
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int xiph_lacing_16bit(const uint8_t **ptr, const uint8_t *end)
Read a 1- or 2-byte frame length.
static int xiph_lacing_full(const uint8_t **ptr, const uint8_t *end)
Read a multi-byte length (used for code 3 packet padding size)
main external API structure.
const uint64_t ff_vorbis_channel_layouts[9]
int config
configuration: tells the audio mode, bandwidth, and frame duration
int stereo
whether this packet is mono or stereo
int data_size
size of the useful data – packet size - padding
static const uint16_t opus_frame_duration[32]
int packet_size
packet size
int channels
number of audio channels
int frame_offset[MAX_FRAMES]
frame offsets
enum OpusBandwidth bandwidth
bandwidth
static void * av_mallocz_array(size_t nmemb, size_t size)
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, OpusContext *s)
const uint8_t ff_vorbis_channel_layout_offsets[8][8]
int code
packet code: specifies the frame layout
#define AV_CH_LAYOUT_MONO