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