shaka-player 4.2.5 → 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.
Files changed (143) hide show
  1. package/.github/workflows/build-and-test.yaml +7 -0
  2. package/.github/workflows/sync-labels.yaml +1 -1
  3. package/.github/workflows/update-issues.yaml +1 -1
  4. package/AUTHORS +4 -0
  5. package/CHANGELOG.md +114 -74
  6. package/CONTRIBUTORS +4 -0
  7. package/README.md +14 -0
  8. package/conditional/dummy_cast_proxy.js +120 -0
  9. package/demo/common/assets.js +58 -0
  10. package/demo/common/message_ids.js +22 -1
  11. package/demo/config.js +89 -5
  12. package/demo/demo.less +7 -1
  13. package/demo/index.html +8 -1
  14. package/demo/locales/en.json +21 -1
  15. package/demo/locales/source.json +82 -2
  16. package/demo/main.js +57 -1
  17. package/demo/search.js +2 -0
  18. package/demo/visualizer.js +337 -0
  19. package/demo/visualizer_button.js +103 -0
  20. package/dist/controls.css +1 -1
  21. package/dist/controls.css.map +1 -1
  22. package/dist/demo.compiled.debug.js +107 -88
  23. package/dist/demo.compiled.debug.map +4 -4
  24. package/dist/demo.compiled.js +107 -88
  25. package/dist/demo.compiled.map +4 -4
  26. package/dist/demo.css +1 -1
  27. package/dist/demo.css.map +1 -1
  28. package/dist/deps.js +21 -13
  29. package/dist/locales.js +31 -31
  30. package/dist/receiver.compiled.debug.js +75 -77
  31. package/dist/receiver.compiled.debug.map +3 -3
  32. package/dist/receiver.compiled.js +75 -77
  33. package/dist/receiver.compiled.map +3 -3
  34. package/dist/shaka-player.compiled.d.ts +181 -27
  35. package/dist/shaka-player.compiled.debug.d.ts +181 -27
  36. package/dist/shaka-player.compiled.debug.externs.js +169 -31
  37. package/dist/shaka-player.compiled.debug.js +510 -450
  38. package/dist/shaka-player.compiled.debug.map +4 -4
  39. package/dist/shaka-player.compiled.externs.js +169 -31
  40. package/dist/shaka-player.compiled.js +912 -874
  41. package/dist/shaka-player.compiled.map +4 -4
  42. package/dist/shaka-player.ui.d.ts +181 -27
  43. package/dist/shaka-player.ui.debug.d.ts +181 -27
  44. package/dist/shaka-player.ui.debug.externs.js +169 -31
  45. package/dist/shaka-player.ui.debug.js +533 -471
  46. package/dist/shaka-player.ui.debug.map +4 -4
  47. package/dist/shaka-player.ui.externs.js +169 -31
  48. package/dist/shaka-player.ui.js +1073 -1036
  49. package/dist/shaka-player.ui.map +4 -4
  50. package/docs/design/lcevc-architecture.png +0 -0
  51. package/docs/design/lcevc-demo.png +0 -0
  52. package/docs/design/lcevc-integration.md +72 -0
  53. package/docs/tutorials/fairplay.md +7 -0
  54. package/docs/tutorials/faq.md +1 -1
  55. package/docs/tutorials/ui.md +7 -7
  56. package/docs/tutorials/upgrade.md +6 -0
  57. package/externs/ima.js +13 -1
  58. package/externs/lcevc.js +81 -0
  59. package/externs/mux.js +1 -42
  60. package/externs/shaka/ads.js +11 -1
  61. package/externs/shaka/manifest_parser.js +5 -1
  62. package/externs/shaka/mp4_parser.js +3 -0
  63. package/externs/shaka/player.js +178 -15
  64. package/lib/abr/simple_abr_manager.js +7 -0
  65. package/lib/ads/ad_manager.js +0 -8
  66. package/lib/ads/client_side_ad.js +15 -0
  67. package/lib/ads/client_side_ad_manager.js +21 -8
  68. package/lib/ads/server_side_ad.js +15 -0
  69. package/lib/ads/server_side_ad_manager.js +3 -3
  70. package/lib/cast/cast_utils.js +2 -0
  71. package/lib/cea/dummy_cea_parser.js +28 -0
  72. package/lib/cea/i_cea_parser.js +14 -2
  73. package/lib/cea/mp4_cea_parser.js +108 -5
  74. package/lib/config/auto_show_text.js +33 -0
  75. package/lib/dash/dash_parser.js +1 -1
  76. package/lib/hls/hls_parser.js +808 -384
  77. package/lib/lcevc/lcevc_dil.js +152 -0
  78. package/lib/media/closed_caption_parser.js +9 -6
  79. package/lib/media/drm_engine.js +14 -6
  80. package/lib/media/media_source_capabilities.js +36 -0
  81. package/lib/media/media_source_engine.js +113 -28
  82. package/lib/media/presentation_timeline.js +26 -11
  83. package/lib/media/segment_reference.js +49 -1
  84. package/lib/media/streaming_engine.js +142 -12
  85. package/lib/media/transmuxer.js +78 -21
  86. package/lib/offline/storage.js +1 -0
  87. package/lib/player.js +456 -77
  88. package/lib/polyfill/media_capabilities.js +9 -5
  89. package/lib/polyfill/patchedmediakeys_apple.js +63 -4
  90. package/lib/text/vtt_text_parser.js +35 -1
  91. package/lib/util/dom_utils.js +0 -1
  92. package/lib/util/error.js +17 -0
  93. package/lib/util/fake_event.js +2 -0
  94. package/lib/util/id3_utils.js +300 -0
  95. package/lib/util/mime_utils.js +3 -6
  96. package/lib/util/mp4_box_parsers.js +39 -5
  97. package/lib/util/mp4_parser.js +35 -0
  98. package/lib/util/player_configuration.js +23 -1
  99. package/lib/util/stream_utils.js +5 -3
  100. package/lib/util/ts_parser.js +499 -0
  101. package/maintained-branches.md +2 -2
  102. package/package.json +7 -4
  103. package/roadmap.md +5 -3
  104. package/test/ads/ad_manager_unit.js +182 -29
  105. package/test/cast/cast_utils_unit.js +3 -1
  106. package/test/dash/dash_parser_content_protection_unit.js +1 -0
  107. package/test/dash/dash_parser_live_unit.js +1 -0
  108. package/test/dash/dash_parser_manifest_unit.js +93 -1
  109. package/test/dash/dash_parser_segment_base_unit.js +1 -0
  110. package/test/dash/dash_parser_segment_list_unit.js +1 -0
  111. package/test/dash/dash_parser_segment_template_unit.js +1 -0
  112. package/test/demo/demo_unit.js +2 -1
  113. package/test/hls/hls_live_unit.js +253 -19
  114. package/test/hls/hls_parser_unit.js +631 -12
  115. package/test/media/closed_caption_parser_unit.js +2 -1
  116. package/test/media/drm_engine_integration.js +3 -1
  117. package/test/media/media_source_engine_integration.js +71 -6
  118. package/test/media/media_source_engine_unit.js +10 -5
  119. package/test/media/streaming_engine_integration.js +4 -1
  120. package/test/media/streaming_engine_unit.js +144 -1
  121. package/test/media/transmuxer_integration.js +21 -10
  122. package/test/player_integration.js +224 -82
  123. package/test/player_unit.js +5 -2
  124. package/test/polyfill/media_capabilities_unit.js +21 -23
  125. package/test/polyfill/patchedmediakeys_apple_unit.js +130 -0
  126. package/test/test/assets/id3-metadata.aac +0 -0
  127. package/test/test/assets/id3-metadata.ts +0 -0
  128. package/test/test/assets/thumbnails-sprites.vtt +10 -0
  129. package/test/test/assets/thumbnails.vtt +10 -0
  130. package/test/test/util/dash_parser_util.js +2 -0
  131. package/test/test/util/fake_ad.js +21 -0
  132. package/test/test/util/fake_media_source_engine.js +7 -0
  133. package/test/test/util/id3_generator.js +100 -0
  134. package/test/test/util/manifest_generator.js +3 -6
  135. package/test/test/util/simple_fakes.js +4 -0
  136. package/test/test/util/stream_generator.js +38 -0
  137. package/test/test/util/test_scheme.js +43 -14
  138. package/test/text/vtt_text_parser_unit.js +11 -0
  139. package/test/util/id3_utils_unit.js +116 -0
  140. package/test/util/ts_parser_unit.js +77 -0
  141. package/third_party/closure-uri/uri.js +1 -1
  142. package/ui/less/containers.less +7 -0
  143. package/ui/ui.js +43 -4
