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 "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/opt.h"
36 #include "libavutil/log.h"
37 
38 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
39 #define kAudioFormatEnhancedAC3 'ec-3'
40 #endif
41 
42 typedef struct ATDecodeContext {
44 
45  AudioConverterRef converter;
46  AudioStreamPacketDescription pkt_desc;
49  char *decoded_data;
50  int channel_map[64];
51 
52  uint8_t *extradata;
54 
55  int64_t last_pts;
56  int eof;
58 
59 static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile)
60 {
61  switch (codec) {
62  case AV_CODEC_ID_AAC:
63  return kAudioFormatMPEG4AAC;
64  case AV_CODEC_ID_AC3:
65  return kAudioFormatAC3;
67  return kAudioFormatAppleIMA4;
68  case AV_CODEC_ID_ALAC:
69  return kAudioFormatAppleLossless;
70  case AV_CODEC_ID_AMR_NB:
71  return kAudioFormatAMR;
72  case AV_CODEC_ID_EAC3:
74  case AV_CODEC_ID_GSM_MS:
75  return kAudioFormatMicrosoftGSM;
76  case AV_CODEC_ID_ILBC:
77  return kAudioFormatiLBC;
78  case AV_CODEC_ID_MP1:
79  return kAudioFormatMPEGLayer1;
80  case AV_CODEC_ID_MP2:
81  return kAudioFormatMPEGLayer2;
82  case AV_CODEC_ID_MP3:
83  return kAudioFormatMPEGLayer3;
85  return kAudioFormatALaw;
87  return kAudioFormatULaw;
88  case AV_CODEC_ID_QDMC:
89  return kAudioFormatQDesign;
90  case AV_CODEC_ID_QDM2:
91  return kAudioFormatQDesign2;
92  default:
93  av_assert0(!"Invalid codec ID!");
94  return 0;
95  }
96 }
97 
98 static int ffat_get_channel_id(AudioChannelLabel label)
99 {
100  if (label == 0)
101  return -1;
102  else if (label <= kAudioChannelLabel_LFEScreen)
103  return label - 1;
104  else if (label <= kAudioChannelLabel_RightSurround)
105  return label + 4;
106  else if (label <= kAudioChannelLabel_CenterSurround)
107  return label + 1;
108  else if (label <= kAudioChannelLabel_RightSurroundDirect)
109  return label + 23;
110  else if (label <= kAudioChannelLabel_TopBackRight)
111  return label - 1;
112  else if (label < kAudioChannelLabel_RearSurroundLeft)
113  return -1;
114  else if (label <= kAudioChannelLabel_RearSurroundRight)
115  return label - 29;
116  else if (label <= kAudioChannelLabel_RightWide)
117  return label - 4;
118  else if (label == kAudioChannelLabel_LFE2)
120  else if (label == kAudioChannelLabel_Mono)
122  else
123  return -1;
124 }
125 
126 static int ffat_compare_channel_descriptions(const void* a, const void* b)
127 {
128  const AudioChannelDescription* da = a;
129  const AudioChannelDescription* db = b;
130  return ffat_get_channel_id(da->mChannelLabel) - ffat_get_channel_id(db->mChannelLabel);
131 }
132 
133 static AudioChannelLayout *ffat_convert_layout(AudioChannelLayout *layout, UInt32* size)
134 {
135  AudioChannelLayoutTag tag = layout->mChannelLayoutTag;
136  AudioChannelLayout *new_layout;
137  if (tag == kAudioChannelLayoutTag_UseChannelDescriptions)
138  return layout;
139  else if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
140  AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
141  sizeof(UInt32), &layout->mChannelBitmap, size);
142  else
143  AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
144  sizeof(AudioChannelLayoutTag), &tag, size);
145  new_layout = av_malloc(*size);
146  if (!new_layout) {
147  av_free(layout);
148  return NULL;
149  }
150  if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
151  AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
152  sizeof(UInt32), &layout->mChannelBitmap, size, new_layout);
153  else
154  AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
155  sizeof(AudioChannelLayoutTag), &tag, size, new_layout);
156  new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
157  av_free(layout);
158  return new_layout;
159 }
160 
161 static int ffat_update_ctx(AVCodecContext *avctx)
162 {
163  ATDecodeContext *at = avctx->priv_data;
164  AudioStreamBasicDescription format;
165  UInt32 size = sizeof(format);
166  if (!AudioConverterGetProperty(at->converter,
167  kAudioConverterCurrentInputStreamDescription,
168  &size, &format)) {
169  if (format.mSampleRate)
170  avctx->sample_rate = format.mSampleRate;
172  av_channel_layout_default(&avctx->ch_layout, format.mChannelsPerFrame);
173  avctx->frame_size = format.mFramesPerPacket;
174  }
175 
176  if (!AudioConverterGetProperty(at->converter,
177  kAudioConverterCurrentOutputStreamDescription,
178  &size, &format)) {
179  format.mSampleRate = avctx->sample_rate;
180  format.mChannelsPerFrame = avctx->ch_layout.nb_channels;
181  AudioConverterSetProperty(at->converter,
182  kAudioConverterCurrentOutputStreamDescription,
183  size, &format);
184  }
185 
186  if (!AudioConverterGetPropertyInfo(at->converter, kAudioConverterOutputChannelLayout,
187  &size, NULL) && size) {
188  AudioChannelLayout *layout = av_malloc(size);
189  uint64_t layout_mask = 0;
190  int i;
191  if (!layout)
192  return AVERROR(ENOMEM);
193  AudioConverterGetProperty(at->converter, kAudioConverterOutputChannelLayout,
194  &size, layout);
196  return AVERROR(ENOMEM);
197  for (i = 0; i < layout->mNumberChannelDescriptions; i++) {
198  int id = ffat_get_channel_id(layout->mChannelDescriptions[i].mChannelLabel);
199  if (id < 0)
200  goto done;
201  if (layout_mask & (1 << id))
202  goto done;
203  layout_mask |= 1 << id;
204  layout->mChannelDescriptions[i].mChannelFlags = i; // Abusing flags as index
205  }
207  av_channel_layout_from_mask(&avctx->ch_layout, layout_mask);
208  qsort(layout->mChannelDescriptions, layout->mNumberChannelDescriptions,
209  sizeof(AudioChannelDescription), &ffat_compare_channel_descriptions);
210  for (i = 0; i < layout->mNumberChannelDescriptions; i++)
211  at->channel_map[i] = layout->mChannelDescriptions[i].mChannelFlags;
212 done:
213  av_free(layout);
214  }
215 
216  if (!avctx->frame_size)
217  avctx->frame_size = 2048;
218 
219  return 0;
220 }
221 
222 static void put_descr(PutByteContext *pb, int tag, unsigned int size)
223 {
224  int i = 3;
225  bytestream2_put_byte(pb, tag);
226  for (; i > 0; i--)
227  bytestream2_put_byte(pb, (size >> (7 * i)) | 0x80);
228  bytestream2_put_byte(pb, size & 0x7F);
229 }
230 
231 static uint8_t* ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
232 {
233  ATDecodeContext *at = avctx->priv_data;
234  if (avctx->codec_id == AV_CODEC_ID_AAC) {
235  char *extradata;
236  PutByteContext pb;
237  *cookie_size = 5 + 3 + 5+13 + 5+at->extradata_size;
238  if (!(extradata = av_malloc(*cookie_size)))
239  return NULL;
240 
241  bytestream2_init_writer(&pb, extradata, *cookie_size);
242 
243  // ES descriptor
244  put_descr(&pb, 0x03, 3 + 5+13 + 5+at->extradata_size);
245  bytestream2_put_be16(&pb, 0);
246  bytestream2_put_byte(&pb, 0x00); // flags (= no flags)
247 
248  // DecoderConfig descriptor
249  put_descr(&pb, 0x04, 13 + 5+at->extradata_size);
250 
251  // Object type indication
252  bytestream2_put_byte(&pb, 0x40);
253 
254  bytestream2_put_byte(&pb, 0x15); // flags (= Audiostream)
255 
256  bytestream2_put_be24(&pb, 0); // Buffersize DB
257 
258  bytestream2_put_be32(&pb, 0); // maxbitrate
259  bytestream2_put_be32(&pb, 0); // avgbitrate
260 
261  // DecoderSpecific info descriptor
262  put_descr(&pb, 0x05, at->extradata_size);
264  return extradata;
265  } else {
266  *cookie_size = at->extradata_size;
267  return at->extradata;
268  }
269 }
270 
272 {
273  ATDecodeContext *at = avctx->priv_data;
274  return at->extradata_size &&
275  (avctx->codec_id == AV_CODEC_ID_ALAC ||
276  avctx->codec_id == AV_CODEC_ID_QDM2 ||
277  avctx->codec_id == AV_CODEC_ID_QDMC ||
278  avctx->codec_id == AV_CODEC_ID_AAC);
279 }
280 
282 {
283  ATDecodeContext *at = avctx->priv_data;
284  if (ffat_usable_extradata(avctx)) {
285  OSStatus status;
286  UInt32 cookie_size;
287  uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
288  if (!cookie)
289  return AVERROR(ENOMEM);
290 
291  status = AudioConverterSetProperty(at->converter,
292  kAudioConverterDecompressionMagicCookie,
293  cookie_size, cookie);
294  if (status != 0)
295  av_log(avctx, AV_LOG_WARNING, "AudioToolbox cookie error: %i\n", (int)status);
296 
297  if (cookie != at->extradata)
298  av_free(cookie);
299  }
300  return 0;
301 }
302 
304  const AVPacket *pkt)
305 {
306  ATDecodeContext *at = avctx->priv_data;
307  OSStatus status;
308  int i;
309 
310  enum AVSampleFormat sample_fmt = (avctx->bits_per_raw_sample == 32) ?
312 
313  AudioStreamBasicDescription in_format = {
314  .mFormatID = ffat_get_format_id(avctx->codec_id, avctx->profile),
315  .mBytesPerPacket = (avctx->codec_id == AV_CODEC_ID_ILBC) ? avctx->block_align : 0,
316  };
317  AudioStreamBasicDescription out_format = {
318  .mFormatID = kAudioFormatLinearPCM,
319  .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
320  .mFramesPerPacket = 1,
321  .mBitsPerChannel = av_get_bytes_per_sample(sample_fmt) * 8,
322  };
323 
324  avctx->sample_fmt = sample_fmt;
325 
326  if (ffat_usable_extradata(avctx)) {
327  UInt32 format_size = sizeof(in_format);
328  UInt32 cookie_size;
329  uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
330  if (!cookie)
331  return AVERROR(ENOMEM);
332  status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
333  cookie_size, cookie, &format_size, &in_format);
334  if (cookie != at->extradata)
335  av_free(cookie);
336  if (status != 0) {
337  av_log(avctx, AV_LOG_ERROR, "AudioToolbox header-parse error: %i\n", (int)status);
338  return AVERROR_UNKNOWN;
339  }
340 #if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
341  } else if (pkt && pkt->size >= 4 &&
342  (avctx->codec_id == AV_CODEC_ID_MP1 ||
343  avctx->codec_id == AV_CODEC_ID_MP2 ||
344  avctx->codec_id == AV_CODEC_ID_MP3)) {
345  enum AVCodecID codec_id;
346  int bit_rate;
348  &in_format.mChannelsPerFrame, &avctx->frame_size,
349  &bit_rate, &codec_id) < 0)
350  return AVERROR_INVALIDDATA;
351  avctx->bit_rate = bit_rate;
352  in_format.mSampleRate = avctx->sample_rate;
353 #endif
354 #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
355  } else if (pkt && pkt->size >= 7 &&
356  (avctx->codec_id == AV_CODEC_ID_AC3 ||
357  avctx->codec_id == AV_CODEC_ID_EAC3)) {
358  AC3HeaderInfo hdr;
359  GetBitContext gbc;
360  init_get_bits8(&gbc, pkt->data, pkt->size);
361  if (ff_ac3_parse_header(&gbc, &hdr) < 0)
362  return AVERROR_INVALIDDATA;
363  in_format.mSampleRate = hdr.sample_rate;
364  in_format.mChannelsPerFrame = hdr.channels;
365  avctx->frame_size = hdr.num_blocks * 256;
366  avctx->bit_rate = hdr.bit_rate;
367 #endif
368  } else {
369  in_format.mSampleRate = avctx->sample_rate ? avctx->sample_rate : 44100;
370  in_format.mChannelsPerFrame = avctx->ch_layout.nb_channels ? avctx->ch_layout.nb_channels : 1;
371  }
372 
373  avctx->sample_rate = out_format.mSampleRate = in_format.mSampleRate;
376  avctx->ch_layout.nb_channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
377 
378  out_format.mBytesPerFrame =
379  out_format.mChannelsPerFrame * (out_format.mBitsPerChannel / 8);
380  out_format.mBytesPerPacket =
381  out_format.mBytesPerFrame * out_format.mFramesPerPacket;
382 
383  if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_QT)
384  in_format.mFramesPerPacket = 64;
385 
386  status = AudioConverterNew(&in_format, &out_format, &at->converter);
387 
388  if (status != 0) {
389  av_log(avctx, AV_LOG_ERROR, "AudioToolbox init error: %i\n", (int)status);
390  return AVERROR_UNKNOWN;
391  }
392 
393  if ((status = ffat_set_extradata(avctx)) < 0)
394  return status;
395 
396  for (i = 0; i < (sizeof(at->channel_map) / sizeof(at->channel_map[0])); i++)
397  at->channel_map[i] = i;
398 
399  ffat_update_ctx(avctx);
400 
402  * avctx->frame_size * avctx->ch_layout.nb_channels)))
403  return AVERROR(ENOMEM);
404 
405  at->last_pts = AV_NOPTS_VALUE;
406 
407  return 0;
408 }
409 
411 {
412  ATDecodeContext *at = avctx->priv_data;
413  if (avctx->extradata_size) {
415  if (!at->extradata)
416  return AVERROR(ENOMEM);
417  at->extradata_size = avctx->extradata_size;
418  memcpy(at->extradata, avctx->extradata, avctx->extradata_size);
419  }
420 
421  if ((avctx->ch_layout.nb_channels && avctx->sample_rate) || ffat_usable_extradata(avctx))
422  return ffat_create_decoder(avctx, NULL);
423  else
424  return 0;
425 }
426 
427 static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets,
428  AudioBufferList *data,
429  AudioStreamPacketDescription **packets,
430  void *inctx)
431 {
432  AVCodecContext *avctx = inctx;
433  ATDecodeContext *at = avctx->priv_data;
434 
435  if (at->eof) {
436  *nb_packets = 0;
437  if (packets) {
438  *packets = &at->pkt_desc;
439  at->pkt_desc.mDataByteSize = 0;
440  }
441  return 0;
442  }
443 
444  av_packet_unref(&at->in_pkt);
446 
447  if (!at->in_pkt.data) {
448  *nb_packets = 0;
449  return 1;
450  }
451 
452  data->mNumberBuffers = 1;
453  data->mBuffers[0].mNumberChannels = 0;
454  data->mBuffers[0].mDataByteSize = at->in_pkt.size;
455  data->mBuffers[0].mData = at->in_pkt.data;
456  *nb_packets = 1;
457 
458  if (packets) {
459  *packets = &at->pkt_desc;
460  at->pkt_desc.mDataByteSize = at->in_pkt.size;
461  }
462 
463  return 0;
464 }
465 
466 #define COPY_SAMPLES(type) \
467  type *in_ptr = (type*)at->decoded_data; \
468  type *end_ptr = in_ptr + frame->nb_samples * avctx->ch_layout.nb_channels; \
469  type *out_ptr = (type*)frame->data[0]; \
470  for (; in_ptr < end_ptr; in_ptr += avctx->ch_layout.nb_channels, out_ptr += avctx->ch_layout.nb_channels) { \
471  int c; \
472  for (c = 0; c < avctx->ch_layout.nb_channels; c++) \
473  out_ptr[c] = in_ptr[at->channel_map[c]]; \
474  }
475 
477 {
478  ATDecodeContext *at = avctx->priv_data;
479  if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) {
481  } else {
482  COPY_SAMPLES(int16_t);
483  }
484 }
485 
487  int *got_frame_ptr, AVPacket *avpkt)
488 {
489  ATDecodeContext *at = avctx->priv_data;
490  int pkt_size = avpkt->size;
491  OSStatus ret;
492  AudioBufferList out_buffers;
493 
494  if (avctx->codec_id == AV_CODEC_ID_AAC) {
495  if (!at->extradata_size) {
496  uint8_t *side_data;
497  size_t side_data_size;
498 
500  &side_data_size);
501  if (side_data_size) {
502  at->extradata = av_mallocz(side_data_size + AV_INPUT_BUFFER_PADDING_SIZE);
503  if (!at->extradata)
504  return AVERROR(ENOMEM);
505  at->extradata_size = side_data_size;
506  memcpy(at->extradata, side_data, side_data_size);
507  }
508  }
509  }
510 
511  if (!at->converter) {
512  if ((ret = ffat_create_decoder(avctx, avpkt)) < 0) {
513  return ret;
514  }
515  }
516 
517  out_buffers = (AudioBufferList){
518  .mNumberBuffers = 1,
519  .mBuffers = {
520  {
521  .mNumberChannels = avctx->ch_layout.nb_channels,
522  .mDataByteSize = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->frame_size
523  * avctx->ch_layout.nb_channels,
524  }
525  }
526  };
527 
529 
530  if (avpkt->size) {
531  if ((ret = av_packet_ref(&at->new_in_pkt, avpkt)) < 0) {
532  return ret;
533  }
534  } else {
535  at->eof = 1;
536  }
537 
538  frame->sample_rate = avctx->sample_rate;
539 
540  frame->nb_samples = avctx->frame_size;
541 
542  out_buffers.mBuffers[0].mData = at->decoded_data;
543 
544  ret = AudioConverterFillComplexBuffer(at->converter, ffat_decode_callback, avctx,
545  &frame->nb_samples, &out_buffers, NULL);
546  if ((!ret || ret == 1) && frame->nb_samples) {
547  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
548  return ret;
549  ffat_copy_samples(avctx, frame);
550  *got_frame_ptr = 1;
551  if (at->last_pts != AV_NOPTS_VALUE) {
552  frame->pts = at->last_pts;
553  at->last_pts = avpkt->pts;
554  }
555  } else if (ret && ret != 1) {
556  av_log(avctx, AV_LOG_WARNING, "Decode error: %i\n", ret);
557  } else {
558  at->last_pts = avpkt->pts;
559  }
560 
561  return pkt_size;
562 }
563 
565 {
566  ATDecodeContext *at = avctx->priv_data;
567  AudioConverterReset(at->converter);
569  av_packet_unref(&at->in_pkt);
570 }
571 
573 {
574  ATDecodeContext *at = avctx->priv_data;
575  if (at->converter)
576  AudioConverterDispose(at->converter);
578  av_packet_unref(&at->in_pkt);
579  av_freep(&at->decoded_data);
580  av_freep(&at->extradata);
581  return 0;
582 }
583 
584 #define FFAT_DEC_CLASS(NAME) \
585  static const AVClass ffat_##NAME##_dec_class = { \
586  .class_name = "at_" #NAME "_dec", \
587  .version = LIBAVUTIL_VERSION_INT, \
588  };
589 
590 #define FFAT_DEC(NAME, ID, bsf_name) \
591  FFAT_DEC_CLASS(NAME) \
592  const FFCodec ff_##NAME##_at_decoder = { \
593  .p.name = #NAME "_at", \
594  CODEC_LONG_NAME(#NAME " (AudioToolbox)"), \
595  .p.type = AVMEDIA_TYPE_AUDIO, \
596  .p.id = ID, \
597  .priv_data_size = sizeof(ATDecodeContext), \
598  .init = ffat_init_decoder, \
599  .close = ffat_close_decoder, \
600  FF_CODEC_DECODE_CB(ffat_decode), \
601  .flush = ffat_decode_flush, \
602  .p.priv_class = &ffat_##NAME##_dec_class, \
603  .bsfs = bsf_name, \
604  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_CHANNEL_CONF, \
605  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
606  .p.wrapper_name = "at", \
607  };
608 
609 FFAT_DEC(aac, AV_CODEC_ID_AAC, "aac_adtstoasc")
611 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:1062
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:422
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:365
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:441
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
ffat_close_decoder
static av_cold int ffat_close_decoder(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:572
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1034
COPY_SAMPLES
#define COPY_SAMPLES(type)
Definition: audiotoolboxdec.c:466
AV_CH_LOW_FREQUENCY_2
#define AV_CH_LOW_FREQUENCY_2
Definition: channel_layout.h:188
put_descr
static void put_descr(PutByteContext *pb, int tag, unsigned int size)
Definition: audiotoolboxdec.c:222
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
mpegaudiodecheader.h
AVPacket::data
uint8_t * data
Definition: packet.h:374
ffat_init_decoder
static av_cold int ffat_init_decoder(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:410
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:146
AV_CODEC_ID_ALAC
@ AV_CODEC_ID_ALAC
Definition: codec_id.h:454
ATDecodeContext::extradata
uint8_t * extradata
Definition: audiotoolboxdec.c:52
AV_CODEC_ID_AMR_NB
@ AV_CODEC_ID_AMR_NB
Definition: codec_id.h:419
ATDecodeContext::decoded_data
char * decoded_data
Definition: audiotoolboxdec.c:49
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:306
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
ATDecodeContext::new_in_pkt
AVPacket new_in_pkt
Definition: audiotoolboxdec.c:48
ffat_decode_callback
static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets, AudioBufferList *data, AudioStreamPacketDescription **packets, void *inctx)
Definition: audiotoolboxdec.c:427
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
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:59
ffat_usable_extradata
static av_cold int ffat_usable_extradata(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:271
ATDecodeContext::eof
int eof
Definition: audiotoolboxdec.c:56
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2054
GetBitContext
Definition: get_bits.h:107
AC3HeaderInfo
Definition: ac3_parser_internal.h:34
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:439
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:524
ffat_update_ctx
static int ffat_update_ctx(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:161
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:528
format
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
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_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:438
av_channel_layout_from_mask
FF_ENABLE_DEPRECATION_WARNINGS 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.
Definition: channel_layout.c:391
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:1487
decode.h
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:332
ATDecodeContext::pkt_desc
AudioStreamPacketDescription pkt_desc
Definition: audiotoolboxdec.c:46
AC3HeaderInfo::sample_rate
uint16_t sample_rate
Definition: ac3_parser_internal.h:58
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:388
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:436
AV_CODEC_ID_PCM_ALAW
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:333
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:98
NULL
#define NULL
Definition: coverity.c:32
ff_ctzll
#define ff_ctzll
Definition: intmath.h:127
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:476
AV_CODEC_ID_QDM2
@ AV_CODEC_ID_QDM2
Definition: codec_id.h:457
AV_CH_FRONT_CENTER
#define AV_CH_FRONT_CENTER
Definition: channel_layout.h:166
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:430
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:479
ffat_decode
static int ffat_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: audiotoolboxdec.c:486
AC3HeaderInfo::num_blocks
int num_blocks
number of audio blocks
Definition: ac3_parser_internal.h:50
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
AV_CODEC_ID_EAC3
@ AV_CODEC_ID_EAC3
Definition: codec_id.h:478
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:440
PutByteContext
Definition: bytestream.h:37
AC3HeaderInfo::channels
uint8_t channels
Definition: ac3_parser_internal.h:60
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1473
ffat_create_decoder
static av_cold int ffat_create_decoder(AVCodecContext *avctx, const AVPacket *pkt)
Definition: audiotoolboxdec.c:303
ffat_get_magic_cookie
static uint8_t * ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
Definition: audiotoolboxdec.c:231
ac3_parser_internal.h
AVPacket::size
int size
Definition: packet.h:375
codec_internal.h
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1050
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:488
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
ffat_set_extradata
static int ffat_set_extradata(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:281
FFAT_DEC
#define FFAT_DEC(NAME, ID, bsf_name)
Definition: audiotoolboxdec.c:590
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:39
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:962
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:269
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:108
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:527
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:251
ATDecodeContext::in_pkt
AVPacket in_pkt
Definition: audiotoolboxdec.c:47
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
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:254
profile
int profile
Definition: mxfenc.c:2009
avcodec.h
AV_CODEC_ID_GSM_MS
@ AV_CODEC_ID_GSM_MS
Definition: codec_id.h:468
tag
uint32_t tag
Definition: movenc.c:1641
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:1083
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
id
enum AVCodecID id
Definition: dts2pts_bsf.c:364
ATDecodeContext::converter
AudioConverterRef converter
Definition: audiotoolboxdec.c:45
AVCodecContext
main external API structure.
Definition: avcodec.h:426
ffat_convert_layout
static AudioChannelLayout * ffat_convert_layout(AudioChannelLayout *layout, UInt32 *size)
Definition: audiotoolboxdec.c:133
channel_layout.h
ffat_decode_flush
static av_cold void ffat_decode_flush(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:564
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:56
ATDecodeContext
Definition: audiotoolboxdec.c:42
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1565
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:632
ffat_copy_samples
static void ffat_copy_samples(AVCodecContext *avctx, AVFrame *frame)
Definition: audiotoolboxdec.c:476
ffat_compare_channel_descriptions
static int ffat_compare_channel_descriptions(const void *a, const void *b)
Definition: audiotoolboxdec.c:126
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:453
AVPacket
This structure stores compressed data.
Definition: packet.h:351
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
ATDecodeContext::last_pts
int64_t last_pts
Definition: audiotoolboxdec.c:55
AV_CODEC_ID_ILBC
@ AV_CODEC_ID_ILBC
Definition: codec_id.h:497
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
ATDecodeContext::av_class
AVClass * av_class
Definition: audiotoolboxdec.c:43
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ATDecodeContext::extradata_size
int extradata_size
Definition: audiotoolboxdec.c:53
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
AV_CODEC_ID_MP1
@ AV_CODEC_ID_MP1
Definition: codec_id.h:480
AC3HeaderInfo::bit_rate
uint32_t bit_rate
Definition: ac3_parser_internal.h:59
ATDecodeContext::channel_map
int channel_map[64]
Definition: audiotoolboxdec.c:50