html.test.js
61.8 KB
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
import document from 'global/document';
import window from 'global/window';
import QUnit from 'qunit';
import sinon from 'sinon';
import videojs from 'video.js';
import HtmlMediaSource from '../src/html-media-source';
import {
gopsSafeToAlignWith,
updateGopBuffer,
removeGopBuffer
} from '../src/virtual-source-buffer';
// we disable this because browserify needs to include these files
// but the exports are not important
/* eslint-disable no-unused-vars */
import {MediaSource, URL} from '../src/videojs-contrib-media-sources.js';
/* eslint-disable no-unused-vars */
QUnit.module('videojs-contrib-media-sources - HTML', {
beforeEach() {
this.fixture = document.getElementById('qunit-fixture');
this.video = document.createElement('video');
this.fixture.appendChild(this.video);
this.source = document.createElement('source');
this.player = videojs(this.video);
// add a fake source so that we can get this.player_ on sourceopen
this.url = 'fake.ts';
this.source.src = this.url;
this.video.appendChild(this.source);
// Mock the environment's timers because certain things - particularly
// player readiness - are asynchronous in video.js 5.
this.clock = sinon.useFakeTimers();
this.oldMediaSource = window.MediaSource || window.WebKitMediaSource;
window.MediaSource = videojs.extend(videojs.EventTarget, {
constructor() {
this.isNative = true;
this.sourceBuffers = [];
this.duration = NaN;
},
addSourceBuffer(type) {
let buffer = new (videojs.extend(videojs.EventTarget, {
type,
appendBuffer() {}
}))();
this.sourceBuffers.push(buffer);
return buffer;
}
});
window.MediaSource.isTypeSupported = function(mime) {
return true;
};
window.WebKitMediaSource = window.MediaSource;
},
afterEach() {
this.clock.restore();
this.player.dispose();
window.MediaSource = this.oldMediaSource;
window.WebKitMediaSource = window.MediaSource;
}
});
QUnit.test('constructs a native MediaSource', function() {
QUnit.ok(
new videojs.MediaSource().nativeMediaSource_.isNative,
'constructed a MediaSource'
);
});
const createDataMessage = function(type, typedArray, extraObject) {
let message = {
data: {
action: 'data',
segment: {
type,
data: typedArray.buffer,
initSegment: {
data: typedArray.buffer,
byteOffset: typedArray.byteOffset,
byteLength: typedArray.byteLength
}
},
byteOffset: typedArray.byteOffset,
byteLength: typedArray.byteLength
}
};
return Object.keys(extraObject || {}).reduce(function(obj, key) {
obj.data.segment[key] = extraObject[key];
return obj;
}, message);
};
// Create a WebWorker-style message that signals the transmuxer is done
const doneMessage = {
data: {
action: 'done'
}
};
// send fake data to the transmuxer to trigger the creation of the
// native source buffers
const initializeNativeSourceBuffers = function(sourceBuffer) {
// initialize an audio source buffer
sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', new Uint8Array(1)));
// initialize a video source buffer
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', new Uint8Array(1)));
// instruct the transmuxer to flush the "data" it has buffered so
// far
sourceBuffer.transmuxer_.onmessage(doneMessage);
};
QUnit.test('creates mp4 source buffers for mp2t segments', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
initializeNativeSourceBuffers(sourceBuffer);
QUnit.ok(mediaSource.videoBuffer_, 'created a video buffer');
QUnit.equal(
mediaSource.videoBuffer_.type,
'video/mp4;codecs="avc1.4d400d"',
'video buffer has the default codec'
);
QUnit.ok(mediaSource.audioBuffer_, 'created an audio buffer');
QUnit.equal(
mediaSource.audioBuffer_.type,
'audio/mp4;codecs="mp4a.40.2"',
'audio buffer has the default codec'
);
QUnit.equal(mediaSource.sourceBuffers.length, 1, 'created one virtual buffer');
QUnit.equal(
mediaSource.sourceBuffers[0],
sourceBuffer,
'returned the virtual buffer'
);
QUnit.ok(sourceBuffer.transmuxer_, 'created a transmuxer');
});
QUnit.test(
'the terminate is called on the transmuxer when the media source is killed',
function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let terminates = 0;
sourceBuffer.transmuxer_ = {
terminate() {
terminates++;
}
};
mediaSource.trigger('sourceclose');
QUnit.equal(terminates, 1, 'called terminate on transmux web worker');
});
QUnit.test('duration is faked when playing a live stream', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
mediaSource.duration = Infinity;
mediaSource.nativeMediaSource_.duration = 100;
QUnit.equal(mediaSource.nativeMediaSource_.duration, 100,
'native duration was not set to infinity');
QUnit.equal(mediaSource.duration, Infinity,
'the MediaSource wrapper pretends it has an infinite duration');
});
QUnit.test(
'duration uses the underlying MediaSource\'s duration when not live', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
mediaSource.duration = 100;
mediaSource.nativeMediaSource_.duration = 120;
QUnit.equal(mediaSource.duration, 120,
'the MediaSource wrapper returns the native duration');
});
QUnit.test('abort on the fake source buffer calls abort on the real ones', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let messages = [];
let aborts = 0;
initializeNativeSourceBuffers(sourceBuffer);
sourceBuffer.transmuxer_.postMessage = function(message) {
messages.push(message);
};
sourceBuffer.bufferUpdating_ = true;
sourceBuffer.videoBuffer_.abort = function() {
aborts++;
};
sourceBuffer.audioBuffer_.abort = function() {
aborts++;
};
sourceBuffer.abort();
QUnit.equal(aborts, 2, 'called abort on both');
QUnit.equal(
sourceBuffer.bufferUpdating_,
false,
'set updating to false'
);
QUnit.equal(messages.length, 1, 'has one message');
QUnit.equal(messages[0].action, 'reset', 'reset called on transmuxer');
});
QUnit.test(
'calling remove deletes cues and invokes remove on any extant source buffers',
function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let removedCue = [];
let removes = 0;
initializeNativeSourceBuffers(sourceBuffer);
sourceBuffer.inbandTextTracks_ = {
CC1: {
removeCue(cue) {
removedCue.push(cue);
this.cues.splice(this.cues.indexOf(cue), 1);
},
cues: [
{startTime: 10, endTime: 20, text: 'delete me'},
{startTime: 0, endTime: 2, text: 'save me'}
]
}
};
mediaSource.videoBuffer_.remove = function(start, end) {
if (start === 3 && end === 10) {
removes++;
}
};
mediaSource.audioBuffer_.remove = function(start, end) {
if (start === 3 && end === 10) {
removes++;
}
};
sourceBuffer.remove(3, 10);
QUnit.equal(removes, 2, 'called remove on both sourceBuffers');
QUnit.equal(
sourceBuffer.inbandTextTracks_.CC1.cues.length,
1,
'one cue remains after remove'
);
QUnit.equal(
removedCue[0].text,
'delete me',
'the cue that overlapped the remove region was removed'
);
});
QUnit.test(
'calling remove property handles absence of cues (null)',
function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
initializeNativeSourceBuffers(sourceBuffer);
sourceBuffer.inbandTextTracks_ = {
CC1: {
cues: null
}
};
mediaSource.videoBuffer_.remove = function(start, end) {
// pass
};
mediaSource.audioBuffer_.remove = function(start, end) {
// pass
};
// this call should not raise an exception
sourceBuffer.remove(3, 10);
QUnit.equal(
sourceBuffer.inbandTextTracks_.CC1.cues,
null,
'cues are still null'
);
});
QUnit.test('removing doesn\'t happen with audio disabled', function() {
let mediaSource = new videojs.MediaSource();
let muxedBuffer = mediaSource.addSourceBuffer('video/mp2t');
// creating this audio buffer disables audio in the muxed one
let audioBuffer = mediaSource.addSourceBuffer('audio/mp2t; codecs="mp4a.40.2"');
let removedCue = [];
let removes = 0;
initializeNativeSourceBuffers(muxedBuffer);
muxedBuffer.inbandTextTracks_ = {
CC1: {
removeCue(cue) {
removedCue.push(cue);
this.cues.splice(this.cues.indexOf(cue), 1);
},
cues: [
{startTime: 10, endTime: 20, text: 'delete me'},
{startTime: 0, endTime: 2, text: 'save me'}
]
}
};
mediaSource.videoBuffer_.remove = function(start, end) {
if (start === 3 && end === 10) {
removes++;
}
};
mediaSource.audioBuffer_.remove = function(start, end) {
if (start === 3 && end === 10) {
removes++;
}
};
muxedBuffer.remove(3, 10);
QUnit.equal(removes, 1, 'called remove on only one source buffer');
QUnit.equal(muxedBuffer.inbandTextTracks_.CC1.cues.length,
1,
'one cue remains after remove');
QUnit.equal(removedCue[0].text,
'delete me',
'the cue that overlapped the remove region was removed');
});
QUnit.test('readyState delegates to the native implementation', function() {
let mediaSource = new HtmlMediaSource();
QUnit.equal(
mediaSource.readyState,
mediaSource.nativeMediaSource_.readyState,
'readyStates are equal'
);
mediaSource.nativeMediaSource_.readyState = 'nonsense stuff';
QUnit.equal(
mediaSource.readyState,
mediaSource.nativeMediaSource_.readyState,
'readyStates are equal'
);
});
QUnit.test('addSeekableRange_ throws an error for media with known duration', function() {
let mediaSource = new videojs.MediaSource();
mediaSource.duration = 100;
QUnit.throws(function() {
mediaSource.addSeekableRange_(0, 100);
}, 'cannot add seekable range');
});
QUnit.test('addSeekableRange_ adds to the native MediaSource duration', function() {
let mediaSource = new videojs.MediaSource();
mediaSource.duration = Infinity;
mediaSource.addSeekableRange_(120, 240);
QUnit.equal(mediaSource.nativeMediaSource_.duration, 240, 'set native duration');
QUnit.equal(mediaSource.duration, Infinity, 'emulated duration');
mediaSource.addSeekableRange_(120, 220);
QUnit.equal(mediaSource.nativeMediaSource_.duration, 240, 'ignored the smaller range');
QUnit.equal(mediaSource.duration, Infinity, 'emulated duration');
});
QUnit.test('appendBuffer error triggers on the player', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let error = false;
mediaSource.player_ = this.player;
initializeNativeSourceBuffers(sourceBuffer);
sourceBuffer.videoBuffer_.appendBuffer = () => {
throw new Error();
};
this.player.on('error', () => error = true);
// send fake data to the source buffer from the transmuxer to append to native buffer
// initializeNativeSourceBuffers does the same thing to trigger the creation of
// native source buffers.
let fakeTransmuxerMessage = initializeNativeSourceBuffers;
fakeTransmuxerMessage(sourceBuffer);
this.clock.tick(1);
QUnit.ok(error, 'error triggered on player');
});
QUnit.test('transmuxes mp2t segments', function() {
let mp2tSegments = [];
let mp4Segments = [];
let data = new Uint8Array(1);
let mediaSource;
let sourceBuffer;
mediaSource = new videojs.MediaSource();
sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
sourceBuffer.transmuxer_.postMessage = function(segment) {
if (segment.action === 'push') {
let buffer = new Uint8Array(segment.data, segment.byteOffset, segment.byteLength);
mp2tSegments.push(buffer);
}
};
sourceBuffer.concatAndAppendSegments_ = function(segmentObj, destinationBuffer) {
mp4Segments.push(segmentObj);
};
sourceBuffer.appendBuffer(data);
QUnit.equal(mp2tSegments.length, 1, 'transmuxed one segment');
QUnit.equal(mp2tSegments[0].length, 1, 'did not alter the segment');
QUnit.equal(mp2tSegments[0][0], data[0], 'did not alter the segment');
// an init segment
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', new Uint8Array(1)));
// a media segment
sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', new Uint8Array(1)));
// Segments are concatenated
QUnit.equal(
mp4Segments.length,
0,
'segments are not appended until after the `done` message'
);
// send `done` message
sourceBuffer.transmuxer_.onmessage(doneMessage);
// Segments are concatenated
QUnit.equal(mp4Segments.length, 2, 'appended the segments');
});
QUnit.test(
'handles typed-arrays that are subsets of their underlying buffer',
function() {
let mp2tSegments = [];
let mp4Segments = [];
let dataBuffer = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
let data = dataBuffer.subarray(5, 7);
let mediaSource;
let sourceBuffer;
mediaSource = new videojs.MediaSource();
sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
sourceBuffer.transmuxer_.postMessage = function(segment) {
if (segment.action === 'push') {
let buffer = new Uint8Array(segment.data, segment.byteOffset, segment.byteLength);
mp2tSegments.push(buffer);
}
};
sourceBuffer.concatAndAppendSegments_ = function(segmentObj, destinationBuffer) {
mp4Segments.push(segmentObj.segments[0]);
};
sourceBuffer.appendBuffer(data);
QUnit.equal(mp2tSegments.length, 1, 'emitted the fragment');
QUnit.equal(
mp2tSegments[0].length,
2,
'correctly handled a typed-array that is a subset'
);
QUnit.equal(mp2tSegments[0][0], 5, 'fragment contains the correct first byte');
QUnit.equal(mp2tSegments[0][1], 6, 'fragment contains the correct second byte');
// an init segment
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', data));
// Segments are concatenated
QUnit.equal(
mp4Segments.length,
0,
'segments are not appended until after the `done` message'
);
// send `done` message
sourceBuffer.transmuxer_.onmessage(doneMessage);
// Segments are concatenated
QUnit.equal(mp4Segments.length, 1, 'emitted the fragment');
QUnit.equal(
mp4Segments[0].length,
2,
'correctly handled a typed-array that is a subset'
);
QUnit.equal(mp4Segments[0][0], 5, 'fragment contains the correct first byte');
QUnit.equal(mp4Segments[0][1], 6, 'fragment contains the correct second byte');
});
QUnit.test(
'only appends audio init segment for first segment or on audio/media changes',
function() {
let mp4Segments = [];
let initBuffer = new Uint8Array([0, 1]);
let dataBuffer = new Uint8Array([2, 3]);
let mediaSource;
let sourceBuffer;
mediaSource = new videojs.MediaSource();
sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
sourceBuffer.audioDisabled_ = false;
mediaSource.player_ = this.player;
mediaSource.url_ = this.url;
mediaSource.trigger('sourceopen');
sourceBuffer.concatAndAppendSegments_ = function(segmentObj, destinationBuffer) {
let segment = segmentObj.segments.reduce((seg, arr) => seg.concat(Array.from(arr)),
[]);
mp4Segments.push(segment);
};
QUnit.ok(sourceBuffer.appendAudioInitSegment_, 'will append init segment next');
// an init segment
sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', dataBuffer, {
initSegment: {
data: initBuffer.buffer,
byteOffset: initBuffer.byteOffset,
byteLength: initBuffer.byteLength
}
}));
// Segments are concatenated
QUnit.equal(
mp4Segments.length,
0,
'segments are not appended until after the `done` message'
);
// send `done` message
sourceBuffer.transmuxer_.onmessage(doneMessage);
// Segments are concatenated
QUnit.equal(mp4Segments.length, 1, 'emitted the fragment');
// Contains init segment on first segment
QUnit.equal(mp4Segments[0][0], 0, 'fragment contains the correct first byte');
QUnit.equal(mp4Segments[0][1], 1, 'fragment contains the correct second byte');
QUnit.equal(mp4Segments[0][2], 2, 'fragment contains the correct third byte');
QUnit.equal(mp4Segments[0][3], 3, 'fragment contains the correct fourth byte');
QUnit.ok(!sourceBuffer.appendAudioInitSegment_, 'will not append init segment next');
dataBuffer = new Uint8Array([4, 5]);
sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', dataBuffer, {
initSegment: {
data: initBuffer.buffer,
byteOffset: initBuffer.byteOffset,
byteLength: initBuffer.byteLength
}
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(mp4Segments.length, 2, 'emitted the fragment');
// does not contain init segment on next segment
QUnit.equal(mp4Segments[1][0], 4, 'fragment contains the correct first byte');
QUnit.equal(mp4Segments[1][1], 5, 'fragment contains the correct second byte');
// audio track change
this.player.audioTracks().trigger('change');
sourceBuffer.audioDisabled_ = false;
QUnit.ok(sourceBuffer.appendAudioInitSegment_, 'audio change sets appendAudioInitSegment_');
dataBuffer = new Uint8Array([6, 7]);
sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', dataBuffer, {
initSegment: {
data: initBuffer.buffer,
byteOffset: initBuffer.byteOffset,
byteLength: initBuffer.byteLength
}
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(mp4Segments.length, 3, 'emitted the fragment');
// contains init segment after audio track change
QUnit.equal(mp4Segments[2][0], 0, 'fragment contains the correct first byte');
QUnit.equal(mp4Segments[2][1], 1, 'fragment contains the correct second byte');
QUnit.equal(mp4Segments[2][2], 6, 'fragment contains the correct third byte');
QUnit.equal(mp4Segments[2][3], 7, 'fragment contains the correct fourth byte');
QUnit.ok(!sourceBuffer.appendAudioInitSegment_, 'will not append init segment next');
dataBuffer = new Uint8Array([8, 9]);
sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', dataBuffer, {
initSegment: {
data: initBuffer.buffer,
byteOffset: initBuffer.byteOffset,
byteLength: initBuffer.byteLength
}
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(mp4Segments.length, 4, 'emitted the fragment');
// does not contain init segment in next segment
QUnit.equal(mp4Segments[3][0], 8, 'fragment contains the correct first byte');
QUnit.equal(mp4Segments[3][1], 9, 'fragment contains the correct second byte');
QUnit.ok(!sourceBuffer.appendAudioInitSegment_, 'will not append init segment next');
// rendition switch
this.player.trigger('mediachange');
QUnit.ok(sourceBuffer.appendAudioInitSegment_, 'media change sets appendAudioInitSegment_');
dataBuffer = new Uint8Array([10, 11]);
sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', dataBuffer, {
initSegment: {
data: initBuffer.buffer,
byteOffset: initBuffer.byteOffset,
byteLength: initBuffer.byteLength
}
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(mp4Segments.length, 5, 'emitted the fragment');
// contains init segment after audio track change
QUnit.equal(mp4Segments[4][0], 0, 'fragment contains the correct first byte');
QUnit.equal(mp4Segments[4][1], 1, 'fragment contains the correct second byte');
QUnit.equal(mp4Segments[4][2], 10, 'fragment contains the correct third byte');
QUnit.equal(mp4Segments[4][3], 11, 'fragment contains the correct fourth byte');
QUnit.ok(!sourceBuffer.appendAudioInitSegment_, 'will not append init segment next');
});
QUnit.test(
'appends video init segment for every segment',
function() {
let mp4Segments = [];
let initBuffer = new Uint8Array([0, 1]);
let dataBuffer = new Uint8Array([2, 3]);
let mediaSource;
let sourceBuffer;
mediaSource = new videojs.MediaSource();
sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
mediaSource.player_ = this.player;
mediaSource.url_ = this.url;
mediaSource.trigger('sourceopen');
sourceBuffer.concatAndAppendSegments_ = function(segmentObj, destinationBuffer) {
let segment = segmentObj.segments.reduce((seg, arr) => seg.concat(Array.from(arr)),
[]);
mp4Segments.push(segment);
};
// an init segment
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', dataBuffer, {
initSegment: {
data: initBuffer.buffer,
byteOffset: initBuffer.byteOffset,
byteLength: initBuffer.byteLength
}
}));
// Segments are concatenated
QUnit.equal(
mp4Segments.length,
0,
'segments are not appended until after the `done` message'
);
// send `done` message
sourceBuffer.transmuxer_.onmessage(doneMessage);
// Segments are concatenated
QUnit.equal(mp4Segments.length, 1, 'emitted the fragment');
// Contains init segment on first segment
QUnit.equal(mp4Segments[0][0], 0, 'fragment contains the correct first byte');
QUnit.equal(mp4Segments[0][1], 1, 'fragment contains the correct second byte');
QUnit.equal(mp4Segments[0][2], 2, 'fragment contains the correct third byte');
QUnit.equal(mp4Segments[0][3], 3, 'fragment contains the correct fourth byte');
dataBuffer = new Uint8Array([4, 5]);
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', dataBuffer, {
initSegment: {
data: initBuffer.buffer,
byteOffset: initBuffer.byteOffset,
byteLength: initBuffer.byteLength
}
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(mp4Segments.length, 2, 'emitted the fragment');
QUnit.equal(mp4Segments[1][0], 0, 'fragment contains the correct first byte');
QUnit.equal(mp4Segments[1][1], 1, 'fragment contains the correct second byte');
QUnit.equal(mp4Segments[1][2], 4, 'fragment contains the correct third byte');
QUnit.equal(mp4Segments[1][3], 5, 'fragment contains the correct fourth byte');
dataBuffer = new Uint8Array([6, 7]);
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', dataBuffer, {
initSegment: {
data: initBuffer.buffer,
byteOffset: initBuffer.byteOffset,
byteLength: initBuffer.byteLength
}
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(mp4Segments.length, 3, 'emitted the fragment');
// contains init segment after audio track change
QUnit.equal(mp4Segments[2][0], 0, 'fragment contains the correct first byte');
QUnit.equal(mp4Segments[2][1], 1, 'fragment contains the correct second byte');
QUnit.equal(mp4Segments[2][2], 6, 'fragment contains the correct third byte');
QUnit.equal(mp4Segments[2][3], 7, 'fragment contains the correct fourth byte');
});
QUnit.test('handles empty codec string value', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer =
mediaSource.addSourceBuffer('video/mp2t; codecs=""');
initializeNativeSourceBuffers(sourceBuffer);
QUnit.ok(mediaSource.videoBuffer_, 'created a video buffer');
QUnit.equal(
mediaSource.videoBuffer_.type,
'video/mp4;codecs="avc1.4d400d"',
'video buffer has the default codec'
);
QUnit.ok(mediaSource.audioBuffer_, 'created an audio buffer');
QUnit.equal(
mediaSource.audioBuffer_.type,
'audio/mp4;codecs="mp4a.40.2"',
'audio buffer has the default codec'
);
QUnit.equal(mediaSource.sourceBuffers.length, 1, 'created one virtual buffer');
QUnit.equal(
mediaSource.sourceBuffers[0],
sourceBuffer,
'returned the virtual buffer'
);
});
QUnit.test('can create an audio buffer by itself', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer =
mediaSource.addSourceBuffer('video/mp2t; codecs="mp4a.40.2"');
initializeNativeSourceBuffers(sourceBuffer);
QUnit.ok(!mediaSource.videoBuffer_, 'did not create a video buffer');
QUnit.ok(mediaSource.audioBuffer_, 'created an audio buffer');
QUnit.equal(
mediaSource.audioBuffer_.type,
'audio/mp4;codecs="mp4a.40.2"',
'audio buffer has the default codec'
);
QUnit.equal(mediaSource.sourceBuffers.length, 1, 'created one virtual buffer');
QUnit.equal(
mediaSource.sourceBuffers[0],
sourceBuffer,
'returned the virtual buffer'
);
});
QUnit.test('can create an video buffer by itself', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer =
mediaSource.addSourceBuffer('video/mp2t; codecs="avc1.4d400d"');
initializeNativeSourceBuffers(sourceBuffer);
QUnit.ok(!mediaSource.audioBuffer_, 'did not create an audio buffer');
QUnit.ok(mediaSource.videoBuffer_, 'created an video buffer');
QUnit.equal(
mediaSource.videoBuffer_.type,
'video/mp4;codecs="avc1.4d400d"',
'video buffer has the codec that was passed'
);
QUnit.equal(mediaSource.sourceBuffers.length, 1, 'created one virtual buffer');
QUnit.equal(
mediaSource.sourceBuffers[0],
sourceBuffer,
'returned the virtual buffer'
);
});
QUnit.test('handles invalid codec string', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer =
mediaSource.addSourceBuffer('video/mp2t; codecs="nope"');
initializeNativeSourceBuffers(sourceBuffer);
QUnit.ok(mediaSource.videoBuffer_, 'created a video buffer');
QUnit.equal(
mediaSource.videoBuffer_.type,
'video/mp4;codecs="avc1.4d400d"',
'video buffer has the default codec'
);
QUnit.ok(mediaSource.audioBuffer_, 'created an audio buffer');
QUnit.equal(
mediaSource.audioBuffer_.type,
'audio/mp4;codecs="mp4a.40.2"',
'audio buffer has the default codec'
);
QUnit.equal(mediaSource.sourceBuffers.length, 1, 'created one virtual buffer');
QUnit.equal(
mediaSource.sourceBuffers[0],
sourceBuffer,
'returned the virtual buffer'
);
});
QUnit.test('handles codec strings in reverse order', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer =
mediaSource.addSourceBuffer('video/mp2t; codecs="mp4a.40.5,avc1.64001f"');
initializeNativeSourceBuffers(sourceBuffer);
QUnit.ok(mediaSource.videoBuffer_, 'created a video buffer');
QUnit.equal(
mediaSource.videoBuffer_.type,
'video/mp4;codecs="avc1.64001f"',
'video buffer has the passed codec'
);
QUnit.ok(mediaSource.audioBuffer_, 'created an audio buffer');
QUnit.equal(
mediaSource.audioBuffer_.type,
'audio/mp4;codecs="mp4a.40.5"',
'audio buffer has the passed codec'
);
QUnit.equal(mediaSource.sourceBuffers.length, 1, 'created one virtual buffer');
QUnit.equal(
mediaSource.sourceBuffers[0],
sourceBuffer,
'returned the virtual buffer'
);
QUnit.ok(sourceBuffer.transmuxer_, 'created a transmuxer');
});
QUnit.test('forwards codec strings to native buffers when specified', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer =
mediaSource.addSourceBuffer('video/mp2t; codecs="avc1.64001f,mp4a.40.5"');
initializeNativeSourceBuffers(sourceBuffer);
QUnit.ok(mediaSource.videoBuffer_, 'created a video buffer');
QUnit.equal(mediaSource.videoBuffer_.type,
'video/mp4;codecs="avc1.64001f"',
'passed the video codec along');
QUnit.ok(mediaSource.audioBuffer_, 'created a video buffer');
QUnit.equal(mediaSource.audioBuffer_.type,
'audio/mp4;codecs="mp4a.40.5"',
'passed the audio codec along');
});
QUnit.test('parses old-school apple codec strings to the modern standard', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer =
mediaSource.addSourceBuffer('video/mp2t; codecs="avc1.100.31,mp4a.40.5"');
initializeNativeSourceBuffers(sourceBuffer);
QUnit.ok(mediaSource.videoBuffer_, 'created a video buffer');
QUnit.equal(mediaSource.videoBuffer_.type,
'video/mp4;codecs="avc1.64001f"',
'passed the video codec along');
QUnit.ok(mediaSource.audioBuffer_, 'created a video buffer');
QUnit.equal(mediaSource.audioBuffer_.type,
'audio/mp4;codecs="mp4a.40.5"',
'passed the audio codec along');
});
QUnit.test('specifies reasonable codecs if none are specified', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
initializeNativeSourceBuffers(sourceBuffer);
QUnit.ok(mediaSource.videoBuffer_, 'created a video buffer');
QUnit.equal(mediaSource.videoBuffer_.type,
'video/mp4;codecs="avc1.4d400d"',
'passed the video codec along');
QUnit.ok(mediaSource.audioBuffer_, 'created a video buffer');
QUnit.equal(mediaSource.audioBuffer_.type,
'audio/mp4;codecs="mp4a.40.2"',
'passed the audio codec along');
});
QUnit.test('virtual buffers are updating if either native buffer is', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
initializeNativeSourceBuffers(sourceBuffer);
mediaSource.videoBuffer_.updating = true;
mediaSource.audioBuffer_.updating = false;
QUnit.equal(sourceBuffer.updating, true, 'virtual buffer is updating');
mediaSource.audioBuffer_.updating = true;
QUnit.equal(sourceBuffer.updating, true, 'virtual buffer is updating');
mediaSource.videoBuffer_.updating = false;
QUnit.equal(sourceBuffer.updating, true, 'virtual buffer is updating');
mediaSource.audioBuffer_.updating = false;
QUnit.equal(sourceBuffer.updating, false, 'virtual buffer is not updating');
});
QUnit.test(
'virtual buffers have a position buffered if both native buffers do',
function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
initializeNativeSourceBuffers(sourceBuffer);
mediaSource.videoBuffer_.buffered = videojs.createTimeRanges([
[0, 10],
[20, 30]
]);
mediaSource.audioBuffer_.buffered = videojs.createTimeRanges([
[0, 7],
[11, 15],
[16, 40]
]);
QUnit.equal(sourceBuffer.buffered.length, 2, 'two buffered ranges');
QUnit.equal(sourceBuffer.buffered.start(0), 0, 'first starts at zero');
QUnit.equal(sourceBuffer.buffered.end(0), 7, 'first ends at seven');
QUnit.equal(sourceBuffer.buffered.start(1), 20, 'second starts at twenty');
QUnit.equal(sourceBuffer.buffered.end(1), 30, 'second ends at 30');
});
QUnit.test('disabled audio does not affect buffered property', function() {
let mediaSource = new videojs.MediaSource();
let muxedBuffer = mediaSource.addSourceBuffer('video/mp2t');
// creating a separate audio buffer disables audio on the muxed one
let audioBuffer = mediaSource.addSourceBuffer('audio/mp2t; codecs="mp4a.40.2"');
initializeNativeSourceBuffers(muxedBuffer);
mediaSource.videoBuffer_.buffered = videojs.createTimeRanges([[1, 10]]);
mediaSource.audioBuffer_.buffered = videojs.createTimeRanges([[2, 11]]);
QUnit.equal(audioBuffer.buffered.length, 1, 'one buffered range');
QUnit.equal(audioBuffer.buffered.start(0), 2, 'starts at two');
QUnit.equal(audioBuffer.buffered.end(0), 11, 'ends at eleven');
QUnit.equal(muxedBuffer.buffered.length, 1, 'one buffered range');
QUnit.equal(muxedBuffer.buffered.start(0), 1, 'starts at one');
QUnit.equal(muxedBuffer.buffered.end(0), 10, 'ends at ten');
});
QUnit.test('sets transmuxer baseMediaDecodeTime on appends', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let resets = [];
sourceBuffer.transmuxer_.postMessage = function(message) {
if (message.action === 'setTimestampOffset') {
resets.push(message.timestampOffset);
}
};
sourceBuffer.timestampOffset = 42;
QUnit.equal(
resets.length,
1,
'reset called'
);
QUnit.equal(
resets[0],
42,
'set the baseMediaDecodeTime based on timestampOffset'
);
});
QUnit.test('aggregates source buffer update events', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let updates = 0;
let updateends = 0;
let updatestarts = 0;
initializeNativeSourceBuffers(sourceBuffer);
mediaSource.player_ = this.player;
sourceBuffer.addEventListener('updatestart', function() {
updatestarts++;
});
sourceBuffer.addEventListener('update', function() {
updates++;
});
sourceBuffer.addEventListener('updateend', function() {
updateends++;
});
QUnit.equal(updatestarts, 0, 'no updatestarts before a `done` message is received');
QUnit.equal(updates, 0, 'no updates before a `done` message is received');
QUnit.equal(updateends, 0, 'no updateends before a `done` message is received');
// the video buffer begins updating first:
sourceBuffer.videoBuffer_.updating = true;
sourceBuffer.audioBuffer_.updating = false;
sourceBuffer.videoBuffer_.trigger('updatestart');
QUnit.equal(updatestarts, 1, 'aggregated updatestart');
sourceBuffer.audioBuffer_.updating = true;
sourceBuffer.audioBuffer_.trigger('updatestart');
QUnit.equal(updatestarts, 1, 'aggregated updatestart');
// the audio buffer finishes first:
sourceBuffer.audioBuffer_.updating = false;
sourceBuffer.videoBuffer_.updating = true;
sourceBuffer.audioBuffer_.trigger('update');
QUnit.equal(updates, 0, 'waited for the second update');
sourceBuffer.videoBuffer_.updating = false;
sourceBuffer.videoBuffer_.trigger('update');
QUnit.equal(updates, 1, 'aggregated update');
// audio finishes first:
sourceBuffer.videoBuffer_.updating = true;
sourceBuffer.audioBuffer_.updating = false;
sourceBuffer.audioBuffer_.trigger('updateend');
QUnit.equal(updateends, 0, 'waited for the second updateend');
sourceBuffer.videoBuffer_.updating = false;
sourceBuffer.videoBuffer_.trigger('updateend');
QUnit.equal(updateends, 1, 'aggregated updateend');
});
QUnit.test('translates caption events into WebVTT cues', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let types = [];
let hls608 = 0;
mediaSource.player_ = {
addRemoteTextTrack(options) {
types.push(options.kind);
return {
track: {
kind: options.kind,
label: options.label,
cues: [],
addCue(cue) {
this.cues.push(cue);
}
}
};
},
textTracks() {
return {
getTrackById() {}
};
},
remoteTextTracks() {
},
tech_: new videojs.EventTarget()
};
mediaSource.player_.tech_.on('usage', (event) => {
if (event.name === 'hls-608') {
hls608++;
}
});
sourceBuffer.timestampOffset = 10;
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', new Uint8Array(1), {
captions: [{
startTime: 1,
endTime: 3,
text: 'This is an in-band caption in CC1',
stream: 'CC1'
}],
captionStreams: {CC1: true}
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
let cues = sourceBuffer.inbandTextTracks_.CC1.cues;
QUnit.equal(hls608, 1, 'one hls-608 event was triggered');
QUnit.equal(types.length, 1, 'created one text track');
QUnit.equal(types[0], 'captions', 'the type was captions');
QUnit.equal(cues.length, 1, 'created one cue');
QUnit.equal(cues[0].text, 'This is an in-band caption in CC1', 'included the text');
QUnit.equal(cues[0].startTime, 11, 'started at eleven');
QUnit.equal(cues[0].endTime, 13, 'ended at thirteen');
});
QUnit.test('captions use existing tracks with id equal to CC#', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let addTrackCalled = 0;
let tracks = {
CC1: {
kind: 'captions',
label: 'CC1',
id: 'CC1',
cues: [],
addCue(cue) {
this.cues.push(cue);
}
},
CC2: {
kind: 'captions',
label: 'CC2',
id: 'CC2',
cues: [],
addCue(cue) {
this.cues.push(cue);
}
}
};
mediaSource.player_ = {
addRemoteTextTrack(options) {
addTrackCalled++;
},
textTracks() {
return {
getTrackById(id) {
return tracks[id];
}
};
},
remoteTextTracks() {
},
tech_: new videojs.EventTarget()
};
sourceBuffer.timestampOffset = 10;
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', new Uint8Array(1), {
captions: [{
stream: 'CC1',
startTime: 1,
endTime: 3,
text: 'This is an in-band caption in CC1'
}, {
stream: 'CC2',
startTime: 1,
endTime: 3,
text: 'This is an in-band caption in CC2'
}],
captionStreams: {CC1: true, CC2: true}
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
let cues = sourceBuffer.inbandTextTracks_.CC1.cues;
QUnit.equal(addTrackCalled, 0, 'no tracks were created');
QUnit.equal(tracks.CC1.cues.length, 1, 'CC1 contains 1 cue');
QUnit.equal(tracks.CC2.cues.length, 1, 'CC2 contains 1 cue');
QUnit.equal(tracks.CC1.cues[0].text, 'This is an in-band caption in CC1', 'CC1 contains the right cue');
QUnit.equal(tracks.CC2.cues[0].text, 'This is an in-band caption in CC2', 'CC2 contains the right cue');
});
QUnit.test('translates metadata events into WebVTT cues', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
mediaSource.duration = Infinity;
mediaSource.nativeMediaSource_.duration = 60;
let types = [];
let metadata = [{
cueTime: 2,
frames: [{
url: 'This is a url tag'
}, {
value: 'This is a text tag'
}]
}, {
cueTime: 12,
frames: [{
data: 'This is a priv tag'
}]
}];
metadata.dispatchType = 0x10;
mediaSource.player_ = {
addRemoteTextTrack(options) {
types.push(options.kind);
return {
track: {
kind: options.kind,
label: options.label,
cues: [],
addCue(cue) {
this.cues.push(cue);
}
}
};
},
remoteTextTracks() {
}
};
sourceBuffer.timestampOffset = 10;
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', new Uint8Array(1), {
metadata
}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(
sourceBuffer.metadataTrack_.inBandMetadataTrackDispatchType,
16,
'in-band metadata track dispatch type correctly set'
);
let cues = sourceBuffer.metadataTrack_.cues;
QUnit.equal(types.length, 1, 'created one text track');
QUnit.equal(types[0], 'metadata', 'the type was metadata');
QUnit.equal(cues.length, 3, 'created three cues');
QUnit.equal(cues[0].text, 'This is a url tag', 'included the text');
QUnit.equal(cues[0].startTime, 12, 'started at twelve');
QUnit.equal(cues[0].endTime, 22, 'ended at StartTime of next cue(22)');
QUnit.equal(cues[1].text, 'This is a text tag', 'included the text');
QUnit.equal(cues[1].startTime, 12, 'started at twelve');
QUnit.equal(cues[1].endTime, 22, 'ended at the startTime of next cue(22)');
QUnit.equal(cues[2].text, 'This is a priv tag', 'included the text');
QUnit.equal(cues[2].startTime, 22, 'started at twenty two');
QUnit.equal(cues[2].endTime, Number.MAX_VALUE, 'ended at the maximum value');
mediaSource.duration = 100;
mediaSource.trigger('sourceended');
QUnit.equal(cues[2].endTime, mediaSource.duration, 'sourceended is fired');
});
QUnit.test('does not wrap mp4 source buffers', function() {
let mediaSource = new videojs.MediaSource();
mediaSource.addSourceBuffer('video/mp4;codecs=avc1.4d400d');
mediaSource.addSourceBuffer('audio/mp4;codecs=mp4a.40.2');
QUnit.equal(
mediaSource.sourceBuffers.length,
mediaSource.nativeMediaSource_.sourceBuffers.length,
'did not need virtual buffers'
);
QUnit.equal(mediaSource.sourceBuffers.length, 2, 'created native buffers');
});
QUnit.test('can get activeSourceBuffers', function() {
let mediaSource = new videojs.MediaSource();
// although activeSourceBuffers should technically be a SourceBufferList, we are
// returning it as an array, and users may expect it to behave as such
QUnit.ok(Array.isArray(mediaSource.activeSourceBuffers));
});
QUnit.test('active source buffers are updated on each buffer\'s updateend',
function() {
let mediaSource = new videojs.MediaSource();
let updateCallCount = 0;
let sourceBuffer;
mediaSource.updateActiveSourceBuffers_ = () => {
updateCallCount++;
};
sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
mediaSource.player_ = this.player;
mediaSource.url_ = this.url;
mediaSource.trigger('sourceopen');
QUnit.equal(updateCallCount, 0,
'active source buffers not updated on adding source buffer');
mediaSource.player_.audioTracks().trigger('addtrack');
QUnit.equal(updateCallCount, 1,
'active source buffers updated after addtrack');
sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
QUnit.equal(updateCallCount, 1,
'active source buffers not updated on adding second source buffer');
mediaSource.player_.audioTracks().trigger('removetrack');
QUnit.equal(updateCallCount, 2,
'active source buffers updated after removetrack');
mediaSource.player_.audioTracks().trigger('change');
QUnit.equal(updateCallCount, 3,
'active source buffers updated after change');
});
QUnit.test('combined buffer is the only active buffer when main track enabled',
function() {
let mediaSource = new videojs.MediaSource();
let sourceBufferAudio;
let sourceBufferCombined;
let audioTracks = [{
enabled: true,
kind: 'main',
label: 'main'
}, {
enabled: false,
kind: 'alternative',
label: 'English (UK)'
}];
this.player.audioTracks = () => audioTracks;
mediaSource.player_ = this.player;
sourceBufferCombined = mediaSource.addSourceBuffer('video/m2pt');
sourceBufferCombined.videoCodec_ = true;
sourceBufferCombined.audioCodec_ = true;
sourceBufferAudio = mediaSource.addSourceBuffer('video/m2pt');
sourceBufferAudio.videoCodec_ = false;
sourceBufferAudio.audioCodec_ = true;
mediaSource.updateActiveSourceBuffers_();
QUnit.equal(mediaSource.activeSourceBuffers.length, 1,
'active source buffers starts with one source buffer');
QUnit.equal(mediaSource.activeSourceBuffers[0], sourceBufferCombined,
'active source buffers starts with combined source buffer');
});
QUnit.test('combined & audio buffers are active when alternative track enabled',
function() {
let mediaSource = new videojs.MediaSource();
let sourceBufferAudio;
let sourceBufferCombined;
let audioTracks = [{
enabled: false,
kind: 'main',
label: 'main'
}, {
enabled: true,
kind: 'alternative',
label: 'English (UK)'
}];
this.player.audioTracks = () => audioTracks;
mediaSource.player_ = this.player;
sourceBufferCombined = mediaSource.addSourceBuffer('video/m2pt');
sourceBufferCombined.videoCodec_ = true;
sourceBufferCombined.audioCodec_ = true;
sourceBufferAudio = mediaSource.addSourceBuffer('video/m2pt');
sourceBufferAudio.videoCodec_ = false;
sourceBufferAudio.audioCodec_ = true;
mediaSource.updateActiveSourceBuffers_();
QUnit.equal(mediaSource.activeSourceBuffers.length, 2,
'active source buffers includes both source buffers');
// maintains same order as source buffers were created
QUnit.equal(mediaSource.activeSourceBuffers[0], sourceBufferCombined,
'active source buffers starts with combined source buffer');
QUnit.equal(mediaSource.activeSourceBuffers[1], sourceBufferAudio,
'active source buffers ends with audio source buffer');
});
QUnit.test('video only & audio only buffers are always active',
function() {
let mediaSource = new videojs.MediaSource();
let sourceBufferAudio;
let sourceBufferCombined;
let audioTracks = [{
enabled: false,
kind: 'main',
label: 'main'
}, {
enabled: true,
kind: 'alternative',
label: 'English (UK)'
}];
this.player.audioTracks = () => audioTracks;
mediaSource.player_ = this.player;
sourceBufferCombined = mediaSource.addSourceBuffer('video/m2pt');
sourceBufferCombined.videoCodec_ = true;
sourceBufferCombined.audioCodec_ = false;
sourceBufferAudio = mediaSource.addSourceBuffer('video/m2pt');
sourceBufferAudio.videoCodec_ = false;
sourceBufferAudio.audioCodec_ = true;
mediaSource.updateActiveSourceBuffers_();
QUnit.equal(mediaSource.activeSourceBuffers.length, 2,
'active source buffers includes both source buffers');
// maintains same order as source buffers were created
QUnit.equal(mediaSource.activeSourceBuffers[0], sourceBufferCombined,
'active source buffers starts with combined source buffer');
QUnit.equal(mediaSource.activeSourceBuffers[1], sourceBufferAudio,
'active source buffers ends with audio source buffer');
audioTracks[0].enabled = true;
audioTracks[1].enabled = false;
mediaSource.updateActiveSourceBuffers_();
QUnit.equal(mediaSource.activeSourceBuffers.length, 2,
'active source buffers includes both source buffers');
// maintains same order as source buffers were created
QUnit.equal(mediaSource.activeSourceBuffers[0], sourceBufferCombined,
'active source buffers starts with combined source buffer');
QUnit.equal(mediaSource.activeSourceBuffers[1], sourceBufferAudio,
'active source buffers ends with audio source buffer');
});
QUnit.test('Single buffer always active. Audio disabled depends on audio codec',
function() {
let mediaSource = new videojs.MediaSource();
let audioTracks = [{
enabled: true,
kind: 'main',
label: 'main'
}];
this.player.audioTracks = () => audioTracks;
mediaSource.player_ = this.player;
let sourceBuffer = mediaSource.addSourceBuffer('video/m2pt');
// video only
sourceBuffer.videoCodec_ = true;
sourceBuffer.audioCodec_ = false;
mediaSource.updateActiveSourceBuffers_();
QUnit.equal(mediaSource.activeSourceBuffers.length, 1, 'sourceBuffer is active');
QUnit.ok(mediaSource.activeSourceBuffers[0].audioDisabled_,
'audio is disabled on video only active sourceBuffer');
// audio only
sourceBuffer.videoCodec_ = false;
sourceBuffer.audioCodec_ = true;
mediaSource.updateActiveSourceBuffers_();
QUnit.equal(mediaSource.activeSourceBuffers.length, 1, 'sourceBuffer is active');
QUnit.notOk(mediaSource.activeSourceBuffers[0].audioDisabled_,
'audio not disabled on audio only active sourceBuffer');
});
QUnit.test('video segments with info trigger videooinfo event', function() {
let data = new Uint8Array(1);
let infoEvents = [];
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let info = {width: 100};
let newinfo = {width: 225};
mediaSource.on('videoinfo', (e) => infoEvents.push(e));
// send an audio segment with info, then send done
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', data, {info}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(infoEvents.length, 1, 'video info should trigger');
QUnit.deepEqual(infoEvents[0].info, info, 'video info = muxed info');
// send an audio segment with info, then send done
sourceBuffer.transmuxer_.onmessage(createDataMessage('video', data, {info: newinfo}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(infoEvents.length, 2, 'video info should trigger');
QUnit.deepEqual(infoEvents[1].info, newinfo, 'video info = muxed info');
});
QUnit.test('audio segments with info trigger audioinfo event', function() {
let data = new Uint8Array(1);
let infoEvents = [];
let mediaSource = new videojs.MediaSource();
let sourceBuffer = mediaSource.addSourceBuffer('video/mp2t');
let info = {width: 100};
let newinfo = {width: 225};
mediaSource.on('audioinfo', (e) => infoEvents.push(e));
// send an audio segment with info, then send done
sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', data, {info}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(infoEvents.length, 1, 'audio info should trigger');
QUnit.deepEqual(infoEvents[0].info, info, 'audio info = muxed info');
// send an audio segment with info, then send done
sourceBuffer.transmuxer_.onmessage(createDataMessage('audio', data, {info: newinfo}));
sourceBuffer.transmuxer_.onmessage(doneMessage);
QUnit.equal(infoEvents.length, 2, 'audio info should trigger');
QUnit.deepEqual(infoEvents[1].info, newinfo, 'audio info = muxed info');
});
QUnit.test('creates native SourceBuffers immediately if a second ' +
'VirtualSourceBuffer is created', function() {
let mediaSource = new videojs.MediaSource();
let sourceBuffer =
mediaSource.addSourceBuffer('video/mp2t; codecs="avc1.64001f,mp4a.40.5"');
let sourceBuffer2 =
mediaSource.addSourceBuffer('video/mp2t; codecs="mp4a.40.5"');
QUnit.ok(mediaSource.videoBuffer_, 'created a video buffer');
QUnit.equal(
mediaSource.videoBuffer_.type,
'video/mp4;codecs="avc1.64001f"',
'video buffer has the specified codec'
);
QUnit.ok(mediaSource.audioBuffer_, 'created an audio buffer');
QUnit.equal(
mediaSource.audioBuffer_.type,
'audio/mp4;codecs="mp4a.40.5"',
'audio buffer has the specified codec'
);
QUnit.equal(mediaSource.sourceBuffers.length, 2, 'created two virtual buffers');
QUnit.equal(
mediaSource.sourceBuffers[0],
sourceBuffer,
'returned the virtual buffer');
QUnit.equal(
mediaSource.sourceBuffers[1],
sourceBuffer2,
'returned the virtual buffer');
QUnit.equal(
sourceBuffer.audioDisabled_,
true,
'first source buffer\'s audio is automatically disabled');
QUnit.ok(
sourceBuffer2.audioBuffer_,
'second source buffer has an audio source buffer');
});
QUnit.module('VirtualSourceBuffer - Isolated Functions');
QUnit.test('gopsSafeToAlignWith returns correct list', function() {
// gopsSafeToAlignWith uses a 3 second safetyNet so that gops very close to the playhead
// are not considered safe to append to
const safetyNet = 3;
const pts = (time) => Math.ceil(time * 90000);
let mapping = 0;
let currentTime = 0;
let buffer = [];
let player;
let actual;
let expected;
expected = [];
actual = gopsSafeToAlignWith(buffer, player, mapping);
QUnit.deepEqual(actual, expected, 'empty array when player is undefined');
player = { currentTime: () => currentTime };
actual = gopsSafeToAlignWith(buffer, player, mapping);
QUnit.deepEqual(actual, expected, 'empty array when buffer is empty');
buffer = expected = [
{ pts: pts(currentTime + safetyNet + 1) },
{ pts: pts(currentTime + safetyNet + 2) },
{ pts: pts(currentTime + safetyNet + 3) }
];
actual = gopsSafeToAlignWith(buffer, player, mapping);
QUnit.deepEqual(actual, expected,
'entire buffer considered safe when all gops come after currentTime + safetyNet');
buffer = [
{ pts: pts(currentTime + safetyNet) },
{ pts: pts(currentTime + safetyNet + 1) },
{ pts: pts(currentTime + safetyNet + 2) }
];
expected = [
{ pts: pts(currentTime + safetyNet + 1) },
{ pts: pts(currentTime + safetyNet + 2) }
];
actual = gopsSafeToAlignWith(buffer, player, mapping);
QUnit.deepEqual(actual, expected, 'safetyNet comparison is not inclusive');
currentTime = 10;
mapping = -5;
buffer = [
{ pts: pts(currentTime - mapping + safetyNet - 2) },
{ pts: pts(currentTime - mapping + safetyNet - 1) },
{ pts: pts(currentTime - mapping + safetyNet) },
{ pts: pts(currentTime - mapping + safetyNet + 1) },
{ pts: pts(currentTime - mapping + safetyNet + 2) }
];
expected = [
{ pts: pts(currentTime - mapping + safetyNet + 1) },
{ pts: pts(currentTime - mapping + safetyNet + 2) }
];
actual = gopsSafeToAlignWith(buffer, player, mapping);
QUnit.deepEqual(actual, expected, 'uses mapping to shift currentTime');
currentTime = 20;
expected = [];
actual = gopsSafeToAlignWith(buffer, player, mapping);
QUnit.deepEqual(actual, expected,
'empty array when no gops in buffer come after currentTime');
});
QUnit.test('updateGopBuffer correctly processes new gop information', function() {
let buffer = [];
let gops = [];
let replace = true;
let actual;
let expected;
buffer = expected = [{ pts: 100 }, { pts: 200 }];
actual = updateGopBuffer(buffer, gops, replace);
QUnit.deepEqual(actual, expected, 'returns buffer when no new gops');
gops = expected = [{ pts: 300 }, { pts: 400 }];
actual = updateGopBuffer(buffer, gops, replace);
QUnit.deepEqual(actual, expected, 'returns only new gops when replace is true');
replace = false;
buffer = [];
gops = [{ pts: 100 }];
expected = [{ pts: 100 }];
actual = updateGopBuffer(buffer, gops, replace);
QUnit.deepEqual(actual, expected, 'appends new gops to empty buffer');
buffer = [{ pts: 100 }, { pts: 200 }];
gops = [{ pts: 300 }, { pts: 400 }];
expected = [{ pts: 100 }, { pts: 200 }, { pts: 300 }, { pts: 400 }];
actual = updateGopBuffer(buffer, gops, replace);
QUnit.deepEqual(actual, expected, 'appends new gops at end of buffer when no overlap');
buffer = [{ pts: 100 }, { pts: 200 }, { pts: 300 }, { pts: 400 }];
gops = [{ pts: 250 }, { pts: 300 }, { pts: 350 }];
expected = [{ pts: 100 }, { pts: 200 }, { pts: 250 }, { pts: 300 }, { pts: 350 }];
actual = updateGopBuffer(buffer, gops, replace);
QUnit.deepEqual(actual, expected,
'slices buffer at point of overlap and appends new gops');
buffer = [{ pts: 100 }, { pts: 200 }, { pts: 300 }, { pts: 400 }];
gops = [{ pts: 200 }, { pts: 300 }, { pts: 350 }];
expected = [{ pts: 100 }, { pts: 200 }, { pts: 300 }, { pts: 350 }];
actual = updateGopBuffer(buffer, gops, replace);
QUnit.deepEqual(actual, expected, 'overlap slice is inclusive');
buffer = [{ pts: 300 }, { pts: 400 }, { pts: 500 }, { pts: 600 }];
gops = [{ pts: 100 }, { pts: 200 }, { pts: 250 }];
expected = [{ pts: 100 }, { pts: 200 }, { pts: 250 }];
actual = updateGopBuffer(buffer, gops, replace);
QUnit.deepEqual(actual, expected,
'completely replaces buffer with new gops when all gops come before buffer');
});
QUnit.test('removeGopBuffer correctly removes range from buffer', function() {
const pts = (time) => Math.ceil(time * 90000);
let buffer = [];
let start = 0;
let end = 0;
let mapping = -5;
let actual;
let expected;
expected = [];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'returns empty array when buffer empty');
start = 0;
end = 8;
buffer = expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected,
'no removal when remove range comes before start of buffer');
start = 22;
end = 30;
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected,
'removes last gop when remove range is after end of buffer');
start = 0;
end = 10;
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
expected = [
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'clamps start range to begining of buffer');
start = 0;
end = 12;
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
expected = [
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'clamps start range to begining of buffer');
start = 0;
end = 14;
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
expected = [
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'clamps start range to begining of buffer');
start = 15;
end = 30;
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'clamps end range to end of buffer');
start = 17;
end = 30;
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'clamps end range to end of buffer');
start = 20;
end = 30;
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'clamps end range to end of buffer');
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
start = 12;
end = 15;
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'removes gops that remove range intersects with');
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
start = 12;
end = 14;
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'removes gops that remove range intersects with');
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
start = 13;
end = 14;
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'removes gops that remove range intersects with');
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
start = 13;
end = 15;
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'removes gops that remove range intersects with');
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
start = 12;
end = 17;
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'removes gops that remove range intersects with');
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
start = 13;
end = 16;
expected = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected, 'removes gops that remove range intersects with');
start = 10;
end = 20;
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
expected = [];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected,
'removes entire buffer when buffer inside remove range');
start = 0;
end = 30;
buffer = [
{ pts: pts(10 - mapping) },
{ pts: pts(11 - mapping) },
{ pts: pts(12 - mapping) },
{ pts: pts(15 - mapping) },
{ pts: pts(18 - mapping) },
{ pts: pts(20 - mapping) }
];
expected = [];
actual = removeGopBuffer(buffer, start, end, mapping);
QUnit.deepEqual(actual, expected,
'removes entire buffer when buffer inside remove range');
});