1 | #include <gst/gst.h> |
---|
2 | #include <unistd.h> |
---|
3 | |
---|
4 | /* threadc.c |
---|
5 | * this tests if we can make a GstBin and iterate it inside a GThread |
---|
6 | */ |
---|
7 | |
---|
8 | #define MAX_IDENTITIES 29 |
---|
9 | #define RUNS_PER_IDENTITY 5 |
---|
10 | |
---|
11 | volatile gboolean running = FALSE; |
---|
12 | volatile gboolean done = FALSE; |
---|
13 | |
---|
14 | static void |
---|
15 | construct_pipeline (GstElement * pipeline, gint identities) |
---|
16 | { |
---|
17 | GstElement *src, *sink, *identity = NULL; |
---|
18 | GstElement *from; |
---|
19 | int i; |
---|
20 | |
---|
21 | src = gst_element_factory_make ("fakesrc", NULL); |
---|
22 | sink = gst_element_factory_make ("fakesink", NULL); |
---|
23 | g_assert (src); |
---|
24 | g_assert (sink); |
---|
25 | gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); |
---|
26 | from = src; |
---|
27 | |
---|
28 | for (i = 0; i < identities; ++i) { |
---|
29 | identity = gst_element_factory_make ("identity", NULL); |
---|
30 | g_assert (identity); |
---|
31 | gst_bin_add (GST_BIN (pipeline), identity); |
---|
32 | gst_element_link (from, identity); |
---|
33 | from = identity; |
---|
34 | } |
---|
35 | gst_element_link (identity, sink); |
---|
36 | |
---|
37 | g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL); |
---|
38 | } |
---|
39 | |
---|
40 | static void |
---|
41 | iterator (GstElement * bin) |
---|
42 | { |
---|
43 | gst_element_set_state (bin, GST_STATE_PLAYING); |
---|
44 | while (gst_bin_iterate (GST_BIN (bin))) |
---|
45 | g_print ("+"); |
---|
46 | gst_element_set_state (bin, GST_STATE_NULL); |
---|
47 | g_print ("\n"); |
---|
48 | done = TRUE; |
---|
49 | } |
---|
50 | |
---|
51 | int |
---|
52 | main (gint argc, gchar * argv[]) |
---|
53 | { |
---|
54 | int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY; |
---|
55 | int i; |
---|
56 | GstElement *pipeline; |
---|
57 | |
---|
58 | g_thread_init (NULL); |
---|
59 | gst_init (&argc, &argv); |
---|
60 | |
---|
61 | for (i = 0; i < runs; ++i) { |
---|
62 | pipeline = gst_pipeline_new ("main_pipeline"); |
---|
63 | g_assert (pipeline); |
---|
64 | |
---|
65 | /* connect state change signal */ |
---|
66 | construct_pipeline (pipeline, i / RUNS_PER_IDENTITY + 1); |
---|
67 | |
---|
68 | done = FALSE; |
---|
69 | g_thread_create ((GThreadFunc) iterator, pipeline, FALSE, NULL); |
---|
70 | g_print ("Created GThread\n"); |
---|
71 | |
---|
72 | g_print ("Waiting for thread PLAYING->PAUSED\n"); |
---|
73 | while (!done) /* do nothing */ |
---|
74 | ; |
---|
75 | running = FALSE; |
---|
76 | g_print ("Unreffing pipeline\n"); |
---|
77 | g_object_unref (G_OBJECT (pipeline)); |
---|
78 | } |
---|
79 | |
---|
80 | return 0; |
---|
81 | } |
---|