diff options
Diffstat (limited to 'gtk/src/hb-backend.c')
-rw-r--r-- | gtk/src/hb-backend.c | 158 |
1 files changed, 62 insertions, 96 deletions
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 |