2002-01-31 12:17:46 +00:00
|
|
|
/*
|
|
|
|
* test for tee element
|
|
|
|
* this tests for proxying of caps from tee sink to src's in various situations
|
2002-02-05 14:40:56 +00:00
|
|
|
* it also tests if you get a good, unique pad when requesting a third one
|
|
|
|
* which shows a bug in 0.3.2 :
|
|
|
|
* request pad, get 0
|
|
|
|
* request pad, get 1
|
|
|
|
* remove pad 0,
|
|
|
|
* request pad, get 1 (number of pads), already exists, assert fail
|
|
|
|
*
|
2002-01-31 12:17:46 +00:00
|
|
|
* thomas@apestaart.org
|
2002-02-05 13:24:46 +00:00
|
|
|
* originally written for 0.3.2
|
2002-01-31 12:17:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2002-02-12 13:51:40 +00:00
|
|
|
#include <property.h>
|
2002-01-31 12:17:46 +00:00
|
|
|
|
|
|
|
GstElement *
|
|
|
|
element_create (char *name, char *element)
|
|
|
|
/*
|
|
|
|
* create the element
|
|
|
|
* print an error if it can't be created
|
|
|
|
* return NULL if it couldn't be created
|
|
|
|
* return element if it did work
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
GstElement *el = NULL;
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
el = (GstElement *) gst_element_factory_make (element, name);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (el == NULL) {
|
2002-01-31 12:17:46 +00:00
|
|
|
fprintf (stderr, "Could not create element %s (%s) !\n", name, element);
|
|
|
|
return NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
} else
|
2002-01-31 12:17:46 +00:00
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GstElement *pipeline = NULL;
|
|
|
|
GstElement *tee, *src, *sink1, *sink2;
|
2002-02-05 11:48:36 +00:00
|
|
|
GstPad *tee_src1, *tee_src2;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-12-22 18:58:58 +00:00
|
|
|
#if 0
|
2002-02-05 13:23:09 +00:00
|
|
|
GstCaps *src_caps = NULL;
|
|
|
|
GstCaps *sink_caps = NULL;
|
2003-12-22 01:39:35 +00:00
|
|
|
GstStructure *structure = NULL;
|
2002-05-09 16:44:22 +00:00
|
|
|
GstPad *pad = NULL;
|
2003-12-22 18:58:58 +00:00
|
|
|
#endif
|
2002-01-31 12:17:46 +00:00
|
|
|
|
|
|
|
/* init */
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
|
|
|
/* create */
|
|
|
|
g_print ("Creating pipeline\n");
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
|
2002-02-12 13:51:40 +00:00
|
|
|
g_print ("Connecting signals to pipeline\n");
|
2004-03-13 15:27:01 +00:00
|
|
|
g_signal_connect (pipeline, "deep_notify",
|
|
|
|
G_CALLBACK (property_change_callback), NULL);
|
|
|
|
|
2002-01-31 12:17:46 +00:00
|
|
|
g_print ("Creating elements\n");
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!(tee = element_create ("tee", "tee")))
|
|
|
|
return 1;
|
|
|
|
if (!(src = element_create ("src", "fakesrc")))
|
|
|
|
return 1;
|
2002-02-05 11:48:36 +00:00
|
|
|
g_object_set (G_OBJECT (src), "sizetype", 2, NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (!(sink1 = element_create ("sink1", "fakesink")))
|
|
|
|
return 1;
|
|
|
|
if (!(sink2 = element_create ("sink2", "fakesink")))
|
|
|
|
return 1;
|
|
|
|
|
2002-01-31 12:17:46 +00:00
|
|
|
/* add */
|
|
|
|
g_print ("Adding elements to bin\n");
|
|
|
|
gst_bin_add (GST_BIN (pipeline), src);
|
|
|
|
gst_bin_add (GST_BIN (pipeline), tee);
|
|
|
|
|
2003-01-10 04:54:20 +00:00
|
|
|
/* link input part */
|
|
|
|
g_print ("Linking input elements\n");
|
|
|
|
gst_pad_link (gst_element_get_pad (src, "src"),
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_element_get_pad (tee, "sink"));
|
|
|
|
|
2002-02-05 11:48:36 +00:00
|
|
|
/* request one pad from tee */
|
|
|
|
g_print ("Requesting first pad\n");
|
2002-04-12 14:38:19 +00:00
|
|
|
tee_src1 = gst_element_get_request_pad (tee, "src%d");
|
2002-02-05 11:48:36 +00:00
|
|
|
gst_bin_add (GST_BIN (pipeline), sink1);
|
2003-01-10 04:54:20 +00:00
|
|
|
gst_pad_link (tee_src1, gst_element_get_pad (sink1, "sink"));
|
2002-01-31 12:17:46 +00:00
|
|
|
|
|
|
|
/* set to play */
|
2002-02-05 11:48:36 +00:00
|
|
|
g_print ("Doing 1 iteration\n");
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
gst_bin_iterate (GST_BIN (pipeline));
|
|
|
|
|
|
|
|
/* pause and request another pad */
|
|
|
|
g_print ("Requesting second pad\n");
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
2002-04-12 14:38:19 +00:00
|
|
|
tee_src2 = gst_element_get_request_pad (tee, "src%d");
|
2002-02-05 11:48:36 +00:00
|
|
|
gst_bin_add (GST_BIN (pipeline), sink2);
|
2003-01-10 04:54:20 +00:00
|
|
|
gst_pad_link (tee_src2, gst_element_get_pad (sink2, "sink"));
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-10 04:54:20 +00:00
|
|
|
/* now we have two fakesinks linked, iterate */
|
2002-02-05 11:48:36 +00:00
|
|
|
g_print ("Doing 1 iteration\n");
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
gst_bin_iterate (GST_BIN (pipeline));
|
|
|
|
|
2003-12-22 18:58:58 +00:00
|
|
|
/* We don't allow apps to call gst_pad_try_set_caps(). */
|
|
|
|
#if 0
|
2002-02-05 13:23:09 +00:00
|
|
|
/* now we try setting caps on the src pad */
|
|
|
|
/* FIXME: should we set to pause here ? */
|
2003-12-22 01:39:35 +00:00
|
|
|
src_caps = gst_caps_from_string ("audio/raw, format=(s)\"int\", "
|
|
|
|
"rate=(i)44100");
|
|
|
|
|
2002-02-05 13:23:09 +00:00
|
|
|
g_assert (src_caps != NULL);
|
|
|
|
g_print ("Setting caps on fakesrc's src pad\n");
|
2002-05-09 16:44:22 +00:00
|
|
|
pad = gst_element_get_pad (src, "src");
|
2003-12-22 01:39:35 +00:00
|
|
|
if ((gst_pad_try_set_caps (pad, src_caps)) <= 0) {
|
2002-02-05 13:23:09 +00:00
|
|
|
g_print ("Could not set caps !\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now iterate and see if it proxies caps ok */
|
|
|
|
gst_bin_iterate (GST_BIN (pipeline));
|
|
|
|
sink_caps = gst_pad_get_caps (gst_element_get_pad (sink1, "sink"));
|
2003-12-22 01:39:35 +00:00
|
|
|
if (sink_caps && gst_caps_is_fixed (sink_caps)) {
|
|
|
|
structure = gst_caps_get_structure (sink_caps, 0);
|
2004-03-13 15:27:01 +00:00
|
|
|
} else {
|
2003-12-22 01:39:35 +00:00
|
|
|
structure = NULL;
|
|
|
|
g_print ("sink_caps is not fixed\n");
|
|
|
|
}
|
|
|
|
if (structure == NULL || !(gst_structure_has_field (structure, "rate"))) {
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("Hm, rate has not been propagated to sink1.\n");
|
2002-02-05 13:23:09 +00:00
|
|
|
return 1;
|
2003-12-22 01:39:35 +00:00
|
|
|
} else {
|
2002-04-12 14:38:19 +00:00
|
|
|
int rate;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
gst_structure_get_int (structure, "rate", &rate);
|
2002-04-12 14:38:19 +00:00
|
|
|
g_print ("Rate of pad on sink1 : %d\n", rate);
|
|
|
|
}
|
2002-02-05 13:23:09 +00:00
|
|
|
sink_caps = gst_pad_get_caps (gst_element_get_pad (sink2, "sink"));
|
2003-12-22 01:39:35 +00:00
|
|
|
structure = gst_caps_get_structure (sink_caps, 0);
|
2004-03-13 15:27:01 +00:00
|
|
|
if (structure != NULL && !(gst_structure_has_field (structure, "rate"))) {
|
|
|
|
g_print ("Hm, rate has not been propagated to sink2.\n");
|
2002-02-05 13:23:09 +00:00
|
|
|
return 1;
|
2003-12-22 01:39:35 +00:00
|
|
|
} else {
|
2002-04-12 14:38:19 +00:00
|
|
|
int rate;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-12-22 01:39:35 +00:00
|
|
|
gst_structure_get_int (structure, "rate", &rate);
|
2002-04-12 14:38:19 +00:00
|
|
|
g_print ("Rate of pad on sink2 : %d\n", rate);
|
|
|
|
}
|
2003-12-22 18:58:58 +00:00
|
|
|
#endif
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-02-05 11:48:36 +00:00
|
|
|
/* remove the first one, iterate */
|
|
|
|
g_print ("Removing first sink\n");
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
2003-01-10 04:54:20 +00:00
|
|
|
gst_pad_unlink (tee_src1, gst_element_get_pad (sink1, "sink"));
|
2002-02-05 11:48:36 +00:00
|
|
|
gst_bin_remove (GST_BIN (pipeline), sink1);
|
|
|
|
|
2003-01-10 04:54:20 +00:00
|
|
|
/* only second fakesink linked, iterate */
|
2002-02-05 11:48:36 +00:00
|
|
|
g_print ("Doing 1 iteration\n");
|
2002-01-31 12:17:46 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
gst_bin_iterate (GST_BIN (pipeline));
|
|
|
|
|
2002-02-05 14:40:56 +00:00
|
|
|
/* request another pad */
|
|
|
|
g_print ("Requesting third pad\n");
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
/* in 0.3.2 the next statement gives an assert error */
|
2002-04-12 14:38:19 +00:00
|
|
|
tee_src1 = gst_element_get_request_pad (tee, "src%d");
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-25 19:56:04 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
|
2002-01-31 12:17:46 +00:00
|
|
|
g_print ("Done !\n");
|
2002-02-05 10:55:21 +00:00
|
|
|
return 0;
|
2002-01-31 12:17:46 +00:00
|
|
|
}
|