MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / decavcodecaInit

Function decavcodecaInit

libhb/decavcodec.c:367–548  ·  view source on GitHub ↗

* hb_work_decavcodec_init *********************************************************************** * **********************************************************************/

Source from the content-addressed store, hash-verified

365 *
366 **********************************************************************/
367static int decavcodecaInit( hb_work_object_t * w, hb_job_t * job )
368{
369 const AVCodec *codec;
370
371 hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
372 w->private_data = pv;
373
374 pv->job = job;
375 pv->audio = w->audio;
376 pv->drop_samples = w->audio->config.in.encoder_delay;
377 pv->next_pts = (int64_t)AV_NOPTS_VALUE;
378 if (job)
379 pv->title = job->title;
380 else
381 pv->title = w->title;
382 hb_buffer_list_clear(&pv->list);
383
384 codec = avcodec_find_decoder(w->codec_param);
385 pv->context = avcodec_alloc_context3(codec);
386
387 if (pv->title->opaque_priv != NULL)
388 {
389 AVFormatContext *ic = (AVFormatContext*)pv->title->opaque_priv;
390 avcodec_parameters_to_context(pv->context,
391 ic->streams[w->audio->id]->codecpar);
392 // libav's eac3 parser toggles the codec_id in the context as
393 // it reads eac3 data between AV_CODEC_ID_AC3 and AV_CODEC_ID_EAC3.
394 // It detects an AC3 sync pattern sometimes in ac3_sync() which
395 // causes it to eventually set avctx->codec_id to AV_CODEC_ID_AC3
396 // in ff_aac_ac3_parse(). Since we are parsing some data before
397 // we get here, the codec_id may have flipped. This will cause an
398 // error in hb_avcodec_open(). So flip it back!
399 pv->context->codec_id = w->codec_param;
400 }
401 else
402 {
403 pv->parser = av_parser_init(w->codec_param);
404 }
405 hb_ff_set_sample_fmt(pv->context, codec, AV_SAMPLE_FMT_FLT);
406
407 // Set decoder opts...
408 AVDictionary *av_opts = NULL;
409
410 /* Downmixing & sample_fmt conversion */
411 if (!(w->audio->config.out.codec & HB_ACODEC_PASS_FLAG))
412 {
413 // Currently, samplerate conversion is performed in sync.c
414 // So set output samplerate to input samplerate
415 // This should someday get reworked to be part of an audio
416 // filter pipeline.
417 pv->resample =
418 hb_audio_resample_init(AV_SAMPLE_FMT_FLT,
419 w->audio->config.in.samplerate,
420 w->audio->config.out.mixdown,
421 w->audio->config.out.normalize_mix_level);
422 if (pv->resample == NULL)
423 {
424 hb_error("decavcodecaInit: hb_audio_resample_init() failed");

Callers

nothing calls this directly

Calls 11

hb_buffer_list_clearFunction · 0.85
hb_ff_set_sample_fmtFunction · 0.85
hb_audio_resample_initFunction · 0.85
hb_errorFunction · 0.85
ac3_downmix_maskFunction · 0.85
dca_downmix_maskFunction · 0.85
truehd_downmix_maskFunction · 0.85
hb_logFunction · 0.85
hb_audio_can_apply_drcFunction · 0.85
hb_avcodec_openFunction · 0.85

Tested by

no test coverage detected