WinGui: Fix another instance of the Caliburn vs Json.net sillyness where objects...
[HandBrake.git] / gtk / src / videohandler.c
blobb4c0437b8e803285c2b80de63a7024997f5fb754
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * callbacks.c
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)
11 * any later version.
14 #include <glib/gi18n.h>
15 #include "ghbcompat.h"
16 #include <string.h>
17 #include "settings.h"
18 #include "values.h"
19 #include "callbacks.h"
20 #include "presets.h"
21 #include "preview.h"
22 #include "hb-backend.h"
23 #include "x264handler.h"
25 int ghb_get_video_encoder(GhbValue *settings)
27 const char *encoder;
28 encoder = ghb_dict_get_string(settings, "VideoEncoder");
29 return hb_video_encoder_get_from_name(encoder);
32 G_MODULE_EXPORT void
33 vcodec_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
35 float val, vqmin, vqmax, step, page;
36 int inverted, digits;
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);
42 ghb_live_reset(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;
62 int count = 0;
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);
67 if (count)
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;
81 void
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;
95 const char *preset;
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("");
107 const char *preset;
108 const char *tune;
109 const char *profile;
110 const char *level;
111 const char *opts;
112 char *tunes;
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);
134 char * new_opts;
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)
148 h = w * 9 / 16;
150 if (w == 0 && h != 0)
152 w = h * 16 / 9;
155 if (w == 0 || h == 0)
157 w = 1280;
158 h = 720;
162 if (!strcasecmp(profile, "auto"))
164 profile = "";
166 if (!strcasecmp(level, "auto"))
168 level = "";
170 new_opts = hb_x264_param_unparse(
171 preset, tunes, opts, profile, level, w, h);
172 if (new_opts)
173 ghb_update_x264Option(ud, new_opts);
174 else
175 ghb_update_x264Option(ud, "");
177 GtkWidget *eo = GTK_WIDGET(GHB_WIDGET(ud->builder, "VideoOptionExtra"));
179 char * tt;
180 if (new_opts)
181 tt = g_strdup_printf(_("%s\n\nExpanded Options:\n\"%s\""),
182 video_option_tooltip, new_opts);
183 else
184 tt = g_strdup_printf(_("%s\n\nExpanded Options:\n\"\""),
185 video_option_tooltip);
186 gtk_widget_set_tooltip_text(eo, tt);
188 g_free(tt);
189 g_free(new_opts);
191 g_free(tunes);
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"));
198 char * tt;
199 if (opts)
200 tt = g_strdup_printf(_("%s\n\nExpanded Options:\n\"%s\""),
201 video_option_tooltip, opts);
202 else
203 tt = g_strdup_printf(_("%s\n\nExpanded Options:\n\"\""),
204 video_option_tooltip);
205 gtk_widget_set_tooltip_text(eo, tt);
206 g_free(tt);
209 ghb_check_dependency(ud, widget, NULL);
210 ghb_clear_presets_selection(ud);
213 G_MODULE_EXPORT void
214 video_setting_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
216 ghb_video_setting_changed(widget, ud);
219 G_MODULE_EXPORT void
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));
228 return;
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);
246 G_MODULE_EXPORT void
247 video_option_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
249 GtkWidget *textview;
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;
259 const char *preset;
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");