1 | #include <gst/gst.h> |
---|
2 | |
---|
3 | /* threadf.c |
---|
4 | * this tests if we can make a GThread and construct and interate a pipeline |
---|
5 | * inside it |
---|
6 | * used to fail because of cothread ctx key not being reset on context |
---|
7 | * destroy |
---|
8 | */ |
---|
9 | |
---|
10 | #define MAX_IDENTITIES 29 |
---|
11 | #define RUNS_PER_IDENTITY 5 |
---|
12 | |
---|
13 | volatile gboolean running = FALSE; |
---|
14 | volatile gboolean done = FALSE; |
---|
15 | |
---|
16 | static void |
---|
17 | construct_pipeline (GstElement * pipeline, gint identities) |
---|
18 | { |
---|
19 | GstElement *src, *sink; |
---|
20 | GstElement *identity = NULL; |
---|
21 | GstElement *from; |
---|
22 | int i; |
---|
23 | |
---|
24 | identity = NULL; |
---|
25 | src = gst_element_factory_make ("fakesrc", NULL); |
---|
26 | sink = gst_element_factory_make ("fakesink", NULL); |
---|
27 | g_assert (src); |
---|
28 | g_assert (sink); |
---|
29 | gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); |
---|
30 | from = src; |
---|
31 | |
---|
32 | for (i = 0; i < identities; ++i) { |
---|
33 | identity = gst_element_factory_make ("identity", NULL); |
---|
34 | g_assert (identity); |
---|
35 | gst_bin_add (GST_BIN (pipeline), identity); |
---|
36 | if (!(gst_element_link (from, identity))) |
---|
37 | g_print ("Warning: can't link identity with previous element\n"); |
---|
38 | from = identity; |
---|
39 | } |
---|
40 | gst_element_link (identity, sink); |
---|
41 | |
---|
42 | g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL); |
---|
43 | } |
---|
44 | |
---|
45 | static void |
---|
46 | thread (void) |
---|
47 | { |
---|
48 | int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY; |
---|
49 | int i; |
---|
50 | GstElement *pipeline; |
---|
51 | |
---|
52 | for (i = 30; i < runs; ++i) { |
---|
53 | pipeline = gst_pipeline_new ("main_pipeline"); |
---|
54 | g_assert (pipeline); |
---|
55 | |
---|
56 | g_print ("Run %d, using %d identities\n", i, i / RUNS_PER_IDENTITY + 1); |
---|
57 | construct_pipeline (pipeline, i / RUNS_PER_IDENTITY + 1); |
---|
58 | if (!gst_element_set_state (pipeline, GST_STATE_PLAYING)) |
---|
59 | g_print ("WARNING: can't set pipeline to play\n"); |
---|
60 | while (gst_bin_iterate (GST_BIN (pipeline))) |
---|
61 | g_print ("+"); |
---|
62 | g_print ("\n"); |
---|
63 | g_print ("Unreffing pipeline\n"); |
---|
64 | g_object_unref (G_OBJECT (pipeline)); |
---|
65 | } |
---|
66 | done = TRUE; |
---|
67 | } |
---|
68 | |
---|
69 | int |
---|
70 | main (gint argc, gchar * argv[]) |
---|
71 | { |
---|
72 | done = FALSE; |
---|
73 | |
---|
74 | g_thread_init (NULL); |
---|
75 | gst_init (&argc, &argv); |
---|
76 | |
---|
77 | g_thread_create ((GThreadFunc) thread, NULL, FALSE, NULL); |
---|
78 | g_print ("main: created GThread\n"); |
---|
79 | while (!done) |
---|
80 | g_usleep (G_USEC_PER_SEC); |
---|
81 | g_print ("main: done\n"); |
---|
82 | return 0; |
---|
83 | } |
---|