diff options
Diffstat (limited to 'gtk/src')
-rw-r--r-- | gtk/src/audiohandler.c | 36 | ||||
-rw-r--r-- | gtk/src/hb-backend.c | 158 | ||||
-rw-r--r-- | gtk/src/hb-backend.h | 7 | ||||
-rw-r--r-- | gtk/src/queuehandler.c | 17 |
4 files changed, 93 insertions, 125 deletions
diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c index 8be0cd82f..c7bdb63c1 100644 --- a/gtk/src/audiohandler.c +++ b/gtk/src/audiohandler.c @@ -225,7 +225,7 @@ audio_sanitize_settings(GValue *settings, GValue *asettings) acodec = ghb_settings_audio_encoder_codec(asettings, "AudioEncoder"); mix = ghb_settings_mixdown_mix(asettings, "AudioMixdown"); bitrate = ghb_settings_combo_int(asettings, "AudioBitrate"); - sr = ghb_settings_combo_int(asettings, "AudioSamplerate"); + sr = ghb_settings_audio_samplerate_rate(asettings, "AudioSamplerate"); aconfig = ghb_get_audio_info(title, track); if (sr == 0) @@ -248,7 +248,7 @@ audio_sanitize_settings(GValue *settings, GValue *asettings) hb_mixdown_get_short_name(mix)); select_acodec &= aconfig->in.codec | HB_ACODEC_PASS_FLAG; ghb_settings_set_string(asettings, "AudioSamplerate", - ghb_lookup_combo_string("AudioSamplerate", ghb_int_value(0))); + ghb_audio_samplerate_get_short_name(0)); } else { @@ -256,7 +256,7 @@ audio_sanitize_settings(GValue *settings, GValue *asettings) ghb_settings_set_string(asettings, "AudioMixdown", hb_mixdown_get_short_name(mix)); ghb_settings_set_string(asettings, "AudioSamplerate", - ghb_lookup_combo_string("AudioSamplerate", ghb_int_value(0))); + ghb_audio_samplerate_get_short_name(0)); bitrate = 448; } ghb_settings_set_double(asettings, "AudioTrackDRCSlider", 0.0); @@ -310,10 +310,7 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) bitrate = ghb_lookup_combo_int("AudioBitrate", gval); ghb_value_free(gval); - widget = GHB_WIDGET(ud->builder, "AudioSamplerate"); - gval = ghb_widget_value(widget); - sr = ghb_lookup_combo_int("AudioSamplerate", gval); - ghb_value_free(gval); + sr = ghb_settings_audio_samplerate_rate(ud->settings, "AudioSamplerate"); aconfig = ghb_get_audio_info(title, track); if (sr == 0) @@ -338,11 +335,15 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) ghb_string_value(hb_mixdown_get_short_name(mix))); select_acodec &= aconfig->in.codec | HB_ACODEC_PASS_FLAG; codec_defined_bitrate = TRUE; - ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(0)); + ghb_ui_update(ud, "AudioSamplerate", + ghb_string_value( + ghb_audio_samplerate_get_short_name(0))); } else { - ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(0)); + ghb_ui_update(ud, "AudioSamplerate", + ghb_string_value( + ghb_audio_samplerate_get_short_name(0))); mix = HB_AMIXDOWN_NONE; ghb_ui_update(ud, "AudioMixdown", ghb_string_value(hb_mixdown_get_short_name(mix))); @@ -481,7 +482,7 @@ audio_add_track( ghb_lookup_combo_string("AudioBitrate", ghb_int_value(bitrate))); ghb_settings_set_string(asettings, "AudioSamplerate", - ghb_lookup_combo_string("AudioSamplerate", ghb_int_value(samplerate))); + ghb_audio_samplerate_get_short_name(samplerate)); if (aconfig != NULL) { @@ -531,7 +532,7 @@ audio_select_and_add_track( fallback = ghb_select_fallback(settings, acodec); bitrate = ghb_settings_combo_int(audio, "AudioBitrate"); - samplerate = ghb_settings_combo_int(audio, "AudioSamplerate"); + samplerate = ghb_settings_audio_samplerate_rate(audio, "AudioSamplerate"); mix = ghb_settings_mixdown_mix(audio, "AudioMixdown"); drc = ghb_settings_get_double(audio, "AudioTrackDRCSlider"); gain = ghb_settings_get_double(audio, "AudioTrackGainSlider"); @@ -598,7 +599,8 @@ static void set_pref_audio_with_lang( fallback = ghb_select_fallback(settings, acodec); copy_mask = ghb_get_copy_mask(settings); bitrate = ghb_settings_combo_int(audio, "AudioBitrate"); - samplerate = ghb_settings_combo_int(audio, "AudioSamplerate"); + samplerate = ghb_settings_audio_samplerate_rate(audio, + "AudioSamplerate"); mix = ghb_settings_mixdown_mix(audio, "AudioMixdown"); drc = ghb_settings_get_double(audio, "AudioTrackDRCSlider"); gain = ghb_settings_get_double(audio, "AudioTrackGainSlider"); @@ -791,7 +793,7 @@ audio_refresh_list_row_ui( ghb_settings_combo_option(settings, "AudioBitrate")); } - sr = ghb_settings_combo_int(settings, "AudioSamplerate"); + sr = ghb_settings_audio_samplerate_rate(settings, "AudioSamplerate"); if (sr == 0) { sr = aconfig->in.samplerate; @@ -997,7 +999,8 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud) if (asettings != NULL) { br = ghb_settings_get_int(asettings, "AudioBitrate"); - sr = ghb_settings_combo_int(asettings, "AudioSamplerate"); + sr = ghb_settings_audio_samplerate_rate(asettings, + "AudioSamplerate"); mix = ghb_settings_mixdown_mix(asettings, "AudioMixdown"); } else @@ -1012,7 +1015,8 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud) { sr = ghb_find_closest_audio_samplerate(sr); } - ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(sr)); + ghb_ui_update(ud, "AudioSamplerate", + ghb_string_value(ghb_audio_samplerate_get_short_name(sr))); hb_audio_config_t *aconfig; aconfig = ghb_get_audio_info(title, track); @@ -2147,7 +2151,7 @@ void audio_def_set_limits(signal_user_data_t *ud, GtkWidget *widget) { enc = ghb_select_fallback(ud->settings, enc); } - int sr = ghb_settings_combo_int(adict, "AudioSamplerate"); + int sr = ghb_settings_audio_samplerate_rate(adict, "AudioSamplerate"); if (sr == 0) { sr = 48000; diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index 114881a0e..86d1b7a1e 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -861,75 +861,6 @@ lookup_generic_option(combo_opts_t *opts, const GValue *gval) return result; } -static const hb_rate_t * -lookup_audio_samplerate(const GValue *grate) -{ - const hb_rate_t *rate; - - if (G_VALUE_TYPE(grate) == G_TYPE_STRING) - { - // Coincidentally, the string "source" will return 0 - // which is our flag to use "same as source" - gchar * str = ghb_value_string(grate); - for (rate = hb_audio_samplerate_get_next(NULL); rate != NULL; - rate = hb_audio_samplerate_get_next(rate)) - { - if (strcmp(rate->name, str) == 0) - { - g_free(str); - return rate; - } - } - g_free(str); - } - else if (G_VALUE_TYPE(grate) == G_TYPE_INT || - G_VALUE_TYPE(grate) == G_TYPE_INT64 || - G_VALUE_TYPE(grate) == G_TYPE_DOUBLE) - { - gint val = ghb_value_int(grate); - for (rate = hb_audio_samplerate_get_next(NULL); rate != NULL; - rate = hb_audio_samplerate_get_next(rate)) - { - if (val == rate->rate) - { - return rate; - } - } - } - return NULL; -} - -static gint -lookup_audio_samplerate_int(const GValue *grate) -{ - const hb_rate_t *rate = lookup_audio_samplerate(grate); - if (rate != NULL) - return rate->rate; - return 0; -} - -static const gchar* -lookup_audio_samplerate_def(const GValue *grate, const char *def) -{ - const gchar *result = def; - const hb_rate_t *rate = lookup_audio_samplerate(grate); - if (rate != NULL) - return rate->name; - return result; -} - -static const gchar* -lookup_audio_samplerate_option(const GValue *grate) -{ - return lookup_audio_samplerate_def(grate, "Same as Source"); -} - -static const gchar* -lookup_audio_samplerate_string(const GValue *grate) -{ - return lookup_audio_samplerate_def(grate, "source"); -} - gint ghb_find_closest_audio_samplerate(gint irate) { @@ -1378,25 +1309,72 @@ ghb_audio_samplerate_opts_set(GtkComboBox *combo) } } +static void +audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name) +{ + g_debug("audio_samplerate_opts_set ()\n"); + GtkComboBox *combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name)); + ghb_audio_samplerate_opts_set(combo); +} + +const hb_rate_t sas_rate = +{ + .name = N_("Same as source"), + .rate = 0, +}; + +const char* +ghb_audio_samplerate_get_short_name(int rate) +{ + const char *name; + name = hb_audio_samplerate_get_name(rate); + if (name == NULL) + name = "source"; + return name; +} + const hb_rate_t* -ghb_lookup_samplerate(const char *name) +ghb_lookup_audio_samplerate(const char *name) { - const hb_rate_t *rate; - for (rate = hb_audio_samplerate_get_next(NULL); rate != NULL; - rate = hb_audio_samplerate_get_next(rate)) + // Check for special "Same as source" value + if (!strncmp(name, "source", 8)) + return &sas_rate; + + // First find an enabled rate + int rate = hb_audio_samplerate_get_from_name(name); + + // Now find the matching rate info + const hb_rate_t *hb_rate, *first; + for (first = hb_rate = hb_audio_samplerate_get_next(NULL); hb_rate != NULL; + hb_rate = hb_audio_samplerate_get_next(hb_rate)) { - if (!strncmp(name, rate->name, 80)) - return rate; + if (rate == hb_rate->rate) + { + return hb_rate; + } } - return NULL; + // Return a default rate if nothing matches + return first; } -static void -audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name) +int +ghb_lookup_audio_samplerate_rate(const char *name) { - g_debug("audio_samplerate_opts_set ()\n"); - GtkComboBox *combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name)); - ghb_audio_samplerate_opts_set(combo); + return ghb_lookup_audio_samplerate(name)->rate; +} + +int +ghb_settings_audio_samplerate_rate(const GValue *settings, const char *name) +{ + const char *rate_id = ghb_settings_get_const_string(settings, name); + return ghb_lookup_audio_samplerate_rate(rate_id); +} + +const hb_rate_t* +ghb_settings_audio_samplerate(const GValue *settings, const char *name) +{ + const char *rate_id = ghb_settings_get_const_string(settings, name); + return ghb_lookup_audio_samplerate(rate_id); } static void @@ -1450,12 +1428,6 @@ video_framerate_opts_set(GtkBuilder *builder, const gchar *name) } } -const hb_rate_t sas_rate = -{ - .name = N_("Same as source"), - .rate = 0, -}; - const hb_rate_t* ghb_lookup_video_framerate(const char *name) { @@ -2526,8 +2498,6 @@ ghb_lookup_combo_int(const gchar *name, const GValue *gval) return 0; if (strcmp(name, "AudioBitrate") == 0) return lookup_audio_bitrate_int(gval); - else if (strcmp(name, "AudioSamplerate") == 0) - return lookup_audio_samplerate_int(gval); else if (strcmp(name, "SrtLanguage") == 0) return lookup_audio_lang_int(gval); else @@ -2545,8 +2515,6 @@ ghb_lookup_combo_double(const gchar *name, const GValue *gval) return 0; if (strcmp(name, "AudioBitrate") == 0) return lookup_audio_bitrate_int(gval); - else if (strcmp(name, "AudioSamplerate") == 0) - return lookup_audio_samplerate_int(gval); else if (strcmp(name, "SrtLanguage") == 0) return lookup_audio_lang_int(gval); else @@ -2564,8 +2532,6 @@ ghb_lookup_combo_option(const gchar *name, const GValue *gval) return NULL; if (strcmp(name, "AudioBitrate") == 0) return lookup_audio_bitrate_option(gval); - else if (strcmp(name, "AudioSamplerate") == 0) - return lookup_audio_samplerate_option(gval); else if (strcmp(name, "SrtLanguage") == 0) return lookup_audio_lang_option(gval); else @@ -2583,8 +2549,6 @@ ghb_lookup_combo_string(const gchar *name, const GValue *gval) return NULL; if (strcmp(name, "AudioBitrate") == 0) return lookup_audio_bitrate_option(gval); - else if (strcmp(name, "AudioSamplerate") == 0) - return lookup_audio_samplerate_string(gval); else if (strcmp(name, "SrtLanguage") == 0) return lookup_audio_lang_option(gval); else @@ -4702,7 +4666,9 @@ add_job(hb_handle_t *h, GValue *js, gint unique_id, int titleindex) // Make sure the mixdown is valid and pick a new one if not. audio.out.mixdown = ghb_get_best_mix(aconfig, audio.out.codec, audio.out.mixdown); - gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate"); + gint srate; + srate = ghb_settings_audio_samplerate_rate( + asettings, "AudioSamplerate"); if (srate == 0) // 0 is same as source audio.out.samplerate = aconfig->in.samplerate; else diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h index 8445c28d2..11ec4ac07 100644 --- a/gtk/src/hb-backend.h +++ b/gtk/src/hb-backend.h @@ -193,5 +193,12 @@ int ghb_lookup_video_framerate_rate(const char *name); int ghb_settings_video_framerate_rate(const GValue *settings, const char *name); const hb_rate_t* ghb_settings_video_framerate( const GValue *settings, const char *name); +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 GValue *settings, const char *name); +const hb_rate_t* ghb_settings_audio_samplerate( + const GValue *settings, const char *name); +const char* ghb_audio_samplerate_get_short_name(int rate); #endif // _HBBACKEND_H_ diff --git a/gtk/src/queuehandler.c b/gtk/src/queuehandler.c index e7f8788cd..55e712892 100644 --- a/gtk/src/queuehandler.c +++ b/gtk/src/queuehandler.c @@ -530,9 +530,8 @@ add_to_queue_list(signal_user_data_t *ud, GValue *settings, GtkTreeIter *piter) } for (ii = 0; ii < count; ii++) { - gchar *quality = NULL, *samplerate, *track; + gchar *quality = NULL, *track; GValue *asettings; - gdouble sr; const hb_encoder_t *audio_encoder; asettings = ghb_array_get_nth(audio_list, ii); @@ -551,15 +550,8 @@ add_to_queue_list(signal_user_data_t *ud, GValue *settings, GtkTreeIter *piter) quality = g_strdup_printf("Bitrate: %s", br); g_free(br); } - sr = ghb_settings_get_double(asettings, "AudioSamplerate"); - if ((int)sr == 0) - { - samplerate = g_strdup("Same As Source"); - } - else - { - samplerate = g_strdup_printf("%.4g", sr); - } + const hb_rate_t *sr; + sr = ghb_settings_audio_samplerate(asettings, "AudioSamplerate"); track = ghb_settings_get_string(asettings, "AudioTrackDescription"); const hb_mixdown_t *mix; mix = ghb_settings_mixdown(asettings, "AudioMixdown"); @@ -575,11 +567,10 @@ add_to_queue_list(signal_user_data_t *ud, GValue *settings, GtkTreeIter *piter) { XPRINT( "<small>%s, Encoder: %s, Mixdown: %s, SampleRate: %s, %s</small>\n", - track, audio_encoder->name, mix->name, samplerate, quality); + track, audio_encoder->name, mix->name, sr->name, quality); } g_free(track); g_free(quality); - g_free(samplerate); } // Next line in the display (Subtitle) |