2 /*** block a from ../../../docs/manual/advanced-autoplugging.xml ***/
5 /*** block b from ../../../docs/manual/advanced-autoplugging.xml ***/
7 my_bus_callback (GstBus *bus,
11 GMainLoop *loop = data;
13 switch (GST_MESSAGE_TYPE (message)) {
14 case GST_MESSAGE_ERROR: {
18 gst_message_parse_error (message, &err, &debug);
19 g_print ("Error: %s\n", err->message);
23 g_main_loop_quit (loop);
28 g_main_loop_quit (loop);
34 /* remove from queue */
38 /*** block c from ../../../docs/manual/advanced-autoplugging.xml ***/
40 idle_exit_loop (gpointer data)
42 g_main_loop_quit ((GMainLoop *) data);
49 cb_typefound (GstElement *typefind,
54 GMainLoop *loop = data;
57 type = gst_caps_to_string (caps);
58 g_print ("Media type %s found, probability %d%%\n", type, probability);
61 /* since we connect to a signal in the pipeline thread context, we need
62 * to set an idle handler to exit the main loop in the mainloop context.
63 * Normally, your app should not need to worry about such things. */
64 g_idle_add (idle_exit_loop, loop);
72 GstElement *pipeline, *filesrc, *typefind, *fakesink;
76 gst_init (&argc, &argv);
77 loop = g_main_loop_new (NULL, FALSE);
81 g_print ("Usage: %s <filename>\n", argv[0]);
85 /* create a new pipeline to hold the elements */
86 pipeline = gst_pipeline_new ("pipe");
88 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
89 gst_bus_add_watch (bus, my_bus_callback, NULL);
90 gst_object_unref (bus);
92 /* create file source and typefind element */
93 filesrc = gst_element_factory_make ("filesrc", "source");
94 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
95 typefind = gst_element_factory_make ("typefind", "typefinder");
96 g_signal_connect (typefind, "have-type", G_CALLBACK (cb_typefound), loop);
97 fakesink = gst_element_factory_make ("fakesink", "sink");
100 gst_bin_add_many (GST_BIN (pipeline), filesrc, typefind, fakesink, NULL);
101 gst_element_link_many (filesrc, typefind, fakesink, NULL);
102 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
103 g_main_loop_run (loop);
106 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
107 gst_object_unref (GST_OBJECT (pipeline));