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

Function decode_init_mp3on4

libavcodec/mpegaudiodec.c:2355–2405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2353
2354
2355static int decode_init_mp3on4(AVCodecContext * avctx)
2356{
2357 MP3On4DecodeContext *s = avctx->priv_data;
2358 MPEG4AudioConfig cfg;
2359 int i;
2360
2361 if ((avctx->extradata_size < 2) || (avctx->extradata == NULL)) {
2362 av_log(avctx, AV_LOG_ERROR, "Codec extradata missing or too short.\n");
2363 return -1;
2364 }
2365
2366 ff_mpeg4audio_get_config(&cfg, avctx->extradata, avctx->extradata_size);
2367 if (!cfg.chan_config || cfg.chan_config > 7) {
2368 av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n");
2369 return -1;
2370 }
2371 s->frames = mp3Frames[cfg.chan_config];
2372 s->coff = chan_offset[cfg.chan_config];
2373 avctx->channels = ff_mpeg4audio_channels[cfg.chan_config];
2374
2375 if (cfg.sample_rate < 16000)
2376 s->syncword = 0xffe00000;
2377 else
2378 s->syncword = 0xfff00000;
2379
2380 /* Init the first mp3 decoder in standard way, so that all tables get builded
2381 * We replace avctx->priv_data with the context of the first decoder so that
2382 * decode_init() does not have to be changed.
2383 * Other decoders will be initialized here copying data from the first context
2384 */
2385 // Allocate zeroed memory for the first decoder context
2386 s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext));
2387 // Put decoder context in place to make init_decode() happy
2388 avctx->priv_data = s->mp3decctx[0];
2389 decode_init(avctx);
2390 // Restore mp3on4 context pointer
2391 avctx->priv_data = s;
2392 s->mp3decctx[0]->adu_mode = 1; // Set adu mode
2393
2394 /* Create a separate codec/context for each frame (first is already ok).
2395 * Each frame is 1 or 2 channels - up to 5 frames allowed
2396 */
2397 for (i = 1; i < s->frames; i++) {
2398 s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext));
2399 s->mp3decctx[i]->compute_antialias = s->mp3decctx[0]->compute_antialias;
2400 s->mp3decctx[i]->adu_mode = 1;
2401 s->mp3decctx[i]->avctx = avctx;
2402 }
2403
2404 return 0;
2405}
2406
2407
2408static av_cold int decode_close_mp3on4(AVCodecContext * avctx)

Callers

nothing calls this directly

Calls 4

av_logFunction · 0.85
ff_mpeg4audio_get_configFunction · 0.85
av_malloczFunction · 0.85
decode_initFunction · 0.70

Tested by

no test coverage detected