3 int main(int argc, char *argv[]) {
4 GstElement *pipeline, *audio_source, *tee, *audio_queue, *audio_convert, *audio_resample, *audio_sink;
5 GstElement *video_queue, *visual, *video_convert, *video_sink;
8 GstPadTemplate *tee_src_pad_template;
9 GstPad *tee_audio_pad, *tee_video_pad;
10 GstPad *queue_audio_pad, *queue_video_pad;
12 /* Initialize GStreamer */
13 gst_init (&argc, &argv);
15 /* Create the elements */
16 audio_source = gst_element_factory_make ("audiotestsrc", "audio_source");
17 tee = gst_element_factory_make ("tee", "tee");
18 audio_queue = gst_element_factory_make ("queue", "audio_queue");
19 audio_convert = gst_element_factory_make ("audioconvert", "audio_convert");
20 audio_resample = gst_element_factory_make ("audioresample", "audio_resample");
21 audio_sink = gst_element_factory_make ("autoaudiosink", "audio_sink");
22 video_queue = gst_element_factory_make ("queue", "video_queue");
23 visual = gst_element_factory_make ("wavescope", "visual");
24 video_convert = gst_element_factory_make ("videoconvert", "video_convert");
25 video_sink = gst_element_factory_make ("autovideosink", "video_sink");
27 /* Create the empty pipeline */
28 pipeline = gst_pipeline_new ("test-pipeline");
30 if (!pipeline || !audio_source || !tee || !audio_queue || !audio_convert || !audio_resample || !audio_sink ||
31 !video_queue || !visual || !video_convert || !video_sink) {
32 g_printerr ("Not all elements could be created.\n");
36 /* Configure elements */
37 g_object_set (audio_source, "freq", 215.0f, NULL);
38 g_object_set (visual, "shader", 0, "style", 1, NULL);
40 /* Link all elements that can be automatically linked because they have "Always" pads */
41 gst_bin_add_many (GST_BIN (pipeline), audio_source, tee, audio_queue, audio_convert, audio_resample, audio_sink,
42 video_queue, visual, video_convert, video_sink, NULL);
43 if (gst_element_link_many (audio_source, tee, NULL) != TRUE ||
44 gst_element_link_many (audio_queue, audio_convert, audio_resample, audio_sink, NULL) != TRUE ||
45 gst_element_link_many (video_queue, visual, video_convert, video_sink, NULL) != TRUE) {
46 g_printerr ("Elements could not be linked.\n");
47 gst_object_unref (pipeline);
51 /* Manually link the Tee, which has "Request" pads */
52 tee_src_pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (tee), "src_%u");
53 tee_audio_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL);
54 g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name (tee_audio_pad));
55 queue_audio_pad = gst_element_get_static_pad (audio_queue, "sink");
56 tee_video_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL);
57 g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad));
58 queue_video_pad = gst_element_get_static_pad (video_queue, "sink");
59 if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK ||
60 gst_pad_link (tee_video_pad, queue_video_pad) != GST_PAD_LINK_OK) {
61 g_printerr ("Tee could not be linked.\n");
62 gst_object_unref (pipeline);
65 gst_object_unref (queue_audio_pad);
66 gst_object_unref (queue_video_pad);
68 /* Start playing the pipeline */
69 gst_element_set_state (pipeline, GST_STATE_PLAYING);
71 /* Wait until error or EOS */
72 bus = gst_element_get_bus (pipeline);
73 msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
75 /* Release the request pads from the Tee, and unref them */
76 gst_element_release_request_pad (tee, tee_audio_pad);
77 gst_element_release_request_pad (tee, tee_video_pad);
78 gst_object_unref (tee_audio_pad);
79 gst_object_unref (tee_video_pad);
83 gst_message_unref (msg);
84 gst_object_unref (bus);
85 gst_element_set_state (pipeline, GST_STATE_NULL);
87 gst_object_unref (pipeline);