diff options
author | John Stebbins <[email protected]> | 2016-09-08 09:08:43 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2016-09-08 09:10:56 -0700 |
commit | 0b33dd8bb12afc94ee0616859b268b28a35d4906 (patch) | |
tree | 67d808016ef798e8dc3d009f67458b806658b5db /libhb | |
parent | e9b2d291789edf2d08453c6554e1594aedfd495d (diff) |
LinGui: fix some issues with reloading audio defaults
Reloading the audio defaults basically didn't work right. Some settings
didn't get loaded, some got loaded and not displayed or displayed wrong.
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/preset.c | 99 | ||||
-rw-r--r-- | libhb/preset.h | 2 |
2 files changed, 101 insertions, 0 deletions
diff --git a/libhb/preset.c b/libhb/preset.c index 8f6ccc07c..60f46b218 100644 --- a/libhb/preset.c +++ b/libhb/preset.c @@ -507,6 +507,101 @@ static int sanitize_audio_codec(int in_codec, int out_codec, return codec; } +void hb_sanitize_audio_settings(const hb_title_t * title, + hb_value_t * audio_settings) +{ + const char * mix_name; + const char * codec_name; + int track, codec, mix, bitrate, samplerate; + int quality_enable; + double quality; + hb_value_t * val; + hb_audio_config_t * audio_config = NULL; + + track = hb_dict_get_int(audio_settings, "Track"); + codec_name = hb_dict_get_string(audio_settings, "Encoder"); + codec = hb_audio_encoder_get_from_name(codec_name); + mix_name = hb_dict_get_string(audio_settings, "Mixdown"); + mix = hb_mixdown_get_from_name(mix_name); + bitrate = hb_dict_get_int(audio_settings, "Bitrate"); + quality = hb_dict_get_double(audio_settings, "Quality"); + samplerate = hb_dict_get_int(audio_settings, "Samplerate"); + val = hb_dict_get(audio_settings, "Quality"); + quality_enable = !(bitrate > 0 || val == NULL || + quality == HB_INVALID_AUDIO_QUALITY); + + if (title != NULL) + { + audio_config = hb_list_audio_config_item(title->list_audio, track); + } + if (samplerate == 0 && audio_config != NULL) + { + samplerate = audio_config->in.samplerate; + } + + if (codec & HB_ACODEC_PASS_FLAG) + { + mix = HB_AMIXDOWN_NONE; + hb_dict_set(audio_settings, "Mixdown", + hb_value_string(hb_mixdown_get_short_name(mix))); + hb_dict_set(audio_settings, "Samplerate", hb_value_int(0)); + hb_dict_set(audio_settings, "DRC", hb_value_double(0.0)); + } + else + { + int layout = AV_CH_LAYOUT_5POINT1; + if (audio_config != NULL) + { + layout = audio_config->in.channel_layout; + } + if (mix == HB_AMIXDOWN_NONE) + { + mix = HB_INVALID_AMIXDOWN; + } + mix = hb_mixdown_get_best(codec, layout, mix); + if (quality_enable) + { + float low, high, gran; + int dir; + hb_audio_quality_get_limits(codec, &low, &high, &gran, &dir); + if (quality < low || quality > high) + { + quality = hb_audio_quality_get_default(codec); + } + else + { + quality = hb_audio_quality_get_best(codec, quality); + } + } + else + { + if (bitrate != -1) + { + bitrate = hb_audio_bitrate_get_best(codec, bitrate, + samplerate, mix); + } + else + { + bitrate = hb_audio_bitrate_get_default(codec, samplerate, mix); + } + } + hb_dict_set(audio_settings, "Mixdown", + hb_value_string(hb_mixdown_get_short_name(mix))); + } + if (quality_enable) + { + bitrate = -1; + } + else + { + quality = HB_INVALID_AUDIO_QUALITY; + } + hb_dict_set(audio_settings, "Quality", hb_value_double(quality)); + hb_dict_set(audio_settings, "Bitrate", hb_value_int(bitrate)); + hb_dict_set(audio_settings, "Encoder", + hb_value_string(hb_audio_encoder_get_short_name(codec))); +} + static void add_audio_for_lang(hb_value_array_t *list, const hb_dict_t *preset, hb_title_t *title, int mux, int copy_mask, int fallback, const char *lang, @@ -616,6 +711,10 @@ static void add_audio_for_lang(hb_value_array_t *list, const hb_dict_t *preset, HB_VALUE_TYPE_INT)); } } + + // Sanitize the settings before adding to the audio list + hb_sanitize_audio_settings(title, audio_dict); + hb_value_array_append(list, audio_dict); } if (behavior == 2) diff --git a/libhb/preset.h b/libhb/preset.h index 25653ff62..0515b3cd1 100644 --- a/libhb/preset.h +++ b/libhb/preset.h @@ -149,6 +149,8 @@ int hb_preset_job_add_subtitles(hb_handle_t *h, int title_index, // Reinitialize audio from preset defaults. int hb_preset_job_add_audio(hb_handle_t *h, int title_index, const hb_dict_t *preset, hb_dict_t *job_dict); +void hb_sanitize_audio_settings(const hb_title_t * title, + hb_value_t * audio_settings); // Lookup a preset in the preset list. The "name" may contain '/' // separators to explicitely specify a preset within the preset lists |