• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * Copyright (C) 2020 LTN Global Communications
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include <gst/gst.h>
22 #include <gst/check/gstcheck.h>
23 #include <gst/check/gstharness.h>
24 
25 #define PACKETSIZE 188
26 
27 /* Output of the following pipeline, split into standard 188-bytes packets:
28  *
29  * audiotestsrc num-buffers=1 samplesperbuffer=1280 wave=silence
30  * ! avenc_aac ! mpegtsmux
31  */
32 static const guint8 aac_ts[] = {
33   0x47, 0x40, 0x00, 0x31, 0xa6, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
34   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
35   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
36   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
37   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
38   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
39   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
40   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
41   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
42   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
43   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
44   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
45   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
46   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
47   0xff, 0xff, 0xff, 0x00, 0x00, 0xb0, 0x0d, 0x00, 0x01, 0xc1, 0x00, 0x00,
48   0x00, 0x01, 0xe0, 0x20, 0xa2, 0xc3, 0x29, 0x41,
49 
50   0x47, 0x40, 0x20, 0x31, 0x9b, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
51   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
52   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
53   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
54   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
55   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
56   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
57   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
58   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
59   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
60   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
61   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
62   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
63   0xff, 0xff, 0xff, 0xff, 0x00, 0x02, 0xb0, 0x18, 0x00, 0x01, 0xc1, 0x00,
64   0x00, 0xe0, 0x41, 0xf0, 0x00, 0x0f, 0xe0, 0x41, 0xf0, 0x06, 0x0a, 0x04,
65   0x65, 0x6e, 0x00, 0x00, 0xfa, 0xa6, 0x03, 0x09,
66 
67   0x47, 0x40, 0x41, 0x31, 0x8d, 0x10, 0x09, 0xa7, 0xd6, 0x87, 0x7e, 0x00,
68   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
69   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
70   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
71   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
72   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
73   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
74   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
75   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
76   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
77   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
78   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
79   0xff, 0xff, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x24, 0x81, 0x80, 0x05, 0x21,
80   0x4d, 0x3f, 0xb2, 0x01, 0xff, 0xf1, 0x50, 0x40, 0x03, 0x9f, 0xfc, 0xde,
81   0x02, 0x00, 0x4c, 0x61, 0x76, 0x63, 0x35, 0x38, 0x2e, 0x35, 0x34, 0x2e,
82   0x31, 0x30, 0x30, 0x00, 0x02, 0x30, 0x40, 0x0e,
83 
84   0x47, 0x40, 0x41, 0x32, 0x9e, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
85   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
86   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
87   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
88   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
89   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
90   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
91   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
92   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
93   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
94   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
95   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
96   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
97   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0xc0, 0x00,
98   0x13, 0x81, 0x80, 0x05, 0x21, 0x4d, 0x3f, 0xc2, 0x53, 0xff, 0xf1, 0x50,
99   0x40, 0x01, 0x7f, 0xfc, 0x01, 0x18, 0x20, 0x07,
100 
101   0x47, 0x40, 0x41, 0x33, 0x9e, 0x10, 0x09, 0xa7, 0xde, 0xb0, 0xfe, 0x00,
102   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
103   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
104   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
105   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
106   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
107   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
108   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
109   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
110   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
111   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
112   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
113   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
114   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0xc0, 0x00,
115   0x13, 0x81, 0x80, 0x05, 0x21, 0x4d, 0x3f, 0xd2, 0xa7, 0xff, 0xf1, 0x50,
116   0x40, 0x01, 0x7f, 0xfc, 0x01, 0x18, 0x20, 0x07
117 };
118 
119 G_STATIC_ASSERT (sizeof aac_ts % PACKETSIZE == 0);
120 static const guint aac_ts_packets = sizeof aac_ts / PACKETSIZE;
121 
122 /* Buffers output by tsdemux for above data */
123 static const guint8 aac_data[] = {
124   0xff, 0xf1, 0x50, 0x40, 0x03, 0x9f, 0xfc, 0xde, 0x02, 0x00, 0x4c, 0x61,
125   0x76, 0x63, 0x35, 0x38, 0x2e, 0x35, 0x34, 0x2e, 0x31, 0x30, 0x30, 0x00,
126   0x02, 0x30, 0x40, 0x0e,
127 
128   0xff, 0xf1, 0x50, 0x40, 0x01, 0x7f, 0xfc, 0x01, 0x18, 0x20, 0x07,
129 
130   0xff, 0xf1, 0x50, 0x40, 0x01, 0x7f, 0xfc, 0x01, 0x18, 0x20, 0x07
131 };
132 
133 /* Padding packet */
134 static const guint8 padding_ts[] = {
135   0x47, 0x1f, 0xff, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
139   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
145   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
146   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
151 };
152 
153 G_STATIC_ASSERT (sizeof padding_ts == PACKETSIZE);
154 
GST_START_TEST(test_tsparse_simple)155 GST_START_TEST (test_tsparse_simple)
156 {
157   GstHarness *h = gst_harness_new ("tsparse");
158   GstBuffer *buf;
159 
160   gst_harness_set_src_caps_str (h, "video/mpegts,systemstream=true");
161   gst_harness_set_sink_caps_str (h,
162       "video/mpegts,systemstream=true,packetsize=" G_STRINGIFY (PACKETSIZE));
163 
164   buf =
165       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, (guint8 *) aac_ts,
166       sizeof aac_ts, 0, sizeof aac_ts, NULL, NULL);
167   buf = gst_harness_push_and_pull (h, buf);
168   gst_check_buffer_data (buf, aac_ts, sizeof aac_ts);
169   gst_buffer_unref (buf);
170 
171   gst_harness_push_event (h, gst_event_new_eos ());
172   fail_unless (gst_harness_buffers_in_queue (h) == 0);
173 
174   gst_harness_teardown (h);
175 }
176 
177 GST_END_TEST;
178 
GST_START_TEST(test_tsparse_align_auto)179 GST_START_TEST (test_tsparse_align_auto)
180 {
181   GstHarness *h = gst_harness_new ("tsparse");
182   GstBuffer *buf;
183   gsize i;
184 
185   gst_harness_set_src_caps_str (h, "video/mpegts,systemstream=true");
186   gst_harness_set_sink_caps_str (h,
187       "video/mpegts,systemstream=true,packetsize=" G_STRINGIFY (PACKETSIZE));
188 
189   buf =
190       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, (guint8 *) aac_ts,
191       sizeof aac_ts, 0, sizeof aac_ts, NULL, NULL);
192   for (i = 0; i < sizeof aac_ts; i += 1) {
193     fail_unless (gst_harness_push (h, gst_buffer_copy_region (buf,
194                 GST_BUFFER_COPY_MEMORY, i, 1)) == GST_FLOW_OK);
195   }
196   gst_buffer_unref (buf);
197 
198   /* FIXME: Using automatic alignment, feeding tsparse one byte at a time should
199    * make it return each packet in a separate buffer (5 buffers total) but at
200    * the time of writing it only outputs 2 buffers.
201    */
202 
203   gst_harness_push_event (h, gst_event_new_eos ());
204   fail_unless (gst_harness_buffers_in_queue (h) == aac_ts_packets,
205       "Expected %u buffers, got %u", aac_ts_packets,
206       gst_harness_buffers_in_queue (h));
207 
208   for (i = 0; i < sizeof aac_ts; i += PACKETSIZE) {
209     buf = gst_harness_pull (h);
210     gst_check_buffer_data (buf, aac_ts + i, PACKETSIZE);
211     gst_buffer_unref (buf);
212   }
213 
214   gst_harness_teardown (h);
215 }
216 
217 GST_END_TEST;
218 
GST_START_TEST(test_tsparse_align_fuse)219 GST_START_TEST (test_tsparse_align_fuse)
220 {
221   GstHarness *h = gst_harness_new ("tsparse");
222   GstBuffer *buf;
223   gsize i;
224 
225   gst_harness_set (h, "tsparse", "alignment", aac_ts_packets, NULL);
226 
227   gst_harness_set_src_caps_str (h, "video/mpegts,systemstream=true");
228   gst_harness_set_sink_caps_str (h,
229       "video/mpegts,systemstream=true,packetsize=" G_STRINGIFY (PACKETSIZE));
230 
231   buf =
232       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, (guint8 *) aac_ts,
233       sizeof aac_ts, 0, sizeof aac_ts, NULL, NULL);
234   for (i = 0; i < sizeof aac_ts; i += 1) {
235     fail_unless (gst_harness_push (h, gst_buffer_copy_region (buf,
236                 GST_BUFFER_COPY_MEMORY, i, 1)) == GST_FLOW_OK);
237   }
238   gst_buffer_unref (buf);
239 
240   gst_harness_push_event (h, gst_event_new_eos ());
241   fail_unless (gst_harness_buffers_in_queue (h) == 1,
242       "Expected 1 buffer, got %u", gst_harness_buffers_in_queue (h));
243 
244   buf = gst_harness_pull (h);
245   gst_check_buffer_data (buf, aac_ts, sizeof aac_ts);
246   gst_buffer_unref (buf);
247 
248   gst_harness_teardown (h);
249 }
250 
251 GST_END_TEST;
252 
253 
GST_START_TEST(test_tsparse_align_split)254 GST_START_TEST (test_tsparse_align_split)
255 {
256   GstHarness *h = gst_harness_new ("tsparse");
257   GstBuffer *buf;
258   gsize i;
259 
260   gst_harness_set (h, "tsparse", "alignment", 1, NULL);
261 
262   gst_harness_set_src_caps_str (h, "video/mpegts,systemstream=true");
263   gst_harness_set_sink_caps_str (h,
264       "video/mpegts,systemstream=true,packetsize=" G_STRINGIFY (PACKETSIZE));
265 
266   buf =
267       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, (guint8 *) aac_ts,
268       sizeof aac_ts, 0, sizeof aac_ts, NULL, NULL);
269   fail_unless (gst_harness_push (h, buf) == GST_FLOW_OK);
270 
271   gst_harness_push_event (h, gst_event_new_eos ());
272   fail_unless (gst_harness_buffers_in_queue (h) == aac_ts_packets,
273       "Expected %u buffers, got %u", aac_ts_packets,
274       gst_harness_buffers_in_queue (h));
275 
276   for (i = 0; i < sizeof aac_ts; i += PACKETSIZE) {
277     buf = gst_harness_pull (h);
278     gst_check_buffer_data (buf, aac_ts + i, PACKETSIZE);
279     gst_buffer_unref (buf);
280   }
281 
282   gst_harness_teardown (h);
283 }
284 
285 GST_END_TEST;
286 
GST_START_TEST(test_tsparse_padding)287 GST_START_TEST (test_tsparse_padding)
288 {
289   GstHarness *h = gst_harness_new ("tsparse");
290   GstBuffer *buf, *padding;
291 
292   gst_harness_set_src_caps_str (h, "video/mpegts,systemstream=true");
293   gst_harness_set_sink_caps_str (h,
294       "video/mpegts,systemstream=true,packetsize=" G_STRINGIFY (PACKETSIZE));
295 
296   buf =
297       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, (guint8 *) aac_ts,
298       sizeof aac_ts, 0, sizeof aac_ts, NULL, NULL);
299   padding =
300       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
301       (guint8 *) padding_ts, sizeof padding_ts, 0, sizeof padding_ts, NULL,
302       NULL);
303 
304   fail_unless (gst_harness_push (h, gst_buffer_ref (buf)) == GST_FLOW_OK);
305   fail_unless (gst_harness_push (h, gst_buffer_ref (padding)) == GST_FLOW_OK);
306   fail_unless (gst_harness_push (h, buf) == GST_FLOW_OK);
307   fail_unless (gst_harness_push (h, gst_buffer_ref (padding)) == GST_FLOW_OK);
308   fail_unless (gst_harness_push (h, padding) == GST_FLOW_OK);
309 
310   buf = gst_harness_pull (h);
311   gst_check_buffer_data (buf, aac_ts, sizeof aac_ts);
312   gst_buffer_unref (buf);
313 
314   padding = gst_harness_pull (h);
315   gst_check_buffer_data (padding, padding_ts, sizeof padding_ts);
316   gst_buffer_unref (padding);
317 
318   buf = gst_harness_pull (h);
319   gst_check_buffer_data (buf, aac_ts, sizeof aac_ts);
320   gst_buffer_unref (buf);
321 
322   padding = gst_harness_pull (h);
323   gst_check_buffer_data (padding, padding_ts, sizeof padding_ts);
324   gst_buffer_unref (padding);
325 
326   padding = gst_harness_pull (h);
327   gst_check_buffer_data (padding, padding_ts, sizeof padding_ts);
328   gst_buffer_unref (padding);
329 
330   gst_harness_push_event (h, gst_event_new_eos ());
331   fail_unless (gst_harness_buffers_in_queue (h) == 0);
332 
333   gst_harness_teardown (h);
334 }
335 
336 GST_END_TEST;
337 
338 static void
tsdemux_simple_pad_added(GstElement * tsdemux,GstPad * pad,GstHarness * h)339 tsdemux_simple_pad_added (GstElement * tsdemux, GstPad * pad, GstHarness * h)
340 {
341   fail_unless (g_strcmp0 (GST_PAD_NAME (pad), "audio_0_0041") == 0);
342   gst_harness_add_element_src_pad (h, pad);
343 }
344 
GST_START_TEST(test_tsdemux_simple)345 GST_START_TEST (test_tsdemux_simple)
346 {
347   GstHarness *h = gst_harness_new_with_padnames ("tsdemux", "sink", NULL);
348   GstBuffer *buf;
349   GstCaps *caps;
350   GstSegment segment;
351 
352   caps = gst_caps_from_string ("video/mpegts,systemstream=true");
353   gst_harness_push_event (h, gst_event_new_caps (caps));
354   gst_caps_unref (caps);
355 
356   gst_segment_init (&segment, GST_FORMAT_BYTES);
357   gst_harness_push_event (h, gst_event_new_segment (&segment));
358 
359   gst_harness_set_sink_caps_str (h,
360       "audio/mpeg,mpegversion=4,stream-format=adts");
361 
362   g_signal_connect (h->element, "pad-added",
363       G_CALLBACK (tsdemux_simple_pad_added), h);
364 
365   buf =
366       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, (guint8 *) aac_ts,
367       sizeof aac_ts, 0, sizeof aac_ts, NULL, NULL);
368   fail_unless (gst_harness_push (h, buf) == GST_FLOW_OK);
369   gst_harness_push_event (h, gst_event_new_eos ());
370 
371   buf = gst_harness_take_all_data_as_buffer (h);
372   gst_check_buffer_data (buf, aac_data, sizeof aac_data);
373   gst_buffer_unref (buf);
374 
375   gst_harness_teardown (h);
376 }
377 
378 GST_END_TEST;
379 
380 static Suite *
mpegtsdemux_suite(void)381 mpegtsdemux_suite (void)
382 {
383   Suite *s = suite_create ("mpegtsdemux");
384   TCase *tc;
385 
386   tc = tcase_create ("tsparse");
387   suite_add_tcase (s, tc);
388   tcase_add_test (tc, test_tsparse_simple);
389   tcase_skip_broken_test (tc, test_tsparse_align_auto);
390   tcase_add_test (tc, test_tsparse_align_fuse);
391   tcase_add_test (tc, test_tsparse_align_split);
392   tcase_add_test (tc, test_tsparse_padding);
393 
394   tc = tcase_create ("tsdemux");
395   suite_add_tcase (s, tc);
396   tcase_add_test (tc, test_tsdemux_simple);
397 
398   return s;
399 }
400 
401 GST_CHECK_MAIN (mpegtsdemux);
402