source: trunk/third/gstreamer/testsuite/threads/threadd.c @ 21448

Revision 21448, 2.5 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21447, which included commits to RCS files with non-trunk default branches.
Line 
1#include <gst/gst.h>
2#include <unistd.h>
3
4/* threadc.c
5 * this tests if we can make a GstThread, with enough cothreads to stress it
6 */
7
8#define MAX_IDENTITIES 29
9#define RUNS_PER_IDENTITY 5
10
11volatile gboolean running = FALSE;
12
13/* must be volatile, we're going to fool the compiler */
14volatile gboolean done = FALSE;
15
16static void
17construct_pipeline (GstElement * pipeline, gint identities)
18{
19  GstElement *src, *sink, *identity = NULL;
20  GstElement *from;
21  int i;
22
23  src = gst_element_factory_make ("fakesrc", NULL);
24  sink = gst_element_factory_make ("fakesink", NULL);
25  g_assert (src);
26  g_assert (sink);
27  gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
28  from = src;
29
30  for (i = 0; i < identities; ++i) {
31    identity = gst_element_factory_make ("identity", NULL);
32    g_assert (identity);
33    gst_bin_add (GST_BIN (pipeline), identity);
34    gst_element_link (from, identity);
35    from = identity;
36  }
37  gst_element_link (identity, sink);
38
39  g_object_set (G_OBJECT (src), "num_buffers", 10, "sizetype", 3, NULL);
40}
41
42void
43state_changed (GstElement * el, gint arg1, gint arg2, gpointer user_data)
44{
45  GstElementState state = gst_element_get_state (el);
46
47  g_print ("element %s has changed state to %s\n",
48      GST_ELEMENT_NAME (el), gst_element_state_get_name (state));
49  if (state == GST_STATE_PLAYING)
50    running = TRUE;
51  /* if we move from PLAYING to PAUSED, we're done */
52  if (state == GST_STATE_PAUSED && running)
53    done = TRUE;
54}
55
56int
57main (gint argc, gchar * argv[])
58{
59  int runs = MAX_IDENTITIES * RUNS_PER_IDENTITY;
60  int i;
61  gulong id;
62  GstElement *thread;
63
64  gst_init (&argc, &argv);
65
66  for (i = 0; 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 / RUNS_PER_IDENTITY + 1);
74
75    g_print ("Setting thread to play with %d identities\n",
76        i / RUNS_PER_IDENTITY + 1);
77    done = FALSE;
78    if (gst_element_set_state (thread, GST_STATE_PLAYING) == GST_STATE_FAILURE) {
79      g_warning ("failed to go to PLAYING");
80    } else {
81      g_print ("Waiting for thread PLAYING->PAUSED\n");
82      while (!done)             /* do nothing */
83        ;
84    }
85    running = FALSE;
86    g_print ("Coming out of the main GStreamer loop\n");
87    g_signal_handler_disconnect (G_OBJECT (thread), id);
88    gst_element_set_state (thread, GST_STATE_NULL);
89    g_print ("Unreffing thread\n");
90    g_object_unref (G_OBJECT (thread));
91  }
92
93  return 0;
94}
Note: See TracBrowser for help on using the repository browser.