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;
72 return kAudioFormatMicrosoftGSM;
74 return kAudioFormatiLBC;
76 return kAudioFormatMPEGLayer1;
78 return kAudioFormatMPEGLayer2;
80 return kAudioFormatMPEGLayer3;
82 return kAudioFormatALaw;
84 return kAudioFormatULaw;
86 return kAudioFormatQDesign;
88 return kAudioFormatQDesign2;
99 else if (label <= kAudioChannelLabel_LFEScreen)
101 else if (label <= kAudioChannelLabel_RightSurround)
103 else if (label <= kAudioChannelLabel_CenterSurround)
105 else if (label <= kAudioChannelLabel_RightSurroundDirect)
107 else if (label <= kAudioChannelLabel_TopBackRight)
109 else if (label < kAudioChannelLabel_RearSurroundLeft)
111 else if (label <= kAudioChannelLabel_RearSurroundRight)
113 else if (label <= kAudioChannelLabel_RightWide)
115 else if (label == kAudioChannelLabel_LFE2)
117 else if (label == kAudioChannelLabel_Mono)
125 const AudioChannelDescription* da =
a;
126 const AudioChannelDescription* db =
b;
132 AudioChannelLayoutTag
tag =
layout->mChannelLayoutTag;
133 AudioChannelLayout *new_layout;
134 if (
tag == kAudioChannelLayoutTag_UseChannelDescriptions)
136 else if (
tag == kAudioChannelLayoutTag_UseChannelBitmap)
137 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
138 sizeof(UInt32), &
layout->mChannelBitmap,
size);
140 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
141 sizeof(AudioChannelLayoutTag), &
tag,
size);
147 if (
tag == kAudioChannelLayoutTag_UseChannelBitmap)
148 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
149 sizeof(UInt32), &
layout->mChannelBitmap,
size, new_layout);
151 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
152 sizeof(AudioChannelLayoutTag), &
tag,
size, new_layout);
153 new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
161 AudioStreamBasicDescription
format;
163 if (!AudioConverterGetProperty(at->
converter,
164 kAudioConverterCurrentInputStreamDescription,
173 if (!AudioConverterGetProperty(at->
converter,
174 kAudioConverterCurrentOutputStreamDescription,
179 kAudioConverterCurrentOutputStreamDescription,
183 if (!AudioConverterGetPropertyInfo(at->
converter, kAudioConverterOutputChannelLayout,
186 uint64_t layout_mask = 0;
190 AudioConverterGetProperty(at->
converter, kAudioConverterOutputChannelLayout,
194 for (
i = 0;
i <
layout->mNumberChannelDescriptions;
i++) {
198 if (layout_mask & (1 <<
id))
200 layout_mask |= 1 <<
id;
201 layout->mChannelDescriptions[
i].mChannelFlags =
i;
204 qsort(
layout->mChannelDescriptions,
layout->mNumberChannelDescriptions,
206 for (
i = 0;
i <
layout->mNumberChannelDescriptions;
i++)
221 bytestream2_put_byte(pb,
tag);
223 bytestream2_put_byte(pb, (
size >> (7 *
i)) | 0x80);
224 bytestream2_put_byte(pb,
size & 0x7F);
234 if (!(extradata =
av_malloc(*cookie_size)))
241 bytestream2_put_be16(&pb, 0);
242 bytestream2_put_byte(&pb, 0x00);
248 bytestream2_put_byte(&pb, 0x40);
250 bytestream2_put_byte(&pb, 0x15);
252 bytestream2_put_be24(&pb, 0);
254 bytestream2_put_be32(&pb, 0);
255 bytestream2_put_be32(&pb, 0);
288 kAudioConverterDecompressionMagicCookie,
289 cookie_size, cookie);
309 AudioStreamBasicDescription in_format = {
313 AudioStreamBasicDescription out_format = {
314 .mFormatID = kAudioFormatLinearPCM,
315 .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
316 .mFramesPerPacket = 1,
323 UInt32 format_size =
sizeof(in_format);
328 status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
329 cookie_size, cookie, &format_size, &in_format);
336 #if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
344 &in_format.mChannelsPerFrame, &avctx->
frame_size,
350 #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
360 in_format.mChannelsPerFrame = hdr.
channels;
369 avctx->
sample_rate = out_format.mSampleRate = in_format.mSampleRate;
370 avctx->
channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
373 in_format.mFramesPerPacket = 64;
417 AudioBufferList *
data,
418 AudioStreamPacketDescription **packets,
441 data->mNumberBuffers = 1;
442 data->mBuffers[0].mNumberChannels = 0;
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) { \
461 for (c = 0; c < avctx->channels; c++) \
462 out_ptr[c] = in_ptr[at->channel_map[c]]; \
476 int *got_frame_ptr,
AVPacket *avpkt)
480 int pkt_size = avpkt->
size;
482 AudioBufferList out_buffers;
491 if (side_data_size) {
496 memcpy(at->
extradata, side_data, side_data_size);
507 out_buffers = (AudioBufferList){
550 }
else if (
ret &&
ret != 1) {
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, \
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, \
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, \
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", \