FFmpeg
Loading...
Searching...
No Matches
audiotoolboxdec.c
Go to the documentation of this file.
1/*
2 * Audio Toolbox system codecs
3 *
4 * copyright (c) 2016 rcombs
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <AudioToolbox/AudioToolbox.h>
24
25#include "config.h"
26#include "config_components.h"
27#include "avcodec.h"
28#include "ac3_parser_internal.h"
29#include "bytestream.h"
30#include "codec_internal.h"
31#include "decode.h"
32#include "mpegaudiodecheader.h"
33#include "libavutil/avassert.h"
35#include "libavutil/mem.h"
36#include "libavutil/opt.h"
37#include "libavutil/log.h"
38
39#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
40#define kAudioFormatEnhancedAC3 'ec-3'
41#endif
42
43typedef struct ATDecodeContext {
45
46 AudioConverterRef converter;
47 AudioStreamPacketDescription pkt_desc;
51 int channel_map[64];
52
53 uint8_t *extradata;
55
57 int eof;
59
60static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile)
61{
62 switch (codec) {
63 case AV_CODEC_ID_AAC:
64 return kAudioFormatMPEG4AAC;
65 case AV_CODEC_ID_AC3:
66 return kAudioFormatAC3;
68 return kAudioFormatAppleIMA4;
70 return kAudioFormatAppleLossless;
72 return kAudioFormatAMR;
75#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
77 return kAudioFormatMicrosoftGSM;
79 return kAudioFormatiLBC;
80#endif
81 case AV_CODEC_ID_MP1:
82 return kAudioFormatMPEGLayer1;
83 case AV_CODEC_ID_MP2:
84 return kAudioFormatMPEGLayer2;
85 case AV_CODEC_ID_MP3:
86 return kAudioFormatMPEGLayer3;
88 return kAudioFormatALaw;
90 return kAudioFormatULaw;
92 return kAudioFormatQDesign;
94 return kAudioFormatQDesign2;
95 default:
96 av_assert0(!"Invalid codec ID!");
97 return 0;
98 }
99}
100
101static int ffat_get_channel_id(AudioChannelLabel label)
102{
103 if (label == 0)
104 return -1;
105 else if (label <= kAudioChannelLabel_LFEScreen)
106 return label - 1;
107 else if (label <= kAudioChannelLabel_RightSurround)
108 return label + 4;
109 else if (label <= kAudioChannelLabel_CenterSurround)
110 return label + 1;
111 else if (label <= kAudioChannelLabel_RightSurroundDirect)
112 return label + 23;
113 else if (label <= kAudioChannelLabel_TopBackRight)
114 return label - 1;
115 else if (label < kAudioChannelLabel_RearSurroundLeft)
116 return -1;
117 else if (label <= kAudioChannelLabel_RearSurroundRight)
118 return label - 29;
119 else if (label <= kAudioChannelLabel_RightWide)
120 return label - 4;
121 else if (label == kAudioChannelLabel_LFE2)
123 else if (label == kAudioChannelLabel_Mono)
125 else
126 return -1;
127}
128
129static int ffat_compare_channel_descriptions(const void* a, const void* b)
130{
131 const AudioChannelDescription* da = a;
132 const AudioChannelDescription* db = b;
133 return ffat_get_channel_id(da->mChannelLabel) - ffat_get_channel_id(db->mChannelLabel);
134}
135
136static AudioChannelLayout *ffat_convert_layout(AudioChannelLayout *layout, UInt32* size)
137{
138 AudioChannelLayoutTag tag = layout->mChannelLayoutTag;
139 AudioChannelLayout *new_layout;
140 if (tag == kAudioChannelLayoutTag_UseChannelDescriptions)
141 return layout;
142 else if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
143 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
144 sizeof(UInt32), &layout->mChannelBitmap, size);
145 else
146 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
147 sizeof(AudioChannelLayoutTag), &tag, size);
148 new_layout = av_malloc(*size);
149 if (!new_layout) {
151 return NULL;
152 }
153 if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
154 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
155 sizeof(UInt32), &layout->mChannelBitmap, size, new_layout);
156 else
157 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
158 sizeof(AudioChannelLayoutTag), &tag, size, new_layout);
159 new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
161 return new_layout;
162}
163
165{
166 ATDecodeContext *at = avctx->priv_data;
167 AudioStreamBasicDescription format;
168 UInt32 size = sizeof(format);
169 if (!AudioConverterGetProperty(at->converter,
170 kAudioConverterCurrentInputStreamDescription,
171 &size, &format)) {
172 if (format.mSampleRate)
173 avctx->sample_rate = format.mSampleRate;
175 av_channel_layout_default(&avctx->ch_layout, format.mChannelsPerFrame);
176 avctx->frame_size = format.mFramesPerPacket;
177 }
178
179 if (!AudioConverterGetProperty(at->converter,
180 kAudioConverterCurrentOutputStreamDescription,
181 &size, &format)) {
182 format.mSampleRate = avctx->sample_rate;
183 format.mChannelsPerFrame = avctx->ch_layout.nb_channels;
184 AudioConverterSetProperty(at->converter,
185 kAudioConverterCurrentOutputStreamDescription,
186 size, &format);
187 }
188
189 if (!AudioConverterGetPropertyInfo(at->converter, kAudioConverterOutputChannelLayout,
190 &size, NULL) && size) {
191 AudioChannelLayout *layout = av_malloc(size);
192 uint64_t layout_mask = 0;
193 int i;
194 if (!layout)
195 return AVERROR(ENOMEM);
196 AudioConverterGetProperty(at->converter, kAudioConverterOutputChannelLayout,
197 &size, layout);
199 return AVERROR(ENOMEM);
200 for (i = 0; i < layout->mNumberChannelDescriptions; i++) {
201 int id = ffat_get_channel_id(layout->mChannelDescriptions[i].mChannelLabel);
202 if (id < 0)
203 goto done;
204 if (layout_mask & (1ULL << id))
205 goto done;
206 layout_mask |= 1ULL << id;
207 layout->mChannelDescriptions[i].mChannelFlags = i; // Abusing flags as index
208 }
210 av_channel_layout_from_mask(&avctx->ch_layout, layout_mask);
211 qsort(layout->mChannelDescriptions, layout->mNumberChannelDescriptions,
212 sizeof(AudioChannelDescription), &ffat_compare_channel_descriptions);
213 for (i = 0; i < layout->mNumberChannelDescriptions; i++)
214 at->channel_map[i] = layout->mChannelDescriptions[i].mChannelFlags;
215done:
217 }
218
219 if (!avctx->frame_size)
220 avctx->frame_size = 2048;
221
222 return 0;
223}
224
225static void put_descr(PutByteContext *pb, int tag, unsigned int size)
226{
227 int i = 3;
228 bytestream2_put_byte(pb, tag);
229 for (; i > 0; i--)
230 bytestream2_put_byte(pb, (size >> (7 * i)) | 0x80);
231 bytestream2_put_byte(pb, size & 0x7F);
232}
233
234static uint8_t* ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
235{
236 ATDecodeContext *at = avctx->priv_data;
237 if (avctx->codec_id == AV_CODEC_ID_AAC) {
238 char *extradata;
240 *cookie_size = 5 + 3 + 5+13 + 5+at->extradata_size;
241 if (!(extradata = av_malloc(*cookie_size)))
242 return NULL;
243
244 bytestream2_init_writer(&pb, extradata, *cookie_size);
245
246 // ES descriptor
247 put_descr(&pb, 0x03, 3 + 5+13 + 5+at->extradata_size);
248 bytestream2_put_be16(&pb, 0);
249 bytestream2_put_byte(&pb, 0x00); // flags (= no flags)
250
251 // DecoderConfig descriptor
252 put_descr(&pb, 0x04, 13 + 5+at->extradata_size);
253
254 // Object type indication
255 bytestream2_put_byte(&pb, 0x40);
256
257 bytestream2_put_byte(&pb, 0x15); // flags (= Audiostream)
258
259 bytestream2_put_be24(&pb, 0); // Buffersize DB
260
261 bytestream2_put_be32(&pb, 0); // maxbitrate
262 bytestream2_put_be32(&pb, 0); // avgbitrate
263
264 // DecoderSpecific info descriptor
265 put_descr(&pb, 0x05, at->extradata_size);
267 return extradata;
268 } else {
269 *cookie_size = at->extradata_size;
270 return at->extradata;
271 }
272}
273
275{
276 ATDecodeContext *at = avctx->priv_data;
277 return at->extradata_size &&
278 (avctx->codec_id == AV_CODEC_ID_ALAC ||
279 avctx->codec_id == AV_CODEC_ID_QDM2 ||
280 avctx->codec_id == AV_CODEC_ID_QDMC ||
281 avctx->codec_id == AV_CODEC_ID_AAC);
282}
283
285{
286 ATDecodeContext *at = avctx->priv_data;
287 if (ffat_usable_extradata(avctx)) {
288 OSStatus status;
289 UInt32 cookie_size;
290 uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
291 if (!cookie)
292 return AVERROR(ENOMEM);
293
294 status = AudioConverterSetProperty(at->converter,
295 kAudioConverterDecompressionMagicCookie,
296 cookie_size, cookie);
297 if (status != 0)
298 av_log(avctx, AV_LOG_WARNING, "AudioToolbox cookie error: %i\n", (int)status);
299
300 if (cookie != at->extradata)
301 av_free(cookie);
302 }
303 return 0;
304}
305
307 const AVPacket *pkt)
308{
309 ATDecodeContext *at = avctx->priv_data;
310 OSStatus status;
311 int i;
312
313 enum AVSampleFormat sample_fmt = (avctx->bits_per_raw_sample == 32) ?
315
316 AudioStreamBasicDescription in_format = {
317 .mFormatID = ffat_get_format_id(avctx->codec_id, avctx->profile),
318 .mBytesPerPacket = (avctx->codec_id == AV_CODEC_ID_ILBC) ? avctx->block_align : 0,
319 };
320 AudioStreamBasicDescription out_format = {
321 .mFormatID = kAudioFormatLinearPCM,
322 .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
323 .mFramesPerPacket = 1,
324 .mBitsPerChannel = av_get_bytes_per_sample(sample_fmt) * 8,
325 };
326
327 avctx->sample_fmt = sample_fmt;
328
329 if (ffat_usable_extradata(avctx)) {
330 UInt32 format_size = sizeof(in_format);
331 UInt32 cookie_size;
332 uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
333 if (!cookie)
334 return AVERROR(ENOMEM);
335 status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
336 cookie_size, cookie, &format_size, &in_format);
337 if (cookie != at->extradata)
338 av_free(cookie);
339 if (status != 0) {
340 av_log(avctx, AV_LOG_ERROR, "AudioToolbox header-parse error: %i\n", (int)status);
341 return AVERROR_UNKNOWN;
342 }
343#if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
344 } else if (pkt && pkt->size >= 4 &&
345 (avctx->codec_id == AV_CODEC_ID_MP1 ||
346 avctx->codec_id == AV_CODEC_ID_MP2 ||
347 avctx->codec_id == AV_CODEC_ID_MP3)) {
348 enum AVCodecID codec_id;
349 int bit_rate;
350 if (ff_mpa_decode_header(AV_RB32(pkt->data), &avctx->sample_rate,
351 &in_format.mChannelsPerFrame, &avctx->frame_size,
352 &bit_rate, &codec_id) < 0)
353 return AVERROR_INVALIDDATA;
354 avctx->bit_rate = bit_rate;
355 in_format.mSampleRate = avctx->sample_rate;
356#endif
357#if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
358 } else if (pkt && pkt->size >= 7 &&
359 (avctx->codec_id == AV_CODEC_ID_AC3 ||
360 avctx->codec_id == AV_CODEC_ID_EAC3)) {
361 AC3HeaderInfo hdr;
362 GetBitContext gbc;
363 init_get_bits8(&gbc, pkt->data, pkt->size);
364 if (ff_ac3_parse_header(&gbc, &hdr) < 0)
365 return AVERROR_INVALIDDATA;
366 in_format.mSampleRate = hdr.sample_rate;
367 in_format.mChannelsPerFrame = hdr.channels;
368 avctx->frame_size = hdr.num_blocks * 256;
369 avctx->bit_rate = hdr.bit_rate;
370#endif
371 } else {
372 in_format.mSampleRate = avctx->sample_rate ? avctx->sample_rate : 44100;
373 in_format.mChannelsPerFrame = avctx->ch_layout.nb_channels ? avctx->ch_layout.nb_channels : 1;
374 }
375
376 avctx->sample_rate = out_format.mSampleRate = in_format.mSampleRate;
379 avctx->ch_layout.nb_channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
380
381 out_format.mBytesPerFrame =
382 out_format.mChannelsPerFrame * (out_format.mBitsPerChannel / 8);
383 out_format.mBytesPerPacket =
384 out_format.mBytesPerFrame * out_format.mFramesPerPacket;
385
387 in_format.mFramesPerPacket = 64;
388
389 status = AudioConverterNew(&in_format, &out_format, &at->converter);
390
391 if (status != 0) {
392 av_log(avctx, AV_LOG_ERROR, "AudioToolbox init error: %i\n", (int)status);
393 return AVERROR_UNKNOWN;
394 }
395
396 if ((status = ffat_set_extradata(avctx)) < 0)
397 return status;
398
399 for (i = 0; i < (sizeof(at->channel_map) / sizeof(at->channel_map[0])); i++)
400 at->channel_map[i] = i;
401
402 ffat_update_ctx(avctx);
403
405 * avctx->frame_size * avctx->ch_layout.nb_channels)))
406 return AVERROR(ENOMEM);
407
409
410 return 0;
411}
412
414{
415 ATDecodeContext *at = avctx->priv_data;
416 if (avctx->extradata_size) {
418 if (!at->extradata)
419 return AVERROR(ENOMEM);
420 at->extradata_size = avctx->extradata_size;
421 memcpy(at->extradata, avctx->extradata, avctx->extradata_size);
422 }
423
424 if ((avctx->ch_layout.nb_channels && avctx->sample_rate) || ffat_usable_extradata(avctx))
425 return ffat_create_decoder(avctx, NULL);
426 else
427 return 0;
428}
429
430static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets,
431 AudioBufferList *data,
432 AudioStreamPacketDescription **packets,
433 void *inctx)
434{
435 AVCodecContext *avctx = inctx;
436 ATDecodeContext *at = avctx->priv_data;
437
438 if (at->eof) {
439 *nb_packets = 0;
440 if (packets) {
441 *packets = &at->pkt_desc;
442 at->pkt_desc.mDataByteSize = 0;
443 }
444 return 0;
445 }
446
449
450 if (!at->in_pkt.data) {
451 *nb_packets = 0;
452 return 1;
453 }
454
455 data->mNumberBuffers = 1;
456 data->mBuffers[0].mNumberChannels = 0;
457 data->mBuffers[0].mDataByteSize = at->in_pkt.size;
458 data->mBuffers[0].mData = at->in_pkt.data;
459 *nb_packets = 1;
460
461 if (packets) {
462 *packets = &at->pkt_desc;
463 at->pkt_desc.mDataByteSize = at->in_pkt.size;
464 }
465
466 return 0;
467}
468
469#define COPY_SAMPLES(type) \
470 type *in_ptr = (type*)at->decoded_data; \
471 type *end_ptr = in_ptr + frame->nb_samples * avctx->ch_layout.nb_channels; \
472 type *out_ptr = (type*)frame->data[0]; \
473 for (; in_ptr < end_ptr; in_ptr += avctx->ch_layout.nb_channels, out_ptr += avctx->ch_layout.nb_channels) { \
474 int c; \
475 for (c = 0; c < avctx->ch_layout.nb_channels; c++) \
476 out_ptr[c] = in_ptr[at->channel_map[c]]; \
477 }
478
480{
481 ATDecodeContext *at = avctx->priv_data;
482 if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) {
484 } else {
485 COPY_SAMPLES(int16_t);
486 }
487}
488
490 int *got_frame_ptr, AVPacket *avpkt)
491{
492 ATDecodeContext *at = avctx->priv_data;
493 int pkt_size = avpkt->size;
494 OSStatus ret;
495 AudioBufferList out_buffers;
496
497 if (avctx->codec_id == AV_CODEC_ID_AAC) {
498 if (!at->extradata_size) {
499 uint8_t *side_data;
500 size_t side_data_size;
501
503 &side_data_size);
504 if (side_data_size) {
505 at->extradata = av_mallocz(side_data_size + AV_INPUT_BUFFER_PADDING_SIZE);
506 if (!at->extradata)
507 return AVERROR(ENOMEM);
508 at->extradata_size = side_data_size;
509 memcpy(at->extradata, side_data, side_data_size);
510 }
511 }
512 }
513
514 if (!at->converter) {
515 if ((ret = ffat_create_decoder(avctx, avpkt)) < 0) {
516 return ret;
517 }
518 }
519
520 out_buffers = (AudioBufferList){
521 .mNumberBuffers = 1,
522 .mBuffers = {
523 {
524 .mNumberChannels = avctx->ch_layout.nb_channels,
525 .mDataByteSize = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->frame_size
526 * avctx->ch_layout.nb_channels,
527 }
528 }
529 };
530
532
533 if (avpkt->size) {
534 if ((ret = av_packet_ref(&at->new_in_pkt, avpkt)) < 0) {
535 return ret;
536 }
537 } else {
538 at->eof = 1;
539 }
540
541 frame->sample_rate = avctx->sample_rate;
542
543 frame->nb_samples = avctx->frame_size;
544
545 frame->flags |= AV_FRAME_FLAG_KEY;
546
547 out_buffers.mBuffers[0].mData = at->decoded_data;
548
549 ret = AudioConverterFillComplexBuffer(at->converter, ffat_decode_callback, avctx,
550 &frame->nb_samples, &out_buffers, NULL);
551 if ((!ret || ret == 1) && frame->nb_samples) {
552 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
553 return ret;
554 ffat_copy_samples(avctx, frame);
555 *got_frame_ptr = 1;
556 if (at->last_pts != AV_NOPTS_VALUE) {
557 frame->pts = at->last_pts;
558 at->last_pts = avpkt->pts;
559 }
560 } else if (ret && ret != 1) {
561 av_log(avctx, AV_LOG_WARNING, "Decode error: %i\n", ret);
562 } else {
563 at->last_pts = avpkt->pts;
564 }
565
566 return pkt_size;
567}
568
570{
571 ATDecodeContext *at = avctx->priv_data;
572 AudioConverterReset(at->converter);
575}
576
578{
579 ATDecodeContext *at = avctx->priv_data;
580 if (at->converter)
581 AudioConverterDispose(at->converter);
585 av_freep(&at->extradata);
586 return 0;
587}
588
589#define FFAT_DEC_CLASS(NAME) \
590 static const AVClass ffat_##NAME##_dec_class = { \
591 .class_name = "at_" #NAME "_dec", \
592 .version = LIBAVUTIL_VERSION_INT, \
593 };
594
595#define FFAT_DEC(NAME, ID, bsf_name) \
596 FFAT_DEC_CLASS(NAME) \
597 const FFCodec ff_##NAME##_at_decoder = { \
598 .p.name = #NAME "_at", \
599 CODEC_LONG_NAME(#NAME " (AudioToolbox)"), \
600 .p.type = AVMEDIA_TYPE_AUDIO, \
601 .p.id = ID, \
602 .priv_data_size = sizeof(ATDecodeContext), \
603 .init = ffat_init_decoder, \
604 .close = ffat_close_decoder, \
605 FF_CODEC_DECODE_CB(ffat_decode), \
606 .flush = ffat_decode_flush, \
607 .p.priv_class = &ffat_##NAME##_dec_class, \
608 .bsfs = bsf_name, \
609 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_CHANNEL_CONF, \
610 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
611 .p.wrapper_name = "at", \
612 };
613
614FFAT_DEC(aac, AV_CODEC_ID_AAC, "aac_adtstoasc")
int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
Parse AC-3 frame header.
static const char *const format[]
Definition af_aiir.c:444
int32_t
static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets, AudioBufferList *data, AudioStreamPacketDescription **packets, void *inctx)
static AudioChannelLayout * ffat_convert_layout(AudioChannelLayout *layout, UInt32 *size)
#define COPY_SAMPLES(type)
static av_cold int ffat_usable_extradata(AVCodecContext *avctx)
static av_cold int ffat_create_decoder(AVCodecContext *avctx, const AVPacket *pkt)
static int ffat_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static av_cold void ffat_decode_flush(AVCodecContext *avctx)
static av_cold int ffat_close_decoder(AVCodecContext *avctx)
static int ffat_update_ctx(AVCodecContext *avctx)
static int ffat_set_extradata(AVCodecContext *avctx)
static int ffat_get_channel_id(AudioChannelLabel label)
static void ffat_copy_samples(AVCodecContext *avctx, AVFrame *frame)
#define kAudioFormatEnhancedAC3
static uint8_t * ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
static int ffat_compare_channel_descriptions(const void *a, const void *b)
static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile)
static av_cold int ffat_init_decoder(AVCodecContext *avctx)
#define FFAT_DEC(NAME, ID, bsf_name)
static void put_descr(PutByteContext *pb, int tag, unsigned int size)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Libavcodec external API header.
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition bytestream.h:147
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition bytestream.h:286
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
Public libavutil channel layout APIs header.
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1777
static AVPacket * pkt
static AVFrame * frame
enum AVCodecID id
Definition dts2pts.c:607
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
#define AV_CH_LOW_FREQUENCY_2
#define AV_CH_FRONT_CENTER
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_EAC3
Definition codec_id.h:493
@ AV_CODEC_ID_MP1
Definition codec_id.h:495
@ AV_CODEC_ID_GSM_MS
Definition codec_id.h:483
@ AV_CODEC_ID_PCM_ALAW
Definition codec_id.h:337
@ AV_CODEC_ID_ALAC
Definition codec_id.h:469
@ AV_CODEC_ID_AMR_NB
Definition codec_id.h:434
@ AV_CODEC_ID_MP2
Definition codec_id.h:453
@ AV_CODEC_ID_ADPCM_IMA_QT
Definition codec_id.h:370
@ AV_CODEC_ID_AAC
Definition codec_id.h:455
@ AV_CODEC_ID_AC3
Definition codec_id.h:456
@ AV_CODEC_ID_QDM2
Definition codec_id.h:472
@ AV_CODEC_ID_ILBC
Definition codec_id.h:512
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition codec_id.h:454
@ AV_CODEC_ID_QDMC
Definition codec_id.h:503
@ AV_CODEC_ID_PCM_MULAW
Definition codec_id.h:336
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition packet.h:56
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition packet.c:491
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition packet.c:252
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition packet.c:442
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
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_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition error.h:73
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition frame.h:687
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define ff_ctzll
Definition intmath.h:125
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition samplefmt.c:108
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition samplefmt.h:59
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition samplefmt.h:58
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
int a
#define b
Definition input.c:43
#define AV_RB32(p)
#define av_cold
Definition attributes.h:117
uint64_t layout
Memory handling functions.
uint32_t tag
Definition movenc.c:2087
int ff_mpa_decode_header(uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate, enum AVCodecID *codec_id)
MPEG Audio header decoder.
const char data[16]
Definition mxf.c:149
int profile
Definition mxfenc.c:2299
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
Coded AC-3 header values up to the lfeon element, plus derived values.
int num_blocks
number of audio blocks
AudioConverterRef converter
AudioStreamPacketDescription pkt_desc
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1055
enum AVSampleFormat sample_fmt
audio sample format
Definition avcodec.h:1047
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
int profile
profile
Definition avcodec.h:1636
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1571
int sample_rate
samples per second
Definition avcodec.h:1040
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
enum AVCodecID codec_id
Definition avcodec.h:453
int extradata_size
Definition avcodec.h:527
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition avcodec.h:1075
int frame_size
Number of samples per channel in an audio frame.
Definition avcodec.h:1068
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition packet.h:596
uint8_t * data
Definition packet.h:603
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
int size
enum AVCodecID codec_id