FFmpeg  4.4.9
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 
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 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
72  case AV_CODEC_ID_GSM_MS:
73  return kAudioFormatMicrosoftGSM;
74  case AV_CODEC_ID_ILBC:
75  return kAudioFormatiLBC;
76 #endif
77  case AV_CODEC_ID_MP1:
78  return kAudioFormatMPEGLayer1;
79  case AV_CODEC_ID_MP2:
80  return kAudioFormatMPEGLayer2;
81  case AV_CODEC_ID_MP3:
82  return kAudioFormatMPEGLayer3;
84  return kAudioFormatALaw;
86  return kAudioFormatULaw;
87  case AV_CODEC_ID_QDMC:
88  return kAudioFormatQDesign;
89  case AV_CODEC_ID_QDM2:
90  return kAudioFormatQDesign2;
91  default:
92  av_assert0(!"Invalid codec ID!");
93  return 0;
94  }
95 }
96 
97 static int ffat_get_channel_id(AudioChannelLabel label)
98 {
99  if (label == 0)
100  return -1;
101  else if (label <= kAudioChannelLabel_LFEScreen)
102  return label - 1;
103  else if (label <= kAudioChannelLabel_RightSurround)
104  return label + 4;
105  else if (label <= kAudioChannelLabel_CenterSurround)
106  return label + 1;
107  else if (label <= kAudioChannelLabel_RightSurroundDirect)
108  return label + 23;
109  else if (label <= kAudioChannelLabel_TopBackRight)
110  return label - 1;
111  else if (label < kAudioChannelLabel_RearSurroundLeft)
112  return -1;
113  else if (label <= kAudioChannelLabel_RearSurroundRight)
114  return label - 29;
115  else if (label <= kAudioChannelLabel_RightWide)
116  return label - 4;
117  else if (label == kAudioChannelLabel_LFE2)
119  else if (label == kAudioChannelLabel_Mono)
121  else
122  return -1;
123 }
124 
125 static int ffat_compare_channel_descriptions(const void* a, const void* b)
126 {
127  const AudioChannelDescription* da = a;
128  const AudioChannelDescription* db = b;
129  return ffat_get_channel_id(da->mChannelLabel) - ffat_get_channel_id(db->mChannelLabel);
130 }
131 
132 static AudioChannelLayout *ffat_convert_layout(AudioChannelLayout *layout, UInt32* size)
133 {
134  AudioChannelLayoutTag tag = layout->mChannelLayoutTag;
135  AudioChannelLayout *new_layout;
136  if (tag == kAudioChannelLayoutTag_UseChannelDescriptions)
137  return layout;
138  else if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
139  AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
140  sizeof(UInt32), &layout->mChannelBitmap, size);
141  else
142  AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
143  sizeof(AudioChannelLayoutTag), &tag, size);
144  new_layout = av_malloc(*size);
145  if (!new_layout) {
146  av_free(layout);
147  return NULL;
148  }
149  if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
150  AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
151  sizeof(UInt32), &layout->mChannelBitmap, size, new_layout);
152  else
153  AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
154  sizeof(AudioChannelLayoutTag), &tag, size, new_layout);
155  new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
156  av_free(layout);
157  return new_layout;
158 }
159 
160 static int ffat_update_ctx(AVCodecContext *avctx)
161 {
162  ATDecodeContext *at = avctx->priv_data;
163  AudioStreamBasicDescription format;
164  UInt32 size = sizeof(format);
165  if (!AudioConverterGetProperty(at->converter,
166  kAudioConverterCurrentInputStreamDescription,
167  &size, &format)) {
168  if (format.mSampleRate)
169  avctx->sample_rate = format.mSampleRate;
170  avctx->channels = format.mChannelsPerFrame;
172  avctx->frame_size = format.mFramesPerPacket;
173  }
174 
175  if (!AudioConverterGetProperty(at->converter,
176  kAudioConverterCurrentOutputStreamDescription,
177  &size, &format)) {
178  format.mSampleRate = avctx->sample_rate;
179  format.mChannelsPerFrame = avctx->channels;
180  AudioConverterSetProperty(at->converter,
181  kAudioConverterCurrentOutputStreamDescription,
182  size, &format);
183  }
184 
185  if (!AudioConverterGetPropertyInfo(at->converter, kAudioConverterOutputChannelLayout,
186  &size, NULL) && size) {
187  AudioChannelLayout *layout = av_malloc(size);
188  uint64_t layout_mask = 0;
189  int i;
190  if (!layout)
191  return AVERROR(ENOMEM);
192  AudioConverterGetProperty(at->converter, kAudioConverterOutputChannelLayout,
193  &size, layout);
195  return AVERROR(ENOMEM);
196  for (i = 0; i < layout->mNumberChannelDescriptions; i++) {
197  int id = ffat_get_channel_id(layout->mChannelDescriptions[i].mChannelLabel);
198  if (id < 0)
199  goto done;
200  if (layout_mask & (1ULL << id))
201  goto done;
202  layout_mask |= 1ULL << id;
203  layout->mChannelDescriptions[i].mChannelFlags = i; // Abusing flags as index
204  }
205  avctx->channel_layout = layout_mask;
206  qsort(layout->mChannelDescriptions, layout->mNumberChannelDescriptions,
207  sizeof(AudioChannelDescription), &ffat_compare_channel_descriptions);
208  for (i = 0; i < layout->mNumberChannelDescriptions; i++)
209  at->channel_map[i] = layout->mChannelDescriptions[i].mChannelFlags;
210 done:
211  av_free(layout);
212  }
213 
214  if (!avctx->frame_size)
215  avctx->frame_size = 2048;
216 
217  return 0;
218 }
219 
220 static void put_descr(PutByteContext *pb, int tag, unsigned int size)
221 {
222  int i = 3;
223  bytestream2_put_byte(pb, tag);
224  for (; i > 0; i--)
225  bytestream2_put_byte(pb, (size >> (7 * i)) | 0x80);
226  bytestream2_put_byte(pb, size & 0x7F);
227 }
228 
229 static uint8_t* ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
230 {
231  ATDecodeContext *at = avctx->priv_data;
232  if (avctx->codec_id == AV_CODEC_ID_AAC) {
233  char *extradata;
234  PutByteContext pb;
235  *cookie_size = 5 + 3 + 5+13 + 5+at->extradata_size;
236  if (!(extradata = av_malloc(*cookie_size)))
237  return NULL;
238 
239  bytestream2_init_writer(&pb, extradata, *cookie_size);
240 
241  // ES descriptor
242  put_descr(&pb, 0x03, 3 + 5+13 + 5+at->extradata_size);
243  bytestream2_put_be16(&pb, 0);
244  bytestream2_put_byte(&pb, 0x00); // flags (= no flags)
245 
246  // DecoderConfig descriptor
247  put_descr(&pb, 0x04, 13 + 5+at->extradata_size);
248 
249  // Object type indication
250  bytestream2_put_byte(&pb, 0x40);
251 
252  bytestream2_put_byte(&pb, 0x15); // flags (= Audiostream)
253 
254  bytestream2_put_be24(&pb, 0); // Buffersize DB
255 
256  bytestream2_put_be32(&pb, 0); // maxbitrate
257  bytestream2_put_be32(&pb, 0); // avgbitrate
258 
259  // DecoderSpecific info descriptor
260  put_descr(&pb, 0x05, at->extradata_size);
262  return extradata;
263  } else {
264  *cookie_size = at->extradata_size;
265  return at->extradata;
266  }
267 }
268 
270 {
271  ATDecodeContext *at = avctx->priv_data;
272  return at->extradata_size &&
273  (avctx->codec_id == AV_CODEC_ID_ALAC ||
274  avctx->codec_id == AV_CODEC_ID_QDM2 ||
275  avctx->codec_id == AV_CODEC_ID_QDMC ||
276  avctx->codec_id == AV_CODEC_ID_AAC);
277 }
278 
280 {
281  ATDecodeContext *at = avctx->priv_data;
282  if (ffat_usable_extradata(avctx)) {
283  OSStatus status;
284  UInt32 cookie_size;
285  uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
286  if (!cookie)
287  return AVERROR(ENOMEM);
288 
289  status = AudioConverterSetProperty(at->converter,
290  kAudioConverterDecompressionMagicCookie,
291  cookie_size, cookie);
292  if (status != 0)
293  av_log(avctx, AV_LOG_WARNING, "AudioToolbox cookie error: %i\n", (int)status);
294 
295  if (cookie != at->extradata)
296  av_free(cookie);
297  }
298  return 0;
299 }
300 
302  const AVPacket *pkt)
303 {
304  ATDecodeContext *at = avctx->priv_data;
305  OSStatus status;
306  int i;
307 
308  enum AVSampleFormat sample_fmt = (avctx->bits_per_raw_sample == 32) ?
310 
311  AudioStreamBasicDescription in_format = {
312  .mFormatID = ffat_get_format_id(avctx->codec_id, avctx->profile),
313  .mBytesPerPacket = (avctx->codec_id == AV_CODEC_ID_ILBC) ? avctx->block_align : 0,
314  };
315  AudioStreamBasicDescription out_format = {
316  .mFormatID = kAudioFormatLinearPCM,
317  .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
318  .mFramesPerPacket = 1,
319  .mBitsPerChannel = av_get_bytes_per_sample(sample_fmt) * 8,
320  };
321 
322  avctx->sample_fmt = sample_fmt;
323 
324  if (ffat_usable_extradata(avctx)) {
325  UInt32 format_size = sizeof(in_format);
326  UInt32 cookie_size;
327  uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
328  if (!cookie)
329  return AVERROR(ENOMEM);
330  status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
331  cookie_size, cookie, &format_size, &in_format);
332  if (cookie != at->extradata)
333  av_free(cookie);
334  if (status != 0) {
335  av_log(avctx, AV_LOG_ERROR, "AudioToolbox header-parse error: %i\n", (int)status);
336  return AVERROR_UNKNOWN;
337  }
338 #if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
339  } else if (pkt && pkt->size >= 4 &&
340  (avctx->codec_id == AV_CODEC_ID_MP1 ||
341  avctx->codec_id == AV_CODEC_ID_MP2 ||
342  avctx->codec_id == AV_CODEC_ID_MP3)) {
343  enum AVCodecID codec_id;
344  int bit_rate;
346  &in_format.mChannelsPerFrame, &avctx->frame_size,
347  &bit_rate, &codec_id) < 0)
348  return AVERROR_INVALIDDATA;
349  avctx->bit_rate = bit_rate;
350  in_format.mSampleRate = avctx->sample_rate;
351 #endif
352 #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
353  } else if (pkt && pkt->size >= 7 &&
354  (avctx->codec_id == AV_CODEC_ID_AC3 ||
355  avctx->codec_id == AV_CODEC_ID_EAC3)) {
356  AC3HeaderInfo hdr;
357  GetBitContext gbc;
358  init_get_bits8(&gbc, pkt->data, pkt->size);
359  if (ff_ac3_parse_header(&gbc, &hdr) < 0)
360  return AVERROR_INVALIDDATA;
361  in_format.mSampleRate = hdr.sample_rate;
362  in_format.mChannelsPerFrame = hdr.channels;
363  avctx->frame_size = hdr.num_blocks * 256;
364  avctx->bit_rate = hdr.bit_rate;
365 #endif
366  } else {
367  in_format.mSampleRate = avctx->sample_rate ? avctx->sample_rate : 44100;
368  in_format.mChannelsPerFrame = avctx->channels ? avctx->channels : 1;
369  }
370 
371  avctx->sample_rate = out_format.mSampleRate = in_format.mSampleRate;
372  avctx->channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
373 
374  if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_QT)
375  in_format.mFramesPerPacket = 64;
376 
377  status = AudioConverterNew(&in_format, &out_format, &at->converter);
378 
379  if (status != 0) {
380  av_log(avctx, AV_LOG_ERROR, "AudioToolbox init error: %i\n", (int)status);
381  return AVERROR_UNKNOWN;
382  }
383 
384  if ((status = ffat_set_extradata(avctx)) < 0)
385  return status;
386 
387  for (i = 0; i < (sizeof(at->channel_map) / sizeof(at->channel_map[0])); i++)
388  at->channel_map[i] = i;
389 
390  ffat_update_ctx(avctx);
391 
393  * avctx->frame_size * avctx->channels)))
394  return AVERROR(ENOMEM);
395 
396  at->last_pts = AV_NOPTS_VALUE;
397 
398  return 0;
399 }
400 
402 {
403  ATDecodeContext *at = avctx->priv_data;
404  if (avctx->extradata_size) {
406  if (!at->extradata)
407  return AVERROR(ENOMEM);
408  at->extradata_size = avctx->extradata_size;
409  memcpy(at->extradata, avctx->extradata, avctx->extradata_size);
410  }
411 
412  if ((avctx->channels && avctx->sample_rate) || ffat_usable_extradata(avctx))
413  return ffat_create_decoder(avctx, NULL);
414  else
415  return 0;
416 }
417 
418 static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets,
419  AudioBufferList *data,
420  AudioStreamPacketDescription **packets,
421  void *inctx)
422 {
423  AVCodecContext *avctx = inctx;
424  ATDecodeContext *at = avctx->priv_data;
425 
426  if (at->eof) {
427  *nb_packets = 0;
428  if (packets) {
429  *packets = &at->pkt_desc;
430  at->pkt_desc.mDataByteSize = 0;
431  }
432  return 0;
433  }
434 
435  av_packet_unref(&at->in_pkt);
437 
438  if (!at->in_pkt.data) {
439  *nb_packets = 0;
440  return 1;
441  }
442 
443  data->mNumberBuffers = 1;
444  data->mBuffers[0].mNumberChannels = 0;
445  data->mBuffers[0].mDataByteSize = at->in_pkt.size;
446  data->mBuffers[0].mData = at->in_pkt.data;
447  *nb_packets = 1;
448 
449  if (packets) {
450  *packets = &at->pkt_desc;
451  at->pkt_desc.mDataByteSize = at->in_pkt.size;
452  }
453 
454  return 0;
455 }
456 
457 #define COPY_SAMPLES(type) \
458  type *in_ptr = (type*)at->decoded_data; \
459  type *end_ptr = in_ptr + frame->nb_samples * avctx->channels; \
460  type *out_ptr = (type*)frame->data[0]; \
461  for (; in_ptr < end_ptr; in_ptr += avctx->channels, out_ptr += avctx->channels) { \
462  int c; \
463  for (c = 0; c < avctx->channels; c++) \
464  out_ptr[c] = in_ptr[at->channel_map[c]]; \
465  }
466 
468 {
469  ATDecodeContext *at = avctx->priv_data;
470  if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) {
472  } else {
473  COPY_SAMPLES(int16_t);
474  }
475 }
476 
477 static int ffat_decode(AVCodecContext *avctx, void *data,
478  int *got_frame_ptr, AVPacket *avpkt)
479 {
480  ATDecodeContext *at = avctx->priv_data;
481  AVFrame *frame = data;
482  int pkt_size = avpkt->size;
483  OSStatus ret;
484  AudioBufferList out_buffers;
485 
486  if (avctx->codec_id == AV_CODEC_ID_AAC) {
487  if (!at->extradata_size) {
488  uint8_t *side_data;
489  buffer_size_t side_data_size;
490 
492  &side_data_size);
493  if (side_data_size) {
494  at->extradata = av_mallocz(side_data_size + AV_INPUT_BUFFER_PADDING_SIZE);
495  if (!at->extradata)
496  return AVERROR(ENOMEM);
497  at->extradata_size = side_data_size;
498  memcpy(at->extradata, side_data, side_data_size);
499  }
500  }
501  }
502 
503  if (!at->converter) {
504  if ((ret = ffat_create_decoder(avctx, avpkt)) < 0) {
505  return ret;
506  }
507  }
508 
509  out_buffers = (AudioBufferList){
510  .mNumberBuffers = 1,
511  .mBuffers = {
512  {
513  .mNumberChannels = avctx->channels,
514  .mDataByteSize = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->frame_size
515  * avctx->channels,
516  }
517  }
518  };
519 
521 
522  if (avpkt->size) {
523  if ((ret = av_packet_ref(&at->new_in_pkt, avpkt)) < 0) {
524  return ret;
525  }
526  } else {
527  at->eof = 1;
528  }
529 
530  frame->sample_rate = avctx->sample_rate;
531 
532  frame->nb_samples = avctx->frame_size;
533 
534  out_buffers.mBuffers[0].mData = at->decoded_data;
535 
536  ret = AudioConverterFillComplexBuffer(at->converter, ffat_decode_callback, avctx,
537  &frame->nb_samples, &out_buffers, NULL);
538  if ((!ret || ret == 1) && frame->nb_samples) {
539  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
540  return ret;
541  ffat_copy_samples(avctx, frame);
542  *got_frame_ptr = 1;
543  if (at->last_pts != AV_NOPTS_VALUE) {
544  frame->pts = at->last_pts;
545 #if FF_API_PKT_PTS
547  frame->pkt_pts = at->last_pts;
549 #endif
550  at->last_pts = avpkt->pts;
551  }
552  } else if (ret && ret != 1) {
553  av_log(avctx, AV_LOG_WARNING, "Decode error: %i\n", ret);
554  } else {
555  at->last_pts = avpkt->pts;
556  }
557 
558  return pkt_size;
559 }
560 
562 {
563  ATDecodeContext *at = avctx->priv_data;
564  AudioConverterReset(at->converter);
566  av_packet_unref(&at->in_pkt);
567 }
568 
570 {
571  ATDecodeContext *at = avctx->priv_data;
572  if (at->converter)
573  AudioConverterDispose(at->converter);
575  av_packet_unref(&at->in_pkt);
576  av_freep(&at->decoded_data);
577  av_freep(&at->extradata);
578  return 0;
579 }
580 
581 #define FFAT_DEC_CLASS(NAME) \
582  static const AVClass ffat_##NAME##_dec_class = { \
583  .class_name = "at_" #NAME "_dec", \
584  .version = LIBAVUTIL_VERSION_INT, \
585  };
586 
587 #define FFAT_DEC(NAME, ID, bsf_name) \
588  FFAT_DEC_CLASS(NAME) \
589  AVCodec ff_##NAME##_at_decoder = { \
590  .name = #NAME "_at", \
591  .long_name = NULL_IF_CONFIG_SMALL(#NAME " (AudioToolbox)"), \
592  .type = AVMEDIA_TYPE_AUDIO, \
593  .id = ID, \
594  .priv_data_size = sizeof(ATDecodeContext), \
595  .init = ffat_init_decoder, \
596  .close = ffat_close_decoder, \
597  .decode = ffat_decode, \
598  .flush = ffat_decode_flush, \
599  .priv_class = &ffat_##NAME##_dec_class, \
600  .bsfs = bsf_name, \
601  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_CHANNEL_CONF, \
602  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, \
603  .wrapper_name = "at", \
604  };
605 
606 FFAT_DEC(aac, AV_CODEC_ID_AAC, "aac_adtstoasc")
608 FFAT_DEC(adpcm_ima_qt, AV_CODEC_ID_ADPCM_IMA_QT, NULL)
int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
Parse AC-3 frame header.
static const char *const format[]
Definition: af_aiir.c:457
#define av_cold
Definition: attributes.h:88
uint8_t
int32_t
static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets, AudioBufferList *data, AudioStreamPacketDescription **packets, void *inctx)
#define COPY_SAMPLES(type)
static AudioChannelLayout * ffat_convert_layout(AudioChannelLayout *layout, UInt32 *size)
static av_cold int ffat_usable_extradata(AVCodecContext *avctx)
static av_cold int ffat_create_decoder(AVCodecContext *avctx, const AVPacket *pkt)
static av_cold void ffat_decode_flush(AVCodecContext *avctx)
static av_cold int ffat_close_decoder(AVCodecContext *avctx)
static int ffat_update_ctx(AVCodecContext *avctx)
static int ffat_set_extradata(AVCodecContext *avctx)
static int ffat_get_channel_id(AudioChannelLabel label)
static void ffat_copy_samples(AVCodecContext *avctx, AVFrame *frame)
#define kAudioFormatEnhancedAC3
static int ffat_compare_channel_descriptions(const void *a, const void *b)
static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile)
static av_cold int ffat_init_decoder(AVCodecContext *avctx)
#define FFAT_DEC(NAME, ID, bsf_name)
static uint8_t * ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
static int ffat_decode(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static void put_descr(PutByteContext *pb, int tag, unsigned int size)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Libavcodec external API header.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t *size)
Definition: avpacket.c:368
#define AV_RB32
Definition: intreadwrite.h:130
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:147
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:286
uint64_t layout
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1911
static AVFrame * frame
enum AVCodecID id
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:677
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
#define AV_CH_LOW_FREQUENCY_2
#define AV_CH_FRONT_CENTER
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:46
@ AV_CODEC_ID_EAC3
Definition: codec_id.h:464
@ AV_CODEC_ID_MP1
Definition: codec_id.h:466
@ AV_CODEC_ID_GSM_MS
Definition: codec_id.h:454
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:320
@ AV_CODEC_ID_ALAC
Definition: codec_id.h:440
@ AV_CODEC_ID_AMR_NB
Definition: codec_id.h:406
@ AV_CODEC_ID_MP2
Definition: codec_id.h:424
@ AV_CODEC_ID_ADPCM_IMA_QT
Definition: codec_id.h:353
@ AV_CODEC_ID_AAC
Definition: codec_id.h:426
@ AV_CODEC_ID_AC3
Definition: codec_id.h:427
@ AV_CODEC_ID_QDM2
Definition: codec_id.h:443
@ AV_CODEC_ID_ILBC
Definition: codec_id.h:483
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:425
@ AV_CODEC_ID_QDMC
Definition: codec_id.h:474
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:319
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition: avcodec.h:215
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:634
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:690
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_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
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
#define ff_ctzll
Definition: intmath.h:126
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
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:62
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
int i
Definition: input.c:407
common internal API header
int buffer_size_t
Definition: internal.h:306
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
uint32_t tag
Definition: movenc.c:1611
int ff_mpa_decode_header(uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate, enum AVCodecID *codec_id)
MPEG Audio header decoder.
const char data[16]
Definition: mxf.c:142
AVOptions.
mfxU16 profile
Definition: qsvenc.c:45
Coded AC-3 header values up to the lfeon element, plus derived values.
Definition: ac3.h:178
uint8_t channels
Definition: ac3.h:204
int num_blocks
number of audio blocks
Definition: ac3.h:194
uint16_t sample_rate
Definition: ac3.h:202
uint32_t bit_rate
Definition: ac3.h:203
AudioConverterRef converter
AVClass * av_class
uint8_t * extradata
AudioStreamPacketDescription pkt_desc
Describe the class of an AVClass context structure.
Definition: log.h:67
main external API structure.
Definition: avcodec.h:536
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1204
int64_t bit_rate
the average bitrate
Definition: avcodec.h:586
int profile
profile
Definition: avcodec.h:1862
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1751
int sample_rate
samples per second
Definition: avcodec.h:1196
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:637
int channels
number of audio channels
Definition: avcodec.h:1197
enum AVCodecID codec_id
Definition: avcodec.h:546
int extradata_size
Definition: avcodec.h:638
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
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1247
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1216
void * priv_data
Definition: avcodec.h:563
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:384
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:419
int sample_rate
Sample rate of the audio data.
Definition: frame.h:490
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
uint8_t * data
Definition: packet.h:369
#define av_free(p)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
AVPacket * pkt
Definition: movenc.c:59
int size
enum AVCodecID codec_id
Definition: vaapi_decode.c:374
const char * b
Definition: vf_curves.c:119