diff options
author | jstebbins <[email protected]> | 2011-06-10 18:20:30 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2011-06-10 18:20:30 +0000 |
commit | bf638bca8ae57005b4d570b4260d10af45d1c7a0 (patch) | |
tree | 582f371110d7a1ab53b0ee107d3f35599b9495b7 /libhb | |
parent | 8b804a5e65b322aa2a0cbbfd43e0c54b62b5f5f5 (diff) |
libhb: clean up AVCodecContext initializations
also fixes warning message generated by libav when initializing "silence"
sample about channel layout setting.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4038 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/decavcodec.c | 11 | ||||
-rw-r--r-- | libhb/encavcodecaudio.c | 5 | ||||
-rw-r--r-- | libhb/sync.c | 44 |
3 files changed, 50 insertions, 10 deletions
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 6d9632bab..770a7914e 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -203,8 +203,7 @@ static int decavcodecInit( hb_work_object_t * w, hb_job_t * job ) codec = avcodec_find_decoder( codec_id ); pv->parser = av_parser_init( codec_id ); - pv->context = avcodec_alloc_context(); - avcodec_get_context_defaults3(pv->context, codec); + pv->context = avcodec_alloc_context3(codec); hb_ff_set_sample_fmt( pv->context, codec ); hb_avcodec_open( pv->context, codec, 0 ); @@ -522,8 +521,7 @@ static int decavcodecBSInfo( hb_work_object_t *w, const hb_buffer_t *buf, info->name = strncpy( codec_name, codec->name, sizeof(codec_name)-1 ); AVCodecParserContext *parser = av_parser_init( codec->id ); - AVCodecContext *context = avcodec_alloc_context(); - avcodec_get_context_defaults3(context, codec); + AVCodecContext *context = avcodec_alloc_context3(codec); hb_ff_set_sample_fmt( context, codec ); hb_avcodec_open( context, codec, 0 ); uint8_t *buffer = av_malloc( AVCODEC_MAX_AUDIO_FRAME_SIZE ); @@ -1150,6 +1148,9 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in, // first frame because of M$ VC1 braindamage). if ( pv->context->extradata == NULL ) { + AVCodec *codec = avcodec_find_decoder( w->codec_param ); + avcodec_get_context_defaults3( pv->context, codec ); + hb_ff_set_sample_fmt( pv->context, codec ); if ( setup_extradata( w, in ) ) { // we didn't find the headers needed to set up extradata. @@ -1158,11 +1159,9 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in, hb_buffer_close( &in ); return HB_WORK_OK; } - AVCodec *codec = avcodec_find_decoder( w->codec_param ); // There's a mis-feature in ffmpeg that causes the context to be // incorrectly initialized the 1st time avcodec_open is called. // If you close it and open a 2nd time, it finishes the job. - hb_ff_set_sample_fmt( pv->context, codec ); hb_avcodec_open( pv->context, codec, 0 ); hb_avcodec_close( pv->context ); // disable threaded decoding for scan, can cause crashes diff --git a/libhb/encavcodecaudio.c b/libhb/encavcodecaudio.c index 9cf9c9831..7c0a51971 100644 --- a/libhb/encavcodecaudio.c +++ b/libhb/encavcodecaudio.c @@ -55,8 +55,7 @@ static int encavcodecaInit( hb_work_object_t * w, hb_job_t * job ) "failed" ); return 1; } - context = avcodec_alloc_context(); - avcodec_get_context_defaults3(context, codec); + context = avcodec_alloc_context3(codec); int ret = av_set_string3( context, "stereo_mode", "ms_off", 1, NULL ); /* Let avutil sanity check the options for us*/ @@ -83,7 +82,7 @@ static int encavcodecaInit( hb_work_object_t * w, hb_job_t * job ) break; default: - hb_log(" encavcodecaInit: bad mixdown" ); + hb_log("encavcodecaInit: bad mixdown" ); break; } diff --git a/libhb/sync.c b/libhb/sync.c index f4cb29f25..670c019f2 100644 --- a/libhb/sync.c +++ b/libhb/sync.c @@ -1112,13 +1112,55 @@ static void InitAudio( hb_job_t * job, hb_sync_common_t * common, int i ) short * zeros; codec = avcodec_find_encoder( CODEC_ID_AC3 ); - c = avcodec_alloc_context(); + c = avcodec_alloc_context3( codec ); c->bit_rate = w->audio->config.in.bitrate; c->sample_rate = w->audio->config.in.samplerate; c->channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT( w->audio->config.in.channel_layout ); c->sample_fmt = AV_SAMPLE_FMT_FLT; + switch( w->audio->config.in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK ) + { + case HB_INPUT_CH_LAYOUT_MONO: + c->channel_layout = AV_CH_LAYOUT_MONO; + break; + + case HB_INPUT_CH_LAYOUT_STEREO: + case HB_INPUT_CH_LAYOUT_DOLBY: + c->channel_layout = AV_CH_LAYOUT_STEREO; + break; + + case HB_INPUT_CH_LAYOUT_3F2R: + c->channel_layout = AV_CH_LAYOUT_5POINT0; + break; + + case HB_INPUT_CH_LAYOUT_3F1R: + c->channel_layout = AV_CH_LAYOUT_4POINT0; + break; + + case HB_INPUT_CH_LAYOUT_3F: + c->channel_layout = AV_CH_LAYOUT_SURROUND; + break; + + case HB_INPUT_CH_LAYOUT_2F1R: + c->channel_layout = AV_CH_LAYOUT_2_1; + break; + + case HB_INPUT_CH_LAYOUT_2F2R: + c->channel_layout = AV_CH_LAYOUT_QUAD; + break; + + default: + c->channel_layout = AV_CH_LAYOUT_STEREO; + hb_log("sync: unrecognized channel layout" ); + break; + } + + if ( w->audio->config.in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE ) + { + c->channel_layout |= AV_CH_LOW_FREQUENCY; + } + if( hb_avcodec_open( c, codec, 0 ) < 0 ) { hb_log( "sync: avcodec_open failed" ); |