70 if (*ptr >= end ||
val > INT_MAX - 254)
88 const uint8_t *ptr = buf;
89 const uint8_t *end = buf + buf_size;
98 pkt->code = (
i ) & 0x3;
99 pkt->stereo = (
i >> 2) & 0x1;
100 pkt->config = (
i >> 3) & 0x1F;
103 if (
pkt->code >= 2 && buf_size < 2)
109 pkt->frame_count = 1;
112 if (self_delimiting) {
117 buf_size = end - buf;
120 frame_bytes = end - ptr;
123 pkt->frame_offset[0] = ptr - buf;
124 pkt->frame_size[0] = frame_bytes;
128 pkt->frame_count = 2;
131 if (self_delimiting) {
136 buf_size = end - buf;
139 frame_bytes = end - ptr;
142 pkt->frame_offset[0] = ptr - buf;
143 pkt->frame_size[0] = frame_bytes >> 1;
144 pkt->frame_offset[1] =
pkt->frame_offset[0] +
pkt->frame_size[0];
145 pkt->frame_size[1] = frame_bytes >> 1;
149 pkt->frame_count = 2;
157 if (self_delimiting) {
161 end = ptr + frame_bytes +
len;
162 buf_size = end - buf;
165 pkt->frame_offset[0] = ptr - buf;
166 pkt->frame_size[0] = frame_bytes;
169 frame_bytes = end - ptr -
pkt->frame_size[0];
172 pkt->frame_offset[1] =
pkt->frame_offset[0] +
pkt->frame_size[0];
173 pkt->frame_size[1] = frame_bytes;
178 pkt->frame_count = (
i ) & 0x3F;
179 padding = (
i >> 6) & 0x01;
180 pkt->vbr = (
i >> 7) & 0x01;
197 for (
i = 0;
i <
pkt->frame_count - 1;
i++) {
201 pkt->frame_size[
i] = frame_bytes;
202 total_bytes += frame_bytes;
205 if (self_delimiting) {
209 end = ptr + total_bytes +
len + padding;
210 buf_size = end - buf;
213 frame_bytes = end - ptr - padding;
214 if (total_bytes > frame_bytes)
216 pkt->frame_offset[0] = ptr - buf;
217 for (
i = 1;
i <
pkt->frame_count;
i++)
218 pkt->frame_offset[
i] =
pkt->frame_offset[
i-1] +
pkt->frame_size[
i-1];
219 pkt->frame_size[
pkt->frame_count-1] = frame_bytes - total_bytes;
223 if (self_delimiting) {
225 if (frame_bytes < 0 || pkt->frame_count * frame_bytes + padding > end - ptr)
227 end = ptr +
pkt->frame_count * frame_bytes + padding;
228 buf_size = end - buf;
230 frame_bytes = end - ptr - padding;
231 if (frame_bytes %
pkt->frame_count ||
234 frame_bytes /=
pkt->frame_count;
237 pkt->frame_offset[0] = ptr - buf;
238 pkt->frame_size[0] = frame_bytes;
239 for (
i = 1;
i <
pkt->frame_count;
i++) {
240 pkt->frame_offset[
i] =
pkt->frame_offset[
i-1] +
pkt->frame_size[
i-1];
241 pkt->frame_size[
i] = frame_bytes;
246 pkt->packet_size = buf_size;
247 pkt->data_size =
pkt->packet_size - padding;
255 if (
pkt->config < 12) {
257 pkt->bandwidth =
pkt->config >> 2;
258 }
else if (
pkt->config < 16) {
263 pkt->bandwidth = (
pkt->config - 16) >> 2;
272 memset(
pkt, 0,
sizeof(*
pkt));
289 static const uint8_t default_channel_map[2] = { 0, 1 };
296 int version, map_type, streams, stereo_streams,
i, j, ret;
302 "Multichannel configuration without extradata.\n");
312 if (extradata_size < 19) {
332 s->gain_i =
AV_RL16(extradata + 16);
334 map_type = extradata[18];
338 "Channel mapping 0 is only specified for up to 2 channels\n");
347 }
else if (map_type == 1 || map_type == 2 || map_type == 255) {
348 if (extradata_size < 21 +
channels) {
355 streams = extradata[19];
356 stereo_streams = extradata[20];
357 if (!streams || stereo_streams > streams ||
358 streams + stereo_streams > 255) {
360 "Invalid stream/stereo stream count: %d/%d\n", streams, stereo_streams);
368 "Channel mapping 1 is only specified for up to 8 channels\n");
374 }
else if (map_type == 2) {
376 if (
channels != ((ambisonic_order + 1) * (ambisonic_order + 1)) &&
377 channels != ((ambisonic_order + 1) * (ambisonic_order + 1) + 2)) {
379 "Channel mapping 2 is only specified for channel counts"
380 " which can be written as (n + 1)^2 or (n + 1)^2 + 2"
381 " for nonnegative integer n\n");
393 if (
channels != ((ambisonic_order + 1) * (ambisonic_order + 1)))
407 if (!
s->channel_maps) {
419 }
else if (idx >= streams + stereo_streams) {
421 "Invalid channel map for output channel %d: %d\n",
i, idx);
429 for (j = 0; j <
i; j++)
436 if (idx < 2 * stereo_streams) {
437 map->stream_idx = idx / 2;
438 map->channel_idx = idx & 1;
440 map->stream_idx = idx - stereo_streams;
441 map->channel_idx = 0;
449 s->nb_streams = streams;
450 s->nb_stereo_streams = stereo_streams;
static double val(void *priv, double ch)
static const uint8_t channel_map[8][8]
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
const uint16_t ff_opus_frame_duration[32]
#define AV_CH_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_MONO
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
@ AV_CHANNEL_ORDER_AMBISONIC
The audio is represented as the decomposition of the sound field into spherical harmonics.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const VDPAUPixFmtMap * map
common internal api header.
Macro definitions for various function/variable attributes.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
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 xiph_lacing_full(const uint8_t **ptr, const uint8_t *end)
Read a multi-byte length (used for code 3 packet padding size)
av_cold int ff_opus_parse_extradata(AVCodecContext *avctx, OpusParseContext *s)
static int channel_reorder_unknown(int nb_channels, int channel_idx)
static int channel_reorder_vorbis(int nb_channels, int channel_idx)
static int xiph_lacing_16bit(const uint8_t **ptr, const uint8_t *end)
Read a 1- or 2-byte frame length.
@ OPUS_BANDWIDTH_SUPERWIDEBAND
static const uint8_t opus_default_extradata[30]
#define OPUS_MAX_PACKET_DUR
#define OPUS_MAX_FRAME_SIZE
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
#define avpriv_request_sample(...)
const AVChannelLayout ff_vorbis_ch_layouts[9]
const uint8_t ff_vorbis_channel_layout_offsets[8][8]