[21447] | 1 | /* |
---|
| 2 | * Test that: |
---|
| 3 | * - get-based sources can return data, loop-based sources can push. |
---|
| 4 | * - chain-based filters receive/push, loop-based filters can pull/push. |
---|
| 5 | * - chain-based sinks receive, loop-based sinks pull. |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include <gst/gst.h> |
---|
| 9 | |
---|
| 10 | /* |
---|
| 11 | * Scary type code. |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | typedef struct _GstTestElement |
---|
| 15 | { |
---|
| 16 | GstElement parent; |
---|
| 17 | GstPad *srcpad, *sinkpad; |
---|
| 18 | } GstTestSrc, GstTestFilter, GstTestSink, GstTestElement; |
---|
| 19 | |
---|
| 20 | typedef GstElementClass GstTestSrcClass, GstTestFilterClass, GstTestSinkClass, |
---|
| 21 | GstTestElementClass; |
---|
| 22 | |
---|
| 23 | #define gst_test_src_class_init gst_test_element_class_init |
---|
| 24 | #define gst_test_filter_class_init gst_test_element_class_init |
---|
| 25 | #define gst_test_sink_class_init gst_test_element_class_init |
---|
| 26 | |
---|
| 27 | #define gst_test_src_base_init gst_test_element_base_init |
---|
| 28 | #define gst_test_filter_base_init gst_test_element_base_init |
---|
| 29 | #define gst_test_sink_base_init gst_test_element_base_init |
---|
| 30 | |
---|
| 31 | static void |
---|
| 32 | gst_test_element_class_init (GstTestElementClass * klass) |
---|
| 33 | { |
---|
| 34 | } |
---|
| 35 | static void |
---|
| 36 | gst_test_element_base_init (gpointer klass) |
---|
| 37 | { |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | /* |
---|
| 41 | * Actual element code. |
---|
| 42 | */ |
---|
| 43 | |
---|
| 44 | gboolean loop = FALSE; |
---|
| 45 | |
---|
| 46 | static GstData * |
---|
| 47 | gst_test_src_get (GstPad * pad) |
---|
| 48 | { |
---|
| 49 | return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT)); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | static void |
---|
| 53 | gst_test_src_loop (GstElement * element) |
---|
| 54 | { |
---|
| 55 | GstTestSrc *src = (GstTestElement *) element; |
---|
| 56 | |
---|
| 57 | gst_pad_push (src->srcpad, gst_test_src_get (src->srcpad)); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | static void |
---|
| 61 | gst_test_src_init (GstTestElement * src) |
---|
| 62 | { |
---|
| 63 | src->srcpad = gst_pad_new ("src", GST_PAD_SRC); |
---|
| 64 | if (loop) { |
---|
| 65 | gst_element_set_loop_function (GST_ELEMENT (src), gst_test_src_loop); |
---|
| 66 | } else { |
---|
| 67 | gst_pad_set_get_function (src->srcpad, gst_test_src_get); |
---|
| 68 | } |
---|
| 69 | gst_element_add_pad (GST_ELEMENT (src), src->srcpad); |
---|
| 70 | |
---|
| 71 | GST_FLAG_SET (src, GST_ELEMENT_EVENT_AWARE); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | static void |
---|
| 75 | gst_test_filter_chain (GstPad * pad, GstData * data) |
---|
| 76 | { |
---|
| 77 | GstTestFilter *filter = (GstTestElement *) gst_pad_get_parent (pad); |
---|
| 78 | |
---|
| 79 | gst_pad_push (filter->srcpad, data); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | static void |
---|
| 83 | gst_test_filter_loop (GstElement * element) |
---|
| 84 | { |
---|
| 85 | GstTestFilter *filter = (GstTestElement *) element; |
---|
| 86 | |
---|
| 87 | gst_test_filter_chain (filter->sinkpad, gst_pad_pull (filter->sinkpad)); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | static void |
---|
| 91 | gst_test_filter_init (GstTestElement * filter) |
---|
| 92 | { |
---|
| 93 | filter->sinkpad = gst_pad_new ("sink", GST_PAD_SINK); |
---|
| 94 | if (loop) { |
---|
| 95 | gst_element_set_loop_function (GST_ELEMENT (filter), gst_test_filter_loop); |
---|
| 96 | } else { |
---|
| 97 | gst_pad_set_chain_function (filter->sinkpad, gst_test_filter_chain); |
---|
| 98 | } |
---|
| 99 | gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad); |
---|
| 100 | |
---|
| 101 | filter->srcpad = gst_pad_new ("src", GST_PAD_SRC); |
---|
| 102 | gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad); |
---|
| 103 | |
---|
| 104 | GST_FLAG_SET (filter, GST_ELEMENT_EVENT_AWARE); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | static void |
---|
| 108 | gst_test_sink_chain (GstPad * pad, GstData * data) |
---|
| 109 | { |
---|
| 110 | gst_data_unref (data); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | static void |
---|
| 114 | gst_test_sink_loop (GstElement * element) |
---|
| 115 | { |
---|
| 116 | GstTestSink *sink = (GstTestElement *) element; |
---|
| 117 | |
---|
| 118 | gst_test_sink_chain (sink->sinkpad, gst_pad_pull (sink->sinkpad)); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | static void |
---|
| 122 | gst_test_sink_init (GstTestElement * sink) |
---|
| 123 | { |
---|
| 124 | sink->sinkpad = gst_pad_new ("sink", GST_PAD_SINK); |
---|
| 125 | if (loop) { |
---|
| 126 | gst_element_set_loop_function (GST_ELEMENT (sink), gst_test_sink_loop); |
---|
| 127 | } else { |
---|
| 128 | gst_pad_set_chain_function (sink->sinkpad, gst_test_sink_chain); |
---|
| 129 | } |
---|
| 130 | gst_element_add_pad (GST_ELEMENT (sink), sink->sinkpad); |
---|
| 131 | |
---|
| 132 | GST_FLAG_SET (sink, GST_ELEMENT_EVENT_AWARE); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | #define parent_class src_parent_class |
---|
| 136 | GST_BOILERPLATE (GstTestSrc, gst_test_src, GstElement, GST_TYPE_ELEMENT); |
---|
| 137 | #undef parent_class |
---|
| 138 | #define parent_class filter_parent_class |
---|
| 139 | GST_BOILERPLATE (GstTestFilter, gst_test_filter, GstElement, GST_TYPE_ELEMENT); |
---|
| 140 | #undef parent_class |
---|
| 141 | #define parent_class sink_parent_class |
---|
| 142 | GST_BOILERPLATE (GstTestSink, gst_test_sink, GstElement, GST_TYPE_ELEMENT); |
---|
| 143 | #undef parent_class |
---|
| 144 | |
---|
| 145 | /* |
---|
| 146 | * Actual test. |
---|
| 147 | */ |
---|
| 148 | |
---|
| 149 | static void |
---|
| 150 | cb_error (GstElement * element) |
---|
| 151 | { |
---|
| 152 | g_assert_not_reached (); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | int |
---|
| 156 | main (int argc, char *argv[]) |
---|
| 157 | { |
---|
| 158 | GstElement *pipeline, *src, *filter, *sink; |
---|
| 159 | gint n, r; |
---|
| 160 | gboolean res; |
---|
| 161 | |
---|
| 162 | gst_init (&argc, &argv); |
---|
| 163 | |
---|
| 164 | for (r = 0; r < 2; r++) { |
---|
| 165 | pipeline = gst_pipeline_new ("p"); |
---|
| 166 | g_signal_connect (pipeline, "error", G_CALLBACK (cb_error), NULL); |
---|
| 167 | src = g_object_new (gst_test_src_get_type (), NULL); |
---|
| 168 | gst_object_set_name (GST_OBJECT (src), "src"); |
---|
| 169 | filter = g_object_new (gst_test_filter_get_type (), NULL); |
---|
| 170 | gst_object_set_name (GST_OBJECT (filter), "filter"); |
---|
| 171 | sink = g_object_new (gst_test_sink_get_type (), NULL); |
---|
| 172 | gst_object_set_name (GST_OBJECT (sink), "sink"); |
---|
| 173 | gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL); |
---|
| 174 | res = gst_element_link (src, filter); |
---|
| 175 | g_assert (res); |
---|
| 176 | res = gst_element_link (filter, sink); |
---|
| 177 | g_assert (res); |
---|
| 178 | gst_element_set_state (pipeline, GST_STATE_PLAYING); |
---|
| 179 | |
---|
| 180 | for (n = 0; n < 100; n++) { |
---|
| 181 | if (!gst_bin_iterate (GST_BIN (pipeline))) |
---|
| 182 | g_assert_not_reached (); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | gst_element_set_state (pipeline, GST_STATE_NULL); |
---|
| 186 | gst_object_unref (GST_OBJECT (pipeline)); |
---|
| 187 | |
---|
| 188 | /* switch element types */ |
---|
| 189 | g_print ("Loop=%s done\n", loop ? "true" : "false"); |
---|
| 190 | loop = !loop; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | return 0; |
---|
| 194 | } |
---|