1 /* gstmatrix-example - test program for the GStreamer matrix element
3 * Copyright (C) 2013 Antonio Ospite <ospite@studenti.unina.it>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 /* FIXME: suppress warnings for deprecated API such as GValueArray
20 * with newer GLib versions (>= 2.31.0)
22 * It is just not possible to switch to GArray yet because the python API in
23 * 1.2.0 still passes iterable properties as GValueArray */
24 #define GLIB_DISABLE_DEPRECATION_WARNINGS
27 static gboolean on_message(GstBus *bus, GstMessage *message, gpointer user_data)
29 GMainLoop *loop = (GMainLoop *)user_data;
31 switch (GST_MESSAGE_TYPE(message)) {
32 case GST_MESSAGE_ERROR:
34 g_main_loop_quit(loop);
36 case GST_MESSAGE_WARNING:
37 g_warning("Got WARNING");
38 g_main_loop_quit(loop);
41 g_main_loop_quit(loop);
50 static void set_matrix(GstElement *element)
57 /* Initialize a 2D perspective matrix, you can use
58 * cvGetPerspectiveTransform() from OpenCV to build it
59 * from a quad-to-quad transformation */
60 m[0] = 1.9999999999999982;
61 m[1] = 0.8333333333333287;
62 m[2] = -399.99999999999926;
63 m[3] = 3.9968028886505525e-15;
64 m[4] = 1.9999999999999978;
65 m[5] = -8.277822871605139e-13;
66 m[6] = 2.428612866367518e-18;
67 m[7] = 0.0020833333333333294;
68 m[8] = 0.9999999999999996;
70 va = g_value_array_new(1);
72 g_value_init(&v, G_TYPE_DOUBLE);
73 for (i = 0; i < 9; i++) {
74 g_value_set_double(&v, m[i]);
75 g_value_array_append(va, &v);
78 g_object_set(G_OBJECT(element), "m", va, NULL);
79 g_value_array_free(va);
84 GstElement *pipeline, *src, *capsfilter, *matrix, *conv, *sink;
92 pipeline = gst_element_factory_make("pipeline", NULL);
94 src = gst_element_factory_make("videotestsrc", NULL);
96 caps = gst_caps_from_string("video/x-raw,format=AYUV,width=800,height=480");
98 capsfilter = gst_element_factory_make("capsfilter", NULL);
99 g_object_set(G_OBJECT(capsfilter), "caps", caps, NULL);
101 matrix = gst_element_factory_make("matrix", NULL);
104 conv = gst_element_factory_make("videoconvert", NULL);
106 sink = gst_element_factory_make("autovideosink", NULL);
107 g_return_val_if_fail(sink != NULL, -1);
109 gst_bin_add_many(GST_BIN(pipeline), src, capsfilter, matrix, conv, sink, NULL);
110 ret = gst_element_link_many(src, capsfilter, matrix, conv, sink, NULL);
112 g_error("Failed to link elements");
116 loop = g_main_loop_new(NULL, FALSE);
118 bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
119 gst_bus_add_signal_watch(bus);
120 g_signal_connect(G_OBJECT(bus), "message", G_CALLBACK(on_message),
122 gst_object_unref(GST_OBJECT(bus));
124 ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
125 if (ret == GST_STATE_CHANGE_FAILURE) {
126 g_error("Failed to go into PLAYING state");
130 g_main_loop_run(loop);
132 gst_element_set_state(pipeline, GST_STATE_NULL);
134 g_main_loop_unref(loop);
135 gst_object_unref(pipeline);