4 #include <gst/video/colorbalance.h>
6 typedef struct _CustomData {
11 /* Process a color balance command */
12 static void update_color_channel (const gchar *channel_name, gboolean increase, GstColorBalance *cb) {
15 GstColorBalanceChannel *channel = NULL;
16 const GList *channels, *l;
18 /* Retrieve the list of channels and locate the requested one */
19 channels = gst_color_balance_list_channels (cb);
20 for (l = channels; l != NULL; l = l->next) {
21 GstColorBalanceChannel *tmp = (GstColorBalanceChannel *)l->data;
23 if (g_strrstr (tmp->label, channel_name)) {
31 /* Change the channel's value */
32 step = 0.1 * (channel->max_value - channel->min_value);
33 value = gst_color_balance_get_value (cb, channel);
35 value = (gint)(value + step);
36 if (value > channel->max_value)
37 value = channel->max_value;
39 value = (gint)(value - step);
40 if (value < channel->min_value)
41 value = channel->min_value;
43 gst_color_balance_set_value (cb, channel, value);
46 /* Output the current values of all Color Balance channels */
47 static void print_current_values (GstElement *pipeline) {
48 const GList *channels, *l;
50 /* Output Color Balance values */
51 channels = gst_color_balance_list_channels (GST_COLOR_BALANCE (pipeline));
52 for (l = channels; l != NULL; l = l->next) {
53 GstColorBalanceChannel *channel = (GstColorBalanceChannel *)l->data;
54 gint value = gst_color_balance_get_value (GST_COLOR_BALANCE (pipeline), channel);
55 g_print ("%s: %3d%% ", channel->label,
56 100 * (value - channel->min_value) / (channel->max_value - channel->min_value));
61 /* Process keyboard input */
62 static gboolean handle_keyboard (GIOChannel *source, GIOCondition cond, CustomData *data) {
65 if (g_io_channel_read_line (source, &str, NULL, NULL, NULL) != G_IO_STATUS_NORMAL) {
69 switch (g_ascii_tolower (str[0])) {
71 update_color_channel ("CONTRAST", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));
74 update_color_channel ("BRIGHTNESS", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));
77 update_color_channel ("HUE", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));
80 update_color_channel ("SATURATION", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline));
83 g_main_loop_quit (data->loop);
91 print_current_values (data->pipeline);
96 int main(int argc, char *argv[]) {
98 GstStateChangeReturn ret;
101 /* Initialize GStreamer */
102 gst_init (&argc, &argv);
104 /* Initialize our data structure */
105 memset (&data, 0, sizeof (data));
107 /* Print usage map */
109 "USAGE: Choose one of the following options, then press enter:\n"
110 " 'C' to increase contrast, 'c' to decrease contrast\n"
111 " 'B' to increase brightness, 'b' to decrease brightness\n"
112 " 'H' to increase hue, 'h' to decrease hue\n"
113 " 'S' to increase saturation, 's' to decrease saturation\n"
116 /* Build the pipeline */
117 data.pipeline = gst_parse_launch ("playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm", NULL);
119 /* Add a keyboard watch so we get notified of keystrokes */
121 io_stdin = g_io_channel_win32_new_fd (fileno (stdin));
123 io_stdin = g_io_channel_unix_new (fileno (stdin));
125 g_io_add_watch (io_stdin, G_IO_IN, (GIOFunc)handle_keyboard, &data);
128 ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
129 if (ret == GST_STATE_CHANGE_FAILURE) {
130 g_printerr ("Unable to set the pipeline to the playing state.\n");
131 gst_object_unref (data.pipeline);
134 print_current_values (data.pipeline);
136 /* Create a GLib Main Loop and set it to run */
137 data.loop = g_main_loop_new (NULL, FALSE);
138 g_main_loop_run (data.loop);
141 g_main_loop_unref (data.loop);
142 g_io_channel_unref (io_stdin);
143 gst_element_set_state (data.pipeline, GST_STATE_NULL);
144 gst_object_unref (data.pipeline);