2001-12-05 18:39:20 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
usage (void)
|
|
|
|
{
|
|
|
|
g_print ("usage: thread <testnum> \n"
|
|
|
|
" available testnums: \n"
|
|
|
|
" 1: stress test state change \n"
|
|
|
|
" 2: iterate once \n"
|
|
|
|
" 3: iterate twice \n"
|
|
|
|
" 4: state change while running \n"
|
|
|
|
" 5: state change in thread context\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
construct_pipeline (GstElement *pipeline)
|
|
|
|
{
|
2002-05-25 17:45:51 +00:00
|
|
|
GstElement *src, *sink, *queue, *identity, *thread;
|
2001-12-05 18:39:20 +00:00
|
|
|
|
2002-05-25 17:45:51 +00:00
|
|
|
src = gst_element_factory_make ("fakesrc", NULL);
|
|
|
|
sink = gst_element_factory_make ("fakesink", NULL);
|
|
|
|
identity = gst_element_factory_make ("identity", NULL);
|
|
|
|
queue = gst_element_factory_make ("queue", NULL);
|
|
|
|
thread = gst_element_factory_make ("thread", NULL);
|
2001-12-05 18:39:20 +00:00
|
|
|
|
2002-05-25 17:45:51 +00:00
|
|
|
gst_element_connect_many (src, queue, identity, sink, NULL);
|
2001-12-05 18:39:20 +00:00
|
|
|
|
2002-05-25 17:45:51 +00:00
|
|
|
gst_bin_add_many (GST_BIN (pipeline), src, queue, thread, NULL);
|
|
|
|
gst_bin_add_many (GST_BIN (thread), identity, sink, NULL);
|
2001-12-05 18:39:20 +00:00
|
|
|
|
|
|
|
g_object_set (G_OBJECT (src), "num_buffers", 5, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
change_state (GstElement *element, GstBuffer *buf, GstElement *pipeline)
|
|
|
|
{
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
main (gint argc, gchar *argv[])
|
|
|
|
{
|
|
|
|
GstElement *pipeline;
|
|
|
|
gint testnum;
|
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
testnum = atoi (argv[1]);
|
|
|
|
|
|
|
|
pipeline = gst_pipeline_new ("main_pipeline");
|
|
|
|
construct_pipeline (pipeline);
|
|
|
|
|
|
|
|
if (testnum == 1) {
|
|
|
|
g_print ("stress test state changes...\n");
|
|
|
|
|
2001-12-18 19:45:31 +00:00
|
|
|
g_print ("NULL\n");
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
2001-12-18 19:45:31 +00:00
|
|
|
g_print ("READY\n");
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_READY);
|
2001-12-18 19:45:31 +00:00
|
|
|
g_print ("NULL\n");
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
2001-12-18 19:45:31 +00:00
|
|
|
g_print ("PAUSED\n");
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
2001-12-18 19:45:31 +00:00
|
|
|
g_print ("READY\n");
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_READY);
|
2001-12-18 19:45:31 +00:00
|
|
|
g_print ("PAUSED\n");
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
2001-12-18 19:45:31 +00:00
|
|
|
g_print ("PLAYING\n");
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
2002-05-25 17:45:51 +00:00
|
|
|
/* element likely hits EOS and does a state transition to PAUSED */
|
2001-12-18 19:45:31 +00:00
|
|
|
g_print ("READY\n");
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_READY);
|
2001-12-18 19:45:31 +00:00
|
|
|
g_print ("NULL\n");
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (testnum == 2 || testnum == 3) {
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
g_print ("running ...\n");
|
|
|
|
while (gst_bin_iterate (GST_BIN (pipeline)));
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
if (testnum == 3) {
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
g_print ("running2 ...\n");
|
|
|
|
while (gst_bin_iterate (GST_BIN (pipeline)));
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
if (testnum == 4) {
|
|
|
|
gint run;
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
g_print ("running3 ...\n");
|
|
|
|
for (run = 0; run < 3; run++) {
|
|
|
|
gst_bin_iterate (GST_BIN (pipeline));
|
|
|
|
}
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
if (testnum == 5) {
|
|
|
|
GstElement *sink;
|
|
|
|
|
|
|
|
sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
|
|
|
|
|
2002-05-25 17:45:51 +00:00
|
|
|
g_signal_connect (G_OBJECT (sink), "handoff", G_CALLBACK (change_state), pipeline);
|
2001-12-05 18:39:20 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
g_print ("running3 ...\n");
|
|
|
|
while (gst_bin_iterate (GST_BIN (pipeline)));
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|