FFmpeg
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 "avcodec.h"
27 #include "ac3_parser_internal.h"
28 #include "bytestream.h"
29 #include "internal.h"
30 #include "mpegaudiodecheader.h"
31 #include "libavutil/avassert.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/log.h"
35 
36 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
37 #define kAudioFormatEnhancedAC3 'ec-3'
38 #endif
39 
40 typedef struct ATDecodeContext {
42 
43  AudioConverterRef converter;
44  AudioStreamPacketDescription pkt_desc;
47  char *decoded_data;
48  int channel_map[64];
49 
50  uint8_t *extradata;
52 
53  int64_t last_pts;
54  int eof;
56 
57 static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile)
58 {
59  switch (codec) {
60  case AV_CODEC_ID_AAC:
61  return kAudioFormatMPEG4AAC;
62  case AV_CODEC_ID_AC3:
63  return kAudioFormatAC3;
65  return kAudioFormatAppleIMA4;
66  case AV_CODEC_ID_ALAC:
67  return kAudioFormatAppleLossless;
68  case AV_CODEC_ID_AMR_NB:
69  return kAudioFormatAMR;
70  case AV_CODEC_ID_EAC3:
72  case AV_CODEC_ID_GSM_MS:
73  return kAudioFormatMicrosoftGSM;
74  case AV_CODEC_ID_ILBC:
75  return kAudioFormatiLBC;
76  case AV_CODEC_ID_MP1:
77  return kAudioFormatMPEGLayer1;
78  case AV_CODEC_ID_MP2:
79  return kAudioFormatMPEGLayer2;
80  case AV_CODEC_ID_MP3:
81  return kAudioFormatMPEGLayer3;
83  return kAudioFormatALaw;
85  return kAudioFormatULaw;
86  case AV_CODEC_ID_QDMC:
87  return kAudioFormatQDesign;
88  case AV_CODEC_ID_QDM2:
89  return kAudioFormatQDesign2;
90  default:
91  av_assert0(!"Invalid codec ID!");
92  return 0;
93  }
94 }
95 
96 static int ffat_get_channel_id(AudioChannelLabel label)
97 {
98  if (label == 0)
99  return -1;
100  else if (label <= kAudioChannelLabel_LFEScreen)
101  return label - 1;
102  else if (label <= kAudioChannelLabel_RightSurround)
103  return label + 4;
104  else if (label <= kAudioChannelLabel_CenterSurround)
105  return label + 1;
106  else if (label <= kAudioChannelLabel_RightSurroundDirect)
107  return label + 23;
108  else if (label <= kAudioChannelLabel_TopBackRight)
109  return label - 1;
110  else if (label < kAudioChannelLabel_RearSurroundLeft)
111  return -1;
112  else if (label <= kAudioChannelLabel_RearSurroundRight)
113  return label - 29;
114  else if (label <= kAudioChannelLabel_RightWide)
115  return label - 4;
116  else if (label == kAudioChannelLabel_LFE2)
118  else if (label == kAudioChannelLabel_Mono)
120  else
121  return -1;
122 }
123 
124 static int ffat_compare_channel_descriptions(const void* a, const void* b)
125 {
126  const AudioChannelDescription* da = a;
127  const AudioChannelDescription* db = b;
128  return ffat_get_channel_id(da->mChannelLabel) - ffat_get_channel_id(db->mChannelLabel);
129 }
130 
131 static AudioChannelLayout *ffat_convert_layout(AudioChannelLayout *layout, UInt32* size)
132 {
133  AudioChannelLayoutTag tag = layout->mChannelLayoutTag;
134  AudioChannelLayout *new_layout;
135  if (tag == kAudioChannelLayoutTag_UseChannelDescriptions)
136  return layout;
137  else if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
138  AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
139  sizeof(UInt32), &layout->mChannelBitmap, size);
140  else
141  AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
142  sizeof(AudioChannelLayoutTag), &tag, size);
143  new_layout = av_malloc(*size);
144  if (!new_layout) {
145  av_free(layout);
146  return NULL;
147  }
148  if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
149  AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
150  sizeof(UInt32), &layout->mChannelBitmap, size, new_layout);
151  else
152  AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
153  sizeof(AudioChannelLayoutTag), &tag, size, new_layout);
154  new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
155  av_free(layout);
156  return new_layout;
157 }
158 
159 static int ffat_update_ctx(AVCodecContext *avctx)
160 {
161  ATDecodeContext *at = avctx->priv_data;
162  AudioStreamBasicDescription format;
163  UInt32 size = sizeof(format);
164  if (!AudioConverterGetProperty(at->converter,
165  kAudioConverterCurrentInputStreamDescription,
166  &size, &format)) {
167  if (format.mSampleRate)
168  avctx->sample_rate = format.mSampleRate;
169  avctx->channels = format.mChannelsPerFrame;
171  avctx->frame_size = format.mFramesPerPacket;
172  }
173 
174  if (!AudioConverterGetProperty(at->converter,
175  kAudioConverterCurrentOutputStreamDescription,
176  &size, &format)) {
177  format.mSampleRate = avctx->sample_rate;
178  format.mChannelsPerFrame = avctx->channels;
179  AudioConverterSetProperty(at->converter,
180  kAudioConverterCurrentOutputStreamDescription,
181  size, &format);
182  }
183 
184  if (!AudioConverterGetPropertyInfo(at->converter, kAudioConverterOutputChannelLayout,
185  &size, NULL) && size) {
186  AudioChannelLayout *layout = av_malloc(size);
187  uint64_t layout_mask = 0;
188  int i;
189  if (!layout)
190  return AVERROR(ENOMEM);
191  AudioConverterGetProperty(at->converter, kAudioConverterOutputChannelLayout,
192  &size, layout);
194  return AVERROR(ENOMEM);
195  for (i = 0; i < layout->mNumberChannelDescriptions; i++) {
196  int id = ffat_get_channel_id(layout->mChannelDescriptions[i].mChannelLabel);
197  if (id < 0)
198  goto done;
199  if (layout_mask & (1 << id))
200  goto done;
201  layout_mask |= 1 << id;
202  layout->mChannelDescriptions[i].mChannelFlags = i; // Abusing flags as index
203  }
204  avctx->channel_layout = layout_mask;
205  qsort(layout->mChannelDescriptions, layout->mNumberChannelDescriptions,
206  sizeof(AudioChannelDescription), &ffat_compare_channel_descriptions);
207  for (i = 0; i < layout->mNumberChannelDescriptions; i++)
208  at->channel_map[i] = layout->mChannelDescriptions[i].mChannelFlags;
209 done:
210  av_free(layout);
211  }
212 
213  if (!avctx->frame_size)
214  avctx->frame_size = 2048;
215 
216  return 0;
217 }
218 
219 static void put_descr(PutByteContext *pb, int tag, unsigned int size)
220 {
221  int i = 3;
222  bytestream2_put_byte(pb, tag);
223  for (; i > 0; i--)
224  bytestream2_put_byte(pb, (size >> (7 * i)) | 0x80);
225  bytestream2_put_byte(pb, size & 0x7F);
226 }
227 
228 static uint8_t* ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
229 {
230  ATDecodeContext *at = avctx->priv_data;
231  if (avctx->codec_id == AV_CODEC_ID_AAC) {
232  char *extradata;
233  PutByteContext pb;
234  *cookie_size = 5 + 3 + 5+13 + 5+at->extradata_size;
235  if (!(extradata = av_malloc(*cookie_size)))
236  return NULL;
237 
238  bytestream2_init_writer(&pb, extradata, *cookie_size);
239 
240  // ES descriptor
241  put_descr(&pb, 0x03, 3 + 5+13 + 5+at->extradata_size);
242  bytestream2_put_be16(&pb, 0);
243  bytestream2_put_byte(&pb, 0x00); // flags (= no flags)
244 
245  // DecoderConfig descriptor
246  put_descr(&pb, 0x04, 13 + 5+at->extradata_size);
247 
248  // Object type indication
249  bytestream2_put_byte(&pb, 0x40);
250 
251  bytestream2_put_byte(&pb, 0x15); // flags (= Audiostream)
252 
253  bytestream2_put_be24(&pb, 0); // Buffersize DB
254 
255  bytestream2_put_be32(&pb, 0); // maxbitrate
256  bytestream2_put_be32(&pb, 0); // avgbitrate
257 
258  // DecoderSpecific info descriptor
259  put_descr(&pb, 0x05, at->extradata_size);
261  return extradata;
262  } else {
263  *cookie_size = at->extradata_size;
264  return at->extradata;
265  }
266 }
267 
269 {
270  ATDecodeContext *at = avctx->priv_data;
271  return at->extradata_size &&
272  (avctx->codec_id == AV_CODEC_ID_ALAC ||
273  avctx->codec_id == AV_CODEC_ID_QDM2 ||
274  avctx->codec_id == AV_CODEC_ID_QDMC ||
275  avctx->codec_id == AV_CODEC_ID_AAC);
276 }
277 
279 {
280  ATDecodeContext *at = avctx->priv_data;
281  if (ffat_usable_extradata(avctx)) {
282  OSStatus status;
283  UInt32 cookie_size;
284  uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
285  if (!cookie)
286  return AVERROR(ENOMEM);
287 
288  status = AudioConverterSetProperty(at->converter,
289  kAudioConverterDecompressionMagicCookie,
290  cookie_size, cookie);
291  if (status != 0)
292  av_log(avctx, AV_LOG_WARNING, "AudioToolbox cookie error: %i\n", (int)status);
293 
294  if (cookie != at->extradata)
295  av_free(cookie);
296  }
297  return 0;
298 }
299 
301  const AVPacket *pkt)
302 {
303  ATDecodeContext *at = avctx->priv_data;
304  OSStatus status;
305  int i;
306 
307  enum AVSampleFormat sample_fmt = (avctx->bits_per_raw_sample == 32) ?
309 
310  AudioStreamBasicDescription in_format = {
311  .mFormatID = ffat_get_format_id(avctx->codec_id, avctx->profile),
312  .mBytesPerPacket = (avctx->codec_id == AV_CODEC_ID_ILBC) ? avctx->block_align : 0,
313  };
314  AudioStreamBasicDescription out_format = {
315  .mFormatID = kAudioFormatLinearPCM,
316  .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
317  .mFramesPerPacket = 1,
318  .mBitsPerChannel = av_get_bytes_per_sample(sample_fmt) * 8,
319  };
320 
321  avctx->sample_fmt = sample_fmt;
322 
323  if (ffat_usable_extradata(avctx)) {
324  UInt32 format_size = sizeof(in_format);
325  UInt32 cookie_size;
326  uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
327  if (!cookie)
328  return AVERROR(ENOMEM);
329  status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
330  cookie_size, cookie, &format_size, &in_format);
331  if (cookie != at->extradata)
332  av_free(cookie);
333  if (status != 0) {
334  av_log(avctx, AV_LOG_ERROR, "AudioToolbox header-parse error: %i\n", (int)status);
335  return AVERROR_UNKNOWN;
336  }
337 #if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
338  } else if (pkt && pkt->size >= 4 &&
339  (avctx->codec_id == AV_CODEC_ID_MP1 ||
340  avctx->codec_id == AV_CODEC_ID_MP2 ||
341  avctx->codec_id == AV_CODEC_ID_MP3)) {
342  enum AVCodecID codec_id;
343  int bit_rate;
345  &in_format.mChannelsPerFrame, &avctx->frame_size,
346  &bit_rate, &codec_id) < 0)
347  return AVERROR_INVALIDDATA;
348  avctx->bit_rate = bit_rate;
349  in_format.mSampleRate = avctx->sample_rate;
350 #endif
351 #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
352  } else if (pkt && pkt->size >= 7 &&
353  (avctx->codec_id == AV_CODEC_ID_AC3 ||
354  avctx->codec_id == AV_CODEC_ID_EAC3)) {
355  AC3HeaderInfo hdr;
356  GetBitContext gbc;
357  init_get_bits8(&gbc, pkt->data, pkt->size);
358  if (ff_ac3_parse_header(&gbc, &hdr) < 0)
359  return AVERROR_INVALIDDATA;
360  in_format.mSampleRate = hdr.sample_rate;
361  in_format.mChannelsPerFrame = hdr.channels;
362  avctx->frame_size = hdr.num_blocks * 256;
363  avctx->bit_rate = hdr.bit_rate;
364 #endif
365  } else {
366  in_format.mSampleRate = avctx->sample_rate ? avctx->sample_rate : 44100;
367  in_format.mChannelsPerFrame = avctx->channels ? avctx->channels : 1;
368  }
369 
370  avctx->sample_rate = out_format.mSampleRate = in_format.mSampleRate;
371  avctx->channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
372 
373  if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_QT)
374  in_format.mFramesPerPacket = 64;
375 
376  status = AudioConverterNew(&in_format, &out_format, &at->converter);
377 
378  if (status != 0) {
379  av_log(avctx, AV_LOG_ERROR, "AudioToolbox init error: %i\n", (int)status);
380  return AVERROR_UNKNOWN;
381  }
382 
383  if ((status = ffat_set_extradata(avctx)) < 0)
384  return status;
385 
386  for (i = 0; i < (sizeof(at->channel_map) / sizeof(at->channel_map[0])); i++)
387  at->channel_map[i] = i;
388 
389  ffat_update_ctx(avctx);
390 
392  * avctx->frame_size * avctx->channels)))
393  return AVERROR(ENOMEM);
394 
395  at->last_pts = AV_NOPTS_VALUE;
396 
397  return 0;
398 }
399 
401 {
402  ATDecodeContext *at = avctx->priv_data;
403  if (avctx->extradata_size) {
405  if (!at->extradata)
406  return AVERROR(ENOMEM);
407  at->extradata_size = avctx->extradata_size;
408  memcpy(at->extradata, avctx->extradata, avctx->extradata_size);
409  }
410 
411  if ((avctx->channels && avctx->sample_rate) || ffat_usable_extradata(avctx))
412  return ffat_create_decoder(avctx, NULL);
413  else
414  return 0;
415 }
416 
417 static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets,
418  AudioBufferList *data,
419  AudioStreamPacketDescription **packets,
420  void *inctx)
421 {
422  AVCodecContext *avctx = inctx;
423  ATDecodeContext *at = avctx->priv_data;
424 
425  if (at->eof) {
426  *nb_packets = 0;
427  if (packets) {
428  *packets = &at->pkt_desc;
429  at->pkt_desc.mDataByteSize = 0;
430  }
431  return 0;
432  }
433 
434  av_packet_unref(&at->in_pkt);
436 
437  if (!at->in_pkt.data) {
438  *nb_packets = 0;
439  return 1;
440  }
441 
442  data->mNumberBuffers = 1;
443  data->mBuffers[0].mNumberChannels = 0;
444  data->mBuffers[0].mDataByteSize = at->in_pkt.size;
445  data->mBuffers[0].mData = at->in_pkt.data;
446  *nb_packets = 1;
447 
448  if (packets) {
449  *packets = &at->pkt_desc;
450  at->pkt_desc.mDataByteSize = at->in_pkt.size;
451  }
452 
453  return 0;
454 }
455 
456 #define COPY_SAMPLES(type) \
457  type *in_ptr = (type*)at->decoded_data; \
458  type *end_ptr = in_ptr + frame->nb_samples * avctx->channels; \
459  type *out_ptr = (type*)frame->data[0]; \
460  for (; in_ptr < end_ptr; in_ptr += avctx->channels, out_ptr += avctx->channels) { \
461  int c; \
462  for (c = 0; c < avctx->channels; c++) \
463  out_ptr[c] = in_ptr[at->channel_map[c]]; \
464  }
465 
467 {
468  ATDecodeContext *at = avctx->priv_data;
469  if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) {
471  } else {
472  COPY_SAMPLES(int16_t);
473  }
474 }
475 
476 static int ffat_decode(AVCodecContext *avctx, void *data,
477  int *got_frame_ptr, AVPacket *avpkt)
478 {
479  ATDecodeContext *at = avctx->priv_data;
480  AVFrame *frame = data;
481  int pkt_size = avpkt->size;
482  OSStatus ret;
483  AudioBufferList out_buffers;
484 
485  if (avctx->codec_id == AV_CODEC_ID_AAC) {
486  if (!at->extradata_size) {
487  uint8_t *side_data;
488  size_t side_data_size;
489 
491  &side_data_size);
492  if (side_data_size) {
493  at->extradata = av_mallocz(side_data_size + AV_INPUT_BUFFER_PADDING_SIZE);
494  if (!at->extradata)
495  return AVERROR(ENOMEM);
496  at->extradata_size = side_data_size;
497  memcpy(at->extradata, side_data, side_data_size);
498  }
499  }
500  }
501 
502  if (!at->converter) {
503  if ((ret = ffat_create_decoder(avctx, avpkt)) < 0) {
504  return ret;
505  }
506  }
507 
508  out_buffers = (AudioBufferList){
509  .mNumberBuffers = 1,
510  .mBuffers = {
511  {
512  .mNumberChannels = avctx->channels,
513  .mDataByteSize = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->frame_size
514  * avctx->channels,
515  }
516  }
517  };
518 
520 
521  if (avpkt->size) {
522  if ((ret = av_packet_ref(&at->new_in_pkt, avpkt)) < 0) {
523  return ret;
524  }
525  } else {
526  at->eof = 1;
527  }
528 
529  frame->sample_rate = avctx->sample_rate;
530 
531  frame->nb_samples = avctx->frame_size;
532 
533  out_buffers.mBuffers[0].mData = at->decoded_data;
534 
535  ret = AudioConverterFillComplexBuffer(at->converter, ffat_decode_callback, avctx,
536  &frame->nb_samples, &out_buffers, NULL);
537  if ((!ret || ret == 1) && frame->nb_samples) {
538  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
539  return ret;
540  ffat_copy_samples(avctx, frame);
541  *got_frame_ptr = 1;
542  if (at->last_pts != AV_NOPTS_VALUE) {
543  frame->pts = at->last_pts;
544  at->last_pts = avpkt->pts;
545  }
546  } else if (ret && ret != 1) {
547  av_log(avctx, AV_LOG_WARNING, "Decode error: %i\n", ret);
548  } else {
549  at->last_pts = avpkt->pts;
550  }
551 
552  return pkt_size;
553 }
554 
556 {
557  ATDecodeContext *at = avctx->priv_data;
558  AudioConverterReset(at->converter);
560  av_packet_unref(&at->in_pkt);
561 }
562 
564 {
565  ATDecodeContext *at = avctx->priv_data;
566  if (at->converter)
567  AudioConverterDispose(at->converter);
569  av_packet_unref(&at->in_pkt);
570  av_freep(&at->decoded_data);
571  av_freep(&at->extradata);
572  return 0;
573 }
574 
575 #define FFAT_DEC_CLASS(NAME) \
576  static const AVClass ffat_##NAME##_dec_class = { \
577  .class_name = "at_" #NAME "_dec", \
578  .version = LIBAVUTIL_VERSION_INT, \
579  };
580 
581 #define FFAT_DEC(NAME, ID, bsf_name) \
582  FFAT_DEC_CLASS(NAME) \
583  const AVCodec ff_##NAME##_at_decoder = { \
584  .name = #NAME "_at", \
585  .long_name = NULL_IF_CONFIG_SMALL(#NAME " (AudioToolbox)"), \
586  .type = AVMEDIA_TYPE_AUDIO, \
587  .id = ID, \
588  .priv_data_size = sizeof(ATDecodeContext), \
589  .init = ffat_init_decoder, \
590  .close = ffat_close_decoder, \
591  .decode = ffat_decode, \
592  .flush = ffat_decode_flush, \
593  .priv_class = &ffat_##NAME##_dec_class, \
594  .bsfs = bsf_name, \
595  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_CHANNEL_CONF, \
596  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, \
597  .wrapper_name = "at", \
598  };
599 
600 FFAT_DEC(aac, AV_CODEC_ID_AAC, "aac_adtstoasc")
602 FFAT_DEC(adpcm_ima_qt, AV_CODEC_ID_ADPCM_IMA_QT, NULL)
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1012
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:424
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_CODEC_ID_ADPCM_IMA_QT
@ AV_CODEC_ID_ADPCM_IMA_QT
Definition: codec_id.h:353
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:426
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1043
ffat_close_decoder
static av_cold int ffat_close_decoder(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:563
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:992
COPY_SAMPLES
#define COPY_SAMPLES(type)
Definition: audiotoolboxdec.c:456
AV_CH_LOW_FREQUENCY_2
#define AV_CH_LOW_FREQUENCY_2
Definition: channel_layout.h:73
put_descr
static void put_descr(PutByteContext *pb, int tag, unsigned int size)
Definition: audiotoolboxdec.c:219
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
mpegaudiodecheader.h
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:373
ffat_init_decoder
static av_cold int ffat_init_decoder(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:400
b
#define b
Definition: input.c:40
data
const char data[16]
Definition: mxf.c:143
AV_CODEC_ID_ALAC
@ AV_CODEC_ID_ALAC
Definition: codec_id.h:439
ATDecodeContext::extradata
uint8_t * extradata
Definition: audiotoolboxdec.c:50
AV_CODEC_ID_AMR_NB
@ AV_CODEC_ID_AMR_NB
Definition: codec_id.h:406
ATDecodeContext::decoded_data
char * decoded_data
Definition: audiotoolboxdec.c:47
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
ATDecodeContext::new_in_pkt
AVPacket new_in_pkt
Definition: audiotoolboxdec.c:46
ffat_decode_callback
static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets, AudioBufferList *data, AudioStreamPacketDescription **packets, void *inctx)
Definition: audiotoolboxdec.c:417
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
ff_mpa_decode_header
int ff_mpa_decode_header(uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate, enum AVCodecID *codec_id)
Definition: mpegaudiodecheader.c:120
ffat_get_format_id
static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile)
Definition: audiotoolboxdec.c:57
ffat_usable_extradata
static av_cold int ffat_usable_extradata(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:268
ATDecodeContext::eof
int eof
Definition: audiotoolboxdec.c:54
GetBitContext
Definition: get_bits.h:62
AC3HeaderInfo
Definition: ac3.h:177
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:424
avassert.h
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:678
ffat_update_ctx
static int ffat_update_ctx(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:159
bytestream2_init_writer
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:147
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:485
bytestream2_put_buffer
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:286
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:423
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1425
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:320
ATDecodeContext::pkt_desc
AudioStreamPacketDescription pkt_desc
Definition: audiotoolboxdec.c:44
AC3HeaderInfo::sample_rate
uint16_t sample_rate
Definition: ac3.h:201
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:369
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:393
AV_CODEC_ID_PCM_ALAW
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:321
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
ffat_get_channel_id
static int ffat_get_channel_id(AudioChannelLabel label)
Definition: audiotoolboxdec.c:96
NULL
#define NULL
Definition: coverity.c:32
ff_ctzll
#define ff_ctzll
Definition: intmath.h:126
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:433
AV_CODEC_ID_QDM2
@ AV_CODEC_ID_QDM2
Definition: codec_id.h:442
AV_CH_FRONT_CENTER
#define AV_CH_FRONT_CENTER
Definition: channel_layout.h:51
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:432
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:481
AC3HeaderInfo::num_blocks
int num_blocks
number of audio blocks
Definition: ac3.h:193
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
AV_CODEC_ID_EAC3
@ AV_CODEC_ID_EAC3
Definition: codec_id.h:463
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:425
PutByteContext
Definition: bytestream.h:37
AC3HeaderInfo::channels
uint8_t channels
Definition: ac3.h:203
ffat_decode
static int ffat_decode(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: audiotoolboxdec.c:476
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1652
ffat_create_decoder
static av_cold int ffat_create_decoder(AVCodecContext *avctx, const AVPacket *pkt)
Definition: audiotoolboxdec.c:300
ffat_get_magic_cookie
static uint8_t * ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
Definition: audiotoolboxdec.c:228
ac3_parser_internal.h
AVPacket::size
int size
Definition: packet.h:374
id
enum AVCodecID id
Definition: extract_extradata_bsf.c:325
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1000
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AV_CODEC_ID_QDMC
@ AV_CODEC_ID_QDMC
Definition: codec_id.h:473
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
format
ofilter format
Definition: ffmpeg_filter.c:172
ffat_set_extradata
static int ffat_set_extradata(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:278
FFAT_DEC
#define FFAT_DEC(NAME, ID, bsf_name)
Definition: audiotoolboxdec.c:581
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
kAudioFormatEnhancedAC3
#define kAudioFormatEnhancedAC3
Definition: audiotoolboxdec.c:37
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:993
layout
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
Definition: filter_design.txt:18
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:366
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:484
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: avpacket.c:253
ATDecodeContext::in_pkt
AVPacket in_pkt
Definition: audiotoolboxdec.c:45
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:263
profile
int profile
Definition: mxfenc.c:2003
avcodec.h
AV_CODEC_ID_GSM_MS
@ AV_CODEC_ID_GSM_MS
Definition: codec_id.h:453
tag
uint32_t tag
Definition: movenc.c:1596
ret
ret
Definition: filter_design.txt:187
AVCodecContext::block_align
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition: avcodec.h:1029
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
ff_ac3_parse_header
int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
Parse AC-3 frame header.
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
ATDecodeContext::converter
AudioConverterRef converter
Definition: audiotoolboxdec.c:43
AVCodecContext
main external API structure.
Definition: avcodec.h:383
ffat_convert_layout
static AudioChannelLayout * ffat_convert_layout(AudioChannelLayout *layout, UInt32 *size)
Definition: audiotoolboxdec.c:131
channel_layout.h
ffat_decode_flush
static av_cold void ffat_decode_flush(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:555
AV_PKT_DATA_NEW_EXTRADATA
@ 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:55
ATDecodeContext
Definition: audiotoolboxdec.c:40
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1525
ffat_copy_samples
static void ffat_copy_samples(AVCodecContext *avctx, AVFrame *frame)
Definition: audiotoolboxdec.c:466
ffat_compare_channel_descriptions
static int ffat_compare_channel_descriptions(const void *a, const void *b)
Definition: audiotoolboxdec.c:124
av_get_default_channel_layout
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
Definition: channel_layout.c:231
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:410
AVPacket
This structure stores compressed data.
Definition: packet.h:350
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
ATDecodeContext::last_pts
int64_t last_pts
Definition: audiotoolboxdec.c:53
AV_CODEC_ID_ILBC
@ AV_CODEC_ID_ILBC
Definition: codec_id.h:482
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
ATDecodeContext::av_class
AVClass * av_class
Definition: audiotoolboxdec.c:41
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ATDecodeContext::extradata_size
int extradata_size
Definition: audiotoolboxdec.c:51
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:62
AV_CODEC_ID_MP1
@ AV_CODEC_ID_MP1
Definition: codec_id.h:465
AC3HeaderInfo::bit_rate
uint32_t bit_rate
Definition: ac3.h:202
ATDecodeContext::channel_map
int channel_map[64]
Definition: audiotoolboxdec.c:48