23 #include <AudioToolbox/AudioToolbox.h>
35 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
36 #define kAudioFormatEnhancedAC3 'ec-3'
60 return kAudioFormatMPEG4AAC;
62 return kAudioFormatAC3;
64 return kAudioFormatAppleIMA4;
66 return kAudioFormatAppleLossless;
68 return kAudioFormatAMR;
71 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
73 return kAudioFormatMicrosoftGSM;
75 return kAudioFormatiLBC;
78 return kAudioFormatMPEGLayer1;
80 return kAudioFormatMPEGLayer2;
82 return kAudioFormatMPEGLayer3;
84 return kAudioFormatALaw;
86 return kAudioFormatULaw;
88 return kAudioFormatQDesign;
90 return kAudioFormatQDesign2;
101 else if (label <= kAudioChannelLabel_LFEScreen)
103 else if (label <= kAudioChannelLabel_RightSurround)
105 else if (label <= kAudioChannelLabel_CenterSurround)
107 else if (label <= kAudioChannelLabel_RightSurroundDirect)
109 else if (label <= kAudioChannelLabel_TopBackRight)
111 else if (label < kAudioChannelLabel_RearSurroundLeft)
113 else if (label <= kAudioChannelLabel_RearSurroundRight)
115 else if (label <= kAudioChannelLabel_RightWide)
117 else if (label == kAudioChannelLabel_LFE2)
119 else if (label == kAudioChannelLabel_Mono)
127 const AudioChannelDescription* da =
a;
128 const AudioChannelDescription* db =
b;
134 AudioChannelLayoutTag
tag =
layout->mChannelLayoutTag;
135 AudioChannelLayout *new_layout;
136 if (
tag == kAudioChannelLayoutTag_UseChannelDescriptions)
138 else if (
tag == kAudioChannelLayoutTag_UseChannelBitmap)
139 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
140 sizeof(UInt32), &
layout->mChannelBitmap,
size);
142 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
143 sizeof(AudioChannelLayoutTag), &
tag,
size);
149 if (
tag == kAudioChannelLayoutTag_UseChannelBitmap)
150 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
151 sizeof(UInt32), &
layout->mChannelBitmap,
size, new_layout);
153 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
154 sizeof(AudioChannelLayoutTag), &
tag,
size, new_layout);
155 new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
163 AudioStreamBasicDescription
format;
165 if (!AudioConverterGetProperty(at->
converter,
166 kAudioConverterCurrentInputStreamDescription,
175 if (!AudioConverterGetProperty(at->
converter,
176 kAudioConverterCurrentOutputStreamDescription,
181 kAudioConverterCurrentOutputStreamDescription,
185 if (!AudioConverterGetPropertyInfo(at->
converter, kAudioConverterOutputChannelLayout,
188 uint64_t layout_mask = 0;
192 AudioConverterGetProperty(at->
converter, kAudioConverterOutputChannelLayout,
196 for (
i = 0;
i <
layout->mNumberChannelDescriptions;
i++) {
200 if (layout_mask & (1ULL <<
id))
202 layout_mask |= 1ULL <<
id;
203 layout->mChannelDescriptions[
i].mChannelFlags =
i;
206 qsort(
layout->mChannelDescriptions,
layout->mNumberChannelDescriptions,
208 for (
i = 0;
i <
layout->mNumberChannelDescriptions;
i++)
223 bytestream2_put_byte(pb,
tag);
225 bytestream2_put_byte(pb, (
size >> (7 *
i)) | 0x80);
226 bytestream2_put_byte(pb,
size & 0x7F);
236 if (!(extradata =
av_malloc(*cookie_size)))
243 bytestream2_put_be16(&pb, 0);
244 bytestream2_put_byte(&pb, 0x00);
250 bytestream2_put_byte(&pb, 0x40);
252 bytestream2_put_byte(&pb, 0x15);
254 bytestream2_put_be24(&pb, 0);
256 bytestream2_put_be32(&pb, 0);
257 bytestream2_put_be32(&pb, 0);
289 status = AudioConverterSetProperty(at->
converter,
290 kAudioConverterDecompressionMagicCookie,
291 cookie_size, cookie);
311 AudioStreamBasicDescription in_format = {
315 AudioStreamBasicDescription out_format = {
316 .mFormatID = kAudioFormatLinearPCM,
317 .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
318 .mFramesPerPacket = 1,
325 UInt32 format_size =
sizeof(in_format);
330 status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
331 cookie_size, cookie, &format_size, &in_format);
338 #if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
346 &in_format.mChannelsPerFrame, &avctx->
frame_size,
352 #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
362 in_format.mChannelsPerFrame = hdr.
channels;
371 avctx->
sample_rate = out_format.mSampleRate = in_format.mSampleRate;
372 avctx->
channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
375 in_format.mFramesPerPacket = 64;
377 status = AudioConverterNew(&in_format, &out_format, &at->
converter);
419 AudioBufferList *
data,
420 AudioStreamPacketDescription **packets,
443 data->mNumberBuffers = 1;
444 data->mBuffers[0].mNumberChannels = 0;
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) { \
463 for (c = 0; c < avctx->channels; c++) \
464 out_ptr[c] = in_ptr[at->channel_map[c]]; \
478 int *got_frame_ptr,
AVPacket *avpkt)
482 int pkt_size = avpkt->
size;
484 AudioBufferList out_buffers;
493 if (side_data_size) {
498 memcpy(at->
extradata, side_data, side_data_size);
509 out_buffers = (AudioBufferList){
552 }
else if (ret && ret != 1) {
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, \
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, \
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, \
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", \
int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
Parse AC-3 frame header.
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t *size)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
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.
@ AV_CODEC_ID_ADPCM_IMA_QT
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
@ 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...
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define AV_NOPTS_VALUE
Undefined timestamp value.
common internal API header
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
AudioConverterRef converter
AudioStreamPacketDescription pkt_desc
Describe the class of an AVClass context structure.
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int64_t bit_rate
the average bitrate
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int sample_rate
samples per second
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
uint64_t channel_layout
Audio channel layout.
int frame_size
Number of samples per channel in an audio frame.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
int sample_rate
Sample rate of the audio data.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...