3 * this tests for proxying of caps from tee sink to src's in various situations
11 element_create (char *name, char *element)
14 * print an error if it can't be created
15 * return NULL if it couldn't be created
16 * return element if it did work
19 GstElement *el = NULL;
21 el = (GstElement *) gst_elementfactory_make (element, name);
24 fprintf (stderr, "Could not create element %s (%s) !\n", name, element);
32 main (int argc, char *argv[])
34 GstElement *pipeline = NULL;
35 GstElement *tee, *src, *sink1, *sink2;
36 GstPad *tee_src1, *tee_src2;
37 GstCaps *src_caps = NULL;
38 GstCaps *sink_caps = NULL;
39 GstProps *props = NULL;
42 gst_init (&argc, &argv);
45 g_print ("Creating pipeline\n");
46 pipeline = gst_pipeline_new ("pipeline");
47 g_signal_connect (G_OBJECT (pipeline), "event", G_CALLBACK (event_func), NULL);
49 g_print ("Creating elements\n");
50 if (!(tee = element_create ("tee", "tee"))) return 1;
51 if (!(src = element_create ("src", "fakesrc"))) return 1;
52 g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
53 if (!(sink1 = element_create ("sink1", "fakesink"))) return 1;
54 if (!(sink2 = element_create ("sink2", "fakesink"))) return 1;
57 g_print ("Adding elements to bin\n");
58 gst_bin_add (GST_BIN (pipeline), src);
59 gst_bin_add (GST_BIN (pipeline), tee);
61 /* connect input part */
62 g_print ("Connecting input elements\n");
63 gst_pad_connect (gst_element_get_pad (src, "src"),
64 gst_element_get_pad (tee, "sink"));
66 /* request one pad from tee */
67 g_print ("Requesting first pad\n");
68 tee_src1 = gst_element_request_pad_by_name (tee, "src%d");
69 gst_bin_add (GST_BIN (pipeline), sink1);
70 gst_pad_connect (tee_src1, gst_element_get_pad (sink1, "sink"));
73 g_print ("Doing 1 iteration\n");
74 gst_element_set_state (pipeline, GST_STATE_PLAYING);
75 gst_bin_iterate (GST_BIN (pipeline));
77 /* pause and request another pad */
78 g_print ("Requesting second pad\n");
79 gst_element_set_state (pipeline, GST_STATE_PAUSED);
80 tee_src2 = gst_element_request_pad_by_name (tee, "src%d");
81 gst_bin_add (GST_BIN (pipeline), sink2);
82 gst_pad_connect (tee_src2, gst_element_get_pad (sink2, "sink"));
84 /* now we have two fakesinks connected, iterate */
85 g_print ("Doing 1 iteration\n");
86 gst_element_set_state (pipeline, GST_STATE_PLAYING);
87 gst_bin_iterate (GST_BIN (pipeline));
89 /* now we try setting caps on the src pad */
90 /* FIXME: should we set to pause here ? */
91 src_caps = GST_CAPS_NEW (
94 "format", GST_PROPS_STRING ("int"),
95 "rate", GST_PROPS_INT (44100)
97 g_assert (src_caps != NULL);
98 g_print ("Setting caps on fakesrc's src pad\n");
99 if (! (gst_pad_try_set_caps (gst_element_get_pad (src, "src"), src_caps)))
101 g_print ("Could not set caps !\n");
104 /* now iterate and see if it proxies caps ok */
105 gst_bin_iterate (GST_BIN (pipeline));
106 sink_caps = gst_pad_get_caps (gst_element_get_pad (sink1, "sink"));
107 props = gst_caps_get_props (sink_caps);
108 if (! (gst_props_has_property (props, "rate")))
110 g_print ("Hm, rate has not been propagated to sink1.\n");
114 g_print ("Rate of pad on sink1 : %d\n", gst_props_get_int (props, "rate"));
115 sink_caps = gst_pad_get_caps (gst_element_get_pad (sink2, "sink"));
116 props = gst_caps_get_props (sink_caps);
117 if (! (gst_props_has_property (props, "rate")))
119 g_print ("Hm, rate has not been propagated to sink2.\n");
123 g_print ("Rate of pad on sink2 : %d\n", gst_props_get_int (props, "rate"));
125 /* remove the first one, iterate */
126 g_print ("Removing first sink\n");
127 gst_element_set_state (pipeline, GST_STATE_PAUSED);
128 gst_pad_disconnect (tee_src1, gst_element_get_pad (sink1, "sink"));
129 gst_pad_destroy (tee_src1);
130 gst_bin_remove (GST_BIN (pipeline), sink1);
132 /* only second fakesink connected, iterate */
133 g_print ("Doing 1 iteration\n");
134 gst_element_set_state (pipeline, GST_STATE_PLAYING);
135 gst_bin_iterate (GST_BIN (pipeline));
137 g_print ("Done !\n");