Debian Codegraph @

tests/examples/gl/gtk/filternovideooverlay/main.cpp

raw
1 /*
2 * GStreamer
3 * Copyright (C) 2008-2009 Julien Isorce <[email protected]>
4 * Copyright (C) 2014 Matthew Waters <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include <gst/gst.h>
23 #include <gtk/gtk.h>
24 #include <gdk/gdk.h>
25
26
27 static void end_stream_cb(GstBus* bus, GstMessage* message, GstElement* pipeline)
28 {
29 g_print("End of stream\n");
30
31 gst_element_set_state (pipeline, GST_STATE_NULL);
32 gst_object_unref(pipeline);
33
34 gtk_main_quit();
35 }
36
37 static void button_state_null_cb(GtkWidget* widget, GstElement* pipeline)
38 {
39 gst_element_set_state (pipeline, GST_STATE_NULL);
40 g_print ("GST_STATE_NULL\n");
41 }
42
43
44 static void button_state_ready_cb(GtkWidget* widget, GstElement* pipeline)
45 {
46 gst_element_set_state (pipeline, GST_STATE_READY);
47 g_print ("GST_STATE_READY\n");
48 }
49
50
51 static void button_state_paused_cb(GtkWidget* widget, GstElement* pipeline)
52 {
53 gst_element_set_state (pipeline, GST_STATE_PAUSED);
54 g_print ("GST_STATE_PAUSED\n");
55 }
56
57
58 static void button_state_playing_cb(GtkWidget* widget, GstElement* pipeline)
59 {
60 gst_element_set_state (pipeline, GST_STATE_PLAYING);
61 g_print ("GST_STATE_PLAYING\n");
62 }
63
64
65 static gchar* slider_fps_cb (GtkScale* scale, gdouble value, GstElement* pipeline)
66 {
67 //change the video frame rate dynamically
68 return g_strdup_printf ("video framerate: %0.*g", gtk_scale_get_digits (scale), value);
69 }
70
71
72
73 gint main (gint argc, gchar *argv[])
74 {
75 gtk_init (&argc, &argv);
76 gst_init (&argc, &argv);
77
78 GstElement* pipeline = gst_pipeline_new ("pipeline");
79
80 //window to control the states
81 GtkWidget* window_control = gtk_window_new (GTK_WINDOW_TOPLEVEL);
82 GdkGeometry geometry;
83 geometry.min_width = 1;
84 geometry.min_height = 1;
85 geometry.max_width = -1;
86 geometry.max_height = -1;
87 gtk_window_set_geometry_hints (GTK_WINDOW (window_control), window_control, &geometry, GDK_HINT_MIN_SIZE);
88 gtk_window_set_resizable (GTK_WINDOW (window_control), FALSE);
89 gtk_window_move (GTK_WINDOW (window_control), 10, 10);
90 GtkWidget* table = gtk_grid_new ();
91 gtk_container_add (GTK_CONTAINER (window_control), table);
92
93 //control state null
94 GtkWidget* button_state_null = gtk_button_new_with_label ("GST_STATE_NULL");
95 g_signal_connect (G_OBJECT (button_state_null), "clicked",
96 G_CALLBACK (button_state_null_cb), pipeline);
97 gtk_grid_attach (GTK_GRID (table), button_state_null, 0, 0, 1, 1);
98 gtk_widget_show (button_state_null);
99
100 //control state ready
101 GtkWidget* button_state_ready = gtk_button_new_with_label ("GST_STATE_READY");
102 g_signal_connect (G_OBJECT (button_state_ready), "clicked",
103 G_CALLBACK (button_state_ready_cb), pipeline);
104 gtk_grid_attach (GTK_GRID (table), button_state_ready, 0, 1, 1, 1);
105 gtk_widget_show (button_state_ready);
106
107 //control state paused
108 GtkWidget* button_state_paused = gtk_button_new_with_label ("GST_STATE_PAUSED");
109 g_signal_connect (G_OBJECT (button_state_paused), "clicked",
110 G_CALLBACK (button_state_paused_cb), pipeline);
111 gtk_grid_attach (GTK_GRID (table), button_state_paused, 0, 2, 1, 1);
112 gtk_widget_show (button_state_paused);
113
114 //control state playing
115 GtkWidget* button_state_playing = gtk_button_new_with_label ("GST_STATE_PLAYING");
116 g_signal_connect (G_OBJECT (button_state_playing), "clicked",
117 G_CALLBACK (button_state_playing_cb), pipeline);
118 gtk_grid_attach (GTK_GRID (table), button_state_playing, 0, 3, 1, 1);
119 gtk_widget_show (button_state_playing);
120
121 //change framerate
122 GtkWidget* slider_fps = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
123 1, 30, 2);
124 g_signal_connect (G_OBJECT (slider_fps), "format-value",
125 G_CALLBACK (slider_fps_cb), pipeline);
126 gtk_grid_attach (GTK_GRID (table), slider_fps, 1, 0, 1, 3);
127 gtk_widget_show (slider_fps);
128
129 gtk_widget_show (table);
130 gtk_widget_show (window_control);
131
132 GstElement* videosrc = gst_element_factory_make ("videotestsrc", "videotestsrc");
133 GstElement* upload = gst_element_factory_make ("glupload", "glupload");
134 GstElement* glfiltercube = gst_element_factory_make ("glfiltercube", "glfiltercube");
135 GstElement* videosink = gst_element_factory_make ("glimagesink", "glimagesink");
136
137 GstCaps *caps = gst_caps_new_simple("video/x-raw",
138 "width", G_TYPE_INT, 640,
139 "height", G_TYPE_INT, 480,
140 "framerate", GST_TYPE_FRACTION, 25, 1,
141 "format", G_TYPE_STRING, "RGBA",
142 NULL) ;
143
144 gst_bin_add_many (GST_BIN (pipeline), videosrc, upload, glfiltercube, videosink, NULL);
145
146 gboolean link_ok = gst_element_link_filtered(videosrc, upload, caps) ;
147 gst_caps_unref(caps) ;
148 if(!link_ok)
149 {
150 g_warning("Failed to link videosrc to glfiltercube!\n") ;
151 return -1;
152 }
153
154 if(!gst_element_link_many(upload, glfiltercube, videosink, NULL))
155 {
156 g_warning("Failed to link glfiltercube to videosink!\n") ;
157 return -1;
158 }
159
160 //set window id on this event
161 GstBus* bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
162 gst_bus_add_signal_watch (bus);
163 g_signal_connect(bus, "message::error", G_CALLBACK(end_stream_cb), pipeline);
164 g_signal_connect(bus, "message::warning", G_CALLBACK(end_stream_cb), pipeline);
165 g_signal_connect(bus, "message::eos", G_CALLBACK(end_stream_cb), pipeline);
166 gst_object_unref (bus);
167
168 //start
169 GstStateChangeReturn ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
170 if (ret == GST_STATE_CHANGE_FAILURE)
171 {
172 g_print ("Failed to start up pipeline!\n");
173 return -1;
174 }
175
176 gtk_main();
177
178 return 0;
179 }
180