source: trunk/third/gstreamer/testsuite/threads/threadb.c @ 21005

Revision 21005, 2.0 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21004, which included commits to RCS files with non-trunk default branches.
Line 
1#include <gst/gst.h>
2
3/* threadb.c
4 * this tests if we can make a GstThread, put some stuff in it,
5 * dispatch it, and let it run from a main gst loop
6 * we repeat the main loop a hundred times to test thread reuse
7 * underneath GstThread
8 */
9
10gboolean running = FALSE;
11
12static void
13construct_pipeline (GstElement * pipeline)
14{
15  GstElement *src, *sink, *identity;
16
17  src = gst_element_factory_make ("fakesrc", NULL);
18  identity = gst_element_factory_make ("identity", NULL);
19  sink = gst_element_factory_make ("fakesink", NULL);
20  g_assert (src);
21  g_assert (identity);
22  g_assert (sink);
23
24  gst_element_link_many (src, identity, sink, NULL);
25
26  gst_bin_add_many (GST_BIN (pipeline), src, identity, sink, NULL);
27
28  g_object_set (G_OBJECT (src), "num_buffers", 5, NULL);
29}
30
31void
32state_changed (GstElement * el, gint arg1, gint arg2, gpointer user_data)
33{
34  GstElementState state = gst_element_get_state (el);
35
36  g_print ("element %s has changed state to %s\n",
37      GST_ELEMENT_NAME (el), gst_element_state_get_name (state));
38  if (state == GST_STATE_PLAYING)
39    running = TRUE;
40  /* if we move from PLAYING to PAUSED, we're done */
41  if (state == GST_STATE_PAUSED && running) {
42    running = FALSE;
43    gst_main_quit ();
44  }
45}
46
47int
48main (gint argc, gchar * argv[])
49{
50  int runs = 100;
51  int i;
52  gulong id;
53  GstElement *thread;
54
55  gst_init (&argc, &argv);
56
57  for (i = 0; i < runs; ++i) {
58    thread = gst_thread_new ("main_thread");
59    g_assert (thread);
60
61    /* connect state change signal */
62    id = g_signal_connect (G_OBJECT (thread), "state_change",
63        G_CALLBACK (state_changed), NULL);
64    construct_pipeline (thread);
65
66    g_print ("Setting thread to play\n");
67    gst_element_set_state (thread, GST_STATE_PLAYING);
68
69    g_print ("Going into the main GStreamer loop\n");
70    gst_main ();
71    g_print ("Coming out of the main GStreamer loop\n");
72    g_signal_handler_disconnect (G_OBJECT (thread), id);
73    gst_element_set_state (thread, GST_STATE_NULL);
74    g_print ("Unreffing thread\n");
75    g_object_unref (G_OBJECT (thread));
76    running = FALSE;
77  }
78
79  return 0;
80}
Note: See TracBrowser for help on using the repository browser.