forked from Dash-Industry-Forum/dash.js
/
dash.models.DashManifestModel.js
1006 lines (769 loc) · 48.1 KB
/
dash.models.DashManifestModel.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
import DashManifestModel from '../../src/dash/models/DashManifestModel';
import DashConstants from '../../src/dash/constants/DashConstants';
import Constants from '../../src/streaming/constants/Constants';
import BaseURL from '../../src/dash/vo/BaseURL';
import MpdHelper from './helpers/MPDHelper';
import VoHelper from './helpers/VOHelper';
import ErrorHandlerMock from './mocks/ErrorHandlerMock';
const expect = require('chai').expect;
const context = {};
const errorHandlerMock = new ErrorHandlerMock();
const dashManifestModel = DashManifestModel(context).getInstance();
const TEST_URL = 'http://www.example.com/';
const RELATIVE_TEST_URL = './';
const SERVICE_LOCATION = 'testServiceLocation';
const EMPTY_STRING = '';
const mpd_sample = {
'manifest': {
'Period': [
{
'id': '153199'
},
{
'id': '153202'
}
],
'Period_asArray': [
{
'id': '153199'
},
{
'id': '153202'
}
],
'type': 'static'
},
'maxSegmentDuration': 4.5,
'mediaPresentationDuration': 300.0
};
describe('DashManifestModel', function () {
describe('SetConfig not previously called', function () {
it('should throw an exception when attempting to call getEndTimeForLastPeriod while setConfig has not been called', function () {
expect(dashManifestModel.getRegularPeriods.bind(dashManifestModel, mpd_sample)).to.throw(Constants.MISSING_CONFIG_ERROR);
});
});
describe('SetConfig previously called', function () {
beforeEach(function () {
dashManifestModel.setConfig({
errHandler: errorHandlerMock
});
});
const mpdHelper = new MpdHelper();
const voHelper = new VoHelper();
it('should throw an exception when attempting to call getIsTypeOf with undefined parameters', function () {
expect(dashManifestModel.getIsTypeOf.bind(dashManifestModel)).to.throw('adaptation is not defined');
const adaptation = mpdHelper.composeAdaptation('video');
expect(dashManifestModel.getIsTypeOf.bind(dashManifestModel, adaptation)).to.throw('type is not defined');
expect(dashManifestModel.getIsTypeOf.bind(dashManifestModel, adaptation, EMPTY_STRING)).to.throw('type is not defined');
});
it('should return null when getSuggestedPresentationDelay is called and mpd is undefined', () => {
const suggestedPresentationDelay = dashManifestModel.getSuggestedPresentationDelay();
expect(suggestedPresentationDelay).to.be.null; // jshint ignore:line
});
it('should return null when getSuggestedPresentationDelay is called and mpd is an empty object', () => {
const suggestedPresentationDelay = dashManifestModel.getSuggestedPresentationDelay({});
expect(suggestedPresentationDelay).to.be.null; // jshint ignore:line
});
it('should return 5 when getSuggestedPresentationDelay is called and mpd is an object with suggestedPresentationDelay attribute', () => {
const suggestedPresentationDelay = dashManifestModel.getSuggestedPresentationDelay({suggestedPresentationDelay: 5});
expect(suggestedPresentationDelay).to.be.equal(5); // jshint ignore:line
});
it('should return null when getAvailabilityStartTime is called and mpd is undefined', () => {
const availabilityStartTime = dashManifestModel.getAvailabilityStartTime();
expect(availabilityStartTime).to.be.null; // jshint ignore:line
});
it('should return null when getAvailabilityStartTime is called and mpd is an empty object', () => {
const availabilityStartTime = dashManifestModel.getAvailabilityStartTime({});
expect(availabilityStartTime).to.be.null; // jshint ignore:line
});
it('should return correct value when getAvailabilityStartTime is called and mpd is object with the availabilityStartTime attribute', () => {
const now = new Date();
const availabilityStartTime = dashManifestModel.getAvailabilityStartTime({availabilityStartTime: now});
expect(availabilityStartTime).to.be.equal(now.getTime()); // jshint ignore:line
});
it('should return false when getUseCalculatedLiveEdgeTimeForAdaptation is called and adaptation is undefined', () => {
const useCalculatedLiveEdge = dashManifestModel.getUseCalculatedLiveEdgeTimeForAdaptation();
expect(useCalculatedLiveEdge).to.be.false; // jshint ignore:line
});
it('should return false when getUseCalculatedLiveEdgeTimeForAdaptation is called and voAdaptation is defined, but without reference to real adaptation', () => {
const voAdaptation = {period: {index: 0, mpd: {manifest: {Period_asArray: [{AdaptationSet_asArray: [{}]}]}}}, index: 0, type: 'video'};
const useCalculatedLiveEdge = dashManifestModel.getUseCalculatedLiveEdgeTimeForAdaptation(voAdaptation);
expect(useCalculatedLiveEdge).to.be.false; // jshint ignore:line
});
it('should return true when getUseCalculatedLiveEdgeTimeForAdaptation is called and voAdaptation is defined, with reference to real adaptation', () => {
const voAdaptation = {period: {index: 0, mpd: {manifest: {Period_asArray: [{AdaptationSet_asArray: [{Representation_asArray: [{SegmentTemplate: {SegmentTimeline: {S_asArray: [{r: 2}]}}}]}]}]}}}, index: 0, type: 'video'};
const useCalculatedLiveEdge = dashManifestModel.getUseCalculatedLiveEdgeTimeForAdaptation(voAdaptation);
expect(useCalculatedLiveEdge).to.be.true; // jshint ignore:line
});
it('should return false when getIsTextTrack is called and type is undefined', () => {
const isTextTrack = dashManifestModel.getIsTextTrack();
expect(isTextTrack).to.be.false; // jshint ignore:line
});
it('should return empty string when getLanguageForAdaptation is called and adaptation is undefined', () => {
const language = dashManifestModel.getLanguageForAdaptation();
expect(language).to.equal(EMPTY_STRING); // jshint ignore:line
});
it('should return null when getViewpointForAdaptation is called and adaptation is undefined', () => {
const viewPoint = dashManifestModel.getViewpointForAdaptation();
expect(viewPoint).to.be.null; // jshint ignore:line
});
it('should return an empty array when getAudioChannelConfigurationForAdaptation is called and adaptation is undefined', () => {
const AudioChannelConfigurationArray = dashManifestModel.getAudioChannelConfigurationForAdaptation();
expect(AudioChannelConfigurationArray).to.be.instanceOf(Array); // jshint ignore:line
expect(AudioChannelConfigurationArray).to.be.empty; // jshint ignore:line
});
it('should return an empty array when getAccessibilityForAdaptation is called and adaptation is undefined', () => {
const accessibilityArray = dashManifestModel.getAccessibilityForAdaptation();
expect(accessibilityArray).to.be.instanceOf(Array); // jshint ignore:line
expect(accessibilityArray).to.be.empty; // jshint ignore:line
});
it('should return an empty array when getRolesForAdaptation is called and adaptation is undefined', () => {
const rolesArray = dashManifestModel.getRolesForAdaptation();
expect(rolesArray).to.be.instanceOf(Array); // jshint ignore:line
expect(rolesArray).to.be.empty; // jshint ignore:line
});
it('should return null when getAdaptationForId is called and id, manifest and periodIndex are undefined', () => {
const adaptation = dashManifestModel.getAdaptationForId(undefined, undefined, undefined);
expect(adaptation).to.be.null; // jshint ignore:line
});
it('should return null when getAdaptationForId is called and id and periodIndex are undefined', () => {
const manifest = { Period_asArray: [] };
const adaptation = dashManifestModel.getAdaptationForId(undefined, manifest, undefined);
expect(adaptation).to.be.null; // jshint ignore:line
});
it('should return null when getAdaptationForId is called and id is undefined', () => {
const manifest = { Period_asArray: [] };
const adaptation = dashManifestModel.getAdaptationForId(undefined, manifest, 2);
expect(adaptation).to.be.null; // jshint ignore:line
});
it('should return null when getAdaptationForId is called and id is undefined and periodIndex = 0', () => {
const manifest = { Period_asArray: [{ AdaptationSet_asArray: [{ id: 0 }] }] };
const adaptation = dashManifestModel.getAdaptationForId(undefined, manifest, 0);
expect(adaptation).to.be.null; // jshint ignore:line
});
it('should return valid value when getAdaptationForId is called and id is 0 and periodIndex = 0', () => {
const manifest = { Period_asArray: [{ AdaptationSet_asArray: [{ id: 0 }] }] };
const adaptation = dashManifestModel.getAdaptationForId(0, manifest, 0);
expect(adaptation.id).to.equal(0); // jshint ignore:line
});
it('should return null when getAdaptationForIndex is called and index, manifest and periodIndex are undefined', () => {
const adaptation = dashManifestModel.getAdaptationForIndex(undefined, undefined, undefined);
expect(adaptation).to.be.null; // jshint ignore:line
});
it('should return null when getAdaptationForIndex is called and id and periodIndex are undefined', () => {
const manifest = { Period_asArray: [] };
const adaptation = dashManifestModel.getAdaptationForIndex(undefined, manifest, undefined);
expect(adaptation).to.be.null; // jshint ignore:line
});
it('should return null when getAdaptationForIndex is called and id is undefined', () => {
const manifest = { Period_asArray: [] };
const adaptation = dashManifestModel.getAdaptationForIndex(undefined, manifest, 2);
expect(adaptation).to.be.null; // jshint ignore:line
});
it('should return null when getAdaptationForIndex is called and id is undefined and periodIndex = 0', () => {
const manifest = { Period_asArray: [{ AdaptationSet_asArray: [{ id: 0 }] }] };
const adaptation = dashManifestModel.getAdaptationForIndex(undefined, manifest, 0);
expect(adaptation).to.be.null; // jshint ignore:line
});
it('should return valid value when getAdaptationForIndex is called and id is 0 and periodIndex = 0', () => {
const manifest = { Period_asArray: [{ AdaptationSet_asArray: [{ id: 0 }] }] };
const adaptation = dashManifestModel.getAdaptationForIndex(0, manifest, 0);
expect(adaptation.id).to.equal(0); // jshint ignore:line
});
it('should return -1 when getIndexForAdaptation is called and adaptation, manifest and periodIndex are undefined', () => {
const index = dashManifestModel.getIndexForAdaptation(undefined, undefined, undefined);
expect(index).to.equal(-1); // jshint ignore:line
});
it('should return -1 when getIndexForAdaptation is called and manifest and periodIndex are undefined', () => {
const manifest = { Period_asArray: [] };
var adaptation = mpdHelper.composeAdaptation('video');
const index = dashManifestModel.getIndexForAdaptation(adaptation, manifest, undefined);
expect(index).to.equal(-1); // jshint ignore:line
});
it('should return -1 when getIndexForAdaptation is called and periodIndex are undefined', () => {
var adaptation = mpdHelper.composeAdaptation('video');
const index = dashManifestModel.getIndexForAdaptation(adaptation, undefined, undefined);
expect(index).to.equal(-1); // jshint ignore:line
});
it('should return an empty array when getAdaptationsForType is called and manifest, periodIndex and type are undefined', () => {
const adaptationsArray = dashManifestModel.getAdaptationsForType();
expect(adaptationsArray).to.be.instanceOf(Array); // jshint ignore:line
expect(adaptationsArray).to.be.empty; // jshint ignore:line
});
it('should return an empty array when getAdaptationsForType is called and periodIndex and type are undefined', () => {
const manifest = { Period_asArray: [] };
const adaptationsArray = dashManifestModel.getAdaptationsForType(manifest, undefined, undefined);
expect(adaptationsArray).to.be.instanceOf(Array); // jshint ignore:line
expect(adaptationsArray).to.be.empty; // jshint ignore:line
});
it('should return an empty array when getAdaptationsForType is called and type is undefined', () => {
const manifest = { Period_asArray: [{ AdaptationSet_asArray: [{ id: 0 }] }] };
expect(dashManifestModel.getAdaptationsForType.bind(dashManifestModel, manifest, 0, undefined)).to.throw('type is not defined');
});
it('should return null when getCodec is called and adaptation is undefined', () => {
const codec = dashManifestModel.getCodec();
expect(codec).to.be.null; // jshint ignore:line
});
it('should return null when getCodec is called and adaptation.Representation_asArray is undefined', () => {
const codec = dashManifestModel.getCodec({});
expect(codec).to.be.null; // jshint ignore:line
});
it('should return null when getCodec is called and adaptation.Representation_asArray.length is -1', () => {
const codec = dashManifestModel.getCodec({ Representation_asArray: { length: -1 } });
expect(codec).to.be.null; // jshint ignore:line
});
it('should return null when getCodec is called and representationId is not an integer', () => {
const codec = dashManifestModel.getCodec({ Representation_asArray: { length: 1 } }, true);
expect(codec).to.be.null; // jshint ignore:line
});
it('should return correct codec when getCodec is called and representationId is an integer and addResolutionInfo is true', () => {
const codec = dashManifestModel.getCodec({ Representation_asArray: [{mimeType: 'video/mp4', codecs: 'avc1.4D400D', width: 1080, height: 960}] }, 0, true);
expect(codec).to.be.equal('video/mp4;codecs="avc1.4D400D";width="1080";height="960"'); // jshint ignore:line
});
it('should return correct codec when getCodec is called and representationId is an integer and addResolutionInfo is false', () => {
const codec = dashManifestModel.getCodec({ Representation_asArray: [{mimeType: 'video/mp4', codecs: 'avc1.4D400D', width: 1080, height: 960}] }, 0, false);
expect(codec).to.be.equal('video/mp4;codecs="avc1.4D400D"'); // jshint ignore:line
});
it('should return correct codec without a correct mime type profile when getCodec is called and representationId is an integer and addResolutionInfo is false', () => {
const codec = dashManifestModel.getCodec({ Representation_asArray: [{mimeType: 'video/mp4 profiles="cmfc,cfhd"', codecs: 'avc1.4D400D', width: 1080, height: 960}] }, 0, false);
expect(codec).to.be.equal('video/mp4;codecs="avc1.4D400D"'); // jshint ignore:line
});
it('should return correct codec without an invalid mime type profile when getCodec is called and representationId is an integer and addResolutionInfo is false', () => {
const codec = dashManifestModel.getCodec({ Representation_asArray: [{mimeType: 'video/mp4 profiles="cmfc,cf', codecs: 'avc1.4D400D', width: 1080, height: 960}] }, 0, false);
expect(codec).to.be.equal('video/mp4;codecs="avc1.4D400D"'); // jshint ignore:line
});
it('should return null when getMimeType is called and adaptation is undefined', () => {
const mimeType = dashManifestModel.getMimeType();
expect(mimeType).to.be.null; // jshint ignore:line
});
it('should return null when getMimeType is called and adaptation.Representation_asArray is undefined', () => {
const mimeType = dashManifestModel.getMimeType({});
expect(mimeType).to.be.null; // jshint ignore:line
});
it('should return null when getMimeType is called and adaptation.Representation_asArray.length is -1', () => {
const mimeType = dashManifestModel.getMimeType({ Representation_asArray: { length: -1 } });
expect(mimeType).to.be.null; // jshint ignore:line
});
it('should return null when getKID is called and adaptation is undefined', () => {
const kid = dashManifestModel.getKID();
expect(kid).to.be.null; // jshint ignore:line
});
it('should return kid value when getKID is called and adaptation is well defined', () => {
const kid = dashManifestModel.getKID({'cenc:default_KID': 'testKid'});
expect(kid).to.equal('testKid'); // jshint ignore:line
});
it('should return empty array when getLabelsForAdaptation is called and adaptation is undefined', () => {
const labels = dashManifestModel.getLabelsForAdaptation();
expect(labels).to.be.instanceOf(Array); // jshint ignore:line
expect(labels).to.be.empty; // jshint ignore:line
});
it('should return empty array when getLabelsForAdaptation is called and adaptation is not well defined', () => {
const labels = dashManifestModel.getLabelsForAdaptation({});
expect(labels).to.be.instanceOf(Array); // jshint ignore:line
expect(labels).to.be.empty; // jshint ignore:line
});
it('should return empty array when getLabelsForAdaptation is called and adaptation is not well defined', () => {
const labels = dashManifestModel.getLabelsForAdaptation({Label_asArray: true});
expect(labels).to.be.instanceOf(Array); // jshint ignore:line
expect(labels).to.be.empty; // jshint ignore:line
});
it('should return empty array when getLabelsForAdaptation is called and adaptation is well defined with an empty Label_asArray', () => {
const labels = dashManifestModel.getLabelsForAdaptation({Label_asArray: []});
expect(labels).to.be.instanceOf(Array); // jshint ignore:line
expect(labels).to.be.empty; // jshint ignore:line
});
it('should return correct array when getLabelsForAdaptation is called and adaptation is well defined', () => {
const labels = dashManifestModel.getLabelsForAdaptation({Label_asArray: [{lang: 'fre', __text: 'french'}, {lang: 'eng', __text: 'english'}]});
expect(labels).to.be.instanceOf(Array); // jshint ignore:line
expect(labels.length).to.equal(2); // jshint ignore:line
expect(labels[0].lang).to.equal('fre'); // jshint ignore:line
});
it('should return null when getContentProtectionData is called and adaptation is undefined', () => {
const contentProtection = dashManifestModel.getContentProtectionData();
expect(contentProtection).to.be.null; // jshint ignore:line
});
it('should return null when getContentProtectionData is called and adaptation is defined, but ContentProtection_asArray is an empty array', () => {
const adaptation = {ContentProtection_asArray: []};
const contentProtection = dashManifestModel.getContentProtectionData(adaptation);
expect(contentProtection).to.be.null; // jshint ignore:line
});
it('should return false when getIsDynamic is called and manifest is undefined', () => {
const isDynamic = dashManifestModel.getIsDynamic();
expect(isDynamic).to.be.false; // jshint ignore:line
});
it('should return Number.MAX_SAFE_NUMBER (or Number.MAX_VALUE in case MAX_SAFE_NUMBER is not defined) when getDuration is called and manifest is undefined', () => {
const duration = dashManifestModel.getDuration();
expect(duration).to.equal(Number.MAX_SAFE_INTEGER || Number.MAX_VALUE); // jshint ignore:line
});
it('should return duration when getDuration is called and manifest has a defined mediaPresentationDuration', () => {
const duration = dashManifestModel.getDuration({mediaPresentationDuration: 50});
expect(duration).to.equal(50); // jshint ignore:line
});
it('should return infinity when getDuration is called and manifest is a dynamic one', () => {
const duration = dashManifestModel.getDuration({type: DashConstants.DYNAMIC});
expect(duration).to.equal(Infinity); // jshint ignore:line
});
it('should return 0 when getRepresentationCount is called and adaptation is undefined', () => {
const representationCount = dashManifestModel.getRepresentationCount();
expect(representationCount).to.equal(0); // jshint ignore:line
});
it('should return NaN when getBandwidth is called and representation is undefined', () => {
const bdtw = dashManifestModel.getBandwidth();
expect(bdtw).to.be.NaN; // jshint ignore:line
});
it('should return correct value when getBandwidth is called and representation is defined', () => {
const bdtw = dashManifestModel.getBandwidth({bandwidth: 9600});
expect(bdtw).to.equal(9600); // jshint ignore:line
});
it('should return empty array when getBitrateListForAdaptation is called and adaptation is undefined', () => {
const bitrateList = dashManifestModel.getBitrateListForAdaptation();
expect(bitrateList).to.be.instanceOf(Array); // jshint ignore:line
expect(bitrateList).to.be.empty; // jshint ignore:line
});
it('should not return empty array when getBitrateListForAdaptation is called and adaptation is defined', () => {
const realAdaptation = {Representation_asArray: [{}]};
const bitrateList = dashManifestModel.getBitrateListForAdaptation(realAdaptation);
expect(bitrateList).to.be.instanceOf(Array); // jshint ignore:line
expect(bitrateList).not.to.be.empty; // jshint ignore:line
});
it('should return null when getRepresentationFor is called and index and adaptation are undefined', () => {
const representation = dashManifestModel.getRepresentationFor();
expect(representation).to.be.null; // jshint ignore:line
});
it('should return null when getRepresentationFor is called and index and andadaptation.Representation_asArray are undefined', () => {
const adaptation = {};
const representation = dashManifestModel.getRepresentationFor(undefined, adaptation);
expect(representation).to.be.null; // jshint ignore:line
});
it('should return null when getRepresentationFor is called and index is undefined', () => {
var adaptation = mpdHelper.composeAdaptation('video');
const representation = dashManifestModel.getRepresentationFor(undefined, adaptation);
expect(representation).to.be.null; // jshint ignore:line
});
it('should return representation.id = video20 when getRepresentationFor is called', () => {
var adaptation = mpdHelper.composeAdaptation('video');
const representation = dashManifestModel.getRepresentationFor(0, adaptation);
expect(representation.id).equal('video20'); // jshint ignore:line
});
it('should return undefined when getLocation is called and manifest is undefined', () => {
const location = dashManifestModel.getLocation();
expect(location).to.be.undefined; // jshint ignore:line
});
it('should return undefined when getLocation is called and manifest is an empty object', () => {
const location = dashManifestModel.getLocation({});
expect(location).to.be.undefined; // jshint ignore:line
});
it('should return valid location when getLocation is called and manifest is a valid object', () => {
const location = dashManifestModel.getLocation({Location: '', Location_asArray: ['location_1']});
expect(location).to.be.equal('location_1'); // jshint ignore:line
});
it('should return an empty Array when getUTCTimingSources is called and manifest is undefined', () => {
const utcSourceArray = dashManifestModel.getUTCTimingSources();
expect(utcSourceArray).to.be.instanceOf(Array); // jshint ignore:line
expect(utcSourceArray).to.be.empty; // jshint ignore:line
});
it('should return an empty Array when getEventStreamForRepresentation is called and manifest and representation are undefined', () => {
const eventsStream = dashManifestModel.getEventStreamForRepresentation();
expect(eventsStream).to.be.instanceOf(Array); // jshint ignore:line
expect(eventsStream).to.be.empty; // jshint ignore:line
});
it('should not return an empty Array when getEventStreamForRepresentation is called and manifest and representation are well defined', () => {
const manifest = {
Period: [
{
'id': '153199',
AdaptationSet: [{Representation: [{InbandEventStream: []}]}]
},
{
'id': '153202',
AdaptationSet: [{Representation: [{InbandEventStream: []}]}]
}
],
Period_asArray: [
{
'id': '153199',
AdaptationSet_asArray: [{Representation_asArray: [{InbandEventStream_asArray: []}]}]
},
{
'id': '153202',
AdaptationSet_asArray: [{Representation_asArray: [{InbandEventStream_asArray: []}]}]
}
],
'type': 'static'
};
const representation = {adaptation: {index: 0, period: {index: 0}}, index: 0};
const eventsStream = dashManifestModel.getEventStreamForRepresentation(manifest, representation);
expect(eventsStream).to.be.instanceOf(Array); // jshint ignore:line
expect(eventsStream).to.be.empty; // jshint ignore:line
});
it('should return an empty Array when getEventStreamForAdaptationSet is called and manifest and adaptation are undefined', () => {
const eventsStream = dashManifestModel.getEventStreamForAdaptationSet();
expect(eventsStream).to.be.instanceOf(Array); // jshint ignore:line
expect(eventsStream).to.be.empty; // jshint ignore:line
});
it('should return an empty Array when getEventsForPeriod is called and manifest and period are undefined', () => {
const eventsStream = dashManifestModel.getEventsForPeriod();
expect(eventsStream).to.be.instanceOf(Array); // jshint ignore:line
expect(eventsStream).to.be.empty; // jshint ignore:line
});
it('should return mpd.manifest = null when getMpd is called and manifest is undefined', () => {
const mpd = dashManifestModel.getMpd();
expect(mpd.manifest).to.be.null; // jshint ignore:line
});
it('should return mpd.manifest not null when getMpd is called and manifest is defined', () => {
const mpd = dashManifestModel.getMpd({});
expect(mpd.manifest).not.to.be.null; // jshint ignore:line
expect(mpd.manifest.availabilityStartTime).to.be.undefined; // jshint ignore:line
});
it('should return an error when getRegularPeriods and getEndTimeForLastPeriod are called and duration is undefined', () => {
dashManifestModel.getRegularPeriods(mpd_sample);
expect(errorHandlerMock.errorValue).to.equal('Must have @mediaPresentationDuration on MPD or an explicit @duration on the last period.');
});
it('should return an empty array when getRegularPeriods is called and mpd is undefined', () => {
const periodsArray = dashManifestModel.getRegularPeriods();
expect(periodsArray).to.be.instanceOf(Array); // jshint ignore:line
expect(periodsArray).to.be.empty; // jshint ignore:line
});
it('should return just the first period when type is static and neither start nor duration period attributes are provided', () => {
const mpd = {
'manifest': {
'Period': [
{
'id': '153199'
},
{
'id': '153202'
}
],
'Period_asArray': [
{
'id': '153199'
},
{
'id': '153202'
}
],
'type': 'static',
'mediaPresentationDuration': 300.0
},
'maxSegmentDuration': 4.5,
'mediaPresentationDuration': 300.0
};
const periodsArray = dashManifestModel.getRegularPeriods(mpd);
expect(periodsArray).to.be.instanceOf(Array); // jshint ignore:line
expect(periodsArray).to.have.lengthOf(1); // jshint ignore:line
expect(periodsArray[0].start).to.equals(0);
expect(periodsArray[0].duration).to.equals(300);
});
it('should calculate period start and duration properties of periods when duration properties are provided for all but the latest', () => {
const manifest = {
'manifest': {
'Period': [
{
'id': '153199',
'duration': 100
},
{
'id': '153200',
'duration': 50
},
{
'id': '153201'
}
],
'Period_asArray': [
{
'id': '153199',
'duration': 100
},
{
'id': '153200',
'duration': 50
},
{
'id': '153201'
}
],
'type': 'static',
'mediaPresentationDuration': 320.0
},
'maxSegmentDuration': 4.5,
'mediaPresentationDuration': 320.0
};
const periodsArray = dashManifestModel.getRegularPeriods(manifest);
expect(periodsArray).to.be.instanceOf(Array); // jshint ignore:line
expect(periodsArray).to.have.lengthOf(3); // jshint ignore:line
expect(periodsArray[0].start).to.equals(0);
expect(periodsArray[0].duration).to.equals(100);
expect(periodsArray[1].start).to.equals(100);
expect(periodsArray[1].duration).to.equals(50);
expect(periodsArray[2].start).to.equals(150);
expect(periodsArray[2].duration).to.equals(170);
});
it('should calculate period start and duration properties of periods when start properties are provided for all but the first', () => {
const manifest = {
'manifest': {
'Period': [
{
'id': '153199'
},
{
'id': '153200',
'start': 80
},
{
'id': '153201',
'start': 120
}
],
'Period_asArray': [
{
'id': '153199'
},
{
'id': '153200',
'start': 80
},
{
'id': '153201',
'start': 120
}
],
'type': 'static',
'mediaPresentationDuration': 300.0
},
'maxSegmentDuration': 4.5,
'mediaPresentationDuration': 300.0
};
const periodsArray = dashManifestModel.getRegularPeriods(manifest);
expect(periodsArray).to.be.instanceOf(Array); // jshint ignore:line
expect(periodsArray).to.have.lengthOf(3); // jshint ignore:line
expect(periodsArray[0].start).to.equals(0);
expect(periodsArray[0].duration).to.equals(80);
expect(periodsArray[1].start).to.equals(80);
expect(periodsArray[1].duration).to.equals(40);
expect(periodsArray[2].start).to.equals(120);
expect(periodsArray[2].duration).to.equals(180);
});
it('should return an empty array when getAdaptationsForPeriod is called and period is undefined', () => {
const adaptationArray = dashManifestModel.getAdaptationsForPeriod();
expect(adaptationArray).to.be.instanceOf(Array); // jshint ignore:line
expect(adaptationArray).to.be.empty; // jshint ignore:line
});
it('should not return an empty array when getAdaptationsForPeriod is called and period is defined', () => {
const period = voHelper.getDummyPeriod();
const adaptationArray = dashManifestModel.getAdaptationsForPeriod(period);
expect(adaptationArray).to.be.instanceOf(Array); // jshint ignore:line
expect(adaptationArray).not.to.be.empty; // jshint ignore:line
expect(adaptationArray[0].index).to.equals(0); // jshint ignore:line
});
it('should return an empty array when getRepresentationsForAdaptation is called and adaptation is undefined', () => {
const representationArray = dashManifestModel.getRepresentationsForAdaptation();
expect(representationArray).to.be.instanceOf(Array); // jshint ignore:line
expect(representationArray).to.be.empty; // jshint ignore:line
});
it('should not return an empty array when getRepresentationsForAdaptation is called and adaptation is defined', () => {
const voAdaptation = {period: {index: 0, mpd: {manifest: {Period_asArray: [{AdaptationSet_asArray: [{Representation_asArray: [{SegmentTemplate: {SegmentTimeline: {S_asArray: [{d: 2, r: 2}]}}}]}]}]}}}, index: 0, type: 'video'};
const representationArray = dashManifestModel.getRepresentationsForAdaptation(voAdaptation);
expect(representationArray).to.be.instanceOf(Array); // jshint ignore:line
expect(representationArray).not.to.be.empty; // jshint ignore:line
expect(representationArray[0].index).to.equals(0); // jshint ignore:line
});
it('should return false when hasProfile is called and manifest is undefined', () => {
const IsDVB = dashManifestModel.hasProfile();
expect(IsDVB).to.be.false; // jshint ignore:line
});
it('should return true when hasProfile is called and manifest contains a valid DVB profile', () => {
const manifest = {
profiles: 'urn:dvb:dash:profile:dvb-dash:2014,urn:dvb:dash:profile:dvb-dash:isoff-ext-live:2014'
};
const isDVB = dashManifestModel.hasProfile(manifest, 'urn:dvb:dash:profile:dvb-dash:2014');
expect(isDVB).to.be.true; // jshint ignore:line
});
it('should return false when hasProfile is called and manifest does not contain a valid DVB profile', () => {
const manifest = {
profiles: 'urn:mpeg:dash:profile:isoff-on-demand:2011, http://dashif.org/guildelines/dash264'
};
const isDVB = dashManifestModel.hasProfile(manifest, 'urn:dvb:dash:profile:dvb-dash:2014');
expect(isDVB).to.be.false; // jshint ignore:line
});
it('should return NaN when getManifestUpdatePeriod is called and manifest is undefined', () => {
const updatePeriod = dashManifestModel.getManifestUpdatePeriod();
expect(updatePeriod).to.be.NaN; // jshint ignore:line
});
it('should return NaN when minimumUpdatePeriod is not present in manifest', () => {
const manifest = {};
const updatePeriod = dashManifestModel.getManifestUpdatePeriod(manifest);
expect(updatePeriod).to.be.NaN; // jshint ignore:line
});
it('should return valid value when minimumUpdatePeriod is present in manifest and latencyOfLastUpdate is defined', () => {
const minimumUpdatePeriod = 30;
const latencyOfLastUpdate = 0.5;
const manifest = { minimumUpdatePeriod: minimumUpdatePeriod };
const expectedResult = minimumUpdatePeriod - latencyOfLastUpdate;
const updatePeriod = dashManifestModel.getManifestUpdatePeriod(manifest, latencyOfLastUpdate);
expect(updatePeriod).to.equal(expectedResult); // jshint ignore:line
});
it('should return valid value when minimumUpdatePeriod is present in manifest and latencyOfLastUpdate is not defined', () => {
const minimumUpdatePeriod = 30;
const manifest = { minimumUpdatePeriod: minimumUpdatePeriod };
const expectedResult = minimumUpdatePeriod;
const updatePeriod = dashManifestModel.getManifestUpdatePeriod(manifest);
expect(updatePeriod).to.equal(expectedResult); // jshint ignore:line
});
describe('getBaseUrlsFromElement', () => {
it('returns an empty Array when no BaseURLs or baseUri are present on a node', () => {
const node = {};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.be.empty; // jshint ignore:line
});
it('returns an Array of BaseURLs when no BaseURLs are present on a node, but there is a baseUri', () => {
const node = {
baseUri: TEST_URL
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(1); // jshint ignore:line
expect(obj[0]).to.be.instanceOf(BaseURL); // jshint ignore:line
expect(obj[0].url).to.equal(TEST_URL); // jshint ignore:line
});
it('returns an Array of BaseURLs with BaseURL[0] serviceLocation set to URL when no serviceLocation was specified', () => {
const node = {
BaseURL_asArray: [{
__text: TEST_URL
}]
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(1); // jshint ignore:line
expect(obj[0]).to.be.instanceOf(BaseURL); // jshint ignore:line
expect(obj[0].url).to.equal(TEST_URL); // jshint ignore:line
expect(obj[0].serviceLocation).to.equal(TEST_URL); // jshint ignore:line
});
it('returns an Array of BaseURLs with length 1 when multiple relative BaseUrls were specified', () => {
const node = {
BaseURL_asArray: [
{
__text: RELATIVE_TEST_URL + '0'
},
{
__text: RELATIVE_TEST_URL + '1'
}
]
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(1); // jshint ignore:line
expect(obj[0]).to.be.instanceOf(BaseURL); // jshint ignore:line
expect(obj[0].url).to.equal(RELATIVE_TEST_URL + '0'); // jshint ignore:line
});
it('returns an Array of BaseURLs when multiple BaseUrls were specified', () => {
const node = {
BaseURL_asArray: [
{
__text: TEST_URL + '0'
},
{
__text: TEST_URL + '1'
}
]
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(2); // jshint ignore:line
obj.forEach((o, i) => {
expect(o).to.be.instanceOf(BaseURL); // jshint ignore:line
expect(o.url).to.equal(TEST_URL + i); // jshint ignore:line
});
});
it('returns an Array of BaseURLs with BaseURL[0] serviceLocation set when serviceLocation was specified', () => {
const node = {
BaseURL_asArray: [{
__text: TEST_URL,
serviceLocation: SERVICE_LOCATION
}]
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(1); // jshint ignore:line
expect(obj[0]).to.be.instanceOf(BaseURL); // jshint ignore:line
expect(obj[0].url).to.equal(TEST_URL); // jshint ignore:line
expect(obj[0].serviceLocation).to.equal(SERVICE_LOCATION); // jshint ignore:line
});
it('returns an Array of BaseURLs with BaseURL[0] having correct defaults for DVB extensions when not specified', () => {
const node = {
BaseURL_asArray: [{
__text: TEST_URL
}]
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(1); // jshint ignore:line
expect(obj[0].dvb_priority).to.equal(BaseURL.DEFAULT_DVB_PRIORITY); // jshint ignore:line
expect(obj[0].dvb_weight).to.equal(BaseURL.DEFAULT_DVB_WEIGHT); // jshint ignore:line
});
it('returns an Array of BaseURLs with BaseURL[0] having correct priority and weight for DVB extensions when specified', () => {
const TEST_PRIORITY = 3;
const TEST_WEIGHT = 2;
const node = {
BaseURL_asArray: [{
__text: TEST_URL,
'dvb:priority': TEST_PRIORITY,
'dvb:weight': TEST_WEIGHT
}]
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(1); // jshint ignore:line
expect(obj[0].dvb_priority).to.equal(TEST_PRIORITY); // jshint ignore:line
expect(obj[0].dvb_weight).to.equal(TEST_WEIGHT); // jshint ignore:line
});
it('returns an Array of BaseURLs with BaseURL[0] resolved to the document base uri when the base uri is specified and the input url is relative', () => {
const node = {
baseUri: TEST_URL,
BaseURL_asArray: [{
__text: RELATIVE_TEST_URL
}]
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(1); // jshint ignore:line
expect(obj[0].url).to.equal(TEST_URL + RELATIVE_TEST_URL); // jshint ignore:line
});
it('returns an Array of BaseURLs with BaseURL[0] resolved to the document base uri when the base uri is the mpd and the input url is relative', () => {
const node = {
baseUri: TEST_URL + 'example.mpd',
BaseURL_asArray: [{
__text: RELATIVE_TEST_URL
}]
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(1); // jshint ignore:line
expect(obj[0].url).to.equal(TEST_URL + RELATIVE_TEST_URL); // jshint ignore:line
});
it('returns an Array of BaseURLs with BaseURL[0] ignoring the document base uri when the base uri is specified and the input url is absolute', () => {
const node = {
baseUri: TEST_URL,
BaseURL_asArray: [{
__text: TEST_URL
}]
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line
expect(obj).to.have.lengthOf(1); // jshint ignore:line
expect(obj[0].url).to.equal(TEST_URL); // jshint ignore:line
});
it('returns an Array of BaseURLs with BaseURL[0] resolved to the document base uri when the base uri is specified but no other urls', () => {
const node = {
baseUri: TEST_URL
};
const obj = dashManifestModel.getBaseURLsFromElement(node);
expect(obj).to.be.instanceOf(Array); // jshint ignore:line