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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
/* GStreamer unit test for MPEG-DASH
*
* Copyright (c) <2015> YouView TV Ltd
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "../../ext/dash/gstmpdparser.c"
#undef GST_CAT_DEFAULT
#include <gst/check/gstcheck.h>
GST_DEBUG_CATEGORY (gst_dash_demux_debug);
/*
* compute the number of milliseconds contained in a duration value specified by
* year, month, day, hour, minute, second, millisecond
*
* This function must use the same conversion algorithm implemented in
* gst_mpdparser_get_xml_prop_duration from gstmpdparser.c file.
*/
static gint64
duration_to_ms (guint year, guint month, guint day, guint hour, guint minute,
guint second, guint millisecond)
{
gint64 days = (gint64) year * 365 + month * 30 + day;
gint64 hours = days * 24 + hour;
gint64 minutes = hours * 60 + minute;
gint64 seconds = minutes * 60 + second;
gint64 ms = seconds * 1000 + millisecond;
return ms;
}
/*
* Test to ensure a simple mpd file successfully parses.
*
*/
GST_START_TEST (dash_mpdparser_validsimplempd)
{
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\"> </MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, TRUE);
/* check that unset elements with default values are properly configured */
assert_equals_int (mpdclient->mpd_node->type, GST_MPD_FILE_TYPE_STATIC);
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing the MPD attributes.
*
*/
GST_START_TEST (dash_mpdparser_mpd)
{
GstDateTime *availabilityStartTime;
GstDateTime *availabilityEndTime;
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\""
" id=\"testId\""
" type=\"static\""
" availabilityStartTime=\"2015-03-24T1:10:50\""
" availabilityEndTime=\"2015-03-24T1:10:50\""
" mediaPresentationDuration=\"P0Y1M2DT12H10M20.5S\""
" minimumUpdatePeriod=\"P0Y1M2DT12H10M20.5S\""
" minBufferTime=\"P0Y1M2DT12H10M20.5S\""
" timeShiftBufferDepth=\"P0Y1M2DT12H10M20.5S\""
" suggestedPresentationDelay=\"P0Y1M2DT12H10M20.5S\""
" maxSegmentDuration=\"P0Y1M2DT12H10M20.5S\""
" maxSubsegmentDuration=\"P0Y1M2DT12H10M20.5S\"></MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, TRUE);
assert_equals_string (mpdclient->mpd_node->id, "testId");
assert_equals_int (mpdclient->mpd_node->type, GST_MPD_FILE_TYPE_STATIC);
availabilityStartTime = mpdclient->mpd_node->availabilityStartTime;
assert_equals_int (gst_date_time_get_year (availabilityStartTime), 2015);
assert_equals_int (gst_date_time_get_month (availabilityStartTime), 3);
assert_equals_int (gst_date_time_get_day (availabilityStartTime), 24);
assert_equals_int (gst_date_time_get_hour (availabilityStartTime), 1);
assert_equals_int (gst_date_time_get_minute (availabilityStartTime), 10);
assert_equals_int (gst_date_time_get_second (availabilityStartTime), 50);
availabilityEndTime = mpdclient->mpd_node->availabilityEndTime;
assert_equals_int (gst_date_time_get_year (availabilityEndTime), 2015);
assert_equals_int (gst_date_time_get_month (availabilityEndTime), 3);
assert_equals_int (gst_date_time_get_day (availabilityEndTime), 24);
assert_equals_int (gst_date_time_get_hour (availabilityEndTime), 1);
assert_equals_int (gst_date_time_get_minute (availabilityEndTime), 10);
assert_equals_int (gst_date_time_get_second (availabilityEndTime), 50);
assert_equals_int64 (mpdclient->mpd_node->mediaPresentationDuration,
duration_to_ms (0, 1, 2, 12, 10, 20, 500));
assert_equals_int64 (mpdclient->mpd_node->minimumUpdatePeriod,
duration_to_ms (0, 1, 2, 12, 10, 20, 500));
assert_equals_int64 (mpdclient->mpd_node->minBufferTime,
duration_to_ms (0, 1, 2, 12, 10, 20, 500));
assert_equals_int64 (mpdclient->mpd_node->timeShiftBufferDepth,
duration_to_ms (0, 1, 2, 12, 10, 20, 500));
assert_equals_int64 (mpdclient->mpd_node->suggestedPresentationDelay,
duration_to_ms (0, 1, 2, 12, 10, 20, 500));
assert_equals_int64 (mpdclient->mpd_node->maxSegmentDuration,
duration_to_ms (0, 1, 2, 12, 10, 20, 500));
assert_equals_int64 (mpdclient->mpd_node->maxSubsegmentDuration,
duration_to_ms (0, 1, 2, 12, 10, 20, 500));
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing the ProgramInformation attributes
*
*/
GST_START_TEST (dash_mpdparser_program_information)
{
GstProgramInformationNode *program;
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\">"
"<ProgramInformation lang=\"en\""
" moreInformationURL=\"TestMoreInformationUrl\">"
"<Title>TestTitle</Title>"
"<Source>TestSource</Source>"
"<Copyright>TestCopyright</Copyright> </ProgramInformation> </MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, TRUE);
program =
(GstProgramInformationNode *) mpdclient->mpd_node->ProgramInfo->data;
assert_equals_string (program->lang, "en");
assert_equals_string (program->moreInformationURL, "TestMoreInformationUrl");
assert_equals_string (program->Title, "TestTitle");
assert_equals_string (program->Source, "TestSource");
assert_equals_string (program->Copyright, "TestCopyright");
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing the BaseURL attributes
*
*/
GST_START_TEST (dash_mpdparser_base_URL)
{
GstBaseURL *baseURL;
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\">"
"<BaseURL serviceLocation=\"TestServiceLocation\""
" byteRange=\"TestByteRange\">TestBaseURL</BaseURL></MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, TRUE);
baseURL = (GstBaseURL *) mpdclient->mpd_node->BaseURLs->data;
assert_equals_string (baseURL->baseURL, "TestBaseURL");
assert_equals_string (baseURL->serviceLocation, "TestServiceLocation");
assert_equals_string (baseURL->byteRange, "TestByteRange");
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing the location attributes
*
*/
GST_START_TEST (dash_mpdparser_location)
{
const gchar *location;
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\">"
"<Location>TestLocation</Location></MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, TRUE);
location = (gchar *) mpdclient->mpd_node->Locations->data;
assert_equals_string (location, "TestLocation");
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing metrics attributes
*
*/
GST_START_TEST (dash_mpdparser_metrics)
{
GstMetricsNode *metricsNode;
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\">"
"<Metrics metrics=\"TestMetric\"></Metrics></MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, TRUE);
metricsNode = (GstMetricsNode *) mpdclient->mpd_node->Metrics->data;
assert_equals_string (metricsNode->metrics, "TestMetric");
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing metrics range attributes
*
*/
GST_START_TEST (dash_mpdparser_metrics_range)
{
GstMetricsNode *metricsNode;
GstMetricsRangeNode *metricsRangeNode;
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\">"
"<Metrics><Range starttime=\"P0Y1M2DT12H10M20.5S\""
" duration=\"P0Y1M2DT12H10M20.1234567S\"></Range></Metrics></MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, TRUE);
metricsNode = (GstMetricsNode *) mpdclient->mpd_node->Metrics->data;
assert_equals_pointer (metricsNode->metrics, NULL);
metricsRangeNode = (GstMetricsRangeNode *) metricsNode->MetricsRanges->data;
assert_equals_int64 (metricsRangeNode->starttime,
duration_to_ms (0, 1, 2, 12, 10, 20, 500));
assert_equals_int64 (metricsRangeNode->duration,
duration_to_ms (0, 1, 2, 12, 10, 20, 123));
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing metrics reporting attributes
*
*/
GST_START_TEST (dash_mpdparser_metrics_reporting)
{
GstMetricsNode *metricsNode;
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\">"
"<Metrics><Reporting></Reporting></Metrics></MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, TRUE);
metricsNode = (GstMetricsNode *) mpdclient->mpd_node->Metrics->data;
assert_equals_pointer (metricsNode->metrics, NULL);
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing the type property: value "dynamic"
*
*/
GST_START_TEST (dash_mpdparser_type_dynamic)
{
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD type=\"dynamic\" xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\"> </MPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, TRUE);
assert_equals_int (mpdclient->mpd_node->type, GST_MPD_FILE_TYPE_DYNAMIC);
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing empty xml string
*
*/
GST_START_TEST (dash_mpdparser_missing_xml)
{
const gchar *xml = "";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, FALSE);
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing an xml with no mpd tag
*
*/
GST_START_TEST (dash_mpdparser_missing_mpd)
{
const gchar *xml = "<?xml version=\"1.0\"?>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, FALSE);
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* Test parsing an MPD with a wrong end tag
*/
GST_START_TEST (dash_mpdparser_no_end_tag)
{
const gchar *xml =
"<?xml version=\"1.0\"?>"
"<MPD xmlns=\"urn:mpeg:dash:schema:mpd:2011\""
" profiles=\"urn:mpeg:dash:profile:isoff-main:2011\"> </NPD>";
gboolean ret;
GstMpdClient *mpdclient = gst_mpd_client_new ();
ret = gst_mpd_parse (mpdclient, xml, strlen (xml));
assert_equals_int (ret, FALSE);
gst_mpd_client_free (mpdclient);
}
GST_END_TEST;
/*
* create a test suite containing all dash testcases
*/
static Suite *
dash_suite (void)
{
Suite *s = suite_create ("dash");
TCase *tc_simpleMPD = tcase_create ("simpleMPD");
TCase *tc_negativeTests = tcase_create ("negativeTests");
GST_DEBUG_CATEGORY_INIT (gst_dash_demux_debug, "gst_dash_demux_debug", 0,
"mpeg dash tests");
/* test parsing the simplest possible mpd */
tcase_add_test (tc_simpleMPD, dash_mpdparser_validsimplempd);
/* tests parsing attributes from each element type */
tcase_add_test (tc_simpleMPD, dash_mpdparser_mpd);
tcase_add_test (tc_simpleMPD, dash_mpdparser_program_information);
tcase_add_test (tc_simpleMPD, dash_mpdparser_base_URL);
tcase_add_test (tc_simpleMPD, dash_mpdparser_location);
tcase_add_test (tc_simpleMPD, dash_mpdparser_metrics);
tcase_add_test (tc_simpleMPD, dash_mpdparser_metrics_range);
tcase_add_test (tc_simpleMPD, dash_mpdparser_metrics_reporting);
/* tests checking other possible values for attributes */
tcase_add_test (tc_simpleMPD, dash_mpdparser_type_dynamic);
/* tests checking the parsing of missing/incomplete attributes of xml */
tcase_add_test (tc_negativeTests, dash_mpdparser_missing_xml);
tcase_add_test (tc_negativeTests, dash_mpdparser_missing_mpd);
tcase_add_test (tc_negativeTests, dash_mpdparser_no_end_tag);
suite_add_tcase (s, tc_simpleMPD);
suite_add_tcase (s, tc_negativeTests);
return s;
}
GST_CHECK_MAIN (dash);
|