1 /* gst-basic-example - basic example program for the GStreamer 1,0 API
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/>.
21 static gboolean on_message(GstBus *bus, GstMessage *message, gpointer user_data)
23 GMainLoop *loop = (GMainLoop *)user_data;
25 switch (GST_MESSAGE_TYPE(message)) {
26 case GST_MESSAGE_ERROR:
28 g_main_loop_quit(loop);
30 case GST_MESSAGE_WARNING:
31 g_warning("Got WARNING");
32 g_main_loop_quit(loop);
35 g_main_loop_quit(loop);
46 GstElement *pipeline, *src, *capsfilter, *conv, *sink;
54 pipeline = gst_element_factory_make("pipeline", NULL);
56 src = gst_element_factory_make("videotestsrc", NULL);
58 caps = gst_caps_from_string("video/x-raw,format=AYUV,width=800,height=480");
60 capsfilter = gst_element_factory_make("capsfilter", NULL);
61 g_object_set(G_OBJECT(capsfilter), "caps", caps, NULL);
63 conv = gst_element_factory_make("videoconvert", NULL);
65 sink = gst_element_factory_make("autovideosink", NULL);
66 g_return_val_if_fail(sink != NULL, -1);
68 gst_bin_add_many(GST_BIN(pipeline), src, capsfilter, conv, sink, NULL);
69 ret = gst_element_link_many(src, capsfilter, conv, sink, NULL);
71 g_error("Failed to link elements");
75 loop = g_main_loop_new(NULL, FALSE);
77 bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
78 gst_bus_add_signal_watch(bus);
79 g_signal_connect(G_OBJECT(bus), "message", G_CALLBACK(on_message),
81 gst_object_unref(GST_OBJECT(bus));
83 ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
84 if (ret == GST_STATE_CHANGE_FAILURE) {
85 g_error("Failed to go into PLAYING state");
89 g_main_loop_run(loop);
91 gst_element_set_state(pipeline, GST_STATE_NULL);
93 g_main_loop_unref(loop);
94 gst_object_unref(pipeline);