2 /*** block a from ../../../docs/manual/highlevel-components.xml ***/
5 /*** block b from ../../../docs/manual/highlevel-components.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);
31 /* unhandled message */
35 /* remove message from the queue */
39 /*** block c from ../../../docs/manual/highlevel-components.xml ***/
40 GstElement *pipeline, *audio;
43 cb_newpad (GstElement *decodebin,
53 audiopad = gst_element_get_static_pad (audio, "sink");
54 if (GST_PAD_IS_LINKED (audiopad)) {
55 g_object_unref (audiopad);
59 /* check media type */
60 caps = gst_pad_get_caps (pad);
61 str = gst_caps_get_structure (caps, 0);
62 if (!g_strrstr (gst_structure_get_name (str), "audio")) {
63 gst_caps_unref (caps);
64 gst_object_unref (audiopad);
67 gst_caps_unref (caps);
70 gst_pad_link (pad, audiopad);
72 g_object_unref (audiopad);
80 GstElement *src, *dec, *conv, *sink;
85 gst_init (&argc, &argv);
86 loop = g_main_loop_new (NULL, FALSE);
88 /* make sure we have input */
90 g_print ("Usage: %s <filename>\n", argv[0]);
95 pipeline = gst_pipeline_new ("pipeline");
97 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
98 gst_bus_add_watch (bus, my_bus_callback, loop);
99 gst_object_unref (bus);
101 src = gst_element_factory_make ("filesrc", "source");
102 g_object_set (G_OBJECT (src), "location", argv[1], NULL);
103 dec = gst_element_factory_make ("decodebin", "decoder");
104 g_signal_connect (dec, "new-decoded-pad", G_CALLBACK (cb_newpad), NULL);
105 gst_bin_add_many (GST_BIN (pipeline), src, dec, NULL);
106 gst_element_link (src, dec);
108 /* create audio output */
109 audio = gst_bin_new ("audiobin");
110 conv = gst_element_factory_make ("audioconvert", "aconv");
111 audiopad = gst_element_get_static_pad (conv, "sink");
112 sink = gst_element_factory_make ("alsasink", "sink");
113 gst_bin_add_many (GST_BIN (audio), conv, sink, NULL);
114 gst_element_link (conv, sink);
115 gst_element_add_pad (audio,
116 gst_ghost_pad_new ("sink", audiopad));
117 gst_object_unref (audiopad);
118 gst_bin_add (GST_BIN (pipeline), audio);
121 gst_element_set_state (pipeline, GST_STATE_PLAYING);
122 g_main_loop_run (loop);
125 gst_element_set_state (pipeline, GST_STATE_NULL);
126 gst_object_unref (GST_OBJECT (pipeline));