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,
166 if (format.mSampleRate)
168 avctx->
channels = format.mChannelsPerFrame;
173 if (!AudioConverterGetProperty(at->
converter,
174 kAudioConverterCurrentOutputStreamDescription,
177 format.mChannelsPerFrame = avctx->
channels;
179 kAudioConverterCurrentOutputStreamDescription,
183 if (!AudioConverterGetPropertyInfo(at->
converter, kAudioConverterOutputChannelLayout,
184 &size,
NULL) && size) {
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++)
207 at->
channel_map[i] = layout->mChannelDescriptions[i].mChannelFlags;
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);
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 336 }
else if (pkt && pkt->
size >= 4 &&
343 &in_format.mChannelsPerFrame, &avctx->
frame_size,
344 &bit_rate, &codec_id) < 0)
349 #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER 350 }
else if (pkt && pkt->
size >= 7 &&
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;
374 status = AudioConverterNew(&in_format, &out_format, &at->
converter);
416 AudioBufferList *
data,
417 AudioStreamPacketDescription **packets,
440 data->mNumberBuffers = 1;
441 data->mBuffers[0].mNumberChannels = 0;
442 data->mBuffers[0].mDataByteSize = at->
in_pkt.
size;
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)
481 AudioBufferList out_buffers;
490 if (side_data_size) {
495 memcpy(at->
extradata, side_data, side_data_size);
506 out_buffers = (AudioBufferList){
535 if ((!ret || ret == 1) && frame->
nb_samples) {
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 | AV_CODEC_CAP_CHANNEL_CONF, \ 599 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, \ 600 .wrapper_name = "at", \
int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
Parse AC-3 frame header.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
#define AV_CH_LOW_FREQUENCY_2
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
enum AVSampleFormat sample_fmt
audio sample format
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
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.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
preferred ID for decoding MPEG audio layer 1, 2 or 3
simple assert() macros that are a bit more flexible than ISO C assert().
uint64_t channel_layout
Audio channel layout.
AudioStreamPacketDescription pkt_desc
AudioConverterRef converter
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define AV_CH_FRONT_CENTER
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
int frame_size
Number of samples per channel in an audio frame.
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
int sample_rate
samples per second
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Describe the class of an AVClass context structure.
int sample_rate
Sample rate of the audio data.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
#define FF_ENABLE_DEPRECATION_WARNINGS
int channels
number of audio channels
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
#define AV_NOPTS_VALUE
Undefined timestamp value.