3 int main(int argc, char *argv[]) {
\r
4 GstElement *pipeline, *source, *sink;
\r
7 GstStateChangeReturn ret;
\r
9 /* Initialize GStreamer */
\r
10 gst_init (&argc, &argv);
\r
12 /* Create the elements */
\r
13 source = gst_element_factory_make ("videotestsrc", "source");
\r
14 sink = gst_element_factory_make ("autovideosink", "sink");
\r
16 /* Create the empty pipeline */
\r
17 pipeline = gst_pipeline_new ("test-pipeline");
\r
19 if (!pipeline || !source || !sink) {
\r
20 g_printerr ("Not all elements could be created.\n");
\r
24 /* Build the pipeline */
\r
25 gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
\r
26 if (gst_element_link (source, sink) != TRUE) {
\r
27 g_printerr ("Elements could not be linked.\n");
\r
28 gst_object_unref (pipeline);
\r
32 /* Modify the source's properties */
\r
33 g_object_set (source, "pattern", 0, NULL);
\r
36 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
\r
37 if (ret == GST_STATE_CHANGE_FAILURE) {
\r
38 g_printerr ("Unable to set the pipeline to the playing state.\n");
\r
39 gst_object_unref (pipeline);
\r
43 /* Wait until error or EOS */
\r
44 bus = gst_element_get_bus (pipeline);
\r
45 msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
\r
52 switch (GST_MESSAGE_TYPE (msg)) {
\r
53 case GST_MESSAGE_ERROR:
\r
54 gst_message_parse_error (msg, &err, &debug_info);
\r
55 g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
\r
56 g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
\r
57 g_clear_error (&err);
\r
58 g_free (debug_info);
\r
60 case GST_MESSAGE_EOS:
\r
61 g_print ("End-Of-Stream reached.\n");
\r
64 /* We should not reach here because we only asked for ERRORs and EOS */
\r
65 g_printerr ("Unexpected message received.\n");
\r
68 gst_message_unref (msg);
\r
71 /* Free resources */
\r
72 gst_object_unref (bus);
\r
73 gst_element_set_state (pipeline, GST_STATE_NULL);
\r
74 gst_object_unref (pipeline);
\r