23 #include <AudioToolbox/AudioToolbox.h>
26 #include "config_components.h"
38 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
39 #define kAudioFormatEnhancedAC3 'ec-3'
63 return kAudioFormatMPEG4AAC;
65 return kAudioFormatAC3;
67 return kAudioFormatAppleIMA4;
69 return kAudioFormatAppleLossless;
71 return kAudioFormatAMR;
75 return kAudioFormatMicrosoftGSM;
77 return kAudioFormatiLBC;
79 return kAudioFormatMPEGLayer1;
81 return kAudioFormatMPEGLayer2;
83 return kAudioFormatMPEGLayer3;
85 return kAudioFormatALaw;
87 return kAudioFormatULaw;
89 return kAudioFormatQDesign;
91 return kAudioFormatQDesign2;
102 else if (label <= kAudioChannelLabel_LFEScreen)
104 else if (label <= kAudioChannelLabel_RightSurround)
106 else if (label <= kAudioChannelLabel_CenterSurround)
108 else if (label <= kAudioChannelLabel_RightSurroundDirect)
110 else if (label <= kAudioChannelLabel_TopBackRight)
112 else if (label < kAudioChannelLabel_RearSurroundLeft)
114 else if (label <= kAudioChannelLabel_RearSurroundRight)
116 else if (label <= kAudioChannelLabel_RightWide)
118 else if (label == kAudioChannelLabel_LFE2)
120 else if (label == kAudioChannelLabel_Mono)
128 const AudioChannelDescription* da =
a;
129 const AudioChannelDescription* db =
b;
135 AudioChannelLayoutTag
tag =
layout->mChannelLayoutTag;
136 AudioChannelLayout *new_layout;
137 if (
tag == kAudioChannelLayoutTag_UseChannelDescriptions)
139 else if (
tag == kAudioChannelLayoutTag_UseChannelBitmap)
140 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
141 sizeof(UInt32), &
layout->mChannelBitmap,
size);
143 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
144 sizeof(AudioChannelLayoutTag), &
tag,
size);
150 if (
tag == kAudioChannelLayoutTag_UseChannelBitmap)
151 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
152 sizeof(UInt32), &
layout->mChannelBitmap,
size, new_layout);
154 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
155 sizeof(AudioChannelLayoutTag), &
tag,
size, new_layout);
156 new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
164 AudioStreamBasicDescription
format;
166 if (!AudioConverterGetProperty(at->
converter,
167 kAudioConverterCurrentInputStreamDescription,
176 if (!AudioConverterGetProperty(at->
converter,
177 kAudioConverterCurrentOutputStreamDescription,
182 kAudioConverterCurrentOutputStreamDescription,
186 if (!AudioConverterGetPropertyInfo(at->
converter, kAudioConverterOutputChannelLayout,
189 uint64_t layout_mask = 0;
193 AudioConverterGetProperty(at->
converter, kAudioConverterOutputChannelLayout,
197 for (
i = 0;
i <
layout->mNumberChannelDescriptions;
i++) {
201 if (layout_mask & (1 <<
id))
203 layout_mask |= 1 <<
id;
204 layout->mChannelDescriptions[
i].mChannelFlags =
i;
208 qsort(
layout->mChannelDescriptions,
layout->mNumberChannelDescriptions,
210 for (
i = 0;
i <
layout->mNumberChannelDescriptions;
i++)
225 bytestream2_put_byte(pb,
tag);
227 bytestream2_put_byte(pb, (
size >> (7 *
i)) | 0x80);
228 bytestream2_put_byte(pb,
size & 0x7F);
238 if (!(extradata =
av_malloc(*cookie_size)))
245 bytestream2_put_be16(&pb, 0);
246 bytestream2_put_byte(&pb, 0x00);
252 bytestream2_put_byte(&pb, 0x40);
254 bytestream2_put_byte(&pb, 0x15);
256 bytestream2_put_be24(&pb, 0);
258 bytestream2_put_be32(&pb, 0);
259 bytestream2_put_be32(&pb, 0);
292 kAudioConverterDecompressionMagicCookie,
293 cookie_size, cookie);
313 AudioStreamBasicDescription in_format = {
317 AudioStreamBasicDescription out_format = {
318 .mFormatID = kAudioFormatLinearPCM,
319 .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
320 .mFramesPerPacket = 1,
327 UInt32 format_size =
sizeof(in_format);
332 status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
333 cookie_size, cookie, &format_size, &in_format);
340 #if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
348 &in_format.mChannelsPerFrame, &avctx->
frame_size,
354 #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
364 in_format.mChannelsPerFrame = hdr.
channels;
373 avctx->
sample_rate = out_format.mSampleRate = in_format.mSampleRate;
378 out_format.mBytesPerFrame =
379 out_format.mChannelsPerFrame * (out_format.mBitsPerChannel / 8);
380 out_format.mBytesPerPacket =
381 out_format.mBytesPerFrame * out_format.mFramesPerPacket;
384 in_format.mFramesPerPacket = 64;
428 AudioBufferList *
data,
429 AudioStreamPacketDescription **packets,
452 data->mNumberBuffers = 1;
453 data->mBuffers[0].mNumberChannels = 0;
466 #define COPY_SAMPLES(type) \
467 type *in_ptr = (type*)at->decoded_data; \
468 type *end_ptr = in_ptr + frame->nb_samples * avctx->ch_layout.nb_channels; \
469 type *out_ptr = (type*)frame->data[0]; \
470 for (; in_ptr < end_ptr; in_ptr += avctx->ch_layout.nb_channels, out_ptr += avctx->ch_layout.nb_channels) { \
472 for (c = 0; c < avctx->ch_layout.nb_channels; c++) \
473 out_ptr[c] = in_ptr[at->channel_map[c]]; \
487 int *got_frame_ptr,
AVPacket *avpkt)
490 int pkt_size = avpkt->
size;
492 AudioBufferList out_buffers;
497 size_t side_data_size;
501 if (side_data_size) {
506 memcpy(at->
extradata, side_data, side_data_size);
517 out_buffers = (AudioBufferList){
555 }
else if (
ret &&
ret != 1) {
584 #define FFAT_DEC_CLASS(NAME) \
585 static const AVClass ffat_##NAME##_dec_class = { \
586 .class_name = "at_" #NAME "_dec", \
587 .version = LIBAVUTIL_VERSION_INT, \
590 #define FFAT_DEC(NAME, ID, bsf_name) \
591 FFAT_DEC_CLASS(NAME) \
592 const FFCodec ff_##NAME##_at_decoder = { \
593 .p.name = #NAME "_at", \
594 CODEC_LONG_NAME(#NAME " (AudioToolbox)"), \
595 .p.type = AVMEDIA_TYPE_AUDIO, \
597 .priv_data_size = sizeof(ATDecodeContext), \
598 .init = ffat_init_decoder, \
599 .close = ffat_close_decoder, \
600 FF_CODEC_DECODE_CB(ffat_decode), \
601 .flush = ffat_decode_flush, \
602 .p.priv_class = &ffat_##NAME##_dec_class, \
604 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_CHANNEL_CONF, \
605 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
606 .p.wrapper_name = "at", \