2002-11-14 21:19:55 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
/* threadc.c
|
|
|
|
* this tests if we can make a GstThread, with enough cothreads to stress it
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean running = FALSE;
|
|
|
|
gboolean can_quit = FALSE;
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
construct_pipeline (GstElement * pipeline, gint identities)
|
2002-11-14 21:19:55 +00:00
|
|
|
{
|
2002-12-07 14:16:52 +00:00
|
|
|
GstElement *src, *sink;
|
|
|
|
GstElement *identity = NULL;
|
2002-11-14 21:19:55 +00:00
|
|
|
GstElement *from;
|
|
|
|
int i;
|
|
|
|
|
2002-12-05 23:43:49 +00:00
|
|
|
identity = NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
src = gst_element_factory_make ("fakesrc", NULL);
|
|
|
|
sink = gst_element_factory_make ("fakesink", NULL);
|
2002-11-14 21:19:55 +00:00
|
|
|
g_assert (src);
|
|
|
|
g_assert (sink);
|
|
|
|
gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
|
|
|
|
from = src;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < identities; ++i) {
|
2002-11-14 21:19:55 +00:00
|
|
|
identity = gst_element_factory_make ("identity", NULL);
|
|
|
|
g_assert (identity);
|
|
|
|
gst_bin_add (GST_BIN (pipeline), identity);
|
2003-01-09 20:02:34 +00:00
|
|
|
gst_element_link (from, identity);
|
2002-11-14 21:19:55 +00:00
|
|
|
from = identity;
|
|
|
|
}
|
2003-01-09 20:02:34 +00:00
|
|
|
gst_element_link (identity, sink);
|
2002-11-14 21:19:55 +00:00
|
|
|
|
2002-12-07 14:16:52 +00:00
|
|
|
g_object_set (G_OBJECT (src), "num_buffers", 1, "sizetype", 3, NULL);
|
2002-11-14 21:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
state_changed (GstElement * el, gint arg1, gint arg2, gpointer user_data)
|
2002-11-14 21:19:55 +00:00
|
|
|
{
|
|
|
|
GstElementState state = gst_element_get_state (el);
|
2002-12-07 14:16:52 +00:00
|
|
|
|
|
|
|
g_print ("element %s has changed state to %s\n",
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_ELEMENT_NAME (el), gst_element_state_get_name (state));
|
|
|
|
if (state == GST_STATE_PLAYING)
|
|
|
|
running = TRUE;
|
2002-11-14 21:19:55 +00:00
|
|
|
/* if we move from PLAYING to PAUSED, we're done */
|
2004-03-13 15:27:01 +00:00
|
|
|
if (state == GST_STATE_PAUSED && running) {
|
|
|
|
while (!can_quit);
|
2002-11-14 21:19:55 +00:00
|
|
|
can_quit = FALSE;
|
|
|
|
g_print ("quitting main loop\n");
|
|
|
|
gst_main_quit ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-03-13 15:27:01 +00:00
|
|
|
main (gint argc, gchar * argv[])
|
2002-11-14 21:19:55 +00:00
|
|
|
{
|
2002-11-29 13:59:30 +00:00
|
|
|
int runs = 290;
|
2002-11-14 21:19:55 +00:00
|
|
|
int i;
|
|
|
|
gulong id;
|
|
|
|
GstElement *thread;
|
2002-12-07 14:16:52 +00:00
|
|
|
|
2002-11-14 21:19:55 +00:00
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 90; i < runs; ++i) {
|
2002-11-14 21:19:55 +00:00
|
|
|
thread = gst_thread_new ("main_thread");
|
|
|
|
g_assert (thread);
|
|
|
|
|
|
|
|
/* connect state change signal */
|
2002-11-29 13:59:30 +00:00
|
|
|
id = g_signal_connect (G_OBJECT (thread), "state_change",
|
2004-03-15 19:27:17 +00:00
|
|
|
G_CALLBACK (state_changed), NULL);
|
2002-11-14 21:19:55 +00:00
|
|
|
construct_pipeline (thread, i / 10 + 1);
|
|
|
|
|
|
|
|
g_print ("Setting thread to play with %d identities\n", i / 10 + 1);
|
2002-12-03 23:46:16 +00:00
|
|
|
if (gst_element_set_state (thread, GST_STATE_PLAYING) == GST_STATE_FAILURE) {
|
2002-11-29 13:59:30 +00:00
|
|
|
g_error ("Failed setting thread to play\n");
|
2004-03-13 15:27:01 +00:00
|
|
|
} else {
|
2002-12-03 23:46:16 +00:00
|
|
|
g_print ("Going into the main GStreamer loop\n");
|
2004-03-15 19:27:17 +00:00
|
|
|
can_quit = TRUE; /* we don't want gst_main_quit called before gst_main */
|
2002-12-07 14:16:52 +00:00
|
|
|
gst_main ();
|
2002-12-03 23:46:16 +00:00
|
|
|
}
|
2002-11-14 21:19:55 +00:00
|
|
|
running = FALSE;
|
|
|
|
g_print ("Coming out of the main GStreamer loop\n");
|
|
|
|
g_signal_handler_disconnect (G_OBJECT (thread), id);
|
|
|
|
gst_element_set_state (thread, GST_STATE_NULL);
|
|
|
|
g_print ("Unreffing thread\n");
|
|
|
|
g_object_unref (G_OBJECT (thread));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|