1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) John Stebbins 2008-2015 <stebbins@stebbins>
6 * callbacks.c is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
14 #include <glib/gi18n.h>
15 #include "ghbcompat.h"
19 #include "callbacks.h"
22 #include "hb-backend.h"
23 #include "x264handler.h"
25 int ghb_get_video_encoder(GhbValue
*settings
)
28 encoder
= ghb_dict_get_string(settings
, "VideoEncoder");
29 return hb_video_encoder_get_from_name(encoder
);
33 vcodec_changed_cb(GtkWidget
*widget
, signal_user_data_t
*ud
)
35 float val
, vqmin
, vqmax
, step
, page
;
38 ghb_widget_to_setting(ud
->settings
, widget
);
39 ghb_check_dependency(ud
, widget
, NULL
);
40 ghb_show_container_options(ud
);
41 ghb_clear_presets_selection(ud
);
44 // Set the range of the video quality slider
45 val
= ghb_vquality_default(ud
);
46 ghb_vquality_range(ud
, &vqmin
, &vqmax
, &step
, &page
, &digits
, &inverted
);
47 ghb_scale_configure(ud
, "VideoQualitySlider", val
, vqmin
, vqmax
,
48 step
, page
, digits
, inverted
);
50 ghb_update_ui_combo_box(ud
, "VideoTune", NULL
, FALSE
);
51 ghb_update_ui_combo_box(ud
, "VideoProfile", NULL
, FALSE
);
52 ghb_update_ui_combo_box(ud
, "VideoLevel", NULL
, FALSE
);
53 ghb_ui_update(ud
, "VideoTune", ghb_int_value(0));
54 ghb_ui_update(ud
, "VideoProfile", ghb_int_value(0));
55 ghb_ui_update(ud
, "VideoLevel", ghb_int_value(0));
57 // Set the range of the preset slider
58 int encoder
= ghb_get_video_encoder(ud
->settings
);
59 GtkWidget
*presetSlider
= GHB_WIDGET(ud
->builder
, "VideoPresetSlider");
60 GtkWidget
*presetLabel
= GHB_WIDGET(ud
->builder
, "VideoPresetLabel");
61 const char * const *video_presets
;
63 video_presets
= hb_video_encoder_get_presets(encoder
);
64 while (video_presets
&& video_presets
[count
]) count
++;
65 gtk_widget_set_visible(presetSlider
, count
> 0);
66 gtk_widget_set_visible(presetLabel
, count
> 0);
69 gtk_range_set_range(GTK_RANGE(presetSlider
), 0, count
-1);
72 // Advanced options are only for x264
73 if (encoder
!= HB_VCODEC_X264
)
75 ghb_ui_update(ud
, "x264UseAdvancedOptions", ghb_boolean_value(FALSE
));
79 char *video_option_tooltip
= NULL
;
82 ghb_video_setting_changed(GtkWidget
*widget
, signal_user_data_t
*ud
)
84 if (video_option_tooltip
== NULL
)
86 GtkWidget
*eo
= GTK_WIDGET(GHB_WIDGET(ud
->builder
, "VideoOptionExtra"));
87 video_option_tooltip
= gtk_widget_get_tooltip_text(eo
);
90 ghb_widget_to_setting(ud
->settings
, widget
);
92 int encoder
= ghb_get_video_encoder(ud
->settings
);
93 int presetIndex
= ghb_dict_get_int(ud
->settings
, "VideoPresetSlider");
94 const char * const *video_presets
;
96 video_presets
= hb_video_encoder_get_presets(encoder
);
97 if (video_presets
!= NULL
)
99 preset
= video_presets
[presetIndex
];
100 ghb_dict_set_string(ud
->settings
, "VideoPreset", preset
);
103 if (!ghb_dict_get_bool(ud
->settings
, "x264UseAdvancedOptions") &&
104 encoder
== HB_VCODEC_X264
)
106 GString
*str
= g_string_new("");
114 preset
= ghb_dict_get_string(ud
->settings
, "VideoPreset");
115 tune
= ghb_dict_get_string(ud
->settings
, "VideoTune");
116 profile
= ghb_dict_get_string(ud
->settings
, "VideoProfile");
117 level
= ghb_dict_get_string(ud
->settings
, "VideoLevel");
118 opts
= ghb_dict_get_string(ud
->settings
, "VideoOptionExtra");
120 if (tune
[0] && strcmp(tune
, "none"))
122 g_string_append_printf(str
, "%s", tune
);
124 if (ghb_dict_get_bool(ud
->settings
, "x264FastDecode"))
126 g_string_append_printf(str
, "%s%s", str
->str
[0] ? "," : "", "fastdecode");
128 if (ghb_dict_get_bool(ud
->settings
, "x264ZeroLatency"))
130 g_string_append_printf(str
, "%s%s", str
->str
[0] ? "," : "", "zerolatency");
132 tunes
= g_string_free(str
, FALSE
);
136 int w
= ghb_dict_get_int(ud
->settings
, "scale_width");
137 int h
= ghb_dict_get_int(ud
->settings
, "scale_height");
139 if (w
== 0 || h
== 0)
141 if (!ghb_dict_get_bool(ud
->settings
, "autoscale"))
143 w
= ghb_dict_get_int(ud
->settings
, "PictureWidth");
144 h
= ghb_dict_get_int(ud
->settings
, "PictureHeight");
146 if (h
== 0 && w
!= 0)
150 if (w
== 0 && h
!= 0)
155 if (w
== 0 || h
== 0)
162 if (!strcasecmp(profile
, "auto"))
166 if (!strcasecmp(level
, "auto"))
170 new_opts
= hb_x264_param_unparse(
171 preset
, tunes
, opts
, profile
, level
, w
, h
);
173 ghb_update_x264Option(ud
, new_opts
);
175 ghb_update_x264Option(ud
, "");
177 GtkWidget
*eo
= GTK_WIDGET(GHB_WIDGET(ud
->builder
, "VideoOptionExtra"));
181 tt
= g_strdup_printf(_("%s\n\nExpanded Options:\n\"%s\""),
182 video_option_tooltip
, new_opts
);
184 tt
= g_strdup_printf(_("%s\n\nExpanded Options:\n\"\""),
185 video_option_tooltip
);
186 gtk_widget_set_tooltip_text(eo
, tt
);
193 else if (ghb_dict_get_bool(ud
->settings
, "x264UseAdvancedOptions"))
195 const char *opts
= ghb_dict_get_string(ud
->settings
, "x264Option");
197 GtkWidget
*eo
= GTK_WIDGET(GHB_WIDGET(ud
->builder
, "VideoOptionExtra"));
200 tt
= g_strdup_printf(_("%s\n\nExpanded Options:\n\"%s\""),
201 video_option_tooltip
, opts
);
203 tt
= g_strdup_printf(_("%s\n\nExpanded Options:\n\"\""),
204 video_option_tooltip
);
205 gtk_widget_set_tooltip_text(eo
, tt
);
209 ghb_check_dependency(ud
, widget
, NULL
);
210 ghb_clear_presets_selection(ud
);
214 video_setting_changed_cb(GtkWidget
*widget
, signal_user_data_t
*ud
)
216 ghb_video_setting_changed(widget
, ud
);
220 x264_use_advanced_options_changed_cb(GtkWidget
*widget
, signal_user_data_t
*ud
)
222 ghb_widget_to_setting(ud
->settings
, widget
);
224 if (ghb_dict_get_bool(ud
->prefs
, "HideAdvancedVideoSettings") &&
225 ghb_dict_get_bool(ud
->settings
, "x264UseAdvancedOptions"))
227 ghb_ui_update(ud
, "x264UseAdvancedOptions", ghb_boolean_value(FALSE
));
231 if (ghb_dict_get_bool(ud
->settings
, "x264UseAdvancedOptions"))
233 ghb_ui_update(ud
, "VideoPresetSlider", ghb_int_value(5));
234 ghb_ui_update(ud
, "VideoTune", ghb_string_value("none"));
235 ghb_ui_update(ud
, "VideoProfile", ghb_string_value("auto"));
236 ghb_ui_update(ud
, "VideoLevel", ghb_string_value("auto"));
238 const char *options
= ghb_dict_get_string(ud
->settings
, "x264Option");
239 ghb_ui_update(ud
, "VideoOptionExtra", ghb_string_value(options
));
242 ghb_check_dependency(ud
, widget
, NULL
);
243 ghb_clear_presets_selection(ud
);
247 video_option_changed_cb(GtkWidget
*widget
, signal_user_data_t
*ud
)
251 textview
= GTK_WIDGET(GHB_WIDGET(ud
->builder
, "VideoOptionExtra"));
252 ghb_video_setting_changed(textview
, ud
);
255 G_MODULE_EXPORT gchar
*
256 format_video_preset_cb(GtkScale
*scale
, gdouble val
, signal_user_data_t
*ud
)
258 const char * const *video_presets
;
260 int encoder
= ghb_get_video_encoder(ud
->settings
);
262 video_presets
= hb_video_encoder_get_presets(encoder
);
263 if (video_presets
!= NULL
)
265 preset
= video_presets
[(int)val
];
266 return g_strdup_printf(" %-12s", preset
);
268 return g_strdup_printf(" %-12s", "ERROR");