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);
287 status = AudioConverterSetProperty(at->
converter,
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;
375 status = AudioConverterNew(&in_format, &out_format, &at->
converter);
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", \
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_bits(GetBitContext *s, const uint8_t *buffer, int bit_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...