diff options
-rw-r--r-- | gtk/src/audiohandler.c | 32 | ||||
-rw-r--r-- | gtk/src/makedeps.py | 3 | ||||
-rw-r--r-- | libhb/common.c | 22 | ||||
-rw-r--r-- | libhb/common.h | 2 | ||||
-rw-r--r-- | libhb/decavcodec.c | 42 | ||||
-rw-r--r-- | libhb/work.c | 5 | ||||
-rw-r--r-- | macosx/English.lproj/MainMenu.xib | 14 | ||||
-rw-r--r-- | macosx/HBAudio.m | 7 | ||||
-rw-r--r-- | macosx/HBAudioController.h | 1 | ||||
-rw-r--r-- | macosx/HBAudioController.m | 7 |
10 files changed, 119 insertions, 16 deletions
diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c index cdf1d16e3..67e979d14 100644 --- a/gtk/src/audiohandler.c +++ b/gtk/src/audiohandler.c @@ -29,6 +29,35 @@ static void ghb_clear_audio_list_ui(GtkBuilder *builder); static gboolean block_updates = FALSE; +static void audio_deps(signal_user_data_t *ud) +{ + gint track = -1, encoder = 0; + hb_audio_config_t *aconfig = NULL; + gint titleindex = ghb_settings_combo_int(ud->settings, "title"); + GValue *asettings = get_selected_asettings(ud); + + if (asettings != NULL) + { + track = ghb_settings_combo_int(asettings, "AudioTrack"); + encoder = ghb_settings_combo_int(asettings, "AudioEncoderActual"); + aconfig = ghb_get_scan_audio_info(titleindex, track); + } + + gboolean enable_drc = TRUE; + if (aconfig != NULL) + { + enable_drc = hb_audio_can_apply_drc(aconfig->in.codec, + aconfig->in.codec_param, encoder); + } + + GtkWidget * widget = GHB_WIDGET(ud->builder, "AudioTrackDRCSlider"); + gtk_widget_set_sensitive(widget, enable_drc); + widget = GHB_WIDGET(ud->builder, "AudioTrackDRCSliderLabel"); + gtk_widget_set_sensitive(widget, enable_drc); + widget = GHB_WIDGET(ud->builder, "AudioTrackDRCValue"); + gtk_widget_set_sensitive(widget, enable_drc); +} + void ghb_show_hide_advanced_audio( signal_user_data_t *ud ) { @@ -731,6 +760,7 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud) ghb_adjust_audio_rate_combos(ud); ghb_grey_combo_options (ud); ghb_check_dependency(ud, widget, NULL); + audio_deps(ud); prev_acodec = acodec_code; if (asettings != NULL) { @@ -771,6 +801,7 @@ audio_track_changed_cb(GtkWidget *widget, signal_user_data_t *ud) ghb_adjust_audio_rate_combos(ud); ghb_check_dependency(ud, widget, NULL); + audio_deps(ud); ghb_grey_combo_options(ud); asettings = get_selected_asettings(ud); if (asettings != NULL) @@ -1117,6 +1148,7 @@ audio_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t widget = GHB_WIDGET (ud->builder, "audio_remove"); gtk_widget_set_sensitive(widget, FALSE); } + audio_deps(ud); } static gboolean diff --git a/gtk/src/makedeps.py b/gtk/src/makedeps.py index 6ab44ccd4..c0f791d1c 100644 --- a/gtk/src/makedeps.py +++ b/gtk/src/makedeps.py @@ -56,9 +56,6 @@ dep_map = ( DepEntry("AudioEncoderActual", "AudioSamplerate", "copy:mp3|copy:aac|copy:ac3|copy:dts|copy:dtshd", True, False), DepEntry("AudioEncoderActual", "AudioMixdownLabel", "copy:mp3|copy:aac|copy:ac3|copy:dts|copy:dtshd", True, False), DepEntry("AudioEncoderActual", "AudioMixdown", "copy:mp3|copy:aac|copy:ac3|copy:dts|copy:dtshd", True, False), - DepEntry("AudioEncoderActual", "AudioTrackDRCSliderLabel", "copy:mp3|copy:aac|copy:ac3|copy:dts|copy:dtshd", True, False), - DepEntry("AudioEncoderActual", "AudioTrackDRCSlider", "copy:mp3|copy:aac|copy:ac3|copy:dts|copy:dtshd", True, False), - DepEntry("AudioEncoderActual", "AudioTrackDRCValue", "copy:mp3|copy:aac|copy:ac3|copy:dts|copy:dtshd", True, False), DepEntry("AudioEncoderActual", "AudioTrackGainLabel", "copy:mp3|copy:aac|copy:ac3|copy:dts|copy:dtshd", True, False), DepEntry("AudioEncoderActual", "AudioTrackGain", "copy:mp3|copy:aac|copy:ac3|copy:dts|copy:dtshd", True, False), DepEntry("AudioEncoderActual", "AudioTrackGainValue", "copy:mp3|copy:aac|copy:ac3|copy:dts|copy:dtshd", True, False), diff --git a/libhb/common.c b/libhb/common.c index a0e6b7a58..813ece48e 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -3709,6 +3709,28 @@ int hb_subtitle_can_pass( int source, int mux ) } } +int hb_audio_can_apply_drc(uint32_t codec, uint32_t codec_param, int encoder) +{ + if (encoder & HB_ACODEC_PASS_FLAG) + { + // can't apply DRC to passthrough audio + return 0; + } + else if (codec & HB_ACODEC_FF_MASK) + { + return (codec_param == AV_CODEC_ID_AC3 || + codec_param == AV_CODEC_ID_EAC3); + } + else if (codec == HB_ACODEC_AC3) + { + return 1; + } + else + { + return 0; + } +} + /********************************************************************** * hb_metadata_init ********************************************************************** diff --git a/libhb/common.h b/libhb/common.h index 613338b35..cf037e579 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -161,6 +161,8 @@ int hb_subtitle_can_force( int source ); int hb_subtitle_can_burn( int source ); int hb_subtitle_can_pass( int source, int mux ); +int hb_audio_can_apply_drc(uint32_t codec, uint32_t codec_param, int encoder); + hb_attachment_t *hb_attachment_copy(const hb_attachment_t *src); hb_list_t *hb_attachment_list_copy(const hb_list_t *src); diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 5a4b0513c..1e760583b 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -360,12 +360,54 @@ static int decavcodecaInit( hb_work_object_t * w, hb_job_t * job ) AVDictionary * av_opts = NULL; av_dict_set( &av_opts, "refcounted_frames", "1", 0 ); + // Dynamic Range Compression + if (w->audio->config.out.dynamic_range_compression >= 0.0f && + hb_audio_can_apply_drc(w->audio->config.in.codec, + w->audio->config.in.codec_param, 0)) + { + float drc_scale_max = 1.0f; + /* + * avcodec_open will fail if the value for any of the options is out of + * range, so assume a conservative maximum of 1 and try to determine the + * option's actual upper limit. + */ + if (codec != NULL && codec->priv_class != NULL) + { + const AVOption *opt; + opt = av_opt_find2((void*)&codec->priv_class, "drc_scale", NULL, + AV_OPT_FLAG_DECODING_PARAM|AV_OPT_FLAG_AUDIO_PARAM, + AV_OPT_SEARCH_FAKE_OBJ, NULL); + if (opt != NULL) + { + drc_scale_max = opt->max; + } + } + if (w->audio->config.out.dynamic_range_compression > drc_scale_max) + { + hb_log("decavcodecaInit: track %d, sanitizing out-of-range DRC %.2f to %.2f", + w->audio->config.out.track, + w->audio->config.out.dynamic_range_compression, drc_scale_max); + w->audio->config.out.dynamic_range_compression = drc_scale_max; + } + + char drc_scale[5]; // "?.??\n" + snprintf(drc_scale, sizeof(drc_scale), "%.2f", + w->audio->config.out.dynamic_range_compression); + av_dict_set(&av_opts, "drc_scale", drc_scale, 0); + } + if (hb_avcodec_open(pv->context, codec, &av_opts, 0)) { av_dict_free( &av_opts ); hb_log("decavcodecaInit: avcodec_open failed"); return 1; } + // avcodec_open populates av_opts with the things it didn't recognize. + AVDictionaryEntry *t = NULL; + while ((t = av_dict_get(av_opts, "", t, AV_DICT_IGNORE_SUFFIX)) != NULL) + { + hb_log("decavcodecaInit: unknown option '%s'", t->key); + } av_dict_free( &av_opts ); pv->frame = av_frame_alloc(); diff --git a/libhb/work.c b/libhb/work.c index 05f76d46e..abdf19f4f 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -452,7 +452,10 @@ void hb_display_job_info(hb_job_t *job) { hb_log( " + gain: %.fdB", audio->config.out.gain ); } - if( ( audio->config.out.dynamic_range_compression != 0.0 ) && ( audio->config.in.codec == HB_ACODEC_AC3 ) ) + if (audio->config.out.dynamic_range_compression > 0.0f && + hb_audio_can_apply_drc(audio->config.in.codec, + audio->config.in.codec_param, + audio->config.out.codec)) { hb_log( " + dynamic range compression: %f", audio->config.out.dynamic_range_compression ); } diff --git a/macosx/English.lproj/MainMenu.xib b/macosx/English.lproj/MainMenu.xib index 0a7f82d5b..1d3601fe8 100644 --- a/macosx/English.lproj/MainMenu.xib +++ b/macosx/English.lproj/MainMenu.xib @@ -5677,7 +5677,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>bitRates</string> <string>bitRates.keyAudioBitrateName</string> <string>bitRate</string> - <string>AC3Enabled</string> + <string>DRCEnabled</string> <string>gain</string> <string>PassThruEnabled</string> <string>PassThruDisabled</string> @@ -7360,15 +7360,15 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> - <string key="label">enabled: arrangedObjects.AC3Enabled</string> + <string key="label">enabled: arrangedObjects.DRCEnabled</string> <reference key="source" ref="581296833"/> <reference key="destination" ref="141316080"/> <object class="NSNibBindingConnector" key="connector"> <reference key="NSSource" ref="581296833"/> <reference key="NSDestination" ref="141316080"/> - <string key="NSLabel">enabled: arrangedObjects.AC3Enabled</string> + <string key="NSLabel">enabled: arrangedObjects.DRCEnabled</string> <string key="NSBinding">enabled</string> - <string key="NSKeyPath">arrangedObjects.AC3Enabled</string> + <string key="NSKeyPath">arrangedObjects.DRCEnabled</string> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> @@ -7405,15 +7405,15 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> <object class="IBConnectionRecord"> <object class="IBBindingConnection" key="connection"> - <string key="label">enabled: arrangedObjects.AC3Enabled</string> + <string key="label">enabled: arrangedObjects.DRCEnabled</string> <reference key="source" ref="393032802"/> <reference key="destination" ref="141316080"/> <object class="NSNibBindingConnector" key="connector"> <reference key="NSSource" ref="393032802"/> <reference key="NSDestination" ref="141316080"/> - <string key="NSLabel">enabled: arrangedObjects.AC3Enabled</string> + <string key="NSLabel">enabled: arrangedObjects.DRCEnabled</string> <string key="NSBinding">enabled</string> - <string key="NSKeyPath">arrangedObjects.AC3Enabled</string> + <string key="NSKeyPath">arrangedObjects.DRCEnabled</string> <int key="NSNibBindingConnectorVersion">2</int> </object> </object> diff --git a/macosx/HBAudio.m b/macosx/HBAudio.m index 514096cf6..91e18f9d8 100644 --- a/macosx/HBAudio.m +++ b/macosx/HBAudio.m @@ -564,16 +564,17 @@ static NSMutableArray *masterBitRateArray = nil; return retval; } -- (BOOL) AC3Enabled +- (BOOL) DRCEnabled { BOOL retval = [self enabled]; if (retval) { + int myTrackParam = [[[self track] objectForKey: keyAudioInputCodecParam] intValue]; int myTrackCodec = [[[self track] objectForKey: keyAudioInputCodec] intValue]; int myCodecCodec = [[[self codec] objectForKey: keyAudioCodec] intValue]; - if (HB_ACODEC_AC3 != myTrackCodec || HB_ACODEC_AC3_PASS == myCodecCodec) + if (!hb_audio_can_apply_drc(myTrackCodec, myTrackParam, myCodecCodec)) { retval = NO; } @@ -610,7 +611,7 @@ static NSMutableArray *masterBitRateArray = nil; { retval = [NSSet setWithObjects: @"track", @"codec", nil]; } - else if ([key isEqualToString: @"AC3Enabled"]) + else if ([key isEqualToString: @"DRCEnabled"]) { retval = [NSSet setWithObjects: @"track", @"codec", nil]; } diff --git a/macosx/HBAudioController.h b/macosx/HBAudioController.h index 3b0d884b1..c35f5dac9 100644 --- a/macosx/HBAudioController.h +++ b/macosx/HBAudioController.h @@ -13,6 +13,7 @@ extern NSString *keyAudioTrackName; extern NSString *keyAudioInputBitrate; extern NSString *keyAudioInputSampleRate; extern NSString *keyAudioInputCodec; +extern NSString *keyAudioInputCodecParam; extern NSString *keyAudioInputChannelLayout; extern NSString *HBMixdownChangedNotification; diff --git a/macosx/HBAudioController.m b/macosx/HBAudioController.m index 983002306..80ad96c31 100644 --- a/macosx/HBAudioController.m +++ b/macosx/HBAudioController.m @@ -15,6 +15,7 @@ NSString *keyAudioTrackName = @"keyAudioTrackName"; NSString *keyAudioInputBitrate = @"keyAudioInputBitrate"; NSString *keyAudioInputSampleRate = @"keyAudioInputSampleRate"; NSString *keyAudioInputCodec = @"keyAudioInputCodec"; +NSString *keyAudioInputCodecParam = @"keyAudioInputCodecParam"; NSString *keyAudioInputChannelLayout = @"keyAudioInputChannelLayout"; NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; @@ -112,8 +113,9 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; [aDict setObject: [NSNumber numberWithInt:0] forKey: [prefix stringByAppendingString: @"TrackGainSlider"]]; } - if ((HB_ACODEC_AC3 == [[[anAudio track] objectForKey: keyAudioInputCodec] intValue]) && - (HB_ACODEC_AC3_PASS != [[[anAudio codec] objectForKey: keyAudioCodec] intValue])) + if (hb_audio_can_apply_drc([[[anAudio track] objectForKey: keyAudioInputCodec] intValue], + [[[anAudio track] objectForKey: keyAudioInputCodecParam] intValue], + [[[anAudio codec] objectForKey: keyAudioCodec] intValue])) { [aDict setObject: [anAudio drc] forKey: [prefix stringByAppendingString: @"TrackDRCSlider"]]; } @@ -609,6 +611,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; [NSNumber numberWithInt: audio->in.bitrate / 1000], keyAudioInputBitrate, [NSNumber numberWithInt: audio->in.samplerate], keyAudioInputSampleRate, [NSNumber numberWithInt: audio->in.codec], keyAudioInputCodec, + [NSNumber numberWithInt: audio->in.codec_param], keyAudioInputCodecParam, [NSNumber numberWithUnsignedLongLong: audio->in.channel_layout], keyAudioInputChannelLayout, nil]]; } |