@alessmicrosystems/mpegts.js 1.8.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 (121) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +158 -0
  3. package/README_ja.md +153 -0
  4. package/README_zh.md +157 -0
  5. package/d.ts/mpegts.d.ts +524 -0
  6. package/d.ts/src/core/mse-events.d.ts +9 -0
  7. package/d.ts/src/core/transmuxing-events.d.ts +24 -0
  8. package/d.ts/src/demux/aac.d.ts +44 -0
  9. package/d.ts/src/demux/ac3.d.ts +70 -0
  10. package/d.ts/src/demux/av1-parser.d.ts +77 -0
  11. package/d.ts/src/demux/av1.d.ts +11 -0
  12. package/d.ts/src/demux/base-demuxer.d.ts +55 -0
  13. package/d.ts/src/demux/h264.d.ts +40 -0
  14. package/d.ts/src/demux/h265.d.ts +65 -0
  15. package/d.ts/src/demux/klv.d.ts +17 -0
  16. package/d.ts/src/demux/mp3.d.ts +6 -0
  17. package/d.ts/src/demux/mpeg4-audio.d.ts +28 -0
  18. package/d.ts/src/demux/pat-pmt-pes.d.ts +106 -0
  19. package/d.ts/src/demux/patpmt.d.ts +40 -0
  20. package/d.ts/src/demux/pes-private-data.d.ts +14 -0
  21. package/d.ts/src/demux/pgs-data.d.ts +9 -0
  22. package/d.ts/src/demux/scte35.d.ts +250 -0
  23. package/d.ts/src/demux/sei.d.ts +8 -0
  24. package/d.ts/src/demux/smpte2038.d.ts +22 -0
  25. package/d.ts/src/demux/ts-demuxer.d.ts +124 -0
  26. package/d.ts/src/player/live-latency-chaser.d.ts +10 -0
  27. package/d.ts/src/player/live-latency-synchronizer.d.ts +10 -0
  28. package/d.ts/src/player/loading-controller.d.ts +19 -0
  29. package/d.ts/src/player/mse-player.d.ts +30 -0
  30. package/d.ts/src/player/player-engine-dedicated-thread-worker.d.ts +2 -0
  31. package/d.ts/src/player/player-engine-dedicated-thread.d.ts +48 -0
  32. package/d.ts/src/player/player-engine-main-thread.d.ts +50 -0
  33. package/d.ts/src/player/player-engine-worker-cmd-def.d.ts +25 -0
  34. package/d.ts/src/player/player-engine-worker-msg-def.d.ts +54 -0
  35. package/d.ts/src/player/player-engine-worker.d.ts +2 -0
  36. package/d.ts/src/player/player-engine.d.ts +16 -0
  37. package/d.ts/src/player/player-events.d.ts +21 -0
  38. package/d.ts/src/player/seeking-handler.d.ts +22 -0
  39. package/d.ts/src/player/startup-stall-jumper.d.ts +14 -0
  40. package/d.ts/src/utils/typedarray-equality.d.ts +2 -0
  41. package/dist/mpegts.js +3 -0
  42. package/dist/mpegts.js.LICENSE.txt +7 -0
  43. package/dist/mpegts.js.map +1 -0
  44. package/package.json +53 -0
  45. package/src/config.js +67 -0
  46. package/src/core/features.js +88 -0
  47. package/src/core/media-info.js +127 -0
  48. package/src/core/media-segment-info.js +230 -0
  49. package/src/core/mse-controller.js +599 -0
  50. package/src/core/mse-events.ts +28 -0
  51. package/src/core/transmuxer.js +346 -0
  52. package/src/core/transmuxing-controller.js +628 -0
  53. package/src/core/transmuxing-events.ts +43 -0
  54. package/src/core/transmuxing-worker.js +286 -0
  55. package/src/demux/aac.ts +397 -0
  56. package/src/demux/ac3.ts +335 -0
  57. package/src/demux/amf-parser.js +243 -0
  58. package/src/demux/av1-parser.ts +629 -0
  59. package/src/demux/av1.ts +103 -0
  60. package/src/demux/base-demuxer.ts +69 -0
  61. package/src/demux/demux-errors.js +26 -0
  62. package/src/demux/exp-golomb.js +116 -0
  63. package/src/demux/flv-demuxer.js +1854 -0
  64. package/src/demux/h264.ts +187 -0
  65. package/src/demux/h265-parser.js +501 -0
  66. package/src/demux/h265.ts +214 -0
  67. package/src/demux/klv.ts +40 -0
  68. package/src/demux/mp3.ts +7 -0
  69. package/src/demux/mpeg4-audio.ts +45 -0
  70. package/src/demux/pat-pmt-pes.ts +132 -0
  71. package/src/demux/pes-private-data.ts +16 -0
  72. package/src/demux/pgs-data.ts +11 -0
  73. package/src/demux/scte35.ts +723 -0
  74. package/src/demux/sei.ts +99 -0
  75. package/src/demux/smpte2038.ts +89 -0
  76. package/src/demux/sps-parser.js +298 -0
  77. package/src/demux/ts-demuxer.ts +2405 -0
  78. package/src/index.js +4 -0
  79. package/src/io/fetch-stream-loader.js +266 -0
  80. package/src/io/io-controller.js +647 -0
  81. package/src/io/loader.js +134 -0
  82. package/src/io/param-seek-handler.js +85 -0
  83. package/src/io/range-seek-handler.js +52 -0
  84. package/src/io/speed-sampler.js +93 -0
  85. package/src/io/websocket-loader.js +151 -0
  86. package/src/io/xhr-moz-chunked-loader.js +211 -0
  87. package/src/io/xhr-msstream-loader.js +307 -0
  88. package/src/io/xhr-range-loader.js +366 -0
  89. package/src/mpegts.js +95 -0
  90. package/src/player/live-latency-chaser.ts +66 -0
  91. package/src/player/live-latency-synchronizer.ts +79 -0
  92. package/src/player/loading-controller.ts +142 -0
  93. package/src/player/mse-player.ts +150 -0
  94. package/src/player/native-player.js +262 -0
  95. package/src/player/player-engine-dedicated-thread.ts +479 -0
  96. package/src/player/player-engine-main-thread.ts +463 -0
  97. package/src/player/player-engine-worker-cmd-def.ts +62 -0
  98. package/src/player/player-engine-worker-msg-def.ts +102 -0
  99. package/src/player/player-engine-worker.ts +370 -0
  100. package/src/player/player-engine.ts +35 -0
  101. package/src/player/player-errors.js +39 -0
  102. package/src/player/player-events.ts +40 -0
  103. package/src/player/seeking-handler.ts +205 -0
  104. package/src/player/startup-stall-jumper.ts +86 -0
  105. package/src/remux/aac-silent.js +56 -0
  106. package/src/remux/mp4-generator.js +866 -0
  107. package/src/remux/mp4-remuxer.js +778 -0
  108. package/src/utils/browser.js +128 -0
  109. package/src/utils/exception.js +73 -0
  110. package/src/utils/logger.js +140 -0
  111. package/src/utils/logging-control.js +165 -0
  112. package/src/utils/polyfill.js +68 -0
  113. package/src/utils/typedarray-equality.ts +69 -0
  114. package/src/utils/utf8-conv.js +84 -0
  115. package/src/utils/webworkify-webpack.js +202 -0
  116. package/tsconfig.json +16 -0
  117. package/tslint.json +1 -0
  118. package/types/index.d.ts +3 -0
  119. package/types/test-flv.ts +8 -0
  120. package/types/tsconfig.json +24 -0
  121. package/webpack.config.js +55 -0
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright (C) 2016 Bilibili. All Rights Reserved.
3
+ *
4
+ * This file is derived from C++ project libWinTF8 (https://github.com/m13253/libWinTF8)
5
+ * @author zheng qian <xqq@xqq.im>
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ function checkContinuation(uint8array, start, checkLength) {
21
+ let array = uint8array;
22
+ if (start + checkLength < array.length) {
23
+ while (checkLength--) {
24
+ if ((array[++start] & 0xC0) !== 0x80)
25
+ return false;
26
+ }
27
+ return true;
28
+ } else {
29
+ return false;
30
+ }
31
+ }
32
+
33
+ function decodeUTF8(uint8array) {
34
+ let out = [];
35
+ let input = uint8array;
36
+ let i = 0;
37
+ let length = uint8array.length;
38
+
39
+ while (i < length) {
40
+ if (input[i] < 0x80) {
41
+ out.push(String.fromCharCode(input[i]));
42
+ ++i;
43
+ continue;
44
+ } else if (input[i] < 0xC0) {
45
+ // fallthrough
46
+ } else if (input[i] < 0xE0) {
47
+ if (checkContinuation(input, i, 1)) {
48
+ let ucs4 = (input[i] & 0x1F) << 6 | (input[i + 1] & 0x3F);
49
+ if (ucs4 >= 0x80) {
50
+ out.push(String.fromCharCode(ucs4 & 0xFFFF));
51
+ i += 2;
52
+ continue;
53
+ }
54
+ }
55
+ } else if (input[i] < 0xF0) {
56
+ if (checkContinuation(input, i, 2)) {
57
+ let ucs4 = (input[i] & 0xF) << 12 | (input[i + 1] & 0x3F) << 6 | input[i + 2] & 0x3F;
58
+ if (ucs4 >= 0x800 && (ucs4 & 0xF800) !== 0xD800) {
59
+ out.push(String.fromCharCode(ucs4 & 0xFFFF));
60
+ i += 3;
61
+ continue;
62
+ }
63
+ }
64
+ } else if (input[i] < 0xF8) {
65
+ if (checkContinuation(input, i, 3)) {
66
+ let ucs4 = (input[i] & 0x7) << 18 | (input[i + 1] & 0x3F) << 12
67
+ | (input[i + 2] & 0x3F) << 6 | (input[i + 3] & 0x3F);
68
+ if (ucs4 > 0x10000 && ucs4 < 0x110000) {
69
+ ucs4 -= 0x10000;
70
+ out.push(String.fromCharCode((ucs4 >>> 10) | 0xD800));
71
+ out.push(String.fromCharCode((ucs4 & 0x3FF) | 0xDC00));
72
+ i += 4;
73
+ continue;
74
+ }
75
+ }
76
+ }
77
+ out.push(String.fromCharCode(0xFFFD));
78
+ ++i;
79
+ }
80
+
81
+ return out.join('');
82
+ }
83
+
84
+ export default decodeUTF8;
@@ -0,0 +1,202 @@
1
+ function webpackBootstrapFunc (modules) {
2
+ /******/ // The module cache
3
+ /******/ var installedModules = {};
4
+
5
+ /******/ // The require function
6
+ /******/ function __webpack_require__(moduleId) {
7
+
8
+ /******/ // Check if module is in cache
9
+ /******/ if(installedModules[moduleId])
10
+ /******/ return installedModules[moduleId].exports;
11
+
12
+ /******/ // Create a new module (and put it into the cache)
13
+ /******/ var module = installedModules[moduleId] = {
14
+ /******/ i: moduleId,
15
+ /******/ l: false,
16
+ /******/ exports: {}
17
+ /******/ };
18
+
19
+ /******/ // Execute the module function
20
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
+
22
+ /******/ // Flag the module as loaded
23
+ /******/ module.l = true;
24
+
25
+ /******/ // Return the exports of the module
26
+ /******/ return module.exports;
27
+ /******/ }
28
+
29
+ /******/ // expose the modules object (__webpack_modules__)
30
+ /******/ __webpack_require__.m = modules;
31
+
32
+ /******/ // expose the module cache
33
+ /******/ __webpack_require__.c = installedModules;
34
+
35
+ /******/ // identity function for calling harmony imports with the correct context
36
+ /******/ __webpack_require__.i = function(value) { return value; };
37
+
38
+ /******/ // define getter function for harmony exports
39
+ /******/ __webpack_require__.d = function(exports, name, getter) {
40
+ /******/ if(!__webpack_require__.o(exports, name)) {
41
+ /******/ Object.defineProperty(exports, name, {
42
+ /******/ configurable: false,
43
+ /******/ enumerable: true,
44
+ /******/ get: getter
45
+ /******/ });
46
+ /******/ }
47
+ /******/ };
48
+
49
+ /******/ // define __esModule on exports
50
+ /******/ __webpack_require__.r = function(exports) {
51
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
52
+ /******/ };
53
+
54
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
55
+ /******/ __webpack_require__.n = function(module) {
56
+ /******/ var getter = module && module.__esModule ?
57
+ /******/ function getDefault() { return module['default']; } :
58
+ /******/ function getModuleExports() { return module; };
59
+ /******/ __webpack_require__.d(getter, 'a', getter);
60
+ /******/ return getter;
61
+ /******/ };
62
+
63
+ /******/ // Object.prototype.hasOwnProperty.call
64
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
65
+
66
+ /******/ // __webpack_public_path__
67
+ /******/ __webpack_require__.p = "/";
68
+
69
+ /******/ // on error function for async loading
70
+ /******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };
71
+
72
+ var f = __webpack_require__(__webpack_require__.s = ENTRY_MODULE)
73
+ return f.default || f // try to call default if defined to also support babel esmodule exports
74
+ }
75
+
76
+ var moduleNameReqExp = '[\\.|\\-|\\+|\\w|\/|@]+'
77
+ var dependencyRegExp = '\\(\\s*(\/\\*.*?\\*\/)?\\s*.*?(' + moduleNameReqExp + ').*?\\)' // additional chars when output.pathinfo is true
78
+
79
+ // http://stackoverflow.com/a/2593661/130442
80
+ function quoteRegExp (str) {
81
+ return (str + '').replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&')
82
+ }
83
+
84
+ function isNumeric(n) {
85
+ return !isNaN(1 * n); // 1 * n converts integers, integers as string ("123"), 1e3 and "1e3" to integers and strings to NaN
86
+ }
87
+
88
+ function getModuleDependencies (sources, module, queueName) {
89
+ var retval = {}
90
+ retval[queueName] = []
91
+
92
+ var fnString = module.toString()
93
+ var wrapperSignature = fnString.match(/^function\s?\w*\(\w+,\s*\w+,\s*(\w+)\)/)
94
+ if (!wrapperSignature) return retval
95
+ var webpackRequireName = wrapperSignature[1]
96
+
97
+ // main bundle deps
98
+ var re = new RegExp('(\\\\n|\\W)' + quoteRegExp(webpackRequireName) + dependencyRegExp, 'g')
99
+ var match
100
+ while ((match = re.exec(fnString))) {
101
+ if (match[3] === 'dll-reference') continue
102
+ retval[queueName].push(match[3])
103
+ }
104
+
105
+ // dll deps
106
+ re = new RegExp('\\(' + quoteRegExp(webpackRequireName) + '\\("(dll-reference\\s(' + moduleNameReqExp + '))"\\)\\)' + dependencyRegExp, 'g')
107
+ while ((match = re.exec(fnString))) {
108
+ if (!sources[match[2]]) {
109
+ retval[queueName].push(match[1])
110
+ sources[match[2]] = __webpack_require__(match[1]).m
111
+ }
112
+ retval[match[2]] = retval[match[2]] || []
113
+ retval[match[2]].push(match[4])
114
+ }
115
+
116
+ // convert 1e3 back to 1000 - this can be important after uglify-js converted 1000 to 1e3
117
+ var keys = Object.keys(retval);
118
+ for (var i = 0; i < keys.length; i++) {
119
+ for (var j = 0; j < retval[keys[i]].length; j++) {
120
+ if (isNumeric(retval[keys[i]][j])) {
121
+ retval[keys[i]][j] = 1 * retval[keys[i]][j];
122
+ }
123
+ }
124
+ }
125
+
126
+ return retval
127
+ }
128
+
129
+ function hasValuesInQueues (queues) {
130
+ var keys = Object.keys(queues)
131
+ return keys.reduce(function (hasValues, key) {
132
+ return hasValues || queues[key].length > 0
133
+ }, false)
134
+ }
135
+
136
+ function getRequiredModules (sources, moduleId) {
137
+ var modulesQueue = {
138
+ main: [moduleId]
139
+ }
140
+ var requiredModules = {
141
+ main: []
142
+ }
143
+ var seenModules = {
144
+ main: {}
145
+ }
146
+
147
+ while (hasValuesInQueues(modulesQueue)) {
148
+ var queues = Object.keys(modulesQueue)
149
+ for (var i = 0; i < queues.length; i++) {
150
+ var queueName = queues[i]
151
+ var queue = modulesQueue[queueName]
152
+ var moduleToCheck = queue.pop()
153
+ seenModules[queueName] = seenModules[queueName] || {}
154
+ if (seenModules[queueName][moduleToCheck] || !sources[queueName][moduleToCheck]) continue
155
+ seenModules[queueName][moduleToCheck] = true
156
+ requiredModules[queueName] = requiredModules[queueName] || []
157
+ requiredModules[queueName].push(moduleToCheck)
158
+ var newModules = getModuleDependencies(sources, sources[queueName][moduleToCheck], queueName)
159
+ var newModulesKeys = Object.keys(newModules)
160
+ for (var j = 0; j < newModulesKeys.length; j++) {
161
+ modulesQueue[newModulesKeys[j]] = modulesQueue[newModulesKeys[j]] || []
162
+ modulesQueue[newModulesKeys[j]] = modulesQueue[newModulesKeys[j]].concat(newModules[newModulesKeys[j]])
163
+ }
164
+ }
165
+ }
166
+
167
+ return requiredModules
168
+ }
169
+
170
+ module.exports = function (moduleId, options) {
171
+ options = options || {}
172
+ var sources = {
173
+ main: __webpack_modules__
174
+ }
175
+
176
+ var requiredModules = options.all ? { main: Object.keys(sources.main) } : getRequiredModules(sources, moduleId)
177
+
178
+ var src = ''
179
+
180
+ Object.keys(requiredModules).filter(function (m) { return m !== 'main' }).forEach(function (module) {
181
+ var entryModule = 0
182
+ while (requiredModules[module][entryModule]) {
183
+ entryModule++
184
+ }
185
+ requiredModules[module].push(entryModule)
186
+ sources[module][entryModule] = '(function(module, exports, __webpack_require__) { module.exports = __webpack_require__; })'
187
+ src = src + 'var ' + module + ' = (' + webpackBootstrapFunc.toString().replace('ENTRY_MODULE', JSON.stringify(entryModule)) + ')({' + requiredModules[module].map(function (id) { return '' + JSON.stringify(id) + ': ' + sources[module][id].toString() }).join(',') + '});\n'
188
+ })
189
+
190
+ src = src + 'new ((' + webpackBootstrapFunc.toString().replace('ENTRY_MODULE', JSON.stringify(moduleId)) + ')({' + requiredModules.main.map(function (id) { return '' + JSON.stringify(id) + ': ' + sources.main[id].toString() }).join(',') + '}))(self);'
191
+
192
+ var blob = new self.Blob([src], { type: 'text/javascript' })
193
+ if (options.bare) { return blob }
194
+
195
+ var URL = self.URL || self.webkitURL || self.mozURL || self.msURL
196
+
197
+ var workerUrl = URL.createObjectURL(blob)
198
+ var worker = new self.Worker(workerUrl)
199
+ worker.objectURL = workerUrl
200
+
201
+ return worker
202
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist/",
4
+ "allowJs": true,
5
+ "sourceMap": true,
6
+ "module": "es6",
7
+ "target": "es5",
8
+ "experimentalDecorators": true,
9
+ "declaration": true,
10
+ "declarationDir": "./d.ts/",
11
+ "lib": ["dom", "es5", "es2015.promise", "es2015.collection", "ESNext", "WebWorker"]
12
+ },
13
+ "include": [
14
+ "./src/**/*",
15
+ ]
16
+ }
package/tslint.json ADDED
@@ -0,0 +1 @@
1
+ { "extends": "dtslint/dt.json" }
@@ -0,0 +1,3 @@
1
+ // TypeScript Version: 2.3
2
+
3
+ import '../d.ts/mpegts.d.ts';
@@ -0,0 +1,8 @@
1
+ import mpegts from '../';
2
+
3
+ type LoaderStatusAlias = mpegts.LoaderStatus;
4
+ type LoaderErrorsAlias = mpegts.LoaderErrors;
5
+
6
+ interface MediaDataSourceExt extends mpegts.MediaDataSource {
7
+ example: string;
8
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "lib": [
5
+ "es6",
6
+ "dom"
7
+ ],
8
+ "noImplicitAny": true,
9
+ "noImplicitThis": true,
10
+ "strictNullChecks": true,
11
+ "strictFunctionTypes": true,
12
+ "baseUrl": "./",
13
+ "typeRoots": [
14
+ "./"
15
+ ],
16
+ "types": [],
17
+ "noEmit": true,
18
+ "forceConsistentCasingInFileNames": true
19
+ },
20
+ "files": [
21
+ "index.d.ts",
22
+ "../d.ts/mpegts.d.ts"
23
+ ]
24
+ }
@@ -0,0 +1,55 @@
1
+ const webpack = require('webpack');
2
+ const packagejson = require("./package.json");
3
+ const path = require('path');
4
+
5
+ module.exports = {
6
+ entry: './src/index.js',
7
+ output: {
8
+ filename: 'mpegts.js',
9
+ path: path.resolve(__dirname, 'dist'),
10
+ library: 'mpegts',
11
+ libraryTarget: 'umd'
12
+ },
13
+
14
+ devtool: 'source-map',
15
+
16
+ resolve: {
17
+ extensions: ['.ts', '.tsx', '.js', '.json'],
18
+ fallback: {
19
+ 'fs': false,
20
+ 'path': false
21
+ }
22
+ },
23
+
24
+ plugins: [
25
+ new webpack.DefinePlugin({
26
+ __VERSION__: JSON.stringify(packagejson.version)
27
+ })
28
+ ],
29
+
30
+ module: {
31
+ rules: [
32
+ {
33
+ test: /\.(ts|js)$/,
34
+ use: 'ts-loader',
35
+ exclude: /node-modules/
36
+ },
37
+ {
38
+ enforce: 'pre',
39
+ test: /\.js$/,
40
+ use: 'source-map-loader'
41
+ }
42
+ ]
43
+ },
44
+
45
+ devServer: {
46
+ static: ['demo'],
47
+ proxy: [
48
+ {
49
+ context: ['/dist'],
50
+ target: 'http://localhost:8080',
51
+ pathRewrite: {'^/dist' : ''}
52
+ }
53
+ ]
54
+ }
55
+ };