shaka-player 4.3.11 → 4.4.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 (315) hide show
  1. package/AUTHORS +9 -0
  2. package/CHANGELOG.md +303 -202
  3. package/CONTRIBUTORS +8 -0
  4. package/LICENSE +32 -0
  5. package/README.md +63 -10
  6. package/demo/autoTemplate.txt +40 -5
  7. package/demo/close_button.js +11 -0
  8. package/demo/common/asset.js +13 -1
  9. package/demo/common/assets.js +53 -3
  10. package/demo/common/message_ids.js +25 -1
  11. package/demo/config.js +69 -10
  12. package/demo/customWarning.txt +2 -2
  13. package/demo/index.html +3 -1
  14. package/demo/locales/en.json +26 -2
  15. package/demo/locales/source.json +105 -9
  16. package/demo/main.js +52 -9
  17. package/demo/search.js +3 -1
  18. package/demo/service_worker.js +3 -0
  19. package/dist/controls.css +1 -1
  20. package/dist/controls.css.map +1 -1
  21. package/dist/demo.compiled.debug.js +124 -112
  22. package/dist/demo.compiled.debug.map +3 -3
  23. package/dist/demo.compiled.js +124 -112
  24. package/dist/demo.compiled.map +3 -3
  25. package/dist/deps.js +46 -28
  26. package/dist/locales.js +33 -33
  27. package/dist/receiver.compiled.debug.js +52 -46
  28. package/dist/receiver.compiled.debug.map +3 -3
  29. package/dist/receiver.compiled.js +52 -46
  30. package/dist/receiver.compiled.map +3 -3
  31. package/dist/shaka-player.compiled.d.ts +676 -391
  32. package/dist/shaka-player.compiled.debug.d.ts +676 -391
  33. package/dist/shaka-player.compiled.debug.externs.js +1188 -616
  34. package/dist/shaka-player.compiled.debug.js +1043 -699
  35. package/dist/shaka-player.compiled.debug.map +4 -4
  36. package/dist/shaka-player.compiled.externs.js +1188 -616
  37. package/dist/shaka-player.compiled.js +1091 -929
  38. package/dist/shaka-player.compiled.map +4 -4
  39. package/dist/shaka-player.ui.d.ts +677 -392
  40. package/dist/shaka-player.ui.debug.d.ts +677 -392
  41. package/dist/shaka-player.ui.debug.externs.js +1023 -451
  42. package/dist/shaka-player.ui.debug.js +1098 -737
  43. package/dist/shaka-player.ui.debug.map +4 -4
  44. package/dist/shaka-player.ui.externs.js +1023 -451
  45. package/dist/shaka-player.ui.js +1246 -1071
  46. package/dist/shaka-player.ui.map +4 -4
  47. package/docs/tutorials/ad_monetization.md +15 -1
  48. package/docs/tutorials/application-level-redirects.md +1 -1
  49. package/docs/tutorials/config.md +9 -5
  50. package/docs/tutorials/drm-config.md +61 -0
  51. package/docs/tutorials/fairplay.md +19 -4
  52. package/docs/tutorials/license-server-auth.md +4 -4
  53. package/docs/tutorials/license-wrapping.md +2 -2
  54. package/docs/tutorials/ui-customization.md +7 -3
  55. package/docs/tutorials/ui.md +7 -7
  56. package/docs/tutorials/upgrade.md +3 -0
  57. package/externs/ima.js +123 -2
  58. package/externs/isoboxer.js +217 -0
  59. package/externs/mediakeys.js +18 -0
  60. package/externs/mux.js +1 -105
  61. package/externs/pictureinpicture.js +48 -0
  62. package/externs/shaka/ads.js +61 -1
  63. package/externs/shaka/cea.js +110 -0
  64. package/externs/shaka/codecs.js +32 -0
  65. package/externs/shaka/manifest.js +101 -1
  66. package/externs/shaka/manifest_parser.js +0 -10
  67. package/externs/shaka/net.js +36 -7
  68. package/externs/shaka/offline.js +8 -1
  69. package/externs/shaka/player.js +220 -21
  70. package/externs/shaka/text.js +1 -382
  71. package/externs/shaka/transmuxer.js +60 -0
  72. package/karma.conf.js +13 -0
  73. package/lib/abr/simple_abr_manager.js +6 -3
  74. package/lib/ads/ad_manager.js +60 -2
  75. package/lib/ads/client_side_ad.js +86 -0
  76. package/lib/ads/client_side_ad_manager.js +79 -3
  77. package/lib/ads/server_side_ad.js +86 -0
  78. package/lib/ads/server_side_ad_manager.js +13 -0
  79. package/lib/cast/cast_utils.js +1 -0
  80. package/lib/cea/cea608_data_channel.js +24 -14
  81. package/lib/cea/cea608_memory.js +5 -2
  82. package/lib/cea/cea708_service.js +8 -9
  83. package/lib/cea/cea708_window.js +1 -2
  84. package/lib/cea/cea_decoder.js +23 -6
  85. package/lib/cea/cea_utils.js +25 -2
  86. package/lib/cea/dummy_caption_decoder.js +21 -0
  87. package/lib/cea/dummy_cea_parser.js +1 -3
  88. package/lib/cea/mp4_cea_parser.js +15 -10
  89. package/lib/cea/ts_cea_parser.js +69 -0
  90. package/lib/dash/content_protection.js +32 -2
  91. package/lib/dash/dash_parser.js +93 -31
  92. package/lib/dash/mpd_utils.js +6 -25
  93. package/lib/dash/segment_base.js +12 -14
  94. package/lib/dash/segment_list.js +10 -6
  95. package/lib/dash/segment_template.js +349 -32
  96. package/lib/dependencies/all.js +8 -0
  97. package/lib/hls/hls_classes.js +33 -8
  98. package/lib/hls/hls_parser.js +805 -191
  99. package/lib/hls/manifest_text_parser.js +4 -14
  100. package/lib/media/adaptation_set_criteria.js +43 -3
  101. package/lib/media/closed_caption_parser.js +74 -12
  102. package/lib/media/drm_engine.js +189 -49
  103. package/lib/media/gap_jumping_controller.js +1 -1
  104. package/lib/media/manifest_parser.js +34 -0
  105. package/lib/media/media_source_capabilities.js +10 -0
  106. package/lib/media/media_source_engine.js +495 -231
  107. package/lib/media/playhead.js +1 -1
  108. package/lib/media/presentation_timeline.js +62 -0
  109. package/lib/media/segment_index.js +50 -14
  110. package/lib/media/segment_prefetch.js +277 -0
  111. package/lib/media/segment_reference.js +70 -4
  112. package/lib/media/streaming_engine.js +258 -81
  113. package/lib/media/video_wrapper.js +15 -7
  114. package/lib/mss/content_protection.js +353 -0
  115. package/lib/mss/mss_parser.js +1082 -0
  116. package/lib/net/networking_engine.js +60 -10
  117. package/lib/offline/indexeddb/v1_storage_cell.js +1 -0
  118. package/lib/offline/indexeddb/v2_storage_cell.js +1 -0
  119. package/lib/offline/manifest_converter.js +6 -0
  120. package/lib/offline/storage.js +2 -4
  121. package/lib/player.js +309 -105
  122. package/lib/polyfill/media_capabilities.js +43 -3
  123. package/lib/polyfill/patchedmediakeys_apple.js +5 -0
  124. package/lib/polyfill/patchedmediakeys_nop.js +5 -0
  125. package/lib/polyfill/patchedmediakeys_webkit.js +5 -0
  126. package/lib/text/cue.js +208 -130
  127. package/lib/text/lrc_text_parser.js +2 -2
  128. package/lib/text/mp4_vtt_parser.js +2 -2
  129. package/lib/text/sbv_text_parser.js +1 -1
  130. package/lib/text/simple_text_displayer.js +1 -1
  131. package/lib/text/srt_text_parser.js +9 -1
  132. package/lib/text/ssa_text_parser.js +2 -2
  133. package/lib/text/text_engine.js +3 -21
  134. package/lib/text/text_utils.js +71 -20
  135. package/lib/text/ui_text_displayer.js +14 -14
  136. package/lib/text/vtt_text_parser.js +22 -14
  137. package/lib/transmuxer/aac_transmuxer.js +224 -0
  138. package/lib/transmuxer/ac3.js +142 -0
  139. package/lib/transmuxer/ac3_transmuxer.js +213 -0
  140. package/lib/transmuxer/adts.js +232 -0
  141. package/lib/transmuxer/ec3.js +103 -0
  142. package/lib/transmuxer/ec3_transmuxer.js +213 -0
  143. package/lib/transmuxer/h264.js +324 -0
  144. package/lib/transmuxer/mp3_transmuxer.js +205 -0
  145. package/lib/transmuxer/mpeg_audio.js +196 -0
  146. package/lib/transmuxer/mpeg_ts_transmuxer.js +182 -0
  147. package/lib/transmuxer/mss_transmuxer.js +389 -0
  148. package/lib/{media/transmuxer.js → transmuxer/muxjs_transmuxer.js} +34 -80
  149. package/lib/transmuxer/transmuxer_engine.js +161 -0
  150. package/lib/transmuxer/ts_transmuxer.js +721 -0
  151. package/lib/util/cmcd_manager.js +131 -71
  152. package/lib/util/error.js +62 -26
  153. package/lib/util/exp_golomb.js +220 -0
  154. package/lib/util/fairplay_utils.js +64 -13
  155. package/lib/util/id3_utils.js +56 -3
  156. package/lib/util/language_utils.js +11 -8
  157. package/lib/util/manifest_parser_utils.js +3 -0
  158. package/lib/util/mime_utils.js +44 -7
  159. package/lib/util/mp4_box_parsers.js +233 -5
  160. package/lib/util/mp4_generator.js +1388 -0
  161. package/lib/util/periods.js +40 -34
  162. package/lib/util/platform.js +17 -3
  163. package/lib/util/player_configuration.js +38 -1
  164. package/lib/util/stream_utils.js +138 -27
  165. package/lib/util/text_parser.js +1 -1
  166. package/lib/util/ts_parser.js +460 -74
  167. package/lib/util/xml_utils.js +16 -3
  168. package/maintained-branches.md +2 -2
  169. package/package.json +3 -1
  170. package/roadmap.md +21 -6
  171. package/shaka-player.uncompiled.js +18 -0
  172. package/test/abr/simple_abr_manager_unit.js +32 -4
  173. package/test/ads/ad_manager_unit.js +18 -2
  174. package/test/cast/cast_utils_unit.js +7 -2
  175. package/test/cea/cea608_memory_unit.js +24 -0
  176. package/test/cea/cea_decoder_unit.js +33 -0
  177. package/test/dash/dash_parser_content_protection_unit.js +93 -3
  178. package/test/dash/dash_parser_live_unit.js +56 -13
  179. package/test/dash/dash_parser_manifest_unit.js +70 -2
  180. package/test/dash/dash_parser_segment_base_unit.js +14 -9
  181. package/test/dash/dash_parser_segment_template_unit.js +286 -6
  182. package/test/demo/demo_unit.js +5 -1
  183. package/test/hls/hls_live_unit.js +188 -28
  184. package/test/hls/hls_parser_unit.js +250 -109
  185. package/test/hls/manifest_text_parser_unit.js +18 -13
  186. package/test/media/adaptation_set_criteria_unit.js +46 -14
  187. package/test/media/adaptation_set_unit.js +2 -0
  188. package/test/media/drm_engine_integration.js +11 -8
  189. package/test/media/drm_engine_unit.js +220 -7
  190. package/test/media/media_source_engine_integration.js +124 -40
  191. package/test/media/media_source_engine_unit.js +133 -153
  192. package/test/media/playhead_unit.js +3 -0
  193. package/test/media/presentation_timeline_unit.js +51 -0
  194. package/test/media/segment_index_unit.js +52 -0
  195. package/test/media/segment_prefetch_unit.js +243 -0
  196. package/test/media/streaming_engine_integration.js +9 -3
  197. package/test/media/streaming_engine_unit.js +440 -59
  198. package/test/mss/mss_parser_content_protection_unit.js +49 -0
  199. package/test/mss/mss_parser_unit.js +472 -0
  200. package/test/mss/mss_player_integration.js +123 -0
  201. package/test/offline/manifest_convert_unit.js +9 -0
  202. package/test/offline/storage_integration.js +6 -1
  203. package/test/player_unit.js +386 -133
  204. package/test/polyfill/media_capabilities_unit.js +18 -0
  205. package/test/test/assets/hls-raw-aac/fileSequence0.aac +0 -0
  206. package/test/test/assets/hls-raw-aac/fileSequence1.aac +0 -0
  207. package/test/test/assets/hls-raw-aac/fileSequence2.aac +0 -0
  208. package/test/test/assets/hls-raw-aac/fileSequence3.aac +0 -0
  209. package/test/test/assets/hls-raw-aac/manifest.m3u8 +4 -0
  210. package/test/test/assets/hls-raw-aac/stream.m4a.m3u8 +14 -0
  211. package/test/test/assets/hls-raw-ac3/fileSequence0.ac3 +0 -0
  212. package/test/test/assets/hls-raw-ac3/fileSequence1.ac3 +0 -0
  213. package/test/test/assets/hls-raw-ac3/fileSequence2.ac3 +0 -0
  214. package/test/test/assets/hls-raw-ac3/fileSequence3.ac3 +0 -0
  215. package/test/test/assets/hls-raw-ac3/fileSequence4.ac3 +0 -0
  216. package/test/test/assets/hls-raw-ac3/fileSequence5.ac3 +0 -0
  217. package/test/test/assets/hls-raw-ac3/fileSequence6.ac3 +0 -0
  218. package/test/test/assets/hls-raw-ac3/fileSequence7.ac3 +0 -0
  219. package/test/test/assets/hls-raw-ac3/prog_index.m3u8 +31 -0
  220. package/test/test/assets/hls-raw-ec3/fileSequence0.ec3 +0 -0
  221. package/test/test/assets/hls-raw-ec3/fileSequence1.ec3 +0 -0
  222. package/test/test/assets/hls-raw-ec3/fileSequence2.ec3 +0 -0
  223. package/test/test/assets/hls-raw-ec3/fileSequence3.ec3 +0 -0
  224. package/test/test/assets/hls-raw-ec3/fileSequence4.ec3 +0 -0
  225. package/test/test/assets/hls-raw-ec3/fileSequence5.ec3 +0 -0
  226. package/test/test/assets/hls-raw-ec3/fileSequence6.ec3 +0 -0
  227. package/test/test/assets/hls-raw-ec3/fileSequence7.ec3 +0 -0
  228. package/test/test/assets/hls-raw-ec3/prog_index.m3u8 +31 -0
  229. package/test/test/assets/hls-raw-mp3/chunklist_w905519204.m3u8 +13 -0
  230. package/test/test/assets/hls-raw-mp3/media_w905519204_0.mp3 +0 -0
  231. package/test/test/assets/hls-raw-mp3/media_w905519204_1.mp3 +0 -0
  232. package/test/test/assets/hls-raw-mp3/media_w905519204_2.mp3 +0 -0
  233. package/test/test/assets/hls-raw-mp3/media_w905519204_3.mp3 +0 -0
  234. package/test/test/assets/hls-raw-mp3/playlist.m3u8 +4 -0
  235. package/test/test/assets/hls-ts-aac/playlist.m3u8 +23 -0
  236. package/test/test/assets/hls-ts-aac/segment_0.ts +0 -0
  237. package/test/test/assets/hls-ts-aac/segment_1.ts +0 -0
  238. package/test/test/assets/hls-ts-aac/segment_2.ts +0 -0
  239. package/test/test/assets/hls-ts-aac/segment_3.ts +0 -0
  240. package/test/test/assets/hls-ts-aac/segment_4.ts +0 -0
  241. package/test/test/assets/hls-ts-aac/segment_5.ts +0 -0
  242. package/test/test/assets/hls-ts-aac/segment_6.ts +0 -0
  243. package/test/test/assets/hls-ts-aac/segment_7.ts +0 -0
  244. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0000.ts +0 -0
  245. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0001.ts +0 -0
  246. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0002.ts +0 -0
  247. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0003.ts +0 -0
  248. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0004.ts +0 -0
  249. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0005.ts +0 -0
  250. package/test/test/assets/hls-ts-ac3/prog_index.m3u8 +19 -0
  251. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0000.ts +0 -0
  252. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0001.ts +0 -0
  253. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0002.ts +0 -0
  254. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0003.ts +0 -0
  255. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0004.ts +0 -0
  256. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0005.ts +0 -0
  257. package/test/test/assets/hls-ts-ec3/prog_index.m3u8 +19 -0
  258. package/test/test/assets/hls-ts-h264/fileSequence0.ts +0 -0
  259. package/test/test/assets/hls-ts-h264/fileSequence1.ts +0 -0
  260. package/test/test/assets/hls-ts-h264/fileSequence2.ts +0 -0
  261. package/test/test/assets/hls-ts-h264/fileSequence3.ts +0 -0
  262. package/test/test/assets/hls-ts-h264/fileSequence4.ts +0 -0
  263. package/test/test/assets/hls-ts-h264/fileSequence5.ts +0 -0
  264. package/test/test/assets/hls-ts-h264/prog_index.m3u8 +25 -0
  265. package/test/test/assets/hls-ts-mp3/manifest.m3u8 +13 -0
  266. package/test/test/assets/hls-ts-mp3/media_w239891843_0.ts +0 -0
  267. package/test/test/assets/hls-ts-mp3/media_w239891843_1.ts +0 -0
  268. package/test/test/assets/hls-ts-mp3/media_w239891843_2.ts +0 -0
  269. package/test/test/assets/hls-ts-mp3/media_w239891843_3.ts +0 -0
  270. package/test/test/assets/hls-ts-muxed-aac-h264/chunk.m3u8 +17 -0
  271. package/test/test/assets/hls-ts-muxed-aac-h264/n_0_0_0.ts +0 -0
  272. package/test/test/assets/hls-ts-muxed-aac-h264/n_1_0_0.ts +0 -0
  273. package/test/test/assets/hls-ts-muxed-aac-h264/n_2_0_0.ts +0 -0
  274. package/test/test/assets/hls-ts-muxed-aac-h264/n_3_0_0.ts +0 -0
  275. package/test/test/assets/hls-ts-muxed-aac-h264/n_4_0_0.ts +0 -0
  276. package/test/test/assets/hls-ts-muxed-aac-h264/n_5_0_0.ts +0 -0
  277. package/test/test/assets/hls-ts-muxed-aac-h264/playlist.m3u8 +4 -0
  278. package/test/test/boot.js +7 -2
  279. package/test/test/util/fake_ad.js +99 -0
  280. package/test/test/util/fake_ad_manager.js +7 -1
  281. package/test/test/util/fake_networking_engine.js +41 -14
  282. package/test/test/util/fake_segment_prefetch.js +81 -0
  283. package/test/test/util/manifest_generator.js +19 -5
  284. package/test/test/util/mss_parser_util.js +115 -0
  285. package/test/test/util/offline_utils.js +1 -0
  286. package/test/test/util/simple_fakes.js +12 -3
  287. package/test/test/util/streaming_engine_util.js +14 -4
  288. package/test/test/util/ttml_utils.js +2 -2
  289. package/test/text/cue_integration.js +1 -1
  290. package/test/text/srt_text_parser_unit.js +78 -0
  291. package/test/text/text_engine_unit.js +17 -8
  292. package/test/text/ui_text_displayer_unit.js +4 -4
  293. package/test/text/vtt_text_parser_unit.js +59 -40
  294. package/test/text/web_vtt_generator_unit.js +9 -3
  295. package/test/{media/transmuxer_integration.js → transmuxer/muxjs_transmuxer_integration.js} +30 -33
  296. package/test/transmuxer/transmuxer_engine_integration.js +60 -0
  297. package/test/transmuxer/transmuxer_integration.js +296 -0
  298. package/test/util/cmcd_manager_unit.js +162 -13
  299. package/test/util/language_utils_unit.js +9 -2
  300. package/test/util/mp4_box_parsers_unit.js +39 -4
  301. package/test/util/periods_unit.js +34 -26
  302. package/test/util/stream_utils_unit.js +60 -107
  303. package/ui/controls.js +19 -1
  304. package/ui/controls.less +1 -0
  305. package/ui/externs/ui.js +11 -1
  306. package/ui/language_utils.js +15 -0
  307. package/ui/less/thumbnails.less +26 -0
  308. package/ui/locales/oc.json +42 -0
  309. package/ui/pip_button.js +83 -2
  310. package/ui/range_element.js +15 -0
  311. package/ui/resolution_selection.js +9 -2
  312. package/ui/seek_bar.js +223 -0
  313. package/ui/ui.js +5 -0
  314. package/lib/cea/i_caption_decoder.js +0 -51
  315. package/lib/cea/i_cea_parser.js +0 -68
