1 | #include <gst/gst.h> |
---|
2 | |
---|
3 | /* threadc.c |
---|
4 | * this tests if we can make a GstThread, with enough cothreads to stress it |
---|
5 | */ |
---|
6 | |
---|
7 | gboolean running = FALSE; |
---|
8 | gboolean can_quit = FALSE; |
---|
9 | |
---|
10 | static void |
---|
11 | construct_pipeline (GstElement * pipeline, gint identities) |
---|
12 | { |
---|
13 | GstElement *src, *sink; |
---|
14 | GstElement *identity = NULL; |
---|
15 | GstElement *from; |
---|
16 | int i; |
---|
17 | |
---|
18 | identity = NULL; |
---|
19 | src = gst_element_factory_make ("fakesrc", NULL); |
---|
20 | sink = gst_element_factory_make ("fakesink", NULL); |
---|
21 | g_assert (src); |
---|
22 | g_assert (sink); |
---|
23 | gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); |
---|
24 | from = src; |
---|
25 | |
---|
26 | for (i = 0; i < identities; ++i) { |
---|
27 | identity = gst_element_factory_make ("identity", NULL); |
---|
28 | g_assert (identity); |
---|
29 | gst_bin_add (GST_BIN (pipeline), identity); |
---|
30 | gst_element_link (from, identity); |
---|
31 | from = identity; |
---|
32 | } |
---|
33 | gst_element_link (identity, sink); |
---|
34 | |
---|
35 | g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL); |
---|
36 | } |
---|
37 | |
---|
38 | void |
---|
39 | state_changed (GstElement * el, gint arg1, gint arg2, gpointer user_data) |
---|
40 | { |
---|
41 | GstElementState state = gst_element_get_state (el); |
---|
42 | |
---|
43 | g_print ("element %s has changed state to %s\n", |
---|
44 | GST_ELEMENT_NAME (el), gst_element_state_get_name (state)); |
---|
45 | if (state == GST_STATE_PLAYING) |
---|
46 | running = TRUE; |
---|
47 | /* if we move from PLAYING to PAUSED, we're done */ |
---|
48 | if (state == GST_STATE_PAUSED && running) { |
---|
49 | while (!can_quit); |
---|
50 | can_quit = FALSE; |
---|
51 | g_print ("quitting main loop\n"); |
---|
52 | gst_main_quit (); |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | int |
---|
57 | main (gint argc, gchar * argv[]) |
---|
58 | { |
---|
59 | int runs = 290; |
---|
60 | int i; |
---|
61 | gulong id; |
---|
62 | GstElement *thread; |
---|
63 | |
---|
64 | gst_init (&argc, &argv); |
---|
65 | |
---|
66 | for (i = 90; i < runs; ++i) { |
---|
67 | thread = gst_thread_new ("main_thread"); |
---|
68 | g_assert (thread); |
---|
69 | |
---|
70 | /* connect state change signal */ |
---|
71 | id = g_signal_connect (G_OBJECT (thread), "state_change", |
---|
72 | G_CALLBACK (state_changed), NULL); |
---|
73 | construct_pipeline (thread, i / 10 + 1); |
---|
74 | |
---|
75 | g_print ("Setting thread to play with %d identities\n", i / 10 + 1); |
---|
76 | if (gst_element_set_state (thread, GST_STATE_PLAYING) == GST_STATE_FAILURE) { |
---|
77 | g_error ("Failed setting thread to play\n"); |
---|
78 | } else { |
---|
79 | g_print ("Going into the main GStreamer loop\n"); |
---|
80 | can_quit = TRUE; /* we don't want gst_main_quit called before gst_main */ |
---|
81 | gst_main (); |
---|
82 | } |
---|
83 | running = FALSE; |
---|
84 | g_print ("Coming out of the main GStreamer loop\n"); |
---|
85 | g_signal_handler_disconnect (G_OBJECT (thread), id); |
---|
86 | gst_element_set_state (thread, GST_STATE_NULL); |
---|
87 | g_print ("Unreffing thread\n"); |
---|
88 | g_object_unref (G_OBJECT (thread)); |
---|
89 | } |
---|
90 | |
---|
91 | return 0; |
---|
92 | } |
---|