2002-09-12 19:26:54 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
/* threadb.c
|
|
|
|
* this tests if we can make a GstThread, put some stuff in it,
|
|
|
|
* dispatch it, and let it run from a main gst loop
|
2002-11-14 21:20:47 +00:00
|
|
|
* we repeat the main loop a hundred times to test thread reuse
|
|
|
|
* underneath GstThread
|
2002-09-12 19:26:54 +00:00
|
|
|
*/
|
|
|
|
|
2002-11-14 21:20:47 +00:00
|
|
|
gboolean running = FALSE;
|
2002-09-12 19:26:54 +00:00
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
construct_pipeline (GstElement * pipeline)
|
2002-09-12 19:26:54 +00:00
|
|
|
{
|
|
|
|
GstElement *src, *sink, *identity;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
src = gst_element_factory_make ("fakesrc", NULL);
|
2002-09-12 19:26:54 +00:00
|
|
|
identity = gst_element_factory_make ("identity", NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
sink = gst_element_factory_make ("fakesink", NULL);
|
2002-09-12 19:26:54 +00:00
|
|
|
g_assert (src);
|
|
|
|
g_assert (identity);
|
|
|
|
g_assert (sink);
|
|
|
|
|
2003-01-10 04:54:20 +00:00
|
|
|
gst_element_link_many (src, identity, sink, NULL);
|
2002-09-12 19:26:54 +00:00
|
|
|
|
|
|
|
gst_bin_add_many (GST_BIN (pipeline), src, identity, sink, NULL);
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (src), "num_buffers", 5, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
state_changed (GstElement * el, gint arg1, gint arg2, gpointer user_data)
|
2002-09-12 19:26:54 +00:00
|
|
|
{
|
2005-09-02 15:42:00 +00:00
|
|
|
GstState state = gst_element_get_state (el);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
g_print ("element %s has changed state to %s\n",
|
|
|
|
GST_ELEMENT_NAME (el), gst_element_state_get_name (state));
|
|
|
|
if (state == GST_STATE_PLAYING)
|
|
|
|
running = TRUE;
|
2002-11-13 17:06:23 +00:00
|
|
|
/* if we move from PLAYING to PAUSED, we're done */
|
2003-04-15 18:17:24 +00:00
|
|
|
if (state == GST_STATE_PAUSED && running) {
|
|
|
|
running = FALSE;
|
|
|
|
gst_main_quit ();
|
|
|
|
}
|
2002-09-12 19:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-03-13 15:27:01 +00:00
|
|
|
main (gint argc, gchar * argv[])
|
2002-09-12 19:26:54 +00:00
|
|
|
{
|
2002-11-14 21:20:47 +00:00
|
|
|
int runs = 100;
|
|
|
|
int i;
|
|
|
|
gulong id;
|
2002-09-12 19:26:54 +00:00
|
|
|
GstElement *thread;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2002-09-12 19:26:54 +00:00
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < runs; ++i) {
|
2002-11-14 21:20:47 +00:00
|
|
|
thread = gst_thread_new ("main_thread");
|
|
|
|
g_assert (thread);
|
2002-09-12 19:26:54 +00:00
|
|
|
|
2002-11-14 21:20:47 +00:00
|
|
|
/* connect state change signal */
|
2004-03-13 15:27:01 +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:20:47 +00:00
|
|
|
construct_pipeline (thread);
|
2002-09-12 19:26:54 +00:00
|
|
|
|
2002-11-14 21:20:47 +00:00
|
|
|
g_print ("Setting thread to play\n");
|
|
|
|
gst_element_set_state (thread, GST_STATE_PLAYING);
|
2002-09-12 19:26:54 +00:00
|
|
|
|
2002-11-14 21:20:47 +00:00
|
|
|
g_print ("Going into the main GStreamer loop\n");
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_main ();
|
2002-11-14 21:20:47 +00:00
|
|
|
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));
|
|
|
|
running = FALSE;
|
|
|
|
}
|
2002-09-12 19:26:54 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|