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