@@ -0,0 +1,213 @@
1
+ /*! @license
2
+ * Shaka Player
3
+ * Copyright 2016 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ goog.provide('shaka.transmuxer.Ec3Transmuxer');
8
+
9
+ goog.require('shaka.media.Capabilities');
10
+ goog.require('shaka.transmuxer.Ec3');
11
+ goog.require('shaka.transmuxer.TransmuxerEngine');
12
+ goog.require('shaka.util.BufferUtils');
13
+ goog.require('shaka.util.Error');
14
+ goog.require('shaka.util.Id3Utils');
15
+ goog.require('shaka.util.ManifestParserUtils');
16
+ goog.require('shaka.util.Mp4Generator');
17
+ goog.require('shaka.util.Uint8ArrayUtils');
18
+
19
+
20
+ /**
21
+ * @implements {shaka.extern.Transmuxer}
22
+ * @export
23
+ */
24
+ shaka.transmuxer.Ec3Transmuxer = class {
25
+ /**
26
+ * @param {string} mimeType
27
+ */
28
+ constructor(mimeType) {
29
+ /** @private {string} */
30
+ this.originalMimeType_ = mimeType;
31
+
32
+ /** @private {number} */
33
+ this.frameIndex_ = 0;
34
+
35
+ /** @private {!Map.<number, !Uint8Array>} */
36
+ this.initSegments = new Map();
37
+ }
38
+
39
+
40
+ /**
41
+ * @override
42
+ * @export
43
+ */
44
+ destroy() {
45
+ this.initSegments.clear();
46
+ }
47
+
48
+
49
+ /**
50
+ * Check if the mime type and the content type is supported.
51
+ * @param {string} mimeType
52
+ * @param {string=} contentType
53
+ * @return {boolean}
54
+ * @override
55
+ * @export
56
+ */
57
+ isSupported(mimeType, contentType) {
58
+ const Capabilities = shaka.media.Capabilities;
59
+
60
+ if (!this.isEc3Container_(mimeType)) {
61
+ return false;
62
+ }
63
+ const ContentType = shaka.util.ManifestParserUtils.ContentType;
64
+ return Capabilities.isTypeSupported(
65
+ this.convertCodecs(ContentType.AUDIO, mimeType));
66
+ }
67
+
68
+
69
+ /**
70
+ * Check if the mimetype is 'audio/ec3'.
71
+ * @param {string} mimeType
72
+ * @return {boolean}
73
+ * @private
74
+ */
75
+ isEc3Container_(mimeType) {
76
+ return mimeType.toLowerCase().split(';')[0] == 'audio/ec3';
77
+ }
78
+
79
+
80
+ /**
81
+ * @override
82
+ * @export
83
+ */
84
+ convertCodecs(contentType, mimeType) {
85
+ if (this.isEc3Container_(mimeType)) {
86
+ return 'audio/mp4; codecs="ec-3"';
87
+ }
88
+ return mimeType;
89
+ }
90
+
91
+
92
+ /**
93
+ * @override
94
+ * @export
95
+ */
96
+ getOrginalMimeType() {
97
+ return this.originalMimeType_;
98
+ }
99
+
100
+
101
+ /**
102
+ * @override
103
+ * @export
104
+ */
105
+ transmux(data, stream, reference, duration) {
106
+ const Ec3 = shaka.transmuxer.Ec3;
107
+ const Uint8ArrayUtils = shaka.util.Uint8ArrayUtils;
108
+
109
+ const uint8ArrayData = shaka.util.BufferUtils.toUint8(data);
110
+
111
+ const id3Data = shaka.util.Id3Utils.getID3Data(uint8ArrayData);
112
+ let offset = id3Data.length;
113
+ for (; offset < uint8ArrayData.length; offset++) {
114
+ if (Ec3.probe(uint8ArrayData, offset)) {
115
+ break;
116
+ }
117
+ }
118
+
119
+ let timestamp = reference.endTime * 1000;
120
+
121
+ const frames = shaka.util.Id3Utils.getID3Frames(id3Data);
122
+ if (frames.length && reference) {
123
+ const metadataTimestamp = frames.find((frame) => {
124
+ return frame.description ===
125
+ 'com.apple.streaming.transportStreamTimestamp';
126
+ });
127
+ if (metadataTimestamp) {
128
+ timestamp = /** @type {!number} */(metadataTimestamp.data);
129
+ }
130
+ }
131
+
132
+ /** @type {number} */
133
+ let sampleRate = 0;
134
+
135
+ /** @type {!Uint8Array} */
136
+ let audioConfig = new Uint8Array([]);
137
+
138
+ /** @type {!Array.<shaka.util.Mp4Generator.Mp4Sample>} */
139
+ const samples = [];
140
+
141
+ while (offset < uint8ArrayData.length) {
142
+ const frame = Ec3.parseFrame(uint8ArrayData, offset);
143
+ if (!frame) {
144
+ return Promise.reject(new shaka.util.Error(
145
+ shaka.util.Error.Severity.CRITICAL,
146
+ shaka.util.Error.Category.MEDIA,
147
+ shaka.util.Error.Code.TRANSMUXING_FAILED));
148
+ }
149
+ stream.audioSamplingRate = frame.sampleRate;
150
+ stream.channelsCount = frame.channelCount;
151
+ sampleRate = frame.sampleRate;
152
+ audioConfig = frame.audioConfig;
153
+
154
+ const frameData = uint8ArrayData.subarray(
155
+ offset, offset + frame.frameLength);
156
+
157
+ samples.push({
158
+ data: frameData,
159
+ size: frame.frameLength,
160
+ duration: Ec3.EC3_SAMPLES_PER_FRAME,
161
+ cts: 0,
162
+ flags: {
163
+ isLeading: 0,
164
+ isDependedOn: 0,
165
+ hasRedundancy: 0,
166
+ degradPrio: 0,
167
+ dependsOn: 2,
168
+ isNonSync: 0,
169
+ },
170
+ });
171
+ offset += frame.frameLength;
172
+ }
173
+ /** @type {number} */
174
+ const baseMediaDecodeTime = Math.floor(timestamp * sampleRate / 1000);
175
+
176
+ /** @type {shaka.util.Mp4Generator.StreamInfo} */
177
+ const streamInfo = {
178
+ id: stream.id,
179
+ type: shaka.util.ManifestParserUtils.ContentType.AUDIO,
180
+ codecs: 'ec-3',
181
+ encrypted: stream.encrypted && stream.drmInfos.length > 0,
182
+ timescale: sampleRate,
183
+ duration: duration,
184
+ videoNalus: [],
185
+ audioConfig: audioConfig,
186
+ videoConfig: new Uint8Array([]),
187
+ data: {
188
+ sequenceNumber: this.frameIndex_,
189
+ baseMediaDecodeTime: baseMediaDecodeTime,
190
+ samples: samples,
191
+ },
192
+ stream: stream,
193
+ };
194
+ const mp4Generator = new shaka.util.Mp4Generator([streamInfo]);
195
+ let initSegment;
196
+ if (!this.initSegments.has(stream.id)) {
197
+ initSegment = mp4Generator.initSegment();
198
+ this.initSegments.set(stream.id, initSegment);
199
+ } else {
200
+ initSegment = this.initSegments.get(stream.id);
201
+ }
202
+ const segmentData = mp4Generator.segmentData();
203
+
204
+ this.frameIndex_++;
205
+ const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
206
+ return Promise.resolve(transmuxData);
207
+ }
208
+ };
209
+
210
+ shaka.transmuxer.TransmuxerEngine.registerTransmuxer(
211
+ 'audio/ec3',
212
+ () => new shaka.transmuxer.Ec3Transmuxer('audio/ec3'),
213
+ shaka.transmuxer.TransmuxerEngine.PluginPriority.FALLBACK);
@@ -0,0 +1,324 @@
1
+ /*! @license
2
+ * Shaka Player
3
+ * Copyright 2016 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ goog.provide('shaka.transmuxer.H264');
8
+
9
+ goog.require('shaka.util.ExpGolomb');
10
+ goog.require('shaka.util.Uint8ArrayUtils');
11
+
12
+
13
+ /**
14
+ * H.264 utils
15
+ */
16
+ shaka.transmuxer.H264 = class {
17
+ /**
18
+ * Read a sequence parameter set and return some interesting video
19
+ * properties. A sequence parameter set is the H264 metadata that
20
+ * describes the properties of upcoming video frames.
21
+ *
22
+ * @param {!Array.<shaka.extern.VideoNalu>} nalus
23
+ * @return {?{height: number, width: number, videoConfig: !Uint8Array}}
24
+ */
25
+ static parseInfo(nalus) {
26
+ const H264 = shaka.transmuxer.H264;
27
+ if (!nalus.length) {
28
+ return null;
29
+ }
30
+ const spsNalu = nalus.find((nalu) => {
31
+ return nalu.type == H264.NALU_TYPE_SPS_;
32
+ });
33
+ const ppsNalu = nalus.find((nalu) => {
34
+ return nalu.type == H264.NALU_TYPE_PPS_;
35
+ });
36
+ if (!spsNalu || !ppsNalu) {
37
+ return null;
38
+ }
39
+
40
+ const expGolombDecoder = new shaka.util.ExpGolomb(spsNalu.data);
41
+ // profile_idc
42
+ const profileIdc = expGolombDecoder.readUnsignedByte();
43
+ // constraint_set[0-5]_flag
44
+ expGolombDecoder.readUnsignedByte();
45
+ // level_idc u(8)
46
+ expGolombDecoder.readUnsignedByte();
47
+ // seq_parameter_set_id
48
+ expGolombDecoder.skipExpGolomb();
49
+
50
+ // some profiles have more optional data we don't need
51
+ if (H264.PROFILES_WITH_OPTIONAL_SPS_DATA_.includes(profileIdc)) {
52
+ const chromaFormatIdc = expGolombDecoder.readUnsignedExpGolomb();
53
+ if (chromaFormatIdc === 3) {
54
+ // separate_colour_plane_flag
55
+ expGolombDecoder.skipBits(1);
56
+ }
57
+ // bit_depth_luma_minus8
58
+ expGolombDecoder.skipExpGolomb();
59
+ // bit_depth_chroma_minus8
60
+ expGolombDecoder.skipExpGolomb();
61
+ // qpprime_y_zero_transform_bypass_flag
62
+ expGolombDecoder.skipBits(1);
63
+ // seq_scaling_matrix_present_flag
64
+ if (expGolombDecoder.readBoolean()) {
65
+ const scalingListCount = (chromaFormatIdc !== 3) ? 8 : 12;
66
+ for (let i = 0; i < scalingListCount; i++) {
67
+ // seq_scaling_list_present_flag[ i ]
68
+ if (expGolombDecoder.readBoolean()) {
69
+ if (i < 6) {
70
+ expGolombDecoder.skipScalingList(16);
71
+ } else {
72
+ expGolombDecoder.skipScalingList(64);
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ // log2_max_frame_num_minus4
80
+ expGolombDecoder.skipExpGolomb();
81
+ const picOrderCntType = expGolombDecoder.readUnsignedExpGolomb();
82
+
83
+ if (picOrderCntType === 0) {
84
+ // log2_max_pic_order_cnt_lsb_minus4
85
+ expGolombDecoder.readUnsignedExpGolomb();
86
+ } else if (picOrderCntType === 1) {
87
+ // delta_pic_order_always_zero_flag
88
+ expGolombDecoder.skipBits(1);
89
+ // offset_for_non_ref_pic
90
+ expGolombDecoder.skipExpGolomb();
91
+ // offset_for_top_to_bottom_field
92
+ expGolombDecoder.skipExpGolomb();
93
+ const numRefFramesInPicOrderCntCycle =
94
+ expGolombDecoder.readUnsignedExpGolomb();
95
+ for (let i = 0; i < numRefFramesInPicOrderCntCycle; i++) {
96
+ // offset_for_ref_frame[ i ]
97
+ expGolombDecoder.skipExpGolomb();
98
+ }
99
+ }
100
+
101
+ // max_num_ref_frames
102
+ expGolombDecoder.skipExpGolomb();
103
+ // gaps_in_frame_num_value_allowed_flag
104
+ expGolombDecoder.skipBits(1);
105
+
106
+ const picWidthInMbsMinus1 =
107
+ expGolombDecoder.readUnsignedExpGolomb();
108
+ const picHeightInMapUnitsMinus1 =
109
+ expGolombDecoder.readUnsignedExpGolomb();
110
+
111
+ const frameMbsOnlyFlag = expGolombDecoder.readBits(1);
112
+ if (frameMbsOnlyFlag === 0) {
113
+ // mb_adaptive_frame_field_flag
114
+ expGolombDecoder.skipBits(1);
115
+ }
116
+ // direct_8x8_inference_flag
117
+ expGolombDecoder.skipBits(1);
118
+
119
+ let frameCropLeftOffset = 0;
120
+ let frameCropRightOffset = 0;
121
+ let frameCropTopOffset = 0;
122
+ let frameCropBottomOffset = 0;
123
+
124
+ // frame_cropping_flag
125
+ if (expGolombDecoder.readBoolean()) {
126
+ frameCropLeftOffset = expGolombDecoder.readUnsignedExpGolomb();
127
+ frameCropRightOffset = expGolombDecoder.readUnsignedExpGolomb();
128
+ frameCropTopOffset = expGolombDecoder.readUnsignedExpGolomb();
129
+ frameCropBottomOffset = expGolombDecoder.readUnsignedExpGolomb();
130
+ }
131
+
132
+ const height = ((2 - frameMbsOnlyFlag) *
133
+ (picHeightInMapUnitsMinus1 + 1) * 16) - (frameCropTopOffset * 2) -
134
+ (frameCropBottomOffset * 2);
135
+ const width = ((picWidthInMbsMinus1 + 1) * 16) -
136
+ frameCropLeftOffset * 2 - frameCropRightOffset * 2;
137
+
138
+ // assemble the SPSs
139
+ let sps = [];
140
+ const spsData = spsNalu.fullData;
141
+ sps.push((spsData.byteLength >>> 8) & 0xff);
142
+ sps.push(spsData.byteLength & 0xff);
143
+ sps = sps.concat(...spsData);
144
+
145
+ // assemble the PPSs
146
+ let pps = [];
147
+ const ppsData = ppsNalu.fullData;
148
+ pps.push((ppsData.byteLength >>> 8) & 0xff);
149
+ pps.push(ppsData.byteLength & 0xff);
150
+ pps = pps.concat(...ppsData);
151
+
152
+ const videoConfig = new Uint8Array(
153
+ [
154
+ 0x01, // version
155
+ sps[3], // profile
156
+ sps[4], // profile compat
157
+ sps[5], // level
158
+ 0xfc | 3, // lengthSizeMinusOne, hard-coded to 4 bytes
159
+ 0xe0 | 1, // 3bit reserved (111) + numOfSequenceParameterSets
160
+ ].concat(sps).concat([
161
+ 1, // numOfPictureParameterSets
162
+ ]).concat(pps));
163
+
164
+ return {
165
+ height,
166
+ width,
167
+ videoConfig,
168
+ };
169
+ }
170
+
171
+ /**
172
+ * @param {!Array.<shaka.extern.VideoNalu>} nalus
173
+ * @return {?{data: !Uint8Array, isKeyframe: boolean}}
174
+ */
175
+ static parseFrame(nalus) {
176
+ const H264 = shaka.transmuxer.H264;
177
+ let isKeyframe = false;
178
+ let data = new Uint8Array([]);
179
+ const spsNalu = nalus.find((nalu) => {
180
+ return nalu.type == H264.NALU_TYPE_SPS_;
181
+ });
182
+ let avcSample = false;
183
+ for (const nalu of nalus) {
184
+ let push = false;
185
+ switch (nalu.type) {
186
+ case H264.NALU_TYPE_NDR_: {
187
+ avcSample = true;
188
+ push = true;
189
+ const data = nalu.data;
190
+ // Only check slice type to detect KF in case SPS found in same packet
191
+ // (any keyframe is preceded by SPS ...)
192
+ if (spsNalu && data.length > 4) {
193
+ // retrieve slice type by parsing beginning of NAL unit (follow
194
+ // H264 spec,slice_header definition) to detect keyframe embedded
195
+ // in NDR
196
+ const sliceType = new shaka.util.ExpGolomb(data).readSliceType();
197
+ // 2 : I slice, 4 : SI slice, 7 : I slice, 9: SI slice
198
+ // SI slice : A slice that is coded using intra prediction only and
199
+ // using quantisation of the prediction samples.
200
+ // An SI slice can be coded such that its decoded samples can be
201
+ // constructed identically to an SP slice.
202
+ // I slice: A slice that is not an SI slice that is decoded using
203
+ // intra prediction only.
204
+ if (sliceType === 2 || sliceType === 4 ||
205
+ sliceType === 7 || sliceType === 9) {
206
+ isKeyframe = true;
207
+ }
208
+ }
209
+ break;
210
+ }
211
+ case H264.NALU_TYPE_IDR_:
212
+ avcSample = true;
213
+ push = true;
214
+ isKeyframe = true;
215
+ break;
216
+ case H264.NALU_TYPE_SEI_:
217
+ push = true;
218
+ break;
219
+ case H264.NALU_TYPE_SPS_:
220
+ push = true;
221
+ break;
222
+ case H264.NALU_TYPE_PPS_:
223
+ push = true;
224
+ break;
225
+ case H264.NALU_TYPE_AUD_:
226
+ push = true;
227
+ avcSample = true;
228
+ break;
229
+ case H264.NALU_TYPE_FILLER_DATA_:
230
+ push = true;
231
+ break;
232
+ default:
233
+ push = false;
234
+ break;
235
+ }
236
+ if (avcSample && push) {
237
+ const size = nalu.fullData.byteLength;
238
+ const naluLength = new Uint8Array(4);
239
+ naluLength[0] = (size >> 24) & 0xff;
240
+ naluLength[1] = (size >> 16) & 0xff;
241
+ naluLength[2] = (size >> 8) & 0xff;
242
+ naluLength[3] = size & 0xff;
243
+ data = shaka.util.Uint8ArrayUtils.concat(
244
+ data, naluLength, nalu.fullData);
245
+ }
246
+ }
247
+ if (!data.byteLength) {
248
+ return null;
249
+ }
250
+ return {
251
+ data,
252
+ isKeyframe,
253
+ };
254
+ }
255
+ };
256
+
257
+
258
+ /**
259
+ * NALU type for NDR for H.264.
260
+ * @const {number}
261
+ * @private
262
+ */
263
+ shaka.transmuxer.H264.NALU_TYPE_NDR_ = 0x01;
264
+
265
+
266
+ /**
267
+ * NALU type for Instantaneous Decoder Refresh (IDR) for H.264.
268
+ * @const {number}
269
+ * @private
270
+ */
271
+ shaka.transmuxer.H264.NALU_TYPE_IDR_ = 0x05;
272
+
273
+
274
+ /**
275
+ * NALU type for Supplemental Enhancement Information (SEI) for H.264.
276
+ * @const {number}
277
+ * @private
278
+ */
279
+ shaka.transmuxer.H264.NALU_TYPE_SEI_ = 0x06;
280
+
281
+
282
+ /**
283
+ * NALU type for Sequence Parameter Set (SPS) for H.264.
284
+ * @const {number}
285
+ * @private
286
+ */
287
+ shaka.transmuxer.H264.NALU_TYPE_SPS_ = 0x07;
288
+
289
+
290
+ /**
291
+ * NALU type for Picture Parameter Set (PPS) for H.264.
292
+ * @const {number}
293
+ * @private
294
+ */
295
+ shaka.transmuxer.H264.NALU_TYPE_PPS_ = 0x08;
296
+
297
+
298
+ /**
299
+ * NALU type for Access Unit Delimiter (AUD) for H.264.
300
+ * @const {number}
301
+ * @private
302
+ */
303
+ shaka.transmuxer.H264.NALU_TYPE_AUD_ = 0x09;
304
+
305
+
306
+ /**
307
+ * NALU type for Filler Data for H.264.
308
+ * @const {number}
309
+ * @private
310
+ */
311
+ shaka.transmuxer.H264.NALU_TYPE_FILLER_DATA_ = 0x0c;
312
+
313
+
314
+ /**
315
+ * Values of profile_idc that indicate additional fields are included in the
316
+ * SPS.
317
+ * see Recommendation ITU-T H.264 (4/2013)
318
+ * 7.3.2.1.1 Sequence parameter set data syntax
319
+ *
320
+ * @const {!Array.<number>}
321
+ * @private
322
+ */
323
+ shaka.transmuxer.H264.PROFILES_WITH_OPTIONAL_SPS_DATA_ =
324
+ [100, 110, 122, 244, 44, 83, 86, 118, 128, 138, 139, 134];