• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Gstreamer
2  * Copyright (C) <2014> Jesper Larsen <knorr.jesper@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include <gst/check/gstcheck.h>
24 #include <gst/mpegts/mpegts.h>
25 
26 static const guint8 pat_data_check[] = {
27   0x00, 0xB0, 0x11, 0x00, 0x00, 0xc1, 0x00,
28   0x00, 0x00, 0x00, 0xe0, 0x30, 0x00, 0x01,
29   0xe0, 0x31, 0x98, 0xdf, 0x37, 0xc4
30 };
31 
32 static const guint8 pmt_data_check[] = {
33   0x02, 0xb0, 0x29, 0x00, 0x01, 0xc1, 0x00,
34   0x00, 0xff, 0xff, 0xf0, 0x06, 0x05, 0x04,
35   0x48, 0x44, 0x4d, 0x56, 0x1b, 0xe0, 0x40,
36   0xF0, 0x06, 0x05, 0x04, 0x48, 0x44, 0x4d,
37   0x56, 0x1b, 0xe0, 0x41, 0xF0, 0x06, 0x05,
38   0x04, 0x48, 0x44, 0x4d, 0x56, 0x15, 0x41,
39   0x5f, 0x5b
40 };
41 
42 static const guint8 nit_data_check[] = {
43   0x40, 0xf0, 0x49, 0x1f, 0xff, 0xc1, 0x00,
44   0x00, 0xf0, 0x0e, 0x40, 0x0c, 0x4e, 0x65,
45   0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x6e,
46   0x61, 0x6d, 0x65, 0xf0, 0x2e, 0x1f, 0xff,
47   0x1f, 0xfe, 0xf0, 0x11, 0x40, 0x0f, 0x41,
48   0x6e, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20,
49   0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b,
50   0x1f, 0xff, 0x1f, 0xfe, 0xf0, 0x11, 0x40,
51   0x0f, 0x41, 0x6e, 0x6f, 0x74, 0x68, 0x65,
52   0x72, 0x20, 0x6e, 0x65, 0x74, 0x77, 0x6f,
53   0x72, 0x6b, 0xce, 0x03, 0xf5, 0x94
54 };
55 
56 static const guint8 sdt_data_check[] = {
57   0x42, 0xf0, 0x38, 0x1f, 0xff, 0xc1, 0x00,
58   0x00, 0x1f, 0xff, 0xff, 0x00, 0x00, 0xFF,
59   0x90, 0x11, 0x48, 0x0f, 0x01, 0x08, 0x50,
60   0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72,
61   0x04, 0x4e, 0x61, 0x6d, 0x65, 0x00, 0x01,
62   0xFF, 0xB0, 0x11, 0x48, 0x0f, 0x01, 0x08,
63   0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65,
64   0x72, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x25,
65   0xe5, 0x02, 0xd9
66 };
67 
68 static const guint8 stt_data_check[] = {
69   0xcd, 0xf0, 0x11, 0x00, 0x00, 0xc1, 0x00,
70   0x00, 0x00, 0x23, 0xb4, 0xe6, 0x5C, 0x0c,
71   0xc0, 0x00, 0xc4, 0x86, 0x56, 0xa5
72 };
73 
GST_START_TEST(test_scte_sit)74 GST_START_TEST (test_scte_sit)
75 {
76   GstMpegtsSCTESIT *sit;
77   GstMpegtsSection *sit_section;
78   GstMpegtsSCTESpliceEvent *event;
79   guint8 *data;
80   gsize data_size;
81 
82   /* Try a simple NULL command before anything else */
83   sit = gst_mpegts_scte_sit_new ();
84   sit->tier = 123;
85   sit->pts_adjustment = 0x1fedcba12;
86   sit->splice_command_type = GST_MTS_SCTE_SPLICE_COMMAND_NULL;
87 
88   sit_section = gst_mpegts_section_from_scte_sit (sit, 456);
89   fail_if (sit_section == NULL);
90   fail_unless (sit_section->short_section);
91 
92   /* Serialize and check that we can re-parse it into something valid */
93   data = gst_mpegts_section_packetize (sit_section, &data_size);
94   fail_if (data == NULL);
95   GST_MEMDUMP ("section", data, data_size);
96 
97   GST_LOG ("here");
98   sit_section->destroy_parsed (sit_section->cached_parsed);
99   sit_section->cached_parsed = NULL;
100 
101   sit = (GstMpegtsSCTESIT *) gst_mpegts_section_get_scte_sit (sit_section);
102   fail_if (sit == NULL);
103   /* Check the values */
104   fail_unless (sit->encrypted_packet == FALSE);
105   fail_unless (sit->pts_adjustment == 0x1fedcba12);
106   fail_unless (sit->tier == 123);
107   fail_unless (sit->splice_command_type == GST_MTS_SCTE_SPLICE_COMMAND_NULL);
108 
109   gst_mpegts_section_unref (sit_section);
110 
111 
112   /* Same thing but now with an insert command */
113   sit = gst_mpegts_scte_sit_new ();
114   sit->tier = 123;
115   sit->pts_adjustment = 0x1fedcba12;
116   sit->splice_command_type = GST_MTS_SCTE_SPLICE_COMMAND_INSERT;
117 
118   event = gst_mpegts_scte_splice_event_new ();
119   event->insert_event = TRUE;
120   event->splice_event_id = 4285;
121   event->program_splice_flag = TRUE;
122   event->duration_flag = TRUE;
123   event->splice_immediate_flag = FALSE;
124 
125   event->program_splice_time_specified = TRUE;
126   event->program_splice_time = 0x1fdecba12;
127 
128   event->break_duration_auto_return = TRUE;
129   event->break_duration = 590000;
130   event->unique_program_id = 4256;
131   event->avail_num = 2;
132   event->avails_expected = 2;
133   g_ptr_array_add (sit->splices, event);
134 
135   sit_section = gst_mpegts_section_from_scte_sit (sit, 456);
136   fail_if (sit_section == NULL);
137   fail_unless (sit_section->short_section);
138 
139   /* Serialize and check that we can re-parse it into something valid */
140   data = gst_mpegts_section_packetize (sit_section, &data_size);
141   fail_if (data == NULL);
142   GST_MEMDUMP ("section", data, data_size);
143 
144   GST_LOG ("here");
145   sit_section->destroy_parsed (sit_section->cached_parsed);
146   sit_section->cached_parsed = NULL;
147 
148   sit = (GstMpegtsSCTESIT *) gst_mpegts_section_get_scte_sit (sit_section);
149   fail_if (sit == NULL);
150   /* Check the values */
151   fail_unless (sit->encrypted_packet == FALSE);
152   fail_unless (sit->pts_adjustment == 0x1fedcba12);
153   fail_unless (sit->tier == 123);
154   fail_unless (sit->pts_adjustment == 0x1fedcba12);
155   fail_unless (sit->splice_command_type == GST_MTS_SCTE_SPLICE_COMMAND_INSERT);
156 
157   event = g_ptr_array_index (sit->splices, 0);
158   fail_unless (event->insert_event == TRUE);
159   fail_unless (event->splice_event_id == 4285);
160   fail_unless (event->program_splice_flag == TRUE);
161   fail_unless (event->duration_flag == TRUE);
162   fail_unless (event->splice_immediate_flag == FALSE);
163 
164   fail_unless (event->program_splice_time_specified == TRUE);
165   fail_unless (event->program_splice_time == 0x1fdecba12);
166 
167   fail_unless (event->break_duration_auto_return == TRUE);
168   fail_unless (event->break_duration == 590000);
169   fail_unless (event->unique_program_id == 4256);
170   fail_unless (event->avail_num == 2);
171   fail_unless (event->avails_expected == 2);
172 
173 
174   gst_mpegts_section_unref (sit_section);
175 
176 
177 }
178 
179 GST_END_TEST;
180 
GST_START_TEST(test_mpegts_pat)181 GST_START_TEST (test_mpegts_pat)
182 {
183   GstMpegtsPatProgram *program;
184   GPtrArray *pat;
185   GstMpegtsSection *pat_section;
186   gint i;
187   guint8 *data;
188   gsize data_size;
189 
190   /* Check creation of PAT */
191   pat = gst_mpegts_pat_new ();
192 
193   for (i = 0; i < 2; i++) {
194     program = gst_mpegts_pat_program_new ();
195 
196     program->program_number = i;
197     program->network_or_program_map_PID = 0x30 + i;
198 
199     g_ptr_array_add (pat, program);
200   }
201 
202   pat_section = gst_mpegts_section_from_pat (pat, 0);
203   fail_if (pat_section == NULL);
204 
205   /* Re-parse the PAT from section */
206   pat = gst_mpegts_section_get_pat (pat_section);
207 
208   fail_unless (pat->len == 2);
209 
210   for (i = 0; i < 2; i++) {
211     program = g_ptr_array_index (pat, i);
212 
213     assert_equals_int (program->program_number, i);
214     assert_equals_int (program->network_or_program_map_PID, 0x30 + i);
215   }
216   g_ptr_array_unref (pat);
217   pat = NULL;
218 
219   /* Packetize the section, and check the data integrity */
220   data = gst_mpegts_section_packetize (pat_section, &data_size);
221   fail_if (data == NULL);
222 
223   for (i = 0; i < data_size; i++) {
224     if (data[i] != pat_data_check[i])
225       fail ("0x%X != 0x%X in byte %d of PAT section", data[i],
226           pat_data_check[i], i);
227   }
228 
229   /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */
230   pat_section->data[pat_section->section_length - 1]++;
231   pat_section->destroy_parsed (pat_section->cached_parsed);
232   pat_section->cached_parsed = NULL;
233 
234   pat = gst_mpegts_section_get_pat (pat_section);
235   fail_unless (pat == NULL);
236 
237   gst_mpegts_section_unref (pat_section);
238 }
239 
240 GST_END_TEST;
241 
GST_START_TEST(test_mpegts_pmt)242 GST_START_TEST (test_mpegts_pmt)
243 {
244   GstMpegtsPMT *pmt;
245   GstMpegtsPMTStream *stream;
246   GstMpegtsDescriptor *desc;
247   GstMpegtsSection *pmt_section;
248   guint8 *data;
249   gsize data_size;
250   gint i;
251 
252   /* Check creation of PMT */
253   pmt = gst_mpegts_pmt_new ();
254 
255   pmt->pcr_pid = 0x1FFF;
256   pmt->program_number = 1;
257 
258   desc = gst_mpegts_descriptor_from_registration ("HDMV", NULL, 0);
259   g_ptr_array_add (pmt->descriptors, desc);
260 
261   for (i = 0; i < 2; i++) {
262     stream = gst_mpegts_pmt_stream_new ();
263 
264     stream->stream_type = GST_MPEGTS_STREAM_TYPE_VIDEO_H264;
265     stream->pid = 0x40 + i;
266 
267     desc = gst_mpegts_descriptor_from_registration ("HDMV", NULL, 0);
268 
269     g_ptr_array_add (stream->descriptors, desc);
270     g_ptr_array_add (pmt->streams, stream);
271   }
272 
273   pmt_section = gst_mpegts_section_from_pmt (pmt, 0x30);
274   fail_if (pmt_section == NULL);
275 
276   /* Re-parse the PMT from section */
277   pmt = (GstMpegtsPMT *) gst_mpegts_section_get_pmt (pmt_section);
278 
279   fail_unless (pmt->pcr_pid == 0x1FFF);
280   fail_unless (pmt->program_number == 1);
281   fail_unless (pmt->descriptors->len == 1);
282   fail_unless (pmt->streams->len == 2);
283 
284   desc = (GstMpegtsDescriptor *) gst_mpegts_find_descriptor (pmt->descriptors,
285       GST_MTS_DESC_REGISTRATION);
286   fail_if (desc == NULL);
287 
288   for (i = 0; i < 2; i++) {
289     stream = g_ptr_array_index (pmt->streams, i);
290 
291     fail_unless (stream->stream_type == GST_MPEGTS_STREAM_TYPE_VIDEO_H264);
292     fail_unless (stream->pid == 0x40 + i);
293     fail_unless (stream->descriptors->len == 1);
294 
295     desc =
296         (GstMpegtsDescriptor *) gst_mpegts_find_descriptor (stream->descriptors,
297         GST_MTS_DESC_REGISTRATION);
298     fail_if (desc == NULL);
299   }
300 
301   /* Packetize the section, and check data integrity */
302   data = gst_mpegts_section_packetize (pmt_section, &data_size);
303 
304   for (i = 0; i < data_size; i++) {
305     if (data[i] != pmt_data_check[i])
306       fail ("0x%X != 0x%X in byte %d of PMT section", data[i],
307           pmt_data_check[i], i);
308   }
309 
310   /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */
311   pmt_section->data[pmt_section->section_length - 1]++;
312   pmt_section->destroy_parsed (pmt_section->cached_parsed);
313   pmt_section->cached_parsed = NULL;
314   pmt = (GstMpegtsPMT *) gst_mpegts_section_get_pmt (pmt_section);
315 
316   fail_unless (pmt == NULL);
317 
318   gst_mpegts_section_unref (pmt_section);
319 }
320 
321 GST_END_TEST;
322 
323 
GST_START_TEST(test_mpegts_nit)324 GST_START_TEST (test_mpegts_nit)
325 {
326   GstMpegtsNITStream *stream;
327   GstMpegtsNIT *nit;
328   GstMpegtsDescriptor *desc;
329   GstMpegtsSection *nit_section;
330   gchar *name;
331   guint8 *data;
332   gsize data_size;
333   gint i;
334 
335   /* Check creation of NIT */
336   nit = gst_mpegts_nit_new ();
337 
338   nit->actual_network = TRUE;
339   nit->network_id = 0x1FFF;
340 
341   desc = gst_mpegts_descriptor_from_dvb_network_name ("Network name");
342 
343   fail_if (desc == NULL);
344 
345   g_ptr_array_add (nit->descriptors, desc);
346 
347   for (i = 0; i < 2; i++) {
348     stream = gst_mpegts_nit_stream_new ();
349     stream->transport_stream_id = 0x1FFF;
350     stream->original_network_id = 0x1FFE;
351 
352     desc = gst_mpegts_descriptor_from_dvb_network_name ("Another network");
353 
354     g_ptr_array_add (stream->descriptors, desc);
355     g_ptr_array_add (nit->streams, stream);
356   }
357 
358   nit_section = gst_mpegts_section_from_nit (nit);
359   fail_if (nit_section == NULL);
360 
361   /* Re-parse the NIT from section */
362   nit = (GstMpegtsNIT *) gst_mpegts_section_get_nit (nit_section);
363 
364   fail_unless (nit->descriptors->len == 1);
365   fail_unless (nit->streams->len == 2);
366   fail_unless (nit->actual_network == TRUE);
367   fail_unless (nit->network_id == 0x1FFF);
368 
369   desc = (GstMpegtsDescriptor *) gst_mpegts_find_descriptor (nit->descriptors,
370       GST_MTS_DESC_DVB_NETWORK_NAME);
371 
372   fail_if (desc == NULL);
373 
374   fail_unless (gst_mpegts_descriptor_parse_dvb_network_name (desc,
375           &name) == TRUE);
376 
377   g_free (name);
378 
379   for (i = 0; i < 2; i++) {
380     stream = g_ptr_array_index (nit->streams, i);
381 
382     fail_unless (stream->transport_stream_id == 0x1FFF);
383     fail_unless (stream->original_network_id == 0x1FFE);
384     fail_unless (stream->descriptors->len == 1);
385 
386     desc =
387         (GstMpegtsDescriptor *) gst_mpegts_find_descriptor (stream->descriptors,
388         GST_MTS_DESC_DVB_NETWORK_NAME);
389 
390     fail_unless (gst_mpegts_descriptor_parse_dvb_network_name (desc,
391             &name) == TRUE);
392     g_free (name);
393   }
394 
395   /* Packetize the section, and check data integrity */
396   data = gst_mpegts_section_packetize (nit_section, &data_size);
397 
398   fail_if (data == NULL);
399 
400   for (i = 0; i < data_size; i++) {
401     if (data[i] != nit_data_check[i])
402       fail ("0x%X != 0x%X in byte %d of NIT section", data[i],
403           nit_data_check[i], i);
404   }
405 
406   /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */
407   nit_section->data[nit_section->section_length - 1]++;
408   nit_section->destroy_parsed (nit_section->cached_parsed);
409   nit_section->cached_parsed = NULL;
410   nit = (GstMpegtsNIT *) gst_mpegts_section_get_nit (nit_section);
411 
412   fail_unless (nit == NULL);
413 
414   gst_mpegts_section_unref (nit_section);
415 }
416 
417 GST_END_TEST;
418 
GST_START_TEST(test_mpegts_sdt)419 GST_START_TEST (test_mpegts_sdt)
420 {
421   GstMpegtsSDTService *service;
422   GstMpegtsSDT *sdt;
423   GstMpegtsDescriptor *desc;
424   GstMpegtsSection *sdt_section;
425   guint8 *data;
426   gsize data_size;
427   gint i;
428 
429   /* Check creation of SDT */
430   sdt = gst_mpegts_sdt_new ();
431 
432   sdt->actual_ts = TRUE;
433   sdt->original_network_id = 0x1FFF;
434   sdt->transport_stream_id = 0x1FFF;
435 
436   for (i = 0; i < 2; i++) {
437     service = gst_mpegts_sdt_service_new ();
438     service->service_id = i;
439     service->EIT_schedule_flag = TRUE;
440     service->EIT_present_following_flag = TRUE;
441     service->running_status = GST_MPEGTS_RUNNING_STATUS_RUNNING + i;
442     service->free_CA_mode = TRUE;
443 
444     desc = gst_mpegts_descriptor_from_dvb_service
445         (GST_DVB_SERVICE_DIGITAL_TELEVISION, "Name", "Provider");
446 
447     g_ptr_array_add (service->descriptors, desc);
448     g_ptr_array_add (sdt->services, service);
449   }
450 
451   sdt_section = gst_mpegts_section_from_sdt (sdt);
452   fail_if (sdt_section == NULL);
453 
454   /* Re-parse the SDT from section */
455   sdt = (GstMpegtsSDT *) gst_mpegts_section_get_sdt (sdt_section);
456 
457   fail_unless (sdt->services->len == 2);
458   fail_unless (sdt->actual_ts == TRUE);
459   fail_unless (sdt->original_network_id == 0x1FFF);
460   fail_unless (sdt->transport_stream_id == 0x1FFF);
461 
462   for (i = 0; i < 2; i++) {
463     service = g_ptr_array_index (sdt->services, i);
464 
465     fail_if (service == NULL);
466     fail_unless (service->descriptors->len == 1);
467     fail_unless (service->service_id == i);
468     fail_unless (service->EIT_schedule_flag == TRUE);
469     fail_unless (service->EIT_present_following_flag == TRUE);
470     fail_unless (service->running_status ==
471         GST_MPEGTS_RUNNING_STATUS_RUNNING + i);
472     fail_unless (service->free_CA_mode == TRUE);
473 
474     desc = (GstMpegtsDescriptor *)
475         gst_mpegts_find_descriptor (service->descriptors,
476         GST_MTS_DESC_DVB_SERVICE);
477 
478     fail_if (desc == NULL);
479 
480     fail_unless (gst_mpegts_descriptor_parse_dvb_service (desc,
481             NULL, NULL, NULL) == TRUE);
482   }
483 
484   /* Packetize the section, and check data integrity */
485   data = gst_mpegts_section_packetize (sdt_section, &data_size);
486 
487   fail_if (data == NULL);
488 
489   for (i = 0; i < data_size; i++) {
490     if (data[i] != sdt_data_check[i])
491       fail ("0x%X != 0x%X in byte %d of SDT section", data[i],
492           sdt_data_check[i], i);
493   }
494 
495   /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */
496   sdt_section->data[sdt_section->section_length - 1]++;
497   sdt_section->destroy_parsed (sdt_section->cached_parsed);
498   sdt_section->cached_parsed = NULL;
499   sdt = (GstMpegtsSDT *) gst_mpegts_section_get_sdt (sdt_section);
500 
501   fail_unless (sdt == NULL);
502 
503   gst_mpegts_section_unref (sdt_section);
504 }
505 
506 GST_END_TEST;
507 
GST_START_TEST(test_mpegts_atsc_stt)508 GST_START_TEST (test_mpegts_atsc_stt)
509 {
510   const GstMpegtsAtscSTT *stt;
511   GstMpegtsSection *section;
512   guint8 *data;
513   GstDateTime *dt;
514 
515   data = g_memdup2 (stt_data_check, 20);
516 
517   section = gst_mpegts_section_new (0x1ffb, data, 20);
518   stt = gst_mpegts_section_get_atsc_stt (section);
519   fail_if (stt == NULL);
520 
521   fail_unless (stt->protocol_version == 0);
522   fail_unless (stt->system_time == 0x23b4e65c);
523   fail_unless (stt->gps_utc_offset == 12);
524   fail_unless (stt->ds_status == 1);
525   fail_unless (stt->ds_dayofmonth == 0);
526   fail_unless (stt->ds_hour == 0);
527 
528   dt = gst_mpegts_atsc_stt_get_datetime_utc ((GstMpegtsAtscSTT *) stt);
529   fail_unless (gst_date_time_get_day (dt) == 30);
530   fail_unless (gst_date_time_get_month (dt) == 12);
531   fail_unless (gst_date_time_get_year (dt) == 1998);
532   fail_unless (gst_date_time_get_hour (dt) == 13);
533   fail_unless (gst_date_time_get_minute (dt) == 0);
534   fail_unless (gst_date_time_get_second (dt) == 0);
535 
536   gst_date_time_unref (dt);
537   gst_mpegts_section_unref (section);
538 }
539 
540 GST_END_TEST;
541 
542 
543 static const guint8 registration_descriptor[] = {
544   0x05, 0x04, 0x48, 0x44, 0x4d, 0x56
545 };
546 
GST_START_TEST(test_mpegts_descriptors)547 GST_START_TEST (test_mpegts_descriptors)
548 {
549   GstMpegtsDescriptor *desc;
550   guint i;
551 
552   /*
553    * Registration descriptor (0x05)
554    */
555 
556   /* Check creation of descriptor */
557   desc = gst_mpegts_descriptor_from_registration ("HDMV", NULL, 0);
558   fail_if (desc == NULL);
559   fail_unless (desc->length == 4);
560   fail_unless (desc->tag == 0x05);
561   for (i = 0; i < 6; i++) {
562     if (registration_descriptor[i] != desc->data[i])
563       fail ("0x%X != 0x%X in byte %d of registration descriptor",
564           desc->data[i], registration_descriptor[i], i);
565   }
566   gst_mpegts_descriptor_free (desc);
567 }
568 
569 GST_END_TEST;
570 
571 static const guint8 network_name_descriptor[] = {
572   0x40, 0x04, 0x4e, 0x61, 0x6d, 0x65
573 };
574 
575 static const guint8 service_descriptor[] = {
576   0x48, 0x0f, 0x01, 0x08, 0x50, 0x72, 0x6f,
577   0x76, 0x69, 0x64, 0x65, 0x72, 0x04, 0x4e,
578   0x61, 0x6d, 0x65
579 };
580 
GST_START_TEST(test_mpegts_dvb_descriptors)581 GST_START_TEST (test_mpegts_dvb_descriptors)
582 {
583   GstMpegtsDescriptor *desc;
584   GstMpegtsDVBServiceType service_type;
585   gchar *string, *provider;
586   gchar long_string[257];
587   gboolean ret;
588   guint i;
589 
590   /*
591    * Network name descriptor (0x40)
592    */
593 
594   /* Check creation of descriptor */
595   desc = gst_mpegts_descriptor_from_dvb_network_name ("Name");
596   fail_if (desc == NULL);
597   fail_unless (desc->length == 4);
598   fail_unless (desc->tag == 0x40);
599 
600   for (i = 0; i < 6; i++) {
601     if (desc->data[i] != network_name_descriptor[i])
602       fail ("0x%X != 0x%X in byte %d of network name descriptor",
603           desc->data[i], network_name_descriptor[i], i);
604   }
605 
606   /* Check parsing of descriptor */
607   ret = gst_mpegts_descriptor_parse_dvb_network_name (desc, &string);
608   fail_unless (ret == TRUE);
609   fail_unless (strcmp (string, "Name") == 0);
610   g_free (string);
611   gst_mpegts_descriptor_free (desc);
612 
613   /* Descriptor should fail if string is more than 255 bytes */
614   memset (long_string, 0x41, 256);
615   long_string[256] = 0x00;
616   fail_if (gst_mpegts_descriptor_from_dvb_network_name (long_string) != NULL);
617 
618   /*
619    * Service descriptor (0x48)
620    */
621 
622   /* Check creation of descriptor with data */
623   desc = gst_mpegts_descriptor_from_dvb_service
624       (GST_DVB_SERVICE_DIGITAL_TELEVISION, "Name", "Provider");
625   fail_if (desc == NULL);
626   fail_unless (desc->length == 15);
627   fail_unless (desc->tag == 0x48);
628 
629   for (i = 0; i < 17; i++) {
630     if (desc->data[i] != service_descriptor[i])
631       fail ("0x%X != 0x%X in byte %d of service descriptor",
632           desc->data[i], service_descriptor[i], i);
633   }
634 
635   /* Check parsing of descriptor with data */
636   ret = gst_mpegts_descriptor_parse_dvb_service
637       (desc, &service_type, &string, &provider);
638   fail_unless (ret == TRUE);
639   fail_unless (service_type == GST_DVB_SERVICE_DIGITAL_TELEVISION);
640   fail_unless (strcmp (string, "Name") == 0);
641   fail_unless (strcmp (provider, "Provider") == 0);
642   g_free (string);
643   g_free (provider);
644   gst_mpegts_descriptor_free (desc);
645 
646   /* Check creation of descriptor without data */
647   desc = gst_mpegts_descriptor_from_dvb_service
648       (GST_DVB_SERVICE_DIGITAL_TELEVISION, NULL, NULL);
649   fail_if (desc == NULL);
650   fail_unless (desc->length == 3);
651   fail_unless (desc->tag == 0x48);
652 
653   /* Check parsing of descriptor without data */
654   ret = gst_mpegts_descriptor_parse_dvb_service (desc, NULL, NULL, NULL);
655   fail_unless (ret == TRUE);
656   gst_mpegts_descriptor_free (desc);
657 
658   /* Descriptor should fail if string is more than 255 bytes */
659   memset (long_string, 0x41, 256);
660   long_string[256] = 0x00;
661   desc =
662       gst_mpegts_descriptor_from_dvb_service
663       (GST_DVB_SERVICE_DIGITAL_TELEVISION, long_string, NULL);
664   fail_if (desc != NULL);
665   desc =
666       gst_mpegts_descriptor_from_dvb_service
667       (GST_DVB_SERVICE_DIGITAL_TELEVISION, NULL, long_string);
668   fail_if (desc != NULL);
669 }
670 
671 GST_END_TEST;
672 
673 static Suite *
mpegts_suite(void)674 mpegts_suite (void)
675 {
676   Suite *s = suite_create ("MPEG Transport Stream helper library");
677 
678   TCase *tc_chain = tcase_create ("general");
679 
680   gst_mpegts_initialize ();
681 
682   suite_add_tcase (s, tc_chain);
683   tcase_add_test (tc_chain, test_scte_sit);
684   tcase_add_test (tc_chain, test_mpegts_pat);
685   tcase_add_test (tc_chain, test_mpegts_pmt);
686   tcase_add_test (tc_chain, test_mpegts_nit);
687   tcase_add_test (tc_chain, test_mpegts_sdt);
688   tcase_add_test (tc_chain, test_mpegts_atsc_stt);
689   tcase_add_test (tc_chain, test_mpegts_descriptors);
690   tcase_add_test (tc_chain, test_mpegts_dvb_descriptors);
691 
692   return s;
693 }
694 
695 GST_CHECK_MAIN (mpegts);
696