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

Revision 21448, 3.7 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
3/*
4 * FIXME:
5 * these tests should have a maximum run length, so that they get killed
6 * if they lock up, which they're bound to do.
7 */
8
9void
10usage (void)
11{
12  g_print ("compile this test with TESTNUM defined.\n"
13      "   available TESTNUMs:   \n"
14      "          1: stress test state change      \n"
15      "          2: iterate once                  \n"
16      "          3: iterate twice                 \n"
17      "          4: state change while running    \n"
18      "          5: state change in thread context\n");
19}
20
21static void
22construct_pipeline (GstElement * pipeline)
23{
24  GstElement *src, *sink, *queue, *identity, *thread;
25
26  src = gst_element_factory_make ("fakesrc", NULL);
27  sink = gst_element_factory_make ("fakesink", "sink");
28  identity = gst_element_factory_make ("identity", NULL);
29  queue = gst_element_factory_make ("queue", NULL);
30  thread = gst_element_factory_make ("thread", NULL);
31
32  gst_element_link_many (src, queue, identity, sink, NULL);
33
34  gst_bin_add_many (GST_BIN (pipeline), src, queue, thread, NULL);
35  gst_bin_add_many (GST_BIN (thread), identity, sink, NULL);
36
37  g_object_set (G_OBJECT (src), "num_buffers", 5, NULL);
38  //g_object_set (sink, "signal-handoffs", TRUE, NULL);
39}
40
41void
42change_state (GstElement * element, GstBuffer * buf, GstPad * pad,
43    GstElement * pipeline)
44{
45  gst_element_set_state (pipeline, GST_STATE_NULL);
46}
47
48int
49main (gint argc, gchar * argv[])
50{
51  GstElement *pipeline;
52
53  gst_init (&argc, &argv);
54
55#ifndef TESTNUM
56  usage ();
57  return -1;
58#endif
59
60  pipeline = gst_pipeline_new ("main_pipeline");
61  construct_pipeline (pipeline);
62
63  if (TESTNUM == 1) {
64    g_print ("thread test 1: stress test state changes...\n");
65
66    g_print ("NULL\n");
67    gst_element_set_state (pipeline, GST_STATE_NULL);
68    g_print ("READY\n");
69    gst_element_set_state (pipeline, GST_STATE_READY);
70    g_print ("NULL\n");
71    gst_element_set_state (pipeline, GST_STATE_NULL);
72    g_print ("PAUSED\n");
73    gst_element_set_state (pipeline, GST_STATE_PAUSED);
74    g_print ("READY\n");
75    gst_element_set_state (pipeline, GST_STATE_READY);
76    g_print ("PAUSED\n");
77    gst_element_set_state (pipeline, GST_STATE_PAUSED);
78    g_print ("PLAYING\n");
79    gst_element_set_state (pipeline, GST_STATE_PLAYING);
80    /* element likely hits EOS and does a state transition to PAUSED */
81    g_print ("READY\n");
82    gst_element_set_state (pipeline, GST_STATE_READY);
83    g_print ("NULL\n");
84    gst_element_set_state (pipeline, GST_STATE_NULL);
85  }
86
87  if (TESTNUM == 2 || TESTNUM == 3) {
88    gst_element_set_state (pipeline, GST_STATE_PLAYING);
89    g_print ("running ...\n");
90    while (gst_bin_iterate (GST_BIN (pipeline)));
91    g_print ("done ...\n");
92    gst_element_set_state (pipeline, GST_STATE_NULL);
93  }
94  if (TESTNUM == 3) {
95    gst_element_set_state (pipeline, GST_STATE_PLAYING);
96    g_print ("running ...\n");
97    while (gst_bin_iterate (GST_BIN (pipeline)));
98    g_print ("done ...\n");
99    gst_element_set_state (pipeline, GST_STATE_NULL);
100  }
101  if (TESTNUM == 4) {
102    gint run;
103
104    gst_element_set_state (pipeline, GST_STATE_PLAYING);
105    g_print ("running ...\n");
106    for (run = 0; run < 3; run++) {
107      gst_bin_iterate (GST_BIN (pipeline));
108    }
109    gst_element_set_state (pipeline, GST_STATE_NULL);
110  }
111  if (TESTNUM == 5) {
112    /* I don't think this test is supposed to work */
113    GstElement *sink;
114
115    sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
116    g_assert (sink);
117
118    g_signal_connect (G_OBJECT (sink), "handoff",
119        G_CALLBACK (change_state), pipeline);
120    gst_element_set_state (pipeline, GST_STATE_PLAYING);
121    g_print ("running ...\n");
122    while (gst_bin_iterate (GST_BIN (pipeline)));
123    g_print ("stopping ...\n");
124    gst_element_set_state (pipeline, GST_STATE_NULL);
125  }
126
127  return 0;
128}
Note: See TracBrowser for help on using the repository browser.