FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
audiotoolboxdec.c
Go to the documentation of this file.
1 /*
2  * Audio Toolbox system codecs
3  *
4  * copyright (c) 2016 Rodger Combs
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.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 #ifndef __MAC_10_11
36 #define kAudioFormatEnhancedAC3 'ec-3'
37 #endif
38 
39 typedef struct ATDecodeContext {
41 
42  AudioConverterRef converter;
43  AudioStreamPacketDescription pkt_desc;
47  char *decoded_data;
48  int channel_map[64];
49 
52 
53  int64_t last_pts;
54  int eof;
56 
57 static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile)
58 {
59  switch (codec) {
60  case AV_CODEC_ID_AAC:
61  return kAudioFormatMPEG4AAC;
62  case AV_CODEC_ID_AC3:
63  return kAudioFormatAC3;
65  return kAudioFormatAppleIMA4;
66  case AV_CODEC_ID_ALAC:
67  return kAudioFormatAppleLossless;
68  case AV_CODEC_ID_AMR_NB:
69  return kAudioFormatAMR;
70  case AV_CODEC_ID_EAC3:
72  case AV_CODEC_ID_GSM_MS:
73  return kAudioFormatMicrosoftGSM;
74  case AV_CODEC_ID_ILBC:
75  return kAudioFormatiLBC;
76  case AV_CODEC_ID_MP1:
77  return kAudioFormatMPEGLayer1;
78  case AV_CODEC_ID_MP2:
79  return kAudioFormatMPEGLayer2;
80  case AV_CODEC_ID_MP3:
81  return kAudioFormatMPEGLayer3;
83  return kAudioFormatALaw;
85  return kAudioFormatULaw;
86  case AV_CODEC_ID_QDMC:
87  return kAudioFormatQDesign;
88  case AV_CODEC_ID_QDM2:
89  return kAudioFormatQDesign2;
90  default:
91  av_assert0(!"Invalid codec ID!");
92  return 0;
93  }
94 }
95 
96 static int ffat_get_channel_id(AudioChannelLabel label)
97 {
98  if (label == 0)
99  return -1;
100  else if (label <= kAudioChannelLabel_LFEScreen)
101  return label - 1;
102  else if (label <= kAudioChannelLabel_RightSurround)
103  return label + 4;
104  else if (label <= kAudioChannelLabel_CenterSurround)
105  return label + 1;
106  else if (label <= kAudioChannelLabel_RightSurroundDirect)
107  return label + 23;
108  else if (label <= kAudioChannelLabel_TopBackRight)
109  return label - 1;
110  else if (label < kAudioChannelLabel_RearSurroundLeft)
111  return -1;
112  else if (label <= kAudioChannelLabel_RearSurroundRight)
113  return label - 29;
114  else if (label <= kAudioChannelLabel_RightWide)
115  return label - 4;
116  else if (label == kAudioChannelLabel_LFE2)
118  else if (label == kAudioChannelLabel_Mono)
120  else
121  return -1;
122 }
123 
124 static int ffat_compare_channel_descriptions(const void* a, const void* b)
125 {
126  const AudioChannelDescription* da = a;
127  const AudioChannelDescription* db = b;
128  return ffat_get_channel_id(da->mChannelLabel) - ffat_get_channel_id(db->mChannelLabel);
129 }
130 
131 static AudioChannelLayout *ffat_convert_layout(AudioChannelLayout *layout, UInt32* size)
132 {
133  AudioChannelLayoutTag tag = layout->mChannelLayoutTag;
134  AudioChannelLayout *new_layout;
135  if (tag == kAudioChannelLayoutTag_UseChannelDescriptions)
136  return layout;
137  else if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
138  AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
139  sizeof(UInt32), &layout->mChannelBitmap, size);
140  else
141  AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
142  sizeof(AudioChannelLayoutTag), &tag, size);
143  new_layout = av_malloc(*size);
144  if (!new_layout) {
145  av_free(layout);
146  return NULL;
147  }
148  if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
149  AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
150  sizeof(UInt32), &layout->mChannelBitmap, size, new_layout);
151  else
152  AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
153  sizeof(AudioChannelLayoutTag), &tag, size, new_layout);
154  new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
155  av_free(layout);
156  return new_layout;
157 }
158 
159 static int ffat_update_ctx(AVCodecContext *avctx)
160 {
161  ATDecodeContext *at = avctx->priv_data;
162  AudioStreamBasicDescription format;
163  UInt32 size = sizeof(format);
164  if (!AudioConverterGetProperty(at->converter,
165  kAudioConverterCurrentInputStreamDescription,
166  &size, &format)) {
167  if (format.mSampleRate)
168  avctx->sample_rate = format.mSampleRate;
169  avctx->channels = format.mChannelsPerFrame;
171  avctx->frame_size = format.mFramesPerPacket;
172  }
173 
174  if (!AudioConverterGetProperty(at->converter,
175  kAudioConverterCurrentOutputStreamDescription,
176  &size, &format)) {
177  format.mSampleRate = avctx->sample_rate;
178  format.mChannelsPerFrame = avctx->channels;
179  AudioConverterSetProperty(at->converter,
180  kAudioConverterCurrentOutputStreamDescription,
181  size, &format);
182  }
183 
184  if (!AudioConverterGetPropertyInfo(at->converter, kAudioConverterOutputChannelLayout,
185  &size, NULL) && size) {
186  AudioChannelLayout *layout = av_malloc(size);
187  uint64_t layout_mask = 0;
188  int i;
189  if (!layout)
190  return AVERROR(ENOMEM);
191  AudioConverterGetProperty(at->converter, kAudioConverterOutputChannelLayout,
192  &size, layout);
193  if (!(layout = ffat_convert_layout(layout, &size)))
194  return AVERROR(ENOMEM);
195  for (i = 0; i < layout->mNumberChannelDescriptions; i++) {
196  int id = ffat_get_channel_id(layout->mChannelDescriptions[i].mChannelLabel);
197  if (id < 0)
198  goto done;
199  if (layout_mask & (1 << id))
200  goto done;
201  layout_mask |= 1 << id;
202  layout->mChannelDescriptions[i].mChannelFlags = i; // Abusing flags as index
203  }
204  avctx->channel_layout = layout_mask;
205  qsort(layout->mChannelDescriptions, layout->mNumberChannelDescriptions,
206  sizeof(AudioChannelDescription), &ffat_compare_channel_descriptions);
207  for (i = 0; i < layout->mNumberChannelDescriptions; i++)
208  at->channel_map[i] = layout->mChannelDescriptions[i].mChannelFlags;
209 done:
210  av_free(layout);
211  }
212 
213  if (!avctx->frame_size)
214  avctx->frame_size = 2048;
215 
216  return 0;
217 }
218 
219 static void put_descr(PutByteContext *pb, int tag, unsigned int size)
220 {
221  int i = 3;
222  bytestream2_put_byte(pb, tag);
223  for (; i > 0; i--)
224  bytestream2_put_byte(pb, (size >> (7 * i)) | 0x80);
225  bytestream2_put_byte(pb, size & 0x7F);
226 }
227 
228 static uint8_t* ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
229 {
230  ATDecodeContext *at = avctx->priv_data;
231  if (avctx->codec_id == AV_CODEC_ID_AAC) {
232  char *extradata;
233  PutByteContext pb;
234  *cookie_size = 5 + 3 + 5+13 + 5+at->extradata_size;
235  if (!(extradata = av_malloc(*cookie_size)))
236  return NULL;
237 
238  bytestream2_init_writer(&pb, extradata, *cookie_size);
239 
240  // ES descriptor
241  put_descr(&pb, 0x03, 3 + 5+13 + 5+at->extradata_size);
242  bytestream2_put_be16(&pb, 0);
243  bytestream2_put_byte(&pb, 0x00); // flags (= no flags)
244 
245  // DecoderConfig descriptor
246  put_descr(&pb, 0x04, 13 + 5+at->extradata_size);
247 
248  // Object type indication
249  bytestream2_put_byte(&pb, 0x40);
250 
251  bytestream2_put_byte(&pb, 0x15); // flags (= Audiostream)
252 
253  bytestream2_put_be24(&pb, 0); // Buffersize DB
254 
255  bytestream2_put_be32(&pb, 0); // maxbitrate
256  bytestream2_put_be32(&pb, 0); // avgbitrate
257 
258  // DecoderSpecific info descriptor
259  put_descr(&pb, 0x05, at->extradata_size);
261  return extradata;
262  } else {
263  *cookie_size = at->extradata_size;
264  return at->extradata;
265  }
266 }
267 
269 {
270  ATDecodeContext *at = avctx->priv_data;
271  return at->extradata_size &&
272  (avctx->codec_id == AV_CODEC_ID_ALAC ||
273  avctx->codec_id == AV_CODEC_ID_QDM2 ||
274  avctx->codec_id == AV_CODEC_ID_QDMC ||
275  avctx->codec_id == AV_CODEC_ID_AAC);
276 }
277 
279 {
280  ATDecodeContext *at = avctx->priv_data;
281  if (ffat_usable_extradata(avctx)) {
282  OSStatus status;
283  UInt32 cookie_size;
284  uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
285  if (!cookie)
286  return AVERROR(ENOMEM);
287 
288  status = AudioConverterSetProperty(at->converter,
289  kAudioConverterDecompressionMagicCookie,
290  cookie_size, cookie);
291  if (status != 0)
292  av_log(avctx, AV_LOG_WARNING, "AudioToolbox cookie error: %i\n", (int)status);
293 
294  if (cookie != at->extradata)
295  av_free(cookie);
296  }
297  return 0;
298 }
299 
301 {
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;
343  if (ff_mpa_decode_header(AV_RB32(pkt->data), &avctx->sample_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, *phdr = &hdr;
355  GetBitContext gbc;
356  init_get_bits(&gbc, pkt->data, pkt->size);
357  if (avpriv_ac3_parse_header(&gbc, &phdr) < 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  at->extradata = avctx->extradata;
403  at->extradata_size = avctx->extradata_size;
404 
405  if ((avctx->channels && avctx->sample_rate) || ffat_usable_extradata(avctx))
406  return ffat_create_decoder(avctx, NULL);
407  else
408  return 0;
409 }
410 
411 static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets,
412  AudioBufferList *data,
413  AudioStreamPacketDescription **packets,
414  void *inctx)
415 {
416  AVCodecContext *avctx = inctx;
417  ATDecodeContext *at = avctx->priv_data;
418 
419  if (at->eof) {
420  *nb_packets = 0;
421  if (packets) {
422  *packets = &at->pkt_desc;
423  at->pkt_desc.mDataByteSize = 0;
424  }
425  return 0;
426  }
427 
428  av_packet_unref(&at->in_pkt);
430 
431  if (!at->in_pkt.data) {
432  *nb_packets = 0;
433  return 1;
434  }
435 
436  data->mNumberBuffers = 1;
437  data->mBuffers[0].mNumberChannels = 0;
438  data->mBuffers[0].mDataByteSize = at->in_pkt.size;
439  data->mBuffers[0].mData = at->in_pkt.data;
440  *nb_packets = 1;
441 
442  if (packets) {
443  *packets = &at->pkt_desc;
444  at->pkt_desc.mDataByteSize = at->in_pkt.size;
445  }
446 
447  return 0;
448 }
449 
450 #define COPY_SAMPLES(type) \
451  type *in_ptr = (type*)at->decoded_data; \
452  type *end_ptr = in_ptr + frame->nb_samples * avctx->channels; \
453  type *out_ptr = (type*)frame->data[0]; \
454  for (; in_ptr < end_ptr; in_ptr += avctx->channels, out_ptr += avctx->channels) { \
455  int c; \
456  for (c = 0; c < avctx->channels; c++) \
457  out_ptr[c] = in_ptr[at->channel_map[c]]; \
458  }
459 
461 {
462  ATDecodeContext *at = avctx->priv_data;
463  if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) {
465  } else {
466  COPY_SAMPLES(int16_t);
467  }
468 }
469 
470 static int ffat_decode(AVCodecContext *avctx, void *data,
471  int *got_frame_ptr, AVPacket *avpkt)
472 {
473  ATDecodeContext *at = avctx->priv_data;
474  AVFrame *frame = data;
475  int pkt_size = avpkt->size;
476  AVPacket filtered_packet = {0};
477  OSStatus ret;
478  AudioBufferList out_buffers;
479 
480  if (avctx->codec_id == AV_CODEC_ID_AAC && avpkt->size > 2 &&
481  (AV_RB16(avpkt->data) & 0xfff0) == 0xfff0) {
482  AVPacket filter_pkt = {0};
483  if (!at->bsf) {
484  const AVBitStreamFilter *bsf = av_bsf_get_by_name("aac_adtstoasc");
485  if(!bsf)
486  return AVERROR_BSF_NOT_FOUND;
487  if ((ret = av_bsf_alloc(bsf, &at->bsf)))
488  return ret;
489  if (((ret = avcodec_parameters_from_context(at->bsf->par_in, avctx)) < 0) ||
490  ((ret = av_bsf_init(at->bsf)) < 0)) {
491  av_bsf_free(&at->bsf);
492  return ret;
493  }
494  }
495 
496  if ((ret = av_packet_ref(&filter_pkt, avpkt)) < 0)
497  return ret;
498 
499  if ((ret = av_bsf_send_packet(at->bsf, &filter_pkt)) < 0) {
500  av_packet_unref(&filter_pkt);
501  return ret;
502  }
503 
504  if ((ret = av_bsf_receive_packet(at->bsf, &filtered_packet)) < 0)
505  return ret;
506 
507  at->extradata = at->bsf->par_out->extradata;
509 
510  avpkt = &filtered_packet;
511  }
512 
513  if (!at->converter) {
514  if ((ret = ffat_create_decoder(avctx, avpkt)) < 0) {
515  av_packet_unref(&filtered_packet);
516  return ret;
517  }
518  }
519 
520  out_buffers = (AudioBufferList){
521  .mNumberBuffers = 1,
522  .mBuffers = {
523  {
524  .mNumberChannels = avctx->channels,
525  .mDataByteSize = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->frame_size
526  * avctx->channels,
527  }
528  }
529  };
530 
532 
533  if (avpkt->size) {
534  if (filtered_packet.data) {
535  at->new_in_pkt = filtered_packet;
536  } else if ((ret = av_packet_ref(&at->new_in_pkt, avpkt)) < 0) {
537  return ret;
538  }
539  } else {
540  at->eof = 1;
541  }
542 
543  frame->sample_rate = avctx->sample_rate;
544 
545  frame->nb_samples = avctx->frame_size;
546 
547  out_buffers.mBuffers[0].mData = at->decoded_data;
548 
549  ret = AudioConverterFillComplexBuffer(at->converter, ffat_decode_callback, avctx,
550  &frame->nb_samples, &out_buffers, NULL);
551  if ((!ret || ret == 1) && frame->nb_samples) {
552  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
553  return ret;
554  ffat_copy_samples(avctx, frame);
555  *got_frame_ptr = 1;
556  if (at->last_pts != AV_NOPTS_VALUE) {
557  frame->pkt_pts = at->last_pts;
558  at->last_pts = avpkt->pts;
559  }
560  } else if (ret && ret != 1) {
561  av_log(avctx, AV_LOG_WARNING, "Decode error: %i\n", ret);
562  } else {
563  at->last_pts = avpkt->pts;
564  }
565 
566  return pkt_size;
567 }
568 
570 {
571  ATDecodeContext *at = avctx->priv_data;
572  AudioConverterReset(at->converter);
574  av_packet_unref(&at->in_pkt);
575 }
576 
578 {
579  ATDecodeContext *at = avctx->priv_data;
580  AudioConverterDispose(at->converter);
581  av_bsf_free(&at->bsf);
583  av_packet_unref(&at->in_pkt);
584  av_free(at->decoded_data);
585  return 0;
586 }
587 
588 #define FFAT_DEC_CLASS(NAME) \
589  static const AVClass ffat_##NAME##_dec_class = { \
590  .class_name = "at_" #NAME "_dec", \
591  .version = LIBAVUTIL_VERSION_INT, \
592  };
593 
594 #define FFAT_DEC(NAME, ID) \
595  FFAT_DEC_CLASS(NAME) \
596  AVCodec ff_##NAME##_at_decoder = { \
597  .name = #NAME "_at", \
598  .long_name = NULL_IF_CONFIG_SMALL(#NAME " (AudioToolbox)"), \
599  .type = AVMEDIA_TYPE_AUDIO, \
600  .id = ID, \
601  .priv_data_size = sizeof(ATDecodeContext), \
602  .init = ffat_init_decoder, \
603  .close = ffat_close_decoder, \
604  .decode = ffat_decode, \
605  .flush = ffat_decode_flush, \
606  .priv_class = &ffat_##NAME##_dec_class, \
607  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, \
608  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, \
609  };
610 
613 FFAT_DEC(adpcm_ima_qt, AV_CODEC_ID_ADPCM_IMA_QT)
static uint8_t * ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
void av_bsf_free(AVBSFContext **ctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:33
#define NULL
Definition: coverity.c:32
uint8_t * extradata
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
enum AVCodecID codec_id
Definition: ffmpeg_vaapi.c:149
AVCodecParameters * par_out
Parameters of the output stream.
Definition: avcodec.h:5708
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
enum AVCodecID id
Definition: mxfenc.c:104
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1714
The bitstream filter state.
Definition: avcodec.h:5677
int size
Definition: avcodec.h:1581
const char * b
Definition: vf_curves.c:109
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:143
static av_cold int ffat_create_decoder(AVCodecContext *avctx, AVPacket *pkt)
#define AV_CH_LOW_FREQUENCY_2
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
static AVPacket pkt
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:3049
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_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:87
int profile
profile
Definition: avcodec.h:3153
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2447
AVBSFContext * bsf
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:132
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx)
Allocate a context for a given bitstream filter.
Definition: bsf.c:79
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:194
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2418
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
AVOptions.
#define COPY_SAMPLES(type)
static AudioChannelLayout * ffat_convert_layout(AudioChannelLayout *layout, UInt32 *size)
AVClass * av_class
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1764
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:87
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1580
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:617
uint32_t tag
Definition: movenc.c:1367
static av_cold void ffat_decode_flush(AVCodecContext *avctx)
ptrdiff_t size
Definition: opengl_enc.c:101
static void put_descr(PutByteContext *pb, int tag, unsigned int size)
signed 32 bits
Definition: samplefmt.h:62
#define av_log(a,...)
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:572
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:189
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:515
simple assert() macros that are a bit more flexible than ISO C assert().
Coded AC-3 header values up to the lfeon element, plus derived values.
Definition: ac3.h:176
uint16_t sample_rate
Definition: ac3.h:200
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2461
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3940
static int ffat_get_channel_id(AudioChannelLabel label)
static int ffat_update_ctx(AVCodecContext *avctx)
#define ff_ctzll
Definition: intmath.h:126
uint32_t bit_rate
Definition: ac3.h:201
static av_cold int ffat_usable_extradata(AVCodecContext *avctx)
AudioStreamPacketDescription pkt_desc
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:173
int32_t
AudioConverterRef converter
#define AVERROR_BSF_NOT_FOUND
Bitstream filter not found.
Definition: error.h:49
#define AV_CH_FRONT_CENTER
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:282
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2430
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
enum AVCodecID codec_id
Definition: avcodec.h:1666
int sample_rate
samples per second
Definition: avcodec.h:2410
static av_cold int ffat_init_decoder(AVCodecContext *avctx)
main external API structure.
Definition: avcodec.h:1649
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:563
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:928
static int ffat_set_extradata(AVCodecContext *avctx)
int extradata_size
Definition: avcodec.h:1765
static const char * format
Definition: movenc.c:47
Describe the class of an AVClass context structure.
Definition: log.h:67
int sample_rate
Sample rate of the audio data.
Definition: frame.h:344
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: utils.c:4077
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:406
mfxU16 profile
Definition: qsvenc.c:42
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:273
#define kAudioFormatEnhancedAC3
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:104
MPEG Audio header decoder.
static int ffat_decode(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
common internal api header.
signed 16 bits
Definition: samplefmt.h:61
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
void * priv_data
Definition: avcodec.h:1691
static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets, AudioBufferList *data, AudioStreamPacketDescription **packets, void *inctx)
int ff_mpa_decode_header(uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate, enum AVCodecID *codec_id)
#define av_free(p)
int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo **phdr)
Parse AC-3 frame header.
Definition: ac3_parser.c:50
int channels
number of audio channels
Definition: avcodec.h:2411
uint8_t channels
Definition: ac3.h:202
uint64_t layout
static int ffat_compare_channel_descriptions(const void *a, const void *b)
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3936
static av_cold int ffat_close_decoder(AVCodecContext *avctx)
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile)
int num_blocks
number of audio blocks
Definition: ac3.h:192
static void ffat_copy_samples(AVCodecContext *avctx, AVFrame *frame)
This structure stores compressed data.
Definition: avcodec.h:1557
AVCodecParameters * par_in
Parameters of the input stream.
Definition: avcodec.h:5703
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:241
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1573
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240
#define FFAT_DEC(NAME, ID)