summaryrefslogtreecommitdiffstats
path: root/gtk/src
diff options
context:
space:
mode:
Diffstat (limited to 'gtk/src')
-rw-r--r--gtk/src/audiohandler.c31
-rw-r--r--gtk/src/hb-backend.c135
-rw-r--r--gtk/src/hb-backend.h6
-rw-r--r--gtk/src/queuehandler.c6
4 files changed, 100 insertions, 78 deletions
diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c
index c7bdb63c1..9364bd276 100644
--- a/gtk/src/audiohandler.c
+++ b/gtk/src/audiohandler.c
@@ -224,7 +224,7 @@ audio_sanitize_settings(GValue *settings, GValue *asettings)
track = ghb_settings_get_int(asettings, "AudioTrack");
acodec = ghb_settings_audio_encoder_codec(asettings, "AudioEncoder");
mix = ghb_settings_mixdown_mix(asettings, "AudioMixdown");
- bitrate = ghb_settings_combo_int(asettings, "AudioBitrate");
+ bitrate = ghb_settings_audio_bitrate_rate(asettings, "AudioBitrate");
sr = ghb_settings_audio_samplerate_rate(asettings, "AudioSamplerate");
aconfig = ghb_get_audio_info(title, track);
@@ -270,7 +270,7 @@ audio_sanitize_settings(GValue *settings, GValue *asettings)
hb_mixdown_get_short_name(mix));
}
ghb_settings_set_string(asettings, "AudioBitrate",
- ghb_lookup_combo_string("AudioBitrate", ghb_int_value(bitrate)));
+ ghb_audio_bitrate_get_short_name(bitrate));
ghb_settings_set_string(asettings, "AudioEncoder",
hb_audio_encoder_get_short_name(select_acodec));
@@ -304,12 +304,7 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud)
acodec = ghb_settings_audio_encoder_codec(ud->settings, "AudioEncoder");
mix = ghb_settings_mixdown_mix(ud->settings, "AudioMixdown");
-
- widget = GHB_WIDGET(ud->builder, "AudioBitrate");
- gval = ghb_widget_value(widget);
- bitrate = ghb_lookup_combo_int("AudioBitrate", gval);
- ghb_value_free(gval);
-
+ bitrate = ghb_settings_audio_bitrate_rate(ud->settings, "AudioBitrate");
sr = ghb_settings_audio_samplerate_rate(ud->settings, "AudioSamplerate");
aconfig = ghb_get_audio_info(title, track);
@@ -364,9 +359,10 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud)
int low, high;
mix = ghb_get_best_mix( aconfig, select_acodec, mix);
hb_audio_bitrate_get_limits(select_acodec, sr, mix, &low, &high);
- ghb_set_bitrate_opts (ud->builder, low, high, -1);
+ ghb_set_bitrate_opts(ud->builder, low, high, -1);
}
- ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(bitrate));
+ ghb_ui_update(ud, "AudioBitrate",
+ ghb_string_value(ghb_audio_bitrate_get_short_name(bitrate)));
ghb_settings_set_string(ud->settings, "AudioEncoder",
hb_audio_encoder_get_short_name(select_acodec));
@@ -479,7 +475,7 @@ audio_add_track(
ghb_settings_set_double(asettings, "AudioTrackQuality", quality);
ghb_settings_set_string(asettings, "AudioBitrate",
- ghb_lookup_combo_string("AudioBitrate", ghb_int_value(bitrate)));
+ ghb_audio_bitrate_get_short_name(bitrate));
ghb_settings_set_string(asettings, "AudioSamplerate",
ghb_audio_samplerate_get_short_name(samplerate));
@@ -531,7 +527,7 @@ audio_select_and_add_track(
acodec = ghb_settings_audio_encoder_codec(audio, "AudioEncoder");
fallback = ghb_select_fallback(settings, acodec);
- bitrate = ghb_settings_combo_int(audio, "AudioBitrate");
+ bitrate = ghb_settings_audio_bitrate_rate(audio, "AudioBitrate");
samplerate = ghb_settings_audio_samplerate_rate(audio, "AudioSamplerate");
mix = ghb_settings_mixdown_mix(audio, "AudioMixdown");
drc = ghb_settings_get_double(audio, "AudioTrackDRCSlider");
@@ -598,7 +594,7 @@ static void set_pref_audio_with_lang(
acodec = ghb_settings_audio_encoder_codec(audio, "AudioEncoder");
fallback = ghb_select_fallback(settings, acodec);
copy_mask = ghb_get_copy_mask(settings);
- bitrate = ghb_settings_combo_int(audio, "AudioBitrate");
+ bitrate = ghb_settings_audio_bitrate_rate(audio, "AudioBitrate");
samplerate = ghb_settings_audio_samplerate_rate(audio,
"AudioSamplerate");
mix = ghb_settings_mixdown_mix(audio, "AudioMixdown");
@@ -789,8 +785,8 @@ audio_refresh_list_row_ui(
}
else
{
- s_br_quality = g_strdup_printf("Bitrate: %skbps",
- ghb_settings_combo_option(settings, "AudioBitrate"));
+ s_br_quality = g_strdup_printf("Bitrate: %dkbps",
+ ghb_settings_audio_bitrate_rate(settings, "AudioBitrate"));
}
sr = ghb_settings_audio_samplerate_rate(settings, "AudioSamplerate");
@@ -998,7 +994,7 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
if (asettings != NULL)
{
- br = ghb_settings_get_int(asettings, "AudioBitrate");
+ br = ghb_settings_audio_bitrate_rate(asettings, "AudioBitrate");
sr = ghb_settings_audio_samplerate_rate(asettings,
"AudioSamplerate");
mix = ghb_settings_mixdown_mix(asettings, "AudioMixdown");
@@ -1026,7 +1022,8 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
}
mix = ghb_get_best_mix( aconfig, acodec, mix);
br = hb_audio_bitrate_get_best(acodec, br, sr, mix);
- ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(br));
+ ghb_ui_update(ud, "AudioBitrate",
+ ghb_string_value(ghb_audio_bitrate_get_short_name(br)));
ghb_ui_update(ud, "AudioMixdown",
ghb_string_value(hb_mixdown_get_short_name(mix)));
diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c
index 86d1b7a1e..2bab2a7a0 100644
--- a/gtk/src/hb-backend.c
+++ b/gtk/src/hb-backend.c
@@ -880,36 +880,6 @@ ghb_find_closest_audio_samplerate(gint irate)
return result;
}
-int ghb_custom_bitrate = 0;
-gchar *ghb_custom_bitrate_str = NULL;
-
-static gint
-lookup_audio_bitrate_int(const GValue *grate)
-{
- return ghb_value_int(grate);
-}
-
-static const gchar*
-lookup_audio_bitrate_option(const GValue *grate)
-{
- int rate = ghb_value_int(grate);
-
- if (rate == ghb_custom_bitrate && ghb_custom_bitrate_str != NULL)
- return ghb_custom_bitrate_str;
-
- const hb_rate_t *hbrate;
- for (hbrate = hb_audio_bitrate_get_next(NULL); hbrate != NULL;
- hbrate = hb_audio_bitrate_get_next(hbrate))
- {
- if (rate == hbrate->rate)
- {
- return hbrate->name;
- }
- }
-
- return "160";
-}
-
const iso639_lang_t* ghb_iso639_lookup_by_int(int idx)
{
return &ghb_language_table[idx];
@@ -2496,8 +2466,6 @@ ghb_lookup_combo_int(const gchar *name, const GValue *gval)
{
if (gval == NULL)
return 0;
- if (strcmp(name, "AudioBitrate") == 0)
- return lookup_audio_bitrate_int(gval);
else if (strcmp(name, "SrtLanguage") == 0)
return lookup_audio_lang_int(gval);
else
@@ -2513,8 +2481,6 @@ ghb_lookup_combo_double(const gchar *name, const GValue *gval)
{
if (gval == NULL)
return 0;
- if (strcmp(name, "AudioBitrate") == 0)
- return lookup_audio_bitrate_int(gval);
else if (strcmp(name, "SrtLanguage") == 0)
return lookup_audio_lang_int(gval);
else
@@ -2530,8 +2496,6 @@ ghb_lookup_combo_option(const gchar *name, const GValue *gval)
{
if (gval == NULL)
return NULL;
- if (strcmp(name, "AudioBitrate") == 0)
- return lookup_audio_bitrate_option(gval);
else if (strcmp(name, "SrtLanguage") == 0)
return lookup_audio_lang_option(gval);
else
@@ -2547,8 +2511,6 @@ ghb_lookup_combo_string(const gchar *name, const GValue *gval)
{
if (gval == NULL)
return NULL;
- if (strcmp(name, "AudioBitrate") == 0)
- return lookup_audio_bitrate_option(gval);
else if (strcmp(name, "SrtLanguage") == 0)
return lookup_audio_lang_option(gval);
else
@@ -2933,6 +2895,13 @@ ghb_ac3_in_audio_list(const GValue *audio_list)
return FALSE;
}
+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)
{
@@ -2944,32 +2913,28 @@ audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
if (rate >= 0 && rate < 8) return;
- if (ghb_custom_bitrate_str != NULL)
- {
- g_free(ghb_custom_bitrate_str);
- }
- ghb_custom_bitrate = rate;
+ custom_audio_bitrate.rate = rate;
if (rate < 0)
{
- ghb_custom_bitrate_str = g_strdup_printf("N/A");
+ snprintf(custom_audio_bitrate_str, 8, "N/A");
}
else
{
- ghb_custom_bitrate_str = g_strdup_printf("%d", rate);
+ 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 ("<small>%s</small>", ghb_custom_bitrate_str);
+ str = g_strdup_printf ("<small>%s</small>", custom_audio_bitrate.name);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
0, str,
1, TRUE,
- 2, ghb_custom_bitrate_str,
+ 2, custom_audio_bitrate.name,
3, (gdouble)rate,
- 4, ghb_custom_bitrate_str,
+ 4, custom_audio_bitrate.name,
-1);
g_free(str);
}
@@ -3045,9 +3010,8 @@ audio_bitrate_opts_update(
}
else
{
- g_free(ghb_custom_bitrate_str);
- ghb_custom_bitrate_str = NULL;
- ghb_custom_bitrate = 0;
+ custom_audio_bitrate.rate = 0;
+ custom_audio_bitrate_str[0] = 0;
}
}
@@ -3077,16 +3041,16 @@ ghb_audio_bitrate_opts_set(GtkComboBox *combo, gboolean extra)
-1);
g_free(str);
}
- if (extra && ghb_custom_bitrate_str != NULL)
+ if (extra && custom_audio_bitrate.rate != 0)
{
gtk_list_store_append(store, &iter);
- str = g_strdup_printf ("<small>%s</small>", ghb_custom_bitrate_str);
+ str = g_strdup_printf ("<small>%s</small>", custom_audio_bitrate.name);
gtk_list_store_set(store, &iter,
0, str,
1, TRUE,
- 2, ghb_custom_bitrate_str,
- 3, (gdouble)ghb_custom_bitrate,
- 4, ghb_custom_bitrate_str,
+ 2, custom_audio_bitrate.name,
+ 3, (gdouble)custom_audio_bitrate.rate,
+ 4, custom_audio_bitrate.name,
-1);
g_free(str);
}
@@ -3109,6 +3073,63 @@ ghb_set_bitrate_opts(
audio_bitrate_opts_update(builder, "AudioBitrate", first_rate, last_rate, extra_rate);
}
+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))
+ {
+ if (rate == hb_rate->rate)
+ {
+ return hb_rate->name;
+ }
+ }
+ return first->name;
+}
+
+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;
+ hb_rate = hb_audio_bitrate_get_next(hb_rate))
+ {
+ if (!strncmp(name, hb_rate->name, 8))
+ {
+ return hb_rate;
+ }
+ }
+ // Return a default rate if nothing matches
+ return first;
+}
+
+int
+ghb_lookup_audio_bitrate_rate(const char *name)
+{
+ return ghb_lookup_audio_bitrate(name)->rate;
+}
+
+int
+ghb_settings_audio_bitrate_rate(const GValue *settings, const char *name)
+{
+ const char *rate_id = ghb_settings_get_const_string(settings, name);
+ return ghb_lookup_audio_bitrate_rate(rate_id);
+}
+
+const hb_rate_t*
+ghb_settings_audio_bitrate(const GValue *settings, const char *name)
+{
+ const char *rate_id = ghb_settings_get_const_string(settings, name);
+ return ghb_lookup_audio_bitrate(rate_id);
+}
+
static ghb_status_t hb_status;
void
@@ -4684,7 +4705,7 @@ add_job(hb_handle_t *h, GValue *js, gint unique_id, int titleindex)
{
audio.out.quality = HB_INVALID_AUDIO_QUALITY;
audio.out.bitrate =
- ghb_settings_combo_int(asettings, "AudioBitrate");
+ ghb_settings_audio_bitrate_rate(asettings, "AudioBitrate");
audio.out.bitrate = hb_audio_bitrate_get_best(
audio.out.codec, audio.out.bitrate,
diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h
index 11ec4ac07..a17e5c818 100644
--- a/gtk/src/hb-backend.h
+++ b/gtk/src/hb-backend.h
@@ -200,5 +200,11 @@ int ghb_settings_audio_samplerate_rate(
const hb_rate_t* ghb_settings_audio_samplerate(
const GValue *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 GValue *settings, const char *name);
+const hb_rate_t* ghb_settings_audio_bitrate(
+ const GValue *settings, const char *name);
+const char* ghb_audio_bitrate_get_short_name(int rate);
#endif // _HBBACKEND_H_
diff --git a/gtk/src/queuehandler.c b/gtk/src/queuehandler.c
index 55e712892..53e2faede 100644
--- a/gtk/src/queuehandler.c
+++ b/gtk/src/queuehandler.c
@@ -545,10 +545,8 @@ add_to_queue_list(signal_user_data_t *ud, GValue *settings, GtkTreeIter *piter)
}
else
{
- char *br;
- br = ghb_settings_get_string(asettings, "AudioBitrate");
- quality = g_strdup_printf("Bitrate: %s", br);
- g_free(br);
+ int br = ghb_settings_audio_bitrate_rate(asettings, "AudioBitrate");
+ quality = g_strdup_printf("Bitrate: %d", br);
}
const hb_rate_t *sr;
sr = ghb_settings_audio_samplerate(asettings, "AudioSamplerate");