From e4c5f142c7a496f3f1f40faf52d9e0defa79ff49 Mon Sep 17 00:00:00 2001 From: jstebbins Date: Mon, 18 May 2015 20:12:26 +0000 Subject: LinGui: more audio refactoring Since the audio list is now in the proper format for json job, simply copy the audio list when creating the job. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7209 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- gtk/src/audiohandler.c | 326 ++++++++++++++++++++++++++----------------------- gtk/src/hb-backend.c | 224 ++------------------------------- gtk/src/hb-backend.h | 7 +- gtk/src/queuehandler.c | 12 +- 4 files changed, 196 insertions(+), 373 deletions(-) (limited to 'gtk/src') diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c index 45f70d923..054bf59bf 100644 --- a/gtk/src/audiohandler.c +++ b/gtk/src/audiohandler.c @@ -220,10 +220,12 @@ ghb_sanitize_audio_settings(GhbValue *settings, GhbValue *asettings) { int title_id, titleindex; const hb_title_t *title; - gint track, acodec, select_acodec, mix; + gint track, acodec, mix; + double quality; hb_audio_config_t *aconfig; gint bitrate; gint sr; + gboolean qe; const char *mux_id; const hb_container_t *mux; @@ -237,50 +239,98 @@ ghb_sanitize_audio_settings(GhbValue *settings, GhbValue *asettings) track = ghb_dict_get_int(asettings, "Track"); acodec = ghb_settings_audio_encoder_codec(asettings, "Encoder"); mix = ghb_settings_mixdown_mix(asettings, "Mixdown"); - bitrate = ghb_settings_audio_bitrate_rate(asettings, "Bitrate"); - sr = ghb_settings_audio_samplerate_rate(asettings, "Samplerate"); + bitrate = ghb_dict_get_int(asettings, "Bitrate"); + quality = ghb_dict_get_double(asettings, "Quality"); + sr = ghb_dict_get_int(asettings, "Samplerate"); + qe = ghb_dict_get_bool(asettings, "QualityEnable"); aconfig = ghb_get_audio_info(title, track); - if (sr == 0) + if (sr == 0 && aconfig != NULL) { - sr = aconfig ? aconfig->in.samplerate : 48000; + sr = aconfig->in.samplerate; } gint fallback = ghb_select_fallback(settings, acodec); gint copy_mask = ghb_get_copy_mask(settings); - select_acodec = ghb_select_audio_codec(mux->format, aconfig, acodec, - fallback, copy_mask); - if (ghb_audio_is_passthru(select_acodec)) + acodec = ghb_select_audio_codec(mux->format, aconfig, acodec, + fallback, copy_mask); + if (ghb_audio_is_passthru(acodec)) + { + mix = HB_AMIXDOWN_NONE; + ghb_dict_set_string(asettings, "Mixdown", + hb_mixdown_get_short_name(mix)); + ghb_dict_set(asettings, "Samplerate", ghb_int_value_new(0)); + ghb_dict_set_double(asettings, "DRC", 0.0); + } + else { - if (aconfig) + if (mix == HB_AMIXDOWN_NONE) + mix = ghb_get_best_mix(aconfig, acodec, mix); + if (qe) { - bitrate = aconfig->in.bitrate / 1000; - - // Set the values for bitrate and samplerate to the input rates - select_acodec &= aconfig->in.codec | HB_ACODEC_PASS_FLAG; + float low, high, gran; + int dir; + hb_audio_quality_get_limits(acodec, &low, &high, &gran, &dir); + if (quality < low || quality > high) + { + quality = hb_audio_quality_get_default(acodec); + } + else + { + quality = hb_audio_quality_get_best(acodec, quality); + } } else { - bitrate = 448; + if (bitrate != -1) + { + bitrate = hb_audio_bitrate_get_best(acodec, bitrate, sr, mix); + } + else + { + bitrate = hb_audio_bitrate_get_default(acodec, sr, mix); + } } - mix = HB_AMIXDOWN_NONE; ghb_dict_set_string(asettings, "Mixdown", - hb_mixdown_get_short_name(mix)); - ghb_dict_set_string(asettings, "Samplerate", - ghb_audio_samplerate_get_short_name(0)); - ghb_dict_set_double(asettings, "DRC", 0.0); + hb_mixdown_get_short_name(mix)); + } + if (qe) + { + bitrate = -1; } else { - if (mix == HB_AMIXDOWN_NONE) - mix = ghb_get_best_mix(aconfig, select_acodec, mix); - bitrate = hb_audio_bitrate_get_best(select_acodec, bitrate, sr, mix); - ghb_dict_set_string(asettings, "Mixdown", - hb_mixdown_get_short_name(mix)); + quality = HB_INVALID_AUDIO_QUALITY; } - ghb_dict_set_string(asettings, "Bitrate", - ghb_audio_bitrate_get_short_name(bitrate)); + ghb_dict_set_int(asettings, "Quality", quality); + ghb_dict_set_int(asettings, "Bitrate", bitrate); ghb_dict_set_string(asettings, "Encoder", - hb_audio_encoder_get_short_name(select_acodec)); + hb_audio_encoder_get_short_name(acodec)); +} + +static gdouble get_quality(int codec, gdouble quality) +{ + float low, high, gran; + int dir; + hb_audio_quality_get_limits(codec, &low, &high, &gran, &dir); + if (dir) + { + // Quality values are inverted + quality = high - quality + low; + } + return quality; +} + +static char * get_quality_string(int codec, gdouble quality) +{ + char *s_quality = ghb_format_quality("", codec, quality); + return s_quality; +} + +static gdouble get_ui_quality(GhbValue *settings) +{ + int codec = ghb_settings_audio_encoder_codec(settings, "Encoder"); + gdouble quality = ghb_dict_get_double(settings, "Quality"); + return get_quality(codec, quality); } static void @@ -294,7 +344,6 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) int track, title_id, mix, acodec; const hb_title_t *title; hb_audio_config_t *aconfig; - gboolean codec_defined_bitrate = FALSE; title_id = ghb_dict_get_int(ud->settings, "title"); title = ghb_lookup_title(title_id, NULL); @@ -303,32 +352,25 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) acodec = ghb_settings_audio_encoder_codec(asettings, "Encoder"); mix = ghb_settings_mixdown_mix(asettings, "Mixdown"); - if (ghb_audio_is_passthru(acodec)) - { - if (aconfig) - { - int bitrate = aconfig->in.bitrate / 1000; - ghb_set_bitrate_opts(ud->builder, bitrate, bitrate, bitrate); - codec_defined_bitrate = TRUE; - } - } - if (!codec_defined_bitrate) + + int low, high, sr; + sr = ghb_dict_get_int(asettings, "Samplerate"); + if (sr == 0 && aconfig != NULL) { - int low, high, sr; - sr = ghb_settings_audio_samplerate_rate(asettings, - "Samplerate"); - if (sr == 0) - { - sr = aconfig ? aconfig->in.samplerate : 48000; - } - mix = ghb_get_best_mix(aconfig, acodec, mix); - hb_audio_bitrate_get_limits(acodec, sr, mix, &low, &high); - ghb_set_bitrate_opts(ud->builder, low, high, -1); + sr = aconfig->in.samplerate; } + mix = ghb_get_best_mix(aconfig, acodec, mix); + hb_audio_bitrate_get_limits(acodec, sr, mix, &low, &high); + + GtkWidget *w = GHB_WIDGET(ud->builder, "AudioBitrate"); + ghb_audio_bitrate_opts_filter(GTK_COMBO_BOX(w), low, high); + ghb_ui_update(ud, "AudioEncoder", ghb_dict_get_value(asettings, "Encoder")); ghb_ui_update(ud, "AudioBitrate", ghb_dict_get_value(asettings, "Bitrate")); + gdouble quality = get_ui_quality(asettings); + ghb_ui_update(ud, "AudioTrackQualityX", ghb_double_value_new(quality)); ghb_ui_update(ud, "AudioSamplerate", ghb_dict_get_value(asettings, "Samplerate")); ghb_ui_update(ud, "AudioMixdown", @@ -359,6 +401,8 @@ void ghb_santiize_audio_tracks(signal_user_data_t *ud) ghb_dict_get_value(asettings, "Encoder")); ghb_ui_update(ud, "AudioBitrate", ghb_dict_get_value(asettings, "Bitrate")); + gdouble quality = get_ui_quality(asettings); + ghb_ui_update(ud, "AudioTrackQualityX", ghb_double_value_new(quality)); ghb_ui_update(ud, "AudioSamplerate", ghb_dict_get_value(asettings, "Samplerate")); ghb_ui_update(ud, "AudioMixdown", @@ -388,25 +432,6 @@ static char * get_gain_string(gdouble gain) return s_gain; } -static gdouble get_quality(int codec, gdouble quality) -{ - float low, high, gran; - int dir; - hb_audio_quality_get_limits(codec, &low, &high, &gran, &dir); - if (dir) - { - // Quality values are inverted - quality = high - quality + low; - } - return quality; -} - -static char * get_quality_string(int codec, gdouble quality) -{ - char *s_quality = ghb_format_quality("", codec, quality); - return s_quality; -} - static void audio_update_dialog_widgets(signal_user_data_t *ud, GhbValue *asettings) { @@ -414,6 +439,7 @@ audio_update_dialog_widgets(signal_user_data_t *ud, GhbValue *asettings) { double gain, drc, quality, qualityx; char *s_gain, *s_drc, *s_quality; + gboolean qe; block_updates = TRUE; ghb_ui_update(ud, "AudioTrack", @@ -422,8 +448,15 @@ audio_update_dialog_widgets(signal_user_data_t *ud, GhbValue *asettings) ghb_dict_get_value(asettings, "Encoder")); ghb_ui_update(ud, "AudioBitrate", ghb_dict_get_value(asettings, "Bitrate")); - ghb_ui_update(ud, "AudioTrackName", - ghb_dict_get_value(asettings, "Name")); + GhbValue *val = ghb_dict_get_value(asettings, "Name"); + if (val != NULL) + { + ghb_ui_update(ud, "AudioTrackName", val); + } + else + { + ghb_ui_update(ud, "AudioTrackName", ghb_string_value("")); + } ghb_ui_update(ud, "AudioSamplerate", ghb_dict_get_value(asettings, "Samplerate")); ghb_ui_update(ud, "AudioMixdown", @@ -445,8 +478,19 @@ audio_update_dialog_widgets(signal_user_data_t *ud, GhbValue *asettings) ghb_ui_update(ud, "AudioTrackQualityX", ghb_double_value_new(qualityx)); s_quality = get_quality_string(codec, quality); ghb_ui_update(ud, "AudioTrackQualityValue", ghb_string_value(s_quality)); - ghb_ui_update(ud, "AudioTrackQualityEnable", - ghb_dict_get_value(asettings, "QualityEnable")); + // Setting a radio button to FALSE does not automatically make + // the other one TRUE + qe = ghb_dict_get_bool(asettings, "QualityEnable"); + if (qe) + { + ghb_ui_update(ud, "AudioTrackQualityEnable", + ghb_bool_value_new(qe)); + } + else + { + ghb_ui_update(ud, "AudioTrackBitrateEnable", + ghb_bool_value_new(!qe)); + } block_updates = FALSE; } audio_deps(ud, asettings, NULL); @@ -512,28 +556,23 @@ audio_add_track( asettings = ghb_dict_new(); ghb_dict_set_int(asettings, "Track", track); - ghb_dict_set_string(asettings, "Encoder", hb_audio_encoder_get_short_name(encoder)); - ghb_dict_set_bool(asettings, "QualityEnable", enable_quality); ghb_dict_set_double(asettings, "Quality", quality); - - ghb_dict_set_string(asettings, "Bitrate", - ghb_audio_bitrate_get_short_name(bitrate)); - - ghb_dict_set_string(asettings, "Samplerate", - ghb_audio_samplerate_get_short_name(samplerate)); + if (enable_quality) + { + bitrate = -1; + } + ghb_dict_set_int(asettings, "Bitrate", bitrate); + ghb_dict_set_int(asettings, "Samplerate", samplerate); if (aconfig != NULL) { mix = ghb_get_best_mix(aconfig, encoder, mix); } - ghb_dict_set_string(asettings, "Mixdown", - hb_mixdown_get_short_name(mix)); - + ghb_dict_set_string(asettings, "Mixdown", hb_mixdown_get_short_name(mix)); ghb_dict_set_double(asettings, "DRC", drc); - ghb_dict_set_double(asettings, "Gain", gain); ghb_sanitize_audio_settings(settings, asettings); @@ -831,10 +870,10 @@ audio_refresh_list_row_ui( else { s_br_quality = g_strdup_printf(_("Bitrate: %dkbps"), - ghb_settings_audio_bitrate_rate(settings, "Bitrate")); + (int)ghb_dict_get_int(settings, "Bitrate")); } - sr = ghb_settings_audio_samplerate_rate(settings, "Samplerate"); + sr = ghb_dict_get_int(settings, "Samplerate"); if (sr == 0) { sr = aconfig->in.samplerate; @@ -1060,9 +1099,8 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud) if (asettings != NULL) { - br = ghb_settings_audio_bitrate_rate(asettings, "Bitrate"); - sr = ghb_settings_audio_samplerate_rate(asettings, - "Samplerate"); + br = ghb_dict_get_int(asettings, "Bitrate"); + sr = ghb_dict_get_int(asettings, "Samplerate"); mix = ghb_settings_mixdown_mix(asettings, "Mixdown"); } else @@ -1112,7 +1150,9 @@ audio_track_changed_cb(GtkWidget *widget, signal_user_data_t *ud) asettings = audio_get_selected_settings(ud, NULL); if (asettings != NULL) { - ghb_dict_set(asettings, "Track", ghb_widget_value(widget)); + GhbValue *val = ghb_widget_value(widget); + ghb_dict_set(asettings, "Track", ghb_value_xform(val, GHB_INT)); + ghb_value_free(&val); audio_deps(ud, asettings, widget); ghb_audio_list_refresh_selected(ud); ghb_live_reset(ud); @@ -1139,14 +1179,13 @@ audio_track_changed_cb(GtkWidget *widget, signal_user_data_t *ud) } void -audio_widget_changed_cb( - GtkWidget *widget, - const char *name, +audio_update_setting( + GhbValue *val, + const char *name, signal_user_data_t *ud) { GhbValue *asettings; - ghb_widget_to_setting(ud->settings, widget); if (block_updates) { return; @@ -1155,8 +1194,11 @@ audio_widget_changed_cb( asettings = audio_get_selected_settings(ud, NULL); if (asettings != NULL) { - ghb_dict_set(asettings, name, ghb_widget_value(widget)); - audio_deps(ud, asettings, widget); + if (val != NULL) + ghb_dict_set(asettings, name, val); + else + ghb_dict_remove(asettings, name); + audio_deps(ud, asettings, NULL); ghb_audio_list_refresh_selected(ud); ghb_live_reset(ud); } @@ -1165,31 +1207,55 @@ audio_widget_changed_cb( G_MODULE_EXPORT void audio_mix_changed_cb(GtkWidget *widget, signal_user_data_t *ud) { - audio_widget_changed_cb(widget, "Mixdown", ud); + ghb_widget_to_setting(ud->settings, widget); + audio_update_setting(ghb_widget_value(widget), "Mixdown", ud); } G_MODULE_EXPORT void audio_name_changed_cb(GtkWidget *widget, signal_user_data_t *ud) { - audio_widget_changed_cb(widget, "Name", ud); + ghb_widget_to_setting(ud->settings, widget); + const char *s = ghb_dict_get_string(ud->settings, "AudioTrackName"); + if (s != NULL && s[0] != 0) + { + audio_update_setting(ghb_widget_value(widget), "Name", ud); + } + else + { + audio_update_setting(NULL, "Name", ud); + } } G_MODULE_EXPORT void audio_bitrate_changed_cb(GtkWidget *widget, signal_user_data_t *ud) { - audio_widget_changed_cb(widget, "Bitrate", ud); + int br; + + ghb_widget_to_setting(ud->settings, widget); + br = ghb_settings_audio_bitrate_rate(ud->settings, "AudioBitrate"); + audio_update_setting(ghb_int_value_new(br), "Bitrate", ud); } G_MODULE_EXPORT void audio_samplerate_changed_cb(GtkWidget *widget, signal_user_data_t *ud) { - audio_widget_changed_cb(widget, "Samplerate", ud); + int sr; + + ghb_widget_to_setting(ud->settings, widget); + sr = ghb_settings_audio_samplerate_rate(ud->settings, "AudioSamplerate"); + audio_update_setting(ghb_int_value_new(sr), "Samplerate", ud); } G_MODULE_EXPORT void audio_quality_radio_changed_cb(GtkWidget *widget, signal_user_data_t *ud) { - audio_widget_changed_cb(widget, "QualityEnable", ud); + ghb_widget_to_setting(ud->settings, widget); + audio_update_setting(ghb_widget_value(widget), "QualityEnable", ud); + if (!ghb_dict_get_bool(ud->settings, "AudioQualityEnable")) + { + int br = ghb_settings_audio_bitrate_rate(ud->settings, "AudioBitrate"); + audio_update_setting(ghb_int_value_new(br), "Bitrate", ud); + } } G_MODULE_EXPORT void @@ -1236,13 +1302,7 @@ char * ghb_format_quality( const char *prefix, int codec, double quality ) G_MODULE_EXPORT void quality_widget_changed_cb(GtkWidget *widget, gdouble quality, signal_user_data_t *ud) { - GhbValue *asettings; - ghb_widget_to_setting(ud->settings, widget); - if (block_updates) - { - return; - } int codec = ghb_settings_audio_encoder_codec(ud->settings, "AudioEncoder"); quality = get_quality(codec, quality); @@ -1250,39 +1310,22 @@ quality_widget_changed_cb(GtkWidget *widget, gdouble quality, signal_user_data_t ghb_ui_update( ud, "AudioTrackQualityValue", ghb_string_value(s_quality)); g_free(s_quality); - asettings = audio_get_selected_settings(ud, NULL); - if (asettings != NULL) - { - ghb_dict_set_double(asettings, "Quality", quality); - audio_deps(ud, asettings, widget); - ghb_audio_list_refresh_selected(ud); - ghb_live_reset(ud); - } + audio_update_setting(ghb_double_value_new(quality), "Quality", ud); } G_MODULE_EXPORT void drc_widget_changed_cb(GtkWidget *widget, gdouble drc, signal_user_data_t *ud) { - GhbValue *asettings; - ghb_widget_to_setting(ud->settings, widget); - if (block_updates) - { - return; - } + + if (drc < 1.0) + drc = 0.0; char *s_drc = get_drc_string(drc); ghb_ui_update( ud, "AudioTrackDRCValue", ghb_string_value(s_drc)); g_free(s_drc); - asettings = audio_get_selected_settings(ud, NULL); - if (asettings != NULL) - { - ghb_dict_set(asettings, "DRC", ghb_widget_value(widget)); - audio_deps(ud, asettings, widget); - ghb_audio_list_refresh_selected(ud); - ghb_live_reset(ud); - } + audio_update_setting(ghb_double_value_new(drc), "DRC", ud); } G_MODULE_EXPORT gchar* @@ -1296,26 +1339,13 @@ format_gain_cb(GtkScale *scale, gdouble val, signal_user_data_t *ud) G_MODULE_EXPORT void gain_widget_changed_cb(GtkWidget *widget, gdouble gain, signal_user_data_t *ud) { - GhbValue *asettings; - ghb_widget_to_setting(ud->settings, widget); - if (block_updates) - { - return; - } char *s_gain = get_gain_string(gain); ghb_ui_update( ud, "AudioTrackGainValue", ghb_string_value(s_gain)); g_free(s_gain); - asettings = audio_get_selected_settings(ud, NULL); - if (asettings != NULL) - { - ghb_dict_set(asettings, "Gain", ghb_widget_value(widget)); - audio_deps(ud, asettings, widget); - ghb_audio_list_refresh_selected(ud); - ghb_live_reset(ud); - } + audio_update_setting(ghb_double_value_new(gain), "Gain", ud); } void @@ -1459,12 +1489,6 @@ audio_add_to_settings(GhbValue *settings, GhbValue *asettings) g_free(desc); } - GhbValue *aname; - aname = ghb_dict_get(asettings, "Name"); - if (aname == NULL) - { - ghb_dict_set_string(asettings, "Name", ""); - } ghb_array_append(audio_list, asettings); } @@ -1888,7 +1912,7 @@ GtkWidget * ghb_create_audio_settings_row(signal_user_data_t *ud) // Audio Bitrate ComboBox combo = GTK_COMBO_BOX(gtk_combo_box_new()); ghb_init_combo_box(combo); - ghb_audio_bitrate_opts_set(combo, FALSE); + ghb_audio_bitrate_opts_set(combo); ghb_update_widget(GTK_WIDGET(combo), ghb_int_value(192)); gtk_widget_set_tooltip_markup(GTK_WIDGET(combo), _("Set the bitrate to encode this track with.")); @@ -2238,10 +2262,6 @@ void audio_def_set_limits(signal_user_data_t *ud, GtkWidget *widget, gboolean se enc = ghb_select_fallback(ud->settings, enc); } int sr = ghb_settings_audio_samplerate_rate(adict, "AudioSamplerate"); - if (sr == 0) - { - sr = 48000; - } int mix = ghb_settings_mixdown_mix(adict, "AudioMixdown"); int low, high; hb_audio_bitrate_get_limits(enc, sr, mix, &low, &high); diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index 89e0bb946..b0223106d 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -1014,19 +1014,6 @@ fail: return "und"; } -static gint -search_audio_bitrates(gint rate) -{ - const hb_rate_t *hbrate; - for (hbrate = hb_audio_bitrate_get_next(NULL); hbrate != NULL; - hbrate = hb_audio_bitrate_get_next(hbrate)) - { - if (hbrate->rate == rate) - return 1; - } - return 0; -} - static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter); static void @@ -2845,51 +2832,6 @@ ghb_get_chapters(const hb_title_t *title) return chapters; } -static char custom_audio_bitrate_str[8]; -static hb_rate_t custom_audio_bitrate = -{ - .name = custom_audio_bitrate_str, - .rate = 0 -}; - -static void -audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate) -{ - GtkTreeIter iter; - GtkListStore *store; - gchar *str; - - g_debug("audio_bitrate_opts_add ()\n"); - - if (rate >= 0 && rate < 8) return; - - custom_audio_bitrate.rate = rate; - if (rate < 0) - { - snprintf(custom_audio_bitrate_str, 8, _("N/A")); - } - else - { - snprintf(custom_audio_bitrate_str, 8, "%d", rate); - } - - GtkComboBox *combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name)); - store = GTK_LIST_STORE(gtk_combo_box_get_model (combo)); - if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter)) - { - str = g_strdup_printf ("%s", custom_audio_bitrate.name); - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, - 0, str, - 1, TRUE, - 2, custom_audio_bitrate.name, - 3, (gdouble)rate, - 4, custom_audio_bitrate.name, - -1); - g_free(str); - } -} - void ghb_audio_bitrate_opts_filter( GtkComboBox *combo, @@ -2921,52 +2863,8 @@ ghb_audio_bitrate_opts_filter( } } -static void -audio_bitrate_opts_update( - GtkBuilder *builder, - const gchar *name, - gint first_rate, - gint last_rate, - gint extra_rate) -{ - GtkTreeIter iter; - GtkListStore *store; - gdouble ivalue; - gboolean done = FALSE; - - g_debug("audio_bitrate_opts_clean ()\n"); - GtkComboBox *combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name)); - ghb_audio_bitrate_opts_filter(combo, first_rate, last_rate); - - store = GTK_LIST_STORE(gtk_combo_box_get_model (combo)); - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter)) - { - do - { - gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1); - if (!search_audio_bitrates(ivalue) && (ivalue != extra_rate)) - { - done = !gtk_list_store_remove(store, &iter); - } - else - { - done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); - } - } while (!done); - } - if (extra_rate > 0 && !search_audio_bitrates(extra_rate)) - { - audio_bitrate_opts_add(builder, name, extra_rate); - } - else - { - custom_audio_bitrate.rate = 0; - custom_audio_bitrate_str[0] = 0; - } -} - void -ghb_audio_bitrate_opts_set(GtkComboBox *combo, gboolean extra) +ghb_audio_bitrate_opts_set(GtkComboBox *combo) { GtkTreeIter iter; GtkListStore *store; @@ -2991,46 +2889,18 @@ ghb_audio_bitrate_opts_set(GtkComboBox *combo, gboolean extra) -1); g_free(str); } - if (extra && custom_audio_bitrate.rate != 0) - { - gtk_list_store_append(store, &iter); - str = g_strdup_printf ("%s", custom_audio_bitrate.name); - gtk_list_store_set(store, &iter, - 0, str, - 1, TRUE, - 2, custom_audio_bitrate.name, - 3, (gdouble)custom_audio_bitrate.rate, - 4, custom_audio_bitrate.name, - -1); - g_free(str); - } } static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name) { GtkComboBox *combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name)); - ghb_audio_bitrate_opts_set(combo, TRUE); -} - -void -ghb_set_bitrate_opts( - GtkBuilder *builder, - gint first_rate, - gint last_rate, - gint extra_rate) -{ - audio_bitrate_opts_update(builder, "AudioBitrate", first_rate, last_rate, extra_rate); + ghb_audio_bitrate_opts_set(combo); } const char* ghb_audio_bitrate_get_short_name(int rate) { - if (rate == custom_audio_bitrate.rate) - { - return custom_audio_bitrate.name; - } - const hb_rate_t *hb_rate, *first; for (first = hb_rate = hb_audio_bitrate_get_next(NULL); hb_rate != NULL; hb_rate = hb_audio_bitrate_get_next(hb_rate)) @@ -3047,8 +2917,8 @@ const hb_rate_t* ghb_lookup_audio_bitrate(const char *name) { // Now find the matching rate info - const hb_rate_t *hb_rate, *first; - for (first = hb_rate = hb_audio_bitrate_get_next(NULL); hb_rate != NULL; + const hb_rate_t *hb_rate; + for (hb_rate = hb_audio_bitrate_get_next(NULL); hb_rate != NULL; hb_rate = hb_audio_bitrate_get_next(hb_rate)) { if (!strncmp(name, hb_rate->name, 8)) @@ -3057,13 +2927,17 @@ ghb_lookup_audio_bitrate(const char *name) } } // Return a default rate if nothing matches - return first; + return NULL; } int ghb_lookup_audio_bitrate_rate(const char *name) { - return ghb_lookup_audio_bitrate(name)->rate; + const hb_rate_t *rate; + rate = ghb_lookup_audio_bitrate(name); + if (rate == NULL) + return 0; + return rate->rate; } int @@ -4084,14 +3958,6 @@ ghb_validate_audio(GhbValue *settings, GtkWindow *parent) ghb_dict_set_string(asettings, "Mixdown", hb_mixdown_get_short_name(amixdown)); } - int samplerate = ghb_settings_audio_samplerate_rate(asettings, - "Samplerate"); - if (samplerate == 0) - { - samplerate = aconfig->in.samplerate; - ghb_dict_set_string(asettings, "Samplerate", - ghb_audio_samplerate_get_short_name(samplerate)); - } } return TRUE; } @@ -4593,74 +4459,8 @@ add_job(hb_handle_t *h, GhbValue *js, gint unique_id) // Create audio list hb_dict_t *audios_dict = hb_dict_get(dict, "Audio"); - hb_value_array_t *json_audio_list = hb_dict_get(audios_dict, "AudioList"); - const GhbValue *audio_list; - - audio_list = ghb_dict_get_value(js, "audio_list"); - count = ghb_array_len(audio_list); - for (ii = 0; ii < count; ii++) - { - hb_dict_t *audio_dict; - GhbValue *asettings; - int track, acodec, mixdown, samplerate; - const char *aname; - double gain, drc, quality; - - asettings = ghb_array_get(audio_list, ii); - track = ghb_dict_get_int(asettings, "Track"); - aname = ghb_dict_get_string(asettings, "Name"); - acodec = ghb_settings_audio_encoder_codec(asettings, "Encoder"); - audio_dict = json_pack_ex(&error, 0, - "{s:o, s:o}", - "Track", hb_value_int(track), - "Encoder", hb_value_int(acodec)); - if (audio_dict == NULL) - { - g_warning("json pack audio failure: %s", error.text); - return; - } - if (aname != NULL && aname[0] != 0) - { - hb_dict_set(audio_dict, "Name", hb_value_string(aname)); - } - - // It would be better if this were done in libhb for us, but its not yet. - if (!ghb_audio_is_passthru(acodec)) - { - gain = ghb_dict_get_double(asettings, "Gain"); - if (gain > 0) - hb_dict_set(audio_dict, "Gain", hb_value_double(gain)); - drc = ghb_dict_get_double(asettings, "DRC"); - if (drc < 1.0) - drc = 0.0; - if (drc > 0) - hb_dict_set(audio_dict, "DRC", hb_value_double(drc)); - - mixdown = ghb_settings_mixdown_mix(asettings, "Mixdown"); - hb_dict_set(audio_dict, "Mixdown", hb_value_int(mixdown)); - - samplerate = ghb_settings_audio_samplerate_rate( - asettings, "Samplerate"); - hb_dict_set(audio_dict, "Samplerate", hb_value_int(samplerate)); - gboolean qe; - qe = ghb_dict_get_bool(asettings, "QualityEnable"); - quality = ghb_dict_get_double(asettings, "Quality"); - if (qe && quality != HB_INVALID_AUDIO_QUALITY) - { - hb_dict_set(audio_dict, "Quality", hb_value_double(quality)); - } - else - { - int bitrate = - ghb_settings_audio_bitrate_rate(asettings, "Bitrate"); - bitrate = hb_audio_bitrate_get_best( - acodec, bitrate, samplerate, mixdown); - hb_dict_set(audio_dict, "Bitrate", hb_value_int(bitrate)); - } - } - - hb_value_array_append(json_audio_list, audio_dict); - } + hb_dict_set(audios_dict, "AudioList", + ghb_value_dup(ghb_dict_get(js, "audio_list"))); // Create subtitle list hb_dict_t *subtitles_dict = hb_dict_get(dict, "Subtitle"); diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h index a9f35f341..0f5af71f4 100644 --- a/gtk/src/hb-backend.h +++ b/gtk/src/hb-backend.h @@ -126,8 +126,6 @@ gint ghb_get_best_mix(hb_audio_config_t *aconfig, gint acodec, gint mix); gboolean ghb_audio_is_passthru(gint acodec); gboolean ghb_audio_can_passthru(gint acodec); gint ghb_get_default_acodec(void); -void ghb_set_bitrate_opts( - GtkBuilder *builder, gint first_rate, gint last_rate, gint extra_rate); void ghb_grey_combo_options(signal_user_data_t *ud); void ghb_update_ui_combo_box( signal_user_data_t *ud, const gchar *name, @@ -163,7 +161,7 @@ void ghb_init_lang_list_box(GtkListBox *list_box); void ghb_init_combo_box(GtkComboBox *combo); void ghb_audio_encoder_opts_set(GtkComboBox *combo); -void ghb_audio_bitrate_opts_set(GtkComboBox *combo, gboolean extra); +void ghb_audio_bitrate_opts_set(GtkComboBox *combo); void ghb_audio_bitrate_opts_filter(GtkComboBox *combo, gint first_rate, gint last_rate); void ghb_mix_opts_set(GtkComboBox *combo); void ghb_mix_opts_filter(GtkComboBox *combo, gint acodec); @@ -201,12 +199,13 @@ const hb_rate_t* ghb_lookup_audio_samplerate(const char *name); int ghb_lookup_audio_samplerate_rate(const char *name); int ghb_settings_audio_samplerate_rate( const GhbValue *settings, const char *name); +int ghb_settings_audio_bitrate_rate( + const GhbValue *settings, const char *name); const hb_rate_t* ghb_settings_audio_samplerate( const GhbValue *settings, const char *name); const char* ghb_audio_samplerate_get_short_name(int rate); const hb_rate_t* ghb_lookup_audio_bitrate(const char *name); int ghb_lookup_audio_bitrate_rate(const char *name); -int ghb_settings_audio_bitrate_rate(const GhbValue *settings, const char *name); const hb_rate_t* ghb_settings_audio_bitrate( const GhbValue *settings, const char *name); const char* ghb_audio_bitrate_get_short_name(int rate); diff --git a/gtk/src/queuehandler.c b/gtk/src/queuehandler.c index 714bad3db..dcac384f0 100644 --- a/gtk/src/queuehandler.c +++ b/gtk/src/queuehandler.c @@ -562,11 +562,15 @@ add_to_queue_list(signal_user_data_t *ud, GhbValue *settings, GtkTreeIter *piter } else { - int br = ghb_settings_audio_bitrate_rate(asettings, "Bitrate"); + int br = ghb_dict_get_int(asettings, "Bitrate"); quality = g_strdup_printf(_("Bitrate: %d"), br); } - const hb_rate_t *sr; - sr = ghb_settings_audio_samplerate(asettings, "Samplerate"); + const char *sr_name; + int sr_rate = ghb_dict_get_int(asettings, "Samplerate"); + sr_name = hb_audio_samplerate_get_name(sr_rate); + if (sr_name == NULL) + sr_name = "Auto"; + track = ghb_dict_get_string(asettings, "Description"); const hb_mixdown_t *mix; mix = ghb_settings_mixdown(asettings, "Mixdown"); @@ -580,7 +584,7 @@ add_to_queue_list(signal_user_data_t *ud, GhbValue *settings, GtkTreeIter *piter else { XPRINT(_("%s --> Encoder: %s, Mixdown: %s, SampleRate: %s, %s"), - track, audio_encoder->name, mix->name, sr->name, quality); + track, audio_encoder->name, mix->name, sr_name, quality); } g_free(quality); } -- cgit v1.2.3