23 #include <AudioToolbox/AudioToolbox.h>
36 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
37 #define kAudioFormatEnhancedAC3 'ec-3'
61 return kAudioFormatMPEG4AAC;
63 return kAudioFormatAC3;
65 return kAudioFormatAppleIMA4;
67 return kAudioFormatAppleLossless;
69 return kAudioFormatAMR;
73 return kAudioFormatMicrosoftGSM;
75 return kAudioFormatiLBC;
77 return kAudioFormatMPEGLayer1;
79 return kAudioFormatMPEGLayer2;
81 return kAudioFormatMPEGLayer3;
83 return kAudioFormatALaw;
85 return kAudioFormatULaw;
87 return kAudioFormatQDesign;
89 return kAudioFormatQDesign2;
100 else if (label <= kAudioChannelLabel_LFEScreen)
102 else if (label <= kAudioChannelLabel_RightSurround)
104 else if (label <= kAudioChannelLabel_CenterSurround)
106 else if (label <= kAudioChannelLabel_RightSurroundDirect)
108 else if (label <= kAudioChannelLabel_TopBackRight)
110 else if (label < kAudioChannelLabel_RearSurroundLeft)
112 else if (label <= kAudioChannelLabel_RearSurroundRight)
114 else if (label <= kAudioChannelLabel_RightWide)
116 else if (label == kAudioChannelLabel_LFE2)
118 else if (label == kAudioChannelLabel_Mono)
126 const AudioChannelDescription* da =
a;
127 const AudioChannelDescription* db =
b;
133 AudioChannelLayoutTag
tag =
layout->mChannelLayoutTag;
134 AudioChannelLayout *new_layout;
135 if (
tag == kAudioChannelLayoutTag_UseChannelDescriptions)
137 else if (
tag == kAudioChannelLayoutTag_UseChannelBitmap)
138 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
139 sizeof(UInt32), &
layout->mChannelBitmap,
size);
141 AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
142 sizeof(AudioChannelLayoutTag), &
tag,
size);
148 if (
tag == kAudioChannelLayoutTag_UseChannelBitmap)
149 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
150 sizeof(UInt32), &
layout->mChannelBitmap,
size, new_layout);
152 AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
153 sizeof(AudioChannelLayoutTag), &
tag,
size, new_layout);
154 new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
162 AudioStreamBasicDescription
format;
164 if (!AudioConverterGetProperty(at->
converter,
165 kAudioConverterCurrentInputStreamDescription,
174 if (!AudioConverterGetProperty(at->
converter,
175 kAudioConverterCurrentOutputStreamDescription,
180 kAudioConverterCurrentOutputStreamDescription,
184 if (!AudioConverterGetPropertyInfo(at->
converter, kAudioConverterOutputChannelLayout,
187 uint64_t layout_mask = 0;
191 AudioConverterGetProperty(at->
converter, kAudioConverterOutputChannelLayout,
195 for (
i = 0;
i <
layout->mNumberChannelDescriptions;
i++) {
199 if (layout_mask & (1 <<
id))
201 layout_mask |= 1 <<
id;
202 layout->mChannelDescriptions[
i].mChannelFlags =
i;
205 qsort(
layout->mChannelDescriptions,
layout->mNumberChannelDescriptions,
207 for (
i = 0;
i <
layout->mNumberChannelDescriptions;
i++)
222 bytestream2_put_byte(pb,
tag);
224 bytestream2_put_byte(pb, (
size >> (7 *
i)) | 0x80);
225 bytestream2_put_byte(pb,
size & 0x7F);
235 if (!(extradata =
av_malloc(*cookie_size)))
242 bytestream2_put_be16(&pb, 0);
243 bytestream2_put_byte(&pb, 0x00);
249 bytestream2_put_byte(&pb, 0x40);
251 bytestream2_put_byte(&pb, 0x15);
253 bytestream2_put_be24(&pb, 0);
255 bytestream2_put_be32(&pb, 0);
256 bytestream2_put_be32(&pb, 0);
289 kAudioConverterDecompressionMagicCookie,
290 cookie_size, cookie);
310 AudioStreamBasicDescription in_format = {
314 AudioStreamBasicDescription out_format = {
315 .mFormatID = kAudioFormatLinearPCM,
316 .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
317 .mFramesPerPacket = 1,
324 UInt32 format_size =
sizeof(in_format);
329 status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
330 cookie_size, cookie, &format_size, &in_format);
337 #if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
345 &in_format.mChannelsPerFrame, &avctx->
frame_size,
351 #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
361 in_format.mChannelsPerFrame = hdr.
channels;
370 avctx->
sample_rate = out_format.mSampleRate = in_format.mSampleRate;
371 avctx->
channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
374 in_format.mFramesPerPacket = 64;
418 AudioBufferList *
data,
419 AudioStreamPacketDescription **packets,
442 data->mNumberBuffers = 1;
443 data->mBuffers[0].mNumberChannels = 0;
456 #define COPY_SAMPLES(type) \
457 type *in_ptr = (type*)at->decoded_data; \
458 type *end_ptr = in_ptr + frame->nb_samples * avctx->channels; \
459 type *out_ptr = (type*)frame->data[0]; \
460 for (; in_ptr < end_ptr; in_ptr += avctx->channels, out_ptr += avctx->channels) { \
462 for (c = 0; c < avctx->channels; c++) \
463 out_ptr[c] = in_ptr[at->channel_map[c]]; \
477 int *got_frame_ptr,
AVPacket *avpkt)
481 int pkt_size = avpkt->
size;
483 AudioBufferList out_buffers;
488 size_t side_data_size;
492 if (side_data_size) {
497 memcpy(at->
extradata, side_data, side_data_size);
508 out_buffers = (AudioBufferList){
546 }
else if (
ret &&
ret != 1) {
575 #define FFAT_DEC_CLASS(NAME) \
576 static const AVClass ffat_##NAME##_dec_class = { \
577 .class_name = "at_" #NAME "_dec", \
578 .version = LIBAVUTIL_VERSION_INT, \
581 #define FFAT_DEC(NAME, ID, bsf_name) \
582 FFAT_DEC_CLASS(NAME) \
583 const AVCodec ff_##NAME##_at_decoder = { \
584 .name = #NAME "_at", \
585 .long_name = NULL_IF_CONFIG_SMALL(#NAME " (AudioToolbox)"), \
586 .type = AVMEDIA_TYPE_AUDIO, \
588 .priv_data_size = sizeof(ATDecodeContext), \
589 .init = ffat_init_decoder, \
590 .close = ffat_close_decoder, \
591 .decode = ffat_decode, \
592 .flush = ffat_decode_flush, \
593 .priv_class = &ffat_##NAME##_dec_class, \
595 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_CHANNEL_CONF, \
596 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, \
597 .wrapper_name = "at", \