forked from shaka-project/shaka-player
/
dash_parser_manifest_unit.js
2336 lines (2102 loc) · 89.3 KB
/
dash_parser_manifest_unit.js
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
// Test basic manifest parsing functionality.
describe('DashParser Manifest', () => {
const ContentType = shaka.util.ManifestParserUtils.ContentType;
const Dash = shaka.test.Dash;
const mp4IndexSegmentUri = '/base/test/test/assets/index-segment.mp4';
/** @type {!shaka.test.FakeNetworkingEngine} */
let fakeNetEngine;
/** @type {!shaka.dash.DashParser} */
let parser;
/** @type {!jasmine.Spy} */
let onEventSpy;
/** @type {shaka.extern.ManifestParser.PlayerInterface} */
let playerInterface;
/** @type {!ArrayBuffer} */
let mp4Index;
/** @type {string} */
const thumbnailScheme = 'http://dashif.org/guidelines/thumbnail_tile';
/**
* CICP scheme. parameter must be one of the following: "ColourPrimaries",
* "TransferCharacteristics", or "MatrixCoefficients".
*
* @param {string} parameter
* @return {string}
*/
const cicpScheme = (parameter) => `urn:mpeg:mpegB:cicp:${parameter}`;
beforeAll(async () => {
mp4Index = await shaka.test.Util.fetch(mp4IndexSegmentUri);
});
beforeEach(() => {
fakeNetEngine = new shaka.test.FakeNetworkingEngine();
parser = shaka.test.Dash.makeDashParser();
onEventSpy = jasmine.createSpy('onEvent');
playerInterface = {
networkingEngine: fakeNetEngine,
modifyManifestRequest: (request, manifestInfo) => {},
modifySegmentRequest: (request, segmentInfo) => {},
filter: (manifest) => Promise.resolve(),
makeTextStreamsForClosedCaptions: (manifest) => {},
onTimelineRegionAdded: fail, // Should not have any EventStream elements.
onEvent: shaka.test.Util.spyFunc(onEventSpy),
onError: fail,
isLowLatencyMode: () => false,
isAutoLowLatencyMode: () => false,
enableLowLatencyMode: () => {},
};
});
/**
* Makes a series of tests for the given manifest type.
*
* @param {!Array.<string>} startLines
* @param {!Array.<string>} endLines
* @param {shaka.extern.Manifest} expected
*/
function makeTestsForEach(startLines, endLines, expected) {
/**
* Makes manifest text for testing.
*
* @param {!Array.<string>} lines
* @return {string}
*/
function makeTestManifest(lines) {
return startLines.concat(lines, endLines).join('\n');
}
/**
* Tests that the parser produces the correct results.
*
* @param {string} manifestText
* @return {!Promise}
*/
async function testDashParser(manifestText) {
fakeNetEngine.setResponseText('dummy://foo', manifestText);
const actual = await parser.start('dummy://foo', playerInterface);
expect(actual).toEqual(expected);
}
it('with SegmentBase', async () => {
const source = makeTestManifest([
' <SegmentBase indexRange="100-200" timescale="9000">',
' <Initialization sourceURL="init.mp4" range="201-300" />',
' </SegmentBase>',
]);
await testDashParser(source);
});
it('with SegmentList', async () => {
const source = makeTestManifest([
' <SegmentList startNumber="1" duration="10">',
' <Initialization sourceURL="init.mp4" range="201-300" />',
' <SegmentURL media="s1.mp4" />',
' </SegmentList>',
]);
await testDashParser(source);
});
it('with SegmentTemplate', async () => {
const source = makeTestManifest([
' <SegmentTemplate startNumber="1" media="l-$Number$.mp4"',
' initialization="init.mp4">',
' <Initialization sourceURL="init.mp4" range="201-300" />',
' <SegmentTimeline>',
' <S t="0" d="30" />',
' </SegmentTimeline>',
' </SegmentTemplate>',
]);
await testDashParser(source);
});
}
describe('parses and inherits attributes', () => {
makeTestsForEach(
[
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <BaseURL>http://example.com</BaseURL>',
],
[
' <AdaptationSet contentType="video" mimeType="video/mp4"',
' codecs="avc1.4d401f" frameRate="1000000/42000">',
' <Representation bandwidth="100" width="768" height="576" />',
' <Representation bandwidth="50" width="576" height="432" />',
' </AdaptationSet>',
' <AdaptationSet mimeType="text/vtt"',
' lang="es" label="spanish">',
' <Role value="caption" />',
' <Role value="main" />',
' <Representation bandwidth="100" />',
' </AdaptationSet>',
' <AdaptationSet mimeType="audio/mp4" lang="en" ',
' codecs="mp4a.40.29">',
' <Role value="main" />',
' <Representation bandwidth="100" />',
' </AdaptationSet>',
' </Period>',
'</MPD>',
],
shaka.test.ManifestGenerator.generate((manifest) => {
manifest.anyTimeline();
manifest.minBufferTime = 75;
manifest.addPartialVariant((variant) => {
variant.language = 'en';
variant.bandwidth = 200;
variant.primary = true;
variant.addPartialStream(ContentType.VIDEO, (stream) => {
stream.bandwidth = 100;
stream.frameRate = 1000000 / 42000;
stream.size(768, 576);
stream.mime('video/mp4', 'avc1.4d401f');
});
variant.addPartialStream(ContentType.AUDIO, (stream) => {
stream.bandwidth = 100;
stream.primary = true;
stream.roles = ['main'];
stream.mime('audio/mp4', 'mp4a.40.29');
});
});
manifest.addPartialVariant((variant) => {
variant.language = 'en';
variant.bandwidth = 150;
variant.primary = true;
variant.addPartialStream(ContentType.VIDEO, (stream) => {
stream.bandwidth = 50;
stream.frameRate = 1000000 / 42000;
stream.size(576, 432);
stream.mime('video/mp4', 'avc1.4d401f');
});
variant.addPartialStream(ContentType.AUDIO, (stream) => {
stream.bandwidth = 100;
stream.primary = true;
stream.roles = ['main'];
stream.mime('audio/mp4', 'mp4a.40.29');
});
});
manifest.addPartialTextStream((stream) => {
stream.language = 'es';
stream.label = 'spanish';
stream.primary = true;
stream.mimeType = 'text/vtt';
stream.bandwidth = 100;
stream.kind = 'caption';
stream.roles = ['caption', 'main'];
});
}));
});
it('rejects periods after one without duration', async () => {
const periodContents = [
' <AdaptationSet mimeType="video/mp4" lang="en" group="1">',
' <Representation bandwidth="100">',
' <SegmentTemplate startNumber="1" media="l-$Number$.mp4">',
' <SegmentTimeline>',
' <S t="0" d="10" />',
' </SegmentTimeline>',
' </SegmentTemplate>',
' </Representation>',
' </AdaptationSet>',
].join('\n');
const template = [
'<MPD mediaPresentationDuration="PT75S">',
' <Period id="1">',
'%(periodContents)s',
' </Period>',
' <Period id="2">',
'%(periodContents)s',
' </Period>',
'</MPD>',
].join('\n');
const source = sprintf(template, {periodContents: periodContents});
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const video = manifest.variants[0].video;
await video.createSegmentIndex();
// The first period has a segment from 0-10.
// With the second period skipping, we should fail to find a segment at 10.
expect(video.segmentIndex.find(0)).not.toBe(null);
expect(video.segmentIndex.find(10)).toBe(null);
});
it('calculates Period times when missing', async () => {
const periodContents = [
' <AdaptationSet mimeType="video/mp4" lang="en" group="1">',
' <Representation bandwidth="100">',
' <SegmentTemplate duration="2" media="s$Number$.mp4" />',
' </Representation>',
' </AdaptationSet>',
].join('\n');
const template = [
'<MPD>',
' <Period id="1" start="PT10S">',
'%(periodContents)s',
' </Period>',
' <Period id="2" start="PT20S" duration="PT10S">',
'%(periodContents)s',
' </Period>',
' <Period id="3" duration="PT10S">',
'%(periodContents)s',
' </Period>',
'</MPD>',
].join('\n');
const source = sprintf(template, {periodContents: periodContents});
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const timeline = manifest.presentationTimeline;
expect(timeline.getDuration()).toBe(40);
});
it('defaults to SegmentBase with multiple Segment*', async () => {
const source = Dash.makeSimpleManifestText([
'<SegmentBase presentationTimeOffset="1" indexRange="100-200">',
' <Initialization sourceURL="init.mp4" range="201-300" />',
'</SegmentBase>',
'<SegmentList presentationTimeOffset="2" duration="10">',
' <Initialization sourceURL="init.mp4" range="201-300" />',
' <SegmentURL media="s1.mp4" />',
'</SegmentList>',
]);
fakeNetEngine.setResponseText('dummy://foo', source);
fakeNetEngine.setResponseValue('http://example.com', mp4Index);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].video;
await stream.createSegmentIndex();
goog.asserts.assert(stream.segmentIndex != null, 'Null segmentIndex!');
const ref = Array.from(stream.segmentIndex)[0];
expect(ref.timestampOffset).toBe(-1);
});
it('defaults to SegmentList with SegmentTemplate', async () => {
const source = Dash.makeSimpleManifestText([
'<SegmentList presentationTimeOffset="2" duration="10">',
' <Initialization sourceURL="init.mp4" range="201-300" />',
' <SegmentURL media="s1.mp4" />',
'</SegmentList>',
'<SegmentTemplate startNumber="1" media="l-$Number$.mp4"',
' presentationTimeOffset="3" initialization="init.mp4">',
' <Initialization sourceURL="init.mp4" range="201-300" />',
' <SegmentTimeline>',
' <S t="0" d="30" />',
' </SegmentTimeline>',
'</SegmentTemplate>',
]);
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].video;
await stream.createSegmentIndex();
goog.asserts.assert(stream.segmentIndex != null, 'Null segmentIndex!');
const ref = Array.from(stream.segmentIndex)[0];
expect(ref.timestampOffset).toBe(-2);
});
it('generates a correct index for non-segmented text', async () => {
const source = [
'<MPD mediaPresentationDuration="PT30S">',
' <Period>',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="1">',
' <SegmentBase indexRange="100-200" />',
' </Representation>',
' </AdaptationSet>',
' <AdaptationSet mimeType="text/vtt" lang="de">',
' <Representation>',
' <BaseURL>http://example.com/de.vtt</BaseURL>',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream = manifest.textStreams[0];
await stream.createSegmentIndex();
goog.asserts.assert(stream.segmentIndex != null, 'Null segmentIndex!');
const ref = Array.from(stream.segmentIndex)[0];
expect(ref).toEqual(new shaka.media.SegmentReference(
/* startTime= */ 0,
/* endTime= */ 30,
/* getUris= */ () => ['http://example.com/de.vtt'],
/* startByte= */ 0,
/* endBytes= */ null,
/* initSegmentReference= */ null,
/* timestampOffset= */ 0,
/* appendWindowStart= */ 0,
/* appendWindowEnd= */ 30));
});
it('correctly parses mixed captions with channels, services, and languages',
async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4" lang="en" group="1">',
' <Accessibility schemeIdUri="urn:scte:dash:cc:cea-608:2015"',
' value="CC1=eng;CC3=swe"/>',
' <Representation bandwidth="200">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' <AdaptationSet mimeType="video/mp4" lang="ru" group="1">',
' <Accessibility schemeIdUri="urn:scte:dash:cc:cea-708:2015"',
' value="1=lang:bos;3=lang:cze,war:1,er:1"/>',
' <Representation bandwidth="200">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream1 = manifest.variants[0].video;
const stream2 = manifest.variants[1].video;
const expectedClosedCaptions1 = new Map([
['CC1', shaka.util.LanguageUtils.normalize('eng')],
['CC3', shaka.util.LanguageUtils.normalize('swe')],
]);
const expectedClosedCaptions2 = new Map([
['svc1', shaka.util.LanguageUtils.normalize('bos')],
['svc3', shaka.util.LanguageUtils.normalize('cze')],
]);
expect(stream1.closedCaptions).toEqual(expectedClosedCaptions1);
expect(stream2.closedCaptions).toEqual(expectedClosedCaptions2);
});
it('correctly parses CEA-708 caption tags with service numbers and languages',
async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4" lang="en" group="1">',
' <Accessibility schemeIdUri="urn:scte:dash:cc:cea-708:2015"',
' value="1=lang:eng;3=lang:swe,er"/>',
' <Representation bandwidth="200">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].video;
const expectedClosedCaptions = new Map([
['svc1', shaka.util.LanguageUtils.normalize('eng')],
['svc3', shaka.util.LanguageUtils.normalize('swe')],
]);
expect(stream.closedCaptions).toEqual(expectedClosedCaptions);
});
it('correctly parses CEA-708 caption tags without service #s and languages',
async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4" lang="en" group="1">',
' <Accessibility schemeIdUri="urn:scte:dash:cc:cea-708:2015"',
' value="eng;swe"/>',
' <Representation bandwidth="200">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].video;
const expectedClosedCaptions = new Map([
['svc1', shaka.util.LanguageUtils.normalize('eng')],
['svc2', shaka.util.LanguageUtils.normalize('swe')],
]);
expect(stream.closedCaptions).toEqual(expectedClosedCaptions);
});
it('Detects spatial audio', async () => {
const idUri = 'tag:dolby.com,2018:dash:EC3_ExtensionType:2018';
const source = [
'<MPD>',
' <Period duration="PT30M">',
' <AdaptationSet mimeType="audio/mp4" lang="\u2603">',
' <Representation bandwidth="500">',
' <SupplementalProperty schemeIdUri="' + idUri + '" value="JOC"/>',
' <BaseURL>http://example.com</BaseURL>',
' <SegmentTemplate media="2.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].audio;
expect(stream.spatialAudio).toBe(true);
});
it('correctly parses CEA-608 closed caption tags without channel numbers',
async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4" lang="en" group="1">',
' <Accessibility schemeIdUri="urn:scte:dash:cc:cea-608:2015"',
' value="eng;swe"/>',
' <Representation bandwidth="200">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' <AdaptationSet mimeType="video/mp4" lang="en" group="1">',
' <Accessibility schemeIdUri="urn:scte:dash:cc:cea-608:2015"',
' value="eng;swe;fre;pol"/>',
' <Representation bandwidth="200">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream1 = manifest.variants[0].video;
const stream2 = manifest.variants[1].video;
const expectedClosedCaptions1 = new Map([
['CC1', shaka.util.LanguageUtils.normalize('eng')],
['CC3', shaka.util.LanguageUtils.normalize('swe')],
]);
const expectedClosedCaptions2 = new Map([
['CC1', shaka.util.LanguageUtils.normalize('eng')],
['CC2', shaka.util.LanguageUtils.normalize('swe')],
['CC3', shaka.util.LanguageUtils.normalize('fre')],
['CC4', shaka.util.LanguageUtils.normalize('pol')],
]);
expect(stream1.closedCaptions).toEqual(expectedClosedCaptions1);
expect(stream2.closedCaptions).toEqual(expectedClosedCaptions2);
});
it('correctly parses CEA-608 caption tags with no channel and language info',
async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4" lang="en" group="1">',
' <Accessibility schemeIdUri="urn:scte:dash:cc:cea-608:2015"/>',
' <Representation bandwidth="200">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const stream = manifest.variants[0].video;
const expectedClosedCaptions = new Map([['CC1', 'und']]);
expect(stream.closedCaptions).toEqual(expectedClosedCaptions);
});
it('correctly parses UTF-8', async () => {
const source = [
'<MPD>',
' <Period duration="PT30M">',
' <AdaptationSet mimeType="audio/mp4" lang="\u2603">',
' <Representation bandwidth="500">',
' <BaseURL>http://example.com</BaseURL>',
' <SegmentTemplate media="2.mp4" duration="1"',
' initialization="\u0227.mp4" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
const variant = manifest.variants[0];
const stream = variant.audio;
await stream.createSegmentIndex();
goog.asserts.assert(stream.segmentIndex != null, 'Null segmentIndex!');
const segment = Array.from(stream.segmentIndex)[0];
expect(segment.initSegmentReference.getUris()[0])
.toBe('http://example.com/%C8%A7.mp4');
expect(variant.language).toBe('\u2603');
});
describe('UTCTiming', () => {
const originalNow = Date.now;
const dateRequestType = shaka.net.NetworkingEngine.RequestType.TIMING;
beforeAll(() => {
Date.now = () => 10 * 1000;
});
beforeEach(() => {
const config = shaka.util.PlayerConfiguration.createDefault().manifest;
config.dash.autoCorrectDrift = false;
parser.configure(config);
});
afterAll(() => {
Date.now = originalNow;
});
/**
* @param {!Array.<string>} lines
* @return {string}
*/
function makeManifest(lines) {
const template = [
'<MPD type="dynamic"',
' availabilityStartTime="1970-01-01T00:00:00Z"',
' timeShiftBufferDepth="PT60S"',
' maxSegmentDuration="PT5S"',
' suggestedPresentationDelay="PT0S">',
' %s',
' <Period>',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="500">',
' <BaseURL>http://example.com</BaseURL>',
' <SegmentList>',
' <SegmentURL media="s1.mp4" />',
' <SegmentTimeline>',
' <S d="5" t="0" />',
' </SegmentTimeline>',
' </SegmentList>',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
return sprintf(template, lines.join('\n'));
}
/**
* @param {number} expectedTime
* @return {!Promise}
*/
async function runTest(expectedTime) {
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start(
'http://foo.bar/manifest', playerInterface);
expect(manifest.presentationTimeline).toBeTruthy();
expect(manifest.presentationTimeline.getSegmentAvailabilityEnd())
.toBe(expectedTime);
}
it('with direct', async () => {
const source = makeManifest([
'<UTCTiming schemeIdUri="urn:mpeg:dash:utc:direct:2014"',
' value="1970-01-01T00:00:30Z" />',
]);
fakeNetEngine.setResponseText('http://foo.bar/manifest', source);
await runTest(25);
});
it('does not produce errors', async () => {
const source = makeManifest([
'<UTCTiming schemeIdUri="unknown scheme" value="foobar" />',
]);
fakeNetEngine.setResponseText('http://foo.bar/manifest', source);
await runTest(5);
});
it('tries multiple sources', async () => {
const source = makeManifest([
'<UTCTiming schemeIdUri="unknown scheme" value="foobar" />',
'<UTCTiming schemeIdUri="urn:mpeg:dash:utc:direct:2014"',
' value="1970-01-01T00:00:55Z" />',
]);
fakeNetEngine.setResponseText('http://foo.bar/manifest', source);
await runTest(50);
});
it('with HEAD', async () => {
const source = makeManifest([
'<UTCTiming schemeIdUri="urn:mpeg:dash:utc:http-head:2014"',
' value="http://foo.bar/date" />',
]);
fakeNetEngine.request.and.callFake((type, request) => {
if (request.uris[0] == 'http://foo.bar/manifest') {
const data = shaka.util.StringUtils.toUTF8(source);
return shaka.util.AbortableOperation.completed({
data: data,
headers: {},
uri: '',
});
} else {
expect(request.uris[0]).toBe('http://foo.bar/date');
return shaka.util.AbortableOperation.completed({
data: new ArrayBuffer(0),
headers: {'date': '1970-01-01T00:00:40Z'},
uri: '',
});
}
});
await runTest(35);
fakeNetEngine.expectRequest('http://foo.bar/date', dateRequestType);
});
it('with xsdate', async () => {
const source = makeManifest([
'<UTCTiming schemeIdUri="urn:mpeg:dash:utc:http-xsdate:2014"',
' value="http://foo.bar/date" />',
]);
fakeNetEngine
.setResponseText('http://foo.bar/manifest', source)
.setResponseText('http://foo.bar/date', '1970-01-01T00:00:50Z');
await runTest(45);
fakeNetEngine.expectRequest('http://foo.bar/date', dateRequestType);
});
it('with relative paths', async () => {
const source = makeManifest([
'<UTCTiming schemeIdUri="urn:mpeg:dash:utc:http-xsdate:2014"',
' value="/date" />',
]);
fakeNetEngine
.setResponseText('http://foo.bar/manifest', source)
.setResponseText('http://foo.bar/date', '1970-01-01T00:00:50Z');
await runTest(45);
fakeNetEngine.expectRequest('http://foo.bar/date', dateRequestType);
});
it('with paths relative to BaseURLs', async () => {
const source = makeManifest([
'<BaseURL>http://example.com</BaseURL>',
'<UTCTiming schemeIdUri="urn:mpeg:dash:utc:http-xsdate:2014"',
' value="/date" />',
]);
fakeNetEngine
.setResponseText('http://foo.bar/manifest', source)
.setResponseText('http://example.com/date', '1970-01-01T00:00:50Z');
await runTest(45);
fakeNetEngine.expectRequest('http://example.com/date', dateRequestType);
});
it('ignored with autoCorrectDrift', async () => {
const config = shaka.util.PlayerConfiguration.createDefault().manifest;
config.dash.autoCorrectDrift = true;
parser.configure(config);
const source = makeManifest([
'<UTCTiming schemeIdUri="urn:mpeg:dash:utc:http-xsdate:2014"',
' value="http://foo.bar/date" />',
]);
fakeNetEngine
.setResponseText('http://foo.bar/manifest', source)
.setResponseText('http://foo.bar/date', '1970-01-01T00:00:50Z');
// Expect the presentation timeline to end at 5 based on the segments
// instead of 45 based on the UTCTiming element.
await runTest(5);
});
});
it('handles missing Segment* elements', async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4" lang="en" group="1">',
' <Representation bandwidth="100" />',
' <Representation bandwidth="200">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
// First Representation should be dropped.
expect(manifest.variants.length).toBe(1);
expect(manifest.variants[0].bandwidth).toBe(200);
});
describe('allows missing Segment* elements for text', () => {
it('specified via AdaptationSet@contentType', async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="1">',
' <SegmentBase indexRange="100-200" />',
' </Representation>',
' </AdaptationSet>',
' <AdaptationSet contentType="text" lang="en" group="1">',
' <Representation />',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
expect(manifest.textStreams.length).toBe(1);
});
it('specified via AdaptationSet@mimeType', async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="1">',
' <SegmentBase indexRange="100-200" />',
' </Representation>',
' </AdaptationSet>',
' <AdaptationSet mimeType="text/vtt" lang="en" group="1">',
' <Representation />',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
expect(manifest.textStreams.length).toBe(1);
});
it('specified via Representation@mimeType', async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="1">',
' <SegmentBase indexRange="100-200" />',
' </Representation>',
' </AdaptationSet>',
' <AdaptationSet>',
' <Representation mimeType="text/vtt" />',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', source);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
expect(manifest.textStreams.length).toBe(1);
});
});
describe('fails for', () => {
it('invalid XML', async () => {
const source = '<not XML';
const error = new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.DASH_INVALID_XML,
'dummy://foo');
await Dash.testFails(source, error);
});
it('XML with inner errors', async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="1">',
' <SegmentBase indexRange="100-200" />',
' </Representation', // Missing a close bracket.
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
const error = new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.DASH_INVALID_XML,
'dummy://foo');
await Dash.testFails(source, error);
});
it('xlink problems when xlinkFailGracefully is false', async () => {
const source = [
'<MPD minBufferTime="PT75S" xmlns="urn:mpeg:dash:schema:mpd:2011" ' +
'xmlns:xlink="http://www.w3.org/1999/xlink">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="1" xlink:href="https://xlink1" ' +
'xlink:actuate="onInvalid">', // Incorrect actuate
' <SegmentBase indexRange="100-200" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
const error = new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.DASH_UNSUPPORTED_XLINK_ACTUATE);
await Dash.testFails(source, error);
});
it('failed network requests', async () => {
const expectedError = new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.BAD_HTTP_STATUS);
fakeNetEngine.request.and.returnValue(
shaka.util.AbortableOperation.failed(expectedError));
await expectAsync(parser.start('', playerInterface))
.toBeRejectedWith(shaka.test.Util.jasmineError(expectedError));
});
it('missing MPD element', async () => {
const source = '<XML></XML>';
const error = new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.DASH_INVALID_XML,
'dummy://foo');
await Dash.testFails(source, error);
});
it('empty AdaptationSet', async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4" lang="en" group="1" />',
' </Period>',
'</MPD>',
].join('\n');
const error = new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.DASH_EMPTY_ADAPTATION_SET);
await Dash.testFails(source, error);
});
it('empty Period', async () => {
const source = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S" />',
'</MPD>',
].join('\n');
const error = new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.DASH_EMPTY_PERIOD);
await Dash.testFails(source, error);
});
it('duplicate Representation ids with live', async () => {
const source = [
'<MPD minBufferTime="PT75S" type="dynamic"',
' availabilityStartTime="1970-01-01T00:00:00Z">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet mimeType="video/mp4">',
' <Representation id="1" bandwidth="1">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' <AdaptationSet mimeType="video/mp4">',
' <Representation id="1" bandwidth="1">',
' <SegmentTemplate media="2.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
const error = new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.DASH_DUPLICATE_REPRESENTATION_ID);
await Dash.testFails(source, error);
});
});
it('parses trickmode tracks', async () => {
const manifestText = [
'<MPD minBufferTime="PT75S">',
' <Period id="1" duration="PT30S">',
' <AdaptationSet id="1" mimeType="video/mp4">',
' <Representation bandwidth="1" codecs="avc1.4d401f">',
' <SegmentTemplate media="1.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' <AdaptationSet id="2" mimeType="video/mp4">',
' <EssentialProperty value="1" ',
' schemeIdUri="http://dashif.org/guidelines/trickmode" />',
' <Representation bandwidth="1" codecs="avc1.4d401f">',
' <SegmentTemplate media="2.mp4" duration="1" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');
fakeNetEngine.setResponseText('dummy://foo', manifestText);
/** @type {shaka.extern.Manifest} */
const manifest = await parser.start('dummy://foo', playerInterface);
expect(manifest.variants.length).toBe(1);
expect(manifest.textStreams.length).toBe(0);
const variant = manifest.variants[0];
const trickModeVideo = variant && variant.video &&