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/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 
43 typedef struct ATDecodeContext {
45 
46  AudioConverterRef converter;
47  AudioStreamPacketDescription pkt_desc;
50  char *decoded_data;
51  int channel_map[64];
52 
53  uint8_t *extradata;
55 
57  int eof;
59 
60 static 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;
69  case AV_CODEC_ID_ALAC:
70  return kAudioFormatAppleLossless;
71  case AV_CODEC_ID_AMR_NB:
72  return kAudioFormatAMR;
73  case AV_CODEC_ID_EAC3:
75 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
76  case AV_CODEC_ID_GSM_MS:
77  return kAudioFormatMicrosoftGSM;
78  case AV_CODEC_ID_ILBC:
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;
91  case AV_CODEC_ID_QDMC:
92  return kAudioFormatQDesign;
93  case AV_CODEC_ID_QDM2:
94  return kAudioFormatQDesign2;
95  default:
96  av_assert0(!"Invalid codec ID!");
97  return 0;
98  }
99 }
100 
101 static 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 
129 static 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 
136 static 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) {
150  av_free(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;
160  av_free(layout);
161  return new_layout;
162 }
163 
164 static int ffat_update_ctx(AVCodecContext *avctx)
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 & (1 << id))
205  goto done;
206  layout_mask |= 1 << 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;
215 done:
216  av_free(layout);
217  }
218 
219  if (!avctx->frame_size)
220  avctx->frame_size = 2048;
221 
222  return 0;
223 }
224 
225 static 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 
234 static 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;
239  PutByteContext pb;
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;
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 
386  if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_QT)
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 
408  at->last_pts = AV_NOPTS_VALUE;
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 
430 static 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 
447  av_packet_unref(&at->in_pkt);
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  out_buffers.mBuffers[0].mData = at->decoded_data;
546 
547  ret = AudioConverterFillComplexBuffer(at->converter, ffat_decode_callback, avctx,
548  &frame->nb_samples, &out_buffers, NULL);
549  if ((!ret || ret == 1) && frame->nb_samples) {
550  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
551  return ret;
552  ffat_copy_samples(avctx, frame);
553  *got_frame_ptr = 1;
554  if (at->last_pts != AV_NOPTS_VALUE) {
555  frame->pts = at->last_pts;
556  at->last_pts = avpkt->pts;
557  }
558  } else if (ret && ret != 1) {
559  av_log(avctx, AV_LOG_WARNING, "Decode error: %i\n", ret);
560  } else {
561  at->last_pts = avpkt->pts;
562  }
563 
564  return pkt_size;
565 }
566 
568 {
569  ATDecodeContext *at = avctx->priv_data;
570  AudioConverterReset(at->converter);
572  av_packet_unref(&at->in_pkt);
573 }
574 
576 {
577  ATDecodeContext *at = avctx->priv_data;
578  if (at->converter)
579  AudioConverterDispose(at->converter);
581  av_packet_unref(&at->in_pkt);
582  av_freep(&at->decoded_data);
583  av_freep(&at->extradata);
584  return 0;
585 }
586 
587 #define FFAT_DEC_CLASS(NAME) \
588  static const AVClass ffat_##NAME##_dec_class = { \
589  .class_name = "at_" #NAME "_dec", \
590  .version = LIBAVUTIL_VERSION_INT, \
591  };
592 
593 #define FFAT_DEC(NAME, ID, bsf_name) \
594  FFAT_DEC_CLASS(NAME) \
595  const FFCodec ff_##NAME##_at_decoder = { \
596  .p.name = #NAME "_at", \
597  CODEC_LONG_NAME(#NAME " (AudioToolbox)"), \
598  .p.type = AVMEDIA_TYPE_AUDIO, \
599  .p.id = ID, \
600  .priv_data_size = sizeof(ATDecodeContext), \
601  .init = ffat_init_decoder, \
602  .close = ffat_close_decoder, \
603  FF_CODEC_DECODE_CB(ffat_decode), \
604  .flush = ffat_decode_flush, \
605  .p.priv_class = &ffat_##NAME##_dec_class, \
606  .bsfs = bsf_name, \
607  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_CHANNEL_CONF, \
608  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
609  .p.wrapper_name = "at", \
610  };
611 
612 FFAT_DEC(aac, AV_CODEC_ID_AAC, "aac_adtstoasc")
614 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:1083
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:429
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
AV_CODEC_ID_ADPCM_IMA_QT
@ AV_CODEC_ID_ADPCM_IMA_QT
Definition: codec_id.h:373
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:449
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:575
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1056
COPY_SAMPLES
#define COPY_SAMPLES(type)
Definition: audiotoolboxdec.c:469
AV_CH_LOW_FREQUENCY_2
#define AV_CH_LOW_FREQUENCY_2
Definition: channel_layout.h:196
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
int64_t
long long int64_t
Definition: coverity.c:34
put_descr
static void put_descr(PutByteContext *pb, int tag, unsigned int size)
Definition: audiotoolboxdec.c:225
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
mpegaudiodecheader.h
AVPacket::data
uint8_t * data
Definition: packet.h:539
ffat_init_decoder
static av_cold int ffat_init_decoder(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:413
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:149
AV_CODEC_ID_ALAC
@ AV_CODEC_ID_ALAC
Definition: codec_id.h:462
ATDecodeContext::extradata
uint8_t * extradata
Definition: audiotoolboxdec.c:53
AV_CODEC_ID_AMR_NB
@ AV_CODEC_ID_AMR_NB
Definition: codec_id.h:427
ATDecodeContext::decoded_data
char * decoded_data
Definition: audiotoolboxdec.c:50
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:316
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:321
ATDecodeContext::new_in_pkt
AVPacket new_in_pkt
Definition: audiotoolboxdec.c:49
ffat_decode_callback
static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets, AudioBufferList *data, AudioStreamPacketDescription **packets, void *inctx)
Definition: audiotoolboxdec.c:430
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:60
ffat_usable_extradata
static av_cold int ffat_usable_extradata(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:274
ATDecodeContext::eof
int eof
Definition: audiotoolboxdec.c:57
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1071
GetBitContext
Definition: get_bits.h:108
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:447
avassert.h
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
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:545
ffat_update_ctx
static int ffat_update_ctx(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:164
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:530
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:116
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:446
av_channel_layout_from_mask
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:247
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1585
decode.h
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:340
ATDecodeContext::pkt_desc
AudioStreamPacketDescription pkt_desc
Definition: audiotoolboxdec.c:47
AC3HeaderInfo::sample_rate
uint16_t sample_rate
Definition: ac3_parser_internal.h:58
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:461
AV_CODEC_ID_PCM_ALAW
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:341
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
ffat_get_channel_id
static int ffat_get_channel_id(AudioChannelLabel label)
Definition: audiotoolboxdec.c:101
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:501
AV_CODEC_ID_QDM2
@ AV_CODEC_ID_QDM2
Definition: codec_id.h:465
AV_CH_FRONT_CENTER
#define AV_CH_FRONT_CENTER
Definition: channel_layout.h:174
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: packet.c:437
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: packet.c:486
ffat_decode
static int ffat_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: audiotoolboxdec.c:489
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:486
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:448
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:1697
ffat_create_decoder
static av_cold int ffat_create_decoder(AVCodecContext *avctx, const AVPacket *pkt)
Definition: audiotoolboxdec.c:306
ffat_get_magic_cookie
static uint8_t * ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
Definition: audiotoolboxdec.c:234
ac3_parser_internal.h
AVPacket::size
int size
Definition: packet.h:540
codec_internal.h
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1063
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:496
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:284
FFAT_DEC
#define FFAT_DEC(NAME, ID, bsf_name)
Definition: audiotoolboxdec.c:593
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:40
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:834
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:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
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:529
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: packet.c:252
ATDecodeContext::in_pkt
AVPacket in_pkt
Definition: audiotoolboxdec.c:48
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:256
profile
int profile
Definition: mxfenc.c:2228
avcodec.h
AV_CODEC_ID_GSM_MS
@ AV_CODEC_ID_GSM_MS
Definition: codec_id.h:476
tag
uint32_t tag
Definition: movenc.c:1876
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:1089
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.c:367
ATDecodeContext::converter
AudioConverterRef converter
Definition: audiotoolboxdec.c:46
AVCodecContext
main external API structure.
Definition: avcodec.h:451
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
ffat_convert_layout
static AudioChannelLayout * ffat_convert_layout(AudioChannelLayout *layout, UInt32 *size)
Definition: audiotoolboxdec.c:136
channel_layout.h
ffat_decode_flush
static av_cold void ffat_decode_flush(AVCodecContext *avctx)
Definition: audiotoolboxdec.c:567
ATDecodeContext
Definition: audiotoolboxdec.c:43
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1650
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:437
ffat_copy_samples
static void ffat_copy_samples(AVCodecContext *avctx, AVFrame *frame)
Definition: audiotoolboxdec.c:479
mem.h
ffat_compare_channel_descriptions
static int ffat_compare_channel_descriptions(const void *a, const void *b)
Definition: audiotoolboxdec.c:129
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
AVPacket
This structure stores compressed data.
Definition: packet.h:516
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
ATDecodeContext::last_pts
int64_t last_pts
Definition: audiotoolboxdec.c:56
AV_CODEC_ID_ILBC
@ AV_CODEC_ID_ILBC
Definition: codec_id.h:505
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
ATDecodeContext::av_class
AVClass * av_class
Definition: audiotoolboxdec.c:44
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:54
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:488
AC3HeaderInfo::bit_rate
uint32_t bit_rate
Definition: ac3_parser_internal.h:59
ATDecodeContext::channel_map
int channel_map[64]
Definition: audiotoolboxdec.c:51