MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / ffat_init_encoder

Function ffat_init_encoder

libavcodec/audiotoolboxenc.c:251–472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249}
250
251static av_cold int ffat_init_encoder(AVCodecContext *avctx)
252{
253 ATDecodeContext *at = avctx->priv_data;
254 OSStatus status;
255 int ret;
256
257 AudioStreamBasicDescription in_format = {
258 .mSampleRate = avctx->sample_rate,
259 .mFormatID = kAudioFormatLinearPCM,
260 .mFormatFlags = ((avctx->sample_fmt == AV_SAMPLE_FMT_FLT ||
261 avctx->sample_fmt == AV_SAMPLE_FMT_DBL) ? kAudioFormatFlagIsFloat
262 : avctx->sample_fmt == AV_SAMPLE_FMT_U8 ? 0
263 : kAudioFormatFlagIsSignedInteger)
264 | kAudioFormatFlagIsPacked,
265 .mBytesPerPacket = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->ch_layout.nb_channels,
266 .mFramesPerPacket = 1,
267 .mBytesPerFrame = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->ch_layout.nb_channels,
268 .mChannelsPerFrame = avctx->ch_layout.nb_channels,
269 .mBitsPerChannel = av_get_bytes_per_sample(avctx->sample_fmt) * 8,
270 };
271 AudioStreamBasicDescription out_format = {
272 .mSampleRate = avctx->sample_rate,
273 .mFormatID = ffat_get_format_id(avctx->codec_id, avctx->profile),
274 .mChannelsPerFrame = in_format.mChannelsPerFrame,
275 };
276 UInt32 layout_size = sizeof(AudioChannelLayout) +
277 sizeof(AudioChannelDescription) * avctx->ch_layout.nb_channels;
278 AudioChannelLayout *channel_layout = av_malloc(layout_size);
279
280 if (!channel_layout)
281 return AVERROR(ENOMEM);
282
283 if (avctx->codec_id == AV_CODEC_ID_ILBC) {
284 int mode = get_ilbc_mode(avctx);
285 out_format.mFramesPerPacket = 8000 * mode / 1000;
286 out_format.mBytesPerPacket = (mode == 20 ? 38 : 50);
287 }
288
289 status = AudioConverterNew(&in_format, &out_format, &at->converter);
290
291 if (status != 0) {
292 av_log(avctx, AV_LOG_ERROR, "AudioToolbox init error: %i\n", (int)status);
293 av_free(channel_layout);
294 return AVERROR_UNKNOWN;
295 }
296
297 if (avctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
298 av_channel_layout_default(&avctx->ch_layout, avctx->ch_layout.nb_channels);
299
300 if ((status = remap_layout(channel_layout, &avctx->ch_layout)) < 0) {
301 av_log(avctx, AV_LOG_ERROR, "Invalid channel layout\n");
302 av_free(channel_layout);
303 return status;
304 }
305
306 if (AudioConverterSetProperty(at->converter, kAudioConverterInputChannelLayout,
307 layout_size, channel_layout)) {
308 av_log(avctx, AV_LOG_ERROR, "Unsupported input channel layout\n");

Callers

nothing calls this directly

Calls 15

av_get_bytes_per_sampleFunction · 0.85
get_ilbc_modeFunction · 0.85
av_logFunction · 0.85
remap_layoutFunction · 0.85
get_aac_tagFunction · 0.85
bytestream2_initFunction · 0.85
read_descrFunction · 0.85
bytestream2_skipFunction · 0.85
ff_af_queue_initFunction · 0.85
av_frame_allocFunction · 0.85

Tested by

no test coverage detected