shaka-player 4.3.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build-and-test.yaml +7 -0
- package/AUTHORS +1 -0
- package/CHANGELOG.md +33 -0
- package/CONTRIBUTORS +1 -0
- package/conditional/dummy_cast_proxy.js +120 -0
- package/dist/demo.compiled.debug.js +104 -110
- package/dist/demo.compiled.debug.map +3 -3
- package/dist/demo.compiled.js +104 -110
- package/dist/demo.compiled.map +3 -3
- package/dist/deps.js +8 -6
- package/dist/locales.js +28 -28
- package/dist/receiver.compiled.debug.js +54 -60
- package/dist/receiver.compiled.debug.map +3 -3
- package/dist/receiver.compiled.js +54 -60
- package/dist/receiver.compiled.map +3 -3
- package/dist/shaka-player.compiled.d.ts +19 -2
- package/dist/shaka-player.compiled.debug.d.ts +19 -2
- package/dist/shaka-player.compiled.debug.externs.js +102 -80
- package/dist/shaka-player.compiled.debug.js +632 -628
- package/dist/shaka-player.compiled.debug.map +4 -4
- package/dist/shaka-player.compiled.externs.js +102 -80
- package/dist/shaka-player.compiled.js +903 -900
- package/dist/shaka-player.compiled.map +4 -4
- package/dist/shaka-player.ui.d.ts +19 -2
- package/dist/shaka-player.ui.debug.d.ts +19 -2
- package/dist/shaka-player.ui.debug.externs.js +102 -80
- package/dist/shaka-player.ui.debug.js +681 -678
- package/dist/shaka-player.ui.debug.map +4 -4
- package/dist/shaka-player.ui.externs.js +102 -80
- package/dist/shaka-player.ui.js +1033 -1031
- package/dist/shaka-player.ui.map +4 -4
- package/docs/tutorials/welcome.md +2 -2
- package/externs/shaka/mp4_parser.js +3 -0
- package/externs/shaka/player.js +2 -1
- package/lib/cea/cea708_window.js +2 -2
- package/lib/cea/mp4_cea_parser.js +37 -16
- package/lib/dash/segment_template.js +1 -1
- package/lib/hls/hls_parser.js +37 -19
- package/lib/media/content_workarounds.js +12 -0
- package/lib/media/media_source_capabilities.js +36 -0
- package/lib/media/media_source_engine.js +12 -7
- package/lib/media/transmuxer.js +6 -4
- package/lib/player.js +5 -5
- package/lib/polyfill/abort_controller.js +143 -0
- package/lib/polyfill/media_capabilities.js +65 -11
- package/lib/polyfill/patchedmediakeys_apple.js +33 -28
- package/lib/text/ttml_text_parser.js +32 -7
- package/lib/text/ui_text_displayer.js +17 -0
- package/lib/util/mp4_box_parsers.js +24 -0
- package/lib/util/mp4_parser.js +35 -0
- package/lib/util/player_configuration.js +10 -3
- package/lib/util/stream_utils.js +35 -13
- package/package.json +4 -4
- package/shaka-player.uncompiled.js +1 -0
- package/test/ads/ad_manager_unit.js +3 -1
- package/test/dash/dash_parser_manifest_unit.js +1 -0
- package/test/hls/hls_parser_unit.js +132 -0
- package/test/media/drm_engine_unit.js +11 -1
- package/test/media/media_source_engine_integration.js +78 -2
- package/test/polyfill/media_capabilities_unit.js +259 -0
- package/test/polyfill/patchedmediakeys_apple_unit.js +6 -0
- package/test/test/util/stream_generator.js +212 -8
- package/test/test/util/test_scheme.js +4 -3
- package/test/test/util/util.js +3 -2
- package/test/text/mp4_ttml_parser_unit.js +6 -4
- package/test/text/ttml_text_parser_unit.js +119 -86
- package/test/text/ui_text_displayer_unit.js +76 -0
- package/test/util/stream_utils_unit.js +18 -0
- package/test/util/xml_utils_unit.js +6 -1
- package/third_party/closure-uri/uri.js +1 -1
- package/ui/controls.js +45 -36
|
@@ -40,6 +40,7 @@ describe('HlsParser', () => {
|
|
|
40
40
|
|
|
41
41
|
afterEach(() => {
|
|
42
42
|
shaka.log.alwaysWarn = originalAlwaysWarn;
|
|
43
|
+
parser.stop();
|
|
43
44
|
});
|
|
44
45
|
|
|
45
46
|
beforeEach(() => {
|
|
@@ -1089,6 +1090,77 @@ describe('HlsParser', () => {
|
|
|
1089
1090
|
await testHlsParser(master, media, manifest);
|
|
1090
1091
|
});
|
|
1091
1092
|
|
|
1093
|
+
// https://github.com/shaka-project/shaka-player/issues/4759
|
|
1094
|
+
it('makes roles available without loading tracks', async () => {
|
|
1095
|
+
const master = [
|
|
1096
|
+
'#EXTM3U\n',
|
|
1097
|
+
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1",',
|
|
1098
|
+
'RESOLUTION=960x540,FRAME-RATE=60,AUDIO="aud1",SUBTITLES="sub1"\n',
|
|
1099
|
+
'video\n',
|
|
1100
|
+
|
|
1101
|
+
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="en",',
|
|
1102
|
+
'NAME="English",URI="audio"\n',
|
|
1103
|
+
|
|
1104
|
+
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="en",',
|
|
1105
|
+
'CHARACTERISTICS="public.accessibility.describes-video,',
|
|
1106
|
+
'public.accessibility.describes-music-and-sound",',
|
|
1107
|
+
'NAME="English (describes-video)",URI="audio2"\n',
|
|
1108
|
+
|
|
1109
|
+
'#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub1",LANGUAGE="en",',
|
|
1110
|
+
'NAME="English (caption)",DEFAULT=YES,AUTOSELECT=YES,',
|
|
1111
|
+
'URI="text"\n',
|
|
1112
|
+
|
|
1113
|
+
'#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub1",LANGUAGE="en",',
|
|
1114
|
+
'NAME="English (caption)",DEFAULT=YES,AUTOSELECT=YES,',
|
|
1115
|
+
'CHARACTERISTICS="public.accessibility.describes-spoken-dialog,',
|
|
1116
|
+
'public.accessibility.describes-music-and-sound",',
|
|
1117
|
+
'URI="text2"\n',
|
|
1118
|
+
].join('');
|
|
1119
|
+
|
|
1120
|
+
const manifest = shaka.test.ManifestGenerator.generate((manifest) => {
|
|
1121
|
+
manifest.anyTimeline();
|
|
1122
|
+
manifest.addPartialVariant((variant) => {
|
|
1123
|
+
variant.language = 'en';
|
|
1124
|
+
variant.addPartialStream(ContentType.VIDEO);
|
|
1125
|
+
variant.addPartialStream(ContentType.AUDIO, (stream) => {
|
|
1126
|
+
stream.language = 'en';
|
|
1127
|
+
});
|
|
1128
|
+
});
|
|
1129
|
+
manifest.addPartialVariant((variant) => {
|
|
1130
|
+
variant.language = 'en';
|
|
1131
|
+
variant.addPartialStream(ContentType.VIDEO);
|
|
1132
|
+
variant.addPartialStream(ContentType.AUDIO, (stream) => {
|
|
1133
|
+
stream.language = 'en';
|
|
1134
|
+
stream.roles = [
|
|
1135
|
+
'public.accessibility.describes-video',
|
|
1136
|
+
'public.accessibility.describes-music-and-sound',
|
|
1137
|
+
];
|
|
1138
|
+
});
|
|
1139
|
+
});
|
|
1140
|
+
manifest.addPartialTextStream((stream) => {
|
|
1141
|
+
stream.language = 'en';
|
|
1142
|
+
stream.kind = TextStreamKind.SUBTITLE;
|
|
1143
|
+
});
|
|
1144
|
+
manifest.addPartialTextStream((stream) => {
|
|
1145
|
+
stream.language = 'en';
|
|
1146
|
+
stream.kind = TextStreamKind.SUBTITLE;
|
|
1147
|
+
stream.roles = [
|
|
1148
|
+
'public.accessibility.describes-spoken-dialog',
|
|
1149
|
+
'public.accessibility.describes-music-and-sound',
|
|
1150
|
+
];
|
|
1151
|
+
});
|
|
1152
|
+
manifest.sequenceMode = true;
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
fakeNetEngine.setResponseText('test:/master', master);
|
|
1156
|
+
|
|
1157
|
+
// NOTE: Not using testHlsParser here because that unconditionally loads all
|
|
1158
|
+
// streams. We need to test the behavior specifically when streams are
|
|
1159
|
+
// _not_ loaded.
|
|
1160
|
+
const actual = await parser.start('test:/master', playerInterface);
|
|
1161
|
+
expect(actual).toEqual(manifest);
|
|
1162
|
+
});
|
|
1163
|
+
|
|
1092
1164
|
it('gets mime type from header request', async () => {
|
|
1093
1165
|
const master = [
|
|
1094
1166
|
'#EXTM3U\n',
|
|
@@ -4262,4 +4334,64 @@ describe('HlsParser', () => {
|
|
|
4262
4334
|
expect(actualVideo0.mimeType).toBe('video/mp2t');
|
|
4263
4335
|
expect(actualVideo1.mimeType).toBe('video/mp2t');
|
|
4264
4336
|
});
|
|
4337
|
+
|
|
4338
|
+
it('lazy-loads AAC content without filtering it out', async () => {
|
|
4339
|
+
const master = [
|
|
4340
|
+
'#EXTM3U\n',
|
|
4341
|
+
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",URI="audio"\n',
|
|
4342
|
+
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="spa",URI="audio2"\n',
|
|
4343
|
+
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,mp4a",',
|
|
4344
|
+
'RESOLUTION=960x540,FRAME-RATE=60,AUDIO="aud1"\n',
|
|
4345
|
+
'video\n',
|
|
4346
|
+
].join('');
|
|
4347
|
+
|
|
4348
|
+
const video = [
|
|
4349
|
+
'#EXTM3U\n',
|
|
4350
|
+
'#EXT-X-TARGETDURATION:5\n',
|
|
4351
|
+
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
|
|
4352
|
+
'#EXT-X-MEDIA-SEQUENCE:1\n',
|
|
4353
|
+
'#EXTINF:5,\n',
|
|
4354
|
+
'video1.ts\n',
|
|
4355
|
+
'#EXTINF:5,\n',
|
|
4356
|
+
'video2.ts\n',
|
|
4357
|
+
].join('');
|
|
4358
|
+
|
|
4359
|
+
const audio = [
|
|
4360
|
+
'#EXTM3U\n',
|
|
4361
|
+
'#EXT-X-TARGETDURATION:5\n',
|
|
4362
|
+
'#EXT-X-MEDIA-SEQUENCE:3\n',
|
|
4363
|
+
'#EXTINF:5,\n',
|
|
4364
|
+
'audio1.aac\n',
|
|
4365
|
+
'#EXTINF:5,\n',
|
|
4366
|
+
'audio2.aac\n',
|
|
4367
|
+
].join('');
|
|
4368
|
+
|
|
4369
|
+
fakeNetEngine
|
|
4370
|
+
.setResponseText('test:/master', master)
|
|
4371
|
+
.setResponseText('test:/audio', audio)
|
|
4372
|
+
.setResponseText('test:/audio2', audio)
|
|
4373
|
+
.setResponseText('test:/video', video)
|
|
4374
|
+
.setResponseValue('test:/init.mp4', initSegmentData);
|
|
4375
|
+
|
|
4376
|
+
const actualManifest = await parser.start('test:/master', playerInterface);
|
|
4377
|
+
expect(actualManifest.variants.length).toBe(2);
|
|
4378
|
+
|
|
4379
|
+
const actualAudio0 = actualManifest.variants[0].audio;
|
|
4380
|
+
const actualAudio1 = actualManifest.variants[1].audio;
|
|
4381
|
+
|
|
4382
|
+
// Before loading, all MIME types agree, and are defaulted to audio/mp4.
|
|
4383
|
+
expect(actualAudio0.mimeType).toBe('audio/mp4');
|
|
4384
|
+
expect(actualAudio1.mimeType).toBe('audio/mp4');
|
|
4385
|
+
|
|
4386
|
+
await actualAudio0.createSegmentIndex();
|
|
4387
|
+
|
|
4388
|
+
// After loading just ONE stream, all MIME types agree again, and have been
|
|
4389
|
+
// updated to reflect the AAC content found inside the loaded playlist.
|
|
4390
|
+
// This is how we avoid having the unloaded tracks filtered out during
|
|
4391
|
+
// startup.
|
|
4392
|
+
expect(actualAudio0.mimeType).toBe('audio/aac');
|
|
4393
|
+
expect(actualAudio0.codecs).toBe('');
|
|
4394
|
+
expect(actualAudio1.mimeType).toBe('audio/aac');
|
|
4395
|
+
expect(actualAudio1.codecs).toBe('');
|
|
4396
|
+
});
|
|
4265
4397
|
});
|
|
@@ -120,11 +120,17 @@ describe('DrmEngine', () => {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
drmEngine = new shaka.media.DrmEngine(playerInterface);
|
|
123
|
+
|
|
123
124
|
config = shaka.util.PlayerConfiguration.createDefault().drm;
|
|
124
125
|
config.servers = {
|
|
125
126
|
'drm.abc': 'http://abc.drm/license',
|
|
126
127
|
'drm.def': 'http://def.drm/license',
|
|
127
128
|
};
|
|
129
|
+
// Some platforms, such as Xbox, default to parseInbandPssh: true, which
|
|
130
|
+
// ignores encrypted events. So set it explicitly to false, and let
|
|
131
|
+
// individual tests set it to true where relevant.
|
|
132
|
+
config.parseInbandPsshEnabled = false;
|
|
133
|
+
|
|
128
134
|
drmEngine.configure(config);
|
|
129
135
|
});
|
|
130
136
|
|
|
@@ -2548,7 +2554,11 @@ describe('DrmEngine', () => {
|
|
|
2548
2554
|
*/
|
|
2549
2555
|
async function sendEncryptedEvent(
|
|
2550
2556
|
initDataType = 'cenc', initData = new Uint8Array(1), keyId = null) {
|
|
2551
|
-
|
|
2557
|
+
// For some platforms, such as Xbox, where parseInbandPssh defaults to
|
|
2558
|
+
// true, this listener may never be set.
|
|
2559
|
+
if (mockVideo.on['encrypted']) {
|
|
2560
|
+
mockVideo.on['encrypted']({initDataType, initData, keyId});
|
|
2561
|
+
}
|
|
2552
2562
|
|
|
2553
2563
|
await Util.shortDelay();
|
|
2554
2564
|
}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
describe('MediaSourceEngine', () => {
|
|
8
8
|
const ContentType = shaka.util.ManifestParserUtils.ContentType;
|
|
9
|
+
const Cue = shaka.text.Cue;
|
|
10
|
+
const Util = shaka.test.Util;
|
|
9
11
|
const presentationDuration = 840;
|
|
10
12
|
|
|
11
13
|
/** @type {!HTMLVideoElement} */
|
|
@@ -18,6 +20,64 @@ describe('MediaSourceEngine', () => {
|
|
|
18
20
|
let metadata;
|
|
19
21
|
// TODO: add text streams to MSE integration tests
|
|
20
22
|
|
|
23
|
+
const mp4CeaCue0 = jasmine.objectContaining({
|
|
24
|
+
startTime: Util.closeTo(0.067, 0.001),
|
|
25
|
+
endTime: Util.closeTo(1, 0.001),
|
|
26
|
+
textAlign: Cue.textAlign.CENTER,
|
|
27
|
+
nestedCues: [
|
|
28
|
+
jasmine.objectContaining({
|
|
29
|
+
startTime: Util.closeTo(0.067, 0.001),
|
|
30
|
+
endTime: Util.closeTo(1, 0.001),
|
|
31
|
+
payload: 'eng:⠀00:00:00:00',
|
|
32
|
+
textAlign: Cue.textAlign.CENTER,
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const tsCeaCue0 = jasmine.objectContaining({
|
|
38
|
+
startTime: Util.closeTo(0.767, 0.001),
|
|
39
|
+
endTime: Util.closeTo(4.972, 0.001),
|
|
40
|
+
textAlign: Cue.textAlign.CENTER,
|
|
41
|
+
payload: 'These are 608 captions\n(top left)',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const tsCeaCue1 = jasmine.objectContaining({
|
|
45
|
+
startTime: Util.closeTo(5.305, 0.001),
|
|
46
|
+
endTime: Util.closeTo(11.979, 0.001),
|
|
47
|
+
textAlign: Cue.textAlign.CENTER,
|
|
48
|
+
payload: 'These are 608 captions\n(middle)',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const tsCeaCue2 = jasmine.objectContaining({
|
|
52
|
+
startTime: Util.closeTo(12.312, 0.001),
|
|
53
|
+
endTime: Util.closeTo(19.319, 0.001),
|
|
54
|
+
textAlign: Cue.textAlign.CENTER,
|
|
55
|
+
payload: 'These are 608 captions\n(bottom left)',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// The same segments as above, but offset by 40 seconds (yes, 40), which is
|
|
59
|
+
// also 2 segments.
|
|
60
|
+
const tsCeaCue3 = jasmine.objectContaining({
|
|
61
|
+
startTime: Util.closeTo(40.767, 0.001),
|
|
62
|
+
endTime: Util.closeTo(44.972, 0.001),
|
|
63
|
+
textAlign: Cue.textAlign.CENTER,
|
|
64
|
+
payload: 'These are 608 captions\n(top left)',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const tsCeaCue4 = jasmine.objectContaining({
|
|
68
|
+
startTime: Util.closeTo(45.305, 0.001),
|
|
69
|
+
endTime: Util.closeTo(51.979, 0.001),
|
|
70
|
+
textAlign: Cue.textAlign.CENTER,
|
|
71
|
+
payload: 'These are 608 captions\n(middle)',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const tsCeaCue5 = jasmine.objectContaining({
|
|
75
|
+
startTime: Util.closeTo(52.312, 0.001),
|
|
76
|
+
endTime: Util.closeTo(59.319, 0.001),
|
|
77
|
+
textAlign: Cue.textAlign.CENTER,
|
|
78
|
+
payload: 'These are 608 captions\n(bottom left)',
|
|
79
|
+
});
|
|
80
|
+
|
|
21
81
|
/**
|
|
22
82
|
* We use a fake text displayer so that we can check if CEA text is being
|
|
23
83
|
* passed through the system correctly.
|
|
@@ -394,9 +454,14 @@ describe('MediaSourceEngine', () => {
|
|
|
394
454
|
// platforms with native TS support.
|
|
395
455
|
await mediaSourceEngine.init(initObject, /* forceTransmux= */ true);
|
|
396
456
|
mediaSourceEngine.setSelectedClosedCaptionId('CC1');
|
|
457
|
+
|
|
397
458
|
await append(ContentType.VIDEO, 0);
|
|
398
459
|
|
|
399
460
|
expect(textDisplayer.appendSpy).toHaveBeenCalledTimes(3);
|
|
461
|
+
|
|
462
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([tsCeaCue0]);
|
|
463
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([tsCeaCue1]);
|
|
464
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([tsCeaCue2]);
|
|
400
465
|
});
|
|
401
466
|
|
|
402
467
|
it('extracts CEA-708 captions from previous segment from hls', async () => {
|
|
@@ -413,9 +478,19 @@ describe('MediaSourceEngine', () => {
|
|
|
413
478
|
mediaSourceEngine.setSelectedClosedCaptionId('CC1');
|
|
414
479
|
|
|
415
480
|
await append(ContentType.VIDEO, 2);
|
|
481
|
+
|
|
482
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledTimes(3);
|
|
483
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([tsCeaCue3]);
|
|
484
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([tsCeaCue4]);
|
|
485
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([tsCeaCue5]);
|
|
486
|
+
|
|
487
|
+
textDisplayer.appendSpy.calls.reset();
|
|
416
488
|
await appendWithSeek(ContentType.VIDEO, 0);
|
|
417
489
|
|
|
418
|
-
expect(textDisplayer.appendSpy).toHaveBeenCalledTimes(
|
|
490
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledTimes(3);
|
|
491
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([tsCeaCue0]);
|
|
492
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([tsCeaCue1]);
|
|
493
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([tsCeaCue2]);
|
|
419
494
|
});
|
|
420
495
|
|
|
421
496
|
it('buffers partial TS video segments in sequence mode', async () => {
|
|
@@ -468,7 +543,8 @@ describe('MediaSourceEngine', () => {
|
|
|
468
543
|
mediaSourceEngine.setSelectedClosedCaptionId('CC1');
|
|
469
544
|
await appendWithClosedCaptions(ContentType.VIDEO, 0);
|
|
470
545
|
|
|
471
|
-
expect(textDisplayer.appendSpy).
|
|
546
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledTimes(1);
|
|
547
|
+
expect(textDisplayer.appendSpy).toHaveBeenCalledWith([mp4CeaCue0]);
|
|
472
548
|
});
|
|
473
549
|
|
|
474
550
|
it('extracts ID3 metadata from TS', async () => {
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/*! @license
|
|
2
|
+
* Shaka Player
|
|
3
|
+
* Copyright 2016 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
describe('MediaCapabilities', () => {
|
|
8
|
+
const Util = shaka.test.Util;
|
|
9
|
+
const originalCast = window['cast'];
|
|
10
|
+
const originalVendor = navigator.vendor;
|
|
11
|
+
const originalUserAgent = navigator.userAgent;
|
|
12
|
+
const originalRequestMediaKeySystemAccess =
|
|
13
|
+
navigator.requestMediaKeySystemAccess;
|
|
14
|
+
const originalMediaCapabilities = navigator.mediaCapabilities;
|
|
15
|
+
const supportMap = shaka.media.Capabilities.MediaSourceTypeSupportMap;
|
|
16
|
+
|
|
17
|
+
/** @type {MediaDecodingConfiguration} */
|
|
18
|
+
let mockDecodingConfig;
|
|
19
|
+
/** @type {!jasmine.Spy} */
|
|
20
|
+
let mockCanDisplayType;
|
|
21
|
+
|
|
22
|
+
beforeAll(() => {
|
|
23
|
+
Object.defineProperty(window['navigator'],
|
|
24
|
+
'userAgent', {
|
|
25
|
+
value: 'unknown', configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(window['navigator'],
|
|
29
|
+
'vendor', {
|
|
30
|
+
value: 'unknown', configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(window['navigator'],
|
|
34
|
+
'requestMediaKeySystemAccess', {
|
|
35
|
+
value: 'unknown', configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(window['navigator'],
|
|
39
|
+
'mediaCapabilities', {
|
|
40
|
+
value: undefined, configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
mockDecodingConfig = {
|
|
47
|
+
audio: {
|
|
48
|
+
bitrate: 100891,
|
|
49
|
+
channels: 2,
|
|
50
|
+
contentType: 'audio/mp4; codecs="mp4a.40.2"',
|
|
51
|
+
samplerate: 48000,
|
|
52
|
+
spatialRendering: false,
|
|
53
|
+
},
|
|
54
|
+
keySystemConfiguration: {
|
|
55
|
+
audio: {robustness: 'SW_SECURE_CRYPTO'},
|
|
56
|
+
distinctiveIdentifier: 'optional',
|
|
57
|
+
initDataType: 'cenc',
|
|
58
|
+
keySystem: 'com.widevine.alpha',
|
|
59
|
+
persistentState: 'optional',
|
|
60
|
+
sessionTypes: ['temporary'],
|
|
61
|
+
video: {robustness: 'SW_SECURE_CRYPTO'},
|
|
62
|
+
},
|
|
63
|
+
type: 'media-source',
|
|
64
|
+
video: {
|
|
65
|
+
bitrate: 349265,
|
|
66
|
+
contentType: 'video/mp4; codecs="avc1.4D4015"',
|
|
67
|
+
framerate: 23.976023976023978,
|
|
68
|
+
height: 288,
|
|
69
|
+
width: 512,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
shaka.polyfill.MediaCapabilities.memoizedMediaKeySystemAccessRequests_ = {};
|
|
73
|
+
|
|
74
|
+
mockCanDisplayType = jasmine.createSpy('canDisplayType');
|
|
75
|
+
mockCanDisplayType.and.returnValue(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
window['cast'] = originalCast;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterAll(() => {
|
|
83
|
+
window['cast'] = originalCast;
|
|
84
|
+
Object.defineProperty(window['navigator'],
|
|
85
|
+
'userAgent', {value: originalUserAgent});
|
|
86
|
+
Object.defineProperty(window['navigator'],
|
|
87
|
+
'vendor', {value: originalVendor});
|
|
88
|
+
Object.defineProperty(window['navigator'],
|
|
89
|
+
'requestMediaKeySystemAccess',
|
|
90
|
+
{value: originalRequestMediaKeySystemAccess});
|
|
91
|
+
Object.defineProperty(window['navigator'],
|
|
92
|
+
'mediaCapabilities', {value: originalMediaCapabilities});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('install', () => {
|
|
96
|
+
it('should define decoding info method', () => {
|
|
97
|
+
shaka.polyfill.MediaCapabilities.install();
|
|
98
|
+
|
|
99
|
+
expect(navigator.mediaCapabilities.decodingInfo).toBeDefined();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('decodingInfo', () => {
|
|
104
|
+
it('should check codec support when MediaDecodingConfiguration.type ' +
|
|
105
|
+
'is "media-source"', () => {
|
|
106
|
+
expect(window['MediaSource']['isTypeSupported']).toBeDefined();
|
|
107
|
+
shaka.polyfill.MediaCapabilities.install();
|
|
108
|
+
navigator.mediaCapabilities.decodingInfo(mockDecodingConfig);
|
|
109
|
+
|
|
110
|
+
expect(supportMap.has(mockDecodingConfig.video.contentType)).toBe(true);
|
|
111
|
+
expect(supportMap.has(mockDecodingConfig.audio.contentType)).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should check codec support when MediaDecodingConfiguration.type ' +
|
|
115
|
+
'is "file"', () => {
|
|
116
|
+
const supportsMediaTypeSpy =
|
|
117
|
+
spyOn(shaka['util']['Platform'],
|
|
118
|
+
'supportsMediaType').and.returnValue(true);
|
|
119
|
+
mockDecodingConfig.type = 'file';
|
|
120
|
+
shaka.polyfill.MediaCapabilities.install();
|
|
121
|
+
navigator.mediaCapabilities.decodingInfo(mockDecodingConfig);
|
|
122
|
+
|
|
123
|
+
expect(supportsMediaTypeSpy).toHaveBeenCalledTimes(2);
|
|
124
|
+
expect(supportsMediaTypeSpy).toHaveBeenCalledWith(
|
|
125
|
+
mockDecodingConfig.video.contentType,
|
|
126
|
+
);
|
|
127
|
+
expect(supportsMediaTypeSpy).toHaveBeenCalledWith(
|
|
128
|
+
mockDecodingConfig.audio.contentType,
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should check MediaKeySystem when keySystemConfiguration is present',
|
|
133
|
+
async () => {
|
|
134
|
+
const mockResult = {mockKeySystemAccess: 'mockKeySystemAccess'};
|
|
135
|
+
spyOn(window['MediaSource'], 'isTypeSupported').and.returnValue(true);
|
|
136
|
+
const requestKeySystemAccessSpy =
|
|
137
|
+
spyOn(window['navigator'],
|
|
138
|
+
'requestMediaKeySystemAccess').and.returnValue(mockResult);
|
|
139
|
+
|
|
140
|
+
shaka.polyfill.MediaCapabilities.install();
|
|
141
|
+
const result = await navigator.mediaCapabilities
|
|
142
|
+
.decodingInfo(mockDecodingConfig);
|
|
143
|
+
|
|
144
|
+
expect(requestKeySystemAccessSpy).toHaveBeenCalledWith(
|
|
145
|
+
'com.widevine.alpha',
|
|
146
|
+
[{
|
|
147
|
+
audioCapabilities: [
|
|
148
|
+
{
|
|
149
|
+
robustness: 'SW_SECURE_CRYPTO',
|
|
150
|
+
contentType: 'audio/mp4; codecs="mp4a.40.2"',
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
distinctiveIdentifier: 'optional',
|
|
154
|
+
initDataTypes: ['cenc'],
|
|
155
|
+
persistentState: 'optional',
|
|
156
|
+
sessionTypes: ['temporary'],
|
|
157
|
+
videoCapabilities: [{
|
|
158
|
+
robustness: 'SW_SECURE_CRYPTO',
|
|
159
|
+
contentType: 'video/mp4; codecs="avc1.4D4015"',
|
|
160
|
+
}],
|
|
161
|
+
}],
|
|
162
|
+
);
|
|
163
|
+
expect(result.keySystemAccess).toEqual(mockResult);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('throws when the cast namespace is not available', async () => {
|
|
167
|
+
// Temporarily remove window.cast to trigger error. It's restored after
|
|
168
|
+
// every test.
|
|
169
|
+
delete window['cast'];
|
|
170
|
+
|
|
171
|
+
const isChromecastSpy =
|
|
172
|
+
spyOn(shaka['util']['Platform'],
|
|
173
|
+
'isChromecast').and.returnValue(true);
|
|
174
|
+
const expected = Util.jasmineError(new shaka.util.Error(
|
|
175
|
+
shaka.util.Error.Severity.CRITICAL,
|
|
176
|
+
shaka.util.Error.Category.CAST,
|
|
177
|
+
shaka.util.Error.Code.CAST_API_UNAVAILABLE));
|
|
178
|
+
const isTypeSupportedSpy =
|
|
179
|
+
spyOn(window['MediaSource'], 'isTypeSupported').and.returnValue(true);
|
|
180
|
+
|
|
181
|
+
shaka.polyfill.MediaCapabilities.install();
|
|
182
|
+
await expectAsync(
|
|
183
|
+
navigator.mediaCapabilities.decodingInfo(mockDecodingConfig))
|
|
184
|
+
.toBeRejectedWith(expected);
|
|
185
|
+
|
|
186
|
+
expect(isTypeSupportedSpy).not.toHaveBeenCalled();
|
|
187
|
+
// 1 (during install()) + 1 (for video config check).
|
|
188
|
+
expect(isChromecastSpy).toHaveBeenCalledTimes(2);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('falls back to isTypeSupported() when canDisplayType() missing',
|
|
192
|
+
async () => {
|
|
193
|
+
// We only set the cast namespace, but not the canDisplayType() API.
|
|
194
|
+
window['cast'] = {};
|
|
195
|
+
const isChromecastSpy =
|
|
196
|
+
spyOn(shaka['util']['Platform'],
|
|
197
|
+
'isChromecast').and.returnValue(true);
|
|
198
|
+
expect(window['MediaSource']['isTypeSupported']).toBeDefined();
|
|
199
|
+
|
|
200
|
+
shaka.polyfill.MediaCapabilities.install();
|
|
201
|
+
await navigator.mediaCapabilities.decodingInfo(mockDecodingConfig);
|
|
202
|
+
|
|
203
|
+
expect(mockCanDisplayType).not.toHaveBeenCalled();
|
|
204
|
+
// 1 (during install()) + 1 (for video config check).
|
|
205
|
+
expect(isChromecastSpy).toHaveBeenCalledTimes(2);
|
|
206
|
+
// 1 (fallback in canCastDisplayType()) +
|
|
207
|
+
// 1 (mockDecodingConfig.audio).
|
|
208
|
+
expect(supportMap.has(mockDecodingConfig.video.contentType))
|
|
209
|
+
.toBe(true);
|
|
210
|
+
expect(supportMap.has(mockDecodingConfig.audio.contentType))
|
|
211
|
+
.toBe(true);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('should use cast.__platform__.canDisplayType for "supported" field ' +
|
|
215
|
+
'when platform is Cast', async () => {
|
|
216
|
+
// We're using quotes to access window.cast because the compiler
|
|
217
|
+
// knows about lots of Cast-specific APIs we aren't mocking. We
|
|
218
|
+
// don't need this mock strictly type-checked.
|
|
219
|
+
window['cast'] = {
|
|
220
|
+
__platform__: {canDisplayType: mockCanDisplayType},
|
|
221
|
+
};
|
|
222
|
+
const isChromecastSpy =
|
|
223
|
+
spyOn(shaka['util']['Platform'],
|
|
224
|
+
'isChromecast').and.returnValue(true);
|
|
225
|
+
expect(window['MediaSource']['isTypeSupported']).toBeDefined();
|
|
226
|
+
|
|
227
|
+
// Tests an HDR stream's extended MIME type is correctly provided.
|
|
228
|
+
mockDecodingConfig.video.transferFunction = 'pq';
|
|
229
|
+
mockDecodingConfig.video.contentType =
|
|
230
|
+
'video/mp4; codecs="hev1.2.4.L153.B0"';
|
|
231
|
+
// Round to a whole number since we can't rely on number => string
|
|
232
|
+
// conversion precision on all devices.
|
|
233
|
+
mockDecodingConfig.video.framerate = 24;
|
|
234
|
+
|
|
235
|
+
const chromecastType =
|
|
236
|
+
'video/mp4; ' +
|
|
237
|
+
'codecs="hev1.2.4.L153.B0"; ' +
|
|
238
|
+
'width=512; ' +
|
|
239
|
+
'height=288; ' +
|
|
240
|
+
'framerate=24; ' +
|
|
241
|
+
'eotf=smpte2084';
|
|
242
|
+
mockCanDisplayType.and.callFake((type) => {
|
|
243
|
+
expect(type).toBe(chromecastType);
|
|
244
|
+
supportMap.set(type, true);
|
|
245
|
+
return true;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
shaka.polyfill.MediaCapabilities.install();
|
|
249
|
+
await navigator.mediaCapabilities.decodingInfo(mockDecodingConfig);
|
|
250
|
+
|
|
251
|
+
// 1 (during install()) + 1 (for video config check).
|
|
252
|
+
expect(isChromecastSpy).toHaveBeenCalledTimes(2);
|
|
253
|
+
// 1 (mockDecodingConfig.audio).
|
|
254
|
+
expect(supportMap.has(chromecastType)).toBe(true);
|
|
255
|
+
// Called once in canCastDisplayType.
|
|
256
|
+
expect(mockCanDisplayType).toHaveBeenCalledTimes(1);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|