3 * Copyright (C) 2008-2009 Filippo Argiolas <filippo.argiolas@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #define GLIB_DISABLE_DEPRECATION_WARNINGS
26 #include <gdk-pixbuf/gdk-pixbuf.h>
28 #include "../gstgtk.h"
30 #include <gst/video/videooverlay.h>
33 /* TODO: use video overlay in the proper way (like suggested in docs, see gtkvideooverlay example) */
35 expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data)
37 GstVideoOverlay *overlay =
38 GST_VIDEO_OVERLAY (gst_bin_get_by_interface (GST_BIN (data),
39 GST_TYPE_VIDEO_OVERLAY));
41 gst_video_overlay_set_gtk_window (overlay, widget);
47 destroy_cb (GtkWidget * widget, GdkEvent * event, GstElement * pipeline)
49 g_message ("destroy callback");
51 gst_element_set_state (pipeline, GST_STATE_NULL);
52 gst_object_unref (pipeline);
58 apply_fx (GtkWidget * widget, gpointer data)
65 G_PARAM_SPEC_ENUM (g_object_class_find_property (G_OBJECT_GET_CLASS
66 (G_OBJECT (data)), "effect")
69 fx = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget));
70 g_print ("setting: %s - %s\n", fx, g_enum_get_value_by_nick (p_class,
72 g_object_set (G_OBJECT (data), "effect", g_enum_get_value_by_nick (p_class,
78 play_cb (GtkWidget * widget, gpointer data)
80 g_message ("playing");
81 gst_element_set_state (GST_ELEMENT (data), GST_STATE_PLAYING);
86 null_cb (GtkWidget * widget, gpointer data)
88 g_message ("nulling");
89 gst_element_set_state (GST_ELEMENT (data), GST_STATE_NULL);
94 ready_cb (GtkWidget * widget, gpointer data)
96 g_message ("readying");
97 gst_element_set_state (GST_ELEMENT (data), GST_STATE_READY);
102 pause_cb (GtkWidget * widget, gpointer data)
104 g_message ("pausing");
105 gst_element_set_state (GST_ELEMENT (data), GST_STATE_PAUSED);
110 main (gint argc, gchar * argv[])
112 GstStateChangeReturn ret;
113 GstElement *pipeline;
114 GstElement *uload, *filter, *sink;
115 GstElement *sourcebin;
116 GError *error = NULL;
120 GtkWidget *vbox, *combo;
122 GtkWidget *play, *pause, *null, *ready;
124 gchar **source_desc_array = NULL;
125 gchar *source_desc = NULL;
127 GOptionContext *context;
128 GOptionEntry options[] = {
129 {"source-bin", 's', 0, G_OPTION_ARG_STRING_ARRAY, &source_desc_array,
130 "Use a custom source bin description (gst-launch style)", NULL}
135 g_thread_init (NULL);
137 context = g_option_context_new (NULL);
138 g_option_context_add_main_entries (context, options, NULL);
139 g_option_context_add_group (context, gst_init_get_option_group ());
140 g_option_context_add_group (context, gtk_get_option_group (TRUE));
141 if (!g_option_context_parse (context, &argc, &argv, &error)) {
142 g_print ("Inizialization error: %s\n", GST_STR_NULL (error->message));
145 g_option_context_free (context);
147 if (source_desc_array != NULL) {
148 source_desc = g_strjoinv (" ", source_desc_array);
149 g_strfreev (source_desc_array);
151 if (source_desc == NULL) {
154 ("videotestsrc ! video/x-raw, width=352, height=288 ! identity");
158 gst_parse_bin_from_description (g_strdup (source_desc), TRUE, &error);
159 g_free (source_desc);
161 g_print ("Error while parsing source bin description: %s\n",
162 GST_STR_NULL (error->message));
166 g_set_application_name ("gst-gl-effects test app");
168 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
169 gtk_container_set_border_width (GTK_CONTAINER (window), 3);
171 pipeline = gst_pipeline_new ("pipeline");
173 uload = gst_element_factory_make ("glupload", "glu");
174 filter = gst_element_factory_make ("gleffects", "flt");
175 sink = gst_element_factory_make ("glimagesink", "glsink");
177 gst_bin_add_many (GST_BIN (pipeline), sourcebin, uload, filter, sink, NULL);
179 if (!gst_element_link_many (sourcebin, uload, filter, sink, NULL)) {
180 g_print ("Failed to link one or more elements!\n");
184 g_signal_connect (G_OBJECT (window), "delete-event",
185 G_CALLBACK (destroy_cb), pipeline);
186 g_signal_connect (G_OBJECT (window), "destroy-event",
187 G_CALLBACK (destroy_cb), pipeline);
189 screen = gtk_drawing_area_new ();
191 gtk_widget_set_size_request (screen, 640, 480); // 500 x 376
193 vbox = gtk_vbox_new (FALSE, 2);
195 gtk_box_pack_start (GTK_BOX (vbox), screen, TRUE, TRUE, 0);
197 combo = gtk_combo_box_new_text ();
199 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "identity");
200 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "mirror");
201 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "squeeze");
202 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "stretch");
203 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "fisheye");
204 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "twirl");
205 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "bulge");
206 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "tunnel");
207 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "square");
208 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "heat");
209 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "xpro");
210 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "lumaxpro");
211 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "sepia");
212 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "xray");
213 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "sin");
214 gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "glow");
216 g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (apply_fx), filter);
218 gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
220 hbox = gtk_hbox_new (FALSE, 0);
222 play = gtk_button_new_with_label ("PLAY");
224 g_signal_connect (G_OBJECT (play), "clicked", G_CALLBACK (play_cb), pipeline);
226 pause = gtk_button_new_with_label ("PAUSE");
228 g_signal_connect (G_OBJECT (pause), "clicked",
229 G_CALLBACK (pause_cb), pipeline);
231 null = gtk_button_new_with_label ("NULL");
233 g_signal_connect (G_OBJECT (null), "clicked", G_CALLBACK (null_cb), pipeline);
235 ready = gtk_button_new_with_label ("READY");
237 g_signal_connect (G_OBJECT (ready), "clicked",
238 G_CALLBACK (ready_cb), pipeline);
240 gtk_box_pack_start (GTK_BOX (hbox), null, TRUE, TRUE, 0);
241 gtk_box_pack_start (GTK_BOX (hbox), ready, TRUE, TRUE, 0);
242 gtk_box_pack_start (GTK_BOX (hbox), play, TRUE, TRUE, 0);
243 gtk_box_pack_start (GTK_BOX (hbox), pause, TRUE, TRUE, 0);
245 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
247 gtk_container_add (GTK_CONTAINER (window), vbox);
249 g_signal_connect (screen, "expose-event", G_CALLBACK (expose_cb), pipeline);
251 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
252 if (ret == GST_STATE_CHANGE_FAILURE) {
253 g_print ("Failed to start up pipeline!\n");
257 gtk_widget_show_all (GTK_WIDGET (window));