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,721 @@
1
+ /*! @license
2
+ * Shaka Player
3
+ * Copyright 2016 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ goog.provide('shaka.transmuxer.TsTransmuxer');
8
+
9
+ goog.require('shaka.media.Capabilities');
10
+ goog.require('shaka.transmuxer.Ac3');
11
+ goog.require('shaka.transmuxer.ADTS');
12
+ goog.require('shaka.transmuxer.Ec3');
13
+ goog.require('shaka.transmuxer.H264');
14
+ goog.require('shaka.transmuxer.MpegAudio');
15
+ goog.require('shaka.transmuxer.TransmuxerEngine');
16
+ goog.require('shaka.util.BufferUtils');
17
+ goog.require('shaka.util.Error');
18
+ goog.require('shaka.util.ManifestParserUtils');
19
+ goog.require('shaka.util.MimeUtils');
20
+ goog.require('shaka.util.Mp4Generator');
21
+ goog.require('shaka.util.TsParser');
22
+ goog.require('shaka.util.Uint8ArrayUtils');
23
+
24
+
25
+ /**
26
+ * @implements {shaka.extern.Transmuxer}
27
+ * @export
28
+ */
29
+ shaka.transmuxer.TsTransmuxer = class {
30
+ /**
31
+ * @param {string} mimeType
32
+ */
33
+ constructor(mimeType) {
34
+ /** @private {string} */
35
+ this.originalMimeType_ = mimeType;
36
+
37
+ /** @private {number} */
38
+ this.frameIndex_ = 0;
39
+
40
+ /** @private {!Map.<number, !Uint8Array>} */
41
+ this.initSegments = new Map();
42
+
43
+ /** @private {?shaka.util.TsParser} */
44
+ this.tsParser_ = null;
45
+ }
46
+
47
+
48
+ /**
49
+ * @override
50
+ * @export
51
+ */
52
+ destroy() {
53
+ this.initSegments.clear();
54
+ }
55
+
56
+
57
+ /**
58
+ * Check if the mime type and the content type is supported.
59
+ * @param {string} mimeType
60
+ * @param {string=} contentType
61
+ * @return {boolean}
62
+ * @override
63
+ * @export
64
+ */
65
+ isSupported(mimeType, contentType) {
66
+ const Capabilities = shaka.media.Capabilities;
67
+
68
+ if (!this.isTsContainer_(mimeType)) {
69
+ return false;
70
+ }
71
+
72
+ const ContentType = shaka.util.ManifestParserUtils.ContentType;
73
+ const MimeUtils = shaka.util.MimeUtils;
74
+
75
+ const codecs = MimeUtils.getCodecs(mimeType);
76
+ const allCodecs = MimeUtils.splitCodecs(codecs);
77
+
78
+ const audioCodec = shaka.util.ManifestParserUtils.guessCodecsSafe(
79
+ ContentType.AUDIO, allCodecs);
80
+ const videoCodec = shaka.util.ManifestParserUtils.guessCodecsSafe(
81
+ ContentType.VIDEO, allCodecs);
82
+
83
+ // We don't support muxed content yet.
84
+ if (audioCodec && videoCodec) {
85
+ return false;
86
+ }
87
+
88
+ const TsTransmuxer = shaka.transmuxer.TsTransmuxer;
89
+
90
+ if (audioCodec) {
91
+ const normalizedCodec = MimeUtils.getNormalizedCodec(audioCodec);
92
+ if (!TsTransmuxer.SUPPORTED_AUDIO_CODECS_.includes(normalizedCodec)) {
93
+ return false;
94
+ }
95
+ }
96
+
97
+ if (videoCodec) {
98
+ const normalizedCodec = MimeUtils.getNormalizedCodec(videoCodec);
99
+ if (!TsTransmuxer.SUPPORTED_VIDEO_CODECS_.includes(normalizedCodec)) {
100
+ return false;
101
+ }
102
+ }
103
+
104
+ if (contentType) {
105
+ return Capabilities.isTypeSupported(
106
+ this.convertCodecs(contentType, mimeType));
107
+ }
108
+
109
+ const audioMime = this.convertCodecs(ContentType.AUDIO, mimeType);
110
+ const videoMime = this.convertCodecs(ContentType.VIDEO, mimeType);
111
+ return Capabilities.isTypeSupported(audioMime) ||
112
+ Capabilities.isTypeSupported(videoMime);
113
+ }
114
+
115
+
116
+ /**
117
+ * Check if the mimetype is 'video/mp2t'.
118
+ * @param {string} mimeType
119
+ * @return {boolean}
120
+ * @private
121
+ */
122
+ isTsContainer_(mimeType) {
123
+ return mimeType.toLowerCase().split(';')[0] == 'video/mp2t';
124
+ }
125
+
126
+
127
+ /**
128
+ * @override
129
+ * @export
130
+ */
131
+ convertCodecs(contentType, mimeType) {
132
+ if (this.isTsContainer_(mimeType)) {
133
+ const ContentType = shaka.util.ManifestParserUtils.ContentType;
134
+ // The replace it's necessary because Firefox(the only browser that
135
+ // supports MP3 in MP4) only support the MP3 codec with the mp3 string.
136
+ // MediaSource.isTypeSupported('audio/mp4; codecs="mp4a.40.34"') -> false
137
+ // MediaSource.isTypeSupported('audio/mp4; codecs="mp3"') -> true
138
+ const codecs = shaka.util.MimeUtils.getCodecs(mimeType)
139
+ .replace('mp4a.40.34', 'mp3');
140
+ if (contentType == ContentType.AUDIO) {
141
+ return `audio/mp4; codecs="${codecs}"`;
142
+ }
143
+ return `video/mp4; codecs="${codecs}"`;
144
+ }
145
+ return mimeType;
146
+ }
147
+
148
+
149
+ /**
150
+ * @override
151
+ * @export
152
+ */
153
+ getOrginalMimeType() {
154
+ return this.originalMimeType_;
155
+ }
156
+
157
+
158
+ /**
159
+ * @override
160
+ * @export
161
+ */
162
+ transmux(data, stream, reference, duration, contentType) {
163
+ const ContentType = shaka.util.ManifestParserUtils.ContentType;
164
+ if (!this.tsParser_) {
165
+ this.tsParser_ = new shaka.util.TsParser();
166
+ } else {
167
+ this.tsParser_.clearData();
168
+ }
169
+ const Uint8ArrayUtils = shaka.util.Uint8ArrayUtils;
170
+
171
+ const uint8ArrayData = shaka.util.BufferUtils.toUint8(data);
172
+
173
+ let timestamp = reference.endTime * 1000;
174
+
175
+ const tsParser = this.tsParser_.parse(uint8ArrayData);
176
+ const startTime = tsParser.getStartTime();
177
+
178
+ if (startTime.audio != null) {
179
+ timestamp = startTime.audio;
180
+ }
181
+ if (startTime.video != null) {
182
+ timestamp = startTime.video;
183
+ }
184
+ const streamInfos = [];
185
+ const codecs = tsParser.getCodecs();
186
+ try {
187
+ let streamInfo = null;
188
+ if (contentType == ContentType.VIDEO) {
189
+ switch (codecs.video) {
190
+ case 'avc':
191
+ streamInfo =
192
+ this.getAvcStreamInfo_(
193
+ tsParser, timestamp, stream, duration);
194
+ break;
195
+ }
196
+ if (streamInfo) {
197
+ streamInfos.push(streamInfo);
198
+ streamInfo = null;
199
+ }
200
+ }
201
+ if (contentType == ContentType.AUDIO) {
202
+ switch (codecs.audio) {
203
+ case 'aac':
204
+ streamInfo =
205
+ this.getAacStreamInfo_(
206
+ tsParser, timestamp, stream, duration);
207
+ break;
208
+ case 'ac3':
209
+ streamInfo =
210
+ this.getAc3StreamInfo_(
211
+ tsParser, timestamp, stream, duration);
212
+ break;
213
+ case 'ec3':
214
+ streamInfo =
215
+ this.getEc3StreamInfo_(
216
+ tsParser, timestamp, stream, duration);
217
+ break;
218
+ case 'mp3':
219
+ streamInfo =
220
+ this.getMp3StreamInfo_(
221
+ tsParser, timestamp, stream, duration);
222
+ break;
223
+ }
224
+ if (streamInfo) {
225
+ streamInfos.push(streamInfo);
226
+ streamInfo = null;
227
+ }
228
+ }
229
+ } catch (e) {
230
+ return Promise.reject(e);
231
+ }
232
+
233
+ if (!streamInfos.length) {
234
+ return Promise.reject(new shaka.util.Error(
235
+ shaka.util.Error.Severity.CRITICAL,
236
+ shaka.util.Error.Category.MEDIA,
237
+ shaka.util.Error.Code.TRANSMUXING_FAILED));
238
+ }
239
+
240
+ const mp4Generator = new shaka.util.Mp4Generator(streamInfos);
241
+ let initSegment;
242
+ if (!this.initSegments.has(stream.id)) {
243
+ initSegment = mp4Generator.initSegment();
244
+ this.initSegments.set(stream.id, initSegment);
245
+ } else {
246
+ initSegment = this.initSegments.get(stream.id);
247
+ }
248
+ const segmentData = mp4Generator.segmentData();
249
+
250
+ this.frameIndex_++;
251
+ const transmuxData = Uint8ArrayUtils.concat(initSegment, segmentData);
252
+ return Promise.resolve(transmuxData);
253
+ }
254
+
255
+
256
+ /**
257
+ * @param {shaka.util.TsParser} tsParser
258
+ * @param {number} timestamp
259
+ * @param {shaka.extern.Stream} stream
260
+ * @param {number} duration
261
+ * @return {shaka.util.Mp4Generator.StreamInfo}
262
+ * @private
263
+ */
264
+ getAacStreamInfo_(tsParser, timestamp, stream, duration) {
265
+ const ADTS = shaka.transmuxer.ADTS;
266
+
267
+ /** @type {!Array.<shaka.util.Mp4Generator.Mp4Sample>} */
268
+ const samples = [];
269
+
270
+ let info;
271
+
272
+ for (const audioData of tsParser.getAudioData()) {
273
+ const data = audioData.data;
274
+ if (!data) {
275
+ continue;
276
+ }
277
+ let offset = 0;
278
+ info = ADTS.parseInfo(data, offset);
279
+ if (!info) {
280
+ throw new shaka.util.Error(
281
+ shaka.util.Error.Severity.CRITICAL,
282
+ shaka.util.Error.Category.MEDIA,
283
+ shaka.util.Error.Code.TRANSMUXING_FAILED);
284
+ }
285
+ stream.audioSamplingRate = info.sampleRate;
286
+ stream.channelsCount = info.channelCount;
287
+
288
+ while (offset < data.length) {
289
+ const header = ADTS.parseHeader(data, offset);
290
+ if (!header) {
291
+ // We will increment one byte each time until we find the header.
292
+ offset++;
293
+ continue;
294
+ }
295
+ const length = header.headerLength + header.frameLength;
296
+ if (offset + length <= data.length) {
297
+ const frameData = data.subarray(
298
+ offset + header.headerLength, offset + length);
299
+
300
+ samples.push({
301
+ data: frameData,
302
+ size: header.frameLength,
303
+ duration: ADTS.AAC_SAMPLES_PER_FRAME,
304
+ cts: 0,
305
+ flags: {
306
+ isLeading: 0,
307
+ isDependedOn: 0,
308
+ hasRedundancy: 0,
309
+ degradPrio: 0,
310
+ dependsOn: 2,
311
+ isNonSync: 0,
312
+ },
313
+ });
314
+ }
315
+ offset += length;
316
+ }
317
+ }
318
+
319
+ if (!info) {
320
+ throw new shaka.util.Error(
321
+ shaka.util.Error.Severity.CRITICAL,
322
+ shaka.util.Error.Category.MEDIA,
323
+ shaka.util.Error.Code.TRANSMUXING_FAILED);
324
+ }
325
+
326
+ /** @type {number} */
327
+ const sampleRate = info.sampleRate;
328
+ /** @type {number} */
329
+ const baseMediaDecodeTime = Math.floor(timestamp * sampleRate / 1000);
330
+
331
+ return {
332
+ id: stream.id,
333
+ type: shaka.util.ManifestParserUtils.ContentType.AUDIO,
334
+ codecs: info.codec,
335
+ encrypted: stream.encrypted && stream.drmInfos.length > 0,
336
+ timescale: sampleRate,
337
+ duration: duration,
338
+ videoNalus: [],
339
+ audioConfig: new Uint8Array([]),
340
+ videoConfig: new Uint8Array([]),
341
+ data: {
342
+ sequenceNumber: this.frameIndex_,
343
+ baseMediaDecodeTime: baseMediaDecodeTime,
344
+ samples: samples,
345
+ },
346
+ stream: stream,
347
+ };
348
+ }
349
+
350
+
351
+ /**
352
+ * @param {shaka.util.TsParser} tsParser
353
+ * @param {number} timestamp
354
+ * @param {shaka.extern.Stream} stream
355
+ * @param {number} duration
356
+ * @return {shaka.util.Mp4Generator.StreamInfo}
357
+ * @private
358
+ */
359
+ getAc3StreamInfo_(tsParser, timestamp, stream, duration) {
360
+ const Ac3 = shaka.transmuxer.Ac3;
361
+
362
+ /** @type {!Array.<shaka.util.Mp4Generator.Mp4Sample>} */
363
+ const samples = [];
364
+
365
+ /** @type {number} */
366
+ let sampleRate = 0;
367
+
368
+ /** @type {!Uint8Array} */
369
+ let audioConfig = new Uint8Array([]);
370
+
371
+ for (const audioData of tsParser.getAudioData()) {
372
+ const data = audioData.data;
373
+ let offset = 0;
374
+ while (offset < data.length) {
375
+ const frame = Ac3.parseFrame(data, offset);
376
+ if (!frame) {
377
+ offset++;
378
+ continue;
379
+ }
380
+ stream.audioSamplingRate = frame.sampleRate;
381
+ stream.channelsCount = frame.channelCount;
382
+ sampleRate = frame.sampleRate;
383
+ audioConfig = frame.audioConfig;
384
+
385
+ const frameData = data.subarray(
386
+ offset, offset + frame.frameLength);
387
+
388
+ samples.push({
389
+ data: frameData,
390
+ size: frame.frameLength,
391
+ duration: Ac3.AC3_SAMPLES_PER_FRAME,
392
+ cts: 0,
393
+ flags: {
394
+ isLeading: 0,
395
+ isDependedOn: 0,
396
+ hasRedundancy: 0,
397
+ degradPrio: 0,
398
+ dependsOn: 2,
399
+ isNonSync: 0,
400
+ },
401
+ });
402
+ offset += frame.frameLength;
403
+ }
404
+ }
405
+
406
+ if (sampleRate == 0 || audioConfig.byteLength == 0) {
407
+ throw new shaka.util.Error(
408
+ shaka.util.Error.Severity.CRITICAL,
409
+ shaka.util.Error.Category.MEDIA,
410
+ shaka.util.Error.Code.TRANSMUXING_FAILED);
411
+ }
412
+
413
+
414
+ /** @type {number} */
415
+ const baseMediaDecodeTime = Math.floor(timestamp * sampleRate / 1000);
416
+
417
+ return {
418
+ id: stream.id,
419
+ type: shaka.util.ManifestParserUtils.ContentType.AUDIO,
420
+ codecs: 'ac-3',
421
+ encrypted: stream.encrypted && stream.drmInfos.length > 0,
422
+ timescale: sampleRate,
423
+ duration: duration,
424
+ videoNalus: [],
425
+ audioConfig: audioConfig,
426
+ videoConfig: new Uint8Array([]),
427
+ data: {
428
+ sequenceNumber: this.frameIndex_,
429
+ baseMediaDecodeTime: baseMediaDecodeTime,
430
+ samples: samples,
431
+ },
432
+ stream: stream,
433
+ };
434
+ }
435
+
436
+
437
+ /**
438
+ * @param {shaka.util.TsParser} tsParser
439
+ * @param {number} timestamp
440
+ * @param {shaka.extern.Stream} stream
441
+ * @param {number} duration
442
+ * @return {shaka.util.Mp4Generator.StreamInfo}
443
+ * @private
444
+ */
445
+ getEc3StreamInfo_(tsParser, timestamp, stream, duration) {
446
+ const Ec3 = shaka.transmuxer.Ec3;
447
+
448
+ /** @type {!Array.<shaka.util.Mp4Generator.Mp4Sample>} */
449
+ const samples = [];
450
+
451
+ /** @type {number} */
452
+ let sampleRate = 0;
453
+
454
+ /** @type {!Uint8Array} */
455
+ let audioConfig = new Uint8Array([]);
456
+
457
+ for (const audioData of tsParser.getAudioData()) {
458
+ const data = audioData.data;
459
+ let offset = 0;
460
+ while (offset < data.length) {
461
+ const frame = Ec3.parseFrame(data, offset);
462
+ if (!frame) {
463
+ offset++;
464
+ continue;
465
+ }
466
+ stream.audioSamplingRate = frame.sampleRate;
467
+ stream.channelsCount = frame.channelCount;
468
+ sampleRate = frame.sampleRate;
469
+ audioConfig = frame.audioConfig;
470
+
471
+ const frameData = data.subarray(
472
+ offset, offset + frame.frameLength);
473
+
474
+ samples.push({
475
+ data: frameData,
476
+ size: frame.frameLength,
477
+ duration: Ec3.EC3_SAMPLES_PER_FRAME,
478
+ cts: 0,
479
+ flags: {
480
+ isLeading: 0,
481
+ isDependedOn: 0,
482
+ hasRedundancy: 0,
483
+ degradPrio: 0,
484
+ dependsOn: 2,
485
+ isNonSync: 0,
486
+ },
487
+ });
488
+ offset += frame.frameLength;
489
+ }
490
+ }
491
+
492
+ if (sampleRate == 0 || audioConfig.byteLength == 0) {
493
+ throw new shaka.util.Error(
494
+ shaka.util.Error.Severity.CRITICAL,
495
+ shaka.util.Error.Category.MEDIA,
496
+ shaka.util.Error.Code.TRANSMUXING_FAILED);
497
+ }
498
+
499
+
500
+ /** @type {number} */
501
+ const baseMediaDecodeTime = Math.floor(timestamp * sampleRate / 1000);
502
+
503
+ return {
504
+ id: stream.id,
505
+ type: shaka.util.ManifestParserUtils.ContentType.AUDIO,
506
+ codecs: 'ec-3',
507
+ encrypted: stream.encrypted && stream.drmInfos.length > 0,
508
+ timescale: sampleRate,
509
+ duration: duration,
510
+ videoNalus: [],
511
+ audioConfig: audioConfig,
512
+ videoConfig: new Uint8Array([]),
513
+ data: {
514
+ sequenceNumber: this.frameIndex_,
515
+ baseMediaDecodeTime: baseMediaDecodeTime,
516
+ samples: samples,
517
+ },
518
+ stream: stream,
519
+ };
520
+ }
521
+
522
+
523
+ /**
524
+ * @param {shaka.util.TsParser} tsParser
525
+ * @param {number} timestamp
526
+ * @param {shaka.extern.Stream} stream
527
+ * @param {number} duration
528
+ * @return {shaka.util.Mp4Generator.StreamInfo}
529
+ * @private
530
+ */
531
+ getMp3StreamInfo_(tsParser, timestamp, stream, duration) {
532
+ const MpegAudio = shaka.transmuxer.MpegAudio;
533
+
534
+ /** @type {!Array.<shaka.util.Mp4Generator.Mp4Sample>} */
535
+ const samples = [];
536
+
537
+ let firstHeader;
538
+
539
+ for (const audioData of tsParser.getAudioData()) {
540
+ const data = audioData.data;
541
+ if (!data) {
542
+ continue;
543
+ }
544
+ let offset = 0;
545
+ while (offset < data.length) {
546
+ const header = MpegAudio.parseHeader(data, offset);
547
+ if (!header) {
548
+ offset++;
549
+ continue;
550
+ }
551
+ if (!firstHeader) {
552
+ firstHeader = header;
553
+ }
554
+ if (offset + header.frameLength <= data.length) {
555
+ samples.push({
556
+ data: data.subarray(offset, offset + header.frameLength),
557
+ size: header.frameLength,
558
+ duration: MpegAudio.MPEG_AUDIO_SAMPLE_PER_FRAME,
559
+ cts: 0,
560
+ flags: {
561
+ isLeading: 0,
562
+ isDependedOn: 0,
563
+ hasRedundancy: 0,
564
+ degradPrio: 0,
565
+ dependsOn: 2,
566
+ isNonSync: 0,
567
+ },
568
+ });
569
+ }
570
+ offset += header.frameLength;
571
+ }
572
+ }
573
+ if (!firstHeader) {
574
+ throw new shaka.util.Error(
575
+ shaka.util.Error.Severity.CRITICAL,
576
+ shaka.util.Error.Category.MEDIA,
577
+ shaka.util.Error.Code.TRANSMUXING_FAILED);
578
+ }
579
+ /** @type {number} */
580
+ const sampleRate = firstHeader.sampleRate;
581
+ /** @type {number} */
582
+ const baseMediaDecodeTime = Math.floor(timestamp * sampleRate / 1000);
583
+
584
+ return {
585
+ id: stream.id,
586
+ type: shaka.util.ManifestParserUtils.ContentType.AUDIO,
587
+ codecs: 'mp3',
588
+ encrypted: stream.encrypted && stream.drmInfos.length > 0,
589
+ timescale: sampleRate,
590
+ duration: duration,
591
+ videoNalus: [],
592
+ audioConfig: new Uint8Array([]),
593
+ videoConfig: new Uint8Array([]),
594
+ data: {
595
+ sequenceNumber: this.frameIndex_,
596
+ baseMediaDecodeTime: baseMediaDecodeTime,
597
+ samples: samples,
598
+ },
599
+ stream: stream,
600
+ };
601
+ }
602
+
603
+
604
+ /**
605
+ * @param {shaka.util.TsParser} tsParser
606
+ * @param {number} timestamp
607
+ * @param {shaka.extern.Stream} stream
608
+ * @param {number} duration
609
+ * @return {shaka.util.Mp4Generator.StreamInfo}
610
+ * @private
611
+ */
612
+ getAvcStreamInfo_(tsParser, timestamp, stream, duration) {
613
+ const H264 = shaka.transmuxer.H264;
614
+ const timescale = shaka.util.TsParser.Timescale;
615
+
616
+ /** @type {!Array.<shaka.util.Mp4Generator.Mp4Sample>} */
617
+ const samples = [];
618
+
619
+ /** @type {?number} */
620
+ let baseMediaDecodeTime = null;
621
+
622
+ let nalus = [];
623
+ const videoData = tsParser.getVideoData().filter((pes) => {
624
+ return pes.pts != null && pes.dts != null;
625
+ });
626
+ for (let i = 0; i < videoData.length; i++) {
627
+ const pes = videoData[i];
628
+ let nextPes;
629
+ if (i + 1 < videoData.length) {
630
+ nextPes = videoData[i + 1];
631
+ }
632
+ const dataNalus = tsParser.parseAvcNalus(pes, nextPes);
633
+ nalus = nalus.concat(dataNalus);
634
+ const frame = H264.parseFrame(dataNalus);
635
+ if (!frame) {
636
+ continue;
637
+ }
638
+ if (baseMediaDecodeTime == null && pes.dts != null) {
639
+ baseMediaDecodeTime = pes.dts;
640
+ }
641
+ let duration;
642
+ if (i + 1 < videoData.length) {
643
+ duration = (videoData[i + 1].dts || 0) - (pes.dts || 0);
644
+ } else {
645
+ duration = (pes.dts || 0) - (videoData[i - 1].dts || 0);
646
+ }
647
+ samples.push({
648
+ data: frame.data,
649
+ size: frame.data.byteLength,
650
+ duration: duration,
651
+ cts: Math.round((pes.pts || 0) - (pes.dts || 0)),
652
+ flags: {
653
+ isLeading: 0,
654
+ isDependedOn: 0,
655
+ hasRedundancy: 0,
656
+ degradPrio: 0,
657
+ dependsOn: frame.isKeyframe ? 2 : 1,
658
+ isNonSync: frame.isKeyframe ? 0 : 1,
659
+ },
660
+ });
661
+ }
662
+
663
+ const info = H264.parseInfo(nalus);
664
+
665
+ if (!info || baseMediaDecodeTime == null) {
666
+ throw new shaka.util.Error(
667
+ shaka.util.Error.Severity.CRITICAL,
668
+ shaka.util.Error.Category.MEDIA,
669
+ shaka.util.Error.Code.TRANSMUXING_FAILED);
670
+ }
671
+ stream.height = info.height;
672
+ stream.width = info.width;
673
+
674
+ return {
675
+ id: stream.id,
676
+ type: shaka.util.ManifestParserUtils.ContentType.VIDEO,
677
+ codecs: 'avc1',
678
+ encrypted: stream.encrypted && stream.drmInfos.length > 0,
679
+ timescale: timescale,
680
+ duration: duration,
681
+ videoNalus: [],
682
+ audioConfig: new Uint8Array([]),
683
+ videoConfig: info.videoConfig,
684
+ data: {
685
+ sequenceNumber: this.frameIndex_,
686
+ baseMediaDecodeTime: baseMediaDecodeTime,
687
+ samples: samples,
688
+ },
689
+ stream: stream,
690
+ };
691
+ }
692
+ };
693
+
694
+ /**
695
+ * Supported audio codecs.
696
+ *
697
+ * @private
698
+ * @const {!Array.<string>}
699
+ */
700
+ shaka.transmuxer.TsTransmuxer.SUPPORTED_AUDIO_CODECS_ = [
701
+ 'aac',
702
+ 'ac-3',
703
+ 'ec-3',
704
+ 'mp3',
705
+ ];
706
+
707
+ /**
708
+ * Supported audio codecs.
709
+ *
710
+ * @private
711
+ * @const {!Array.<string>}
712
+ */
713
+ shaka.transmuxer.TsTransmuxer.SUPPORTED_VIDEO_CODECS_ = [
714
+ 'avc',
715
+ ];
716
+
717
+
718
+ shaka.transmuxer.TransmuxerEngine.registerTransmuxer(
719
+ 'video/mp2t',
720
+ () => new shaka.transmuxer.TsTransmuxer('video/mp2t'),
721
+ shaka.transmuxer.TransmuxerEngine.PluginPriority.PREFERRED);