summaryrefslogtreecommitdiff
path: root/tests/old/testsuite/pad/link.c
blob: 5d22c381f6d39a02f448633bf7007a2a99181dee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * Test that:
 *  - get-based sources can return data, loop-based sources can push.
 *  - chain-based filters receive/push, loop-based filters can pull/push.
 *  - chain-based sinks receive, loop-based sinks pull.
 */

#include <gst/gst.h>

/*
 * Scary type code.
 */

typedef struct _GstTestElement
{
  GstElement parent;
  GstPad *srcpad, *sinkpad;
} GstTestSrc, GstTestFilter, GstTestSink, GstTestElement;

typedef GstElementClass GstTestSrcClass, GstTestFilterClass, GstTestSinkClass,
    GstTestElementClass;

#define gst_test_src_class_init gst_test_element_class_init
#define gst_test_filter_class_init gst_test_element_class_init
#define gst_test_sink_class_init gst_test_element_class_init

#define gst_test_src_base_init gst_test_element_base_init
#define gst_test_filter_base_init gst_test_element_base_init
#define gst_test_sink_base_init gst_test_element_base_init

static void
gst_test_element_class_init (GstTestElementClass * klass)
{
}
static void
gst_test_element_base_init (gpointer klass)
{
}

/*
 * Actual element code.
 */

gboolean loop = FALSE;

static GstData *
gst_test_src_get (GstPad * pad)
{
  return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
}

static void
gst_test_src_loop (GstElement * element)
{
  GstTestSrc *src = (GstTestElement *) element;

  gst_pad_push (src->srcpad, gst_test_src_get (src->srcpad));
}

static void
gst_test_src_init (GstTestElement * src)
{
  src->srcpad = gst_pad_new ("src", GST_PAD_SRC);
  if (loop) {
    gst_element_set_loop_function (GST_ELEMENT (src), gst_test_src_loop);
  } else {
    gst_pad_set_get_function (src->srcpad, gst_test_src_get);
  }
  gst_element_add_pad (GST_ELEMENT (src), src->srcpad);

  GST_FLAG_SET (src, GST_ELEMENT_EVENT_AWARE);
}

static void
gst_test_filter_chain (GstPad * pad, GstData * data)
{
  GstTestFilter *filter = (GstTestElement *) gst_pad_get_parent (pad);

  gst_pad_push (filter->srcpad, data);
}

static void
gst_test_filter_loop (GstElement * element)
{
  GstTestFilter *filter = (GstTestElement *) element;

  gst_test_filter_chain (filter->sinkpad, gst_pad_pull (filter->sinkpad));
}

static void
gst_test_filter_init (GstTestElement * filter)
{
  filter->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
  if (loop) {
    gst_element_set_loop_function (GST_ELEMENT (filter), gst_test_filter_loop);
  } else {
    gst_pad_set_chain_function (filter->sinkpad, gst_test_filter_chain);
  }
  gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);

  filter->srcpad = gst_pad_new ("src", GST_PAD_SRC);
  gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);

  GST_FLAG_SET (filter, GST_ELEMENT_EVENT_AWARE);
}

static void
gst_test_sink_chain (GstPad * pad, GstData * data)
{
  gst_data_unref (data);
}

static void
gst_test_sink_loop (GstElement * element)
{
  GstTestSink *sink = (GstTestElement *) element;

  gst_test_sink_chain (sink->sinkpad, gst_pad_pull (sink->sinkpad));
}

static void
gst_test_sink_init (GstTestElement * sink)
{
  sink->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
  if (loop) {
    gst_element_set_loop_function (GST_ELEMENT (sink), gst_test_sink_loop);
  } else {
    gst_pad_set_chain_function (sink->sinkpad, gst_test_sink_chain);
  }
  gst_element_add_pad (GST_ELEMENT (sink), sink->sinkpad);

  GST_FLAG_SET (sink, GST_ELEMENT_EVENT_AWARE);
}

#define parent_class src_parent_class
GST_BOILERPLATE (GstTestSrc, gst_test_src, GstElement, GST_TYPE_ELEMENT);
#undef parent_class
#define parent_class filter_parent_class
GST_BOILERPLATE (GstTestFilter, gst_test_filter, GstElement, GST_TYPE_ELEMENT);
#undef parent_class
#define parent_class sink_parent_class
GST_BOILERPLATE (GstTestSink, gst_test_sink, GstElement, GST_TYPE_ELEMENT);
#undef parent_class

/*
 * Actual test.
 */

static void
cb_error (GstElement * element)
{
  g_assert_not_reached ();
}

int
main (int argc, char *argv[])
{
  GstElement *pipeline, *src, *filter, *sink;
  gint n, r;
  gboolean res;

  gst_init (&argc, &argv);

  for (r = 0; r < 2; r++) {
    pipeline = gst_pipeline_new ("p");
    g_signal_connect (pipeline, "error", G_CALLBACK (cb_error), NULL);
    src = g_object_new (gst_test_src_get_type (), NULL);
    gst_object_set_name (GST_OBJECT (src), "src");
    filter = g_object_new (gst_test_filter_get_type (), NULL);
    gst_object_set_name (GST_OBJECT (filter), "filter");
    sink = g_object_new (gst_test_sink_get_type (), NULL);
    gst_object_set_name (GST_OBJECT (sink), "sink");
    gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL);
    res = gst_element_link (src, filter);
    g_assert (res);
    res = gst_element_link (filter, sink);
    g_assert (res);
    gst_element_set_state (pipeline, GST_STATE_PLAYING);

    for (n = 0; n < 100; n++) {
      if (!gst_bin_iterate (GST_BIN (pipeline)))
        g_assert_not_reached ();
    }

    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (GST_OBJECT (pipeline));

    /* switch element types */
    g_print ("Loop=%s done\n", loop ? "true" : "false");
    loop = !loop;
  }

  return 0;
}