1 /*
2 * rtpristext.c
3 *
4 * Copyright (C) 2019 Net Insight AB
5 * Author: Olivier Crete <olivier.crete@collabora.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <gst/check/check.h>
22 #include <gst/rtp/rtp.h>
23
24 static const guint8 ts_packet[] = {
25 0x47, 0x40, 0x41, 0x12, 0x00, 0x00, 0x01, 0xe0, 0x0f, 0x96, 0x81, 0xc0,
26 0x0a, 0x31, 0x4d, 0x41, 0x0f, 0xbf, 0x11, 0x4d, 0x3f, 0x9a, 0x93, 0x00,
27 0x00, 0x00, 0x01, 0x09, 0x30, 0x00, 0x00, 0x01, 0x41, 0x9a, 0x24, 0x6c,
28 0x41, 0xaf, 0xfe, 0xda, 0xa6, 0x58, 0x00, 0x09, 0xcf, 0x64, 0x41, 0xf5,
29 0x7c, 0x67, 0x65, 0x1d, 0x00, 0x23, 0xd3, 0x7c, 0xf2, 0xd2, 0xf8, 0x2f,
30 0x30, 0x20, 0xfe, 0x2b, 0xad, 0x61, 0x0b, 0xd4, 0x47, 0x22, 0x82, 0x2a,
31 0x46, 0xe2, 0xc3, 0x4c, 0x6a, 0xb4, 0x1d, 0x07, 0xc9, 0x77, 0x6c, 0xc9,
32 0xc3, 0x6d, 0x37, 0x14, 0x86, 0x45, 0xb1, 0x0b, 0x44, 0xc4, 0xee, 0x03,
33 0x95, 0xd6, 0x7f, 0x09, 0x54, 0x51, 0xb9, 0xcb, 0xe4, 0xea, 0x6b, 0xc9,
34 0x2f, 0xfc, 0xa2, 0xb3, 0xef, 0x46, 0x86, 0xa0, 0xd9, 0x72, 0x93, 0x20,
35 0xee, 0x5d, 0x31, 0xe2, 0xa1, 0x59, 0x9a, 0xbd, 0x17, 0x25, 0x77, 0x72,
36 0x2d, 0xc4, 0xc4, 0x29, 0xf8, 0x6e, 0x36, 0x9c, 0xe8, 0x3f, 0x61, 0x3b,
37 0x83, 0xc8, 0xc1, 0x0c, 0x53, 0xc9, 0xe1, 0x6a, 0x99, 0xcb, 0x0f, 0xb4,
38 0x2f, 0x53, 0x30, 0x4a, 0xec, 0xec, 0x3d, 0xe4, 0x8f, 0x3c, 0xe3, 0xe4,
39 0xec, 0x13, 0x18, 0x87, 0xed, 0xc4, 0x3f, 0xee, 0x26, 0xcf, 0xd4, 0x5b,
40 0xfd, 0x1c, 0x32, 0x5f, 0xc5, 0xb9, 0xc0, 0x4b
41 };
42
43 static const guint8 null_ts_packet[] = {
44 0x47, 0x1f, 0xff, 0x10, 0x55, 0x33, 0x41, 0xd8, 0x99, 0x92, 0x09, 0xc5,
45 0xd9, 0x74, 0x2f, 0xaf, 0x61, 0xa6, 0xda, 0x36, 0x95, 0xac, 0x72, 0x82,
46 0xa7, 0xda, 0xb9, 0x57, 0x91, 0x66, 0x6e, 0x64, 0xec, 0x75, 0xa4, 0x51,
47 0x31, 0xac, 0x10, 0x4a, 0x33, 0xa6, 0xb9, 0x3f, 0x50, 0x7c, 0xb5, 0x81,
48 0x57, 0x9c, 0x00, 0x32, 0x61, 0x77, 0x70, 0x4e, 0xe6, 0x95, 0x9b, 0xe3,
49 0xe9, 0xd1, 0x9b, 0xa5, 0x81, 0xbc, 0x95, 0x03, 0x24, 0x7a, 0x60, 0x36,
50 0x0d, 0xbf, 0x0d, 0xfd, 0x56, 0x7f, 0xec, 0x73, 0x47, 0x88, 0x5c, 0x52,
51 0x77, 0x24, 0xdc, 0xcb, 0xba, 0x24, 0xc3, 0xbb, 0xa4, 0xa5, 0x2e, 0xd8,
52 0x5b, 0x85, 0x0f, 0x98, 0x1d, 0xb6, 0xe4, 0xb2, 0x5c, 0x14, 0x57, 0x54,
53 0xb2, 0xce, 0xe0, 0x76, 0x86, 0x0b, 0x90, 0xbf, 0x1b, 0x54, 0x98, 0x4f,
54 0xae, 0x77, 0x18, 0x3d, 0x81, 0x10, 0x3e, 0xe6, 0x73, 0xf1, 0xb9, 0xed,
55 0x5e, 0xde, 0x8b, 0xe0, 0x5f, 0x6b, 0xc7, 0xe8, 0x9b, 0xe6, 0x53, 0xf3,
56 0xa0, 0x85, 0x13, 0xcb, 0x46, 0x56, 0x07, 0xe7, 0xfa, 0xb5, 0x3d, 0x5f,
57 0xa4, 0x74, 0x4b, 0xf1, 0x84, 0xdb, 0x94, 0xb4, 0xd7, 0x25, 0x99, 0xa3,
58 0xbe, 0xcb, 0x11, 0x5d, 0xcb, 0x69, 0xe0, 0xb5, 0xd1, 0xda, 0x50, 0x24,
59 0xca, 0x96, 0x09, 0x23, 0xcb, 0x1f, 0xbe, 0x00
60 };
61
62 static GstBuffer *
alloc_ts_buffer(guint num_ts_packets)63 alloc_ts_buffer (guint num_ts_packets)
64 {
65 GstBuffer *buf;
66 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
67
68 buf = gst_rtp_buffer_new_allocate (188 * num_ts_packets, 0, 0);
69 gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
70 gst_rtp_buffer_set_version (&rtp, 2);
71 gst_rtp_buffer_set_ssrc (&rtp, 12);
72 gst_rtp_buffer_set_seq (&rtp, 44);
73 gst_rtp_buffer_set_timestamp (&rtp, 55);
74 gst_rtp_buffer_set_payload_type (&rtp, 33);
75 gst_rtp_buffer_unmap (&rtp);
76
77 return buf;
78 }
79
80 static void
validate_ts_buffer_full(GstRTPBuffer * rtp,guint num_ts_packets,guint16 seq,gboolean extension)81 validate_ts_buffer_full (GstRTPBuffer * rtp, guint num_ts_packets, guint16 seq,
82 gboolean extension)
83 {
84 fail_unless_equals_int (gst_rtp_buffer_get_payload_len (rtp),
85 188 * num_ts_packets);
86 fail_unless_equals_int (gst_rtp_buffer_get_ssrc (rtp), 12);
87 fail_unless_equals_int (gst_rtp_buffer_get_payload_type (rtp), 33);
88 fail_unless_equals_int (gst_rtp_buffer_get_seq (rtp), seq);
89 fail_unless_equals_int (gst_rtp_buffer_get_timestamp (rtp), 55);
90 fail_unless_equals_int (gst_rtp_buffer_get_extension (rtp), extension);
91 }
92
93 static void
validate_ts_buffer_seq(GstRTPBuffer * rtp,guint num_ts_packets,guint16 seq)94 validate_ts_buffer_seq (GstRTPBuffer * rtp, guint num_ts_packets, guint16 seq)
95 {
96 validate_ts_buffer_full (rtp, num_ts_packets, seq, TRUE);
97 }
98
99 static void
validate_ts_buffer(GstRTPBuffer * rtp,guint num_ts_packets)100 validate_ts_buffer (GstRTPBuffer * rtp, guint num_ts_packets)
101 {
102 validate_ts_buffer_full (rtp, num_ts_packets, 44, TRUE);
103 }
104
105 static void
validate_ts_buffer_noext(GstRTPBuffer * rtp,guint num_ts_packets)106 validate_ts_buffer_noext (GstRTPBuffer * rtp, guint num_ts_packets)
107 {
108 validate_ts_buffer_full (rtp, num_ts_packets, 44, FALSE);
109 }
110
111 static void
validate_ext(GstRTPBuffer * rtp,gboolean wanted_has_drop_null,gboolean wanted_has_seqnum_ext,guint wanted_orig_ts_packet_count,guint wanted_ts_packet_size,guint wanted_npd_bits,guint16 wanted_ext)112 validate_ext (GstRTPBuffer * rtp, gboolean wanted_has_drop_null,
113 gboolean wanted_has_seqnum_ext, guint wanted_orig_ts_packet_count,
114 guint wanted_ts_packet_size, guint wanted_npd_bits, guint16 wanted_ext)
115 {
116 guint extlen;
117 gpointer extdata;
118 guint16 bits;
119 gboolean has_seqnum_ext;
120 gboolean has_drop_null;
121 guint orig_ts_packet_count;
122 gboolean ts_packet_size;
123 guint8 *data;
124 guint8 npd_bits;
125
126 fail_unless (gst_rtp_buffer_get_extension_data (rtp, &bits, &extdata,
127 &extlen));
128
129 fail_unless_equals_int (bits, 'R' << 8 | 'I');
130 fail_unless (extlen == 1);
131
132 data = extdata;
133
134 has_drop_null = (data[0] >> 7) & 1; /* N */
135 has_seqnum_ext = (data[0] >> 6) & 1; /* E */
136 orig_ts_packet_count = (data[0] >> 3) & 7; /* Size */
137 ts_packet_size = ((data[1] >> 7) & 1) ? 204 : 188;
138 npd_bits = data[1] & 0x7F;
139
140 fail_unless_equals_int (has_drop_null, wanted_has_drop_null);
141 fail_unless_equals_int (has_seqnum_ext, wanted_has_seqnum_ext);
142 fail_unless_equals_int (orig_ts_packet_count, wanted_orig_ts_packet_count);
143 fail_unless_equals_int (ts_packet_size, wanted_ts_packet_size);
144 fail_unless_equals_int (npd_bits, wanted_npd_bits);
145
146 if (wanted_has_seqnum_ext) {
147 guint16 ext;
148
149 ext = GST_READ_UINT16_BE (data + 2);
150 fail_unless_equals_int (ext, wanted_ext);
151 }
152 }
153
154 /* Don't touch this */
GST_START_TEST(test_noop)155 GST_START_TEST (test_noop)
156 {
157 GstHarness *h = gst_harness_new ("ristrtpext");
158 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
159 GstBuffer *ibuf;
160 GstBuffer *obuf;
161 guint i;
162 guint8 *payload;
163
164 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
165 "clock-rate=90000, encoding-name=MP2T");
166
167 ibuf = alloc_ts_buffer (7);
168 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
169 payload = gst_rtp_buffer_get_payload (&rtp);
170 for (i = 0; i < 7; i++) {
171 memcpy (payload + (i * 188), ts_packet, 188);
172 payload[(i * 188) + 187] = i;
173 }
174 gst_rtp_buffer_unmap (&rtp);
175
176 obuf = gst_harness_push_and_pull (h, ibuf);
177
178 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
179 validate_ts_buffer_noext (&rtp, 7);
180 payload = gst_rtp_buffer_get_payload (&rtp);
181 for (i = 0; i < 7; i++) {
182 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
183 fail_unless_equals_int (payload[(i * 188) + 187], i);
184 }
185 gst_rtp_buffer_unmap (&rtp);
186 gst_buffer_unref (obuf);
187
188 gst_harness_teardown (h);
189 }
190
191 GST_END_TEST;
192
193 /* No null packets */
GST_START_TEST(test_remove_null_none)194 GST_START_TEST (test_remove_null_none)
195 {
196 GstHarness *h = gst_harness_new ("ristrtpext");
197 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
198 GstBuffer *ibuf;
199 GstBuffer *obuf;
200 guint i;
201 guint8 *payload;
202
203 g_object_set (h->element, "drop-null-ts-packets", TRUE, NULL);
204 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
205 "clock-rate=90000, encoding-name=MP2T");
206
207 ibuf = alloc_ts_buffer (7);
208 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
209 payload = gst_rtp_buffer_get_payload (&rtp);
210 for (i = 0; i < 7; i++) {
211 memcpy (payload + (i * 188), ts_packet, 188);
212 payload[(i * 188) + 187] = i;
213 }
214 gst_rtp_buffer_unmap (&rtp);
215
216 obuf = gst_harness_push_and_pull (h, ibuf);
217
218 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
219 validate_ts_buffer (&rtp, 7);
220 validate_ext (&rtp, TRUE, FALSE, 7, 188, 0, 0);
221 payload = gst_rtp_buffer_get_payload (&rtp);
222 for (i = 0; i < 7; i++) {
223 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
224 fail_unless_equals_int (payload[(i * 188) + 187], i);
225 }
226 gst_rtp_buffer_unmap (&rtp);
227 gst_buffer_unref (obuf);
228
229 gst_harness_teardown (h);
230 }
231
232 GST_END_TEST;
233
234 /* 1 null packet in middle */
GST_START_TEST(test_remove_null_middle)235 GST_START_TEST (test_remove_null_middle)
236 {
237 GstHarness *h = gst_harness_new ("ristrtpext");
238 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
239 GstBuffer *ibuf;
240 GstBuffer *obuf;
241 guint i;
242 guint8 *payload;
243
244 g_object_set (h->element, "drop-null-ts-packets", TRUE, NULL);
245 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
246 "clock-rate=90000, encoding-name=MP2T");
247
248 ibuf = alloc_ts_buffer (7);
249 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
250 payload = gst_rtp_buffer_get_payload (&rtp);
251 for (i = 0; i < 3; i++) {
252 memcpy (payload + (i * 188), ts_packet, 188);
253 payload[(i * 188) + 187] = i;
254 }
255 memcpy (payload + (3 * 188), null_ts_packet, 188);
256 for (i = 4; i < 7; i++) {
257 memcpy (payload + (i * 188), ts_packet, 188);
258 payload[(i * 188) + 187] = i;
259 }
260 gst_rtp_buffer_unmap (&rtp);
261
262 obuf = gst_harness_push_and_pull (h, ibuf);
263
264 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
265 validate_ts_buffer (&rtp, 6);
266 validate_ext (&rtp, TRUE, FALSE, 7, 188, 1 << 3, 0);
267 payload = gst_rtp_buffer_get_payload (&rtp);
268 for (i = 0; i < 6; i++) {
269 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
270 if (i < 3) {
271 fail_unless_equals_int (payload[(i * 188) + 187], i);
272 } else {
273 fail_unless_equals_int (payload[(i * 188) + 187], i + 1);
274 }
275 }
276
277 gst_rtp_buffer_unmap (&rtp);
278 gst_buffer_unref (obuf);
279
280 gst_harness_teardown (h);
281 }
282
283 GST_END_TEST;
284
285 /* one null packet at the start and one in the end */
GST_START_TEST(test_remove_null_start_and_end)286 GST_START_TEST (test_remove_null_start_and_end)
287 {
288 GstHarness *h = gst_harness_new ("ristrtpext");
289 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
290 GstBuffer *ibuf;
291 GstBuffer *obuf;
292 guint i;
293 guint8 *payload;
294
295 g_object_set (h->element, "drop-null-ts-packets", TRUE, NULL);
296 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
297 "clock-rate=90000, encoding-name=MP2T");
298
299 ibuf = alloc_ts_buffer (7);
300 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
301 payload = gst_rtp_buffer_get_payload (&rtp);
302 memcpy (payload + (0 * 188), null_ts_packet, 188);
303 for (i = 1; i < 6; i++) {
304 memcpy (payload + (i * 188), ts_packet, 188);
305 payload[(i * 188) + 187] = i;
306 }
307 memcpy (payload + (6 * 188), null_ts_packet, 188);
308 gst_rtp_buffer_unmap (&rtp);
309
310 obuf = gst_harness_push_and_pull (h, ibuf);
311
312 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
313 validate_ts_buffer (&rtp, 5);
314 validate_ext (&rtp, TRUE, FALSE, 7, 188, 1 << 6 | 1, 0);
315 payload = gst_rtp_buffer_get_payload (&rtp);
316 for (i = 0; i < 5; i++) {
317 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
318 fail_unless_equals_int (payload[(i * 188) + 187], i + 1);
319 }
320 gst_rtp_buffer_unmap (&rtp);
321 gst_buffer_unref (obuf);
322
323 gst_harness_teardown (h);
324 }
325
326 GST_END_TEST;
327
328
329 /* All null packets */
GST_START_TEST(test_remove_null_all)330 GST_START_TEST (test_remove_null_all)
331 {
332 GstHarness *h = gst_harness_new ("ristrtpext");
333 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
334 GstBuffer *ibuf;
335 GstBuffer *obuf;
336 guint i;
337 guint8 *payload;
338
339 g_object_set (h->element, "drop-null-ts-packets", TRUE, NULL);
340 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
341 "clock-rate=90000, encoding-name=MP2T");
342
343 ibuf = alloc_ts_buffer (7);
344 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
345 payload = gst_rtp_buffer_get_payload (&rtp);
346 for (i = 0; i < 7; i++) {
347 memcpy (payload + (i * 188), null_ts_packet, 188);
348 payload[(i * 188) + 187] = i;
349 }
350 gst_rtp_buffer_unmap (&rtp);
351
352 obuf = gst_harness_push_and_pull (h, ibuf);
353
354 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
355 validate_ts_buffer (&rtp, 0);
356 validate_ext (&rtp, TRUE, FALSE, 7, 188, 0x7F, 0);
357 gst_rtp_buffer_unmap (&rtp);
358 gst_buffer_unref (obuf);
359
360 gst_harness_teardown (h);
361 }
362
363 GST_END_TEST;
364
GST_START_TEST(test_remove_null_not_ts)365 GST_START_TEST (test_remove_null_not_ts)
366 {
367 GstHarness *h = gst_harness_new ("ristrtpext");
368 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
369 GstBuffer *ibuf;
370 GstBuffer *obuf;
371
372 g_object_set (h->element, "drop-null-ts-packets", TRUE, NULL);
373 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
374 "clock-rate=90000, encoding-name=MP2T");
375
376 ibuf = alloc_ts_buffer (7);
377 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
378 gst_rtp_buffer_set_payload_type (&rtp, 96);
379 gst_rtp_buffer_unmap (&rtp);
380
381 obuf = gst_harness_push_and_pull (h, ibuf);
382
383 fail_unless (obuf == ibuf);
384 gst_buffer_unref (obuf);
385
386 gst_harness_teardown (h);
387 }
388
389 GST_END_TEST;
390
391
392 /* Eight null packets */
GST_START_TEST(test_remove_null_all_8_packets)393 GST_START_TEST (test_remove_null_all_8_packets)
394 {
395 GstHarness *h = gst_harness_new ("ristrtpext");
396 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
397 GstBuffer *ibuf;
398 GstBuffer *obuf;
399 guint i;
400 guint8 *payload;
401
402 g_object_set (h->element, "drop-null-ts-packets", TRUE, NULL);
403 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
404 "clock-rate=90000, encoding-name=MP2T");
405
406 ibuf = alloc_ts_buffer (8);
407 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
408 payload = gst_rtp_buffer_get_payload (&rtp);
409 for (i = 0; i < 8; i++) {
410 memcpy (payload + (i * 188), null_ts_packet, 188);
411 payload[(i * 188) + 187] = i;
412 }
413 gst_rtp_buffer_unmap (&rtp);
414
415 obuf = gst_harness_push_and_pull (h, ibuf);
416
417 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
418 validate_ts_buffer (&rtp, 1);
419 validate_ext (&rtp, TRUE, FALSE, 0, 188, 0x7F, 0);
420 gst_rtp_buffer_unmap (&rtp);
421 gst_buffer_unref (obuf);
422
423 gst_harness_teardown (h);
424 }
425
426 GST_END_TEST;
427
428 /* 204 bytes null packets */
GST_START_TEST(test_remove_null_all_204bytes)429 GST_START_TEST (test_remove_null_all_204bytes)
430 {
431 GstHarness *h = gst_harness_new ("ristrtpext");
432 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
433 GstBuffer *ibuf;
434 GstBuffer *obuf;
435 guint i;
436 guint8 *payload;
437
438 g_object_set (h->element, "drop-null-ts-packets", TRUE, NULL);
439 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
440 "clock-rate=90000, encoding-name=MP2T");
441
442 ibuf = alloc_ts_buffer (7);
443 gst_buffer_append_memory (ibuf, gst_allocator_alloc (NULL, (204 - 188) * 7,
444 NULL));
445 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
446 payload = gst_rtp_buffer_get_payload (&rtp);
447 for (i = 0; i < 7; i++) {
448 memcpy (payload + (i * 204), null_ts_packet, 188);
449 payload[(i * 204) + 187] = i;
450 }
451 gst_rtp_buffer_unmap (&rtp);
452
453 obuf = gst_harness_push_and_pull (h, ibuf);
454
455 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
456 validate_ts_buffer (&rtp, 0);
457 validate_ext (&rtp, TRUE, FALSE, 7, 204, 0x7F, 0);
458 gst_rtp_buffer_unmap (&rtp);
459 gst_buffer_unref (obuf);
460
461 gst_harness_teardown (h);
462 }
463
464 GST_END_TEST;
465
466 /* 2 null packet out of 3 */
GST_START_TEST(test_remove_null_two_of_three)467 GST_START_TEST (test_remove_null_two_of_three)
468 {
469 GstHarness *h = gst_harness_new ("ristrtpext");
470 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
471 GstBuffer *ibuf;
472 GstBuffer *obuf;
473 guint8 *payload;
474
475 g_object_set (h->element, "drop-null-ts-packets", TRUE, NULL);
476 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
477 "clock-rate=90000, encoding-name=MP2T");
478
479 ibuf = alloc_ts_buffer (3);
480 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
481 payload = gst_rtp_buffer_get_payload (&rtp);
482 memcpy (payload + (0 * 188), null_ts_packet, 188);
483 memcpy (payload + (1 * 188), ts_packet, 188);
484 payload[188 + 187] = 33;
485 memcpy (payload + (2 * 188), null_ts_packet, 188);
486
487 gst_rtp_buffer_unmap (&rtp);
488
489 obuf = gst_harness_push_and_pull (h, ibuf);
490
491 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
492 validate_ts_buffer (&rtp, 1);
493 validate_ext (&rtp, TRUE, FALSE, 3, 188, 1 << 6 | 1 << 4, 0);
494 payload = gst_rtp_buffer_get_payload (&rtp);
495 fail_unless_equals_int (memcmp (payload, ts_packet, 187), 0);
496 fail_unless_equals_int (payload[187], 33);
497
498 gst_rtp_buffer_unmap (&rtp);
499 gst_buffer_unref (obuf);
500
501 gst_harness_teardown (h);
502 }
503
504 GST_END_TEST;
505
506 static void
push_one_seqnum(GstHarness * h,guint16 seqnum,guint16 wanted_ext)507 push_one_seqnum (GstHarness * h, guint16 seqnum, guint16 wanted_ext)
508 {
509 GstBuffer *ibuf;
510 GstBuffer *obuf;
511 static const int NUM_PACKETS = 5;
512 guint i;
513 guint8 *payload;
514 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
515
516 ibuf = alloc_ts_buffer (NUM_PACKETS);
517 gst_rtp_buffer_map (ibuf, GST_MAP_READWRITE, &rtp);
518 gst_rtp_buffer_set_seq (&rtp, seqnum);
519 payload = gst_rtp_buffer_get_payload (&rtp);
520 for (i = 0; i < NUM_PACKETS; i++) {
521 memcpy (payload + (i * 188), ts_packet, 188);
522 payload[(i * 188) + 187] = i;
523 }
524
525 gst_rtp_buffer_unmap (&rtp);
526
527 obuf = gst_harness_push_and_pull (h, ibuf);
528
529 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
530 validate_ts_buffer_seq (&rtp, NUM_PACKETS, seqnum);
531 validate_ext (&rtp, FALSE, TRUE, 0, 188, 0, wanted_ext);
532 payload = gst_rtp_buffer_get_payload (&rtp);
533 for (i = 0; i < NUM_PACKETS; i++) {
534 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
535 fail_unless_equals_int (payload[(i * 188) + 187], i);
536 }
537 gst_rtp_buffer_unmap (&rtp);
538 gst_buffer_unref (obuf);
539 }
540
GST_START_TEST(test_add_seqnum_ext)541 GST_START_TEST (test_add_seqnum_ext)
542 {
543 GstHarness *h = gst_harness_new ("ristrtpext");
544
545 g_object_set (h->element, "sequence-number-extension", TRUE, NULL);
546 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
547 "clock-rate=90000, encoding-name=MP2T");
548
549 push_one_seqnum (h, 44, 0);
550
551 gst_harness_teardown (h);
552 }
553
554 GST_END_TEST;
555
GST_START_TEST(test_add_seqnum_ext_roll_over)556 GST_START_TEST (test_add_seqnum_ext_roll_over)
557 {
558 GstHarness *h = gst_harness_new ("ristrtpext");
559
560 g_object_set (h->element, "sequence-number-extension", TRUE, NULL);
561 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
562 "clock-rate=90000, encoding-name=MP2T");
563
564 /* push one */
565 push_one_seqnum (h, 0xA123, 0);
566
567 /* Now roll over */
568 push_one_seqnum (h, 0x0123, 1);
569
570 gst_harness_teardown (h);
571 }
572
573 GST_END_TEST;
574
GST_START_TEST(test_add_seqnum_ext_roll_back)575 GST_START_TEST (test_add_seqnum_ext_roll_back)
576 {
577 GstHarness *h = gst_harness_new ("ristrtpext");
578
579 g_object_set (h->element, "sequence-number-extension", TRUE, NULL);
580 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
581 "clock-rate=90000, encoding-name=MP2T");
582
583 /* Send one packet */
584 push_one_seqnum (h, 0xA123, 0);
585
586 /* Now roll over */
587 push_one_seqnum (h, 0x0123, 1);
588
589 /* Now roll back */
590 push_one_seqnum (h, 0xF123, 0);
591
592 gst_harness_teardown (h);
593 }
594
595 GST_END_TEST;
596
GST_START_TEST(test_add_seqnum_ext_roll_over_twice)597 GST_START_TEST (test_add_seqnum_ext_roll_over_twice)
598 {
599 GstHarness *h = gst_harness_new ("ristrtpext");
600
601 g_object_set (h->element, "sequence-number-extension", TRUE, NULL);
602 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
603 "clock-rate=90000, encoding-name=MP2T");
604
605 /* Send one packet */
606 push_one_seqnum (h, 0xF123, 0);
607
608 /* Now roll over */
609 push_one_seqnum (h, 0x2123, 1);
610
611 /* Now go foward */
612 push_one_seqnum (h, 0x9123, 1);
613
614 /* Now roll back */
615 push_one_seqnum (h, 0x0123, 2);
616
617 gst_harness_teardown (h);
618 }
619
620 GST_END_TEST;
621
622
623 static GstBuffer *
alloc_ts_buffer_with_ext(guint num_ts_packets,gboolean has_drop_null,gboolean has_seqnum_ext,guint orig_ts_packet_count,guint ts_packet_size,guint npd_bits,guint16 extseq)624 alloc_ts_buffer_with_ext (guint num_ts_packets, gboolean has_drop_null,
625 gboolean has_seqnum_ext, guint orig_ts_packet_count,
626 guint ts_packet_size, guint npd_bits, guint16 extseq)
627 {
628 GstBuffer *buf = alloc_ts_buffer (num_ts_packets);
629 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
630 guint8 *payload;
631 guint8 *data;
632 guint i;
633
634 gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
635 gst_rtp_buffer_set_extension_data (&rtp, 'R' << 8 | 'I', 1);
636 gst_rtp_buffer_get_extension_data (&rtp, NULL, (void **) &data, NULL);
637
638 data[0] = has_drop_null << 7; /* N */
639 data[0] |= has_seqnum_ext << 6; /* E */
640 data[0] |= (MIN (orig_ts_packet_count, 7) & 7) << 2; /* Size */
641 data[1] = (ts_packet_size == 204) << 7; /* T */
642 data[1] |= (npd_bits & 0x7F);
643
644 if (has_seqnum_ext && extseq != 0xFFFF)
645 GST_WRITE_UINT16_BE (data + 2, extseq);
646 else
647 GST_WRITE_UINT16_BE (data + 2, 0);
648
649
650 payload = gst_rtp_buffer_get_payload (&rtp);
651 for (i = 0; i < num_ts_packets; i++) {
652 memcpy (payload + (i * 188), ts_packet, 188);
653 payload[(i * 188) + 187] = i;
654 }
655
656 gst_rtp_buffer_unmap (&rtp);
657
658 return buf;
659 }
660
GST_START_TEST(test_deext_noop)661 GST_START_TEST (test_deext_noop)
662 {
663 GstHarness *h = gst_harness_new ("ristrtpdeext");
664 GstBuffer *ibuf, *obuf;
665 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
666
667 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
668 "clock-rate=90000, encoding-name=MP2T");
669
670 ibuf = alloc_ts_buffer_with_ext (7, FALSE, FALSE, 7, 188, 0, 0);
671
672 obuf = gst_harness_push_and_pull (h, ibuf);
673
674 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
675 validate_ts_buffer_noext (&rtp, 7);
676 gst_rtp_buffer_unmap (&rtp);
677
678 gst_buffer_unref (obuf);
679
680 gst_harness_teardown (h);
681 }
682
683 GST_END_TEST;
684
GST_START_TEST(test_deext_restore_middle)685 GST_START_TEST (test_deext_restore_middle)
686 {
687 GstHarness *h = gst_harness_new ("ristrtpdeext");
688 GstBuffer *ibuf, *obuf;
689 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
690 guint8 *payload;
691 guint i;
692
693 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
694 "clock-rate=90000, encoding-name=MP2T");
695
696 ibuf = alloc_ts_buffer_with_ext (6, TRUE, FALSE, 7, 188, 1 << 3, 0);
697
698 obuf = gst_harness_push_and_pull (h, ibuf);
699
700 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
701 validate_ts_buffer_noext (&rtp, 7);
702 payload = gst_rtp_buffer_get_payload (&rtp);
703 for (i = 0; i < 7; i++) {
704 if (i < 3) {
705 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
706 fail_unless_equals_int (payload[(i * 188) + 187], i);
707 } else if (i > 3) {
708 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
709 fail_unless_equals_int (payload[(i * 188) + 187], i - 1);
710 } else {
711 fail_unless_equals_int (memcmp (payload + (188 * i), null_ts_packet, 4),
712 0);
713 }
714 }
715 gst_rtp_buffer_unmap (&rtp);
716 gst_buffer_unref (obuf);
717
718 gst_harness_teardown (h);
719 }
720
721 GST_END_TEST;
722
723
GST_START_TEST(test_deext_restore_start_and_end)724 GST_START_TEST (test_deext_restore_start_and_end)
725 {
726 GstHarness *h = gst_harness_new ("ristrtpdeext");
727 GstBuffer *ibuf, *obuf;
728 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
729 guint8 *payload;
730 guint i;
731
732 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
733 "clock-rate=90000, encoding-name=MP2T");
734
735 ibuf = alloc_ts_buffer_with_ext (5, TRUE, FALSE, 7, 188, 1 << 6 | 1, 0);
736
737 obuf = gst_harness_push_and_pull (h, ibuf);
738
739 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
740 validate_ts_buffer_noext (&rtp, 7);
741 payload = gst_rtp_buffer_get_payload (&rtp);
742 fail_unless_equals_int (memcmp (payload, null_ts_packet, 4), 0);
743 for (i = 1; i < 6; i++) {
744 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
745 fail_unless_equals_int (payload[(i * 188) + 187], i - 1);
746 }
747 fail_unless_equals_int (memcmp (payload + (188 * 6), null_ts_packet, 4), 0);
748 gst_rtp_buffer_unmap (&rtp);
749 gst_buffer_unref (obuf);
750
751 gst_harness_teardown (h);
752 }
753
754 GST_END_TEST;
755
GST_START_TEST(test_deext_restore_middle_no_origcnt)756 GST_START_TEST (test_deext_restore_middle_no_origcnt)
757 {
758 GstHarness *h = gst_harness_new ("ristrtpdeext");
759 GstBuffer *ibuf, *obuf;
760 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
761 guint8 *payload;
762 guint i;
763
764 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
765 "clock-rate=90000, encoding-name=MP2T");
766
767 ibuf = alloc_ts_buffer_with_ext (6, TRUE, FALSE, 0, 188, 1 << 3, 0);
768
769 obuf = gst_harness_push_and_pull (h, ibuf);
770
771 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
772 validate_ts_buffer_noext (&rtp, 7);
773 payload = gst_rtp_buffer_get_payload (&rtp);
774 for (i = 0; i < 7; i++) {
775 if (i < 3) {
776 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
777 fail_unless_equals_int (payload[(i * 188) + 187], i);
778 } else if (i > 3) {
779 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
780 fail_unless_equals_int (payload[(i * 188) + 187], i - 1);
781 } else {
782 fail_unless_equals_int (memcmp (payload + (188 * i), null_ts_packet, 4),
783 0);
784 }
785 }
786 gst_rtp_buffer_unmap (&rtp);
787 gst_buffer_unref (obuf);
788
789 gst_harness_teardown (h);
790 }
791
792 GST_END_TEST;
793
GST_START_TEST(test_deext_restore_all)794 GST_START_TEST (test_deext_restore_all)
795 {
796 GstHarness *h = gst_harness_new ("ristrtpdeext");
797 GstBuffer *ibuf, *obuf;
798 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
799 guint8 *payload;
800 guint i;
801
802 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
803 "clock-rate=90000, encoding-name=MP2T");
804
805 ibuf = alloc_ts_buffer_with_ext (0, TRUE, FALSE, 7, 188, 0x7F, 0);
806
807 obuf = gst_harness_push_and_pull (h, ibuf);
808
809 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
810 validate_ts_buffer_noext (&rtp, 7);
811 payload = gst_rtp_buffer_get_payload (&rtp);
812 for (i = 0; i < 7; i++)
813 fail_unless_equals_int (memcmp (payload + (188 * i), null_ts_packet, 4), 0);
814 gst_rtp_buffer_unmap (&rtp);
815 gst_buffer_unref (obuf);
816
817 gst_harness_teardown (h);
818 }
819
820 GST_END_TEST;
821
GST_START_TEST(test_deext_restore_all_8)822 GST_START_TEST (test_deext_restore_all_8)
823 {
824 GstHarness *h = gst_harness_new ("ristrtpdeext");
825 GstBuffer *ibuf, *obuf;
826 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
827 guint8 *payload;
828 guint i;
829
830 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
831 "clock-rate=90000, encoding-name=MP2T");
832
833 ibuf = alloc_ts_buffer_with_ext (1, TRUE, FALSE, 0, 188, 0x7F, 0);
834
835 obuf = gst_harness_push_and_pull (h, ibuf);
836
837 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
838 validate_ts_buffer_noext (&rtp, 8);
839 payload = gst_rtp_buffer_get_payload (&rtp);
840 for (i = 0; i < 7; i++)
841 fail_unless_equals_int (memcmp (payload + (188 * i), null_ts_packet, 4), 0);
842 fail_unless_equals_int (memcmp (payload + (188 * i), ts_packet, 187), 0);
843 gst_rtp_buffer_unmap (&rtp);
844 gst_buffer_unref (obuf);
845
846 gst_harness_teardown (h);
847 }
848
849 GST_END_TEST;
850
GST_START_TEST(test_deext_restore_all_204bytes)851 GST_START_TEST (test_deext_restore_all_204bytes)
852 {
853 GstHarness *h = gst_harness_new ("ristrtpdeext");
854 GstBuffer *ibuf, *obuf;
855 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
856 guint8 *payload;
857 guint i;
858
859 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
860 "clock-rate=90000, encoding-name=MP2T");
861
862 ibuf = alloc_ts_buffer_with_ext (0, TRUE, FALSE, 7, 204, 0x7F, 0);
863
864 obuf = gst_harness_push_and_pull (h, ibuf);
865
866 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
867
868 fail_unless_equals_int (gst_rtp_buffer_get_payload_len (&rtp), 204 * 7);
869 fail_unless_equals_int (gst_rtp_buffer_get_ssrc (&rtp), 12);
870 fail_unless_equals_int (gst_rtp_buffer_get_payload_type (&rtp), 33);
871 fail_unless_equals_int (gst_rtp_buffer_get_seq (&rtp), 44);
872 fail_unless_equals_int (gst_rtp_buffer_get_timestamp (&rtp), 55);
873 fail_unless_equals_int (gst_rtp_buffer_get_extension (&rtp), FALSE);
874
875 payload = gst_rtp_buffer_get_payload (&rtp);
876 for (i = 0; i < 7; i++)
877 fail_unless_equals_int (memcmp (payload + (204 * i), null_ts_packet, 4), 0);
878 gst_rtp_buffer_unmap (&rtp);
879 gst_buffer_unref (obuf);
880
881 gst_harness_teardown (h);
882 }
883
884 GST_END_TEST;
885
886
GST_START_TEST(test_deext_restore_empty)887 GST_START_TEST (test_deext_restore_empty)
888 {
889 GstHarness *h = gst_harness_new ("ristrtpdeext");
890 GstBuffer *ibuf, *obuf;
891 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
892
893 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
894 "clock-rate=90000, encoding-name=MP2T");
895
896 ibuf = alloc_ts_buffer_with_ext (0, TRUE, FALSE, 0, 188, 0, 0);
897
898 obuf = gst_harness_push_and_pull (h, ibuf);
899
900 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
901 validate_ts_buffer_noext (&rtp, 0);
902 gst_rtp_buffer_unmap (&rtp);
903 gst_buffer_unref (obuf);
904
905 gst_harness_teardown (h);
906 }
907
908 GST_END_TEST;
909
910
GST_START_TEST(test_deext_restore_invalid_origcnt)911 GST_START_TEST (test_deext_restore_invalid_origcnt)
912 {
913 GstHarness *h = gst_harness_new ("ristrtpdeext");
914 GstBuffer *ibuf, *obuf;
915 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
916 guint8 *payload;
917
918 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
919 "clock-rate=90000, encoding-name=MP2T");
920
921 ibuf = alloc_ts_buffer_with_ext (2, TRUE, FALSE, 5, 188, 1 << 6 | 1 << 4, 0);
922
923 obuf = gst_harness_push_and_pull (h, ibuf);
924
925 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
926 validate_ts_buffer_noext (&rtp, 4);
927 payload = gst_rtp_buffer_get_payload (&rtp);
928
929 fail_unless_equals_int (memcmp (payload + (188 * 0), null_ts_packet, 4), 0);
930
931 fail_unless_equals_int (memcmp (payload + (188 * 1), ts_packet, 187), 0);
932 fail_unless_equals_int (payload[(188 * 1) + 187], 0);
933
934 fail_unless_equals_int (memcmp (payload + (188 * 2), null_ts_packet, 4), 0);
935
936 fail_unless_equals_int (memcmp (payload + (188 * 3), ts_packet, 187), 0);
937 fail_unless_equals_int (payload[(188 * 3) + 187], 1);
938
939 gst_rtp_buffer_unmap (&rtp);
940 gst_buffer_unref (obuf);
941
942 gst_harness_teardown (h);
943 }
944
945 GST_END_TEST;
946
947
GST_START_TEST(test_deext_noop_invalid_size)948 GST_START_TEST (test_deext_noop_invalid_size)
949 {
950 GstHarness *h = gst_harness_new ("ristrtpdeext");
951 GstBuffer *ibuf, *obuf;
952 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
953
954 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
955 "clock-rate=90000, encoding-name=MP2T");
956
957 ibuf = alloc_ts_buffer_with_ext (7, FALSE, FALSE, 7, 188, 0, 0);
958
959 gst_buffer_append_memory (ibuf, gst_allocator_alloc (NULL, 5, NULL));
960
961 obuf = gst_harness_push_and_pull (h, ibuf);
962
963 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
964
965 fail_unless_equals_int (gst_rtp_buffer_get_payload_len (&rtp), 188 * 7 + 5);
966 fail_unless_equals_int (gst_rtp_buffer_get_ssrc (&rtp), 12);
967 fail_unless_equals_int (gst_rtp_buffer_get_payload_type (&rtp), 33);
968 fail_unless_equals_int (gst_rtp_buffer_get_seq (&rtp), 44);
969 fail_unless_equals_int (gst_rtp_buffer_get_timestamp (&rtp), 55);
970 fail_unless_equals_int (gst_rtp_buffer_get_extension (&rtp), FALSE);
971
972 gst_rtp_buffer_unmap (&rtp);
973
974 gst_buffer_unref (obuf);
975
976 gst_harness_teardown (h);
977 }
978
979 GST_END_TEST;
980
GST_START_TEST(test_deext_seq_base)981 GST_START_TEST (test_deext_seq_base)
982 {
983 GstHarness *h = gst_harness_new ("ristrtpdeext");
984 GstBuffer *ibuf, *obuf;
985 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
986 guint max_seqnum;
987
988 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
989 "clock-rate=90000, encoding-name=MP2T");
990
991 ibuf = alloc_ts_buffer_with_ext (7, FALSE, TRUE, 7, 188, 0, 0);
992 obuf = gst_harness_push_and_pull (h, ibuf);
993 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
994 validate_ts_buffer_noext (&rtp, 7);
995 gst_rtp_buffer_unmap (&rtp);
996 gst_buffer_unref (obuf);
997
998 g_object_get (h->element, "max-ext-seqnum", &max_seqnum, NULL);
999 fail_unless_equals_int (max_seqnum, 44);
1000
1001 ibuf = alloc_ts_buffer_with_ext (7, FALSE, TRUE, 7, 188, 0, 1);
1002 obuf = gst_harness_push_and_pull (h, ibuf);
1003 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
1004 validate_ts_buffer_noext (&rtp, 7);
1005 gst_rtp_buffer_unmap (&rtp);
1006 gst_buffer_unref (obuf);
1007
1008 g_object_get (h->element, "max-ext-seqnum", &max_seqnum, NULL);
1009 fail_unless_equals_int (max_seqnum, 65536 + 44);
1010
1011 gst_harness_teardown (h);
1012 }
1013
1014 GST_END_TEST;
1015
GST_START_TEST(test_deext_seq_drop)1016 GST_START_TEST (test_deext_seq_drop)
1017 {
1018 GstHarness *h = gst_harness_new ("ristrtpdeext");
1019 GstBuffer *ibuf, *obuf;
1020 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
1021 guint max_seqnum;
1022
1023 gst_harness_set_src_caps_str (h, "application/x-rtp, payload=33,"
1024 "clock-rate=90000, encoding-name=MP2T");
1025
1026 ibuf = alloc_ts_buffer_with_ext (7, FALSE, TRUE, 7, 188, 0, 0);
1027 obuf = gst_harness_push_and_pull (h, ibuf);
1028 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
1029 validate_ts_buffer_noext (&rtp, 7);
1030 gst_rtp_buffer_unmap (&rtp);
1031 gst_buffer_unref (obuf);
1032
1033 g_object_get (h->element, "max-ext-seqnum", &max_seqnum, NULL);
1034 fail_unless_equals_int (max_seqnum, 44);
1035
1036
1037 ibuf = alloc_ts_buffer_with_ext (7, FALSE, TRUE, 7, 188, 0, 2);
1038 obuf = gst_harness_push_and_pull (h, ibuf);
1039 gst_rtp_buffer_map (obuf, GST_MAP_READ, &rtp);
1040 validate_ts_buffer_noext (&rtp, 7);
1041 gst_rtp_buffer_unmap (&rtp);
1042 gst_buffer_unref (obuf);
1043
1044 g_object_get (h->element, "max-ext-seqnum", &max_seqnum, NULL);
1045 fail_unless_equals_int (max_seqnum, 65536 + 65536 + 44);
1046
1047 ibuf = alloc_ts_buffer_with_ext (7, FALSE, TRUE, 7, 188, 0, 0);
1048 fail_unless_equals_int (gst_harness_push (h, ibuf), GST_FLOW_OK);
1049 fail_unless_equals_int (gst_harness_buffers_in_queue (h), 0);
1050
1051 g_object_get (h->element, "max-ext-seqnum", &max_seqnum, NULL);
1052 fail_unless_equals_int (max_seqnum, 65536 + 65536 + 44);
1053
1054 gst_harness_teardown (h);
1055 }
1056
1057 GST_END_TEST;
1058
1059 static Suite *
ristrtpext_suite(void)1060 ristrtpext_suite (void)
1061 {
1062 Suite *s = suite_create ("ristrtpext");
1063 TCase *tc;
1064
1065 tc = tcase_create ("ext");
1066 suite_add_tcase (s, tc);
1067
1068 tcase_add_test (tc, test_noop);
1069 tcase_add_test (tc, test_remove_null_none);
1070 tcase_add_test (tc, test_remove_null_middle);
1071 tcase_add_test (tc, test_remove_null_start_and_end);
1072 tcase_add_test (tc, test_remove_null_all);
1073 tcase_add_test (tc, test_remove_null_not_ts);
1074 tcase_add_test (tc, test_remove_null_all_8_packets);
1075 tcase_add_test (tc, test_remove_null_all_204bytes);
1076 tcase_add_test (tc, test_remove_null_two_of_three);
1077
1078 tcase_add_test (tc, test_add_seqnum_ext);
1079 tcase_add_test (tc, test_add_seqnum_ext_roll_over);
1080 tcase_add_test (tc, test_add_seqnum_ext_roll_back);
1081 tcase_add_test (tc, test_add_seqnum_ext_roll_over_twice);
1082
1083 tc = tcase_create ("deext");
1084 suite_add_tcase (s, tc);
1085
1086 tcase_add_test (tc, test_deext_noop);
1087 tcase_add_test (tc, test_deext_restore_middle);
1088 tcase_add_test (tc, test_deext_restore_start_and_end);
1089 tcase_add_test (tc, test_deext_restore_middle_no_origcnt);
1090 tcase_add_test (tc, test_deext_restore_all);
1091 tcase_add_test (tc, test_deext_restore_all_8);
1092 tcase_add_test (tc, test_deext_restore_all_204bytes);
1093 tcase_add_test (tc, test_deext_restore_empty);
1094 tcase_add_test (tc, test_deext_restore_invalid_origcnt);
1095 tcase_add_test (tc, test_deext_noop_invalid_size);
1096
1097 tcase_add_test (tc, test_deext_seq_base);
1098 tcase_add_test (tc, test_deext_seq_drop);
1099
1100 return s;
1101 }
1102
1103 GST_CHECK_MAIN (ristrtpext);
1104