@@ -78,6 +78,7 @@ describe('HlsParser live', () => {
78
78
  isAutoLowLatencyMode: () => false,
79
79
  enableLowLatencyMode: () => {},
80
80
  updateDuration: () => {},
81
+ newDrmInfo: (stream) => {},
81
82
  };
82
83
 
83
84
  parser = new shaka.hls.HlsParser();
@@ -100,18 +101,16 @@ describe('HlsParser live', () => {
100
101
 
101
102
  /**
102
103
  * @param {string} master
103
- * @param {string} initialMedia
104
- * @param {Array=} initialReferences
105
- * @return {!Promise.<shaka.extern.Manifest>}
104
+ * @param {string} media1
105
+ * @param {string} media2
106
106
  */
107
- async function testInitialManifest(
108
- master, initialMedia, initialReferences=null) {
107
+ function configureNetEngineForInitialManifest(master, media1, media2) {
109
108
  fakeNetEngine
110
109
  .setResponseText('test:/master', master)
111
- .setResponseText('test:/video', initialMedia)
112
- .setResponseText('test:/redirected/video', initialMedia)
113
- .setResponseText('test:/video2', initialMedia)
114
- .setResponseText('test:/audio', initialMedia)
110
+ .setResponseText('test:/video', media1)
111
+ .setResponseText('test:/redirected/video', media1)
112
+ .setResponseText('test:/video2', media2)
113
+ .setResponseText('test:/audio', media1)
115
114
  .setResponseValue('test:/init.mp4', initSegmentData)
116
115
  .setResponseValue('test:/main.mp4', segmentData)
117
116
  .setResponseValue('test:/main2.mp4', segmentData)
@@ -120,24 +119,35 @@ describe('HlsParser live', () => {
120
119
  .setResponseValue('test:/partial.mp4', segmentData)
121
120
  .setResponseValue('test:/partial2.mp4', segmentData)
122
121
  .setResponseValue('test:/selfInit.mp4', selfInitializingSegmentData);
122
+ }
123
+
124
+ /**
125
+ * @param {string} master
126
+ * @param {string} initialMedia
127
+ * @param {Array=} initialReferences
128
+ * @return {!Promise.<shaka.extern.Manifest>}
129
+ */
130
+ async function testInitialManifest(
131
+ master, initialMedia, initialReferences=null) {
132
+ configureNetEngineForInitialManifest(master, initialMedia, initialMedia);
123
133
 
124
134
  const manifest = await parser.start('test:/master', playerInterface);
125
135
 
126
- if (initialReferences) {
127
- await Promise.all(manifest.variants.map(async (variant) => {
128
- await variant.video.createSegmentIndex();
136
+ // Create the segment index for the variants, to finish the lazy-loading.
137
+ await Promise.all(manifest.variants.map(async (variant) => {
138
+ await variant.video.createSegmentIndex();
129
139
 
130
- // The compiler doesn't count null checks done outside this callback,
131
- // so we need an assertion here.
132
- goog.asserts.assert(initialReferences != null, 'references non-null');
140
+ if (initialReferences) {
133
141
  ManifestParser.verifySegmentIndex(variant.video, initialReferences);
142
+ }
134
143
 
135
- if (variant.audio) {
136
- await variant.audio.createSegmentIndex();
144
+ if (variant.audio) {
145
+ await variant.audio.createSegmentIndex();
146
+ if (initialReferences) {
137
147
  ManifestParser.verifySegmentIndex(variant.audio, initialReferences);
138
148
  }
139
- }));
140
- }
149
+ }
150
+ }));
141
151
 
142
152
  return manifest;
143
153
  }
@@ -415,6 +425,26 @@ describe('HlsParser live', () => {
415
425
  'main2.mp4\n',
416
426
  ].join('');
417
427
 
428
+ const mediaWithAdditionalSegment2 = [
429
+ '#EXTM3U\n',
430
+ '#EXT-X-TARGETDURATION:5\n',
431
+ '#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
432
+ '#EXT-X-MEDIA-SEQUENCE:0\n',
433
+ '#EXTINF:2,\n',
434
+ 'main3.mp4\n',
435
+ '#EXTINF:2,\n',
436
+ 'main4.mp4\n',
437
+ ].join('');
438
+
439
+ const mediaWithRemovedSegment2 = [
440
+ '#EXTM3U\n',
441
+ '#EXT-X-TARGETDURATION:5\n',
442
+ '#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
443
+ '#EXT-X-MEDIA-SEQUENCE:1\n',
444
+ '#EXTINF:2,\n',
445
+ 'main4.mp4\n',
446
+ ].join('');
447
+
418
448
  let mediaWithManySegments = [
419
449
  '#EXTM3U\n',
420
450
  '#EXT-X-TARGETDURATION:5\n',
@@ -668,6 +698,93 @@ describe('HlsParser live', () => {
668
698
  await testUpdate(manifest, mediaWithRemovedSegment, [ref2]);
669
699
  });
670
700
 
701
+ it('has correct references if switching after update', async () => {
702
+ const ref1 = makeReference(
703
+ 'test:/main.mp4', 0, 2, /* syncTime= */ null);
704
+ const ref2 = makeReference(
705
+ 'test:/main2.mp4', 2, 4, /* syncTime= */ null);
706
+ const ref4 = makeReference(
707
+ 'test:/main4.mp4', 2, 4, /* syncTime= */ null);
708
+
709
+ const secondVariant = [
710
+ '#EXT-X-STREAM-INF:BANDWIDTH=300,CODECS="avc1",',
711
+ 'RESOLUTION=1200x940,FRAME-RATE=60\n',
712
+ 'video2',
713
+ ].join('');
714
+ const masterWithTwoVariants = master + secondVariant;
715
+ configureNetEngineForInitialManifest(masterWithTwoVariants,
716
+ mediaWithAdditionalSegment, mediaWithAdditionalSegment2);
717
+
718
+ const manifest = await parser.start('test:/master', playerInterface);
719
+ await manifest.variants[0].video.createSegmentIndex();
720
+ ManifestParser.verifySegmentIndex(
721
+ manifest.variants[0].video, [ref1, ref2]);
722
+ expect(manifest.variants[1].video.segmentIndex).toBeNull();
723
+
724
+ // Update.
725
+ fakeNetEngine
726
+ .setResponseText('test:/video', mediaWithRemovedSegment)
727
+ .setResponseText('test:/video2', mediaWithRemovedSegment2);
728
+ await delayForUpdatePeriod();
729
+
730
+ // Switch.
731
+ await manifest.variants[0].video.closeSegmentIndex();
732
+ await manifest.variants[1].video.createSegmentIndex();
733
+
734
+ // Check for variants to be as expected.
735
+ expect(manifest.variants[0].video.segmentIndex).toBeNull();
736
+ ManifestParser.verifySegmentIndex(
737
+ manifest.variants[1].video, [ref4]);
738
+ });
739
+
740
+ it('handles switching during update', async () => {
741
+ const ref1 = makeReference(
742
+ 'test:/main.mp4', 0, 2, /* syncTime= */ null);
743
+ const ref2 = makeReference(
744
+ 'test:/main2.mp4', 2, 4, /* syncTime= */ null);
745
+ const ref4 = makeReference(
746
+ 'test:/main4.mp4', 2, 4, /* syncTime= */ null);
747
+
748
+ const secondVariant = [
749
+ '#EXT-X-STREAM-INF:BANDWIDTH=300,CODECS="avc1",',
750
+ 'RESOLUTION=1200x940,FRAME-RATE=60\n',
751
+ 'video2',
752
+ ].join('');
753
+ const masterWithTwoVariants = master + secondVariant;
754
+ configureNetEngineForInitialManifest(masterWithTwoVariants,
755
+ mediaWithAdditionalSegment, mediaWithAdditionalSegment2);
756
+
757
+ const manifest = await parser.start('test:/master', playerInterface);
758
+ await manifest.variants[0].video.createSegmentIndex();
759
+ ManifestParser.verifySegmentIndex(
760
+ manifest.variants[0].video, [ref1, ref2]);
761
+ expect(manifest.variants[1].video.segmentIndex).toBe(null);
762
+
763
+ // Update.
764
+ fakeNetEngine
765
+ .setResponseText('test:/video', mediaWithRemovedSegment)
766
+ .setResponseText('test:/video2', mediaWithRemovedSegment2);
767
+
768
+ const updatePromise = parser.update();
769
+
770
+ // Verify that the update is not yet complete.
771
+ expect(manifest.variants[0].video.segmentIndex).not.toBe(null);
772
+ ManifestParser.verifySegmentIndex(
773
+ manifest.variants[0].video, [ref1, ref2]);
774
+
775
+ // Mid-update, switch.
776
+ await manifest.variants[0].video.closeSegmentIndex();
777
+ await manifest.variants[1].video.createSegmentIndex();
778
+
779
+ // Finish the update.
780
+ await updatePromise;
781
+
782
+ // Check for variants to be as expected.
783
+ expect(manifest.variants[0].video.segmentIndex).toBe(null);
784
+ ManifestParser.verifySegmentIndex(
785
+ manifest.variants[1].video, [ref4]);
786
+ });
787
+
671
788
  it('handles updates with redirects', async () => {
672
789
  const oldRef1 = makeReference(
673
790
  'test:/main.mp4', 0, 2, /* syncTime= */ null);
@@ -888,7 +1005,124 @@ describe('HlsParser live', () => {
888
1005
  await testUpdate(
889
1006
  manifest, mediaWithSkippedSegments2, [ref1, ref2, ref3, ref4]);
890
1007
  });
1008
+
1009
+ it('updates encryption keys', async () => {
1010
+ const initialKey = 'abc123';
1011
+ const media = [
1012
+ '#EXTM3U\n',
1013
+ '#EXT-X-TARGETDURATION:6\n',
1014
+ '#EXT-X-PLAYLIST-TYPE:EVENT\n',
1015
+ '#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,',
1016
+ 'KEYID=0X' + initialKey + ',',
1017
+ 'KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed",',
1018
+ 'URI="data:text/plain;base64,',
1019
+ 'dGhpcyBpbml0IGRhdGEgY29udGFpbnMgaGlkZGVuIHNlY3JldHMhISE', '",\n',
1020
+ '#EXT-X-MAP:URI="init.mp4"\n',
1021
+ '#EXTINF:5,\n',
1022
+ '#EXT-X-BYTERANGE:121090@616\n',
1023
+ 'main.mp4',
1024
+ ].join('');
1025
+
1026
+ const updatedKey = 'xyz345';
1027
+ const updatedMedia = [
1028
+ '#EXTM3U\n',
1029
+ '#EXT-X-TARGETDURATION:6\n',
1030
+ '#EXT-X-PLAYLIST-TYPE:EVENT\n',
1031
+ '#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,',
1032
+ 'KEYID=0X' + updatedKey + ',',
1033
+ 'KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed",',
1034
+ 'URI="data:text/plain;base64,',
1035
+ 'dGhpcyBpbml0IGRhdGEgY29udGFpbnMgaGlkZGVuIHNlY3JldHMhISE', '",\n',
1036
+ '#EXT-X-MAP:URI="init.mp4"\n',
1037
+ '#EXTINF:5,\n',
1038
+ '#EXT-X-BYTERANGE:121090@616\n',
1039
+ 'main.mp4',
1040
+ ].join('');
1041
+
1042
+ const manifest = await testInitialManifest(master, media, null);
1043
+ await testUpdate(manifest, updatedMedia, null);
1044
+ const keys = Array.from(manifest.variants[0].video.keyIds);
1045
+ expect(keys[0]).toBe(updatedKey);
1046
+ });
891
1047
  }); // describe('update')
1048
+
1049
+ describe('createSegmentIndex', () => {
1050
+ it('handles multiple concurrent calls', async () => {
1051
+ const secondVariant = [
1052
+ '#EXT-X-STREAM-INF:BANDWIDTH=300,CODECS="avc1",',
1053
+ 'RESOLUTION=1200x940,FRAME-RATE=60\n',
1054
+ 'video2',
1055
+ ].join('');
1056
+ const masterWithTwoVariants = master + secondVariant;
1057
+ configureNetEngineForInitialManifest(masterWithTwoVariants,
1058
+ mediaWithAdditionalSegment, mediaWithAdditionalSegment2);
1059
+
1060
+ const manifest = await parser.start('test:/master', playerInterface);
1061
+
1062
+ // No segment index yet.
1063
+ expect(manifest.variants[0].video.segmentIndex).toBe(null);
1064
+
1065
+ // Make two calls to create the segment index.
1066
+ const created1 = manifest.variants[0].video.createSegmentIndex();
1067
+ const created2 = manifest.variants[0].video.createSegmentIndex();
1068
+
1069
+ // Still no segment index yet.
1070
+ expect(manifest.variants[0].video.segmentIndex).toBe(null);
1071
+
1072
+ // Without caring what order these Promises complete in, we should be
1073
+ // able to see that neither resolves without a full segment index being
1074
+ // ready.
1075
+ created1.then(() => {
1076
+ expect(manifest.variants[0].video.segmentIndex).not.toBe(null);
1077
+ });
1078
+ created2.then(() => {
1079
+ expect(manifest.variants[0].video.segmentIndex).not.toBe(null);
1080
+ });
1081
+
1082
+ // Now wait for both Promises to resolve.
1083
+ await Promise.all([created1, created2]);
1084
+ });
1085
+
1086
+ it('handles switching during createSegmentIndex', async () => {
1087
+ const secondVariant = [
1088
+ '#EXT-X-STREAM-INF:BANDWIDTH=300,CODECS="avc1",',
1089
+ 'RESOLUTION=1200x940,FRAME-RATE=60\n',
1090
+ 'video2',
1091
+ ].join('');
1092
+ const masterWithTwoVariants = master + secondVariant;
1093
+ configureNetEngineForInitialManifest(masterWithTwoVariants,
1094
+ mediaWithAdditionalSegment, mediaWithAdditionalSegment2);
1095
+
1096
+ const manifest = await parser.start('test:/master', playerInterface);
1097
+
1098
+ // No segment index yet.
1099
+ expect(manifest.variants[0].video.segmentIndex).toBe(null);
1100
+
1101
+ // Make a call to create the segment index.
1102
+ const created1 = manifest.variants[0].video.createSegmentIndex();
1103
+
1104
+ // Still no segment index yet.
1105
+ expect(manifest.variants[0].video.segmentIndex).toBe(null);
1106
+
1107
+ // Mid-create, switch.
1108
+ await manifest.variants[0].video.closeSegmentIndex();
1109
+ const created2 = manifest.variants[1].video.createSegmentIndex();
1110
+
1111
+ // Finish the original creation call.
1112
+ await created1;
1113
+
1114
+ // The first segment index should never have been created, because the
1115
+ // close call should have cancelled the work in progress.
1116
+ expect(manifest.variants[0].video.segmentIndex).toBe(null);
1117
+
1118
+ // Finish the second creation call.
1119
+ await created2;
1120
+
1121
+ // The second segment index is complete, because the create call was
1122
+ // never interrupted.
1123
+ expect(manifest.variants[1].video.segmentIndex).not.toBe(null);
1124
+ });
1125
+ }); // describe('createSegmentIndex')
892
1126
  }); // describe('playlist type LIVE')
893
1127
 
894
1128
  /**