2002-11-18 22:48:26 +00:00
|
|
|
#include <gst/gst.h>
|
2003-10-15 01:25:41 +00:00
|
|
|
#include <unistd.h>
|
2002-11-18 22:48:26 +00:00
|
|
|
|
|
|
|
/* threadc.c
|
|
|
|
* this tests if we can make a GstBin and iterate it inside a GThread
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_IDENTITIES 29
|
|
|
|
#define RUNS_PER_IDENTITY 5
|
|
|
|
|
2004-09-06 15:57:11 +00:00
|
|
|
volatile gboolean running = FALSE;
|
|
|
|
volatile gboolean done = FALSE;
|
2002-11-18 22:48:26 +00:00
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
construct_pipeline (GstElement * pipeline, gint identities)
|
2002-11-18 22:48:26 +00:00
|
|
|
{
|
2002-12-03 21:55:39 +00:00
|
|
|
GstElement *src, *sink, *identity = NULL;
|
2002-11-18 22:48:26 +00:00
|
|
|
GstElement *from;
|
|
|
|
int i;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
src = gst_element_factory_make ("fakesrc", NULL);
|
|
|
|
sink = gst_element_factory_make ("fakesink", NULL);
|
2002-11-18 22:48:26 +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-18 22:48:26 +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-18 22:48:26 +00:00
|
|
|
from = identity;
|
|
|
|
}
|
2003-01-09 20:02:34 +00:00
|
|
|
gst_element_link (identity, sink);
|
2002-11-18 22:48:26 +00:00
|
|
|
|
|
|
|
g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
iterator (GstElement * bin)
|
2002-11-18 22:48:26 +00:00
|
|
|
{
|
|
|
|
gst_element_set_state (bin, GST_STATE_PLAYING);
|
2004-03-13 15:27:01 +00:00
|
|
|
while (gst_bin_iterate (GST_BIN (bin)))
|
|
|
|
g_print ("+");
|
2002-12-03 21:34:18 +00:00
|
|
|
gst_element_set_state (bin, GST_STATE_NULL);
|
2002-11-18 22:48:26 +00:00
|
|
|
g_print ("\n");
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-03-13 15:27:01 +00:00
|
|
|
main (gint argc, gchar * argv[])
|
2002-11-18 22:48:26 +00:00
|
|
|
{
|
|
|
|
int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY;
|
|
|
|
int i;
|
|
|
|
GstElement *pipeline;
|
|
|
|
|
|
|
|
g_thread_init (NULL);
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < runs; ++i) {
|
2002-11-18 22:48:26 +00:00
|
|
|
pipeline = gst_pipeline_new ("main_pipeline");
|
|
|
|
g_assert (pipeline);
|
|
|
|
|
|
|
|
/* connect state change signal */
|
|
|
|
construct_pipeline (pipeline, i / RUNS_PER_IDENTITY + 1);
|
|
|
|
|
|
|
|
done = FALSE;
|
|
|
|
g_thread_create ((GThreadFunc) iterator, pipeline, FALSE, NULL);
|
|
|
|
g_print ("Created GThread\n");
|
|
|
|
|
|
|
|
g_print ("Waiting for thread PLAYING->PAUSED\n");
|
2004-03-15 19:27:17 +00:00
|
|
|
while (!done) /* do nothing */
|
2004-03-13 15:27:01 +00:00
|
|
|
;
|
2002-11-18 22:48:26 +00:00
|
|
|
running = FALSE;
|
|
|
|
g_print ("Unreffing pipeline\n");
|
|
|
|
g_object_unref (G_OBJECT (pipeline));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|