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