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);
308 AudioStreamBasicDescription in_format = {
312 AudioStreamBasicDescription out_format = {
313 .mFormatID = kAudioFormatLinearPCM,
314 .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
315 .mFramesPerPacket = 1,
322 UInt32 format_size =
sizeof(in_format);
327 status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
328 cookie_size, cookie, &format_size, &in_format);
335 #if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
343 &in_format.mChannelsPerFrame, &avctx->
frame_size,
349 #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
359 in_format.mChannelsPerFrame = hdr.
channels;
368 avctx->
sample_rate = out_format.mSampleRate = in_format.mSampleRate;
369 avctx->
channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
372 in_format.mFramesPerPacket = 64;
416 AudioBufferList *
data,
417 AudioStreamPacketDescription **packets,
440 data->mNumberBuffers = 1;
441 data->mBuffers[0].mNumberChannels = 0;
454 #define COPY_SAMPLES(type) \
455 type *in_ptr = (type*)at->decoded_data; \
456 type *end_ptr = in_ptr + frame->nb_samples * avctx->channels; \
457 type *out_ptr = (type*)frame->data[0]; \
458 for (; in_ptr < end_ptr; in_ptr += avctx->channels, out_ptr += avctx->channels) { \
460 for (c = 0; c < avctx->channels; c++) \
461 out_ptr[c] = in_ptr[at->channel_map[c]]; \
475 int *got_frame_ptr,
AVPacket *avpkt)
479 int pkt_size = avpkt->
size;
481 AudioBufferList out_buffers;
486 int side_data_size = 0;
490 if (side_data_size) {
495 memcpy(at->
extradata, side_data, side_data_size);
506 out_buffers = (AudioBufferList){
549 }
else if (
ret &&
ret != 1) {
578 #define FFAT_DEC_CLASS(NAME) \
579 static const AVClass ffat_##NAME##_dec_class = { \
580 .class_name = "at_" #NAME "_dec", \
581 .version = LIBAVUTIL_VERSION_INT, \
584 #define FFAT_DEC(NAME, ID, bsf_name) \
585 FFAT_DEC_CLASS(NAME) \
586 AVCodec ff_##NAME##_at_decoder = { \
587 .name = #NAME "_at", \
588 .long_name = NULL_IF_CONFIG_SMALL(#NAME " (AudioToolbox)"), \
589 .type = AVMEDIA_TYPE_AUDIO, \
591 .priv_data_size = sizeof(ATDecodeContext), \
592 .init = ffat_init_decoder, \
593 .close = ffat_close_decoder, \
594 .decode = ffat_decode, \
595 .flush = ffat_decode_flush, \
596 .priv_class = &ffat_##NAME##_dec_class, \
598 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, \
599 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, \
600 .wrapper_name = "at", \