@xmov/avatar 2.0.0-alpha.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +139 -0
- package/dist/agent/__tests__/agent.test.d.ts +1 -0
- package/dist/agent/audio-debug.d.ts +3 -0
- package/dist/agent/audio-uplink.d.ts +62 -0
- package/dist/agent/avatar.cjs +2 -0
- package/dist/agent/avatar.cjs.map +1 -0
- package/dist/agent/avatar.modern.js +2 -0
- package/dist/agent/avatar.modern.js.map +1 -0
- package/dist/agent/avatar.module.js +2 -0
- package/dist/agent/avatar.module.js.map +1 -0
- package/dist/agent/avatar.umd.js +2 -0
- package/dist/agent/avatar.umd.js.map +1 -0
- package/dist/agent/e2e-client.d.ts +32 -0
- package/dist/agent/fixed-audio-track.d.ts +48 -0
- package/dist/agent/index.cjs +5 -0
- package/dist/agent/index.d.ts +104 -0
- package/dist/agent/index.umd.js +10 -0
- package/dist/agent/microphone.d.ts +49 -0
- package/dist/agent/types.d.ts +153 -0
- package/dist/baseRender/AudioRenderer.d.ts +46 -0
- package/dist/baseRender/AudioWorklet.d.ts +78 -0
- package/dist/baseRender/AvatarRenderer.d.ts +226 -0
- package/dist/baseRender/MSEAudioPlayer.d.ts +51 -0
- package/dist/baseRender/UIRenderer.d.ts +39 -0
- package/dist/baseRender/pcm-audio-processor.d.ts +63 -0
- package/dist/control/APIForwarder.d.ts +23 -0
- package/dist/control/DataCacheQueue.d.ts +69 -0
- package/dist/control/EventDispatcher.d.ts +35 -0
- package/dist/control/RenderScheduler.d.ts +162 -0
- package/dist/control/SaveAndDownload.d.ts +14 -0
- package/dist/control/StreamingClient.d.ts +33 -0
- package/dist/control/VideoPlayer.d.ts +47 -0
- package/dist/control/ttsa.d.ts +111 -0
- package/dist/encoding/media-recorder-encoder.d.ts +33 -0
- package/dist/encoding/pcm-webm-encoder.d.ts +13 -0
- package/dist/encoding/webcodec-opus-encoder.d.ts +41 -0
- package/dist/encoding/webm-muxer.d.ts +90 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +231 -0
- package/dist/index.modern.js +2 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.module.js +2 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/modules/Composition.d.ts +28 -0
- package/dist/modules/ResourceManager.d.ts +295 -0
- package/dist/modules/TrackRenderer/base-track.d.ts +4 -0
- package/dist/modules/TrackRenderer/index.d.ts +12 -0
- package/dist/modules/TrackRenderer/render-implements.d.ts +19 -0
- package/dist/modules/TrackRenderer/track-pic.d.ts +8 -0
- package/dist/modules/TrackRenderer/track-subtitle.d.ts +8 -0
- package/dist/modules/cache-manager.d.ts +5 -0
- package/dist/modules/decoder.d.ts +84 -0
- package/dist/modules/error-handle.d.ts +17 -0
- package/dist/modules/network.d.ts +21 -0
- package/dist/proto/face_data_pb.d.ts +0 -0
- package/dist/types/capability.d.ts +15 -0
- package/dist/types/error.d.ts +70 -0
- package/dist/types/event.d.ts +25 -0
- package/dist/types/frame-data.d.ts +107 -0
- package/dist/types/index.d.ts +187 -0
- package/dist/types/render.d.ts +18 -0
- package/dist/utils/DataInterface.d.ts +113 -0
- package/dist/utils/GLDevice.d.ts +46 -0
- package/dist/utils/GLPipeline.d.ts +84 -0
- package/dist/utils/GLPipelineDebugTools.d.ts +5 -0
- package/dist/utils/Math.d.ts +21 -0
- package/dist/utils/__tests__/capability-checker.test.d.ts +1 -0
- package/dist/utils/audio-session.d.ts +11 -0
- package/dist/utils/audio.d.ts +1 -0
- package/dist/utils/capability-checker.d.ts +23 -0
- package/dist/utils/encodeToken.d.ts +7 -0
- package/dist/utils/face.d.ts +1 -0
- package/dist/utils/float32-decoder.d.ts +26 -0
- package/dist/utils/fpsTracker.d.ts +27 -0
- package/dist/utils/index.d.ts +22 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/media-recorder-timestamp.d.ts +15 -0
- package/dist/utils/pcmAnalyzer.d.ts +40 -0
- package/dist/utils/perfermance.d.ts +15 -0
- package/dist/utils/request.d.ts +19 -0
- package/dist/utils/requestAnimateFrames.d.ts +31 -0
- package/dist/utils/time.d.ts +9 -0
- package/dist/view/DebugOverlay.d.ts +54 -0
- package/dist/worker/streaming-video.d.ts +1 -0
- package/package.json +82 -0
- package/src/agent/__tests__/agent.test.ts +3787 -0
- package/src/agent/audio-debug.ts +36 -0
- package/src/agent/audio-uplink.ts +392 -0
- package/src/agent/e2e-client.ts +215 -0
- package/src/agent/fixed-audio-track.ts +547 -0
- package/src/agent/index.ts +1393 -0
- package/src/agent/microphone.ts +534 -0
- package/src/agent/types.ts +197 -0
- package/src/baseRender/AudioRenderer.ts +317 -0
- package/src/baseRender/AudioWorklet.ts +776 -0
- package/src/baseRender/AvatarRenderer.ts +1559 -0
- package/src/baseRender/MSEAudioPlayer.ts +243 -0
- package/src/baseRender/UIRenderer.ts +195 -0
- package/src/baseRender/pcm-audio-processor.js +267 -0
- package/src/control/APIForwarder.ts +67 -0
- package/src/control/DataCacheQueue.ts +372 -0
- package/src/control/EventDispatcher.ts +106 -0
- package/src/control/RenderScheduler.ts +945 -0
- package/src/control/SaveAndDownload.js +77 -0
- package/src/control/StreamingClient.ts +138 -0
- package/src/control/VideoPlayer.ts +306 -0
- package/src/control/ttsa.ts +676 -0
- package/src/encoding/media-recorder-encoder.ts +175 -0
- package/src/encoding/pcm-webm-encoder.ts +72 -0
- package/src/encoding/webcodec-opus-encoder.ts +258 -0
- package/src/encoding/webm-muxer.ts +337 -0
- package/src/global.d.ts +105 -0
- package/src/index.ts +1920 -0
- package/src/modules/Composition.ts +79 -0
- package/src/modules/ResourceManager.ts +899 -0
- package/src/modules/TrackRenderer/base-track.ts +7 -0
- package/src/modules/TrackRenderer/index.ts +40 -0
- package/src/modules/TrackRenderer/render-implements.ts +269 -0
- package/src/modules/TrackRenderer/track-pic.ts +19 -0
- package/src/modules/TrackRenderer/track-subtitle.ts +16 -0
- package/src/modules/cache-manager.ts +10 -0
- package/src/modules/decoder.ts +515 -0
- package/src/modules/error-handle.ts +20 -0
- package/src/modules/network.ts +71 -0
- package/src/proto/face_data.proto +45 -0
- package/src/proto/face_data_pb.js +1297 -0
- package/src/proto/protobuf.min.js +8 -0
- package/src/types/capability.ts +23 -0
- package/src/types/error.ts +211 -0
- package/src/types/event.ts +38 -0
- package/src/types/frame-data.ts +121 -0
- package/src/types/index.ts +207 -0
- package/src/types/render.ts +18 -0
- package/src/utils/DataInterface.ts +746 -0
- package/src/utils/GLDevice.ts +286 -0
- package/src/utils/GLPipeline.ts +1293 -0
- package/src/utils/GLPipelineDebugTools.ts +174 -0
- package/src/utils/Math.ts +266 -0
- package/src/utils/__tests__/capability-checker.test.ts +159 -0
- package/src/utils/audio-session.ts +144 -0
- package/src/utils/audio.ts +44 -0
- package/src/utils/blueimp-md5.d.ts +3 -0
- package/src/utils/capability-checker.ts +379 -0
- package/src/utils/encodeToken.ts +100 -0
- package/src/utils/face.ts +29 -0
- package/src/utils/float32-decoder.js +130 -0
- package/src/utils/fpsTracker.ts +100 -0
- package/src/utils/index.ts +182 -0
- package/src/utils/logger.js +36 -0
- package/src/utils/media-recorder-timestamp.ts +79 -0
- package/src/utils/pcmAnalyzer.ts +154 -0
- package/src/utils/perfermance.ts +141 -0
- package/src/utils/request.ts +95 -0
- package/src/utils/requestAnimateFrames.ts +195 -0
- package/src/utils/time.ts +32 -0
- package/src/view/DebugOverlay.ts +404 -0
- package/src/worker/streaming-video.ts +4647 -0
|
@@ -0,0 +1,4647 @@
|
|
|
1
|
+
const mp4boxSource = `
|
|
2
|
+
var Log = function() {
|
|
3
|
+
var i = new Date,
|
|
4
|
+
r = 4;
|
|
5
|
+
return {
|
|
6
|
+
setLogLevel: function(t) {
|
|
7
|
+
r = t == this.debug ? 1 : t == this.info ? 2 : t == this.warn ? 3 : (this.error, 4)
|
|
8
|
+
},
|
|
9
|
+
debug: function(t, e) {
|
|
10
|
+
void 0 === console.debug && (console.debug = console.log),
|
|
11
|
+
r <= 1 && console.debug("[" + Log.getDurationString(new Date - i, 1e3) + "]", "[" + t + "]", e)
|
|
12
|
+
},
|
|
13
|
+
log: function(t, e) {
|
|
14
|
+
this.debug(t.msg)
|
|
15
|
+
},
|
|
16
|
+
info: function(t, e) {
|
|
17
|
+
r <= 2 && console.info("[" + Log.getDurationString(new Date - i, 1e3) + "]", "[" + t + "]", e)
|
|
18
|
+
},
|
|
19
|
+
warn: function(t, e) {
|
|
20
|
+
r <= 3 && console.warn("[" + Log.getDurationString(new Date - i, 1e3) + "]", "[" + t + "]", e)
|
|
21
|
+
},
|
|
22
|
+
error: function(t, e) {
|
|
23
|
+
r <= 4 && console.error("[" + Log.getDurationString(new Date - i, 1e3) + "]", "[" + t + "]", e)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} ();
|
|
27
|
+
Log.getDurationString = function(t, e) {
|
|
28
|
+
var i;
|
|
29
|
+
function r(t, e) {
|
|
30
|
+
for (var i = ("" + t).split("."); i[0].length < e;) i[0] = "0" + i[0];
|
|
31
|
+
return i.join(".")
|
|
32
|
+
}
|
|
33
|
+
t < 0 ? (i = !0, t = -t) : i = !1;
|
|
34
|
+
var s = t / (e || 1),
|
|
35
|
+
a = Math.floor(s / 3600);
|
|
36
|
+
s -= 3600 * a;
|
|
37
|
+
t = Math.floor(s / 60),
|
|
38
|
+
e = 1e3 * (s -= 60 * t);
|
|
39
|
+
return e -= 1e3 * (s = Math.floor(s)),
|
|
40
|
+
e = Math.floor(e),
|
|
41
|
+
(i ? "-": "") + a + ":" + r(t, 2) + ":" + r(s, 2) + "." + r(e, 3)
|
|
42
|
+
},
|
|
43
|
+
Log.printRanges = function(t) {
|
|
44
|
+
var e = t.length;
|
|
45
|
+
if (0 < e) {
|
|
46
|
+
for (var i = "",
|
|
47
|
+
r = 0; r < e; r++) 0 < r && (i += ","),
|
|
48
|
+
i += "[" + Log.getDurationString(t.start(r)) + "," + Log.getDurationString(t.end(r)) + "]";
|
|
49
|
+
return i
|
|
50
|
+
}
|
|
51
|
+
return "(empty)"
|
|
52
|
+
},
|
|
53
|
+
"undefined" != typeof exports && (exports.Log = Log);
|
|
54
|
+
var MP4BoxStream = function(t) {
|
|
55
|
+
if (! (t instanceof ArrayBuffer)) throw "Needs an array buffer";
|
|
56
|
+
this.buffer = t,
|
|
57
|
+
this.dataview = new DataView(t),
|
|
58
|
+
this.position = 0
|
|
59
|
+
};
|
|
60
|
+
MP4BoxStream.prototype.getPosition = function() {
|
|
61
|
+
return this.position
|
|
62
|
+
},
|
|
63
|
+
MP4BoxStream.prototype.getEndPosition = function() {
|
|
64
|
+
return this.buffer.byteLength
|
|
65
|
+
},
|
|
66
|
+
MP4BoxStream.prototype.getLength = function() {
|
|
67
|
+
return this.buffer.byteLength
|
|
68
|
+
},
|
|
69
|
+
MP4BoxStream.prototype.seek = function(t) {
|
|
70
|
+
t = Math.max(0, Math.min(this.buffer.byteLength, t));
|
|
71
|
+
return this.position = isNaN(t) || !isFinite(t) ? 0 : t,
|
|
72
|
+
!0
|
|
73
|
+
},
|
|
74
|
+
MP4BoxStream.prototype.isEos = function() {
|
|
75
|
+
return this.getPosition() >= this.getEndPosition()
|
|
76
|
+
},
|
|
77
|
+
MP4BoxStream.prototype.readAnyInt = function(t, e) {
|
|
78
|
+
var i = 0;
|
|
79
|
+
if (this.position + t <= this.buffer.byteLength) {
|
|
80
|
+
switch (t) {
|
|
81
|
+
case 1:
|
|
82
|
+
i = e ? this.dataview.getInt8(this.position) : this.dataview.getUint8(this.position);
|
|
83
|
+
break;
|
|
84
|
+
case 2:
|
|
85
|
+
i = e ? this.dataview.getInt16(this.position) : this.dataview.getUint16(this.position);
|
|
86
|
+
break;
|
|
87
|
+
case 3:
|
|
88
|
+
if (e) throw "No method for reading signed 24 bits values";
|
|
89
|
+
i = this.dataview.getUint8(this.position) << 16,
|
|
90
|
+
i |= this.dataview.getUint8(this.position + 1) << 8,
|
|
91
|
+
i |= this.dataview.getUint8(this.position + 2);
|
|
92
|
+
break;
|
|
93
|
+
case 4:
|
|
94
|
+
i = e ? this.dataview.getInt32(this.position) : this.dataview.getUint32(this.position);
|
|
95
|
+
break;
|
|
96
|
+
case 8:
|
|
97
|
+
if (e) throw "No method for reading signed 64 bits values";
|
|
98
|
+
i = this.dataview.getUint32(this.position) << 32,
|
|
99
|
+
i |= this.dataview.getUint32(this.position + 4);
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
throw "readInt method not implemented for size: " + t
|
|
103
|
+
}
|
|
104
|
+
return this.position += t,
|
|
105
|
+
i
|
|
106
|
+
}
|
|
107
|
+
throw "Not enough bytes in buffer"
|
|
108
|
+
},
|
|
109
|
+
MP4BoxStream.prototype.readUint8 = function() {
|
|
110
|
+
return this.readAnyInt(1, !1)
|
|
111
|
+
},
|
|
112
|
+
MP4BoxStream.prototype.readUint16 = function() {
|
|
113
|
+
return this.readAnyInt(2, !1)
|
|
114
|
+
},
|
|
115
|
+
MP4BoxStream.prototype.readUint24 = function() {
|
|
116
|
+
return this.readAnyInt(3, !1)
|
|
117
|
+
},
|
|
118
|
+
MP4BoxStream.prototype.readUint32 = function() {
|
|
119
|
+
return this.readAnyInt(4, !1)
|
|
120
|
+
},
|
|
121
|
+
MP4BoxStream.prototype.readUint64 = function() {
|
|
122
|
+
return this.readAnyInt(8, !1)
|
|
123
|
+
},
|
|
124
|
+
MP4BoxStream.prototype.readString = function(t) {
|
|
125
|
+
if (this.position + t <= this.buffer.byteLength) {
|
|
126
|
+
for (var e = "",
|
|
127
|
+
i = 0; i < t; i++) e += String.fromCharCode(this.readUint8());
|
|
128
|
+
return e
|
|
129
|
+
}
|
|
130
|
+
throw "Not enough bytes in buffer"
|
|
131
|
+
},
|
|
132
|
+
MP4BoxStream.prototype.readCString = function() {
|
|
133
|
+
for (var t = [];;) {
|
|
134
|
+
var e = this.readUint8();
|
|
135
|
+
if (0 === e) break;
|
|
136
|
+
t.push(e)
|
|
137
|
+
}
|
|
138
|
+
return String.fromCharCode.apply(null, t)
|
|
139
|
+
},
|
|
140
|
+
MP4BoxStream.prototype.readInt8 = function() {
|
|
141
|
+
return this.readAnyInt(1, !0)
|
|
142
|
+
},
|
|
143
|
+
MP4BoxStream.prototype.readInt16 = function() {
|
|
144
|
+
return this.readAnyInt(2, !0)
|
|
145
|
+
},
|
|
146
|
+
MP4BoxStream.prototype.readInt32 = function() {
|
|
147
|
+
return this.readAnyInt(4, !0)
|
|
148
|
+
},
|
|
149
|
+
MP4BoxStream.prototype.readInt64 = function() {
|
|
150
|
+
return this.readAnyInt(8, !1)
|
|
151
|
+
},
|
|
152
|
+
MP4BoxStream.prototype.readUint8Array = function(t) {
|
|
153
|
+
for (var e = new Uint8Array(t), i = 0; i < t; i++) e[i] = this.readUint8();
|
|
154
|
+
return e
|
|
155
|
+
},
|
|
156
|
+
MP4BoxStream.prototype.readInt16Array = function(t) {
|
|
157
|
+
for (var e = new Int16Array(t), i = 0; i < t; i++) e[i] = this.readInt16();
|
|
158
|
+
return e
|
|
159
|
+
},
|
|
160
|
+
MP4BoxStream.prototype.readUint16Array = function(t) {
|
|
161
|
+
for (var e = new Int16Array(t), i = 0; i < t; i++) e[i] = this.readUint16();
|
|
162
|
+
return e
|
|
163
|
+
},
|
|
164
|
+
MP4BoxStream.prototype.readUint32Array = function(t) {
|
|
165
|
+
for (var e = new Uint32Array(t), i = 0; i < t; i++) e[i] = this.readUint32();
|
|
166
|
+
return e
|
|
167
|
+
},
|
|
168
|
+
MP4BoxStream.prototype.readInt32Array = function(t) {
|
|
169
|
+
for (var e = new Int32Array(t), i = 0; i < t; i++) e[i] = this.readInt32();
|
|
170
|
+
return e
|
|
171
|
+
},
|
|
172
|
+
"undefined" != typeof exports && (exports.MP4BoxStream = MP4BoxStream);
|
|
173
|
+
var DataStream = function(t, e, i) {
|
|
174
|
+
this._byteOffset = e || 0,
|
|
175
|
+
t instanceof ArrayBuffer ? this.buffer = t: "object" == typeof t ? (this.dataView = t, e && (this._byteOffset += e)) : this.buffer = new ArrayBuffer(t || 0),
|
|
176
|
+
this.position = 0,
|
|
177
|
+
this.endianness = null == i ? DataStream.LITTLE_ENDIAN: i
|
|
178
|
+
};
|
|
179
|
+
DataStream.prototype = {},
|
|
180
|
+
DataStream.prototype.getPosition = function() {
|
|
181
|
+
return this.position
|
|
182
|
+
},
|
|
183
|
+
DataStream.prototype._realloc = function(t) {
|
|
184
|
+
if (this._dynamicSize) {
|
|
185
|
+
var e = this._byteOffset + this.position + t,
|
|
186
|
+
i = this._buffer.byteLength;
|
|
187
|
+
if (e <= i) e > this._byteLength && (this._byteLength = e);
|
|
188
|
+
else {
|
|
189
|
+
for (i < 1 && (i = 1); i < e;) i *= 2;
|
|
190
|
+
var r = new ArrayBuffer(i),
|
|
191
|
+
t = new Uint8Array(this._buffer);
|
|
192
|
+
new Uint8Array(r, 0, t.length).set(t),
|
|
193
|
+
this.buffer = r,
|
|
194
|
+
this._byteLength = e
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
DataStream.prototype._trimAlloc = function() {
|
|
199
|
+
var t, e, i;
|
|
200
|
+
this._byteLength != this._buffer.byteLength && (t = new ArrayBuffer(this._byteLength), e = new Uint8Array(t), i = new Uint8Array(this._buffer, 0, e.length), e.set(i), this.buffer = t)
|
|
201
|
+
},
|
|
202
|
+
DataStream.BIG_ENDIAN = !1,
|
|
203
|
+
DataStream.LITTLE_ENDIAN = !0,
|
|
204
|
+
DataStream.prototype._byteLength = 0,
|
|
205
|
+
Object.defineProperty(DataStream.prototype, "byteLength", {
|
|
206
|
+
get: function() {
|
|
207
|
+
return this._byteLength - this._byteOffset
|
|
208
|
+
}
|
|
209
|
+
}),
|
|
210
|
+
Object.defineProperty(DataStream.prototype, "buffer", {
|
|
211
|
+
get: function() {
|
|
212
|
+
return this._trimAlloc(),
|
|
213
|
+
this._buffer
|
|
214
|
+
},
|
|
215
|
+
set: function(t) {
|
|
216
|
+
this._buffer = t,
|
|
217
|
+
this._dataView = new DataView(this._buffer, this._byteOffset),
|
|
218
|
+
this._byteLength = this._buffer.byteLength
|
|
219
|
+
}
|
|
220
|
+
}),
|
|
221
|
+
Object.defineProperty(DataStream.prototype, "byteOffset", {
|
|
222
|
+
get: function() {
|
|
223
|
+
return this._byteOffset
|
|
224
|
+
},
|
|
225
|
+
set: function(t) {
|
|
226
|
+
this._byteOffset = t,
|
|
227
|
+
this._dataView = new DataView(this._buffer, this._byteOffset),
|
|
228
|
+
this._byteLength = this._buffer.byteLength
|
|
229
|
+
}
|
|
230
|
+
}),
|
|
231
|
+
Object.defineProperty(DataStream.prototype, "dataView", {
|
|
232
|
+
get: function() {
|
|
233
|
+
return this._dataView
|
|
234
|
+
},
|
|
235
|
+
set: function(t) {
|
|
236
|
+
this._byteOffset = t.byteOffset,
|
|
237
|
+
this._buffer = t.buffer,
|
|
238
|
+
this._dataView = new DataView(this._buffer, this._byteOffset),
|
|
239
|
+
this._byteLength = this._byteOffset + t.byteLength
|
|
240
|
+
}
|
|
241
|
+
}),
|
|
242
|
+
DataStream.prototype.seek = function(t) {
|
|
243
|
+
t = Math.max(0, Math.min(this.byteLength, t));
|
|
244
|
+
this.position = isNaN(t) || !isFinite(t) ? 0 : t
|
|
245
|
+
},
|
|
246
|
+
DataStream.prototype.isEof = function() {
|
|
247
|
+
return this.position >= this._byteLength
|
|
248
|
+
},
|
|
249
|
+
DataStream.prototype.mapUint8Array = function(t) {
|
|
250
|
+
this._realloc( + t);
|
|
251
|
+
var e = new Uint8Array(this._buffer, this.byteOffset + this.position, t);
|
|
252
|
+
return this.position += +t,
|
|
253
|
+
e
|
|
254
|
+
},
|
|
255
|
+
DataStream.prototype.readInt32Array = function(t, e) {
|
|
256
|
+
t = null == t ? this.byteLength - this.position / 4 : t;
|
|
257
|
+
var i = new Int32Array(t);
|
|
258
|
+
return DataStream.memcpy(i.buffer, 0, this.buffer, this.byteOffset + this.position, t * i.BYTES_PER_ELEMENT),
|
|
259
|
+
DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
260
|
+
this.position += i.byteLength,
|
|
261
|
+
i
|
|
262
|
+
},
|
|
263
|
+
DataStream.prototype.readInt16Array = function(t, e) {
|
|
264
|
+
t = null == t ? this.byteLength - this.position / 2 : t;
|
|
265
|
+
var i = new Int16Array(t);
|
|
266
|
+
return DataStream.memcpy(i.buffer, 0, this.buffer, this.byteOffset + this.position, t * i.BYTES_PER_ELEMENT),
|
|
267
|
+
DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
268
|
+
this.position += i.byteLength,
|
|
269
|
+
i
|
|
270
|
+
},
|
|
271
|
+
DataStream.prototype.readInt8Array = function(t) {
|
|
272
|
+
t = null == t ? this.byteLength - this.position: t;
|
|
273
|
+
var e = new Int8Array(t);
|
|
274
|
+
return DataStream.memcpy(e.buffer, 0, this.buffer, this.byteOffset + this.position, t * e.BYTES_PER_ELEMENT),
|
|
275
|
+
this.position += e.byteLength,
|
|
276
|
+
e
|
|
277
|
+
},
|
|
278
|
+
DataStream.prototype.readUint32Array = function(t, e) {
|
|
279
|
+
t = null == t ? this.byteLength - this.position / 4 : t;
|
|
280
|
+
var i = new Uint32Array(t);
|
|
281
|
+
return DataStream.memcpy(i.buffer, 0, this.buffer, this.byteOffset + this.position, t * i.BYTES_PER_ELEMENT),
|
|
282
|
+
DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
283
|
+
this.position += i.byteLength,
|
|
284
|
+
i
|
|
285
|
+
},
|
|
286
|
+
DataStream.prototype.readUint16Array = function(t, e) {
|
|
287
|
+
t = null == t ? this.byteLength - this.position / 2 : t;
|
|
288
|
+
var i = new Uint16Array(t);
|
|
289
|
+
return DataStream.memcpy(i.buffer, 0, this.buffer, this.byteOffset + this.position, t * i.BYTES_PER_ELEMENT),
|
|
290
|
+
DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
291
|
+
this.position += i.byteLength,
|
|
292
|
+
i
|
|
293
|
+
},
|
|
294
|
+
DataStream.prototype.readUint8Array = function(t) {
|
|
295
|
+
t = null == t ? this.byteLength - this.position: t;
|
|
296
|
+
var e = new Uint8Array(t);
|
|
297
|
+
return DataStream.memcpy(e.buffer, 0, this.buffer, this.byteOffset + this.position, t * e.BYTES_PER_ELEMENT),
|
|
298
|
+
this.position += e.byteLength,
|
|
299
|
+
e
|
|
300
|
+
},
|
|
301
|
+
DataStream.prototype.readFloat64Array = function(t, e) {
|
|
302
|
+
t = null == t ? this.byteLength - this.position / 8 : t;
|
|
303
|
+
var i = new Float64Array(t);
|
|
304
|
+
return DataStream.memcpy(i.buffer, 0, this.buffer, this.byteOffset + this.position, t * i.BYTES_PER_ELEMENT),
|
|
305
|
+
DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
306
|
+
this.position += i.byteLength,
|
|
307
|
+
i
|
|
308
|
+
},
|
|
309
|
+
DataStream.prototype.readFloat32Array = function(t, e) {
|
|
310
|
+
t = null == t ? this.byteLength - this.position / 4 : t;
|
|
311
|
+
var i = new Float32Array(t);
|
|
312
|
+
return DataStream.memcpy(i.buffer, 0, this.buffer, this.byteOffset + this.position, t * i.BYTES_PER_ELEMENT),
|
|
313
|
+
DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
314
|
+
this.position += i.byteLength,
|
|
315
|
+
i
|
|
316
|
+
},
|
|
317
|
+
DataStream.prototype.readInt32 = function(t) {
|
|
318
|
+
t = this._dataView.getInt32(this.position, null == t ? this.endianness: t);
|
|
319
|
+
return this.position += 4,
|
|
320
|
+
t
|
|
321
|
+
},
|
|
322
|
+
DataStream.prototype.readInt16 = function(t) {
|
|
323
|
+
t = this._dataView.getInt16(this.position, null == t ? this.endianness: t);
|
|
324
|
+
return this.position += 2,
|
|
325
|
+
t
|
|
326
|
+
},
|
|
327
|
+
DataStream.prototype.readInt8 = function() {
|
|
328
|
+
var t = this._dataView.getInt8(this.position);
|
|
329
|
+
return this.position += 1,
|
|
330
|
+
t
|
|
331
|
+
},
|
|
332
|
+
DataStream.prototype.readUint32 = function(t) {
|
|
333
|
+
t = this._dataView.getUint32(this.position, null == t ? this.endianness: t);
|
|
334
|
+
return this.position += 4,
|
|
335
|
+
t
|
|
336
|
+
},
|
|
337
|
+
DataStream.prototype.readUint16 = function(t) {
|
|
338
|
+
t = this._dataView.getUint16(this.position, null == t ? this.endianness: t);
|
|
339
|
+
return this.position += 2,
|
|
340
|
+
t
|
|
341
|
+
},
|
|
342
|
+
DataStream.prototype.readUint8 = function() {
|
|
343
|
+
var t = this._dataView.getUint8(this.position);
|
|
344
|
+
return this.position += 1,
|
|
345
|
+
t
|
|
346
|
+
},
|
|
347
|
+
DataStream.prototype.readFloat32 = function(t) {
|
|
348
|
+
t = this._dataView.getFloat32(this.position, null == t ? this.endianness: t);
|
|
349
|
+
return this.position += 4,
|
|
350
|
+
t
|
|
351
|
+
},
|
|
352
|
+
DataStream.prototype.readFloat64 = function(t) {
|
|
353
|
+
t = this._dataView.getFloat64(this.position, null == t ? this.endianness: t);
|
|
354
|
+
return this.position += 8,
|
|
355
|
+
t
|
|
356
|
+
},
|
|
357
|
+
DataStream.endianness = 0 < new Int8Array(new Int16Array([1]).buffer)[0],
|
|
358
|
+
DataStream.memcpy = function(t, e, i, r, s) {
|
|
359
|
+
e = new Uint8Array(t, e, s),
|
|
360
|
+
s = new Uint8Array(i, r, s);
|
|
361
|
+
e.set(s)
|
|
362
|
+
},
|
|
363
|
+
DataStream.arrayToNative = function(t, e) {
|
|
364
|
+
return e == this.endianness ? t: this.flipArrayEndianness(t)
|
|
365
|
+
},
|
|
366
|
+
DataStream.nativeToEndian = function(t, e) {
|
|
367
|
+
return this.endianness == e ? t: this.flipArrayEndianness(t)
|
|
368
|
+
},
|
|
369
|
+
DataStream.flipArrayEndianness = function(t) {
|
|
370
|
+
for (var e = new Uint8Array(t.buffer, t.byteOffset, t.byteLength), i = 0; i < t.byteLength; i += t.BYTES_PER_ELEMENT) for (var r = i + t.BYTES_PER_ELEMENT - 1,
|
|
371
|
+
s = i; s < r; r--, s++) {
|
|
372
|
+
var a = e[s];
|
|
373
|
+
e[s] = e[r],
|
|
374
|
+
e[r] = a
|
|
375
|
+
}
|
|
376
|
+
return t
|
|
377
|
+
},
|
|
378
|
+
DataStream.prototype.failurePosition = 0,
|
|
379
|
+
String.fromCharCodeUint8 = function(t) {
|
|
380
|
+
for (var e = [], i = 0; i < t.length; i++) e[i] = t[i];
|
|
381
|
+
return String.fromCharCode.apply(null, e)
|
|
382
|
+
},
|
|
383
|
+
DataStream.prototype.readString = function(t, e) {
|
|
384
|
+
return null == e || "ASCII" == e ? String.fromCharCodeUint8.apply(null, [this.mapUint8Array(null == t ? this.byteLength - this.position: t)]) : new TextDecoder(e).decode(this.mapUint8Array(t))
|
|
385
|
+
},
|
|
386
|
+
DataStream.prototype.readCString = function(t) {
|
|
387
|
+
var e = this.byteLength - this.position,
|
|
388
|
+
i = new Uint8Array(this._buffer, this._byteOffset + this.position),
|
|
389
|
+
r = e;
|
|
390
|
+
null != t && (r = Math.min(t, e));
|
|
391
|
+
for (var s = 0; s < r && 0 !== i[s]; s++);
|
|
392
|
+
var a = String.fromCharCodeUint8.apply(null, [this.mapUint8Array(s)]);
|
|
393
|
+
return null != t ? this.position += r - s: s != e && (this.position += 1),
|
|
394
|
+
a
|
|
395
|
+
};
|
|
396
|
+
var MAX_SIZE = Math.pow(2, 32);
|
|
397
|
+
DataStream.prototype.readInt64 = function() {
|
|
398
|
+
return this.readInt32() * MAX_SIZE + this.readUint32()
|
|
399
|
+
},
|
|
400
|
+
DataStream.prototype.readUint64 = function() {
|
|
401
|
+
return this.readUint32() * MAX_SIZE + this.readUint32()
|
|
402
|
+
},
|
|
403
|
+
DataStream.prototype.readInt64 = function() {
|
|
404
|
+
return this.readUint32() * MAX_SIZE + this.readUint32()
|
|
405
|
+
},
|
|
406
|
+
DataStream.prototype.readUint24 = function() {
|
|
407
|
+
return (this.readUint8() << 16) + (this.readUint8() << 8) + this.readUint8()
|
|
408
|
+
},
|
|
409
|
+
"undefined" != typeof exports && (exports.DataStream = DataStream),
|
|
410
|
+
DataStream.prototype.save = function(t) {
|
|
411
|
+
var e = new Blob([this.buffer]);
|
|
412
|
+
if (!window.URL || !URL.createObjectURL) throw "DataStream.save: Can't create object URL.";
|
|
413
|
+
var i = window.URL.createObjectURL(e),
|
|
414
|
+
e = document.createElement("a");
|
|
415
|
+
document.body.appendChild(e),
|
|
416
|
+
e.setAttribute("href", i),
|
|
417
|
+
e.setAttribute("download", t),
|
|
418
|
+
e.setAttribute("target", "_self"),
|
|
419
|
+
e.click(),
|
|
420
|
+
window.URL.revokeObjectURL(i)
|
|
421
|
+
},
|
|
422
|
+
DataStream.prototype._dynamicSize = !0,
|
|
423
|
+
Object.defineProperty(DataStream.prototype, "dynamicSize", {
|
|
424
|
+
get: function() {
|
|
425
|
+
return this._dynamicSize
|
|
426
|
+
},
|
|
427
|
+
set: function(t) {
|
|
428
|
+
t || this._trimAlloc(),
|
|
429
|
+
this._dynamicSize = t
|
|
430
|
+
}
|
|
431
|
+
}),
|
|
432
|
+
DataStream.prototype.shift = function(t) {
|
|
433
|
+
var e = new ArrayBuffer(this._byteLength - t),
|
|
434
|
+
i = new Uint8Array(e),
|
|
435
|
+
r = new Uint8Array(this._buffer, t, i.length);
|
|
436
|
+
i.set(r),
|
|
437
|
+
this.buffer = e,
|
|
438
|
+
this.position -= t
|
|
439
|
+
},
|
|
440
|
+
DataStream.prototype.writeInt32Array = function(t, e) {
|
|
441
|
+
if (this._realloc(4 * t.length), t instanceof Int32Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0) DataStream.memcpy(this._buffer, this.byteOffset + this.position, t.buffer, 0, t.byteLength),
|
|
442
|
+
this.mapInt32Array(t.length, e);
|
|
443
|
+
else for (var i = 0; i < t.length; i++) this.writeInt32(t[i], e)
|
|
444
|
+
},
|
|
445
|
+
DataStream.prototype.writeInt16Array = function(t, e) {
|
|
446
|
+
if (this._realloc(2 * t.length), t instanceof Int16Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0) DataStream.memcpy(this._buffer, this.byteOffset + this.position, t.buffer, 0, t.byteLength),
|
|
447
|
+
this.mapInt16Array(t.length, e);
|
|
448
|
+
else for (var i = 0; i < t.length; i++) this.writeInt16(t[i], e)
|
|
449
|
+
},
|
|
450
|
+
DataStream.prototype.writeInt8Array = function(t) {
|
|
451
|
+
if (this._realloc( + t.length), t instanceof Int8Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0) DataStream.memcpy(this._buffer, this.byteOffset + this.position, t.buffer, 0, t.byteLength),
|
|
452
|
+
this.mapInt8Array(t.length);
|
|
453
|
+
else for (var e = 0; e < t.length; e++) this.writeInt8(t[e])
|
|
454
|
+
},
|
|
455
|
+
DataStream.prototype.writeUint32Array = function(t, e) {
|
|
456
|
+
if (this._realloc(4 * t.length), t instanceof Uint32Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0) DataStream.memcpy(this._buffer, this.byteOffset + this.position, t.buffer, 0, t.byteLength),
|
|
457
|
+
this.mapUint32Array(t.length, e);
|
|
458
|
+
else for (var i = 0; i < t.length; i++) this.writeUint32(t[i], e)
|
|
459
|
+
},
|
|
460
|
+
DataStream.prototype.writeUint16Array = function(t, e) {
|
|
461
|
+
if (this._realloc(2 * t.length), t instanceof Uint16Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0) DataStream.memcpy(this._buffer, this.byteOffset + this.position, t.buffer, 0, t.byteLength),
|
|
462
|
+
this.mapUint16Array(t.length, e);
|
|
463
|
+
else for (var i = 0; i < t.length; i++) this.writeUint16(t[i], e)
|
|
464
|
+
},
|
|
465
|
+
DataStream.prototype.writeUint8Array = function(t) {
|
|
466
|
+
if (this._realloc( + t.length), t instanceof Uint8Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0) DataStream.memcpy(this._buffer, this.byteOffset + this.position, t.buffer, 0, t.byteLength),
|
|
467
|
+
this.mapUint8Array(t.length);
|
|
468
|
+
else for (var e = 0; e < t.length; e++) this.writeUint8(t[e])
|
|
469
|
+
},
|
|
470
|
+
DataStream.prototype.writeFloat64Array = function(t, e) {
|
|
471
|
+
if (this._realloc(8 * t.length), t instanceof Float64Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0) DataStream.memcpy(this._buffer, this.byteOffset + this.position, t.buffer, 0, t.byteLength),
|
|
472
|
+
this.mapFloat64Array(t.length, e);
|
|
473
|
+
else for (var i = 0; i < t.length; i++) this.writeFloat64(t[i], e)
|
|
474
|
+
},
|
|
475
|
+
DataStream.prototype.writeFloat32Array = function(t, e) {
|
|
476
|
+
if (this._realloc(4 * t.length), t instanceof Float32Array && this.byteOffset + this.position % t.BYTES_PER_ELEMENT === 0) DataStream.memcpy(this._buffer, this.byteOffset + this.position, t.buffer, 0, t.byteLength),
|
|
477
|
+
this.mapFloat32Array(t.length, e);
|
|
478
|
+
else for (var i = 0; i < t.length; i++) this.writeFloat32(t[i], e)
|
|
479
|
+
},
|
|
480
|
+
DataStream.prototype.writeInt32 = function(t, e) {
|
|
481
|
+
this._realloc(4),
|
|
482
|
+
this._dataView.setInt32(this.position, t, null == e ? this.endianness: e),
|
|
483
|
+
this.position += 4
|
|
484
|
+
},
|
|
485
|
+
DataStream.prototype.writeInt16 = function(t, e) {
|
|
486
|
+
this._realloc(2),
|
|
487
|
+
this._dataView.setInt16(this.position, t, null == e ? this.endianness: e),
|
|
488
|
+
this.position += 2
|
|
489
|
+
},
|
|
490
|
+
DataStream.prototype.writeInt8 = function(t) {
|
|
491
|
+
this._realloc(1),
|
|
492
|
+
this._dataView.setInt8(this.position, t),
|
|
493
|
+
this.position += 1
|
|
494
|
+
},
|
|
495
|
+
DataStream.prototype.writeUint32 = function(t, e) {
|
|
496
|
+
this._realloc(4),
|
|
497
|
+
this._dataView.setUint32(this.position, t, null == e ? this.endianness: e),
|
|
498
|
+
this.position += 4
|
|
499
|
+
},
|
|
500
|
+
DataStream.prototype.writeUint16 = function(t, e) {
|
|
501
|
+
this._realloc(2),
|
|
502
|
+
this._dataView.setUint16(this.position, t, null == e ? this.endianness: e),
|
|
503
|
+
this.position += 2
|
|
504
|
+
},
|
|
505
|
+
DataStream.prototype.writeUint8 = function(t) {
|
|
506
|
+
this._realloc(1),
|
|
507
|
+
this._dataView.setUint8(this.position, t),
|
|
508
|
+
this.position += 1
|
|
509
|
+
},
|
|
510
|
+
DataStream.prototype.writeFloat32 = function(t, e) {
|
|
511
|
+
this._realloc(4),
|
|
512
|
+
this._dataView.setFloat32(this.position, t, null == e ? this.endianness: e),
|
|
513
|
+
this.position += 4
|
|
514
|
+
},
|
|
515
|
+
DataStream.prototype.writeFloat64 = function(t, e) {
|
|
516
|
+
this._realloc(8),
|
|
517
|
+
this._dataView.setFloat64(this.position, t, null == e ? this.endianness: e),
|
|
518
|
+
this.position += 8
|
|
519
|
+
},
|
|
520
|
+
DataStream.prototype.writeUCS2String = function(t, e, i) {
|
|
521
|
+
null == i && (i = t.length);
|
|
522
|
+
for (var r = 0; r < t.length && r < i; r++) this.writeUint16(t.charCodeAt(r), e);
|
|
523
|
+
for (; r < i; r++) this.writeUint16(0)
|
|
524
|
+
},
|
|
525
|
+
DataStream.prototype.writeString = function(t, e, i) {
|
|
526
|
+
var r = 0;
|
|
527
|
+
if (null == e || "ASCII" == e) if (null != i) {
|
|
528
|
+
for (var s = Math.min(t.length, i), r = 0; r < s; r++) this.writeUint8(t.charCodeAt(r));
|
|
529
|
+
for (; r < i; r++) this.writeUint8(0)
|
|
530
|
+
} else for (r = 0; r < t.length; r++) this.writeUint8(t.charCodeAt(r));
|
|
531
|
+
else this.writeUint8Array(new TextEncoder(e).encode(t.substring(0, i)))
|
|
532
|
+
},
|
|
533
|
+
DataStream.prototype.writeCString = function(t, e) {
|
|
534
|
+
var i = 0;
|
|
535
|
+
if (null != e) {
|
|
536
|
+
for (var r = Math.min(t.length, e), i = 0; i < r; i++) this.writeUint8(t.charCodeAt(i));
|
|
537
|
+
for (; i < e; i++) this.writeUint8(0)
|
|
538
|
+
} else {
|
|
539
|
+
for (i = 0; i < t.length; i++) this.writeUint8(t.charCodeAt(i));
|
|
540
|
+
this.writeUint8(0)
|
|
541
|
+
}
|
|
542
|
+
},
|
|
543
|
+
DataStream.prototype.writeStruct = function(t, e) {
|
|
544
|
+
for (var i = 0; i < t.length; i += 2) {
|
|
545
|
+
var r = t[i + 1];
|
|
546
|
+
this.writeType(r, e[t[i]], e)
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
DataStream.prototype.writeType = function(t, e, i) {
|
|
550
|
+
var r;
|
|
551
|
+
if ("function" == typeof t) return t(this, e);
|
|
552
|
+
if ("object" == typeof t && !(t instanceof Array)) return t.set(this, e, i);
|
|
553
|
+
var s = null,
|
|
554
|
+
a = "ASCII",
|
|
555
|
+
i = this.position;
|
|
556
|
+
switch ("string" == typeof t && /:/.test(t) && (t = (r = t.split(":"))[0], s = parseInt(r[1])), "string" == typeof t && /,/.test(t) && (t = (r = t.split(","))[0], a = parseInt(r[1])), t) {
|
|
557
|
+
case "uint8":
|
|
558
|
+
this.writeUint8(e);
|
|
559
|
+
break;
|
|
560
|
+
case "int8":
|
|
561
|
+
this.writeInt8(e);
|
|
562
|
+
break;
|
|
563
|
+
case "uint16":
|
|
564
|
+
this.writeUint16(e, this.endianness);
|
|
565
|
+
break;
|
|
566
|
+
case "int16":
|
|
567
|
+
this.writeInt16(e, this.endianness);
|
|
568
|
+
break;
|
|
569
|
+
case "uint32":
|
|
570
|
+
this.writeUint32(e, this.endianness);
|
|
571
|
+
break;
|
|
572
|
+
case "int32":
|
|
573
|
+
this.writeInt32(e, this.endianness);
|
|
574
|
+
break;
|
|
575
|
+
case "float32":
|
|
576
|
+
this.writeFloat32(e, this.endianness);
|
|
577
|
+
break;
|
|
578
|
+
case "float64":
|
|
579
|
+
this.writeFloat64(e, this.endianness);
|
|
580
|
+
break;
|
|
581
|
+
case "uint16be":
|
|
582
|
+
this.writeUint16(e, DataStream.BIG_ENDIAN);
|
|
583
|
+
break;
|
|
584
|
+
case "int16be":
|
|
585
|
+
this.writeInt16(e, DataStream.BIG_ENDIAN);
|
|
586
|
+
break;
|
|
587
|
+
case "uint32be":
|
|
588
|
+
this.writeUint32(e, DataStream.BIG_ENDIAN);
|
|
589
|
+
break;
|
|
590
|
+
case "int32be":
|
|
591
|
+
this.writeInt32(e, DataStream.BIG_ENDIAN);
|
|
592
|
+
break;
|
|
593
|
+
case "float32be":
|
|
594
|
+
this.writeFloat32(e, DataStream.BIG_ENDIAN);
|
|
595
|
+
break;
|
|
596
|
+
case "float64be":
|
|
597
|
+
this.writeFloat64(e, DataStream.BIG_ENDIAN);
|
|
598
|
+
break;
|
|
599
|
+
case "uint16le":
|
|
600
|
+
this.writeUint16(e, DataStream.LITTLE_ENDIAN);
|
|
601
|
+
break;
|
|
602
|
+
case "int16le":
|
|
603
|
+
this.writeInt16(e, DataStream.LITTLE_ENDIAN);
|
|
604
|
+
break;
|
|
605
|
+
case "uint32le":
|
|
606
|
+
this.writeUint32(e, DataStream.LITTLE_ENDIAN);
|
|
607
|
+
break;
|
|
608
|
+
case "int32le":
|
|
609
|
+
this.writeInt32(e, DataStream.LITTLE_ENDIAN);
|
|
610
|
+
break;
|
|
611
|
+
case "float32le":
|
|
612
|
+
this.writeFloat32(e, DataStream.LITTLE_ENDIAN);
|
|
613
|
+
break;
|
|
614
|
+
case "float64le":
|
|
615
|
+
this.writeFloat64(e, DataStream.LITTLE_ENDIAN);
|
|
616
|
+
break;
|
|
617
|
+
case "cstring":
|
|
618
|
+
this.writeCString(e, s);
|
|
619
|
+
break;
|
|
620
|
+
case "string":
|
|
621
|
+
this.writeString(e, a, s);
|
|
622
|
+
break;
|
|
623
|
+
case "u16string":
|
|
624
|
+
this.writeUCS2String(e, this.endianness, s);
|
|
625
|
+
break;
|
|
626
|
+
case "u16stringle":
|
|
627
|
+
this.writeUCS2String(e, DataStream.LITTLE_ENDIAN, s);
|
|
628
|
+
break;
|
|
629
|
+
case "u16stringbe":
|
|
630
|
+
this.writeUCS2String(e, DataStream.BIG_ENDIAN, s);
|
|
631
|
+
break;
|
|
632
|
+
default:
|
|
633
|
+
if (3 == t.length) {
|
|
634
|
+
for (var n = t[1], o = 0; o < e.length; o++) this.writeType(n, e[o]);
|
|
635
|
+
break
|
|
636
|
+
}
|
|
637
|
+
this.writeStruct(t, e)
|
|
638
|
+
}
|
|
639
|
+
null != s && (this.position = i, this._realloc(s), this.position = i + s)
|
|
640
|
+
},
|
|
641
|
+
DataStream.prototype.writeUint64 = function(t) {
|
|
642
|
+
var e = Math.floor(t / MAX_SIZE);
|
|
643
|
+
this.writeUint32(e),
|
|
644
|
+
this.writeUint32(4294967295 & t)
|
|
645
|
+
},
|
|
646
|
+
DataStream.prototype.writeUint24 = function(t) {
|
|
647
|
+
this.writeUint8((16711680 & t) >> 16),
|
|
648
|
+
this.writeUint8((65280 & t) >> 8),
|
|
649
|
+
this.writeUint8(255 & t)
|
|
650
|
+
},
|
|
651
|
+
DataStream.prototype.adjustUint32 = function(t, e) {
|
|
652
|
+
var i = this.position;
|
|
653
|
+
this.seek(t),
|
|
654
|
+
this.writeUint32(e),
|
|
655
|
+
this.seek(i)
|
|
656
|
+
},
|
|
657
|
+
DataStream.prototype.mapInt32Array = function(t, e) {
|
|
658
|
+
this._realloc(4 * t);
|
|
659
|
+
var i = new Int32Array(this._buffer, this.byteOffset + this.position, t);
|
|
660
|
+
return DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
661
|
+
this.position += 4 * t,
|
|
662
|
+
i
|
|
663
|
+
},
|
|
664
|
+
DataStream.prototype.mapInt16Array = function(t, e) {
|
|
665
|
+
this._realloc(2 * t);
|
|
666
|
+
var i = new Int16Array(this._buffer, this.byteOffset + this.position, t);
|
|
667
|
+
return DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
668
|
+
this.position += 2 * t,
|
|
669
|
+
i
|
|
670
|
+
},
|
|
671
|
+
DataStream.prototype.mapInt8Array = function(t) {
|
|
672
|
+
this._realloc( + t);
|
|
673
|
+
var e = new Int8Array(this._buffer, this.byteOffset + this.position, t);
|
|
674
|
+
return this.position += +t,
|
|
675
|
+
e
|
|
676
|
+
},
|
|
677
|
+
DataStream.prototype.mapUint32Array = function(t, e) {
|
|
678
|
+
this._realloc(4 * t);
|
|
679
|
+
var i = new Uint32Array(this._buffer, this.byteOffset + this.position, t);
|
|
680
|
+
return DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
681
|
+
this.position += 4 * t,
|
|
682
|
+
i
|
|
683
|
+
},
|
|
684
|
+
DataStream.prototype.mapUint16Array = function(t, e) {
|
|
685
|
+
this._realloc(2 * t);
|
|
686
|
+
var i = new Uint16Array(this._buffer, this.byteOffset + this.position, t);
|
|
687
|
+
return DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
688
|
+
this.position += 2 * t,
|
|
689
|
+
i
|
|
690
|
+
},
|
|
691
|
+
DataStream.prototype.mapFloat64Array = function(t, e) {
|
|
692
|
+
this._realloc(8 * t);
|
|
693
|
+
var i = new Float64Array(this._buffer, this.byteOffset + this.position, t);
|
|
694
|
+
return DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
695
|
+
this.position += 8 * t,
|
|
696
|
+
i
|
|
697
|
+
},
|
|
698
|
+
DataStream.prototype.mapFloat32Array = function(t, e) {
|
|
699
|
+
this._realloc(4 * t);
|
|
700
|
+
var i = new Float32Array(this._buffer, this.byteOffset + this.position, t);
|
|
701
|
+
return DataStream.arrayToNative(i, null == e ? this.endianness: e),
|
|
702
|
+
this.position += 4 * t,
|
|
703
|
+
i
|
|
704
|
+
};
|
|
705
|
+
var MultiBufferStream = function(t) {
|
|
706
|
+
this.buffers = [],
|
|
707
|
+
this.bufferIndex = -1,
|
|
708
|
+
t && (this.insertBuffer(t), this.bufferIndex = 0)
|
|
709
|
+
};
|
|
710
|
+
MultiBufferStream.prototype = new DataStream(new ArrayBuffer, 0, DataStream.BIG_ENDIAN),
|
|
711
|
+
MultiBufferStream.prototype.initialized = function() {
|
|
712
|
+
var t;
|
|
713
|
+
return - 1 < this.bufferIndex || (0 < this.buffers.length ? 0 === (t = this.buffers[0]).fileStart ? (this.buffer = t, this.bufferIndex = 0, Log.debug("MultiBufferStream", "Stream ready for parsing"), !0) : (Log.warn("MultiBufferStream", "The first buffer should have a fileStart of 0"), this.logBufferLevel(), !1) : (Log.warn("MultiBufferStream", "No buffer to start parsing from"), this.logBufferLevel(), !1))
|
|
714
|
+
},
|
|
715
|
+
ArrayBuffer.concat = function(t, e) {
|
|
716
|
+
Log.debug("ArrayBuffer", "Trying to create a new buffer of size: " + (t.byteLength + e.byteLength));
|
|
717
|
+
var i = new Uint8Array(t.byteLength + e.byteLength);
|
|
718
|
+
return i.set(new Uint8Array(t), 0),
|
|
719
|
+
i.set(new Uint8Array(e), t.byteLength),
|
|
720
|
+
i.buffer
|
|
721
|
+
},
|
|
722
|
+
MultiBufferStream.prototype.reduceBuffer = function(t, e, i) {
|
|
723
|
+
var r = new Uint8Array(i);
|
|
724
|
+
return r.set(new Uint8Array(t, e, i)),
|
|
725
|
+
r.buffer.fileStart = t.fileStart + e,
|
|
726
|
+
r.buffer.usedBytes = 0,
|
|
727
|
+
r.buffer
|
|
728
|
+
},
|
|
729
|
+
MultiBufferStream.prototype.insertBuffer = function(t) {
|
|
730
|
+
for (var e = !0,
|
|
731
|
+
i = 0; i < this.buffers.length; i++) {
|
|
732
|
+
var r = this.buffers[i];
|
|
733
|
+
if (t.fileStart <= r.fileStart) {
|
|
734
|
+
if (t.fileStart === r.fileStart) {
|
|
735
|
+
if (t.byteLength > r.byteLength) {
|
|
736
|
+
this.buffers.splice(i, 1),
|
|
737
|
+
i--;
|
|
738
|
+
continue
|
|
739
|
+
}
|
|
740
|
+
Log.warn("MultiBufferStream", "Buffer (fileStart: " + t.fileStart + " - Length: " + t.byteLength + ") already appended, ignoring")
|
|
741
|
+
} else t.fileStart + t.byteLength <= r.fileStart || (t = this.reduceBuffer(t, 0, r.fileStart - t.fileStart)),
|
|
742
|
+
Log.debug("MultiBufferStream", "Appending new buffer (fileStart: " + t.fileStart + " - Length: " + t.byteLength + ")"),
|
|
743
|
+
this.buffers.splice(i, 0, t),
|
|
744
|
+
0 === i && (this.buffer = t);
|
|
745
|
+
e = !1;
|
|
746
|
+
break
|
|
747
|
+
}
|
|
748
|
+
if (t.fileStart < r.fileStart + r.byteLength) {
|
|
749
|
+
var s = r.fileStart + r.byteLength - t.fileStart,
|
|
750
|
+
r = t.byteLength - s;
|
|
751
|
+
if (! (0 < r)) {
|
|
752
|
+
e = !1;
|
|
753
|
+
break
|
|
754
|
+
}
|
|
755
|
+
t = this.reduceBuffer(t, s, r)
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
e && (Log.debug("MultiBufferStream", "Appending new buffer (fileStart: " + t.fileStart + " - Length: " + t.byteLength + ")"), this.buffers.push(t), 0 === i && (this.buffer = t))
|
|
759
|
+
},
|
|
760
|
+
MultiBufferStream.prototype.logBufferLevel = function(t) {
|
|
761
|
+
for (var e, i, r = [], s = "", a = 0, n = 0, o = 0; o < this.buffers.length; o++) e = this.buffers[o],
|
|
762
|
+
0 === o ? (i = {},
|
|
763
|
+
r.push(i), i.start = e.fileStart, i.end = e.fileStart + e.byteLength, s += "[" + i.start + "-") : i.end === e.fileStart ? i.end = e.fileStart + e.byteLength: ((i = {}).start = e.fileStart, s += r[r.length - 1].end - 1 + "], [" + i.start + "-", i.end = e.fileStart + e.byteLength, r.push(i)),
|
|
764
|
+
a += e.usedBytes,
|
|
765
|
+
n += e.byteLength;
|
|
766
|
+
0 < r.length && (s += i.end - 1 + "]");
|
|
767
|
+
t = t ? Log.info: Log.debug;
|
|
768
|
+
0 === this.buffers.length ? t("MultiBufferStream", "No more buffer in memory") : t("MultiBufferStream", this.buffers.length + " stored buffer(s) (" + a + "/" + n + " bytes), continuous ranges: " + s)
|
|
769
|
+
},
|
|
770
|
+
MultiBufferStream.prototype.cleanBuffers = function() {
|
|
771
|
+
for (var t, e = 0; e < this.buffers.length; e++)(t = this.buffers[e]).usedBytes === t.byteLength && (Log.debug("MultiBufferStream", "Removing buffer #" + e), this.buffers.splice(e, 1), e--)
|
|
772
|
+
},
|
|
773
|
+
MultiBufferStream.prototype.mergeNextBuffer = function() {
|
|
774
|
+
var t;
|
|
775
|
+
if (this.bufferIndex + 1 < this.buffers.length) {
|
|
776
|
+
if ((t = this.buffers[this.bufferIndex + 1]).fileStart !== this.buffer.fileStart + this.buffer.byteLength) return ! 1;
|
|
777
|
+
var e = this.buffer.byteLength,
|
|
778
|
+
i = this.buffer.usedBytes,
|
|
779
|
+
r = this.buffer.fileStart;
|
|
780
|
+
return this.buffers[this.bufferIndex] = ArrayBuffer.concat(this.buffer, t),
|
|
781
|
+
this.buffer = this.buffers[this.bufferIndex],
|
|
782
|
+
this.buffers.splice(this.bufferIndex + 1, 1),
|
|
783
|
+
this.buffer.usedBytes = i,
|
|
784
|
+
this.buffer.fileStart = r,
|
|
785
|
+
Log.debug("ISOFile", "Concatenating buffer for box parsing (length: " + e + "->" + this.buffer.byteLength + ")"),
|
|
786
|
+
!0
|
|
787
|
+
}
|
|
788
|
+
return ! 1
|
|
789
|
+
},
|
|
790
|
+
MultiBufferStream.prototype.findPosition = function(t, e, i) {
|
|
791
|
+
for (var r = null,
|
|
792
|
+
s = -1,
|
|
793
|
+
a = !0 === t ? 0 : this.bufferIndex; a < this.buffers.length && (r = this.buffers[a]).fileStart <= e;) s = a,
|
|
794
|
+
i && (r.fileStart + r.byteLength <= e ? r.usedBytes = r.byteLength: r.usedBytes = e - r.fileStart, this.logBufferLevel()),
|
|
795
|
+
a++;
|
|
796
|
+
return - 1 !== s && (r = this.buffers[s]).fileStart + r.byteLength >= e ? (Log.debug("MultiBufferStream", "Found position in existing buffer #" + s), s) : -1
|
|
797
|
+
},
|
|
798
|
+
MultiBufferStream.prototype.findEndContiguousBuf = function(t) {
|
|
799
|
+
var e, i, t = void 0 !== t ? t: this.bufferIndex,
|
|
800
|
+
r = this.buffers[t];
|
|
801
|
+
if (this.buffers.length > t + 1) for (e = t + 1; e < this.buffers.length && (i = this.buffers[e]).fileStart === r.fileStart + r.byteLength; e++) r = i;
|
|
802
|
+
return r.fileStart + r.byteLength
|
|
803
|
+
},
|
|
804
|
+
MultiBufferStream.prototype.getEndFilePositionAfter = function(t) {
|
|
805
|
+
var e = this.findPosition(!0, t, !1);
|
|
806
|
+
return - 1 !== e ? this.findEndContiguousBuf(e) : t
|
|
807
|
+
},
|
|
808
|
+
MultiBufferStream.prototype.addUsedBytes = function(t) {
|
|
809
|
+
this.buffer.usedBytes += t,
|
|
810
|
+
this.logBufferLevel()
|
|
811
|
+
},
|
|
812
|
+
MultiBufferStream.prototype.setAllUsedBytes = function() {
|
|
813
|
+
this.buffer.usedBytes = this.buffer.byteLength,
|
|
814
|
+
this.logBufferLevel()
|
|
815
|
+
},
|
|
816
|
+
MultiBufferStream.prototype.seek = function(t, e, i) {
|
|
817
|
+
i = this.findPosition(e, t, i);
|
|
818
|
+
return - 1 !== i ? (this.buffer = this.buffers[i], this.bufferIndex = i, this.position = t - this.buffer.fileStart, Log.debug("MultiBufferStream", "Repositioning parser at buffer position: " + this.position), !0) : (Log.debug("MultiBufferStream", "Position " + t + " not found in buffered data"), !1)
|
|
819
|
+
},
|
|
820
|
+
MultiBufferStream.prototype.getPosition = function() {
|
|
821
|
+
if (-1 === this.bufferIndex || null === this.buffers[this.bufferIndex]) throw "Error accessing position in the MultiBufferStream";
|
|
822
|
+
return this.buffers[this.bufferIndex].fileStart + this.position
|
|
823
|
+
},
|
|
824
|
+
MultiBufferStream.prototype.getLength = function() {
|
|
825
|
+
return this.byteLength
|
|
826
|
+
},
|
|
827
|
+
MultiBufferStream.prototype.getEndPosition = function() {
|
|
828
|
+
if (-1 === this.bufferIndex || null === this.buffers[this.bufferIndex]) throw "Error accessing position in the MultiBufferStream";
|
|
829
|
+
return this.buffers[this.bufferIndex].fileStart + this.byteLength
|
|
830
|
+
},
|
|
831
|
+
"undefined" != typeof exports && (exports.MultiBufferStream = MultiBufferStream);
|
|
832
|
+
var MPEG4DescriptorParser = function() {
|
|
833
|
+
var s = [];
|
|
834
|
+
s[3] = "ES_Descriptor",
|
|
835
|
+
s[4] = "DecoderConfigDescriptor",
|
|
836
|
+
s[5] = "DecoderSpecificInfo",
|
|
837
|
+
s[6] = "SLConfigDescriptor",
|
|
838
|
+
this.getDescriptorName = function(t) {
|
|
839
|
+
return s[t]
|
|
840
|
+
};
|
|
841
|
+
var r = this,
|
|
842
|
+
a = {};
|
|
843
|
+
return this.parseOneDescriptor = function(t) {
|
|
844
|
+
var e, i = 0,
|
|
845
|
+
r = t.readUint8();
|
|
846
|
+
for (e = t.readUint8(), 0; 128 & e;) i = (i << 7) + (127 & e),
|
|
847
|
+
e = t.readUint8(),
|
|
848
|
+
0;
|
|
849
|
+
return i = (i << 7) + (127 & e),
|
|
850
|
+
Log.debug("MPEG4DescriptorParser", "Found " + (s[r] || "Descriptor " + r) + ", size " + i + " at position " + t.getPosition()),
|
|
851
|
+
(r = new(s[r] ? a[s[r]] : a.Descriptor)(i)).parse(t),
|
|
852
|
+
r
|
|
853
|
+
},
|
|
854
|
+
a.Descriptor = function(t, e) {
|
|
855
|
+
this.tag = t,
|
|
856
|
+
this.size = e,
|
|
857
|
+
this.descs = []
|
|
858
|
+
},
|
|
859
|
+
a.Descriptor.prototype.parse = function(t) {
|
|
860
|
+
this.data = t.readUint8Array(this.size)
|
|
861
|
+
},
|
|
862
|
+
a.Descriptor.prototype.findDescriptor = function(t) {
|
|
863
|
+
for (var e = 0; e < this.descs.length; e++) if (this.descs[e].tag == t) return this.descs[e];
|
|
864
|
+
return null
|
|
865
|
+
},
|
|
866
|
+
a.Descriptor.prototype.parseRemainingDescriptors = function(t) {
|
|
867
|
+
for (var e = t.position; t.position < e + this.size;) {
|
|
868
|
+
var i = r.parseOneDescriptor(t);
|
|
869
|
+
this.descs.push(i)
|
|
870
|
+
}
|
|
871
|
+
},
|
|
872
|
+
a.ES_Descriptor = function(t) {
|
|
873
|
+
a.Descriptor.call(this, 3, t)
|
|
874
|
+
},
|
|
875
|
+
a.ES_Descriptor.prototype = new a.Descriptor,
|
|
876
|
+
a.ES_Descriptor.prototype.parse = function(t) {
|
|
877
|
+
var e;
|
|
878
|
+
this.ES_ID = t.readUint16(),
|
|
879
|
+
this.flags = t.readUint8(),
|
|
880
|
+
this.size -= 3,
|
|
881
|
+
128 & this.flags ? (this.dependsOn_ES_ID = t.readUint16(), this.size -= 2) : this.dependsOn_ES_ID = 0,
|
|
882
|
+
64 & this.flags ? (e = t.readUint8(), this.URL = t.readString(e), this.size -= e + 1) : this.URL = "",
|
|
883
|
+
32 & this.flags ? (this.OCR_ES_ID = t.readUint16(), this.size -= 2) : this.OCR_ES_ID = 0,
|
|
884
|
+
this.parseRemainingDescriptors(t)
|
|
885
|
+
},
|
|
886
|
+
a.ES_Descriptor.prototype.getOTI = function(t) {
|
|
887
|
+
var e = this.findDescriptor(4);
|
|
888
|
+
return e ? e.oti: 0
|
|
889
|
+
},
|
|
890
|
+
a.ES_Descriptor.prototype.getAudioConfig = function(t) {
|
|
891
|
+
var e = this.findDescriptor(4);
|
|
892
|
+
if (!e) return null;
|
|
893
|
+
var i = e.findDescriptor(5);
|
|
894
|
+
if (i && i.data) {
|
|
895
|
+
e = (248 & i.data[0]) >> 3;
|
|
896
|
+
return 31 === e && 2 <= i.data.length && (e = 32 + ((7 & i.data[0]) << 3) + ((224 & i.data[1]) >> 5)),
|
|
897
|
+
e
|
|
898
|
+
}
|
|
899
|
+
return null
|
|
900
|
+
},
|
|
901
|
+
a.DecoderConfigDescriptor = function(t) {
|
|
902
|
+
a.Descriptor.call(this, 4, t)
|
|
903
|
+
},
|
|
904
|
+
a.DecoderConfigDescriptor.prototype = new a.Descriptor,
|
|
905
|
+
a.DecoderConfigDescriptor.prototype.parse = function(t) {
|
|
906
|
+
this.oti = t.readUint8(),
|
|
907
|
+
this.streamType = t.readUint8(),
|
|
908
|
+
this.upStream = 0 != (this.streamType >> 1 & 1),
|
|
909
|
+
this.streamType = this.streamType >>> 2,
|
|
910
|
+
this.bufferSize = t.readUint24(),
|
|
911
|
+
this.maxBitrate = t.readUint32(),
|
|
912
|
+
this.avgBitrate = t.readUint32(),
|
|
913
|
+
this.size -= 13,
|
|
914
|
+
this.parseRemainingDescriptors(t)
|
|
915
|
+
},
|
|
916
|
+
a.DecoderSpecificInfo = function(t) {
|
|
917
|
+
a.Descriptor.call(this, 5, t)
|
|
918
|
+
},
|
|
919
|
+
a.DecoderSpecificInfo.prototype = new a.Descriptor,
|
|
920
|
+
a.SLConfigDescriptor = function(t) {
|
|
921
|
+
a.Descriptor.call(this, 6, t)
|
|
922
|
+
},
|
|
923
|
+
a.SLConfigDescriptor.prototype = new a.Descriptor,
|
|
924
|
+
this
|
|
925
|
+
};
|
|
926
|
+
"undefined" != typeof exports && (exports.MPEG4DescriptorParser = MPEG4DescriptorParser);
|
|
927
|
+
var BoxParser = {
|
|
928
|
+
ERR_INVALID_DATA: -1,
|
|
929
|
+
ERR_NOT_ENOUGH_DATA: 0,
|
|
930
|
+
OK: 1,
|
|
931
|
+
BASIC_BOXES: [{
|
|
932
|
+
type: "mdat",
|
|
933
|
+
name: "MediaDataBox"
|
|
934
|
+
},
|
|
935
|
+
{
|
|
936
|
+
type: "idat",
|
|
937
|
+
name: "ItemDataBox"
|
|
938
|
+
},
|
|
939
|
+
{
|
|
940
|
+
type: "free",
|
|
941
|
+
name: "FreeSpaceBox"
|
|
942
|
+
},
|
|
943
|
+
{
|
|
944
|
+
type: "skip",
|
|
945
|
+
name: "FreeSpaceBox"
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
type: "meco",
|
|
949
|
+
name: "AdditionalMetadataContainerBox"
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
type: "strk",
|
|
953
|
+
name: "SubTrackBox"
|
|
954
|
+
}],
|
|
955
|
+
FULL_BOXES: [{
|
|
956
|
+
type: "hmhd",
|
|
957
|
+
name: "HintMediaHeaderBox"
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
type: "nmhd",
|
|
961
|
+
name: "NullMediaHeaderBox"
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
type: "iods",
|
|
965
|
+
name: "ObjectDescriptorBox"
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
type: "xml ",
|
|
969
|
+
name: "XMLBox"
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
type: "bxml",
|
|
973
|
+
name: "BinaryXMLBox"
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
type: "ipro",
|
|
977
|
+
name: "ItemProtectionBox"
|
|
978
|
+
},
|
|
979
|
+
{
|
|
980
|
+
type: "mere",
|
|
981
|
+
name: "MetaboxRelationBox"
|
|
982
|
+
}],
|
|
983
|
+
CONTAINER_BOXES: [[{
|
|
984
|
+
type: "moov",
|
|
985
|
+
name: "CompressedMovieBox"
|
|
986
|
+
},
|
|
987
|
+
["trak", "pssh"]], [{
|
|
988
|
+
type: "trak",
|
|
989
|
+
name: "TrackBox"
|
|
990
|
+
}], [{
|
|
991
|
+
type: "edts",
|
|
992
|
+
name: "EditBox"
|
|
993
|
+
}], [{
|
|
994
|
+
type: "mdia",
|
|
995
|
+
name: "MediaBox"
|
|
996
|
+
}], [{
|
|
997
|
+
type: "minf",
|
|
998
|
+
name: "MediaInformationBox"
|
|
999
|
+
}], [{
|
|
1000
|
+
type: "dinf",
|
|
1001
|
+
name: "DataInformationBox"
|
|
1002
|
+
}], [{
|
|
1003
|
+
type: "stbl",
|
|
1004
|
+
name: "SampleTableBox"
|
|
1005
|
+
},
|
|
1006
|
+
["sgpd", "sbgp"]], [{
|
|
1007
|
+
type: "mvex",
|
|
1008
|
+
name: "MovieExtendsBox"
|
|
1009
|
+
},
|
|
1010
|
+
["trex"]], [{
|
|
1011
|
+
type: "moof",
|
|
1012
|
+
name: "CompressedMovieFragmentBox"
|
|
1013
|
+
},
|
|
1014
|
+
["traf"]], [{
|
|
1015
|
+
type: "traf",
|
|
1016
|
+
name: "TrackFragmentBox"
|
|
1017
|
+
},
|
|
1018
|
+
["trun", "sgpd", "sbgp"]], [{
|
|
1019
|
+
type: "vttc",
|
|
1020
|
+
name: "VTTCueBox"
|
|
1021
|
+
}], [{
|
|
1022
|
+
type: "tref",
|
|
1023
|
+
name: "TrackReferenceBox"
|
|
1024
|
+
}], [{
|
|
1025
|
+
type: "iref",
|
|
1026
|
+
name: "ItemReferenceBox"
|
|
1027
|
+
}], [{
|
|
1028
|
+
type: "mfra",
|
|
1029
|
+
name: "MovieFragmentRandomAccessBox"
|
|
1030
|
+
},
|
|
1031
|
+
["tfra"]], [{
|
|
1032
|
+
type: "meco",
|
|
1033
|
+
name: "AdditionalMetadataContainerBox"
|
|
1034
|
+
}], [{
|
|
1035
|
+
type: "hnti",
|
|
1036
|
+
name: "trackhintinformation"
|
|
1037
|
+
}], [{
|
|
1038
|
+
type: "hinf",
|
|
1039
|
+
name: "hintstatisticsbox"
|
|
1040
|
+
}], [{
|
|
1041
|
+
type: "strk",
|
|
1042
|
+
name: "SubTrackBox"
|
|
1043
|
+
}], [{
|
|
1044
|
+
type: "strd",
|
|
1045
|
+
name: "SubTrackDefinitionBox"
|
|
1046
|
+
}], [{
|
|
1047
|
+
type: "sinf",
|
|
1048
|
+
name: "ProtectionSchemeInfoBox"
|
|
1049
|
+
}], [{
|
|
1050
|
+
type: "rinf",
|
|
1051
|
+
name: "RestrictedSchemeInfoBox"
|
|
1052
|
+
}], [{
|
|
1053
|
+
type: "schi",
|
|
1054
|
+
name: "SchemeInformationBox"
|
|
1055
|
+
}], [{
|
|
1056
|
+
type: "trgr",
|
|
1057
|
+
name: "TrackGroupBox"
|
|
1058
|
+
}], [{
|
|
1059
|
+
type: "udta",
|
|
1060
|
+
name: "UserDataBox"
|
|
1061
|
+
},
|
|
1062
|
+
["kind"]], [{
|
|
1063
|
+
type: "iprp",
|
|
1064
|
+
name: "ItemPropertiesBox"
|
|
1065
|
+
},
|
|
1066
|
+
["ipma"]], [{
|
|
1067
|
+
type: "ipco",
|
|
1068
|
+
name: "ItemPropertyContainerBox"
|
|
1069
|
+
}], [{
|
|
1070
|
+
type: "grpl",
|
|
1071
|
+
name: "GroupsListBox"
|
|
1072
|
+
}], [{
|
|
1073
|
+
type: "j2kH",
|
|
1074
|
+
name: "J2KHeaderInfoBox"
|
|
1075
|
+
}], [{
|
|
1076
|
+
type: "etyp",
|
|
1077
|
+
name: "ExtendedTypeBox"
|
|
1078
|
+
},
|
|
1079
|
+
["tyco"]]],
|
|
1080
|
+
boxCodes: [],
|
|
1081
|
+
fullBoxCodes: [],
|
|
1082
|
+
containerBoxCodes: [],
|
|
1083
|
+
sampleEntryCodes: {},
|
|
1084
|
+
sampleGroupEntryCodes: [],
|
|
1085
|
+
trackGroupTypes: [],
|
|
1086
|
+
UUIDBoxes: {},
|
|
1087
|
+
UUIDs: [],
|
|
1088
|
+
initialize: function() {
|
|
1089
|
+
BoxParser.FullBox.prototype = new BoxParser.Box,
|
|
1090
|
+
BoxParser.ContainerBox.prototype = new BoxParser.Box,
|
|
1091
|
+
BoxParser.SampleEntry.prototype = new BoxParser.Box,
|
|
1092
|
+
BoxParser.TrackGroupTypeBox.prototype = new BoxParser.FullBox,
|
|
1093
|
+
BoxParser.BASIC_BOXES.forEach(function(t) {
|
|
1094
|
+
BoxParser.createBoxCtor(t.type, t.name)
|
|
1095
|
+
}),
|
|
1096
|
+
BoxParser.FULL_BOXES.forEach(function(t) {
|
|
1097
|
+
BoxParser.createFullBoxCtor(t.type, t.name)
|
|
1098
|
+
}),
|
|
1099
|
+
BoxParser.CONTAINER_BOXES.forEach(function(t) {
|
|
1100
|
+
BoxParser.createContainerBoxCtor(t[0].type, t[0].name, null, t[1])
|
|
1101
|
+
})
|
|
1102
|
+
},
|
|
1103
|
+
Box: function(t, e, i, r) {
|
|
1104
|
+
this.type = t,
|
|
1105
|
+
this.box_name = i,
|
|
1106
|
+
this.size = e,
|
|
1107
|
+
this.uuid = r
|
|
1108
|
+
},
|
|
1109
|
+
FullBox: function(t, e, i, r) {
|
|
1110
|
+
BoxParser.Box.call(this, t, e, i, r),
|
|
1111
|
+
this.flags = 0,
|
|
1112
|
+
this.version = 0
|
|
1113
|
+
},
|
|
1114
|
+
ContainerBox: function(t, e, i, r) {
|
|
1115
|
+
BoxParser.Box.call(this, t, e, i, r),
|
|
1116
|
+
this.boxes = []
|
|
1117
|
+
},
|
|
1118
|
+
SampleEntry: function(t, e, i, r) {
|
|
1119
|
+
BoxParser.ContainerBox.call(this, t, e),
|
|
1120
|
+
this.hdr_size = i,
|
|
1121
|
+
this.start = r
|
|
1122
|
+
},
|
|
1123
|
+
SampleGroupEntry: function(t) {
|
|
1124
|
+
this.grouping_type = t
|
|
1125
|
+
},
|
|
1126
|
+
TrackGroupTypeBox: function(t, e) {
|
|
1127
|
+
BoxParser.FullBox.call(this, t, e)
|
|
1128
|
+
},
|
|
1129
|
+
createBoxCtor: function(e, i, t) {
|
|
1130
|
+
BoxParser.boxCodes.push(e),
|
|
1131
|
+
BoxParser[e + "Box"] = function(t) {
|
|
1132
|
+
BoxParser.Box.call(this, e, t, i)
|
|
1133
|
+
},
|
|
1134
|
+
BoxParser[e + "Box"].prototype = new BoxParser.Box,
|
|
1135
|
+
t && (BoxParser[e + "Box"].prototype.parse = t)
|
|
1136
|
+
},
|
|
1137
|
+
createFullBoxCtor: function(e, i, r) {
|
|
1138
|
+
BoxParser[e + "Box"] = function(t) {
|
|
1139
|
+
BoxParser.FullBox.call(this, e, t, i)
|
|
1140
|
+
},
|
|
1141
|
+
BoxParser[e + "Box"].prototype = new BoxParser.FullBox,
|
|
1142
|
+
BoxParser[e + "Box"].prototype.parse = function(t) {
|
|
1143
|
+
this.parseFullHeader(t),
|
|
1144
|
+
r && r.call(this, t)
|
|
1145
|
+
}
|
|
1146
|
+
},
|
|
1147
|
+
addSubBoxArrays: function(t) {
|
|
1148
|
+
if (t) for (var e = (this.subBoxNames = t).length, i = 0; i < e; i++) this[t[i] + "s"] = []
|
|
1149
|
+
},
|
|
1150
|
+
createContainerBoxCtor: function(e, i, t, r) {
|
|
1151
|
+
BoxParser[e + "Box"] = function(t) {
|
|
1152
|
+
BoxParser.ContainerBox.call(this, e, t, i),
|
|
1153
|
+
BoxParser.addSubBoxArrays.call(this, r)
|
|
1154
|
+
},
|
|
1155
|
+
BoxParser[e + "Box"].prototype = new BoxParser.ContainerBox,
|
|
1156
|
+
t && (BoxParser[e + "Box"].prototype.parse = t)
|
|
1157
|
+
},
|
|
1158
|
+
createMediaSampleEntryCtor: function(t, e, i) {
|
|
1159
|
+
BoxParser.sampleEntryCodes[t] = [],
|
|
1160
|
+
BoxParser[t + "SampleEntry"] = function(t, e) {
|
|
1161
|
+
BoxParser.SampleEntry.call(this, t, e),
|
|
1162
|
+
BoxParser.addSubBoxArrays.call(this, i)
|
|
1163
|
+
},
|
|
1164
|
+
BoxParser[t + "SampleEntry"].prototype = new BoxParser.SampleEntry,
|
|
1165
|
+
e && (BoxParser[t + "SampleEntry"].prototype.parse = e)
|
|
1166
|
+
},
|
|
1167
|
+
createSampleEntryCtor: function(e, i, t, r) {
|
|
1168
|
+
BoxParser.sampleEntryCodes[e].push(i),
|
|
1169
|
+
BoxParser[i + "SampleEntry"] = function(t) {
|
|
1170
|
+
BoxParser[e + "SampleEntry"].call(this, i, t),
|
|
1171
|
+
BoxParser.addSubBoxArrays.call(this, r)
|
|
1172
|
+
},
|
|
1173
|
+
BoxParser[i + "SampleEntry"].prototype = new BoxParser[e + "SampleEntry"],
|
|
1174
|
+
t && (BoxParser[i + "SampleEntry"].prototype.parse = t)
|
|
1175
|
+
},
|
|
1176
|
+
createEncryptedSampleEntryCtor: function(t, e, i) {
|
|
1177
|
+
BoxParser.createSampleEntryCtor.call(this, t, e, i, ["sinf"])
|
|
1178
|
+
},
|
|
1179
|
+
createSampleGroupCtor: function(e, t) {
|
|
1180
|
+
BoxParser[e + "SampleGroupEntry"] = function(t) {
|
|
1181
|
+
BoxParser.SampleGroupEntry.call(this, e, t)
|
|
1182
|
+
},
|
|
1183
|
+
BoxParser[e + "SampleGroupEntry"].prototype = new BoxParser.SampleGroupEntry,
|
|
1184
|
+
t && (BoxParser[e + "SampleGroupEntry"].prototype.parse = t)
|
|
1185
|
+
},
|
|
1186
|
+
createTrackGroupCtor: function(e, t) {
|
|
1187
|
+
BoxParser[e + "TrackGroupTypeBox"] = function(t) {
|
|
1188
|
+
BoxParser.TrackGroupTypeBox.call(this, e, t)
|
|
1189
|
+
},
|
|
1190
|
+
BoxParser[e + "TrackGroupTypeBox"].prototype = new BoxParser.TrackGroupTypeBox,
|
|
1191
|
+
t && (BoxParser[e + "TrackGroupTypeBox"].prototype.parse = t)
|
|
1192
|
+
},
|
|
1193
|
+
createUUIDBox: function(e, i, r, s, a) {
|
|
1194
|
+
BoxParser.UUIDs.push(e),
|
|
1195
|
+
BoxParser.UUIDBoxes[e] = function(t) { (r ? BoxParser.FullBox: s ? BoxParser.ContainerBox: BoxParser.Box).call(this, "uuid", t, i, e)
|
|
1196
|
+
},
|
|
1197
|
+
BoxParser.UUIDBoxes[e].prototype = new(r ? BoxParser.FullBox: s ? BoxParser.ContainerBox: BoxParser.Box),
|
|
1198
|
+
a && (BoxParser.UUIDBoxes[e].prototype.parse = r ?
|
|
1199
|
+
function(t) {
|
|
1200
|
+
this.parseFullHeader(t),
|
|
1201
|
+
a && a.call(this, t)
|
|
1202
|
+
}: a)
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
function printPS(t) {
|
|
1206
|
+
var e = "<table class='inner-table'>";
|
|
1207
|
+
e += "<thead><tr><th>length</th><th>nalu_data</th></tr></thead>",
|
|
1208
|
+
e += "<tbody>";
|
|
1209
|
+
for (var i = 0; i < t.length; i++) {
|
|
1210
|
+
var r = t[i];
|
|
1211
|
+
e += "<tr>",
|
|
1212
|
+
e += "<td>" + r.length + "</td>",
|
|
1213
|
+
e += "<td>",
|
|
1214
|
+
e += r.nalu.reduce(function(t, e) {
|
|
1215
|
+
return t + e.toString(16).padStart(2, "0")
|
|
1216
|
+
},
|
|
1217
|
+
"0x"),
|
|
1218
|
+
e += "</td></tr>"
|
|
1219
|
+
}
|
|
1220
|
+
return e += "</tbody></table>"
|
|
1221
|
+
}
|
|
1222
|
+
function ColorPoint(t, e) {
|
|
1223
|
+
this.x = t,
|
|
1224
|
+
this.y = e
|
|
1225
|
+
}
|
|
1226
|
+
function Pixel(t, e) {
|
|
1227
|
+
this.bad_pixel_row = t,
|
|
1228
|
+
this.bad_pixel_column = e
|
|
1229
|
+
}
|
|
1230
|
+
BoxParser.initialize(),
|
|
1231
|
+
BoxParser.TKHD_FLAG_ENABLED = 1,
|
|
1232
|
+
BoxParser.TKHD_FLAG_IN_MOVIE = 2,
|
|
1233
|
+
BoxParser.TKHD_FLAG_IN_PREVIEW = 4,
|
|
1234
|
+
BoxParser.TFHD_FLAG_BASE_DATA_OFFSET = 1,
|
|
1235
|
+
BoxParser.TFHD_FLAG_SAMPLE_DESC = 2,
|
|
1236
|
+
BoxParser.TFHD_FLAG_SAMPLE_DUR = 8,
|
|
1237
|
+
BoxParser.TFHD_FLAG_SAMPLE_SIZE = 16,
|
|
1238
|
+
BoxParser.TFHD_FLAG_SAMPLE_FLAGS = 32,
|
|
1239
|
+
BoxParser.TFHD_FLAG_DUR_EMPTY = 65536,
|
|
1240
|
+
BoxParser.TFHD_FLAG_DEFAULT_BASE_IS_MOOF = 131072,
|
|
1241
|
+
BoxParser.TRUN_FLAGS_DATA_OFFSET = 1,
|
|
1242
|
+
BoxParser.TRUN_FLAGS_FIRST_FLAG = 4,
|
|
1243
|
+
BoxParser.TRUN_FLAGS_DURATION = 256,
|
|
1244
|
+
BoxParser.TRUN_FLAGS_SIZE = 512,
|
|
1245
|
+
BoxParser.TRUN_FLAGS_FLAGS = 1024,
|
|
1246
|
+
BoxParser.TRUN_FLAGS_CTS_OFFSET = 2048,
|
|
1247
|
+
BoxParser.Box.prototype.add = function(t) {
|
|
1248
|
+
return this.addBox(new BoxParser[t + "Box"])
|
|
1249
|
+
},
|
|
1250
|
+
BoxParser.Box.prototype.addBox = function(t) {
|
|
1251
|
+
return this.boxes.push(t),
|
|
1252
|
+
this[t.type + "s"] ? this[t.type + "s"].push(t) : this[t.type] = t,
|
|
1253
|
+
t
|
|
1254
|
+
},
|
|
1255
|
+
BoxParser.Box.prototype.set = function(t, e) {
|
|
1256
|
+
return this[t] = e,
|
|
1257
|
+
this
|
|
1258
|
+
},
|
|
1259
|
+
BoxParser.Box.prototype.addEntry = function(t, e) {
|
|
1260
|
+
e = e || "entries";
|
|
1261
|
+
return this[e] || (this[e] = []),
|
|
1262
|
+
this[e].push(t),
|
|
1263
|
+
this
|
|
1264
|
+
},
|
|
1265
|
+
"undefined" != typeof exports && (exports.BoxParser = BoxParser),
|
|
1266
|
+
BoxParser.parseUUID = function(t) {
|
|
1267
|
+
return BoxParser.parseHex16(t)
|
|
1268
|
+
},
|
|
1269
|
+
BoxParser.parseHex16 = function(t) {
|
|
1270
|
+
for (var e = "",
|
|
1271
|
+
i = 0; i < 16; i++) {
|
|
1272
|
+
var r = t.readUint8().toString(16);
|
|
1273
|
+
e += 1 === r.length ? "0" + r: r
|
|
1274
|
+
}
|
|
1275
|
+
return e
|
|
1276
|
+
},
|
|
1277
|
+
BoxParser.parseOneBox = function(t, e, i) {
|
|
1278
|
+
var r, s, a = t.getPosition(),
|
|
1279
|
+
n = 0;
|
|
1280
|
+
if (t.getEndPosition() - a < 8) return Log.debug("BoxParser", "Not enough data in stream to parse the type and size of the box"),
|
|
1281
|
+
{
|
|
1282
|
+
code: BoxParser.ERR_NOT_ENOUGH_DATA
|
|
1283
|
+
};
|
|
1284
|
+
if (i && i < 8) return Log.debug("BoxParser", "Not enough bytes left in the parent box to parse a new box"),
|
|
1285
|
+
{
|
|
1286
|
+
code: BoxParser.ERR_NOT_ENOUGH_DATA
|
|
1287
|
+
};
|
|
1288
|
+
var o = t.readUint32(),
|
|
1289
|
+
h = t.readString(4),
|
|
1290
|
+
d = h;
|
|
1291
|
+
if (Log.debug("BoxParser", "Found box of type '" + h + "' and size " + o + " at position " + a), n = 8, "uuid" == h) {
|
|
1292
|
+
if (t.getEndPosition() - t.getPosition() < 16 || i - n < 16) return t.seek(a),
|
|
1293
|
+
Log.debug("BoxParser", "Not enough bytes left in the parent box to parse a UUID box"),
|
|
1294
|
+
{
|
|
1295
|
+
code: BoxParser.ERR_NOT_ENOUGH_DATA
|
|
1296
|
+
};
|
|
1297
|
+
n += 16,
|
|
1298
|
+
d = s = BoxParser.parseUUID(t)
|
|
1299
|
+
}
|
|
1300
|
+
if (1 == o) {
|
|
1301
|
+
if (t.getEndPosition() - t.getPosition() < 8 || i && i - n < 8) return t.seek(a),
|
|
1302
|
+
Log.warn("BoxParser", 'Not enough data in stream to parse the extended size of the "' + h + '" box'),
|
|
1303
|
+
{
|
|
1304
|
+
code: BoxParser.ERR_NOT_ENOUGH_DATA
|
|
1305
|
+
};
|
|
1306
|
+
o = t.readUint64(),
|
|
1307
|
+
n += 8
|
|
1308
|
+
} else if (0 === o) if (i) o = i;
|
|
1309
|
+
else if ("mdat" !== h) return Log.error("BoxParser", "Unlimited box size not supported for type: '" + h + "'"),
|
|
1310
|
+
r = new BoxParser.Box(h, o),
|
|
1311
|
+
{
|
|
1312
|
+
code: BoxParser.OK,
|
|
1313
|
+
box: r,
|
|
1314
|
+
size: r.size
|
|
1315
|
+
};
|
|
1316
|
+
return 0 !== o && o < n ? (Log.error("BoxParser", "Box of type " + h + " has an invalid size " + o + " (too small to be a box)"), {
|
|
1317
|
+
code: BoxParser.ERR_NOT_ENOUGH_DATA,
|
|
1318
|
+
type: h,
|
|
1319
|
+
size: o,
|
|
1320
|
+
hdr_size: n,
|
|
1321
|
+
start: a
|
|
1322
|
+
}) : 0 !== o && i && i < o ? (Log.error("BoxParser", "Box of type '" + h + "' has a size " + o + " greater than its container size " + i), {
|
|
1323
|
+
code: BoxParser.ERR_NOT_ENOUGH_DATA,
|
|
1324
|
+
type: h,
|
|
1325
|
+
size: o,
|
|
1326
|
+
hdr_size: n,
|
|
1327
|
+
start: a
|
|
1328
|
+
}) : 0 !== o && a + o > t.getEndPosition() ? (t.seek(a), Log.info("BoxParser", "Not enough data in stream to parse the entire '" + h + "' box"), {
|
|
1329
|
+
code: BoxParser.ERR_NOT_ENOUGH_DATA,
|
|
1330
|
+
type: h,
|
|
1331
|
+
size: o,
|
|
1332
|
+
hdr_size: n,
|
|
1333
|
+
start: a
|
|
1334
|
+
}) : e ? {
|
|
1335
|
+
code: BoxParser.OK,
|
|
1336
|
+
type: h,
|
|
1337
|
+
size: o,
|
|
1338
|
+
hdr_size: n,
|
|
1339
|
+
start: a
|
|
1340
|
+
}: (BoxParser[h + "Box"] ? r = new BoxParser[h + "Box"](o) : "uuid" !== h ? (Log.warn("BoxParser", "Unknown box type: '" + h + "'"), (r = new BoxParser.Box(h, o)).has_unparsed_data = !0) : BoxParser.UUIDBoxes[s] ? r = new BoxParser.UUIDBoxes[s](o) : (Log.warn("BoxParser", "Unknown uuid type: '" + s + "'"), (r = new BoxParser.Box(h, o)).uuid = s, r.has_unparsed_data = !0), r.hdr_size = n, r.start = a, r.write === BoxParser.Box.prototype.write && "mdat" !== r.type && (Log.info("BoxParser", "'" + d + "' box writing not yet implemented, keeping unparsed data in memory for later write"), r.parseDataAndRewind(t)), r.parse(t), (a = t.getPosition() - (r.start + r.size)) < 0 ? (Log.warn("BoxParser", "Parsing of box '" + d + "' did not read the entire indicated box data size (missing " + -a + " bytes), seeking forward"), t.seek(r.start + r.size)) : 0 < a && (Log.error("BoxParser", "Parsing of box '" + d + "' read " + a + " more bytes than the indicated box data size, seeking backwards"), 0 !== r.size && t.seek(r.start + r.size)), {
|
|
1341
|
+
code: BoxParser.OK,
|
|
1342
|
+
box: r,
|
|
1343
|
+
size: r.size
|
|
1344
|
+
})
|
|
1345
|
+
},
|
|
1346
|
+
BoxParser.Box.prototype.parse = function(t) {
|
|
1347
|
+
"mdat" != this.type ? this.data = t.readUint8Array(this.size - this.hdr_size) : 0 === this.size ? t.seek(t.getEndPosition()) : t.seek(this.start + this.size)
|
|
1348
|
+
},
|
|
1349
|
+
BoxParser.Box.prototype.parseDataAndRewind = function(t) {
|
|
1350
|
+
this.data = t.readUint8Array(this.size - this.hdr_size),
|
|
1351
|
+
t.position -= this.size - this.hdr_size
|
|
1352
|
+
},
|
|
1353
|
+
BoxParser.FullBox.prototype.parseDataAndRewind = function(t) {
|
|
1354
|
+
this.parseFullHeader(t),
|
|
1355
|
+
this.data = t.readUint8Array(this.size - this.hdr_size),
|
|
1356
|
+
this.hdr_size -= 4,
|
|
1357
|
+
t.position -= this.size - this.hdr_size
|
|
1358
|
+
},
|
|
1359
|
+
BoxParser.FullBox.prototype.parseFullHeader = function(t) {
|
|
1360
|
+
this.version = t.readUint8(),
|
|
1361
|
+
this.flags = t.readUint24(),
|
|
1362
|
+
this.hdr_size += 4
|
|
1363
|
+
},
|
|
1364
|
+
BoxParser.FullBox.prototype.parse = function(t) {
|
|
1365
|
+
this.parseFullHeader(t),
|
|
1366
|
+
this.data = t.readUint8Array(this.size - this.hdr_size)
|
|
1367
|
+
},
|
|
1368
|
+
BoxParser.ContainerBox.prototype.parse = function(t) {
|
|
1369
|
+
for (; t.getPosition() < this.start + this.size;) {
|
|
1370
|
+
if ((e = BoxParser.parseOneBox(t, !1, this.size - (t.getPosition() - this.start))).code !== BoxParser.OK) return;
|
|
1371
|
+
var e, i = e.box;
|
|
1372
|
+
this.boxes.push(i),
|
|
1373
|
+
this.subBoxNames && -1 != this.subBoxNames.indexOf(i.type) ? this[this.subBoxNames[this.subBoxNames.indexOf(i.type)] + "s"].push(i) : this[e = "uuid" !== i.type ? i.type: i.uuid] ? Log.warn("Box of type " + e + " already stored in field of this type") : this[e] = i
|
|
1374
|
+
}
|
|
1375
|
+
},
|
|
1376
|
+
BoxParser.Box.prototype.parseLanguage = function(t) {
|
|
1377
|
+
this.language = t.readUint16();
|
|
1378
|
+
t = [];
|
|
1379
|
+
t[0] = this.language >> 10 & 31,
|
|
1380
|
+
t[1] = this.language >> 5 & 31,
|
|
1381
|
+
t[2] = 31 & this.language,
|
|
1382
|
+
this.languageString = String.fromCharCode(t[0] + 96, t[1] + 96, t[2] + 96)
|
|
1383
|
+
},
|
|
1384
|
+
BoxParser.SAMPLE_ENTRY_TYPE_VISUAL = "Visual",
|
|
1385
|
+
BoxParser.SAMPLE_ENTRY_TYPE_AUDIO = "Audio",
|
|
1386
|
+
BoxParser.SAMPLE_ENTRY_TYPE_HINT = "Hint",
|
|
1387
|
+
BoxParser.SAMPLE_ENTRY_TYPE_METADATA = "Metadata",
|
|
1388
|
+
BoxParser.SAMPLE_ENTRY_TYPE_SUBTITLE = "Subtitle",
|
|
1389
|
+
BoxParser.SAMPLE_ENTRY_TYPE_SYSTEM = "System",
|
|
1390
|
+
BoxParser.SAMPLE_ENTRY_TYPE_TEXT = "Text",
|
|
1391
|
+
BoxParser.SampleEntry.prototype.parseHeader = function(t) {
|
|
1392
|
+
t.readUint8Array(6),
|
|
1393
|
+
this.data_reference_index = t.readUint16(),
|
|
1394
|
+
this.hdr_size += 8
|
|
1395
|
+
},
|
|
1396
|
+
BoxParser.SampleEntry.prototype.parse = function(t) {
|
|
1397
|
+
this.parseHeader(t),
|
|
1398
|
+
this.data = t.readUint8Array(this.size - this.hdr_size)
|
|
1399
|
+
},
|
|
1400
|
+
BoxParser.SampleEntry.prototype.parseDataAndRewind = function(t) {
|
|
1401
|
+
this.parseHeader(t),
|
|
1402
|
+
this.data = t.readUint8Array(this.size - this.hdr_size),
|
|
1403
|
+
this.hdr_size -= 8,
|
|
1404
|
+
t.position -= this.size - this.hdr_size
|
|
1405
|
+
},
|
|
1406
|
+
BoxParser.SampleEntry.prototype.parseFooter = function(t) {
|
|
1407
|
+
BoxParser.ContainerBox.prototype.parse.call(this, t)
|
|
1408
|
+
},
|
|
1409
|
+
BoxParser.createMediaSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_HINT),
|
|
1410
|
+
BoxParser.createMediaSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_METADATA),
|
|
1411
|
+
BoxParser.createMediaSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_SUBTITLE),
|
|
1412
|
+
BoxParser.createMediaSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_SYSTEM),
|
|
1413
|
+
BoxParser.createMediaSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_TEXT),
|
|
1414
|
+
BoxParser.createMediaSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL,
|
|
1415
|
+
function(t) {
|
|
1416
|
+
var e;
|
|
1417
|
+
this.parseHeader(t),
|
|
1418
|
+
t.readUint16(),
|
|
1419
|
+
t.readUint16(),
|
|
1420
|
+
t.readUint32Array(3),
|
|
1421
|
+
this.width = t.readUint16(),
|
|
1422
|
+
this.height = t.readUint16(),
|
|
1423
|
+
this.horizresolution = t.readUint32(),
|
|
1424
|
+
this.vertresolution = t.readUint32(),
|
|
1425
|
+
t.readUint32(),
|
|
1426
|
+
this.frame_count = t.readUint16(),
|
|
1427
|
+
e = Math.min(31, t.readUint8()),
|
|
1428
|
+
this.compressorname = t.readString(e),
|
|
1429
|
+
e < 31 && t.readString(31 - e),
|
|
1430
|
+
this.depth = t.readUint16(),
|
|
1431
|
+
t.readUint16(),
|
|
1432
|
+
this.parseFooter(t)
|
|
1433
|
+
}),
|
|
1434
|
+
BoxParser.createMediaSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO,
|
|
1435
|
+
function(t) {
|
|
1436
|
+
this.parseHeader(t),
|
|
1437
|
+
t.readUint32Array(2),
|
|
1438
|
+
this.channel_count = t.readUint16(),
|
|
1439
|
+
this.samplesize = t.readUint16(),
|
|
1440
|
+
t.readUint16(),
|
|
1441
|
+
t.readUint16(),
|
|
1442
|
+
this.samplerate = t.readUint32() / 65536,
|
|
1443
|
+
this.parseFooter(t)
|
|
1444
|
+
}),
|
|
1445
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "avc1"),
|
|
1446
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "avc2"),
|
|
1447
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "avc3"),
|
|
1448
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "avc4"),
|
|
1449
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "av01"),
|
|
1450
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "dav1"),
|
|
1451
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "hvc1"),
|
|
1452
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "hev1"),
|
|
1453
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "hvt1"),
|
|
1454
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "lhe1"),
|
|
1455
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "dvh1"),
|
|
1456
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "dvhe"),
|
|
1457
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "vvc1"),
|
|
1458
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "vvi1"),
|
|
1459
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "vvs1"),
|
|
1460
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "vvcN"),
|
|
1461
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "vp08"),
|
|
1462
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "vp09"),
|
|
1463
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "avs3"),
|
|
1464
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "j2ki"),
|
|
1465
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "mjp2"),
|
|
1466
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "mjpg"),
|
|
1467
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "uncv"),
|
|
1468
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "mp4a"),
|
|
1469
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "ac-3"),
|
|
1470
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "ac-4"),
|
|
1471
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "ec-3"),
|
|
1472
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "Opus"),
|
|
1473
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "mha1"),
|
|
1474
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "mha2"),
|
|
1475
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "mhm1"),
|
|
1476
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "mhm2"),
|
|
1477
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "fLaC"),
|
|
1478
|
+
BoxParser.createEncryptedSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_VISUAL, "encv"),
|
|
1479
|
+
BoxParser.createEncryptedSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_AUDIO, "enca"),
|
|
1480
|
+
BoxParser.createEncryptedSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_SUBTITLE, "encu"),
|
|
1481
|
+
BoxParser.createEncryptedSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_SYSTEM, "encs"),
|
|
1482
|
+
BoxParser.createEncryptedSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_TEXT, "enct"),
|
|
1483
|
+
BoxParser.createEncryptedSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_METADATA, "encm"),
|
|
1484
|
+
BoxParser.createBoxCtor("a1lx", "AV1LayeredImageIndexingProperty",
|
|
1485
|
+
function(t) {
|
|
1486
|
+
var e = 16 * (1 + (1 & (1 & t.readUint8())));
|
|
1487
|
+
this.layer_size = [];
|
|
1488
|
+
for (var i = 0; i < 3; i++) this.layer_size[i] = 16 == e ? t.readUint16() : t.readUint32()
|
|
1489
|
+
}),
|
|
1490
|
+
BoxParser.createBoxCtor("a1op", "OperatingPointSelectorProperty",
|
|
1491
|
+
function(t) {
|
|
1492
|
+
this.op_index = t.readUint8()
|
|
1493
|
+
}),
|
|
1494
|
+
BoxParser.createFullBoxCtor("auxC", "AuxiliaryTypeProperty",
|
|
1495
|
+
function(t) {
|
|
1496
|
+
this.aux_type = t.readCString();
|
|
1497
|
+
var e = this.size - this.hdr_size - (this.aux_type.length + 1);
|
|
1498
|
+
this.aux_subtype = t.readUint8Array(e)
|
|
1499
|
+
}),
|
|
1500
|
+
BoxParser.createBoxCtor("av1C", "AV1CodecConfigurationBox",
|
|
1501
|
+
function(t) {
|
|
1502
|
+
var e = t.readUint8();
|
|
1503
|
+
if (1 == (e >> 7 & 1)) if (this.version = 127 & e, 1 === this.version) if (e = t.readUint8(), this.seq_profile = e >> 5 & 7, this.seq_level_idx_0 = 31 & e, e = t.readUint8(), this.seq_tier_0 = e >> 7 & 1, this.high_bitdepth = e >> 6 & 1, this.twelve_bit = e >> 5 & 1, this.monochrome = e >> 4 & 1, this.chroma_subsampling_x = e >> 3 & 1, this.chroma_subsampling_y = e >> 2 & 1, this.chroma_sample_position = 3 & e, e = t.readUint8(), this.reserved_1 = e >> 5 & 7, 0 === this.reserved_1) {
|
|
1504
|
+
if (this.initial_presentation_delay_present = e >> 4 & 1, 1 === this.initial_presentation_delay_present) this.initial_presentation_delay_minus_one = 15 & e;
|
|
1505
|
+
else if (this.reserved_2 = 15 & e, 0 !== this.reserved_2) return void Log.error("av1C reserved_2 parsing problem");
|
|
1506
|
+
e = this.size - this.hdr_size - 4;
|
|
1507
|
+
this.configOBUs = t.readUint8Array(e)
|
|
1508
|
+
} else Log.error("av1C reserved_1 parsing problem");
|
|
1509
|
+
else Log.error("av1C version " + this.version + " not supported");
|
|
1510
|
+
else Log.error("av1C marker problem")
|
|
1511
|
+
}),
|
|
1512
|
+
BoxParser.createBoxCtor("avcC", "AVCConfigurationBox",
|
|
1513
|
+
function(t) {
|
|
1514
|
+
var e, i;
|
|
1515
|
+
for (this.configurationVersion = t.readUint8(), this.AVCProfileIndication = t.readUint8(), this.profile_compatibility = t.readUint8(), this.AVCLevelIndication = t.readUint8(), this.lengthSizeMinusOne = 3 & t.readUint8(), this.nb_SPS_nalus = 31 & t.readUint8(), i = this.size - this.hdr_size - 6, this.SPS = [], this.SPS.toString = function() {
|
|
1516
|
+
return printPS(this)
|
|
1517
|
+
},
|
|
1518
|
+
e = 0; e < this.nb_SPS_nalus; e++) this.SPS[e] = {},
|
|
1519
|
+
this.SPS[e].length = t.readUint16(),
|
|
1520
|
+
this.SPS[e].nalu = t.readUint8Array(this.SPS[e].length),
|
|
1521
|
+
i -= 2 + this.SPS[e].length;
|
|
1522
|
+
for (this.nb_PPS_nalus = t.readUint8(), i--, this.PPS = [], this.PPS.toString = function() {
|
|
1523
|
+
return printPS(this)
|
|
1524
|
+
},
|
|
1525
|
+
e = 0; e < this.nb_PPS_nalus; e++) this.PPS[e] = {},
|
|
1526
|
+
this.PPS[e].length = t.readUint16(),
|
|
1527
|
+
this.PPS[e].nalu = t.readUint8Array(this.PPS[e].length),
|
|
1528
|
+
i -= 2 + this.PPS[e].length;
|
|
1529
|
+
0 < i && (this.ext = t.readUint8Array(i))
|
|
1530
|
+
}),
|
|
1531
|
+
BoxParser.createBoxCtor("btrt", "BitRateBox",
|
|
1532
|
+
function(t) {
|
|
1533
|
+
this.bufferSizeDB = t.readUint32(),
|
|
1534
|
+
this.maxBitrate = t.readUint32(),
|
|
1535
|
+
this.avgBitrate = t.readUint32()
|
|
1536
|
+
}),
|
|
1537
|
+
BoxParser.createFullBoxCtor("ccst", "CodingConstraintsBox",
|
|
1538
|
+
function(t) {
|
|
1539
|
+
var e = t.readUint8();
|
|
1540
|
+
this.all_ref_pics_intra = 128 == (128 & e),
|
|
1541
|
+
this.intra_pred_used = 64 == (64 & e),
|
|
1542
|
+
this.max_ref_per_pic = (63 & e) >> 2,
|
|
1543
|
+
t.readUint24()
|
|
1544
|
+
}),
|
|
1545
|
+
BoxParser.createBoxCtor("cdef", "ComponentDefinitionBox",
|
|
1546
|
+
function(t) {
|
|
1547
|
+
var e;
|
|
1548
|
+
for (this.channel_count = t.readUint16(), this.channel_indexes = [], this.channel_types = [], this.channel_associations = [], e = 0; e < this.channel_count; e++) this.channel_indexes.push(t.readUint16()),
|
|
1549
|
+
this.channel_types.push(t.readUint16()),
|
|
1550
|
+
this.channel_associations.push(t.readUint16())
|
|
1551
|
+
}),
|
|
1552
|
+
BoxParser.createBoxCtor("clap", "CleanApertureBox",
|
|
1553
|
+
function(t) {
|
|
1554
|
+
this.cleanApertureWidthN = t.readUint32(),
|
|
1555
|
+
this.cleanApertureWidthD = t.readUint32(),
|
|
1556
|
+
this.cleanApertureHeightN = t.readUint32(),
|
|
1557
|
+
this.cleanApertureHeightD = t.readUint32(),
|
|
1558
|
+
this.horizOffN = t.readUint32(),
|
|
1559
|
+
this.horizOffD = t.readUint32(),
|
|
1560
|
+
this.vertOffN = t.readUint32(),
|
|
1561
|
+
this.vertOffD = t.readUint32()
|
|
1562
|
+
}),
|
|
1563
|
+
BoxParser.createBoxCtor("clli", "ContentLightLevelBox",
|
|
1564
|
+
function(t) {
|
|
1565
|
+
this.max_content_light_level = t.readUint16(),
|
|
1566
|
+
this.max_pic_average_light_level = t.readUint16()
|
|
1567
|
+
}),
|
|
1568
|
+
BoxParser.createFullBoxCtor("cmex", "CameraExtrinsicMatrixProperty",
|
|
1569
|
+
function(t) {
|
|
1570
|
+
1 & this.flags && (this.pos_x = t.readInt32()),
|
|
1571
|
+
2 & this.flags && (this.pos_y = t.readInt32()),
|
|
1572
|
+
4 & this.flags && (this.pos_z = t.readInt32()),
|
|
1573
|
+
8 & this.flags && (0 == this.version ? 16 & this.flags ? (this.quat_x = t.readInt32(), this.quat_y = t.readInt32(), this.quat_z = t.readInt32()) : (this.quat_x = t.readInt16(), this.quat_y = t.readInt16(), this.quat_z = t.readInt16()) : this.version),
|
|
1574
|
+
32 & this.flags && (this.id = t.readUint32())
|
|
1575
|
+
}),
|
|
1576
|
+
BoxParser.createFullBoxCtor("cmin", "CameraIntrinsicMatrixProperty",
|
|
1577
|
+
function(t) {
|
|
1578
|
+
this.focal_length_x = t.readInt32(),
|
|
1579
|
+
this.principal_point_x = t.readInt32(),
|
|
1580
|
+
this.principal_point_y = t.readInt32(),
|
|
1581
|
+
1 & this.flags && (this.focal_length_y = t.readInt32(), this.skew_factor = t.readInt32())
|
|
1582
|
+
}),
|
|
1583
|
+
BoxParser.createBoxCtor("cmpd", "ComponentDefinitionBox",
|
|
1584
|
+
function(t) {
|
|
1585
|
+
for (this.component_count = t.readUint32(), this.component_types = [], this.component_type_urls = [], i = 0; i < this.component_count; i++) {
|
|
1586
|
+
var e = t.readUint16();
|
|
1587
|
+
this.component_types.push(e),
|
|
1588
|
+
32768 <= e && this.component_type_urls.push(t.readCString())
|
|
1589
|
+
}
|
|
1590
|
+
}),
|
|
1591
|
+
BoxParser.createFullBoxCtor("co64", "ChunkLargeOffsetBox",
|
|
1592
|
+
function(t) {
|
|
1593
|
+
var e, i = t.readUint32();
|
|
1594
|
+
if (this.chunk_offsets = [], 0 === this.version) for (e = 0; e < i; e++) this.chunk_offsets.push(t.readUint64())
|
|
1595
|
+
}),
|
|
1596
|
+
BoxParser.createFullBoxCtor("CoLL", "ContentLightLevelBox",
|
|
1597
|
+
function(t) {
|
|
1598
|
+
this.maxCLL = t.readUint16(),
|
|
1599
|
+
this.maxFALL = t.readUint16()
|
|
1600
|
+
}),
|
|
1601
|
+
BoxParser.createBoxCtor("colr", "ColourInformationBox",
|
|
1602
|
+
function(t) {
|
|
1603
|
+
var e;
|
|
1604
|
+
this.colour_type = t.readString(4),
|
|
1605
|
+
"nclx" === this.colour_type ? (this.colour_primaries = t.readUint16(), this.transfer_characteristics = t.readUint16(), this.matrix_coefficients = t.readUint16(), e = t.readUint8(), this.full_range_flag = e >> 7) : "rICC" !== this.colour_type && "prof" !== this.colour_type || (this.ICC_profile = t.readUint8Array(this.size - 4))
|
|
1606
|
+
}),
|
|
1607
|
+
BoxParser.createFullBoxCtor("cprt", "CopyrightBox",
|
|
1608
|
+
function(t) {
|
|
1609
|
+
this.parseLanguage(t),
|
|
1610
|
+
this.notice = t.readCString()
|
|
1611
|
+
}),
|
|
1612
|
+
BoxParser.createFullBoxCtor("cslg", "CompositionToDecodeBox",
|
|
1613
|
+
function(t) {
|
|
1614
|
+
0 === this.version && (this.compositionToDTSShift = t.readInt32(), this.leastDecodeToDisplayDelta = t.readInt32(), this.greatestDecodeToDisplayDelta = t.readInt32(), this.compositionStartTime = t.readInt32(), this.compositionEndTime = t.readInt32())
|
|
1615
|
+
}),
|
|
1616
|
+
BoxParser.createFullBoxCtor("ctts", "CompositionOffsetBox",
|
|
1617
|
+
function(t) {
|
|
1618
|
+
var e, i = t.readUint32();
|
|
1619
|
+
if (this.sample_counts = [], this.sample_offsets = [], 0 === this.version) for (e = 0; e < i; e++) {
|
|
1620
|
+
this.sample_counts.push(t.readUint32());
|
|
1621
|
+
var r = t.readInt32();
|
|
1622
|
+
r < 0 && Log.warn("BoxParser", "ctts box uses negative values without using version 1"),
|
|
1623
|
+
this.sample_offsets.push(r)
|
|
1624
|
+
} else if (1 == this.version) for (e = 0; e < i; e++) this.sample_counts.push(t.readUint32()),
|
|
1625
|
+
this.sample_offsets.push(t.readInt32())
|
|
1626
|
+
}),
|
|
1627
|
+
BoxParser.createBoxCtor("dac3", "AC3SpecificBox",
|
|
1628
|
+
function(t) {
|
|
1629
|
+
var e = t.readUint8(),
|
|
1630
|
+
i = t.readUint8(),
|
|
1631
|
+
t = t.readUint8();
|
|
1632
|
+
this.fscod = e >> 6,
|
|
1633
|
+
this.bsid = e >> 1 & 31,
|
|
1634
|
+
this.bsmod = (1 & e) << 2 | i >> 6 & 3,
|
|
1635
|
+
this.acmod = i >> 3 & 7,
|
|
1636
|
+
this.lfeon = i >> 2 & 1,
|
|
1637
|
+
this.bit_rate_code = 3 & i | t >> 5 & 7
|
|
1638
|
+
}),
|
|
1639
|
+
BoxParser.createBoxCtor("dec3", "EC3SpecificBox",
|
|
1640
|
+
function(t) {
|
|
1641
|
+
var e = t.readUint16();
|
|
1642
|
+
this.data_rate = e >> 3,
|
|
1643
|
+
this.num_ind_sub = 7 & e,
|
|
1644
|
+
this.ind_subs = [];
|
|
1645
|
+
for (var i = 0; i < this.num_ind_sub + 1; i++) {
|
|
1646
|
+
var r = {};
|
|
1647
|
+
this.ind_subs.push(r);
|
|
1648
|
+
var s = t.readUint8(),
|
|
1649
|
+
a = t.readUint8(),
|
|
1650
|
+
n = t.readUint8();
|
|
1651
|
+
r.fscod = s >> 6,
|
|
1652
|
+
r.bsid = s >> 1 & 31,
|
|
1653
|
+
r.bsmod = (1 & s) << 4 | a >> 4 & 15,
|
|
1654
|
+
r.acmod = a >> 1 & 7,
|
|
1655
|
+
r.lfeon = 1 & a,
|
|
1656
|
+
r.num_dep_sub = n >> 1 & 15,
|
|
1657
|
+
0 < r.num_dep_sub && (r.chan_loc = (1 & n) << 8 | t.readUint8())
|
|
1658
|
+
}
|
|
1659
|
+
}),
|
|
1660
|
+
BoxParser.createFullBoxCtor("dfLa", "FLACSpecificBox",
|
|
1661
|
+
function(t) {
|
|
1662
|
+
for (var e = [], i = ["STREAMINFO", "PADDING", "APPLICATION", "SEEKTABLE", "VORBIS_COMMENT", "CUESHEET", "PICTURE", "RESERVED"];;) {
|
|
1663
|
+
var r = t.readUint8(),
|
|
1664
|
+
s = Math.min(127 & r, i.length - 1);
|
|
1665
|
+
if (s ? t.readUint8Array(t.readUint24()) : (t.readUint8Array(13), this.samplerate = t.readUint32() >> 12, t.readUint8Array(20)), e.push(i[s]), 128 & r) break
|
|
1666
|
+
}
|
|
1667
|
+
this.numMetadataBlocks = e.length + " (" + e.join(", ") + ")"
|
|
1668
|
+
}),
|
|
1669
|
+
BoxParser.createBoxCtor("dimm", "hintimmediateBytesSent",
|
|
1670
|
+
function(t) {
|
|
1671
|
+
this.bytessent = t.readUint64()
|
|
1672
|
+
}),
|
|
1673
|
+
BoxParser.createBoxCtor("dmax", "hintlongestpacket",
|
|
1674
|
+
function(t) {
|
|
1675
|
+
this.time = t.readUint32()
|
|
1676
|
+
}),
|
|
1677
|
+
BoxParser.createBoxCtor("dmed", "hintmediaBytesSent",
|
|
1678
|
+
function(t) {
|
|
1679
|
+
this.bytessent = t.readUint64()
|
|
1680
|
+
}),
|
|
1681
|
+
BoxParser.createBoxCtor("dOps", "OpusSpecificBox",
|
|
1682
|
+
function(t) {
|
|
1683
|
+
if (this.Version = t.readUint8(), this.OutputChannelCount = t.readUint8(), this.PreSkip = t.readUint16(), this.InputSampleRate = t.readUint32(), this.OutputGain = t.readInt16(), this.ChannelMappingFamily = t.readUint8(), 0 !== this.ChannelMappingFamily) {
|
|
1684
|
+
this.StreamCount = t.readUint8(),
|
|
1685
|
+
this.CoupledCount = t.readUint8(),
|
|
1686
|
+
this.ChannelMapping = [];
|
|
1687
|
+
for (var e = 0; e < this.OutputChannelCount; e++) this.ChannelMapping[e] = t.readUint8()
|
|
1688
|
+
}
|
|
1689
|
+
}),
|
|
1690
|
+
BoxParser.createFullBoxCtor("dref", "DataReferenceBox",
|
|
1691
|
+
function(t) {
|
|
1692
|
+
var e;
|
|
1693
|
+
this.entries = [];
|
|
1694
|
+
for (var i = t.readUint32(), r = 0; r < i; r++) {
|
|
1695
|
+
if ((e = BoxParser.parseOneBox(t, !1, this.size - (t.getPosition() - this.start))).code !== BoxParser.OK) return;
|
|
1696
|
+
e = e.box,
|
|
1697
|
+
this.entries.push(e)
|
|
1698
|
+
}
|
|
1699
|
+
}),
|
|
1700
|
+
BoxParser.createBoxCtor("drep", "hintrepeatedBytesSent",
|
|
1701
|
+
function(t) {
|
|
1702
|
+
this.bytessent = t.readUint64()
|
|
1703
|
+
}),
|
|
1704
|
+
BoxParser.createFullBoxCtor("elng", "ExtendedLanguageBox",
|
|
1705
|
+
function(t) {
|
|
1706
|
+
this.extended_language = t.readString(this.size - this.hdr_size)
|
|
1707
|
+
}),
|
|
1708
|
+
BoxParser.createFullBoxCtor("elst", "EditListBox",
|
|
1709
|
+
function(t) {
|
|
1710
|
+
this.entries = [];
|
|
1711
|
+
for (var e = t.readUint32(), i = 0; i < e; i++) {
|
|
1712
|
+
var r = {};
|
|
1713
|
+
this.entries.push(r),
|
|
1714
|
+
1 === this.version ? (r.segment_duration = t.readUint64(), r.media_time = t.readInt64()) : (r.segment_duration = t.readUint32(), r.media_time = t.readInt32()),
|
|
1715
|
+
r.media_rate_integer = t.readInt16(),
|
|
1716
|
+
r.media_rate_fraction = t.readInt16()
|
|
1717
|
+
}
|
|
1718
|
+
}),
|
|
1719
|
+
BoxParser.createFullBoxCtor("emsg", "EventMessageBox",
|
|
1720
|
+
function(t) {
|
|
1721
|
+
1 == this.version ? (this.timescale = t.readUint32(), this.presentation_time = t.readUint64(), this.event_duration = t.readUint32(), this.id = t.readUint32(), this.scheme_id_uri = t.readCString(), this.value = t.readCString()) : (this.scheme_id_uri = t.readCString(), this.value = t.readCString(), this.timescale = t.readUint32(), this.presentation_time_delta = t.readUint32(), this.event_duration = t.readUint32(), this.id = t.readUint32());
|
|
1722
|
+
var e = this.size - this.hdr_size - (16 + (this.scheme_id_uri.length + 1) + (this.value.length + 1));
|
|
1723
|
+
1 == this.version && (e -= 4),
|
|
1724
|
+
this.message_data = t.readUint8Array(e)
|
|
1725
|
+
}),
|
|
1726
|
+
BoxParser.createEntityToGroupCtor = function(e, r) {
|
|
1727
|
+
BoxParser[e + "Box"] = function(t) {
|
|
1728
|
+
BoxParser.FullBox.call(this, e, t)
|
|
1729
|
+
},
|
|
1730
|
+
BoxParser[e + "Box"].prototype = new BoxParser.FullBox,
|
|
1731
|
+
BoxParser[e + "Box"].prototype.parse = function(t) {
|
|
1732
|
+
if (this.parseFullHeader(t), r) r.call(this, t);
|
|
1733
|
+
else for (this.group_id = t.readUint32(), this.num_entities_in_group = t.readUint32(), this.entity_ids = [], i = 0; i < this.num_entities_in_group; i++) {
|
|
1734
|
+
var e = t.readUint32();
|
|
1735
|
+
this.entity_ids.push(e)
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
},
|
|
1739
|
+
BoxParser.createEntityToGroupCtor("aebr"),
|
|
1740
|
+
BoxParser.createEntityToGroupCtor("afbr"),
|
|
1741
|
+
BoxParser.createEntityToGroupCtor("albc"),
|
|
1742
|
+
BoxParser.createEntityToGroupCtor("altr"),
|
|
1743
|
+
BoxParser.createEntityToGroupCtor("brst"),
|
|
1744
|
+
BoxParser.createEntityToGroupCtor("dobr"),
|
|
1745
|
+
BoxParser.createEntityToGroupCtor("eqiv"),
|
|
1746
|
+
BoxParser.createEntityToGroupCtor("favc"),
|
|
1747
|
+
BoxParser.createEntityToGroupCtor("fobr"),
|
|
1748
|
+
BoxParser.createEntityToGroupCtor("iaug"),
|
|
1749
|
+
BoxParser.createEntityToGroupCtor("pano"),
|
|
1750
|
+
BoxParser.createEntityToGroupCtor("slid"),
|
|
1751
|
+
BoxParser.createEntityToGroupCtor("ster"),
|
|
1752
|
+
BoxParser.createEntityToGroupCtor("tsyn"),
|
|
1753
|
+
BoxParser.createEntityToGroupCtor("wbbr"),
|
|
1754
|
+
BoxParser.createEntityToGroupCtor("prgr"),
|
|
1755
|
+
BoxParser.createEntityToGroupCtor("pymd",
|
|
1756
|
+
function(t) {
|
|
1757
|
+
this.group_id = t.readUint32(),
|
|
1758
|
+
this.num_entities_in_group = t.readUint32(),
|
|
1759
|
+
this.entity_ids = [];
|
|
1760
|
+
for (var e = 0; e < this.num_entities_in_group; e++) {
|
|
1761
|
+
var i = t.readUint32();
|
|
1762
|
+
this.entity_ids.push(i)
|
|
1763
|
+
}
|
|
1764
|
+
for (this.tile_size_x = t.readUint16(), this.tile_size_y = t.readUint16(), this.layer_binning = [], this.tiles_in_layer_column_minus1 = [], this.tiles_in_layer_row_minus1 = [], e = 0; e < this.num_entities_in_group; e++) this.layer_binning[e] = t.readUint16(),
|
|
1765
|
+
this.tiles_in_layer_row_minus1[e] = t.readUint16(),
|
|
1766
|
+
this.tiles_in_layer_column_minus1[e] = t.readUint16()
|
|
1767
|
+
}),
|
|
1768
|
+
BoxParser.createFullBoxCtor("esds", "ElementaryStreamDescriptorBox",
|
|
1769
|
+
function(t) {
|
|
1770
|
+
var e = t.readUint8Array(this.size - this.hdr_size);
|
|
1771
|
+
void 0 !== MPEG4DescriptorParser && (t = new MPEG4DescriptorParser, this.esd = t.parseOneDescriptor(new DataStream(e.buffer, 0, DataStream.BIG_ENDIAN)))
|
|
1772
|
+
}),
|
|
1773
|
+
BoxParser.createBoxCtor("fiel", "FieldHandlingBox",
|
|
1774
|
+
function(t) {
|
|
1775
|
+
this.fieldCount = t.readUint8(),
|
|
1776
|
+
this.fieldOrdering = t.readUint8()
|
|
1777
|
+
}),
|
|
1778
|
+
BoxParser.createBoxCtor("frma", "OriginalFormatBox",
|
|
1779
|
+
function(t) {
|
|
1780
|
+
this.data_format = t.readString(4)
|
|
1781
|
+
}),
|
|
1782
|
+
BoxParser.createBoxCtor("ftyp", "FileTypeBox",
|
|
1783
|
+
function(t) {
|
|
1784
|
+
var e = this.size - this.hdr_size;
|
|
1785
|
+
this.major_brand = t.readString(4),
|
|
1786
|
+
this.minor_version = t.readUint32(),
|
|
1787
|
+
e -= 8,
|
|
1788
|
+
this.compatible_brands = [];
|
|
1789
|
+
for (var i = 0; 4 <= e;) this.compatible_brands[i] = t.readString(4),
|
|
1790
|
+
e -= 4,
|
|
1791
|
+
i++
|
|
1792
|
+
}),
|
|
1793
|
+
BoxParser.createFullBoxCtor("hdlr", "HandlerBox",
|
|
1794
|
+
function(t) {
|
|
1795
|
+
0 === this.version && (t.readUint32(), this.handler = t.readString(4), t.readUint32Array(3), this.name = t.readString(this.size - this.hdr_size - 20), "\0" === this.name[this.name.length - 1] && (this.name = this.name.slice(0, -1)))
|
|
1796
|
+
}),
|
|
1797
|
+
BoxParser.createBoxCtor("hvcC", "HEVCConfigurationBox",
|
|
1798
|
+
function(t) {
|
|
1799
|
+
var e, i;
|
|
1800
|
+
this.configurationVersion = t.readUint8(),
|
|
1801
|
+
i = t.readUint8(),
|
|
1802
|
+
this.general_profile_space = i >> 6,
|
|
1803
|
+
this.general_tier_flag = (32 & i) >> 5,
|
|
1804
|
+
this.general_profile_idc = 31 & i,
|
|
1805
|
+
this.general_profile_compatibility = t.readUint32(),
|
|
1806
|
+
this.general_constraint_indicator = t.readUint8Array(6),
|
|
1807
|
+
this.general_level_idc = t.readUint8(),
|
|
1808
|
+
this.min_spatial_segmentation_idc = 4095 & t.readUint16(),
|
|
1809
|
+
this.parallelismType = 3 & t.readUint8(),
|
|
1810
|
+
this.chroma_format_idc = 3 & t.readUint8(),
|
|
1811
|
+
this.bit_depth_luma_minus8 = 7 & t.readUint8(),
|
|
1812
|
+
this.bit_depth_chroma_minus8 = 7 & t.readUint8(),
|
|
1813
|
+
this.avgFrameRate = t.readUint16(),
|
|
1814
|
+
i = t.readUint8(),
|
|
1815
|
+
this.constantFrameRate = i >> 6,
|
|
1816
|
+
this.numTemporalLayers = (13 & i) >> 3,
|
|
1817
|
+
this.temporalIdNested = (4 & i) >> 2,
|
|
1818
|
+
this.lengthSizeMinusOne = 3 & i,
|
|
1819
|
+
this.nalu_arrays = [],
|
|
1820
|
+
this.nalu_arrays.toString = function() {
|
|
1821
|
+
var t = "<table class='inner-table'>";
|
|
1822
|
+
t += "<thead><tr><th>completeness</th><th>nalu_type</th><th>nalu_data</th></tr></thead>",
|
|
1823
|
+
t += "<tbody>";
|
|
1824
|
+
for (var e = 0; e < this.length; e++) {
|
|
1825
|
+
var i = this[e];
|
|
1826
|
+
t += "<tr>",
|
|
1827
|
+
t += "<td rowspan='" + i.length + "'>" + i.completeness + "</td>",
|
|
1828
|
+
t += "<td rowspan='" + i.length + "'>" + i.nalu_type + "</td>";
|
|
1829
|
+
for (var r = 0; r < i.length; r++) 0 !== r && (t += "<tr>"),
|
|
1830
|
+
t += "<td>",
|
|
1831
|
+
t += i[r].data.reduce(function(t, e) {
|
|
1832
|
+
return t + e.toString(16).padStart(2, "0")
|
|
1833
|
+
},
|
|
1834
|
+
"0x"),
|
|
1835
|
+
t += "</td></tr>"
|
|
1836
|
+
}
|
|
1837
|
+
return t += "</tbody></table>"
|
|
1838
|
+
};
|
|
1839
|
+
for (var r = t.readUint8(), s = 0; s < r; s++) {
|
|
1840
|
+
var a = [];
|
|
1841
|
+
this.nalu_arrays.push(a),
|
|
1842
|
+
i = t.readUint8(),
|
|
1843
|
+
a.completeness = (128 & i) >> 7,
|
|
1844
|
+
a.nalu_type = 63 & i;
|
|
1845
|
+
for (var n = t.readUint16(), o = 0; o < n; o++) {
|
|
1846
|
+
var h = {};
|
|
1847
|
+
a.push(h),
|
|
1848
|
+
e = t.readUint16(),
|
|
1849
|
+
h.data = t.readUint8Array(e)
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
}),
|
|
1853
|
+
BoxParser.createFullBoxCtor("iinf", "ItemInfoBox",
|
|
1854
|
+
function(t) {
|
|
1855
|
+
var e;
|
|
1856
|
+
0 === this.version ? this.entry_count = t.readUint16() : this.entry_count = t.readUint32(),
|
|
1857
|
+
this.item_infos = [];
|
|
1858
|
+
for (var i = 0; i < this.entry_count; i++) {
|
|
1859
|
+
if ((e = BoxParser.parseOneBox(t, !1, this.size - (t.getPosition() - this.start))).code !== BoxParser.OK) return;
|
|
1860
|
+
"infe" !== e.box.type && Log.error("BoxParser", "Expected 'infe' box, got " + e.box.type),
|
|
1861
|
+
this.item_infos[i] = e.box
|
|
1862
|
+
}
|
|
1863
|
+
}),
|
|
1864
|
+
BoxParser.createFullBoxCtor("iloc", "ItemLocationBox",
|
|
1865
|
+
function(t) {
|
|
1866
|
+
var e = t.readUint8();
|
|
1867
|
+
this.offset_size = e >> 4 & 15,
|
|
1868
|
+
this.length_size = 15 & e,
|
|
1869
|
+
e = t.readUint8(),
|
|
1870
|
+
this.base_offset_size = e >> 4 & 15,
|
|
1871
|
+
1 === this.version || 2 === this.version ? this.index_size = 15 & e: this.index_size = 0,
|
|
1872
|
+
this.items = [];
|
|
1873
|
+
var i = 0;
|
|
1874
|
+
if (this.version < 2) i = t.readUint16();
|
|
1875
|
+
else {
|
|
1876
|
+
if (2 !== this.version) throw "version of iloc box not supported";
|
|
1877
|
+
i = t.readUint32()
|
|
1878
|
+
}
|
|
1879
|
+
for (var r = 0; r < i; r++) {
|
|
1880
|
+
var s = {};
|
|
1881
|
+
if (this.items.push(s), this.version < 2) s.item_ID = t.readUint16();
|
|
1882
|
+
else {
|
|
1883
|
+
if (2 !== this.version) throw "version of iloc box not supported";
|
|
1884
|
+
s.item_ID = t.readUint32()
|
|
1885
|
+
}
|
|
1886
|
+
switch (1 === this.version || 2 === this.version ? s.construction_method = 15 & t.readUint16() : s.construction_method = 0, s.data_reference_index = t.readUint16(), this.base_offset_size) {
|
|
1887
|
+
case 0:
|
|
1888
|
+
s.base_offset = 0;
|
|
1889
|
+
break;
|
|
1890
|
+
case 4:
|
|
1891
|
+
s.base_offset = t.readUint32();
|
|
1892
|
+
break;
|
|
1893
|
+
case 8:
|
|
1894
|
+
s.base_offset = t.readUint64();
|
|
1895
|
+
break;
|
|
1896
|
+
default:
|
|
1897
|
+
throw "Error reading base offset size"
|
|
1898
|
+
}
|
|
1899
|
+
var a = t.readUint16();
|
|
1900
|
+
s.extents = [];
|
|
1901
|
+
for (var n = 0; n < a; n++) {
|
|
1902
|
+
var o = {};
|
|
1903
|
+
if (s.extents.push(o), 1 === this.version || 2 === this.version) switch (this.index_size) {
|
|
1904
|
+
case 0:
|
|
1905
|
+
o.extent_index = 0;
|
|
1906
|
+
break;
|
|
1907
|
+
case 4:
|
|
1908
|
+
o.extent_index = t.readUint32();
|
|
1909
|
+
break;
|
|
1910
|
+
case 8:
|
|
1911
|
+
o.extent_index = t.readUint64();
|
|
1912
|
+
break;
|
|
1913
|
+
default:
|
|
1914
|
+
throw "Error reading extent index"
|
|
1915
|
+
}
|
|
1916
|
+
switch (this.offset_size) {
|
|
1917
|
+
case 0:
|
|
1918
|
+
o.extent_offset = 0;
|
|
1919
|
+
break;
|
|
1920
|
+
case 4:
|
|
1921
|
+
o.extent_offset = t.readUint32();
|
|
1922
|
+
break;
|
|
1923
|
+
case 8:
|
|
1924
|
+
o.extent_offset = t.readUint64();
|
|
1925
|
+
break;
|
|
1926
|
+
default:
|
|
1927
|
+
throw "Error reading extent index"
|
|
1928
|
+
}
|
|
1929
|
+
switch (this.length_size) {
|
|
1930
|
+
case 0:
|
|
1931
|
+
o.extent_length = 0;
|
|
1932
|
+
break;
|
|
1933
|
+
case 4:
|
|
1934
|
+
o.extent_length = t.readUint32();
|
|
1935
|
+
break;
|
|
1936
|
+
case 8:
|
|
1937
|
+
o.extent_length = t.readUint64();
|
|
1938
|
+
break;
|
|
1939
|
+
default:
|
|
1940
|
+
throw "Error reading extent index"
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
}),
|
|
1945
|
+
BoxParser.createBoxCtor("imir", "ImageMirror",
|
|
1946
|
+
function(t) {
|
|
1947
|
+
t = t.readUint8();
|
|
1948
|
+
this.reserved = t >> 7,
|
|
1949
|
+
this.axis = 1 & t
|
|
1950
|
+
}),
|
|
1951
|
+
BoxParser.createFullBoxCtor("infe", "ItemInfoEntry",
|
|
1952
|
+
function(t) {
|
|
1953
|
+
return 0 !== this.version && 1 !== this.version || (this.item_ID = t.readUint16(), this.item_protection_index = t.readUint16(), this.item_name = t.readCString(), this.content_type = t.readCString(), this.content_encoding = t.readCString()),
|
|
1954
|
+
1 === this.version ? (this.extension_type = t.readString(4), Log.warn("BoxParser", "Cannot parse extension type"), void t.seek(this.start + this.size)) : void(2 <= this.version && (2 === this.version ? this.item_ID = t.readUint16() : 3 === this.version && (this.item_ID = t.readUint32()), this.item_protection_index = t.readUint16(), this.item_type = t.readString(4), this.item_name = t.readCString(), "mime" === this.item_type ? (this.content_type = t.readCString(), this.content_encoding = t.readCString()) : "uri " === this.item_type && (this.item_uri_type = t.readCString())))
|
|
1955
|
+
}),
|
|
1956
|
+
BoxParser.createFullBoxCtor("ipma", "ItemPropertyAssociationBox",
|
|
1957
|
+
function(t) {
|
|
1958
|
+
var e, i;
|
|
1959
|
+
for (entry_count = t.readUint32(), this.associations = [], e = 0; e < entry_count; e++) {
|
|
1960
|
+
var r = {};
|
|
1961
|
+
this.associations.push(r),
|
|
1962
|
+
this.version < 1 ? r.id = t.readUint16() : r.id = t.readUint32();
|
|
1963
|
+
var s = t.readUint8();
|
|
1964
|
+
for (r.props = [], i = 0; i < s; i++) {
|
|
1965
|
+
var a = t.readUint8(),
|
|
1966
|
+
n = {};
|
|
1967
|
+
r.props.push(n),
|
|
1968
|
+
n.essential = (128 & a) >> 7 == 1,
|
|
1969
|
+
1 & this.flags ? n.property_index = (127 & a) << 8 | t.readUint8() : n.property_index = 127 & a
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
}),
|
|
1973
|
+
BoxParser.createFullBoxCtor("iref", "ItemReferenceBox",
|
|
1974
|
+
function(t) {
|
|
1975
|
+
var e;
|
|
1976
|
+
for (this.references = []; t.getPosition() < this.start + this.size;) {
|
|
1977
|
+
if ((e = BoxParser.parseOneBox(t, !0, this.size - (t.getPosition() - this.start))).code !== BoxParser.OK) return; (e = new(0 === this.version ? BoxParser.SingleItemTypeReferenceBox: BoxParser.SingleItemTypeReferenceBoxLarge)(e.type, e.size, e.hdr_size, e.start)).write === BoxParser.Box.prototype.write && "mdat" !== e.type && (Log.warn("BoxParser", e.type + " box writing not yet implemented, keeping unparsed data in memory for later write"), e.parseDataAndRewind(t)),
|
|
1978
|
+
e.parse(t),
|
|
1979
|
+
this.references.push(e)
|
|
1980
|
+
}
|
|
1981
|
+
}),
|
|
1982
|
+
BoxParser.createBoxCtor("irot", "ImageRotation",
|
|
1983
|
+
function(t) {
|
|
1984
|
+
this.angle = 3 & t.readUint8()
|
|
1985
|
+
}),
|
|
1986
|
+
BoxParser.createFullBoxCtor("ispe", "ImageSpatialExtentsProperty",
|
|
1987
|
+
function(t) {
|
|
1988
|
+
this.image_width = t.readUint32(),
|
|
1989
|
+
this.image_height = t.readUint32()
|
|
1990
|
+
}),
|
|
1991
|
+
BoxParser.createFullBoxCtor("kind", "KindBox",
|
|
1992
|
+
function(t) {
|
|
1993
|
+
this.schemeURI = t.readCString(),
|
|
1994
|
+
this.value = t.readCString()
|
|
1995
|
+
}),
|
|
1996
|
+
BoxParser.createFullBoxCtor("leva", "LevelAssignmentBox",
|
|
1997
|
+
function(t) {
|
|
1998
|
+
var e = t.readUint8();
|
|
1999
|
+
this.levels = [];
|
|
2000
|
+
for (var i = 0; i < e; i++) {
|
|
2001
|
+
var r = {}; (this.levels[i] = r).track_ID = t.readUint32();
|
|
2002
|
+
var s = t.readUint8();
|
|
2003
|
+
switch (r.padding_flag = s >> 7, r.assignment_type = 127 & s, r.assignment_type) {
|
|
2004
|
+
case 0:
|
|
2005
|
+
r.grouping_type = t.readString(4);
|
|
2006
|
+
break;
|
|
2007
|
+
case 1:
|
|
2008
|
+
r.grouping_type = t.readString(4),
|
|
2009
|
+
r.grouping_type_parameter = t.readUint32();
|
|
2010
|
+
break;
|
|
2011
|
+
case 2:
|
|
2012
|
+
case 3:
|
|
2013
|
+
break;
|
|
2014
|
+
case 4:
|
|
2015
|
+
r.sub_track_id = t.readUint32();
|
|
2016
|
+
break;
|
|
2017
|
+
default:
|
|
2018
|
+
Log.warn("BoxParser", "Unknown leva assignement type")
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
}),
|
|
2022
|
+
BoxParser.createBoxCtor("lhvC", "LHEVCConfigurationBox",
|
|
2023
|
+
function(t) {
|
|
2024
|
+
var e;
|
|
2025
|
+
this.configurationVersion = t.readUint8(),
|
|
2026
|
+
this.min_spatial_segmentation_idc = 4095 & t.readUint16(),
|
|
2027
|
+
this.parallelismType = 3 & t.readUint8(),
|
|
2028
|
+
e = t.readUint8(),
|
|
2029
|
+
this.numTemporalLayers = (13 & e) >> 3,
|
|
2030
|
+
this.temporalIdNested = (4 & e) >> 2,
|
|
2031
|
+
this.lengthSizeMinusOne = 3 & e,
|
|
2032
|
+
this.nalu_arrays = [],
|
|
2033
|
+
this.nalu_arrays.toString = function() {
|
|
2034
|
+
var t = "<table class='inner-table'>";
|
|
2035
|
+
t += "<thead><tr><th>completeness</th><th>nalu_type</th><th>nalu_data</th></tr></thead>",
|
|
2036
|
+
t += "<tbody>";
|
|
2037
|
+
for (var e = 0; e < this.length; e++) {
|
|
2038
|
+
var i = this[e];
|
|
2039
|
+
t += "<tr>",
|
|
2040
|
+
t += "<td rowspan='" + i.length + "'>" + i.completeness + "</td>",
|
|
2041
|
+
t += "<td rowspan='" + i.length + "'>" + i.nalu_type + "</td>";
|
|
2042
|
+
for (var r = 0; r < i.length; r++) 0 !== r && (t += "<tr>"),
|
|
2043
|
+
t += "<td>",
|
|
2044
|
+
t += i[r].data.reduce(function(t, e) {
|
|
2045
|
+
return t + e.toString(16).padStart(2, "0")
|
|
2046
|
+
},
|
|
2047
|
+
"0x"),
|
|
2048
|
+
t += "</td></tr>"
|
|
2049
|
+
}
|
|
2050
|
+
return t += "</tbody></table>"
|
|
2051
|
+
};
|
|
2052
|
+
for (var i = t.readUint8(), r = 0; r < i; r++) {
|
|
2053
|
+
var s = [];
|
|
2054
|
+
this.nalu_arrays.push(s),
|
|
2055
|
+
e = t.readUint8(),
|
|
2056
|
+
s.completeness = (128 & e) >> 7,
|
|
2057
|
+
s.nalu_type = 63 & e;
|
|
2058
|
+
for (var a = t.readUint16(), n = 0; n < a; n++) {
|
|
2059
|
+
var o = {};
|
|
2060
|
+
s.push(o);
|
|
2061
|
+
var h = t.readUint16();
|
|
2062
|
+
o.data = t.readUint8Array(h)
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
}),
|
|
2066
|
+
BoxParser.createBoxCtor("lsel", "LayerSelectorProperty",
|
|
2067
|
+
function(t) {
|
|
2068
|
+
this.layer_id = t.readUint16()
|
|
2069
|
+
}),
|
|
2070
|
+
BoxParser.createBoxCtor("maxr", "hintmaxrate",
|
|
2071
|
+
function(t) {
|
|
2072
|
+
this.period = t.readUint32(),
|
|
2073
|
+
this.bytes = t.readUint32()
|
|
2074
|
+
}),
|
|
2075
|
+
ColorPoint.prototype.toString = function() {
|
|
2076
|
+
return "(" + this.x + "," + this.y + ")"
|
|
2077
|
+
},
|
|
2078
|
+
BoxParser.createBoxCtor("mdcv", "MasteringDisplayColourVolumeBox",
|
|
2079
|
+
function(t) {
|
|
2080
|
+
this.display_primaries = [],
|
|
2081
|
+
this.display_primaries[0] = new ColorPoint(t.readUint16(), t.readUint16()),
|
|
2082
|
+
this.display_primaries[1] = new ColorPoint(t.readUint16(), t.readUint16()),
|
|
2083
|
+
this.display_primaries[2] = new ColorPoint(t.readUint16(), t.readUint16()),
|
|
2084
|
+
this.white_point = new ColorPoint(t.readUint16(), t.readUint16()),
|
|
2085
|
+
this.max_display_mastering_luminance = t.readUint32(),
|
|
2086
|
+
this.min_display_mastering_luminance = t.readUint32()
|
|
2087
|
+
}),
|
|
2088
|
+
BoxParser.createFullBoxCtor("mdhd", "MediaHeaderBox",
|
|
2089
|
+
function(t) {
|
|
2090
|
+
1 == this.version ? (this.creation_time = t.readUint64(), this.modification_time = t.readUint64(), this.timescale = t.readUint32(), this.duration = t.readUint64()) : (this.creation_time = t.readUint32(), this.modification_time = t.readUint32(), this.timescale = t.readUint32(), this.duration = t.readUint32()),
|
|
2091
|
+
this.parseLanguage(t),
|
|
2092
|
+
t.readUint16()
|
|
2093
|
+
}),
|
|
2094
|
+
BoxParser.createFullBoxCtor("mehd", "MovieExtendsHeaderBox",
|
|
2095
|
+
function(t) {
|
|
2096
|
+
1 & this.flags && (Log.warn("BoxParser", "mehd box incorrectly uses flags set to 1, converting version to 1"), this.version = 1),
|
|
2097
|
+
1 == this.version ? this.fragment_duration = t.readUint64() : this.fragment_duration = t.readUint32()
|
|
2098
|
+
}),
|
|
2099
|
+
BoxParser.createFullBoxCtor("meta", "MetaBox",
|
|
2100
|
+
function(t) {
|
|
2101
|
+
this.boxes = [],
|
|
2102
|
+
BoxParser.ContainerBox.prototype.parse.call(this, t)
|
|
2103
|
+
}),
|
|
2104
|
+
BoxParser.createFullBoxCtor("mfhd", "MovieFragmentHeaderBox",
|
|
2105
|
+
function(t) {
|
|
2106
|
+
this.sequence_number = t.readUint32()
|
|
2107
|
+
}),
|
|
2108
|
+
BoxParser.createFullBoxCtor("mfro", "MovieFragmentRandomAccessOffsetBox",
|
|
2109
|
+
function(t) {
|
|
2110
|
+
this._size = t.readUint32()
|
|
2111
|
+
}),
|
|
2112
|
+
BoxParser.createFullBoxCtor("mskC", "MaskConfigurationProperty",
|
|
2113
|
+
function(t) {
|
|
2114
|
+
this.bits_per_pixel = t.readUint8()
|
|
2115
|
+
}),
|
|
2116
|
+
BoxParser.createFullBoxCtor("mvhd", "MovieHeaderBox",
|
|
2117
|
+
function(t) {
|
|
2118
|
+
1 == this.version ? (this.creation_time = t.readUint64(), this.modification_time = t.readUint64(), this.timescale = t.readUint32(), this.duration = t.readUint64()) : (this.creation_time = t.readUint32(), this.modification_time = t.readUint32(), this.timescale = t.readUint32(), this.duration = t.readUint32()),
|
|
2119
|
+
this.rate = t.readUint32(),
|
|
2120
|
+
this.volume = t.readUint16() >> 8,
|
|
2121
|
+
t.readUint16(),
|
|
2122
|
+
t.readUint32Array(2),
|
|
2123
|
+
this.matrix = t.readUint32Array(9),
|
|
2124
|
+
t.readUint32Array(6),
|
|
2125
|
+
this.next_track_id = t.readUint32()
|
|
2126
|
+
}),
|
|
2127
|
+
BoxParser.createBoxCtor("npck", "hintPacketsSent",
|
|
2128
|
+
function(t) {
|
|
2129
|
+
this.packetssent = t.readUint32()
|
|
2130
|
+
}),
|
|
2131
|
+
BoxParser.createBoxCtor("nump", "hintPacketsSent",
|
|
2132
|
+
function(t) {
|
|
2133
|
+
this.packetssent = t.readUint64()
|
|
2134
|
+
}),
|
|
2135
|
+
BoxParser.createFullBoxCtor("padb", "PaddingBitsBox",
|
|
2136
|
+
function(t) {
|
|
2137
|
+
var e = t.readUint32();
|
|
2138
|
+
this.padbits = [];
|
|
2139
|
+
for (var i = 0; i < Math.floor((e + 1) / 2); i++) this.padbits = t.readUint8()
|
|
2140
|
+
}),
|
|
2141
|
+
BoxParser.createBoxCtor("pasp", "PixelAspectRatioBox",
|
|
2142
|
+
function(t) {
|
|
2143
|
+
this.hSpacing = t.readUint32(),
|
|
2144
|
+
this.vSpacing = t.readUint32()
|
|
2145
|
+
}),
|
|
2146
|
+
BoxParser.createBoxCtor("payl", "CuePayloadBox",
|
|
2147
|
+
function(t) {
|
|
2148
|
+
this.text = t.readString(this.size - this.hdr_size)
|
|
2149
|
+
}),
|
|
2150
|
+
BoxParser.createBoxCtor("payt", "hintpayloadID",
|
|
2151
|
+
function(t) {
|
|
2152
|
+
this.payloadID = t.readUint32();
|
|
2153
|
+
var e = t.readUint8();
|
|
2154
|
+
this.rtpmap_string = t.readString(e)
|
|
2155
|
+
}),
|
|
2156
|
+
BoxParser.createFullBoxCtor("pdin", "ProgressiveDownloadInfoBox",
|
|
2157
|
+
function(t) {
|
|
2158
|
+
var e = (this.size - this.hdr_size) / 8;
|
|
2159
|
+
this.rate = [],
|
|
2160
|
+
this.initial_delay = [];
|
|
2161
|
+
for (var i = 0; i < e; i++) this.rate[i] = t.readUint32(),
|
|
2162
|
+
this.initial_delay[i] = t.readUint32()
|
|
2163
|
+
}),
|
|
2164
|
+
BoxParser.createFullBoxCtor("pitm", "PrimaryItemBox",
|
|
2165
|
+
function(t) {
|
|
2166
|
+
0 === this.version ? this.item_id = t.readUint16() : this.item_id = t.readUint32()
|
|
2167
|
+
}),
|
|
2168
|
+
BoxParser.createFullBoxCtor("pixi", "PixelInformationProperty",
|
|
2169
|
+
function(t) {
|
|
2170
|
+
var e;
|
|
2171
|
+
for (this.num_channels = t.readUint8(), this.bits_per_channels = [], e = 0; e < this.num_channels; e++) this.bits_per_channels[e] = t.readUint8()
|
|
2172
|
+
}),
|
|
2173
|
+
BoxParser.createBoxCtor("pmax", "hintlargestpacket",
|
|
2174
|
+
function(t) {
|
|
2175
|
+
this.bytes = t.readUint32()
|
|
2176
|
+
}),
|
|
2177
|
+
BoxParser.createFullBoxCtor("prdi", "ProgressiveDerivedImageItemInformationProperty",
|
|
2178
|
+
function(t) {
|
|
2179
|
+
if (this.step_count = t.readUint16(), this.item_count = [], 2 & this.flags) for (var e = 0; e < this.step_count; e++) this.item_count[e] = t.readUint16()
|
|
2180
|
+
}),
|
|
2181
|
+
BoxParser.createFullBoxCtor("prft", "ProducerReferenceTimeBox",
|
|
2182
|
+
function(t) {
|
|
2183
|
+
this.ref_track_id = t.readUint32(),
|
|
2184
|
+
this.ntp_timestamp = t.readUint64(),
|
|
2185
|
+
0 === this.version ? this.media_time = t.readUint32() : this.media_time = t.readUint64()
|
|
2186
|
+
}),
|
|
2187
|
+
BoxParser.createFullBoxCtor("pssh", "ProtectionSystemSpecificHeaderBox",
|
|
2188
|
+
function(t) {
|
|
2189
|
+
if (this.system_id = BoxParser.parseHex16(t), 0 < this.version) {
|
|
2190
|
+
var e = t.readUint32();
|
|
2191
|
+
this.kid = [];
|
|
2192
|
+
for (var i = 0; i < e; i++) this.kid[i] = BoxParser.parseHex16(t)
|
|
2193
|
+
}
|
|
2194
|
+
var r = t.readUint32();
|
|
2195
|
+
0 < r && (this.data = t.readUint8Array(r))
|
|
2196
|
+
}),
|
|
2197
|
+
BoxParser.createFullBoxCtor("clef", "TrackCleanApertureDimensionsBox",
|
|
2198
|
+
function(t) {
|
|
2199
|
+
this.width = t.readUint32(),
|
|
2200
|
+
this.height = t.readUint32()
|
|
2201
|
+
}),
|
|
2202
|
+
BoxParser.createFullBoxCtor("enof", "TrackEncodedPixelsDimensionsBox",
|
|
2203
|
+
function(t) {
|
|
2204
|
+
this.width = t.readUint32(),
|
|
2205
|
+
this.height = t.readUint32()
|
|
2206
|
+
}),
|
|
2207
|
+
BoxParser.createFullBoxCtor("prof", "TrackProductionApertureDimensionsBox",
|
|
2208
|
+
function(t) {
|
|
2209
|
+
this.width = t.readUint32(),
|
|
2210
|
+
this.height = t.readUint32()
|
|
2211
|
+
}),
|
|
2212
|
+
BoxParser.createContainerBoxCtor("tapt", "TrackApertureModeDimensionsBox", null, ["clef", "prof", "enof"]),
|
|
2213
|
+
BoxParser.createBoxCtor("rtp ", "rtpmoviehintinformation",
|
|
2214
|
+
function(t) {
|
|
2215
|
+
this.descriptionformat = t.readString(4),
|
|
2216
|
+
this.sdptext = t.readString(this.size - this.hdr_size - 4)
|
|
2217
|
+
}),
|
|
2218
|
+
BoxParser.createFullBoxCtor("saio", "SampleAuxiliaryInformationOffsetsBox",
|
|
2219
|
+
function(t) {
|
|
2220
|
+
1 & this.flags && (this.aux_info_type = t.readString(4), this.aux_info_type_parameter = t.readUint32());
|
|
2221
|
+
var e = t.readUint32();
|
|
2222
|
+
this.offset = [];
|
|
2223
|
+
for (var i = 0; i < e; i++) 0 === this.version ? this.offset[i] = t.readUint32() : this.offset[i] = t.readUint64()
|
|
2224
|
+
}),
|
|
2225
|
+
BoxParser.createFullBoxCtor("saiz", "SampleAuxiliaryInformationSizesBox",
|
|
2226
|
+
function(t) {
|
|
2227
|
+
if (1 & this.flags && (this.aux_info_type = t.readString(4), this.aux_info_type_parameter = t.readUint32()), this.default_sample_info_size = t.readUint8(), this.sample_count = t.readUint32(), this.sample_info_size = [], 0 === this.default_sample_info_size) for (var e = 0; e < this.sample_count; e++) this.sample_info_size[e] = t.readUint8()
|
|
2228
|
+
}),
|
|
2229
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_METADATA, "mett",
|
|
2230
|
+
function(t) {
|
|
2231
|
+
this.parseHeader(t),
|
|
2232
|
+
this.content_encoding = t.readCString(),
|
|
2233
|
+
this.mime_format = t.readCString(),
|
|
2234
|
+
this.parseFooter(t)
|
|
2235
|
+
}),
|
|
2236
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_METADATA, "metx",
|
|
2237
|
+
function(t) {
|
|
2238
|
+
this.parseHeader(t),
|
|
2239
|
+
this.content_encoding = t.readCString(),
|
|
2240
|
+
this.namespace = t.readCString(),
|
|
2241
|
+
this.schema_location = t.readCString(),
|
|
2242
|
+
this.parseFooter(t)
|
|
2243
|
+
}),
|
|
2244
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_SUBTITLE, "sbtt",
|
|
2245
|
+
function(t) {
|
|
2246
|
+
this.parseHeader(t),
|
|
2247
|
+
this.content_encoding = t.readCString(),
|
|
2248
|
+
this.mime_format = t.readCString(),
|
|
2249
|
+
this.parseFooter(t)
|
|
2250
|
+
}),
|
|
2251
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_SUBTITLE, "stpp",
|
|
2252
|
+
function(t) {
|
|
2253
|
+
this.parseHeader(t),
|
|
2254
|
+
this.namespace = t.readCString(),
|
|
2255
|
+
this.schema_location = t.readCString(),
|
|
2256
|
+
this.auxiliary_mime_types = t.readCString(),
|
|
2257
|
+
this.parseFooter(t)
|
|
2258
|
+
}),
|
|
2259
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_SUBTITLE, "stxt",
|
|
2260
|
+
function(t) {
|
|
2261
|
+
this.parseHeader(t),
|
|
2262
|
+
this.content_encoding = t.readCString(),
|
|
2263
|
+
this.mime_format = t.readCString(),
|
|
2264
|
+
this.parseFooter(t)
|
|
2265
|
+
}),
|
|
2266
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_SUBTITLE, "tx3g",
|
|
2267
|
+
function(t) {
|
|
2268
|
+
this.parseHeader(t),
|
|
2269
|
+
this.displayFlags = t.readUint32(),
|
|
2270
|
+
this.horizontal_justification = t.readInt8(),
|
|
2271
|
+
this.vertical_justification = t.readInt8(),
|
|
2272
|
+
this.bg_color_rgba = t.readUint8Array(4),
|
|
2273
|
+
this.box_record = t.readInt16Array(4),
|
|
2274
|
+
this.style_record = t.readUint8Array(12),
|
|
2275
|
+
this.parseFooter(t)
|
|
2276
|
+
}),
|
|
2277
|
+
BoxParser.createSampleEntryCtor(BoxParser.SAMPLE_ENTRY_TYPE_METADATA, "wvtt",
|
|
2278
|
+
function(t) {
|
|
2279
|
+
this.parseHeader(t),
|
|
2280
|
+
this.parseFooter(t)
|
|
2281
|
+
}),
|
|
2282
|
+
BoxParser.createSampleGroupCtor("alst",
|
|
2283
|
+
function(t) {
|
|
2284
|
+
var e, i = t.readUint16();
|
|
2285
|
+
for (this.first_output_sample = t.readUint16(), this.sample_offset = [], e = 0; e < i; e++) this.sample_offset[e] = t.readUint32();
|
|
2286
|
+
var r = this.description_length - 4 - 4 * i;
|
|
2287
|
+
for (this.num_output_samples = [], this.num_total_samples = [], e = 0; e < r / 4; e++) this.num_output_samples[e] = t.readUint16(),
|
|
2288
|
+
this.num_total_samples[e] = t.readUint16()
|
|
2289
|
+
}),
|
|
2290
|
+
BoxParser.createSampleGroupCtor("avll",
|
|
2291
|
+
function(t) {
|
|
2292
|
+
this.layerNumber = t.readUint8(),
|
|
2293
|
+
this.accurateStatisticsFlag = t.readUint8(),
|
|
2294
|
+
this.avgBitRate = t.readUint16(),
|
|
2295
|
+
this.avgFrameRate = t.readUint16()
|
|
2296
|
+
}),
|
|
2297
|
+
BoxParser.createSampleGroupCtor("avss",
|
|
2298
|
+
function(t) {
|
|
2299
|
+
this.subSequenceIdentifier = t.readUint16(),
|
|
2300
|
+
this.layerNumber = t.readUint8();
|
|
2301
|
+
var e = t.readUint8();
|
|
2302
|
+
this.durationFlag = e >> 7,
|
|
2303
|
+
this.avgRateFlag = e >> 6 & 1,
|
|
2304
|
+
this.durationFlag && (this.duration = t.readUint32()),
|
|
2305
|
+
this.avgRateFlag && (this.accurateStatisticsFlag = t.readUint8(), this.avgBitRate = t.readUint16(), this.avgFrameRate = t.readUint16()),
|
|
2306
|
+
this.dependency = [];
|
|
2307
|
+
for (var i = t.readUint8(), r = 0; r < i; r++) {
|
|
2308
|
+
var s = {};
|
|
2309
|
+
this.dependency.push(s),
|
|
2310
|
+
s.subSeqDirectionFlag = t.readUint8(),
|
|
2311
|
+
s.layerNumber = t.readUint8(),
|
|
2312
|
+
s.subSequenceIdentifier = t.readUint16()
|
|
2313
|
+
}
|
|
2314
|
+
}),
|
|
2315
|
+
BoxParser.createSampleGroupCtor("dtrt",
|
|
2316
|
+
function(t) {
|
|
2317
|
+
Log.warn("BoxParser", "Sample Group type: " + this.grouping_type + " not fully parsed")
|
|
2318
|
+
}),
|
|
2319
|
+
BoxParser.createSampleGroupCtor("mvif",
|
|
2320
|
+
function(t) {
|
|
2321
|
+
Log.warn("BoxParser", "Sample Group type: " + this.grouping_type + " not fully parsed")
|
|
2322
|
+
}),
|
|
2323
|
+
BoxParser.createSampleGroupCtor("prol",
|
|
2324
|
+
function(t) {
|
|
2325
|
+
this.roll_distance = t.readInt16()
|
|
2326
|
+
}),
|
|
2327
|
+
BoxParser.createSampleGroupCtor("rap ",
|
|
2328
|
+
function(t) {
|
|
2329
|
+
t = t.readUint8();
|
|
2330
|
+
this.num_leading_samples_known = t >> 7,
|
|
2331
|
+
this.num_leading_samples = 127 & t
|
|
2332
|
+
}),
|
|
2333
|
+
BoxParser.createSampleGroupCtor("rash",
|
|
2334
|
+
function(t) {
|
|
2335
|
+
if (this.operation_point_count = t.readUint16(), this.description_length !== 2 + (1 === this.operation_point_count ? 2 : 6 * this.operation_point_count) + 9) Log.warn("BoxParser", "Mismatch in " + this.grouping_type + " sample group length"),
|
|
2336
|
+
this.data = t.readUint8Array(this.description_length - 2);
|
|
2337
|
+
else {
|
|
2338
|
+
if (1 === this.operation_point_count) this.target_rate_share = t.readUint16();
|
|
2339
|
+
else {
|
|
2340
|
+
this.target_rate_share = [],
|
|
2341
|
+
this.available_bitrate = [];
|
|
2342
|
+
for (var e = 0; e < this.operation_point_count; e++) this.available_bitrate[e] = t.readUint32(),
|
|
2343
|
+
this.target_rate_share[e] = t.readUint16()
|
|
2344
|
+
}
|
|
2345
|
+
this.maximum_bitrate = t.readUint32(),
|
|
2346
|
+
this.minimum_bitrate = t.readUint32(),
|
|
2347
|
+
this.discard_priority = t.readUint8()
|
|
2348
|
+
}
|
|
2349
|
+
}),
|
|
2350
|
+
BoxParser.createSampleGroupCtor("roll",
|
|
2351
|
+
function(t) {
|
|
2352
|
+
this.roll_distance = t.readInt16()
|
|
2353
|
+
}),
|
|
2354
|
+
BoxParser.SampleGroupEntry.prototype.parse = function(t) {
|
|
2355
|
+
Log.warn("BoxParser", "Unknown Sample Group type: " + this.grouping_type),
|
|
2356
|
+
this.data = t.readUint8Array(this.description_length)
|
|
2357
|
+
},
|
|
2358
|
+
BoxParser.createSampleGroupCtor("scif",
|
|
2359
|
+
function(t) {
|
|
2360
|
+
Log.warn("BoxParser", "Sample Group type: " + this.grouping_type + " not fully parsed")
|
|
2361
|
+
}),
|
|
2362
|
+
BoxParser.createSampleGroupCtor("scnm",
|
|
2363
|
+
function(t) {
|
|
2364
|
+
Log.warn("BoxParser", "Sample Group type: " + this.grouping_type + " not fully parsed")
|
|
2365
|
+
}),
|
|
2366
|
+
BoxParser.createSampleGroupCtor("seig",
|
|
2367
|
+
function(t) {
|
|
2368
|
+
this.reserved = t.readUint8();
|
|
2369
|
+
var e = t.readUint8();
|
|
2370
|
+
this.crypt_byte_block = e >> 4,
|
|
2371
|
+
this.skip_byte_block = 15 & e,
|
|
2372
|
+
this.isProtected = t.readUint8(),
|
|
2373
|
+
this.Per_Sample_IV_Size = t.readUint8(),
|
|
2374
|
+
this.KID = BoxParser.parseHex16(t),
|
|
2375
|
+
this.constant_IV_size = 0,
|
|
2376
|
+
this.constant_IV = 0,
|
|
2377
|
+
1 === this.isProtected && 0 === this.Per_Sample_IV_Size && (this.constant_IV_size = t.readUint8(), this.constant_IV = t.readUint8Array(this.constant_IV_size))
|
|
2378
|
+
}),
|
|
2379
|
+
BoxParser.createSampleGroupCtor("stsa",
|
|
2380
|
+
function(t) {
|
|
2381
|
+
Log.warn("BoxParser", "Sample Group type: " + this.grouping_type + " not fully parsed")
|
|
2382
|
+
}),
|
|
2383
|
+
BoxParser.createSampleGroupCtor("sync",
|
|
2384
|
+
function(t) {
|
|
2385
|
+
t = t.readUint8();
|
|
2386
|
+
this.NAL_unit_type = 63 & t
|
|
2387
|
+
}),
|
|
2388
|
+
BoxParser.createSampleGroupCtor("tele",
|
|
2389
|
+
function(t) {
|
|
2390
|
+
t = t.readUint8();
|
|
2391
|
+
this.level_independently_decodable = t >> 7
|
|
2392
|
+
}),
|
|
2393
|
+
BoxParser.createSampleGroupCtor("tsas",
|
|
2394
|
+
function(t) {
|
|
2395
|
+
Log.warn("BoxParser", "Sample Group type: " + this.grouping_type + " not fully parsed")
|
|
2396
|
+
}),
|
|
2397
|
+
BoxParser.createSampleGroupCtor("tscl",
|
|
2398
|
+
function(t) {
|
|
2399
|
+
Log.warn("BoxParser", "Sample Group type: " + this.grouping_type + " not fully parsed")
|
|
2400
|
+
}),
|
|
2401
|
+
BoxParser.createSampleGroupCtor("vipr",
|
|
2402
|
+
function(t) {
|
|
2403
|
+
Log.warn("BoxParser", "Sample Group type: " + this.grouping_type + " not fully parsed")
|
|
2404
|
+
}),
|
|
2405
|
+
BoxParser.createFullBoxCtor("sbgp", "SampleToGroupBox",
|
|
2406
|
+
function(t) {
|
|
2407
|
+
this.grouping_type = t.readString(4),
|
|
2408
|
+
1 === this.version ? this.grouping_type_parameter = t.readUint32() : this.grouping_type_parameter = 0,
|
|
2409
|
+
this.entries = [];
|
|
2410
|
+
for (var e = t.readUint32(), i = 0; i < e; i++) {
|
|
2411
|
+
var r = {};
|
|
2412
|
+
this.entries.push(r),
|
|
2413
|
+
r.sample_count = t.readInt32(),
|
|
2414
|
+
r.group_description_index = t.readInt32()
|
|
2415
|
+
}
|
|
2416
|
+
}),
|
|
2417
|
+
Pixel.prototype.toString = function() {
|
|
2418
|
+
return "[row: " + this.bad_pixel_row + ", column: " + this.bad_pixel_column + "]"
|
|
2419
|
+
},
|
|
2420
|
+
BoxParser.createFullBoxCtor("sbpm", "SensorBadPixelsMapBox",
|
|
2421
|
+
function(t) {
|
|
2422
|
+
var e;
|
|
2423
|
+
for (this.component_count = t.readUint16(), this.component_index = [], e = 0; e < this.component_count; e++) this.component_index.push(t.readUint16());
|
|
2424
|
+
var i = t.readUint8();
|
|
2425
|
+
for (this.correction_applied = 128 == (128 & i), this.num_bad_rows = t.readUint32(), this.num_bad_cols = t.readUint32(), this.num_bad_pixels = t.readUint32(), this.bad_rows = [], this.bad_columns = [], this.bad_pixels = [], e = 0; e < this.num_bad_rows; e++) this.bad_rows.push(t.readUint32());
|
|
2426
|
+
for (e = 0; e < this.num_bad_cols; e++) this.bad_columns.push(t.readUint32());
|
|
2427
|
+
for (e = 0; e < this.num_bad_pixels; e++) {
|
|
2428
|
+
var r = t.readUint32(),
|
|
2429
|
+
s = t.readUint32();
|
|
2430
|
+
this.bad_pixels.push(new Pixel(r, s))
|
|
2431
|
+
}
|
|
2432
|
+
}),
|
|
2433
|
+
BoxParser.createFullBoxCtor("schm", "SchemeTypeBox",
|
|
2434
|
+
function(t) {
|
|
2435
|
+
this.scheme_type = t.readString(4),
|
|
2436
|
+
this.scheme_version = t.readUint32(),
|
|
2437
|
+
1 & this.flags && (this.scheme_uri = t.readString(this.size - this.hdr_size - 8))
|
|
2438
|
+
}),
|
|
2439
|
+
BoxParser.createBoxCtor("sdp ", "rtptracksdphintinformation",
|
|
2440
|
+
function(t) {
|
|
2441
|
+
this.sdptext = t.readString(this.size - this.hdr_size)
|
|
2442
|
+
}),
|
|
2443
|
+
BoxParser.createFullBoxCtor("sdtp", "SampleDependencyTypeBox",
|
|
2444
|
+
function(t) {
|
|
2445
|
+
var e, i = this.size - this.hdr_size;
|
|
2446
|
+
this.is_leading = [],
|
|
2447
|
+
this.sample_depends_on = [],
|
|
2448
|
+
this.sample_is_depended_on = [],
|
|
2449
|
+
this.sample_has_redundancy = [];
|
|
2450
|
+
for (var r = 0; r < i; r++) e = t.readUint8(),
|
|
2451
|
+
this.is_leading[r] = e >> 6,
|
|
2452
|
+
this.sample_depends_on[r] = e >> 4 & 3,
|
|
2453
|
+
this.sample_is_depended_on[r] = e >> 2 & 3,
|
|
2454
|
+
this.sample_has_redundancy[r] = 3 & e
|
|
2455
|
+
}),
|
|
2456
|
+
BoxParser.createFullBoxCtor("senc", "SampleEncryptionBox"),
|
|
2457
|
+
BoxParser.createFullBoxCtor("sgpd", "SampleGroupDescriptionBox",
|
|
2458
|
+
function(t) {
|
|
2459
|
+
this.grouping_type = t.readString(4),
|
|
2460
|
+
Log.debug("BoxParser", "Found Sample Groups of type " + this.grouping_type),
|
|
2461
|
+
1 === this.version ? this.default_length = t.readUint32() : this.default_length = 0,
|
|
2462
|
+
2 <= this.version && (this.default_group_description_index = t.readUint32()),
|
|
2463
|
+
this.entries = [];
|
|
2464
|
+
for (var e = t.readUint32(), i = 0; i < e; i++) {
|
|
2465
|
+
var r = new(BoxParser[this.grouping_type + "SampleGroupEntry"] ? BoxParser[this.grouping_type + "SampleGroupEntry"] : BoxParser.SampleGroupEntry)(this.grouping_type);
|
|
2466
|
+
this.entries.push(r),
|
|
2467
|
+
1 === this.version && 0 === this.default_length ? r.description_length = t.readUint32() : r.description_length = this.default_length,
|
|
2468
|
+
r.write === BoxParser.SampleGroupEntry.prototype.write && (Log.info("BoxParser", "SampleGroup for type " + this.grouping_type + " writing not yet implemented, keeping unparsed data in memory for later write"), r.data = t.readUint8Array(r.description_length), t.position -= r.description_length),
|
|
2469
|
+
r.parse(t)
|
|
2470
|
+
}
|
|
2471
|
+
}),
|
|
2472
|
+
BoxParser.createFullBoxCtor("sidx", "CompressedSegmentIndexBox",
|
|
2473
|
+
function(t) {
|
|
2474
|
+
this.reference_ID = t.readUint32(),
|
|
2475
|
+
this.timescale = t.readUint32(),
|
|
2476
|
+
0 === this.version ? (this.earliest_presentation_time = t.readUint32(), this.first_offset = t.readUint32()) : (this.earliest_presentation_time = t.readUint64(), this.first_offset = t.readUint64()),
|
|
2477
|
+
t.readUint16(),
|
|
2478
|
+
this.references = [];
|
|
2479
|
+
for (var e = t.readUint16(), i = 0; i < e; i++) {
|
|
2480
|
+
var r = {};
|
|
2481
|
+
this.references.push(r);
|
|
2482
|
+
var s = t.readUint32();
|
|
2483
|
+
r.reference_type = s >> 31 & 1,
|
|
2484
|
+
r.referenced_size = 2147483647 & s,
|
|
2485
|
+
r.subsegment_duration = t.readUint32(),
|
|
2486
|
+
s = t.readUint32(),
|
|
2487
|
+
r.starts_with_SAP = s >> 31 & 1,
|
|
2488
|
+
r.SAP_type = s >> 28 & 7,
|
|
2489
|
+
r.SAP_delta_time = 268435455 & s
|
|
2490
|
+
}
|
|
2491
|
+
}),
|
|
2492
|
+
BoxParser.SingleItemTypeReferenceBox = function(t, e, i, r) {
|
|
2493
|
+
BoxParser.Box.call(this, t, e),
|
|
2494
|
+
this.hdr_size = i,
|
|
2495
|
+
this.start = r
|
|
2496
|
+
},
|
|
2497
|
+
BoxParser.SingleItemTypeReferenceBox.prototype = new BoxParser.Box,
|
|
2498
|
+
BoxParser.SingleItemTypeReferenceBox.prototype.parse = function(t) {
|
|
2499
|
+
this.from_item_ID = t.readUint16();
|
|
2500
|
+
var e = t.readUint16();
|
|
2501
|
+
this.references = [];
|
|
2502
|
+
for (var i = 0; i < e; i++) this.references[i] = {},
|
|
2503
|
+
this.references[i].to_item_ID = t.readUint16()
|
|
2504
|
+
},
|
|
2505
|
+
BoxParser.SingleItemTypeReferenceBoxLarge = function(t, e, i, r) {
|
|
2506
|
+
BoxParser.Box.call(this, t, e),
|
|
2507
|
+
this.hdr_size = i,
|
|
2508
|
+
this.start = r
|
|
2509
|
+
},
|
|
2510
|
+
BoxParser.SingleItemTypeReferenceBoxLarge.prototype = new BoxParser.Box,
|
|
2511
|
+
BoxParser.SingleItemTypeReferenceBoxLarge.prototype.parse = function(t) {
|
|
2512
|
+
this.from_item_ID = t.readUint32();
|
|
2513
|
+
var e = t.readUint16();
|
|
2514
|
+
this.references = [];
|
|
2515
|
+
for (var i = 0; i < e; i++) this.references[i] = {},
|
|
2516
|
+
this.references[i].to_item_ID = t.readUint32()
|
|
2517
|
+
},
|
|
2518
|
+
BoxParser.createFullBoxCtor("SmDm", "SMPTE2086MasteringDisplayMetadataBox",
|
|
2519
|
+
function(t) {
|
|
2520
|
+
this.primaryRChromaticity_x = t.readUint16(),
|
|
2521
|
+
this.primaryRChromaticity_y = t.readUint16(),
|
|
2522
|
+
this.primaryGChromaticity_x = t.readUint16(),
|
|
2523
|
+
this.primaryGChromaticity_y = t.readUint16(),
|
|
2524
|
+
this.primaryBChromaticity_x = t.readUint16(),
|
|
2525
|
+
this.primaryBChromaticity_y = t.readUint16(),
|
|
2526
|
+
this.whitePointChromaticity_x = t.readUint16(),
|
|
2527
|
+
this.whitePointChromaticity_y = t.readUint16(),
|
|
2528
|
+
this.luminanceMax = t.readUint32(),
|
|
2529
|
+
this.luminanceMin = t.readUint32()
|
|
2530
|
+
}),
|
|
2531
|
+
BoxParser.createFullBoxCtor("smhd", "SoundMediaHeaderBox",
|
|
2532
|
+
function(t) {
|
|
2533
|
+
this.balance = t.readUint16(),
|
|
2534
|
+
t.readUint16()
|
|
2535
|
+
}),
|
|
2536
|
+
BoxParser.createFullBoxCtor("ssix", "CompressedSubsegmentIndexBox",
|
|
2537
|
+
function(t) {
|
|
2538
|
+
this.subsegments = [];
|
|
2539
|
+
for (var e = t.readUint32(), i = 0; i < e; i++) {
|
|
2540
|
+
var r = {};
|
|
2541
|
+
this.subsegments.push(r),
|
|
2542
|
+
r.ranges = [];
|
|
2543
|
+
for (var s = t.readUint32(), a = 0; a < s; a++) {
|
|
2544
|
+
var n = {};
|
|
2545
|
+
r.ranges.push(n),
|
|
2546
|
+
n.level = t.readUint8(),
|
|
2547
|
+
n.range_size = t.readUint24()
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
}),
|
|
2551
|
+
BoxParser.createFullBoxCtor("stco", "ChunkOffsetBox",
|
|
2552
|
+
function(t) {
|
|
2553
|
+
var e = t.readUint32();
|
|
2554
|
+
if (this.chunk_offsets = [], 0 === this.version) for (var i = 0; i < e; i++) this.chunk_offsets.push(t.readUint32())
|
|
2555
|
+
}),
|
|
2556
|
+
BoxParser.createFullBoxCtor("stdp", "DegradationPriorityBox",
|
|
2557
|
+
function(t) {
|
|
2558
|
+
var e = (this.size - this.hdr_size) / 2;
|
|
2559
|
+
this.priority = [];
|
|
2560
|
+
for (var i = 0; i < e; i++) this.priority[i] = t.readUint16()
|
|
2561
|
+
}),
|
|
2562
|
+
BoxParser.createFullBoxCtor("sthd", "SubtitleMediaHeaderBox"),
|
|
2563
|
+
BoxParser.createFullBoxCtor("stri", "SubTrackInformationBox",
|
|
2564
|
+
function(t) {
|
|
2565
|
+
this.switch_group = t.readUint16(),
|
|
2566
|
+
this.alternate_group = t.readUint16(),
|
|
2567
|
+
this.sub_track_id = t.readUint32();
|
|
2568
|
+
var e = (this.size - this.hdr_size - 8) / 4;
|
|
2569
|
+
this.attribute_list = [];
|
|
2570
|
+
for (var i = 0; i < e; i++) this.attribute_list[i] = t.readUint32()
|
|
2571
|
+
}),
|
|
2572
|
+
BoxParser.createFullBoxCtor("stsc", "SampleToChunkBox",
|
|
2573
|
+
function(t) {
|
|
2574
|
+
var e, i = t.readUint32();
|
|
2575
|
+
if (this.first_chunk = [], this.samples_per_chunk = [], this.sample_description_index = [], 0 === this.version) for (e = 0; e < i; e++) this.first_chunk.push(t.readUint32()),
|
|
2576
|
+
this.samples_per_chunk.push(t.readUint32()),
|
|
2577
|
+
this.sample_description_index.push(t.readUint32())
|
|
2578
|
+
}),
|
|
2579
|
+
BoxParser.createFullBoxCtor("stsd", "SampleDescriptionBox",
|
|
2580
|
+
function(t) {
|
|
2581
|
+
var e, i, r, s;
|
|
2582
|
+
for (this.entries = [], r = t.readUint32(), e = 1; e <= r; e++) {
|
|
2583
|
+
if ((i = BoxParser.parseOneBox(t, !0, this.size - (t.getPosition() - this.start))).code !== BoxParser.OK) return;
|
|
2584
|
+
BoxParser[i.type + "SampleEntry"] ? ((s = new BoxParser[i.type + "SampleEntry"](i.size)).hdr_size = i.hdr_size, s.start = i.start) : (Log.warn("BoxParser", "Unknown sample entry type: " + i.type), s = new BoxParser.SampleEntry(i.type, i.size, i.hdr_size, i.start)),
|
|
2585
|
+
s.write === BoxParser.SampleEntry.prototype.write && (Log.info("BoxParser", "SampleEntry " + s.type + " box writing not yet implemented, keeping unparsed data in memory for later write"), s.parseDataAndRewind(t)),
|
|
2586
|
+
s.parse(t),
|
|
2587
|
+
this.entries.push(s)
|
|
2588
|
+
}
|
|
2589
|
+
}),
|
|
2590
|
+
BoxParser.createFullBoxCtor("stsg", "SubTrackSampleGroupBox",
|
|
2591
|
+
function(t) {
|
|
2592
|
+
this.grouping_type = t.readUint32();
|
|
2593
|
+
var e = t.readUint16();
|
|
2594
|
+
this.group_description_index = [];
|
|
2595
|
+
for (var i = 0; i < e; i++) this.group_description_index[i] = t.readUint32()
|
|
2596
|
+
}),
|
|
2597
|
+
BoxParser.createFullBoxCtor("stsh", "ShadowSyncSampleBox",
|
|
2598
|
+
function(t) {
|
|
2599
|
+
var e, i = t.readUint32();
|
|
2600
|
+
if (this.shadowed_sample_numbers = [], this.sync_sample_numbers = [], 0 === this.version) for (e = 0; e < i; e++) this.shadowed_sample_numbers.push(t.readUint32()),
|
|
2601
|
+
this.sync_sample_numbers.push(t.readUint32())
|
|
2602
|
+
}),
|
|
2603
|
+
BoxParser.createFullBoxCtor("stss", "SyncSampleBox",
|
|
2604
|
+
function(t) {
|
|
2605
|
+
var e, i = t.readUint32();
|
|
2606
|
+
if (0 === this.version) for (this.sample_numbers = [], e = 0; e < i; e++) this.sample_numbers.push(t.readUint32())
|
|
2607
|
+
}),
|
|
2608
|
+
BoxParser.createFullBoxCtor("stsz", "SampleSizeBox",
|
|
2609
|
+
function(t) {
|
|
2610
|
+
var e;
|
|
2611
|
+
if (this.sample_sizes = [], 0 === this.version) for (this.sample_size = t.readUint32(), this.sample_count = t.readUint32(), e = 0; e < this.sample_count; e++) 0 === this.sample_size ? this.sample_sizes.push(t.readUint32()) : this.sample_sizes[e] = this.sample_size
|
|
2612
|
+
}),
|
|
2613
|
+
BoxParser.createFullBoxCtor("stts", "TimeToSampleBox",
|
|
2614
|
+
function(t) {
|
|
2615
|
+
var e, i, r = t.readUint32();
|
|
2616
|
+
if (this.sample_counts = [], this.sample_deltas = [], 0 === this.version) for (e = 0; e < r; e++) this.sample_counts.push(t.readUint32()),
|
|
2617
|
+
(i = t.readInt32()) < 0 && (Log.warn("BoxParser", "File uses negative stts sample delta, using value 1 instead, sync may be lost!"), i = 1),
|
|
2618
|
+
this.sample_deltas.push(i)
|
|
2619
|
+
}),
|
|
2620
|
+
BoxParser.createFullBoxCtor("stvi", "StereoVideoBox",
|
|
2621
|
+
function(t) {
|
|
2622
|
+
var e = t.readUint32();
|
|
2623
|
+
this.single_view_allowed = 3 & e,
|
|
2624
|
+
this.stereo_scheme = t.readUint32();
|
|
2625
|
+
var i, e = t.readUint32();
|
|
2626
|
+
for (this.stereo_indication_type = t.readString(e), this.boxes = []; t.getPosition() < this.start + this.size;) {
|
|
2627
|
+
if ((i = BoxParser.parseOneBox(t, !1, this.size - (t.getPosition() - this.start))).code !== BoxParser.OK) return;
|
|
2628
|
+
i = i.box,
|
|
2629
|
+
this.boxes.push(i),
|
|
2630
|
+
this[i.type] = i
|
|
2631
|
+
}
|
|
2632
|
+
}),
|
|
2633
|
+
BoxParser.createBoxCtor("styp", "SegmentTypeBox",
|
|
2634
|
+
function(t) {
|
|
2635
|
+
BoxParser.ftypBox.prototype.parse.call(this, t)
|
|
2636
|
+
}),
|
|
2637
|
+
BoxParser.createFullBoxCtor("stz2", "CompactSampleSizeBox",
|
|
2638
|
+
function(t) {
|
|
2639
|
+
var e, i;
|
|
2640
|
+
if (this.sample_sizes = [], 0 === this.version) if (this.reserved = t.readUint24(), this.field_size = t.readUint8(), i = t.readUint32(), 4 === this.field_size) for (e = 0; e < i; e += 2) {
|
|
2641
|
+
var r = t.readUint8();
|
|
2642
|
+
this.sample_sizes[e] = r >> 4 & 15,
|
|
2643
|
+
this.sample_sizes[e + 1] = 15 & r
|
|
2644
|
+
} else if (8 === this.field_size) for (e = 0; e < i; e++) this.sample_sizes[e] = t.readUint8();
|
|
2645
|
+
else if (16 === this.field_size) for (e = 0; e < i; e++) this.sample_sizes[e] = t.readUint16();
|
|
2646
|
+
else Log.error("BoxParser", "Error in length field in stz2 box")
|
|
2647
|
+
}),
|
|
2648
|
+
BoxParser.createFullBoxCtor("subs", "SubSampleInformationBox",
|
|
2649
|
+
function(t) {
|
|
2650
|
+
var e, i, r, s = t.readUint32();
|
|
2651
|
+
for (this.entries = [], e = 0; e < s; e++) {
|
|
2652
|
+
var a = {};
|
|
2653
|
+
if ((this.entries[e] = a).sample_delta = t.readUint32(), a.subsamples = [], 0 < (r = t.readUint16())) for (i = 0; i < r; i++) {
|
|
2654
|
+
var n = {};
|
|
2655
|
+
a.subsamples.push(n),
|
|
2656
|
+
1 == this.version ? n.size = t.readUint32() : n.size = t.readUint16(),
|
|
2657
|
+
n.priority = t.readUint8(),
|
|
2658
|
+
n.discardable = t.readUint8(),
|
|
2659
|
+
n.codec_specific_parameters = t.readUint32()
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
}),
|
|
2663
|
+
BoxParser.createFullBoxCtor("tenc", "TrackEncryptionBox",
|
|
2664
|
+
function(t) {
|
|
2665
|
+
var e;
|
|
2666
|
+
t.readUint8(),
|
|
2667
|
+
0 === this.version ? t.readUint8() : (e = t.readUint8(), this.default_crypt_byte_block = e >> 4 & 15, this.default_skip_byte_block = 15 & e),
|
|
2668
|
+
this.default_isProtected = t.readUint8(),
|
|
2669
|
+
this.default_Per_Sample_IV_Size = t.readUint8(),
|
|
2670
|
+
this.default_KID = BoxParser.parseHex16(t),
|
|
2671
|
+
1 === this.default_isProtected && 0 === this.default_Per_Sample_IV_Size && (this.default_constant_IV_size = t.readUint8(), this.default_constant_IV = t.readUint8Array(this.default_constant_IV_size))
|
|
2672
|
+
}),
|
|
2673
|
+
BoxParser.createFullBoxCtor("tfdt", "TrackFragmentBaseMediaDecodeTimeBox",
|
|
2674
|
+
function(t) {
|
|
2675
|
+
1 == this.version ? this.baseMediaDecodeTime = t.readUint64() : this.baseMediaDecodeTime = t.readUint32()
|
|
2676
|
+
}),
|
|
2677
|
+
BoxParser.createFullBoxCtor("tfhd", "TrackFragmentHeaderBox",
|
|
2678
|
+
function(t) {
|
|
2679
|
+
var e = 0;
|
|
2680
|
+
this.track_id = t.readUint32(),
|
|
2681
|
+
this.size - this.hdr_size > e && this.flags & BoxParser.TFHD_FLAG_BASE_DATA_OFFSET ? (this.base_data_offset = t.readUint64(), e += 8) : this.base_data_offset = 0,
|
|
2682
|
+
this.size - this.hdr_size > e && this.flags & BoxParser.TFHD_FLAG_SAMPLE_DESC ? (this.default_sample_description_index = t.readUint32(), e += 4) : this.default_sample_description_index = 0,
|
|
2683
|
+
this.size - this.hdr_size > e && this.flags & BoxParser.TFHD_FLAG_SAMPLE_DUR ? (this.default_sample_duration = t.readUint32(), e += 4) : this.default_sample_duration = 0,
|
|
2684
|
+
this.size - this.hdr_size > e && this.flags & BoxParser.TFHD_FLAG_SAMPLE_SIZE ? (this.default_sample_size = t.readUint32(), e += 4) : this.default_sample_size = 0,
|
|
2685
|
+
this.size - this.hdr_size > e && this.flags & BoxParser.TFHD_FLAG_SAMPLE_FLAGS ? (this.default_sample_flags = t.readUint32(), e += 4) : this.default_sample_flags = 0
|
|
2686
|
+
}),
|
|
2687
|
+
BoxParser.createFullBoxCtor("tfra", "TrackFragmentRandomAccessBox",
|
|
2688
|
+
function(t) {
|
|
2689
|
+
this.track_ID = t.readUint32(),
|
|
2690
|
+
t.readUint24();
|
|
2691
|
+
var e = t.readUint8();
|
|
2692
|
+
this.length_size_of_traf_num = e >> 4 & 3,
|
|
2693
|
+
this.length_size_of_trun_num = e >> 2 & 3,
|
|
2694
|
+
this.length_size_of_sample_num = 3 & e,
|
|
2695
|
+
this.entries = [];
|
|
2696
|
+
for (var i = t.readUint32(), r = 0; r < i; r++) 1 === this.version ? (this.time = t.readUint64(), this.moof_offset = t.readUint64()) : (this.time = t.readUint32(), this.moof_offset = t.readUint32()),
|
|
2697
|
+
this.traf_number = t["readUint" + 8 * (this.length_size_of_traf_num + 1)](),
|
|
2698
|
+
this.trun_number = t["readUint" + 8 * (this.length_size_of_trun_num + 1)](),
|
|
2699
|
+
this.sample_number = t["readUint" + 8 * (this.length_size_of_sample_num + 1)]()
|
|
2700
|
+
}),
|
|
2701
|
+
BoxParser.createFullBoxCtor("tkhd", "TrackHeaderBox",
|
|
2702
|
+
function(t) {
|
|
2703
|
+
1 == this.version ? (this.creation_time = t.readUint64(), this.modification_time = t.readUint64(), this.track_id = t.readUint32(), t.readUint32(), this.duration = t.readUint64()) : (this.creation_time = t.readUint32(), this.modification_time = t.readUint32(), this.track_id = t.readUint32(), t.readUint32(), this.duration = t.readUint32()),
|
|
2704
|
+
t.readUint32Array(2),
|
|
2705
|
+
this.layer = t.readInt16(),
|
|
2706
|
+
this.alternate_group = t.readInt16(),
|
|
2707
|
+
this.volume = t.readInt16() >> 8,
|
|
2708
|
+
t.readUint16(),
|
|
2709
|
+
this.matrix = t.readInt32Array(9),
|
|
2710
|
+
this.width = t.readUint32(),
|
|
2711
|
+
this.height = t.readUint32()
|
|
2712
|
+
}),
|
|
2713
|
+
BoxParser.createBoxCtor("tmax", "hintmaxrelativetime",
|
|
2714
|
+
function(t) {
|
|
2715
|
+
this.time = t.readUint32()
|
|
2716
|
+
}),
|
|
2717
|
+
BoxParser.createBoxCtor("tmin", "hintminrelativetime",
|
|
2718
|
+
function(t) {
|
|
2719
|
+
this.time = t.readUint32()
|
|
2720
|
+
}),
|
|
2721
|
+
BoxParser.createBoxCtor("totl", "hintBytesSent",
|
|
2722
|
+
function(t) {
|
|
2723
|
+
this.bytessent = t.readUint32()
|
|
2724
|
+
}),
|
|
2725
|
+
BoxParser.createBoxCtor("tpay", "hintBytesSent",
|
|
2726
|
+
function(t) {
|
|
2727
|
+
this.bytessent = t.readUint32()
|
|
2728
|
+
}),
|
|
2729
|
+
BoxParser.createBoxCtor("tpyl", "hintBytesSent",
|
|
2730
|
+
function(t) {
|
|
2731
|
+
this.bytessent = t.readUint64()
|
|
2732
|
+
}),
|
|
2733
|
+
BoxParser.TrackGroupTypeBox.prototype.parse = function(t) {
|
|
2734
|
+
this.parseFullHeader(t),
|
|
2735
|
+
this.track_group_id = t.readUint32()
|
|
2736
|
+
},
|
|
2737
|
+
BoxParser.createTrackGroupCtor("msrc"),
|
|
2738
|
+
BoxParser.TrackReferenceTypeBox = function(t, e, i, r) {
|
|
2739
|
+
BoxParser.Box.call(this, t, e),
|
|
2740
|
+
this.hdr_size = i,
|
|
2741
|
+
this.start = r
|
|
2742
|
+
},
|
|
2743
|
+
BoxParser.TrackReferenceTypeBox.prototype = new BoxParser.Box,
|
|
2744
|
+
BoxParser.TrackReferenceTypeBox.prototype.parse = function(t) {
|
|
2745
|
+
this.track_ids = t.readUint32Array((this.size - this.hdr_size) / 4)
|
|
2746
|
+
},
|
|
2747
|
+
BoxParser.trefBox.prototype.parse = function(t) {
|
|
2748
|
+
for (var e; t.getPosition() < this.start + this.size;) {
|
|
2749
|
+
if ((e = BoxParser.parseOneBox(t, !0, this.size - (t.getPosition() - this.start))).code !== BoxParser.OK) return; (e = new BoxParser.TrackReferenceTypeBox(e.type, e.size, e.hdr_size, e.start)).write === BoxParser.Box.prototype.write && "mdat" !== e.type && (Log.info("BoxParser", "TrackReference " + e.type + " box writing not yet implemented, keeping unparsed data in memory for later write"), e.parseDataAndRewind(t)),
|
|
2750
|
+
e.parse(t),
|
|
2751
|
+
this.boxes.push(e)
|
|
2752
|
+
}
|
|
2753
|
+
},
|
|
2754
|
+
BoxParser.createFullBoxCtor("trep", "TrackExtensionPropertiesBox",
|
|
2755
|
+
function(t) {
|
|
2756
|
+
for (this.track_ID = t.readUint32(), this.boxes = []; t.getPosition() < this.start + this.size;) {
|
|
2757
|
+
if (ret = BoxParser.parseOneBox(t, !1, this.size - (t.getPosition() - this.start)), ret.code !== BoxParser.OK) return;
|
|
2758
|
+
box = ret.box,
|
|
2759
|
+
this.boxes.push(box)
|
|
2760
|
+
}
|
|
2761
|
+
}),
|
|
2762
|
+
BoxParser.createFullBoxCtor("trex", "TrackExtendsBox",
|
|
2763
|
+
function(t) {
|
|
2764
|
+
this.track_id = t.readUint32(),
|
|
2765
|
+
this.default_sample_description_index = t.readUint32(),
|
|
2766
|
+
this.default_sample_duration = t.readUint32(),
|
|
2767
|
+
this.default_sample_size = t.readUint32(),
|
|
2768
|
+
this.default_sample_flags = t.readUint32()
|
|
2769
|
+
}),
|
|
2770
|
+
BoxParser.createBoxCtor("trpy", "hintBytesSent",
|
|
2771
|
+
function(t) {
|
|
2772
|
+
this.bytessent = t.readUint64()
|
|
2773
|
+
}),
|
|
2774
|
+
BoxParser.createFullBoxCtor("trun", "TrackRunBox",
|
|
2775
|
+
function(t) {
|
|
2776
|
+
var e = 0;
|
|
2777
|
+
if (this.sample_count = t.readUint32(), e += 4, this.size - this.hdr_size > e && this.flags & BoxParser.TRUN_FLAGS_DATA_OFFSET ? (this.data_offset = t.readInt32(), e += 4) : this.data_offset = 0, this.size - this.hdr_size > e && this.flags & BoxParser.TRUN_FLAGS_FIRST_FLAG ? (this.first_sample_flags = t.readUint32(), e += 4) : this.first_sample_flags = 0, this.sample_duration = [], this.sample_size = [], this.sample_flags = [], this.sample_composition_time_offset = [], this.size - this.hdr_size > e) for (var i = 0; i < this.sample_count; i++) this.flags & BoxParser.TRUN_FLAGS_DURATION && (this.sample_duration[i] = t.readUint32()),
|
|
2778
|
+
this.flags & BoxParser.TRUN_FLAGS_SIZE && (this.sample_size[i] = t.readUint32()),
|
|
2779
|
+
this.flags & BoxParser.TRUN_FLAGS_FLAGS && (this.sample_flags[i] = t.readUint32()),
|
|
2780
|
+
this.flags & BoxParser.TRUN_FLAGS_CTS_OFFSET && (0 === this.version ? this.sample_composition_time_offset[i] = t.readUint32() : this.sample_composition_time_offset[i] = t.readInt32())
|
|
2781
|
+
}),
|
|
2782
|
+
BoxParser.createFullBoxCtor("tsel", "TrackSelectionBox",
|
|
2783
|
+
function(t) {
|
|
2784
|
+
this.switch_group = t.readUint32();
|
|
2785
|
+
var e = (this.size - this.hdr_size - 4) / 4;
|
|
2786
|
+
this.attribute_list = [];
|
|
2787
|
+
for (var i = 0; i < e; i++) this.attribute_list[i] = t.readUint32()
|
|
2788
|
+
}),
|
|
2789
|
+
BoxParser.createFullBoxCtor("txtC", "TextConfigBox",
|
|
2790
|
+
function(t) {
|
|
2791
|
+
this.config = t.readCString()
|
|
2792
|
+
}),
|
|
2793
|
+
BoxParser.createBoxCtor("tyco", "TypeCombinationBox",
|
|
2794
|
+
function(t) {
|
|
2795
|
+
var e = (this.size - this.hdr_size) / 4;
|
|
2796
|
+
this.compatible_brands = [];
|
|
2797
|
+
for (var i = 0; i < e; i++) this.compatible_brands[i] = t.readString(4)
|
|
2798
|
+
}),
|
|
2799
|
+
BoxParser.createFullBoxCtor("udes", "UserDescriptionProperty",
|
|
2800
|
+
function(t) {
|
|
2801
|
+
this.lang = t.readCString(),
|
|
2802
|
+
this.name = t.readCString(),
|
|
2803
|
+
this.description = t.readCString(),
|
|
2804
|
+
this.tags = t.readCString()
|
|
2805
|
+
}),
|
|
2806
|
+
BoxParser.createFullBoxCtor("uncC", "UncompressedFrameConfigBox",
|
|
2807
|
+
function(t) {
|
|
2808
|
+
var e;
|
|
2809
|
+
if (this.profile = t.readString(4), 1 != this.version && 0 == this.version) {
|
|
2810
|
+
for (this.component_count = t.readUint32(), this.component_index = [], this.component_bit_depth_minus_one = [], this.component_format = [], this.component_align_size = [], e = 0; e < this.component_count; e++) this.component_index.push(t.readUint16()),
|
|
2811
|
+
this.component_bit_depth_minus_one.push(t.readUint8()),
|
|
2812
|
+
this.component_format.push(t.readUint8()),
|
|
2813
|
+
this.component_align_size.push(t.readUint8());
|
|
2814
|
+
this.sampling_type = t.readUint8(),
|
|
2815
|
+
this.interleave_type = t.readUint8(),
|
|
2816
|
+
this.block_size = t.readUint8();
|
|
2817
|
+
var i = t.readUint8();
|
|
2818
|
+
this.component_little_endian = i >> 7 & 1,
|
|
2819
|
+
this.block_pad_lsb = i >> 6 & 1,
|
|
2820
|
+
this.block_little_endian = i >> 5 & 1,
|
|
2821
|
+
this.block_reversed = i >> 4 & 1,
|
|
2822
|
+
this.pad_unknown = i >> 3 & 1,
|
|
2823
|
+
this.pixel_size = t.readUint32(),
|
|
2824
|
+
this.row_align_size = t.readUint32(),
|
|
2825
|
+
this.tile_align_size = t.readUint32(),
|
|
2826
|
+
this.num_tile_cols_minus_one = t.readUint32(),
|
|
2827
|
+
this.num_tile_rows_minus_one = t.readUint32()
|
|
2828
|
+
}
|
|
2829
|
+
}),
|
|
2830
|
+
BoxParser.createFullBoxCtor("url ", "DataEntryUrlBox",
|
|
2831
|
+
function(t) {
|
|
2832
|
+
1 !== this.flags && (this.location = t.readCString())
|
|
2833
|
+
}),
|
|
2834
|
+
BoxParser.createFullBoxCtor("urn ", "DataEntryUrnBox",
|
|
2835
|
+
function(t) {
|
|
2836
|
+
this.name = t.readCString(),
|
|
2837
|
+
0 < this.size - this.hdr_size - this.name.length - 1 && (this.location = t.readCString())
|
|
2838
|
+
}),
|
|
2839
|
+
BoxParser.createUUIDBox("a5d40b30e81411ddba2f0800200c9a66", "LiveServerManifestBox", !0, !1,
|
|
2840
|
+
function(t) {
|
|
2841
|
+
this.LiveServerManifest = t.readString(this.size - this.hdr_size).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'")
|
|
2842
|
+
}),
|
|
2843
|
+
BoxParser.createUUIDBox("d08a4f1810f34a82b6c832d8aba183d3", "PiffProtectionSystemSpecificHeaderBox", !0, !1,
|
|
2844
|
+
function(t) {
|
|
2845
|
+
this.system_id = BoxParser.parseHex16(t);
|
|
2846
|
+
var e = t.readUint32();
|
|
2847
|
+
0 < e && (this.data = t.readUint8Array(e))
|
|
2848
|
+
}),
|
|
2849
|
+
BoxParser.createUUIDBox("a2394f525a9b4f14a2446c427c648df4", "PiffSampleEncryptionBox", !0, !1),
|
|
2850
|
+
BoxParser.createUUIDBox("8974dbce7be74c5184f97148f9882554", "PiffTrackEncryptionBox", !0, !1,
|
|
2851
|
+
function(t) {
|
|
2852
|
+
this.default_AlgorithmID = t.readUint24(),
|
|
2853
|
+
this.default_IV_size = t.readUint8(),
|
|
2854
|
+
this.default_KID = BoxParser.parseHex16(t)
|
|
2855
|
+
}),
|
|
2856
|
+
BoxParser.createUUIDBox("d4807ef2ca3946958e5426cb9e46a79f", "TfrfBox", !0, !1,
|
|
2857
|
+
function(t) {
|
|
2858
|
+
this.fragment_count = t.readUint8(),
|
|
2859
|
+
this.entries = [];
|
|
2860
|
+
for (var e = 0; e < this.fragment_count; e++) {
|
|
2861
|
+
var i = {},
|
|
2862
|
+
r = 0,
|
|
2863
|
+
s = 0,
|
|
2864
|
+
s = 1 === this.version ? (r = t.readUint64(), t.readUint64()) : (r = t.readUint32(), t.readUint32());
|
|
2865
|
+
i.absolute_time = r,
|
|
2866
|
+
i.absolute_duration = s,
|
|
2867
|
+
this.entries.push(i)
|
|
2868
|
+
}
|
|
2869
|
+
}),
|
|
2870
|
+
BoxParser.createUUIDBox("6d1d9b0542d544e680e2141daff757b2", "TfxdBox", !0, !1,
|
|
2871
|
+
function(t) {
|
|
2872
|
+
1 === this.version ? (this.absolute_time = t.readUint64(), this.duration = t.readUint64()) : (this.absolute_time = t.readUint32(), this.duration = t.readUint32())
|
|
2873
|
+
}),
|
|
2874
|
+
BoxParser.createFullBoxCtor("vmhd", "VideoMediaHeaderBox",
|
|
2875
|
+
function(t) {
|
|
2876
|
+
this.graphicsmode = t.readUint16(),
|
|
2877
|
+
this.opcolor = t.readUint16Array(3)
|
|
2878
|
+
}),
|
|
2879
|
+
BoxParser.createFullBoxCtor("vpcC", "VPCodecConfigurationRecord",
|
|
2880
|
+
function(t) {
|
|
2881
|
+
var e;
|
|
2882
|
+
1 === this.version ? (this.profile = t.readUint8(), this.level = t.readUint8(), e = t.readUint8(), this.bitDepth = e >> 4, this.chromaSubsampling = e >> 1 & 7, this.videoFullRangeFlag = 1 & e, this.colourPrimaries = t.readUint8(), this.transferCharacteristics = t.readUint8(), this.matrixCoefficients = t.readUint8()) : (this.profile = t.readUint8(), this.level = t.readUint8(), e = t.readUint8(), this.bitDepth = e >> 4 & 15, this.colorSpace = 15 & e, e = t.readUint8(), this.chromaSubsampling = e >> 4 & 15, this.transferFunction = e >> 1 & 7, this.videoFullRangeFlag = 1 & e),
|
|
2883
|
+
this.codecIntializationDataSize = t.readUint16(),
|
|
2884
|
+
this.codecIntializationData = t.readUint8Array(this.codecIntializationDataSize)
|
|
2885
|
+
}),
|
|
2886
|
+
BoxParser.createBoxCtor("vttC", "WebVTTConfigurationBox",
|
|
2887
|
+
function(t) {
|
|
2888
|
+
this.text = t.readString(this.size - this.hdr_size)
|
|
2889
|
+
}),
|
|
2890
|
+
BoxParser.createFullBoxCtor("vvcC", "VvcConfigurationBox",
|
|
2891
|
+
function(t) {
|
|
2892
|
+
var e, i = {
|
|
2893
|
+
held_bits: void 0,
|
|
2894
|
+
num_held_bits: 0,
|
|
2895
|
+
stream_read_1_bytes: function(t) {
|
|
2896
|
+
this.held_bits = t.readUint8(),
|
|
2897
|
+
this.num_held_bits = 8
|
|
2898
|
+
},
|
|
2899
|
+
stream_read_2_bytes: function(t) {
|
|
2900
|
+
this.held_bits = t.readUint16(),
|
|
2901
|
+
this.num_held_bits = 16
|
|
2902
|
+
},
|
|
2903
|
+
extract_bits: function(t) {
|
|
2904
|
+
var e = this.held_bits >> this.num_held_bits - t & (1 << t) - 1;
|
|
2905
|
+
return this.num_held_bits -= t,
|
|
2906
|
+
e
|
|
2907
|
+
}
|
|
2908
|
+
};
|
|
2909
|
+
if (i.stream_read_1_bytes(t), i.extract_bits(5), this.lengthSizeMinusOne = i.extract_bits(2), this.ptl_present_flag = i.extract_bits(1), this.ptl_present_flag) {
|
|
2910
|
+
if (i.stream_read_2_bytes(t), this.ols_idx = i.extract_bits(9), this.num_sublayers = i.extract_bits(3), this.constant_frame_rate = i.extract_bits(2), this.chroma_format_idc = i.extract_bits(2), i.stream_read_1_bytes(t), this.bit_depth_minus8 = i.extract_bits(3), i.extract_bits(5), i.stream_read_2_bytes(t), i.extract_bits(2), this.num_bytes_constraint_info = i.extract_bits(6), this.general_profile_idc = i.extract_bits(7), this.general_tier_flag = i.extract_bits(1), this.general_level_idc = t.readUint8(), i.stream_read_1_bytes(t), this.ptl_frame_only_constraint_flag = i.extract_bits(1), this.ptl_multilayer_enabled_flag = i.extract_bits(1), this.general_constraint_info = new Uint8Array(this.num_bytes_constraint_info), this.num_bytes_constraint_info) {
|
|
2911
|
+
for (o = 0; o < this.num_bytes_constraint_info - 1; o++) {
|
|
2912
|
+
var r = i.extract_bits(6);
|
|
2913
|
+
i.stream_read_1_bytes(t);
|
|
2914
|
+
var s = i.extract_bits(2);
|
|
2915
|
+
this.general_constraint_info[o] = r << 2 | s
|
|
2916
|
+
}
|
|
2917
|
+
this.general_constraint_info[this.num_bytes_constraint_info - 1] = i.extract_bits(6)
|
|
2918
|
+
} else i.extract_bits(6);
|
|
2919
|
+
if (1 < this.num_sublayers) {
|
|
2920
|
+
for (i.stream_read_1_bytes(t), this.ptl_sublayer_present_mask = 0, e = this.num_sublayers - 2; 0 <= e; --e) {
|
|
2921
|
+
var a = i.extract_bits(1);
|
|
2922
|
+
this.ptl_sublayer_present_mask |= a << e
|
|
2923
|
+
}
|
|
2924
|
+
for (e = this.num_sublayers; e <= 8 && 1 < this.num_sublayers; ++e) i.extract_bits(1);
|
|
2925
|
+
for (this.sublayer_level_idc = [], e = this.num_sublayers - 2; 0 <= e; --e) this.ptl_sublayer_present_mask & 1 << e && (this.sublayer_level_idc[e] = t.readUint8())
|
|
2926
|
+
}
|
|
2927
|
+
if (this.ptl_num_sub_profiles = t.readUint8(), this.general_sub_profile_idc = [], this.ptl_num_sub_profiles) for (o = 0; o < this.ptl_num_sub_profiles; o++) this.general_sub_profile_idc.push(t.readUint32());
|
|
2928
|
+
this.max_picture_width = t.readUint16(),
|
|
2929
|
+
this.max_picture_height = t.readUint16(),
|
|
2930
|
+
this.avg_frame_rate = t.readUint16()
|
|
2931
|
+
}
|
|
2932
|
+
this.nalu_arrays = [];
|
|
2933
|
+
for (var n = t.readUint8(), o = 0; o < n; o++) {
|
|
2934
|
+
var h = [];
|
|
2935
|
+
this.nalu_arrays.push(h),
|
|
2936
|
+
i.stream_read_1_bytes(t),
|
|
2937
|
+
h.completeness = i.extract_bits(1),
|
|
2938
|
+
i.extract_bits(2),
|
|
2939
|
+
h.nalu_type = i.extract_bits(5);
|
|
2940
|
+
var d = 1;
|
|
2941
|
+
for (13 != h.nalu_type && 12 != h.nalu_type && (d = t.readUint16()), e = 0; e < d; e++) {
|
|
2942
|
+
var l = t.readUint16();
|
|
2943
|
+
h.push({
|
|
2944
|
+
data: t.readUint8Array(l),
|
|
2945
|
+
length: l
|
|
2946
|
+
})
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
}),
|
|
2950
|
+
BoxParser.createFullBoxCtor("vvnC", "VvcNALUConfigBox",
|
|
2951
|
+
function(t) {
|
|
2952
|
+
var e = strm.readUint8();
|
|
2953
|
+
this.lengthSizeMinusOne = 3 & e
|
|
2954
|
+
}),
|
|
2955
|
+
BoxParser.SampleEntry.prototype.isVideo = function() {
|
|
2956
|
+
return ! 1
|
|
2957
|
+
},
|
|
2958
|
+
BoxParser.SampleEntry.prototype.isAudio = function() {
|
|
2959
|
+
return ! 1
|
|
2960
|
+
},
|
|
2961
|
+
BoxParser.SampleEntry.prototype.isSubtitle = function() {
|
|
2962
|
+
return ! 1
|
|
2963
|
+
},
|
|
2964
|
+
BoxParser.SampleEntry.prototype.isMetadata = function() {
|
|
2965
|
+
return ! 1
|
|
2966
|
+
},
|
|
2967
|
+
BoxParser.SampleEntry.prototype.isHint = function() {
|
|
2968
|
+
return ! 1
|
|
2969
|
+
},
|
|
2970
|
+
BoxParser.SampleEntry.prototype.getCodec = function() {
|
|
2971
|
+
return this.type.replace(".", "")
|
|
2972
|
+
},
|
|
2973
|
+
BoxParser.SampleEntry.prototype.getWidth = function() {
|
|
2974
|
+
return ""
|
|
2975
|
+
},
|
|
2976
|
+
BoxParser.SampleEntry.prototype.getHeight = function() {
|
|
2977
|
+
return ""
|
|
2978
|
+
},
|
|
2979
|
+
BoxParser.SampleEntry.prototype.getChannelCount = function() {
|
|
2980
|
+
return ""
|
|
2981
|
+
},
|
|
2982
|
+
BoxParser.SampleEntry.prototype.getSampleRate = function() {
|
|
2983
|
+
return ""
|
|
2984
|
+
},
|
|
2985
|
+
BoxParser.SampleEntry.prototype.getSampleSize = function() {
|
|
2986
|
+
return ""
|
|
2987
|
+
},
|
|
2988
|
+
BoxParser.VisualSampleEntry.prototype.isVideo = function() {
|
|
2989
|
+
return ! 0
|
|
2990
|
+
},
|
|
2991
|
+
BoxParser.VisualSampleEntry.prototype.getWidth = function() {
|
|
2992
|
+
return this.width
|
|
2993
|
+
},
|
|
2994
|
+
BoxParser.VisualSampleEntry.prototype.getHeight = function() {
|
|
2995
|
+
return this.height
|
|
2996
|
+
},
|
|
2997
|
+
BoxParser.AudioSampleEntry.prototype.isAudio = function() {
|
|
2998
|
+
return ! 0
|
|
2999
|
+
},
|
|
3000
|
+
BoxParser.AudioSampleEntry.prototype.getChannelCount = function() {
|
|
3001
|
+
return this.channel_count
|
|
3002
|
+
},
|
|
3003
|
+
BoxParser.AudioSampleEntry.prototype.getSampleRate = function() {
|
|
3004
|
+
return this.samplerate
|
|
3005
|
+
},
|
|
3006
|
+
BoxParser.AudioSampleEntry.prototype.getSampleSize = function() {
|
|
3007
|
+
return this.samplesize
|
|
3008
|
+
},
|
|
3009
|
+
BoxParser.SubtitleSampleEntry.prototype.isSubtitle = function() {
|
|
3010
|
+
return ! 0
|
|
3011
|
+
},
|
|
3012
|
+
BoxParser.MetadataSampleEntry.prototype.isMetadata = function() {
|
|
3013
|
+
return ! 0
|
|
3014
|
+
},
|
|
3015
|
+
BoxParser.decimalToHex = function(t, e) {
|
|
3016
|
+
var i = Number(t).toString(16);
|
|
3017
|
+
for (e = null == e ? e = 2 : e; i.length < e;) i = "0" + i;
|
|
3018
|
+
return i
|
|
3019
|
+
},
|
|
3020
|
+
BoxParser.avc1SampleEntry.prototype.getCodec = BoxParser.avc2SampleEntry.prototype.getCodec = BoxParser.avc3SampleEntry.prototype.getCodec = BoxParser.avc4SampleEntry.prototype.getCodec = function() {
|
|
3021
|
+
var t = BoxParser.SampleEntry.prototype.getCodec.call(this);
|
|
3022
|
+
return this.avcC ? t + "." + BoxParser.decimalToHex(this.avcC.AVCProfileIndication) + BoxParser.decimalToHex(this.avcC.profile_compatibility) + BoxParser.decimalToHex(this.avcC.AVCLevelIndication) : t
|
|
3023
|
+
},
|
|
3024
|
+
BoxParser.hev1SampleEntry.prototype.getCodec = BoxParser.hvc1SampleEntry.prototype.getCodec = function() {
|
|
3025
|
+
var t = BoxParser.SampleEntry.prototype.getCodec.call(this);
|
|
3026
|
+
if (this.hvcC) {
|
|
3027
|
+
switch (t += ".", this.hvcC.general_profile_space) {
|
|
3028
|
+
case 0:
|
|
3029
|
+
t += "";
|
|
3030
|
+
break;
|
|
3031
|
+
case 1:
|
|
3032
|
+
t += "A";
|
|
3033
|
+
break;
|
|
3034
|
+
case 2:
|
|
3035
|
+
t += "B";
|
|
3036
|
+
break;
|
|
3037
|
+
case 3:
|
|
3038
|
+
t += "C"
|
|
3039
|
+
}
|
|
3040
|
+
t += this.hvcC.general_profile_idc,
|
|
3041
|
+
t += ".";
|
|
3042
|
+
for (var e = this.hvcC.general_profile_compatibility,
|
|
3043
|
+
i = 0,
|
|
3044
|
+
r = 0; r < 32 && (i |= 1 & e, 31 != r); r++) i <<= 1,
|
|
3045
|
+
e >>= 1;
|
|
3046
|
+
t += BoxParser.decimalToHex(i, 0),
|
|
3047
|
+
t += ".",
|
|
3048
|
+
0 === this.hvcC.general_tier_flag ? t += "L": t += "H",
|
|
3049
|
+
t += this.hvcC.general_level_idc;
|
|
3050
|
+
var s = !1,
|
|
3051
|
+
a = "";
|
|
3052
|
+
for (r = 5; 0 <= r; r--)(this.hvcC.general_constraint_indicator[r] || s) && (a = "." + BoxParser.decimalToHex(this.hvcC.general_constraint_indicator[r], 0) + a, s = !0);
|
|
3053
|
+
t += a
|
|
3054
|
+
}
|
|
3055
|
+
return t
|
|
3056
|
+
},
|
|
3057
|
+
BoxParser.vvc1SampleEntry.prototype.getCodec = BoxParser.vvi1SampleEntry.prototype.getCodec = function() {
|
|
3058
|
+
var t = BoxParser.SampleEntry.prototype.getCodec.call(this);
|
|
3059
|
+
if (this.vvcC) {
|
|
3060
|
+
t += "." + this.vvcC.general_profile_idc,
|
|
3061
|
+
this.vvcC.general_tier_flag ? t += ".H": t += ".L",
|
|
3062
|
+
t += this.vvcC.general_level_idc;
|
|
3063
|
+
var e = "";
|
|
3064
|
+
if (this.vvcC.general_constraint_info) {
|
|
3065
|
+
var i, r = [],
|
|
3066
|
+
s = 0;
|
|
3067
|
+
for (s |= this.vvcC.ptl_frame_only_constraint << 7, s |= this.vvcC.ptl_multilayer_enabled << 6, h = 0; h < this.vvcC.general_constraint_info.length; ++h) s |= this.vvcC.general_constraint_info[h] >> 2 & 63,
|
|
3068
|
+
r.push(s),
|
|
3069
|
+
s && (i = h),
|
|
3070
|
+
s = this.vvcC.general_constraint_info[h] >> 2 & 3;
|
|
3071
|
+
if (void 0 === i) e = ".CA";
|
|
3072
|
+
else {
|
|
3073
|
+
e = ".C";
|
|
3074
|
+
for (var a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
|
|
3075
|
+
n = 0,
|
|
3076
|
+
o = 0,
|
|
3077
|
+
h = 0; h <= i; ++h) for (n = n << 8 | r[h], o += 8; 5 <= o;) e += a[n >> o - 5 & 31],
|
|
3078
|
+
n &= (1 << (o -= 5)) - 1;
|
|
3079
|
+
o && (e += a[31 & (n <<= 5 - o)])
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
t += e
|
|
3083
|
+
}
|
|
3084
|
+
return t
|
|
3085
|
+
},
|
|
3086
|
+
BoxParser.mp4aSampleEntry.prototype.getCodec = function() {
|
|
3087
|
+
var t = BoxParser.SampleEntry.prototype.getCodec.call(this);
|
|
3088
|
+
if (this.esds && this.esds.esd) {
|
|
3089
|
+
var e = this.esds.esd.getOTI(),
|
|
3090
|
+
i = this.esds.esd.getAudioConfig();
|
|
3091
|
+
return t + "." + BoxParser.decimalToHex(e) + (i ? "." + i: "")
|
|
3092
|
+
}
|
|
3093
|
+
return t
|
|
3094
|
+
},
|
|
3095
|
+
BoxParser.stxtSampleEntry.prototype.getCodec = function() {
|
|
3096
|
+
var t = BoxParser.SampleEntry.prototype.getCodec.call(this);
|
|
3097
|
+
return this.mime_format ? t + "." + this.mime_format: t
|
|
3098
|
+
},
|
|
3099
|
+
BoxParser.vp08SampleEntry.prototype.getCodec = BoxParser.vp09SampleEntry.prototype.getCodec = function() {
|
|
3100
|
+
var t = BoxParser.SampleEntry.prototype.getCodec.call(this),
|
|
3101
|
+
e = this.vpcC.level;
|
|
3102
|
+
0 == e && (e = "00");
|
|
3103
|
+
var i = this.vpcC.bitDepth;
|
|
3104
|
+
return 8 == i && (i = "08"),
|
|
3105
|
+
t + ".0" + this.vpcC.profile + "." + e + "." + i
|
|
3106
|
+
},
|
|
3107
|
+
BoxParser.av01SampleEntry.prototype.getCodec = function() {
|
|
3108
|
+
var t, e = BoxParser.SampleEntry.prototype.getCodec.call(this),
|
|
3109
|
+
i = this.av1C.seq_level_idx_0;
|
|
3110
|
+
return i < 10 && (i = "0" + i),
|
|
3111
|
+
2 === this.av1C.seq_profile && 1 === this.av1C.high_bitdepth ? t = 1 === this.av1C.twelve_bit ? "12": "10": this.av1C.seq_profile <= 2 && (t = 1 === this.av1C.high_bitdepth ? "10": "08"),
|
|
3112
|
+
e + "." + this.av1C.seq_profile + "." + i + (this.av1C.seq_tier_0 ? "H": "M") + "." + t
|
|
3113
|
+
},
|
|
3114
|
+
BoxParser.Box.prototype.writeHeader = function(t, e) {
|
|
3115
|
+
this.size += 8,
|
|
3116
|
+
this.size > MAX_SIZE && (this.size += 8),
|
|
3117
|
+
"uuid" === this.type && (this.size += 16),
|
|
3118
|
+
Log.debug("BoxWriter", "Writing box " + this.type + " of size: " + this.size + " at position " + t.getPosition() + (e || "")),
|
|
3119
|
+
this.size > MAX_SIZE ? t.writeUint32(1) : (this.sizePosition = t.getPosition(), t.writeUint32(this.size)),
|
|
3120
|
+
t.writeString(this.type, null, 4),
|
|
3121
|
+
"uuid" === this.type && t.writeUint8Array(this.uuid),
|
|
3122
|
+
this.size > MAX_SIZE && t.writeUint64(this.size)
|
|
3123
|
+
},
|
|
3124
|
+
BoxParser.FullBox.prototype.writeHeader = function(t) {
|
|
3125
|
+
this.size += 4,
|
|
3126
|
+
BoxParser.Box.prototype.writeHeader.call(this, t, " v=" + this.version + " f=" + this.flags),
|
|
3127
|
+
t.writeUint8(this.version),
|
|
3128
|
+
t.writeUint24(this.flags)
|
|
3129
|
+
},
|
|
3130
|
+
BoxParser.Box.prototype.write = function(t) {
|
|
3131
|
+
"mdat" === this.type ? this.data && (this.size = this.data.length, this.writeHeader(t), t.writeUint8Array(this.data)) : (this.size = this.data ? this.data.length: 0, this.writeHeader(t), this.data && t.writeUint8Array(this.data))
|
|
3132
|
+
},
|
|
3133
|
+
BoxParser.ContainerBox.prototype.write = function(t) {
|
|
3134
|
+
this.size = 0,
|
|
3135
|
+
this.writeHeader(t);
|
|
3136
|
+
for (var e = 0; e < this.boxes.length; e++) this.boxes[e] && (this.boxes[e].write(t), this.size += this.boxes[e].size);
|
|
3137
|
+
Log.debug("BoxWriter", "Adjusting box " + this.type + " with new size " + this.size),
|
|
3138
|
+
t.adjustUint32(this.sizePosition, this.size)
|
|
3139
|
+
},
|
|
3140
|
+
BoxParser.TrackReferenceTypeBox.prototype.write = function(t) {
|
|
3141
|
+
this.size = 4 * this.track_ids.length,
|
|
3142
|
+
this.writeHeader(t),
|
|
3143
|
+
t.writeUint32Array(this.track_ids)
|
|
3144
|
+
},
|
|
3145
|
+
BoxParser.avcCBox.prototype.write = function(t) {
|
|
3146
|
+
var e;
|
|
3147
|
+
for (this.size = 7, e = 0; e < this.SPS.length; e++) this.size += 2 + this.SPS[e].length;
|
|
3148
|
+
for (e = 0; e < this.PPS.length; e++) this.size += 2 + this.PPS[e].length;
|
|
3149
|
+
for (this.ext && (this.size += this.ext.length), this.writeHeader(t), t.writeUint8(this.configurationVersion), t.writeUint8(this.AVCProfileIndication), t.writeUint8(this.profile_compatibility), t.writeUint8(this.AVCLevelIndication), t.writeUint8(this.lengthSizeMinusOne + 252), t.writeUint8(this.SPS.length + 224), e = 0; e < this.SPS.length; e++) t.writeUint16(this.SPS[e].length),
|
|
3150
|
+
t.writeUint8Array(this.SPS[e].nalu);
|
|
3151
|
+
for (t.writeUint8(this.PPS.length), e = 0; e < this.PPS.length; e++) t.writeUint16(this.PPS[e].length),
|
|
3152
|
+
t.writeUint8Array(this.PPS[e].nalu);
|
|
3153
|
+
this.ext && t.writeUint8Array(this.ext)
|
|
3154
|
+
},
|
|
3155
|
+
BoxParser.co64Box.prototype.write = function(t) {
|
|
3156
|
+
var e;
|
|
3157
|
+
for (this.version = 0, this.flags = 0, this.size = 4 + 8 * this.chunk_offsets.length, this.writeHeader(t), t.writeUint32(this.chunk_offsets.length), e = 0; e < this.chunk_offsets.length; e++) t.writeUint64(this.chunk_offsets[e])
|
|
3158
|
+
},
|
|
3159
|
+
BoxParser.cslgBox.prototype.write = function(t) {
|
|
3160
|
+
this.version = 0,
|
|
3161
|
+
this.flags = 0,
|
|
3162
|
+
this.size = 20,
|
|
3163
|
+
this.writeHeader(t),
|
|
3164
|
+
t.writeInt32(this.compositionToDTSShift),
|
|
3165
|
+
t.writeInt32(this.leastDecodeToDisplayDelta),
|
|
3166
|
+
t.writeInt32(this.greatestDecodeToDisplayDelta),
|
|
3167
|
+
t.writeInt32(this.compositionStartTime),
|
|
3168
|
+
t.writeInt32(this.compositionEndTime)
|
|
3169
|
+
},
|
|
3170
|
+
BoxParser.cttsBox.prototype.write = function(t) {
|
|
3171
|
+
var e;
|
|
3172
|
+
for (this.version = 0, this.flags = 0, this.size = 4 + 8 * this.sample_counts.length, this.writeHeader(t), t.writeUint32(this.sample_counts.length), e = 0; e < this.sample_counts.length; e++) t.writeUint32(this.sample_counts[e]),
|
|
3173
|
+
1 === this.version ? t.writeInt32(this.sample_offsets[e]) : t.writeUint32(this.sample_offsets[e])
|
|
3174
|
+
},
|
|
3175
|
+
BoxParser.drefBox.prototype.write = function(t) {
|
|
3176
|
+
this.version = 0,
|
|
3177
|
+
this.flags = 0,
|
|
3178
|
+
this.size = 4,
|
|
3179
|
+
this.writeHeader(t),
|
|
3180
|
+
t.writeUint32(this.entries.length);
|
|
3181
|
+
for (var e = 0; e < this.entries.length; e++) this.entries[e].write(t),
|
|
3182
|
+
this.size += this.entries[e].size;
|
|
3183
|
+
Log.debug("BoxWriter", "Adjusting box " + this.type + " with new size " + this.size),
|
|
3184
|
+
t.adjustUint32(this.sizePosition, this.size)
|
|
3185
|
+
},
|
|
3186
|
+
BoxParser.elngBox.prototype.write = function(t) {
|
|
3187
|
+
this.version = 0,
|
|
3188
|
+
this.flags = 0,
|
|
3189
|
+
this.size = this.extended_language.length,
|
|
3190
|
+
this.writeHeader(t),
|
|
3191
|
+
t.writeString(this.extended_language)
|
|
3192
|
+
},
|
|
3193
|
+
BoxParser.elstBox.prototype.write = function(t) {
|
|
3194
|
+
this.version = 0,
|
|
3195
|
+
this.flags = 0,
|
|
3196
|
+
this.size = 4 + 12 * this.entries.length,
|
|
3197
|
+
this.writeHeader(t),
|
|
3198
|
+
t.writeUint32(this.entries.length);
|
|
3199
|
+
for (var e = 0; e < this.entries.length; e++) {
|
|
3200
|
+
var i = this.entries[e];
|
|
3201
|
+
t.writeUint32(i.segment_duration),
|
|
3202
|
+
t.writeInt32(i.media_time),
|
|
3203
|
+
t.writeInt16(i.media_rate_integer),
|
|
3204
|
+
t.writeInt16(i.media_rate_fraction)
|
|
3205
|
+
}
|
|
3206
|
+
},
|
|
3207
|
+
BoxParser.emsgBox.prototype.write = function(t) {
|
|
3208
|
+
this.version = 0,
|
|
3209
|
+
this.flags = 0,
|
|
3210
|
+
this.size = 16 + this.message_data.length + (this.scheme_id_uri.length + 1) + (this.value.length + 1),
|
|
3211
|
+
this.writeHeader(t),
|
|
3212
|
+
t.writeCString(this.scheme_id_uri),
|
|
3213
|
+
t.writeCString(this.value),
|
|
3214
|
+
t.writeUint32(this.timescale),
|
|
3215
|
+
t.writeUint32(this.presentation_time_delta),
|
|
3216
|
+
t.writeUint32(this.event_duration),
|
|
3217
|
+
t.writeUint32(this.id),
|
|
3218
|
+
t.writeUint8Array(this.message_data)
|
|
3219
|
+
},
|
|
3220
|
+
BoxParser.ftypBox.prototype.write = function(t) {
|
|
3221
|
+
this.size = 8 + 4 * this.compatible_brands.length,
|
|
3222
|
+
this.writeHeader(t),
|
|
3223
|
+
t.writeString(this.major_brand, null, 4),
|
|
3224
|
+
t.writeUint32(this.minor_version);
|
|
3225
|
+
for (var e = 0; e < this.compatible_brands.length; e++) t.writeString(this.compatible_brands[e], null, 4)
|
|
3226
|
+
},
|
|
3227
|
+
BoxParser.hdlrBox.prototype.write = function(t) {
|
|
3228
|
+
this.size = 20 + this.name.length + 1,
|
|
3229
|
+
this.version = 0,
|
|
3230
|
+
this.flags = 0,
|
|
3231
|
+
this.writeHeader(t),
|
|
3232
|
+
t.writeUint32(0),
|
|
3233
|
+
t.writeString(this.handler, null, 4),
|
|
3234
|
+
t.writeUint32(0),
|
|
3235
|
+
t.writeUint32(0),
|
|
3236
|
+
t.writeUint32(0),
|
|
3237
|
+
t.writeCString(this.name)
|
|
3238
|
+
},
|
|
3239
|
+
BoxParser.hvcCBox.prototype.write = function(t) {
|
|
3240
|
+
var e, i;
|
|
3241
|
+
for (this.size = 23, e = 0; e < this.nalu_arrays.length; e++) for (this.size += 3, i = 0; i < this.nalu_arrays[e].length; i++) this.size += 2 + this.nalu_arrays[e][i].data.length;
|
|
3242
|
+
for (this.writeHeader(t), t.writeUint8(this.configurationVersion), t.writeUint8((this.general_profile_space << 6) + (this.general_tier_flag << 5) + this.general_profile_idc), t.writeUint32(this.general_profile_compatibility), t.writeUint8Array(this.general_constraint_indicator), t.writeUint8(this.general_level_idc), t.writeUint16(this.min_spatial_segmentation_idc + (15 << 24)), t.writeUint8(this.parallelismType + 252), t.writeUint8(this.chroma_format_idc + 252), t.writeUint8(this.bit_depth_luma_minus8 + 248), t.writeUint8(this.bit_depth_chroma_minus8 + 248), t.writeUint16(this.avgFrameRate), t.writeUint8((this.constantFrameRate << 6) + (this.numTemporalLayers << 3) + (this.temporalIdNested << 2) + this.lengthSizeMinusOne), t.writeUint8(this.nalu_arrays.length), e = 0; e < this.nalu_arrays.length; e++) for (t.writeUint8((this.nalu_arrays[e].completeness << 7) + this.nalu_arrays[e].nalu_type), t.writeUint16(this.nalu_arrays[e].length), i = 0; i < this.nalu_arrays[e].length; i++) t.writeUint16(this.nalu_arrays[e][i].data.length),
|
|
3243
|
+
t.writeUint8Array(this.nalu_arrays[e][i].data)
|
|
3244
|
+
},
|
|
3245
|
+
BoxParser.kindBox.prototype.write = function(t) {
|
|
3246
|
+
this.version = 0,
|
|
3247
|
+
this.flags = 0,
|
|
3248
|
+
this.size = this.schemeURI.length + 1 + (this.value.length + 1),
|
|
3249
|
+
this.writeHeader(t),
|
|
3250
|
+
t.writeCString(this.schemeURI),
|
|
3251
|
+
t.writeCString(this.value)
|
|
3252
|
+
},
|
|
3253
|
+
BoxParser.mdhdBox.prototype.write = function(t) {
|
|
3254
|
+
this.size = 20,
|
|
3255
|
+
this.flags = 0,
|
|
3256
|
+
this.version = 0,
|
|
3257
|
+
this.writeHeader(t),
|
|
3258
|
+
t.writeUint32(this.creation_time),
|
|
3259
|
+
t.writeUint32(this.modification_time),
|
|
3260
|
+
t.writeUint32(this.timescale),
|
|
3261
|
+
t.writeUint32(this.duration),
|
|
3262
|
+
t.writeUint16(this.language),
|
|
3263
|
+
t.writeUint16(0)
|
|
3264
|
+
},
|
|
3265
|
+
BoxParser.mehdBox.prototype.write = function(t) {
|
|
3266
|
+
this.version = 0,
|
|
3267
|
+
this.flags = 0,
|
|
3268
|
+
this.size = 4,
|
|
3269
|
+
this.writeHeader(t),
|
|
3270
|
+
t.writeUint32(this.fragment_duration)
|
|
3271
|
+
},
|
|
3272
|
+
BoxParser.mfhdBox.prototype.write = function(t) {
|
|
3273
|
+
this.version = 0,
|
|
3274
|
+
this.flags = 0,
|
|
3275
|
+
this.size = 4,
|
|
3276
|
+
this.writeHeader(t),
|
|
3277
|
+
t.writeUint32(this.sequence_number)
|
|
3278
|
+
},
|
|
3279
|
+
BoxParser.mvhdBox.prototype.write = function(t) {
|
|
3280
|
+
this.version = 0,
|
|
3281
|
+
this.flags = 0,
|
|
3282
|
+
this.size = 96,
|
|
3283
|
+
this.writeHeader(t),
|
|
3284
|
+
t.writeUint32(this.creation_time),
|
|
3285
|
+
t.writeUint32(this.modification_time),
|
|
3286
|
+
t.writeUint32(this.timescale),
|
|
3287
|
+
t.writeUint32(this.duration),
|
|
3288
|
+
t.writeUint32(this.rate),
|
|
3289
|
+
t.writeUint16(this.volume << 8),
|
|
3290
|
+
t.writeUint16(0),
|
|
3291
|
+
t.writeUint32(0),
|
|
3292
|
+
t.writeUint32(0),
|
|
3293
|
+
t.writeUint32Array(this.matrix),
|
|
3294
|
+
t.writeUint32(0),
|
|
3295
|
+
t.writeUint32(0),
|
|
3296
|
+
t.writeUint32(0),
|
|
3297
|
+
t.writeUint32(0),
|
|
3298
|
+
t.writeUint32(0),
|
|
3299
|
+
t.writeUint32(0),
|
|
3300
|
+
t.writeUint32(this.next_track_id)
|
|
3301
|
+
},
|
|
3302
|
+
BoxParser.SampleEntry.prototype.writeHeader = function(t) {
|
|
3303
|
+
this.size = 8,
|
|
3304
|
+
BoxParser.Box.prototype.writeHeader.call(this, t),
|
|
3305
|
+
t.writeUint8(0),
|
|
3306
|
+
t.writeUint8(0),
|
|
3307
|
+
t.writeUint8(0),
|
|
3308
|
+
t.writeUint8(0),
|
|
3309
|
+
t.writeUint8(0),
|
|
3310
|
+
t.writeUint8(0),
|
|
3311
|
+
t.writeUint16(this.data_reference_index)
|
|
3312
|
+
},
|
|
3313
|
+
BoxParser.SampleEntry.prototype.writeFooter = function(t) {
|
|
3314
|
+
for (var e = 0; e < this.boxes.length; e++) this.boxes[e].write(t),
|
|
3315
|
+
this.size += this.boxes[e].size;
|
|
3316
|
+
Log.debug("BoxWriter", "Adjusting box " + this.type + " with new size " + this.size),
|
|
3317
|
+
t.adjustUint32(this.sizePosition, this.size)
|
|
3318
|
+
},
|
|
3319
|
+
BoxParser.SampleEntry.prototype.write = function(t) {
|
|
3320
|
+
this.writeHeader(t),
|
|
3321
|
+
t.writeUint8Array(this.data),
|
|
3322
|
+
this.size += this.data.length,
|
|
3323
|
+
Log.debug("BoxWriter", "Adjusting box " + this.type + " with new size " + this.size),
|
|
3324
|
+
t.adjustUint32(this.sizePosition, this.size)
|
|
3325
|
+
},
|
|
3326
|
+
BoxParser.VisualSampleEntry.prototype.write = function(t) {
|
|
3327
|
+
this.writeHeader(t),
|
|
3328
|
+
this.size += 70,
|
|
3329
|
+
t.writeUint16(0),
|
|
3330
|
+
t.writeUint16(0),
|
|
3331
|
+
t.writeUint32(0),
|
|
3332
|
+
t.writeUint32(0),
|
|
3333
|
+
t.writeUint32(0),
|
|
3334
|
+
t.writeUint16(this.width),
|
|
3335
|
+
t.writeUint16(this.height),
|
|
3336
|
+
t.writeUint32(this.horizresolution),
|
|
3337
|
+
t.writeUint32(this.vertresolution),
|
|
3338
|
+
t.writeUint32(0),
|
|
3339
|
+
t.writeUint16(this.frame_count),
|
|
3340
|
+
t.writeUint8(Math.min(31, this.compressorname.length)),
|
|
3341
|
+
t.writeString(this.compressorname, null, 31),
|
|
3342
|
+
t.writeUint16(this.depth),
|
|
3343
|
+
t.writeInt16(-1),
|
|
3344
|
+
this.writeFooter(t)
|
|
3345
|
+
},
|
|
3346
|
+
BoxParser.AudioSampleEntry.prototype.write = function(t) {
|
|
3347
|
+
this.writeHeader(t),
|
|
3348
|
+
this.size += 20,
|
|
3349
|
+
t.writeUint32(0),
|
|
3350
|
+
t.writeUint32(0),
|
|
3351
|
+
t.writeUint16(this.channel_count),
|
|
3352
|
+
t.writeUint16(this.samplesize),
|
|
3353
|
+
t.writeUint16(0),
|
|
3354
|
+
t.writeUint16(0),
|
|
3355
|
+
t.writeUint32(this.samplerate << 16),
|
|
3356
|
+
this.writeFooter(t)
|
|
3357
|
+
},
|
|
3358
|
+
BoxParser.stppSampleEntry.prototype.write = function(t) {
|
|
3359
|
+
this.writeHeader(t),
|
|
3360
|
+
this.size += this.namespace.length + 1 + this.schema_location.length + 1 + this.auxiliary_mime_types.length + 1,
|
|
3361
|
+
t.writeCString(this.namespace),
|
|
3362
|
+
t.writeCString(this.schema_location),
|
|
3363
|
+
t.writeCString(this.auxiliary_mime_types),
|
|
3364
|
+
this.writeFooter(t)
|
|
3365
|
+
},
|
|
3366
|
+
BoxParser.SampleGroupEntry.prototype.write = function(t) {
|
|
3367
|
+
t.writeUint8Array(this.data)
|
|
3368
|
+
},
|
|
3369
|
+
BoxParser.sbgpBox.prototype.write = function(t) {
|
|
3370
|
+
this.version = 1,
|
|
3371
|
+
this.flags = 0,
|
|
3372
|
+
this.size = 12 + 8 * this.entries.length,
|
|
3373
|
+
this.writeHeader(t),
|
|
3374
|
+
t.writeString(this.grouping_type, null, 4),
|
|
3375
|
+
t.writeUint32(this.grouping_type_parameter),
|
|
3376
|
+
t.writeUint32(this.entries.length);
|
|
3377
|
+
for (var e = 0; e < this.entries.length; e++) {
|
|
3378
|
+
var i = this.entries[e];
|
|
3379
|
+
t.writeInt32(i.sample_count),
|
|
3380
|
+
t.writeInt32(i.group_description_index)
|
|
3381
|
+
}
|
|
3382
|
+
},
|
|
3383
|
+
BoxParser.sgpdBox.prototype.write = function(t) {
|
|
3384
|
+
var e, i;
|
|
3385
|
+
for (this.flags = 0, this.size = 12, e = 0; e < this.entries.length; e++) i = this.entries[e],
|
|
3386
|
+
1 === this.version && (0 === this.default_length && (this.size += 4), this.size += i.data.length);
|
|
3387
|
+
for (this.writeHeader(t), t.writeString(this.grouping_type, null, 4), 1 === this.version && t.writeUint32(this.default_length), 2 <= this.version && t.writeUint32(this.default_sample_description_index), t.writeUint32(this.entries.length), e = 0; e < this.entries.length; e++) i = this.entries[e],
|
|
3388
|
+
1 === this.version && 0 === this.default_length && t.writeUint32(i.description_length),
|
|
3389
|
+
i.write(t)
|
|
3390
|
+
},
|
|
3391
|
+
BoxParser.sidxBox.prototype.write = function(t) {
|
|
3392
|
+
this.version = 0,
|
|
3393
|
+
this.flags = 0,
|
|
3394
|
+
this.size = 20 + 12 * this.references.length,
|
|
3395
|
+
this.writeHeader(t),
|
|
3396
|
+
t.writeUint32(this.reference_ID),
|
|
3397
|
+
t.writeUint32(this.timescale),
|
|
3398
|
+
t.writeUint32(this.earliest_presentation_time),
|
|
3399
|
+
t.writeUint32(this.first_offset),
|
|
3400
|
+
t.writeUint16(0),
|
|
3401
|
+
t.writeUint16(this.references.length);
|
|
3402
|
+
for (var e = 0; e < this.references.length; e++) {
|
|
3403
|
+
var i = this.references[e];
|
|
3404
|
+
t.writeUint32(i.reference_type << 31 | i.referenced_size),
|
|
3405
|
+
t.writeUint32(i.subsegment_duration),
|
|
3406
|
+
t.writeUint32(i.starts_with_SAP << 31 | i.SAP_type << 28 | i.SAP_delta_time)
|
|
3407
|
+
}
|
|
3408
|
+
},
|
|
3409
|
+
BoxParser.smhdBox.prototype.write = function(t) {
|
|
3410
|
+
this.version = 0,
|
|
3411
|
+
this.flags = 1,
|
|
3412
|
+
this.size = 4,
|
|
3413
|
+
this.writeHeader(t),
|
|
3414
|
+
t.writeUint16(this.balance),
|
|
3415
|
+
t.writeUint16(0)
|
|
3416
|
+
},
|
|
3417
|
+
BoxParser.stcoBox.prototype.write = function(t) {
|
|
3418
|
+
this.version = 0,
|
|
3419
|
+
this.flags = 0,
|
|
3420
|
+
this.size = 4 + 4 * this.chunk_offsets.length,
|
|
3421
|
+
this.writeHeader(t),
|
|
3422
|
+
t.writeUint32(this.chunk_offsets.length),
|
|
3423
|
+
t.writeUint32Array(this.chunk_offsets)
|
|
3424
|
+
},
|
|
3425
|
+
BoxParser.stscBox.prototype.write = function(t) {
|
|
3426
|
+
var e;
|
|
3427
|
+
for (this.version = 0, this.flags = 0, this.size = 4 + 12 * this.first_chunk.length, this.writeHeader(t), t.writeUint32(this.first_chunk.length), e = 0; e < this.first_chunk.length; e++) t.writeUint32(this.first_chunk[e]),
|
|
3428
|
+
t.writeUint32(this.samples_per_chunk[e]),
|
|
3429
|
+
t.writeUint32(this.sample_description_index[e])
|
|
3430
|
+
},
|
|
3431
|
+
BoxParser.stsdBox.prototype.write = function(t) {
|
|
3432
|
+
var e;
|
|
3433
|
+
for (this.version = 0, this.flags = 0, this.size = 0, this.writeHeader(t), t.writeUint32(this.entries.length), this.size += 4, e = 0; e < this.entries.length; e++) this.entries[e].write(t),
|
|
3434
|
+
this.size += this.entries[e].size;
|
|
3435
|
+
Log.debug("BoxWriter", "Adjusting box " + this.type + " with new size " + this.size),
|
|
3436
|
+
t.adjustUint32(this.sizePosition, this.size)
|
|
3437
|
+
},
|
|
3438
|
+
BoxParser.stshBox.prototype.write = function(t) {
|
|
3439
|
+
var e;
|
|
3440
|
+
for (this.version = 0, this.flags = 0, this.size = 4 + 8 * this.shadowed_sample_numbers.length, this.writeHeader(t), t.writeUint32(this.shadowed_sample_numbers.length), e = 0; e < this.shadowed_sample_numbers.length; e++) t.writeUint32(this.shadowed_sample_numbers[e]),
|
|
3441
|
+
t.writeUint32(this.sync_sample_numbers[e])
|
|
3442
|
+
},
|
|
3443
|
+
BoxParser.stssBox.prototype.write = function(t) {
|
|
3444
|
+
this.version = 0,
|
|
3445
|
+
this.flags = 0,
|
|
3446
|
+
this.size = 4 + 4 * this.sample_numbers.length,
|
|
3447
|
+
this.writeHeader(t),
|
|
3448
|
+
t.writeUint32(this.sample_numbers.length),
|
|
3449
|
+
t.writeUint32Array(this.sample_numbers)
|
|
3450
|
+
},
|
|
3451
|
+
BoxParser.stszBox.prototype.write = function(t) {
|
|
3452
|
+
var e, i = !0;
|
|
3453
|
+
if (this.version = 0, (this.flags = 0) < this.sample_sizes.length) for (e = 0; e + 1 < this.sample_sizes.length;) {
|
|
3454
|
+
if (this.sample_sizes[e + 1] !== this.sample_sizes[0]) {
|
|
3455
|
+
i = !1;
|
|
3456
|
+
break
|
|
3457
|
+
}
|
|
3458
|
+
e++
|
|
3459
|
+
} else i = !1;
|
|
3460
|
+
this.size = 8,
|
|
3461
|
+
i || (this.size += 4 * this.sample_sizes.length),
|
|
3462
|
+
this.writeHeader(t),
|
|
3463
|
+
i ? t.writeUint32(this.sample_sizes[0]) : t.writeUint32(0),
|
|
3464
|
+
t.writeUint32(this.sample_sizes.length),
|
|
3465
|
+
i || t.writeUint32Array(this.sample_sizes)
|
|
3466
|
+
},
|
|
3467
|
+
BoxParser.sttsBox.prototype.write = function(t) {
|
|
3468
|
+
var e;
|
|
3469
|
+
for (this.version = 0, this.flags = 0, this.size = 4 + 8 * this.sample_counts.length, this.writeHeader(t), t.writeUint32(this.sample_counts.length), e = 0; e < this.sample_counts.length; e++) t.writeUint32(this.sample_counts[e]),
|
|
3470
|
+
t.writeUint32(this.sample_deltas[e])
|
|
3471
|
+
},
|
|
3472
|
+
BoxParser.tfdtBox.prototype.write = function(t) {
|
|
3473
|
+
var e = Math.pow(2, 32) - 1;
|
|
3474
|
+
this.version = this.baseMediaDecodeTime > e ? 1 : 0,
|
|
3475
|
+
this.flags = 0,
|
|
3476
|
+
this.size = 4,
|
|
3477
|
+
1 === this.version && (this.size += 4),
|
|
3478
|
+
this.writeHeader(t),
|
|
3479
|
+
1 === this.version ? t.writeUint64(this.baseMediaDecodeTime) : t.writeUint32(this.baseMediaDecodeTime)
|
|
3480
|
+
},
|
|
3481
|
+
BoxParser.tfhdBox.prototype.write = function(t) {
|
|
3482
|
+
this.version = 0,
|
|
3483
|
+
this.size = 4,
|
|
3484
|
+
this.flags & BoxParser.TFHD_FLAG_BASE_DATA_OFFSET && (this.size += 8),
|
|
3485
|
+
this.flags & BoxParser.TFHD_FLAG_SAMPLE_DESC && (this.size += 4),
|
|
3486
|
+
this.flags & BoxParser.TFHD_FLAG_SAMPLE_DUR && (this.size += 4),
|
|
3487
|
+
this.flags & BoxParser.TFHD_FLAG_SAMPLE_SIZE && (this.size += 4),
|
|
3488
|
+
this.flags & BoxParser.TFHD_FLAG_SAMPLE_FLAGS && (this.size += 4),
|
|
3489
|
+
this.writeHeader(t),
|
|
3490
|
+
t.writeUint32(this.track_id),
|
|
3491
|
+
this.flags & BoxParser.TFHD_FLAG_BASE_DATA_OFFSET && t.writeUint64(this.base_data_offset),
|
|
3492
|
+
this.flags & BoxParser.TFHD_FLAG_SAMPLE_DESC && t.writeUint32(this.default_sample_description_index),
|
|
3493
|
+
this.flags & BoxParser.TFHD_FLAG_SAMPLE_DUR && t.writeUint32(this.default_sample_duration),
|
|
3494
|
+
this.flags & BoxParser.TFHD_FLAG_SAMPLE_SIZE && t.writeUint32(this.default_sample_size),
|
|
3495
|
+
this.flags & BoxParser.TFHD_FLAG_SAMPLE_FLAGS && t.writeUint32(this.default_sample_flags)
|
|
3496
|
+
},
|
|
3497
|
+
BoxParser.tkhdBox.prototype.write = function(t) {
|
|
3498
|
+
this.version = 0,
|
|
3499
|
+
this.size = 80,
|
|
3500
|
+
this.writeHeader(t),
|
|
3501
|
+
t.writeUint32(this.creation_time),
|
|
3502
|
+
t.writeUint32(this.modification_time),
|
|
3503
|
+
t.writeUint32(this.track_id),
|
|
3504
|
+
t.writeUint32(0),
|
|
3505
|
+
t.writeUint32(this.duration),
|
|
3506
|
+
t.writeUint32(0),
|
|
3507
|
+
t.writeUint32(0),
|
|
3508
|
+
t.writeInt16(this.layer),
|
|
3509
|
+
t.writeInt16(this.alternate_group),
|
|
3510
|
+
t.writeInt16(this.volume << 8),
|
|
3511
|
+
t.writeUint16(0),
|
|
3512
|
+
t.writeInt32Array(this.matrix),
|
|
3513
|
+
t.writeUint32(this.width),
|
|
3514
|
+
t.writeUint32(this.height)
|
|
3515
|
+
},
|
|
3516
|
+
BoxParser.trexBox.prototype.write = function(t) {
|
|
3517
|
+
this.version = 0,
|
|
3518
|
+
this.flags = 0,
|
|
3519
|
+
this.size = 20,
|
|
3520
|
+
this.writeHeader(t),
|
|
3521
|
+
t.writeUint32(this.track_id),
|
|
3522
|
+
t.writeUint32(this.default_sample_description_index),
|
|
3523
|
+
t.writeUint32(this.default_sample_duration),
|
|
3524
|
+
t.writeUint32(this.default_sample_size),
|
|
3525
|
+
t.writeUint32(this.default_sample_flags)
|
|
3526
|
+
},
|
|
3527
|
+
BoxParser.trunBox.prototype.write = function(t) {
|
|
3528
|
+
this.version = 0,
|
|
3529
|
+
this.size = 4,
|
|
3530
|
+
this.flags & BoxParser.TRUN_FLAGS_DATA_OFFSET && (this.size += 4),
|
|
3531
|
+
this.flags & BoxParser.TRUN_FLAGS_FIRST_FLAG && (this.size += 4),
|
|
3532
|
+
this.flags & BoxParser.TRUN_FLAGS_DURATION && (this.size += 4 * this.sample_duration.length),
|
|
3533
|
+
this.flags & BoxParser.TRUN_FLAGS_SIZE && (this.size += 4 * this.sample_size.length),
|
|
3534
|
+
this.flags & BoxParser.TRUN_FLAGS_FLAGS && (this.size += 4 * this.sample_flags.length),
|
|
3535
|
+
this.flags & BoxParser.TRUN_FLAGS_CTS_OFFSET && (this.size += 4 * this.sample_composition_time_offset.length),
|
|
3536
|
+
this.writeHeader(t),
|
|
3537
|
+
t.writeUint32(this.sample_count),
|
|
3538
|
+
this.flags & BoxParser.TRUN_FLAGS_DATA_OFFSET && (this.data_offset_position = t.getPosition(), t.writeInt32(this.data_offset)),
|
|
3539
|
+
this.flags & BoxParser.TRUN_FLAGS_FIRST_FLAG && t.writeUint32(this.first_sample_flags);
|
|
3540
|
+
for (var e = 0; e < this.sample_count; e++) this.flags & BoxParser.TRUN_FLAGS_DURATION && t.writeUint32(this.sample_duration[e]),
|
|
3541
|
+
this.flags & BoxParser.TRUN_FLAGS_SIZE && t.writeUint32(this.sample_size[e]),
|
|
3542
|
+
this.flags & BoxParser.TRUN_FLAGS_FLAGS && t.writeUint32(this.sample_flags[e]),
|
|
3543
|
+
this.flags & BoxParser.TRUN_FLAGS_CTS_OFFSET && (0 === this.version ? t.writeUint32(this.sample_composition_time_offset[e]) : t.writeInt32(this.sample_composition_time_offset[e]))
|
|
3544
|
+
},
|
|
3545
|
+
BoxParser["url Box"].prototype.write = function(t) {
|
|
3546
|
+
this.version = 0,
|
|
3547
|
+
this.location ? (this.flags = 0, this.size = this.location.length + 1) : (this.flags = 1, this.size = 0),
|
|
3548
|
+
this.writeHeader(t),
|
|
3549
|
+
this.location && t.writeCString(this.location)
|
|
3550
|
+
},
|
|
3551
|
+
BoxParser["urn Box"].prototype.write = function(t) {
|
|
3552
|
+
this.version = 0,
|
|
3553
|
+
this.flags = 0,
|
|
3554
|
+
this.size = this.name.length + 1 + (this.location ? this.location.length + 1 : 0),
|
|
3555
|
+
this.writeHeader(t),
|
|
3556
|
+
t.writeCString(this.name),
|
|
3557
|
+
this.location && t.writeCString(this.location)
|
|
3558
|
+
},
|
|
3559
|
+
BoxParser.vmhdBox.prototype.write = function(t) {
|
|
3560
|
+
this.version = 0,
|
|
3561
|
+
this.flags = 1,
|
|
3562
|
+
this.size = 8,
|
|
3563
|
+
this.writeHeader(t),
|
|
3564
|
+
t.writeUint16(this.graphicsmode),
|
|
3565
|
+
t.writeUint16Array(this.opcolor)
|
|
3566
|
+
},
|
|
3567
|
+
BoxParser.cttsBox.prototype.unpack = function(t) {
|
|
3568
|
+
for (var e, i = 0,
|
|
3569
|
+
r = 0; r < this.sample_counts.length; r++) for (e = 0; e < this.sample_counts[r]; e++) t[i].pts = t[i].dts + this.sample_offsets[r],
|
|
3570
|
+
i++
|
|
3571
|
+
},
|
|
3572
|
+
BoxParser.sttsBox.prototype.unpack = function(t) {
|
|
3573
|
+
for (var e, i = 0,
|
|
3574
|
+
r = 0; r < this.sample_counts.length; r++) for (e = 0; e < this.sample_counts[r]; e++) t[i].dts = 0 === i ? 0 : t[i - 1].dts + this.sample_deltas[r],
|
|
3575
|
+
i++
|
|
3576
|
+
},
|
|
3577
|
+
BoxParser.stcoBox.prototype.unpack = function(t) {
|
|
3578
|
+
for (var e = 0; e < this.chunk_offsets.length; e++) t[e].offset = this.chunk_offsets[e]
|
|
3579
|
+
},
|
|
3580
|
+
BoxParser.stscBox.prototype.unpack = function(t) {
|
|
3581
|
+
for (var e, i, r = 0,
|
|
3582
|
+
s = 0,
|
|
3583
|
+
a = 0; a < this.first_chunk.length; a++) for (e = 0; e < (a + 1 < this.first_chunk.length ? this.first_chunk[a + 1] : 1 / 0); e++) for (s++, i = 0; i < this.samples_per_chunk[a]; i++) {
|
|
3584
|
+
if (!t[r]) return;
|
|
3585
|
+
t[r].description_index = this.sample_description_index[a],
|
|
3586
|
+
t[r].chunk_index = s,
|
|
3587
|
+
r++
|
|
3588
|
+
}
|
|
3589
|
+
},
|
|
3590
|
+
BoxParser.stszBox.prototype.unpack = function(t) {
|
|
3591
|
+
for (var e = 0; e < this.sample_sizes.length; e++) t[e].size = this.sample_sizes[e]
|
|
3592
|
+
},
|
|
3593
|
+
BoxParser.DIFF_BOXES_PROP_NAMES = ["boxes", "entries", "references", "subsamples", "items", "item_infos", "extents", "associations", "subsegments", "ranges", "seekLists", "seekPoints", "esd", "levels"],
|
|
3594
|
+
BoxParser.DIFF_PRIMITIVE_ARRAY_PROP_NAMES = ["compatible_brands", "matrix", "opcolor", "sample_counts", "sample_deltas", "first_chunk", "samples_per_chunk", "sample_sizes", "chunk_offsets", "sample_offsets", "sample_description_index", "sample_duration"],
|
|
3595
|
+
BoxParser.boxEqualFields = function(t, e) {
|
|
3596
|
+
if (t && !e) return ! 1;
|
|
3597
|
+
for (var i in t) if (! (-1 < BoxParser.DIFF_BOXES_PROP_NAMES.indexOf(i) || t[i] instanceof BoxParser.Box || e[i] instanceof BoxParser.Box || void 0 === t[i] || void 0 === e[i] || "function" == typeof t[i] || "function" == typeof e[i] || t.subBoxNames && -1 < t.subBoxNames.indexOf(i.slice(0, 4)) || e.subBoxNames && -1 < e.subBoxNames.indexOf(i.slice(0, 4)) || "data" === i || "start" === i || "size" === i || "creation_time" === i || "modification_time" === i || -1 < BoxParser.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(i) || t[i] === e[i])) return ! 1;
|
|
3598
|
+
return ! 0
|
|
3599
|
+
},
|
|
3600
|
+
BoxParser.boxEqual = function(t, e) {
|
|
3601
|
+
if (!BoxParser.boxEqualFields(t, e)) return ! 1;
|
|
3602
|
+
for (var i = 0; i < BoxParser.DIFF_BOXES_PROP_NAMES.length; i++) {
|
|
3603
|
+
var r = BoxParser.DIFF_BOXES_PROP_NAMES[i];
|
|
3604
|
+
if (t[r] && e[r] && !BoxParser.boxEqual(t[r], e[r])) return ! 1
|
|
3605
|
+
}
|
|
3606
|
+
return ! 0
|
|
3607
|
+
};
|
|
3608
|
+
var VTTin4Parser = function() {};
|
|
3609
|
+
VTTin4Parser.prototype.parseSample = function(t) {
|
|
3610
|
+
for (var e, i = new MP4BoxStream(t.buffer), r = []; ! i.isEos();)(e = BoxParser.parseOneBox(i, !1)).code === BoxParser.OK && "vttc" === e.box.type && r.push(e.box);
|
|
3611
|
+
return r
|
|
3612
|
+
},
|
|
3613
|
+
VTTin4Parser.prototype.getText = function(t, e, i) {
|
|
3614
|
+
function s(t, e, i) {
|
|
3615
|
+
return i = i || "0",
|
|
3616
|
+
(t += "").length >= e ? t: new Array(e - t.length + 1).join(i) + t
|
|
3617
|
+
}
|
|
3618
|
+
function r(t) {
|
|
3619
|
+
var e = Math.floor(t / 3600),
|
|
3620
|
+
i = Math.floor((t - 3600 * e) / 60),
|
|
3621
|
+
r = Math.floor(t - 3600 * e - 60 * i),
|
|
3622
|
+
t = Math.floor(1e3 * (t - 3600 * e - 60 * i - r));
|
|
3623
|
+
return s(e, 2) + ":" + s(i, 2) + ":" + s(r, 2) + "." + s(t, 3)
|
|
3624
|
+
}
|
|
3625
|
+
for (var a = this.parseSample(i), n = "", o = 0; o < a.length; o++) {
|
|
3626
|
+
var h = a[o];
|
|
3627
|
+
n += r(t) + " --\\x3e " + r(e) + "\\r\\n",
|
|
3628
|
+
n += h.payl.text
|
|
3629
|
+
}
|
|
3630
|
+
return n
|
|
3631
|
+
};
|
|
3632
|
+
var XMLSubtitlein4Parser = function() {};
|
|
3633
|
+
XMLSubtitlein4Parser.prototype.parseSample = function(t) {
|
|
3634
|
+
var e, i = {
|
|
3635
|
+
resources: []
|
|
3636
|
+
},
|
|
3637
|
+
r = new MP4BoxStream(t.data.buffer);
|
|
3638
|
+
if (t.subsamples && 0 !== t.subsamples.length) {
|
|
3639
|
+
if (i.documentString = r.readString(t.subsamples[0].size), 1 < t.subsamples.length) for (e = 1; e < t.subsamples.length; e++) i.resources[e] = r.readUint8Array(t.subsamples[e].size)
|
|
3640
|
+
} else i.documentString = r.readString(t.data.length);
|
|
3641
|
+
return "undefined" != typeof DOMParser && (i.document = (new DOMParser).parseFromString(i.documentString, "application/xml")),
|
|
3642
|
+
i
|
|
3643
|
+
};
|
|
3644
|
+
var Textin4Parser = function() {};
|
|
3645
|
+
Textin4Parser.prototype.parseSample = function(t) {
|
|
3646
|
+
return new MP4BoxStream(t.data.buffer).readString(t.data.length)
|
|
3647
|
+
},
|
|
3648
|
+
Textin4Parser.prototype.parseConfig = function(t) {
|
|
3649
|
+
t = new MP4BoxStream(t.buffer);
|
|
3650
|
+
return t.readUint32(),
|
|
3651
|
+
t.readCString()
|
|
3652
|
+
},
|
|
3653
|
+
"undefined" != typeof exports && (exports.VTTin4Parser = VTTin4Parser, exports.XMLSubtitlein4Parser = XMLSubtitlein4Parser, exports.Textin4Parser = Textin4Parser);
|
|
3654
|
+
var ISOFile = function(t) {
|
|
3655
|
+
this.stream = t || new MultiBufferStream,
|
|
3656
|
+
this.boxes = [],
|
|
3657
|
+
this.mdats = [],
|
|
3658
|
+
this.moofs = [],
|
|
3659
|
+
this.isProgressive = !1,
|
|
3660
|
+
this.moovStartFound = !1,
|
|
3661
|
+
this.onMoovStart = null,
|
|
3662
|
+
this.moovStartSent = !1,
|
|
3663
|
+
this.onReady = null,
|
|
3664
|
+
this.readySent = !1,
|
|
3665
|
+
this.onSegment = null,
|
|
3666
|
+
this.onSamples = null,
|
|
3667
|
+
this.onError = null,
|
|
3668
|
+
this.sampleListBuilt = !1,
|
|
3669
|
+
this.fragmentedTracks = [],
|
|
3670
|
+
this.extractedTracks = [],
|
|
3671
|
+
this.isFragmentationInitialized = !1,
|
|
3672
|
+
this.sampleProcessingStarted = !1,
|
|
3673
|
+
this.nextMoofNumber = 0,
|
|
3674
|
+
this.itemListBuilt = !1,
|
|
3675
|
+
this.items = [],
|
|
3676
|
+
this.entity_groups = [],
|
|
3677
|
+
this.onSidx = null,
|
|
3678
|
+
this.sidxSent = !1
|
|
3679
|
+
};
|
|
3680
|
+
ISOFile.prototype.setSegmentOptions = function(t, e, i) {
|
|
3681
|
+
var r, s = this.getTrackById(t);
|
|
3682
|
+
s && (r = {},
|
|
3683
|
+
this.fragmentedTracks.push(r), r.id = t, r.user = e, (r.trak = s).nextSample = 0, r.segmentStream = null, r.nb_samples = 1e3, r.rapAlignement = !0, i && (i.nbSamples && (r.nb_samples = i.nbSamples), i.rapAlignement && (r.rapAlignement = i.rapAlignement)))
|
|
3684
|
+
},
|
|
3685
|
+
ISOFile.prototype.unsetSegmentOptions = function(t) {
|
|
3686
|
+
for (var e = -1,
|
|
3687
|
+
i = 0; i < this.fragmentedTracks.length; i++) this.fragmentedTracks[i].id == t && (e = i); - 1 < e && this.fragmentedTracks.splice(e, 1)
|
|
3688
|
+
},
|
|
3689
|
+
ISOFile.prototype.setExtractionOptions = function(t, e, i) {
|
|
3690
|
+
var r, s = this.getTrackById(t);
|
|
3691
|
+
s && (r = {},
|
|
3692
|
+
this.extractedTracks.push(r), r.id = t, r.user = e, (r.trak = s).nextSample = 0, r.nb_samples = 1e3, r.samples = [], i && i.nbSamples && (r.nb_samples = i.nbSamples))
|
|
3693
|
+
},
|
|
3694
|
+
ISOFile.prototype.unsetExtractionOptions = function(t) {
|
|
3695
|
+
for (var e = -1,
|
|
3696
|
+
i = 0; i < this.extractedTracks.length; i++) this.extractedTracks[i].id == t && (e = i); - 1 < e && this.extractedTracks.splice(e, 1)
|
|
3697
|
+
},
|
|
3698
|
+
ISOFile.prototype.parse = function() {
|
|
3699
|
+
var t;
|
|
3700
|
+
if (!this.restoreParsePosition || this.restoreParsePosition()) for (;;) if (this.hasIncompleteMdat && this.hasIncompleteMdat()) {
|
|
3701
|
+
if (!this.processIncompleteMdat()) return
|
|
3702
|
+
} else if (this.saveParsePosition && this.saveParsePosition(), (t = BoxParser.parseOneBox(this.stream, !1)).code === BoxParser.ERR_NOT_ENOUGH_DATA) {
|
|
3703
|
+
if (!this.processIncompleteBox) return;
|
|
3704
|
+
if (!this.processIncompleteBox(t)) return
|
|
3705
|
+
} else {
|
|
3706
|
+
var e, i = "uuid" !== (e = t.box).type ? e.type: e.uuid;
|
|
3707
|
+
switch (this.boxes.push(e), i) {
|
|
3708
|
+
case "mdat":
|
|
3709
|
+
this.mdats.push(e);
|
|
3710
|
+
break;
|
|
3711
|
+
case "moof":
|
|
3712
|
+
this.moofs.push(e);
|
|
3713
|
+
break;
|
|
3714
|
+
case "moov":
|
|
3715
|
+
this.moovStartFound = !0,
|
|
3716
|
+
0 === this.mdats.length && (this.isProgressive = !0);
|
|
3717
|
+
default:
|
|
3718
|
+
void 0 !== this[i] && Log.warn("ISOFile", "Duplicate Box of type: " + i + ", overriding previous occurrence"),
|
|
3719
|
+
this[i] = e
|
|
3720
|
+
}
|
|
3721
|
+
this.updateUsedBytes && this.updateUsedBytes(e, t)
|
|
3722
|
+
}
|
|
3723
|
+
},
|
|
3724
|
+
ISOFile.prototype.checkBuffer = function(t) {
|
|
3725
|
+
if (null == t) throw "Buffer must be defined and non empty";
|
|
3726
|
+
if (void 0 === t.fileStart) throw "Buffer must have a fileStart property";
|
|
3727
|
+
return 0 === t.byteLength ? (Log.warn("ISOFile", "Ignoring empty buffer (fileStart: " + t.fileStart + ")"), this.stream.logBufferLevel(), !1) : (Log.info("ISOFile", "Processing buffer (fileStart: " + t.fileStart + ")"), t.usedBytes = 0, this.stream.insertBuffer(t), this.stream.logBufferLevel(), !!this.stream.initialized() || (Log.warn("ISOFile", "Not ready to start parsing"), !1))
|
|
3728
|
+
},
|
|
3729
|
+
ISOFile.prototype.appendBuffer = function(t, e) {
|
|
3730
|
+
var i;
|
|
3731
|
+
if (this.checkBuffer(t)) return this.parse(),
|
|
3732
|
+
this.moovStartFound && !this.moovStartSent && (this.moovStartSent = !0, this.onMoovStart && this.onMoovStart()),
|
|
3733
|
+
this.moov ? (this.sampleListBuilt || (this.buildSampleLists(), this.sampleListBuilt = !0), this.updateSampleLists(), this.onReady && !this.readySent && (this.readySent = !0, this.onReady(this.getInfo())), this.processSamples(e), this.nextSeekPosition ? (i = this.nextSeekPosition, this.nextSeekPosition = void 0) : i = this.nextParsePosition, this.stream.getEndFilePositionAfter && (i = this.stream.getEndFilePositionAfter(i))) : i = this.nextParsePosition || 0,
|
|
3734
|
+
this.sidx && this.onSidx && !this.sidxSent && (this.onSidx(this.sidx), this.sidxSent = !0),
|
|
3735
|
+
this.meta && (this.flattenItemInfo && !this.itemListBuilt && (this.flattenItemInfo(), this.itemListBuilt = !0), this.processItems && this.processItems(this.onItem)),
|
|
3736
|
+
this.stream.cleanBuffers && (Log.info("ISOFile", "Done processing buffer (fileStart: " + t.fileStart + ") - next buffer to fetch should have a fileStart position of " + i), this.stream.logBufferLevel(), this.stream.cleanBuffers(), this.stream.logBufferLevel(!0), Log.info("ISOFile", "Sample data size in memory: " + this.getAllocatedSampleDataSize())),
|
|
3737
|
+
i
|
|
3738
|
+
},
|
|
3739
|
+
ISOFile.prototype.getInfo = function() {
|
|
3740
|
+
var t, e, i, r, s, a, n = {},
|
|
3741
|
+
o = new Date("1904-01-01T00:00:00Z").getTime();
|
|
3742
|
+
if (this.moov) for (n.hasMoov = !0, n.duration = this.moov.mvhd.duration, n.timescale = this.moov.mvhd.timescale, n.isFragmented = null != this.moov.mvex, n.isFragmented && this.moov.mvex.mehd && (n.fragment_duration = this.moov.mvex.mehd.fragment_duration), n.isProgressive = this.isProgressive, n.hasIOD = null != this.moov.iods, n.brands = [], n.brands.push(this.ftyp.major_brand), n.brands = n.brands.concat(this.ftyp.compatible_brands), n.created = new Date(o + 1e3 * this.moov.mvhd.creation_time), n.modified = new Date(o + 1e3 * this.moov.mvhd.modification_time), n.tracks = [], n.audioTracks = [], n.videoTracks = [], n.subtitleTracks = [], n.metadataTracks = [], n.hintTracks = [], n.otherTracks = [], t = 0; t < this.moov.traks.length; t++) {
|
|
3743
|
+
if (a = (i = this.moov.traks[t]).mdia.minf.stbl.stsd.entries[0], r = {},
|
|
3744
|
+
n.tracks.push(r), r.id = i.tkhd.track_id, r.name = i.mdia.hdlr.name, r.references = [], i.tref) for (e = 0; e < i.tref.boxes.length; e++) s = {},
|
|
3745
|
+
r.references.push(s),
|
|
3746
|
+
s.type = i.tref.boxes[e].type,
|
|
3747
|
+
s.track_ids = i.tref.boxes[e].track_ids;
|
|
3748
|
+
i.edts && (r.edits = i.edts.elst.entries),
|
|
3749
|
+
r.created = new Date(o + 1e3 * i.tkhd.creation_time),
|
|
3750
|
+
r.modified = new Date(o + 1e3 * i.tkhd.modification_time),
|
|
3751
|
+
r.movie_duration = i.tkhd.duration,
|
|
3752
|
+
r.movie_timescale = n.timescale,
|
|
3753
|
+
r.layer = i.tkhd.layer,
|
|
3754
|
+
r.alternate_group = i.tkhd.alternate_group,
|
|
3755
|
+
r.volume = i.tkhd.volume,
|
|
3756
|
+
r.matrix = i.tkhd.matrix,
|
|
3757
|
+
r.track_width = i.tkhd.width / 65536,
|
|
3758
|
+
r.track_height = i.tkhd.height / 65536,
|
|
3759
|
+
r.timescale = i.mdia.mdhd.timescale,
|
|
3760
|
+
r.cts_shift = i.mdia.minf.stbl.cslg,
|
|
3761
|
+
r.duration = i.mdia.mdhd.duration,
|
|
3762
|
+
r.samples_duration = i.samples_duration,
|
|
3763
|
+
r.codec = a.getCodec(),
|
|
3764
|
+
r.kind = i.udta && i.udta.kinds.length ? i.udta.kinds[0] : {
|
|
3765
|
+
schemeURI: "",
|
|
3766
|
+
value: ""
|
|
3767
|
+
},
|
|
3768
|
+
r.language = i.mdia.elng ? i.mdia.elng.extended_language: i.mdia.mdhd.languageString,
|
|
3769
|
+
r.nb_samples = i.samples.length,
|
|
3770
|
+
r.size = i.samples_size,
|
|
3771
|
+
r.bitrate = 8 * r.size * r.timescale / r.samples_duration,
|
|
3772
|
+
a.isAudio() ? (r.type = "audio", n.audioTracks.push(r), r.audio = {},
|
|
3773
|
+
r.audio.sample_rate = a.getSampleRate(), r.audio.channel_count = a.getChannelCount(), r.audio.sample_size = a.getSampleSize()) : a.isVideo() ? (r.type = "video", n.videoTracks.push(r), r.video = {},
|
|
3774
|
+
r.video.width = a.getWidth(), r.video.height = a.getHeight()) : a.isSubtitle() ? (r.type = "subtitles", n.subtitleTracks.push(r)) : a.isHint() ? (r.type = "metadata", n.hintTracks.push(r)) : a.isMetadata() ? (r.type = "metadata", n.metadataTracks.push(r)) : (r.type = "metadata", n.otherTracks.push(r))
|
|
3775
|
+
} else n.hasMoov = !1;
|
|
3776
|
+
if (n.mime = "", n.hasMoov && n.tracks) {
|
|
3777
|
+
for (n.videoTracks && 0 < n.videoTracks.length ? n.mime += 'video/mp4; codecs="': n.audioTracks && 0 < n.audioTracks.length ? n.mime += 'audio/mp4; codecs="': n.mime += 'application/mp4; codecs="', t = 0; t < n.tracks.length; t++) 0 !== t && (n.mime += ","),
|
|
3778
|
+
n.mime += n.tracks[t].codec;
|
|
3779
|
+
n.mime += '"; profiles="',
|
|
3780
|
+
n.mime += this.ftyp.compatible_brands.join(),
|
|
3781
|
+
n.mime += '"'
|
|
3782
|
+
}
|
|
3783
|
+
return n
|
|
3784
|
+
},
|
|
3785
|
+
ISOFile.prototype.setNextSeekPositionFromSample = function(t) {
|
|
3786
|
+
t && (this.nextSeekPosition ? this.nextSeekPosition = Math.min(t.offset + t.alreadyRead, this.nextSeekPosition) : this.nextSeekPosition = t.offset + t.alreadyRead)
|
|
3787
|
+
},
|
|
3788
|
+
ISOFile.prototype.processSamples = function(t) {
|
|
3789
|
+
var e;
|
|
3790
|
+
if (this.sampleProcessingStarted) {
|
|
3791
|
+
if (this.isFragmentationInitialized && null !== this.onSegment) for (e = 0; e < this.fragmentedTracks.length; e++) for (var i = this.fragmentedTracks[e], r = i.trak; r.nextSample < r.samples.length && this.sampleProcessingStarted;) {
|
|
3792
|
+
Log.debug("ISOFile", "Creating media fragment on track #" + i.id + " for sample " + r.nextSample);
|
|
3793
|
+
var s = this.createFragment(i.id, r.nextSample, i.segmentStream);
|
|
3794
|
+
if (!s) break;
|
|
3795
|
+
if (i.segmentStream = s, r.nextSample++, (r.nextSample % i.nb_samples == 0 || t || r.nextSample >= r.samples.length) && (Log.info("ISOFile", "Sending fragmented data on track #" + i.id + " for samples [" + Math.max(0, r.nextSample - i.nb_samples) + "," + (r.nextSample - 1) + "]"), Log.info("ISOFile", "Sample data size in memory: " + this.getAllocatedSampleDataSize()), this.onSegment && this.onSegment(i.id, i.user, i.segmentStream.buffer, r.nextSample, t || r.nextSample >= r.samples.length), i.segmentStream = null, i !== this.fragmentedTracks[e])) break
|
|
3796
|
+
}
|
|
3797
|
+
if (null !== this.onSamples) for (e = 0; e < this.extractedTracks.length; e++) {
|
|
3798
|
+
var a = this.extractedTracks[e];
|
|
3799
|
+
for (r = a.trak; r.nextSample < r.samples.length && this.sampleProcessingStarted;) {
|
|
3800
|
+
Log.debug("ISOFile", "Exporting on track #" + a.id + " sample #" + r.nextSample);
|
|
3801
|
+
var n = this.getSample(r, r.nextSample);
|
|
3802
|
+
if (!n) {
|
|
3803
|
+
this.setNextSeekPositionFromSample(r.samples[r.nextSample]);
|
|
3804
|
+
break
|
|
3805
|
+
}
|
|
3806
|
+
if (r.nextSample++, a.samples.push(n), (r.nextSample % a.nb_samples == 0 || r.nextSample >= r.samples.length) && (Log.debug("ISOFile", "Sending samples on track #" + a.id + " for sample " + r.nextSample), this.onSamples && this.onSamples(a.id, a.user, a.samples), a.samples = [], a !== this.extractedTracks[e])) break
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
},
|
|
3811
|
+
ISOFile.prototype.getBox = function(t) {
|
|
3812
|
+
t = this.getBoxes(t, !0);
|
|
3813
|
+
return t.length ? t[0] : null
|
|
3814
|
+
},
|
|
3815
|
+
ISOFile.prototype.getBoxes = function(t, e) {
|
|
3816
|
+
var i = [];
|
|
3817
|
+
return ISOFile._sweep.call(this, t, i, e),
|
|
3818
|
+
i
|
|
3819
|
+
},
|
|
3820
|
+
ISOFile._sweep = function(t, e, i) {
|
|
3821
|
+
for (var r in this.type && this.type == t && e.push(this), this.boxes) {
|
|
3822
|
+
if (e.length && i) return;
|
|
3823
|
+
ISOFile._sweep.call(this.boxes[r], t, e, i)
|
|
3824
|
+
}
|
|
3825
|
+
},
|
|
3826
|
+
ISOFile.prototype.getTrackSamplesInfo = function(t) {
|
|
3827
|
+
t = this.getTrackById(t);
|
|
3828
|
+
if (t) return t.samples
|
|
3829
|
+
},
|
|
3830
|
+
ISOFile.prototype.getTrackSample = function(t, e) {
|
|
3831
|
+
t = this.getTrackById(t);
|
|
3832
|
+
return this.getSample(t, e)
|
|
3833
|
+
},
|
|
3834
|
+
ISOFile.prototype.releaseUsedSamples = function(t, e) {
|
|
3835
|
+
var i = 0,
|
|
3836
|
+
r = this.getTrackById(t);
|
|
3837
|
+
r.lastValidSample || (r.lastValidSample = 0);
|
|
3838
|
+
for (var s = r.lastValidSample; s < e; s++) i += this.releaseSample(r, s);
|
|
3839
|
+
Log.info("ISOFile", "Track #" + t + " released samples up to " + e + " (released size: " + i + ", remaining: " + this.samplesDataSize + ")"),
|
|
3840
|
+
r.lastValidSample = e
|
|
3841
|
+
},
|
|
3842
|
+
ISOFile.prototype.start = function() {
|
|
3843
|
+
this.sampleProcessingStarted = !0,
|
|
3844
|
+
this.processSamples(!1)
|
|
3845
|
+
},
|
|
3846
|
+
ISOFile.prototype.stop = function() {
|
|
3847
|
+
this.sampleProcessingStarted = !1
|
|
3848
|
+
},
|
|
3849
|
+
ISOFile.prototype.flush = function() {
|
|
3850
|
+
Log.info("ISOFile", "Flushing remaining samples"),
|
|
3851
|
+
this.updateSampleLists(),
|
|
3852
|
+
this.processSamples(!0),
|
|
3853
|
+
this.stream.cleanBuffers(),
|
|
3854
|
+
this.stream.logBufferLevel(!0)
|
|
3855
|
+
},
|
|
3856
|
+
ISOFile.prototype.seekTrack = function(t, e, i) {
|
|
3857
|
+
var r, s, a, n, o = 0,
|
|
3858
|
+
h = 0;
|
|
3859
|
+
if (0 === i.samples.length) return Log.info("ISOFile", "No sample in track, cannot seek! Using time " + Log.getDurationString(0, 1) + " and offset: 0"),
|
|
3860
|
+
{
|
|
3861
|
+
offset: 0,
|
|
3862
|
+
time: 0
|
|
3863
|
+
};
|
|
3864
|
+
for (r = 0; r < i.samples.length; r++) {
|
|
3865
|
+
if (s = i.samples[r], 0 === r) h = 0,
|
|
3866
|
+
n = s.timescale;
|
|
3867
|
+
else if (s.cts > t * s.timescale) {
|
|
3868
|
+
h = r - 1;
|
|
3869
|
+
break
|
|
3870
|
+
}
|
|
3871
|
+
e && s.is_sync && (o = r)
|
|
3872
|
+
}
|
|
3873
|
+
for (e && (h = o), t = i.samples[h].cts, i.nextSample = h; i.samples[h].alreadyRead === i.samples[h].size && i.samples[h + 1];) h++;
|
|
3874
|
+
return a = i.samples[h].offset + i.samples[h].alreadyRead,
|
|
3875
|
+
Log.info("ISOFile", "Seeking to " + (e ? "RAP": "") + " sample #" + i.nextSample + " on track " + i.tkhd.track_id + ", time " + Log.getDurationString(t, n) + " and offset: " + a),
|
|
3876
|
+
{
|
|
3877
|
+
offset: a,
|
|
3878
|
+
time: t / n
|
|
3879
|
+
}
|
|
3880
|
+
},
|
|
3881
|
+
ISOFile.prototype.getTrackDuration = function(t) {
|
|
3882
|
+
return t.samples ? ((t = t.samples[t.samples.length - 1]).cts + t.duration) / t.timescale: 1 / 0
|
|
3883
|
+
},
|
|
3884
|
+
ISOFile.prototype.seek = function(t, e) {
|
|
3885
|
+
var i, r, s = this.moov,
|
|
3886
|
+
a = {
|
|
3887
|
+
offset: 1 / 0,
|
|
3888
|
+
time: 1 / 0
|
|
3889
|
+
};
|
|
3890
|
+
if (this.moov) {
|
|
3891
|
+
for (r = 0; r < s.traks.length; r++) i = s.traks[r],
|
|
3892
|
+
t > this.getTrackDuration(i) || ((i = this.seekTrack(t, e, i)).offset < a.offset && (a.offset = i.offset), i.time < a.time && (a.time = i.time));
|
|
3893
|
+
return Log.info("ISOFile", "Seeking at time " + Log.getDurationString(a.time, 1) + " needs a buffer with a fileStart position of " + a.offset),
|
|
3894
|
+
a.offset === 1 / 0 ? a = {
|
|
3895
|
+
offset: this.nextParsePosition,
|
|
3896
|
+
time: 0
|
|
3897
|
+
}: a.offset = this.stream.getEndFilePositionAfter(a.offset),
|
|
3898
|
+
Log.info("ISOFile", "Adjusted seek position (after checking data already in buffer): " + a.offset),
|
|
3899
|
+
a
|
|
3900
|
+
}
|
|
3901
|
+
throw "Cannot seek: moov not received!"
|
|
3902
|
+
},
|
|
3903
|
+
ISOFile.prototype.equal = function(t) {
|
|
3904
|
+
for (var e = 0; e < this.boxes.length && e < t.boxes.length;) {
|
|
3905
|
+
var i = this.boxes[e],
|
|
3906
|
+
r = t.boxes[e];
|
|
3907
|
+
if (!BoxParser.boxEqual(i, r)) return ! 1;
|
|
3908
|
+
e++
|
|
3909
|
+
}
|
|
3910
|
+
return ! 0
|
|
3911
|
+
},
|
|
3912
|
+
"undefined" != typeof exports && (exports.ISOFile = ISOFile),
|
|
3913
|
+
ISOFile.prototype.lastBoxStartPosition = 0,
|
|
3914
|
+
ISOFile.prototype.parsingMdat = null,
|
|
3915
|
+
ISOFile.prototype.nextParsePosition = 0,
|
|
3916
|
+
ISOFile.prototype.discardMdatData = !1,
|
|
3917
|
+
ISOFile.prototype.processIncompleteBox = function(t) {
|
|
3918
|
+
var e;
|
|
3919
|
+
return "mdat" === t.type ? (e = new BoxParser[t.type + "Box"](t.size), this.parsingMdat = e, this.boxes.push(e), this.mdats.push(e), e.start = t.start, e.hdr_size = t.hdr_size, this.stream.addUsedBytes(e.hdr_size), this.lastBoxStartPosition = e.start + e.size, this.stream.seek(e.start + e.size, !1, this.discardMdatData) ? !(this.parsingMdat = null) : (this.moovStartFound ? this.nextParsePosition = this.stream.findEndContiguousBuf() : this.nextParsePosition = e.start + e.size, !1)) : ("moov" === t.type && (this.moovStartFound = !0, 0 === this.mdats.length && (this.isProgressive = !0)), !!this.stream.mergeNextBuffer && this.stream.mergeNextBuffer() ? (this.nextParsePosition = this.stream.getEndPosition(), !0) : (!t.type || this.moovStartFound ? this.nextParsePosition = this.stream.getEndPosition() : this.nextParsePosition = this.stream.getPosition() + t.size, !1))
|
|
3920
|
+
},
|
|
3921
|
+
ISOFile.prototype.hasIncompleteMdat = function() {
|
|
3922
|
+
return null !== this.parsingMdat
|
|
3923
|
+
},
|
|
3924
|
+
ISOFile.prototype.processIncompleteMdat = function() {
|
|
3925
|
+
var t = this.parsingMdat;
|
|
3926
|
+
return this.stream.seek(t.start + t.size, !1, this.discardMdatData) ? (Log.debug("ISOFile", "Found 'mdat' end in buffered data"), !(this.parsingMdat = null)) : (this.nextParsePosition = this.stream.findEndContiguousBuf(), !1)
|
|
3927
|
+
},
|
|
3928
|
+
ISOFile.prototype.restoreParsePosition = function() {
|
|
3929
|
+
return this.stream.seek(this.lastBoxStartPosition, !0, this.discardMdatData)
|
|
3930
|
+
},
|
|
3931
|
+
ISOFile.prototype.saveParsePosition = function() {
|
|
3932
|
+
this.lastBoxStartPosition = this.stream.getPosition()
|
|
3933
|
+
},
|
|
3934
|
+
ISOFile.prototype.updateUsedBytes = function(t, e) {
|
|
3935
|
+
this.stream.addUsedBytes && ("mdat" === t.type ? (this.stream.addUsedBytes(t.hdr_size), this.discardMdatData && this.stream.addUsedBytes(t.size - t.hdr_size)) : this.stream.addUsedBytes(t.size))
|
|
3936
|
+
},
|
|
3937
|
+
ISOFile.prototype.add = BoxParser.Box.prototype.add,
|
|
3938
|
+
ISOFile.prototype.addBox = BoxParser.Box.prototype.addBox,
|
|
3939
|
+
ISOFile.prototype.init = function(t) {
|
|
3940
|
+
var e = t || {},
|
|
3941
|
+
t = (this.add("ftyp").set("major_brand", e.brands && e.brands[0] || "iso4").set("minor_version", 0).set("compatible_brands", e.brands || ["iso4"]), this.add("moov"));
|
|
3942
|
+
return t.add("mvhd").set("timescale", e.timescale || 600).set("rate", e.rate || 65536).set("creation_time", 0).set("modification_time", 0).set("duration", e.duration || 0).set("volume", e.width ? 0 : 256).set("matrix", [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824]).set("next_track_id", 1),
|
|
3943
|
+
t.add("mvex"),
|
|
3944
|
+
this
|
|
3945
|
+
},
|
|
3946
|
+
ISOFile.prototype.addTrack = function(t) {
|
|
3947
|
+
this.moov || this.init(t);
|
|
3948
|
+
var e = t || {};
|
|
3949
|
+
e.width = e.width || 320,
|
|
3950
|
+
e.height = e.height || 320,
|
|
3951
|
+
e.id = e.id || this.moov.mvhd.next_track_id,
|
|
3952
|
+
e.type = e.type || "avc1";
|
|
3953
|
+
var i = this.moov.add("trak");
|
|
3954
|
+
this.moov.mvhd.next_track_id = e.id + 1,
|
|
3955
|
+
i.add("tkhd").set("flags", BoxParser.TKHD_FLAG_ENABLED | BoxParser.TKHD_FLAG_IN_MOVIE | BoxParser.TKHD_FLAG_IN_PREVIEW).set("creation_time", 0).set("modification_time", 0).set("track_id", e.id).set("duration", e.duration || 0).set("layer", e.layer || 0).set("alternate_group", 0).set("volume", 1).set("matrix", [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824]).set("width", e.width << 16).set("height", e.height << 16);
|
|
3956
|
+
t = i.add("mdia");
|
|
3957
|
+
t.add("mdhd").set("creation_time", 0).set("modification_time", 0).set("timescale", e.timescale || 1).set("duration", e.media_duration || 0).set("language", e.language || "und"),
|
|
3958
|
+
t.add("hdlr").set("handler", e.hdlr || "vide").set("name", e.name || "Track created with MP4Box.js"),
|
|
3959
|
+
t.add("elng").set("extended_language", e.language || "fr-FR");
|
|
3960
|
+
var r = t.add("minf");
|
|
3961
|
+
if (void 0 !== BoxParser[e.type + "SampleEntry"]) {
|
|
3962
|
+
var s = new BoxParser[e.type + "SampleEntry"];
|
|
3963
|
+
s.data_reference_index = 1;
|
|
3964
|
+
var a, n, o = "";
|
|
3965
|
+
for (a in BoxParser.sampleEntryCodes) for (var h = BoxParser.sampleEntryCodes[a], d = 0; d < h.length; d++) if (-1 < h.indexOf(e.type)) {
|
|
3966
|
+
o = a;
|
|
3967
|
+
break
|
|
3968
|
+
}
|
|
3969
|
+
switch (o) {
|
|
3970
|
+
case "Visual":
|
|
3971
|
+
r.add("vmhd").set("graphicsmode", 0).set("opcolor", [0, 0, 0]),
|
|
3972
|
+
s.set("width", e.width).set("height", e.height).set("horizresolution", 72 << 16).set("vertresolution", 72 << 16).set("frame_count", 1).set("compressorname", e.type + " Compressor").set("depth", 24),
|
|
3973
|
+
e.avcDecoderConfigRecord ? ((n = new BoxParser.avcCBox).parse(new MP4BoxStream(e.avcDecoderConfigRecord)), s.addBox(n)) : e.hevcDecoderConfigRecord && ((n = new BoxParser.hvcCBox).parse(new MP4BoxStream(e.hevcDecoderConfigRecord)), s.addBox(n));
|
|
3974
|
+
break;
|
|
3975
|
+
case "Audio":
|
|
3976
|
+
r.add("smhd").set("balance", e.balance || 0),
|
|
3977
|
+
s.set("channel_count", e.channel_count || 2).set("samplesize", e.samplesize || 16).set("samplerate", e.samplerate || 65536);
|
|
3978
|
+
break;
|
|
3979
|
+
case "Hint":
|
|
3980
|
+
r.add("hmhd");
|
|
3981
|
+
break;
|
|
3982
|
+
case "Subtitle":
|
|
3983
|
+
r.add("sthd"),
|
|
3984
|
+
"stpp" === e.type && s.set("namespace", e.namespace || "nonamespace").set("schema_location", e.schema_location || "").set("auxiliary_mime_types", e.auxiliary_mime_types || "");
|
|
3985
|
+
break;
|
|
3986
|
+
case "Metadata":
|
|
3987
|
+
case "System":
|
|
3988
|
+
default:
|
|
3989
|
+
r.add("nmhd")
|
|
3990
|
+
}
|
|
3991
|
+
e.description && s.addBox(e.description),
|
|
3992
|
+
e.description_boxes && e.description_boxes.forEach(function(t) {
|
|
3993
|
+
s.addBox(t)
|
|
3994
|
+
}),
|
|
3995
|
+
r.add("dinf").add("dref").addEntry((new BoxParser["url Box"]).set("flags", 1));
|
|
3996
|
+
t = r.add("stbl");
|
|
3997
|
+
return t.add("stsd").addEntry(s),
|
|
3998
|
+
t.add("stts").set("sample_counts", []).set("sample_deltas", []),
|
|
3999
|
+
t.add("stsc").set("first_chunk", []).set("samples_per_chunk", []).set("sample_description_index", []),
|
|
4000
|
+
t.add("stco").set("chunk_offsets", []),
|
|
4001
|
+
t.add("stsz").set("sample_sizes", []),
|
|
4002
|
+
this.moov.mvex.add("trex").set("track_id", e.id).set("default_sample_description_index", e.default_sample_description_index || 1).set("default_sample_duration", e.default_sample_duration || 0).set("default_sample_size", e.default_sample_size || 0).set("default_sample_flags", e.default_sample_flags || 0),
|
|
4003
|
+
this.buildTrakSampleLists(i),
|
|
4004
|
+
e.id
|
|
4005
|
+
}
|
|
4006
|
+
},
|
|
4007
|
+
BoxParser.Box.prototype.computeSize = function(t) {
|
|
4008
|
+
t = t || new DataStream;
|
|
4009
|
+
t.endianness = DataStream.BIG_ENDIAN,
|
|
4010
|
+
this.write(t)
|
|
4011
|
+
},
|
|
4012
|
+
ISOFile.prototype.addSample = function(t, e, i) {
|
|
4013
|
+
var r = i || {},
|
|
4014
|
+
i = {},
|
|
4015
|
+
t = this.getTrackById(t);
|
|
4016
|
+
if (null !== t) {
|
|
4017
|
+
i.number = t.samples.length,
|
|
4018
|
+
i.track_id = t.tkhd.track_id,
|
|
4019
|
+
i.timescale = t.mdia.mdhd.timescale,
|
|
4020
|
+
i.description_index = r.sample_description_index ? r.sample_description_index - 1 : 0,
|
|
4021
|
+
i.description = t.mdia.minf.stbl.stsd.entries[i.description_index],
|
|
4022
|
+
i.data = e,
|
|
4023
|
+
i.size = e.byteLength,
|
|
4024
|
+
i.alreadyRead = i.size,
|
|
4025
|
+
i.duration = r.duration || 1,
|
|
4026
|
+
i.cts = r.cts || 0,
|
|
4027
|
+
i.dts = r.dts || 0,
|
|
4028
|
+
i.is_sync = r.is_sync || !1,
|
|
4029
|
+
i.is_leading = r.is_leading || 0,
|
|
4030
|
+
i.depends_on = r.depends_on || 0,
|
|
4031
|
+
i.is_depended_on = r.is_depended_on || 0,
|
|
4032
|
+
i.has_redundancy = r.has_redundancy || 0,
|
|
4033
|
+
i.degradation_priority = r.degradation_priority || 0,
|
|
4034
|
+
i.offset = 0,
|
|
4035
|
+
i.subsamples = r.subsamples,
|
|
4036
|
+
t.samples.push(i),
|
|
4037
|
+
t.samples_size += i.size,
|
|
4038
|
+
t.samples_duration += i.duration,
|
|
4039
|
+
void 0 === t.first_dts && (t.first_dts = r.dts),
|
|
4040
|
+
this.processSamples();
|
|
4041
|
+
r = this.createSingleSampleMoof(i);
|
|
4042
|
+
return this.addBox(r),
|
|
4043
|
+
r.computeSize(),
|
|
4044
|
+
r.trafs[0].truns[0].data_offset = r.size + 8,
|
|
4045
|
+
this.add("mdat").data = new Uint8Array(e),
|
|
4046
|
+
i
|
|
4047
|
+
}
|
|
4048
|
+
},
|
|
4049
|
+
ISOFile.prototype.createSingleSampleMoof = function(t) {
|
|
4050
|
+
var e = 0,
|
|
4051
|
+
e = t.is_sync ? 1 << 25 : 65536,
|
|
4052
|
+
i = new BoxParser.moofBox;
|
|
4053
|
+
i.add("mfhd").set("sequence_number", this.nextMoofNumber),
|
|
4054
|
+
this.nextMoofNumber++;
|
|
4055
|
+
var r = i.add("traf"),
|
|
4056
|
+
s = this.getTrackById(t.track_id);
|
|
4057
|
+
return r.add("tfhd").set("track_id", t.track_id).set("flags", BoxParser.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),
|
|
4058
|
+
r.add("tfdt").set("baseMediaDecodeTime", t.dts - (s.first_dts || 0)),
|
|
4059
|
+
r.add("trun").set("flags", BoxParser.TRUN_FLAGS_DATA_OFFSET | BoxParser.TRUN_FLAGS_DURATION | BoxParser.TRUN_FLAGS_SIZE | BoxParser.TRUN_FLAGS_FLAGS | BoxParser.TRUN_FLAGS_CTS_OFFSET).set("data_offset", 0).set("first_sample_flags", 0).set("sample_count", 1).set("sample_duration", [t.duration]).set("sample_size", [t.size]).set("sample_flags", [e]).set("sample_composition_time_offset", [t.cts - t.dts]),
|
|
4060
|
+
i
|
|
4061
|
+
},
|
|
4062
|
+
ISOFile.prototype.lastMoofIndex = 0,
|
|
4063
|
+
ISOFile.prototype.samplesDataSize = 0,
|
|
4064
|
+
ISOFile.prototype.resetTables = function() {
|
|
4065
|
+
var t, e;
|
|
4066
|
+
for (this.initial_duration = this.moov.mvhd.duration, t = this.moov.mvhd.duration = 0; t < this.moov.traks.length; t++) { (e = this.moov.traks[t]).tkhd.duration = 0,
|
|
4067
|
+
e.mdia.mdhd.duration = 0,
|
|
4068
|
+
(e.mdia.minf.stbl.stco || e.mdia.minf.stbl.co64).chunk_offsets = [],
|
|
4069
|
+
(i = e.mdia.minf.stbl.stsc).first_chunk = [],
|
|
4070
|
+
i.samples_per_chunk = [],
|
|
4071
|
+
i.sample_description_index = [],
|
|
4072
|
+
(e.mdia.minf.stbl.stsz || e.mdia.minf.stbl.stz2).sample_sizes = [],
|
|
4073
|
+
(i = e.mdia.minf.stbl.stts).sample_counts = [],
|
|
4074
|
+
i.sample_deltas = [],
|
|
4075
|
+
(i = e.mdia.minf.stbl.ctts) && (i.sample_counts = [], i.sample_offsets = []),
|
|
4076
|
+
i = e.mdia.minf.stbl.stss;
|
|
4077
|
+
var i = e.mdia.minf.stbl.boxes.indexOf(i); - 1 != i && (e.mdia.minf.stbl.boxes[i] = null)
|
|
4078
|
+
}
|
|
4079
|
+
},
|
|
4080
|
+
ISOFile.initSampleGroups = function(t, e, i, r, s) {
|
|
4081
|
+
var a, n, o, h;
|
|
4082
|
+
function d(t, e, i) {
|
|
4083
|
+
this.grouping_type = t,
|
|
4084
|
+
this.grouping_type_parameter = e,
|
|
4085
|
+
this.sbgp = i,
|
|
4086
|
+
this.last_sample_in_run = -1,
|
|
4087
|
+
this.entry_index = -1
|
|
4088
|
+
}
|
|
4089
|
+
for (e && (e.sample_groups_info = []), t.sample_groups_info || (t.sample_groups_info = []), n = 0; n < i.length; n++) {
|
|
4090
|
+
for (h = i[n].grouping_type + "/" + i[n].grouping_type_parameter, o = new d(i[n].grouping_type, i[n].grouping_type_parameter, i[n]), e && (e.sample_groups_info[h] = o), t.sample_groups_info[h] || (t.sample_groups_info[h] = o), a = 0; a < r.length; a++) r[a].grouping_type === i[n].grouping_type && (o.description = r[a], o.description.used = !0);
|
|
4091
|
+
if (s) for (a = 0; a < s.length; a++) s[a].grouping_type === i[n].grouping_type && (o.fragment_description = s[a], o.fragment_description.used = !0, o.is_fragment = !0)
|
|
4092
|
+
}
|
|
4093
|
+
if (e) {
|
|
4094
|
+
if (s) for (n = 0; n < s.length; n++) ! s[n].used && 2 <= s[n].version && (h = s[n].grouping_type + "/0", (o = new d(s[n].grouping_type, 0)).is_fragment = !0, e.sample_groups_info[h] || (e.sample_groups_info[h] = o))
|
|
4095
|
+
} else for (n = 0; n < r.length; n++) ! r[n].used && 2 <= r[n].version && (h = r[n].grouping_type + "/0", o = new d(r[n].grouping_type, 0), t.sample_groups_info[h] || (t.sample_groups_info[h] = o))
|
|
4096
|
+
},
|
|
4097
|
+
ISOFile.setSampleGroupProperties = function(t, e, i, r) {
|
|
4098
|
+
var s, a, n;
|
|
4099
|
+
for (s in e.sample_groups = [], r) e.sample_groups[s] = {},
|
|
4100
|
+
e.sample_groups[s].grouping_type = r[s].grouping_type,
|
|
4101
|
+
e.sample_groups[s].grouping_type_parameter = r[s].grouping_type_parameter,
|
|
4102
|
+
i >= r[s].last_sample_in_run && (r[s].last_sample_in_run < 0 && (r[s].last_sample_in_run = 0), r[s].entry_index++, r[s].entry_index <= r[s].sbgp.entries.length - 1 && (r[s].last_sample_in_run += r[s].sbgp.entries[r[s].entry_index].sample_count)),
|
|
4103
|
+
r[s].entry_index <= r[s].sbgp.entries.length - 1 ? e.sample_groups[s].group_description_index = r[s].sbgp.entries[r[s].entry_index].group_description_index: e.sample_groups[s].group_description_index = -1,
|
|
4104
|
+
0 !== e.sample_groups[s].group_description_index && (n = r[s].fragment_description || r[s].description, 0 < e.sample_groups[s].group_description_index ? (a = 65535 < e.sample_groups[s].group_description_index ? (e.sample_groups[s].group_description_index >> 16) - 1 : e.sample_groups[s].group_description_index - 1, n && 0 <= a && (e.sample_groups[s].description = n.entries[a])) : n && 2 <= n.version && 0 < n.default_group_description_index && (e.sample_groups[s].description = n.entries[n.default_group_description_index - 1]))
|
|
4105
|
+
},
|
|
4106
|
+
ISOFile.process_sdtp = function(t, e, i) {
|
|
4107
|
+
e && (t ? (e.is_leading = t.is_leading[i], e.depends_on = t.sample_depends_on[i], e.is_depended_on = t.sample_is_depended_on[i], e.has_redundancy = t.sample_has_redundancy[i]) : (e.is_leading = 0, e.depends_on = 0, e.is_depended_on = 0, e.has_redundancy = 0))
|
|
4108
|
+
},
|
|
4109
|
+
ISOFile.prototype.buildSampleLists = function() {
|
|
4110
|
+
for (var t, e = 0; e < this.moov.traks.length; e++) t = this.moov.traks[e],
|
|
4111
|
+
this.buildTrakSampleLists(t)
|
|
4112
|
+
},
|
|
4113
|
+
ISOFile.prototype.buildTrakSampleLists = function(t) {
|
|
4114
|
+
var e, i, r, s, a, n, o, h, d, l, p, f, u, _, c, m, x, g, y, B, S, P, U, b;
|
|
4115
|
+
if (t.samples = [], t.samples_duration = 0, t.samples_size = 0, i = t.mdia.minf.stbl.stco || t.mdia.minf.stbl.co64, r = t.mdia.minf.stbl.stsc, s = t.mdia.minf.stbl.stsz || t.mdia.minf.stbl.stz2, a = t.mdia.minf.stbl.stts, n = t.mdia.minf.stbl.ctts, o = t.mdia.minf.stbl.stss, h = t.mdia.minf.stbl.stsd, d = t.mdia.minf.stbl.subs, f = t.mdia.minf.stbl.stdp, l = t.mdia.minf.stbl.sbgps, p = t.mdia.minf.stbl.sgpds, S = B = y = g = -1, b = U = P = 0, ISOFile.initSampleGroups(t, null, l, p), void 0 !== s) {
|
|
4116
|
+
for (e = 0; e < s.sample_sizes.length; e++) {
|
|
4117
|
+
var v = {};
|
|
4118
|
+
v.number = e,
|
|
4119
|
+
v.track_id = t.tkhd.track_id,
|
|
4120
|
+
v.timescale = t.mdia.mdhd.timescale,
|
|
4121
|
+
v.alreadyRead = 0,
|
|
4122
|
+
(t.samples[e] = v).size = s.sample_sizes[e],
|
|
4123
|
+
t.samples_size += v.size,
|
|
4124
|
+
0 === e ? (_ = 1, u = 0, v.chunk_index = _, v.chunk_run_index = u, x = r.samples_per_chunk[u], m = 0, c = u + 1 < r.first_chunk.length ? r.first_chunk[u + 1] - 1 : 1 / 0) : e < x ? (v.chunk_index = _, v.chunk_run_index = u) : (_++, m = 0, (v.chunk_index = _) <= c || (c = ++u + 1 < r.first_chunk.length ? r.first_chunk[u + 1] - 1 : 1 / 0), v.chunk_run_index = u, x += r.samples_per_chunk[u]),
|
|
4125
|
+
v.description_index = r.sample_description_index[v.chunk_run_index] - 1,
|
|
4126
|
+
v.description = h.entries[v.description_index],
|
|
4127
|
+
v.offset = i.chunk_offsets[v.chunk_index - 1] + m,
|
|
4128
|
+
m += v.size,
|
|
4129
|
+
g < e && (y++, g < 0 && (g = 0), g += a.sample_counts[y]),
|
|
4130
|
+
0 < e ? (t.samples[e - 1].duration = a.sample_deltas[y], t.samples_duration += t.samples[e - 1].duration, v.dts = t.samples[e - 1].dts + t.samples[e - 1].duration) : v.dts = 0,
|
|
4131
|
+
n ? (B <= e && (S++, B < 0 && (B = 0), B += n.sample_counts[S]), v.cts = t.samples[e].dts + n.sample_offsets[S]) : v.cts = v.dts,
|
|
4132
|
+
o ? (e == o.sample_numbers[P] - 1 ? (v.is_sync = !0, P++) : (v.is_sync = !1, v.degradation_priority = 0), d && d.entries[U].sample_delta + b == e + 1 && (v.subsamples = d.entries[U].subsamples, b += d.entries[U].sample_delta, U++)) : v.is_sync = !0,
|
|
4133
|
+
ISOFile.process_sdtp(t.mdia.minf.stbl.sdtp, v, v.number),
|
|
4134
|
+
v.degradation_priority = f ? f.priority[e] : 0,
|
|
4135
|
+
d && d.entries[U].sample_delta + b == e && (v.subsamples = d.entries[U].subsamples, b += d.entries[U].sample_delta),
|
|
4136
|
+
(0 < l.length || 0 < p.length) && ISOFile.setSampleGroupProperties(t, v, e, t.sample_groups_info)
|
|
4137
|
+
}
|
|
4138
|
+
0 < e && (t.samples[e - 1].duration = Math.max(t.mdia.mdhd.duration - t.samples[e - 1].dts, 0), t.samples_duration += t.samples[e - 1].duration)
|
|
4139
|
+
}
|
|
4140
|
+
},
|
|
4141
|
+
ISOFile.prototype.updateSampleLists = function() {
|
|
4142
|
+
var t, e, i, r, s, a, n, o, h, d, l, p;
|
|
4143
|
+
if (void 0 !== this.moov) for (; this.lastMoofIndex < this.moofs.length;) if (n = this.moofs[this.lastMoofIndex], this.lastMoofIndex++, "moof" == n.type) for (o = n, t = 0; t < o.trafs.length; t++) {
|
|
4144
|
+
for (h = o.trafs[t], d = this.getTrackById(h.tfhd.track_id), l = this.getTrexById(h.tfhd.track_id), e = h.tfhd.flags & BoxParser.TFHD_FLAG_SAMPLE_DESC ? h.tfhd.default_sample_description_index: l ? l.default_sample_description_index: 1, i = h.tfhd.flags & BoxParser.TFHD_FLAG_SAMPLE_DUR ? h.tfhd.default_sample_duration: l ? l.default_sample_duration: 0, r = h.tfhd.flags & BoxParser.TFHD_FLAG_SAMPLE_SIZE ? h.tfhd.default_sample_size: l ? l.default_sample_size: 0, s = h.tfhd.flags & BoxParser.TFHD_FLAG_SAMPLE_FLAGS ? h.tfhd.default_sample_flags: l ? l.default_sample_flags: 0, (h.sample_number = 0) < h.sbgps.length && ISOFile.initSampleGroups(d, h, h.sbgps, d.mdia.minf.stbl.sgpds, h.sgpds), y = 0; y < h.truns.length; y++) for (var f = h.truns[y], u = 0; u < f.sample_count; u++) { (p = {}).moof_number = this.lastMoofIndex,
|
|
4145
|
+
p.number_in_traf = h.sample_number,
|
|
4146
|
+
h.sample_number++,
|
|
4147
|
+
p.number = d.samples.length,
|
|
4148
|
+
h.first_sample_index = d.samples.length,
|
|
4149
|
+
d.samples.push(p),
|
|
4150
|
+
p.track_id = d.tkhd.track_id,
|
|
4151
|
+
p.timescale = d.mdia.mdhd.timescale,
|
|
4152
|
+
p.description_index = e - 1,
|
|
4153
|
+
p.description = d.mdia.minf.stbl.stsd.entries[p.description_index],
|
|
4154
|
+
p.size = r,
|
|
4155
|
+
f.flags & BoxParser.TRUN_FLAGS_SIZE && (p.size = f.sample_size[u]),
|
|
4156
|
+
d.samples_size += p.size,
|
|
4157
|
+
p.duration = i,
|
|
4158
|
+
f.flags & BoxParser.TRUN_FLAGS_DURATION && (p.duration = f.sample_duration[u]),
|
|
4159
|
+
d.samples_duration += p.duration,
|
|
4160
|
+
d.first_traf_merged || 0 < u ? p.dts = d.samples[d.samples.length - 2].dts + d.samples[d.samples.length - 2].duration: (h.tfdt ? p.dts = h.tfdt.baseMediaDecodeTime: p.dts = 0, d.first_traf_merged = !0),
|
|
4161
|
+
p.cts = p.dts,
|
|
4162
|
+
f.flags & BoxParser.TRUN_FLAGS_CTS_OFFSET && (p.cts = p.dts + f.sample_composition_time_offset[u]),
|
|
4163
|
+
x = s,
|
|
4164
|
+
f.flags & BoxParser.TRUN_FLAGS_FLAGS ? x = f.sample_flags[u] : 0 === u && f.flags & BoxParser.TRUN_FLAGS_FIRST_FLAG && (x = f.first_sample_flags),
|
|
4165
|
+
p.is_sync = !(x >> 16 & 1),
|
|
4166
|
+
p.is_leading = x >> 26 & 3,
|
|
4167
|
+
p.depends_on = x >> 24 & 3,
|
|
4168
|
+
p.is_depended_on = x >> 22 & 3,
|
|
4169
|
+
p.has_redundancy = x >> 20 & 3,
|
|
4170
|
+
p.degradation_priority = 65535 & x;
|
|
4171
|
+
var _ = !!(h.tfhd.flags & BoxParser.TFHD_FLAG_BASE_DATA_OFFSET),
|
|
4172
|
+
c = !!(h.tfhd.flags & BoxParser.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),
|
|
4173
|
+
m = !!(f.flags & BoxParser.TRUN_FLAGS_DATA_OFFSET),
|
|
4174
|
+
x = 0,
|
|
4175
|
+
x = _ ? h.tfhd.base_data_offset: c || 0 === y ? o.start: a;
|
|
4176
|
+
p.offset = 0 === y && 0 === u ? m ? x + f.data_offset: x: a,
|
|
4177
|
+
a = p.offset + p.size,
|
|
4178
|
+
(0 < h.sbgps.length || 0 < h.sgpds.length || 0 < d.mdia.minf.stbl.sbgps.length || 0 < d.mdia.minf.stbl.sgpds.length) && ISOFile.setSampleGroupProperties(d, p, p.number_in_traf, h.sample_groups_info)
|
|
4179
|
+
}
|
|
4180
|
+
if (h.subs) {
|
|
4181
|
+
d.has_fragment_subsamples = !0;
|
|
4182
|
+
for (var g = h.first_sample_index,
|
|
4183
|
+
y = 0; y < h.subs.entries.length; y++) g += h.subs.entries[y].sample_delta,
|
|
4184
|
+
(p = d.samples[g - 1]).subsamples = h.subs.entries[y].subsamples
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4187
|
+
},
|
|
4188
|
+
ISOFile.prototype.getSample = function(t, e) {
|
|
4189
|
+
var i, r = t.samples[e];
|
|
4190
|
+
if (!this.moov) return null;
|
|
4191
|
+
if (r.data) {
|
|
4192
|
+
if (r.alreadyRead == r.size) return r
|
|
4193
|
+
} else r.data = new Uint8Array(r.size),
|
|
4194
|
+
r.alreadyRead = 0,
|
|
4195
|
+
this.samplesDataSize += r.size,
|
|
4196
|
+
Log.debug("ISOFile", "Allocating sample #" + e + " on track #" + t.tkhd.track_id + " of size " + r.size + " (total: " + this.samplesDataSize + ")");
|
|
4197
|
+
for (;;) {
|
|
4198
|
+
var s = this.stream.findPosition(!0, r.offset + r.alreadyRead, !1);
|
|
4199
|
+
if (! (-1 < s)) return null;
|
|
4200
|
+
s = (i = this.stream.buffers[s]).byteLength - (r.offset + r.alreadyRead - i.fileStart);
|
|
4201
|
+
if (r.size - r.alreadyRead <= s) return Log.debug("ISOFile", "Getting sample #" + e + " data (alreadyRead: " + r.alreadyRead + " offset: " + (r.offset + r.alreadyRead - i.fileStart) + " read size: " + (r.size - r.alreadyRead) + " full size: " + r.size + ")"),
|
|
4202
|
+
DataStream.memcpy(r.data.buffer, r.alreadyRead, i, r.offset + r.alreadyRead - i.fileStart, r.size - r.alreadyRead),
|
|
4203
|
+
i.usedBytes += r.size - r.alreadyRead,
|
|
4204
|
+
this.stream.logBufferLevel(),
|
|
4205
|
+
r.alreadyRead = r.size,
|
|
4206
|
+
r;
|
|
4207
|
+
if (0 == s) return null;
|
|
4208
|
+
Log.debug("ISOFile", "Getting sample #" + e + " partial data (alreadyRead: " + r.alreadyRead + " offset: " + (r.offset + r.alreadyRead - i.fileStart) + " read size: " + s + " full size: " + r.size + ")"),
|
|
4209
|
+
DataStream.memcpy(r.data.buffer, r.alreadyRead, i, r.offset + r.alreadyRead - i.fileStart, s),
|
|
4210
|
+
r.alreadyRead += s,
|
|
4211
|
+
i.usedBytes += s,
|
|
4212
|
+
this.stream.logBufferLevel()
|
|
4213
|
+
}
|
|
4214
|
+
},
|
|
4215
|
+
ISOFile.prototype.releaseSample = function(t, e) {
|
|
4216
|
+
e = t.samples[e];
|
|
4217
|
+
return e.data ? (this.samplesDataSize -= e.size, e.data = null, e.alreadyRead = 0, e.size) : 0
|
|
4218
|
+
},
|
|
4219
|
+
ISOFile.prototype.getAllocatedSampleDataSize = function() {
|
|
4220
|
+
return this.samplesDataSize
|
|
4221
|
+
},
|
|
4222
|
+
ISOFile.prototype.getCodecs = function() {
|
|
4223
|
+
for (var t = "",
|
|
4224
|
+
e = 0; e < this.moov.traks.length; e++) 0 < e && (t += ","),
|
|
4225
|
+
t += this.moov.traks[e].mdia.minf.stbl.stsd.entries[0].getCodec();
|
|
4226
|
+
return t
|
|
4227
|
+
},
|
|
4228
|
+
ISOFile.prototype.getTrexById = function(t) {
|
|
4229
|
+
var e;
|
|
4230
|
+
if (!this.moov || !this.moov.mvex) return null;
|
|
4231
|
+
for (e = 0; e < this.moov.mvex.trexs.length; e++) {
|
|
4232
|
+
var i = this.moov.mvex.trexs[e];
|
|
4233
|
+
if (i.track_id == t) return i
|
|
4234
|
+
}
|
|
4235
|
+
return null
|
|
4236
|
+
},
|
|
4237
|
+
ISOFile.prototype.getTrackById = function(t) {
|
|
4238
|
+
if (void 0 === this.moov) return null;
|
|
4239
|
+
for (var e = 0; e < this.moov.traks.length; e++) {
|
|
4240
|
+
var i = this.moov.traks[e];
|
|
4241
|
+
if (i.tkhd.track_id == t) return i
|
|
4242
|
+
}
|
|
4243
|
+
return null
|
|
4244
|
+
},
|
|
4245
|
+
ISOFile.prototype.itemsDataSize = 0,
|
|
4246
|
+
ISOFile.prototype.flattenItemInfo = function() {
|
|
4247
|
+
var t = this.items,
|
|
4248
|
+
e = this.entity_groups,
|
|
4249
|
+
i = this.meta;
|
|
4250
|
+
if (null != i && void 0 !== i.hdlr && void 0 !== i.iinf) {
|
|
4251
|
+
for (d = 0; d < i.iinf.item_infos.length; d++)(s = {}).id = i.iinf.item_infos[d].item_ID,
|
|
4252
|
+
(t[s.id] = s).ref_to = [],
|
|
4253
|
+
s.name = i.iinf.item_infos[d].item_name,
|
|
4254
|
+
0 < i.iinf.item_infos[d].protection_index && (s.protection = i.ipro.protections[i.iinf.item_infos[d].protection_index - 1]),
|
|
4255
|
+
i.iinf.item_infos[d].item_type ? s.type = i.iinf.item_infos[d].item_type: s.type = "mime",
|
|
4256
|
+
s.content_type = i.iinf.item_infos[d].content_type,
|
|
4257
|
+
s.content_encoding = i.iinf.item_infos[d].content_encoding,
|
|
4258
|
+
s.item_uri_type = i.iinf.item_infos[d].item_uri_type;
|
|
4259
|
+
if (i.grpl) for (d = 0; d < i.grpl.boxes.length; d++) entity_group = {},
|
|
4260
|
+
entity_group.id = i.grpl.boxes[d].group_id,
|
|
4261
|
+
entity_group.entity_ids = i.grpl.boxes[d].entity_ids,
|
|
4262
|
+
entity_group.type = i.grpl.boxes[d].type,
|
|
4263
|
+
e[entity_group.id] = entity_group;
|
|
4264
|
+
if (i.iloc) for (d = 0; d < i.iloc.items.length; d++) {
|
|
4265
|
+
var r = i.iloc.items[d],
|
|
4266
|
+
s = t[r.item_ID];
|
|
4267
|
+
switch (0 !== r.data_reference_index && (Log.warn("Item storage with reference to other files: not supported"), s.source = i.dinf.boxes[r.data_reference_index - 1]), r.construction_method) {
|
|
4268
|
+
case 0:
|
|
4269
|
+
case 1:
|
|
4270
|
+
break;
|
|
4271
|
+
case 2:
|
|
4272
|
+
Log.warn("Item storage with construction_method : not supported")
|
|
4273
|
+
}
|
|
4274
|
+
for (s.extents = [], n = s.size = 0; n < r.extents.length; n++) s.extents[n] = {},
|
|
4275
|
+
s.extents[n].offset = r.extents[n].extent_offset + r.base_offset,
|
|
4276
|
+
1 == r.construction_method && (s.extents[n].offset += i.idat.start + i.idat.hdr_size),
|
|
4277
|
+
s.extents[n].length = r.extents[n].extent_length,
|
|
4278
|
+
s.extents[n].alreadyRead = 0,
|
|
4279
|
+
s.size += s.extents[n].length
|
|
4280
|
+
}
|
|
4281
|
+
if (i.pitm && (t[i.pitm.item_id].primary = !0), i.iref) for (d = 0; d < i.iref.references.length; d++) for (var a = i.iref.references[d], n = 0; n < a.references.length; n++) t[a.from_item_ID].ref_to.push({
|
|
4282
|
+
type: a.type,
|
|
4283
|
+
id: a.references[n]
|
|
4284
|
+
});
|
|
4285
|
+
if (i.iprp) for (var o = 0; o < i.iprp.ipmas.length; o++) for (var h = i.iprp.ipmas[o], d = 0; d < h.associations.length; d++) {
|
|
4286
|
+
var l = h.associations[d];
|
|
4287
|
+
if (s = (s = t[l.id]) || e[l.id]) for (void 0 === s.properties && (s.properties = {},
|
|
4288
|
+
s.properties.boxes = []), n = 0; n < l.props.length; n++) {
|
|
4289
|
+
var p = l.props[n];
|
|
4290
|
+
0 < p.property_index && p.property_index - 1 < i.iprp.ipco.boxes.length && (p = i.iprp.ipco.boxes[p.property_index - 1], s.properties[p.type] = p, s.properties.boxes.push(p))
|
|
4291
|
+
}
|
|
4292
|
+
}
|
|
4293
|
+
}
|
|
4294
|
+
},
|
|
4295
|
+
ISOFile.prototype.getItem = function(t) {
|
|
4296
|
+
var e, i;
|
|
4297
|
+
if (!this.meta) return null;
|
|
4298
|
+
if (! (i = this.items[t]).data && i.size) i.data = new Uint8Array(i.size),
|
|
4299
|
+
i.alreadyRead = 0,
|
|
4300
|
+
this.itemsDataSize += i.size,
|
|
4301
|
+
Log.debug("ISOFile", "Allocating item #" + t + " of size " + i.size + " (total: " + this.itemsDataSize + ")");
|
|
4302
|
+
else if (i.alreadyRead === i.size) return i;
|
|
4303
|
+
for (var r = 0; r < i.extents.length; r++) {
|
|
4304
|
+
var s = i.extents[r];
|
|
4305
|
+
if (s.alreadyRead !== s.length) {
|
|
4306
|
+
var a = this.stream.findPosition(!0, s.offset + s.alreadyRead, !1);
|
|
4307
|
+
if (! (-1 < a)) return null;
|
|
4308
|
+
a = (e = this.stream.buffers[a]).byteLength - (s.offset + s.alreadyRead - e.fileStart);
|
|
4309
|
+
if (! (s.length - s.alreadyRead <= a)) return Log.debug("ISOFile", "Getting item #" + t + " extent #" + r + " partial data (alreadyRead: " + s.alreadyRead + " offset: " + (s.offset + s.alreadyRead - e.fileStart) + " read size: " + a + " full extent size: " + s.length + " full item size: " + i.size + ")"),
|
|
4310
|
+
DataStream.memcpy(i.data.buffer, i.alreadyRead, e, s.offset + s.alreadyRead - e.fileStart, a),
|
|
4311
|
+
s.alreadyRead += a,
|
|
4312
|
+
i.alreadyRead += a,
|
|
4313
|
+
e.usedBytes += a,
|
|
4314
|
+
this.stream.logBufferLevel(),
|
|
4315
|
+
null;
|
|
4316
|
+
Log.debug("ISOFile", "Getting item #" + t + " extent #" + r + " data (alreadyRead: " + s.alreadyRead + " offset: " + (s.offset + s.alreadyRead - e.fileStart) + " read size: " + (s.length - s.alreadyRead) + " full extent size: " + s.length + " full item size: " + i.size + ")"),
|
|
4317
|
+
DataStream.memcpy(i.data.buffer, i.alreadyRead, e, s.offset + s.alreadyRead - e.fileStart, s.length - s.alreadyRead),
|
|
4318
|
+
e.usedBytes += s.length - s.alreadyRead,
|
|
4319
|
+
this.stream.logBufferLevel(),
|
|
4320
|
+
i.alreadyRead += s.length - s.alreadyRead,
|
|
4321
|
+
s.alreadyRead = s.length
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
return i.alreadyRead === i.size ? i: null
|
|
4325
|
+
},
|
|
4326
|
+
ISOFile.prototype.releaseItem = function(t) {
|
|
4327
|
+
var e = this.items[t];
|
|
4328
|
+
if (e.data) {
|
|
4329
|
+
this.itemsDataSize -= e.size,
|
|
4330
|
+
e.data = null;
|
|
4331
|
+
for (var i = e.alreadyRead = 0; i < e.extents.length; i++) e.extents[i].alreadyRead = 0;
|
|
4332
|
+
return e.size
|
|
4333
|
+
}
|
|
4334
|
+
return 0
|
|
4335
|
+
},
|
|
4336
|
+
ISOFile.prototype.processItems = function(t) {
|
|
4337
|
+
for (var e in this.items) {
|
|
4338
|
+
var i = this.items[e];
|
|
4339
|
+
this.getItem(i.id),
|
|
4340
|
+
t && !i.sent && (t(i), i.sent = !0, i.data = null)
|
|
4341
|
+
}
|
|
4342
|
+
},
|
|
4343
|
+
ISOFile.prototype.hasItem = function(t) {
|
|
4344
|
+
for (var e in this.items) {
|
|
4345
|
+
var i = this.items[e];
|
|
4346
|
+
if (i.name === t) return i.id
|
|
4347
|
+
}
|
|
4348
|
+
return - 1
|
|
4349
|
+
},
|
|
4350
|
+
ISOFile.prototype.getMetaHandler = function() {
|
|
4351
|
+
return this.meta ? this.meta.hdlr.handler: null
|
|
4352
|
+
},
|
|
4353
|
+
ISOFile.prototype.getPrimaryItem = function() {
|
|
4354
|
+
return this.meta && this.meta.pitm ? this.getItem(this.meta.pitm.item_id) : null
|
|
4355
|
+
},
|
|
4356
|
+
ISOFile.prototype.itemToFragmentedTrackFile = function(t) {
|
|
4357
|
+
var e = t || {},
|
|
4358
|
+
i = null;
|
|
4359
|
+
if (null == (i = e.itemId ? this.getItem(e.itemId) : this.getPrimaryItem())) return null;
|
|
4360
|
+
t = new ISOFile;
|
|
4361
|
+
t.discardMdatData = !1;
|
|
4362
|
+
e = {
|
|
4363
|
+
type: i.type,
|
|
4364
|
+
description_boxes: i.properties.boxes
|
|
4365
|
+
};
|
|
4366
|
+
i.properties.ispe && (e.width = i.properties.ispe.image_width, e.height = i.properties.ispe.image_height);
|
|
4367
|
+
e = t.addTrack(e);
|
|
4368
|
+
return e ? (t.addSample(e, i.data), t) : null
|
|
4369
|
+
},
|
|
4370
|
+
ISOFile.prototype.write = function(t) {
|
|
4371
|
+
for (var e = 0; e < this.boxes.length; e++) this.boxes[e].write(t)
|
|
4372
|
+
},
|
|
4373
|
+
ISOFile.prototype.createFragment = function(t, e, i) {
|
|
4374
|
+
var r = this.getTrackById(t),
|
|
4375
|
+
t = this.getSample(r, e);
|
|
4376
|
+
if (null == t) return this.setNextSeekPositionFromSample(r.samples[e]),
|
|
4377
|
+
null;
|
|
4378
|
+
e = i || new DataStream;
|
|
4379
|
+
e.endianness = DataStream.BIG_ENDIAN;
|
|
4380
|
+
i = this.createSingleSampleMoof(t);
|
|
4381
|
+
i.write(e),
|
|
4382
|
+
i.trafs[0].truns[0].data_offset = i.size + 8,
|
|
4383
|
+
Log.debug("MP4Box", "Adjusting data_offset with new value " + i.trafs[0].truns[0].data_offset),
|
|
4384
|
+
e.adjustUint32(i.trafs[0].truns[0].data_offset_position, i.trafs[0].truns[0].data_offset);
|
|
4385
|
+
i = new BoxParser.mdatBox;
|
|
4386
|
+
return i.data = t.data,
|
|
4387
|
+
i.write(e),
|
|
4388
|
+
e
|
|
4389
|
+
},
|
|
4390
|
+
ISOFile.writeInitializationSegment = function(t, e, i, r) {
|
|
4391
|
+
var s;
|
|
4392
|
+
Log.debug("ISOFile", "Generating initialization segment");
|
|
4393
|
+
var a = new DataStream;
|
|
4394
|
+
a.endianness = DataStream.BIG_ENDIAN,
|
|
4395
|
+
t.write(a);
|
|
4396
|
+
var n = e.add("mvex");
|
|
4397
|
+
for (i && n.add("mehd").set("fragment_duration", i), s = 0; s < e.traks.length; s++) n.add("trex").set("track_id", e.traks[s].tkhd.track_id).set("default_sample_description_index", 1).set("default_sample_duration", r).set("default_sample_size", 0).set("default_sample_flags", 65536);
|
|
4398
|
+
return e.write(a),
|
|
4399
|
+
a.buffer
|
|
4400
|
+
},
|
|
4401
|
+
ISOFile.prototype.save = function(t) {
|
|
4402
|
+
var e = new DataStream;
|
|
4403
|
+
e.endianness = DataStream.BIG_ENDIAN,
|
|
4404
|
+
this.write(e),
|
|
4405
|
+
e.save(t)
|
|
4406
|
+
},
|
|
4407
|
+
ISOFile.prototype.getBuffer = function() {
|
|
4408
|
+
var t = new DataStream;
|
|
4409
|
+
return t.endianness = DataStream.BIG_ENDIAN,
|
|
4410
|
+
this.write(t),
|
|
4411
|
+
t.buffer
|
|
4412
|
+
},
|
|
4413
|
+
ISOFile.prototype.initializeSegmentation = function() {
|
|
4414
|
+
var t, e, i, r;
|
|
4415
|
+
for (null === this.onSegment && Log.warn("MP4Box", "No segmentation callback set!"), this.isFragmentationInitialized || (this.isFragmentationInitialized = !0, this.nextMoofNumber = 0, this.resetTables()), e = [], t = 0; t < this.fragmentedTracks.length; t++) {
|
|
4416
|
+
var s = new BoxParser.moovBox;
|
|
4417
|
+
s.mvhd = this.moov.mvhd,
|
|
4418
|
+
s.boxes.push(s.mvhd),
|
|
4419
|
+
i = this.getTrackById(this.fragmentedTracks[t].id),
|
|
4420
|
+
s.boxes.push(i),
|
|
4421
|
+
s.traks.push(i),
|
|
4422
|
+
(r = {}).id = i.tkhd.track_id,
|
|
4423
|
+
r.user = this.fragmentedTracks[t].user,
|
|
4424
|
+
r.buffer = ISOFile.writeInitializationSegment(this.ftyp, s, this.moov.mvex && this.moov.mvex.mehd ? this.moov.mvex.mehd.fragment_duration: void 0, 0 < this.moov.traks[t].samples.length ? this.moov.traks[t].samples[0].duration: 0),
|
|
4425
|
+
e.push(r)
|
|
4426
|
+
}
|
|
4427
|
+
return e
|
|
4428
|
+
},
|
|
4429
|
+
BoxParser.Box.prototype.printHeader = function(t) {
|
|
4430
|
+
this.size += 8,
|
|
4431
|
+
this.size > MAX_SIZE && (this.size += 8),
|
|
4432
|
+
"uuid" === this.type && (this.size += 16),
|
|
4433
|
+
t.log(t.indent + "size:" + this.size),
|
|
4434
|
+
t.log(t.indent + "type:" + this.type)
|
|
4435
|
+
},
|
|
4436
|
+
BoxParser.FullBox.prototype.printHeader = function(t) {
|
|
4437
|
+
this.size += 4,
|
|
4438
|
+
BoxParser.Box.prototype.printHeader.call(this, t),
|
|
4439
|
+
t.log(t.indent + "version:" + this.version),
|
|
4440
|
+
t.log(t.indent + "flags:" + this.flags)
|
|
4441
|
+
},
|
|
4442
|
+
BoxParser.Box.prototype.print = function(t) {
|
|
4443
|
+
this.printHeader(t)
|
|
4444
|
+
},
|
|
4445
|
+
BoxParser.ContainerBox.prototype.print = function(t) {
|
|
4446
|
+
this.printHeader(t);
|
|
4447
|
+
for (var e, i = 0; i < this.boxes.length; i++) this.boxes[i] && (e = t.indent, t.indent += " ", this.boxes[i].print(t), t.indent = e)
|
|
4448
|
+
},
|
|
4449
|
+
ISOFile.prototype.print = function(t) {
|
|
4450
|
+
t.indent = "";
|
|
4451
|
+
for (var e = 0; e < this.boxes.length; e++) this.boxes[e] && this.boxes[e].print(t)
|
|
4452
|
+
},
|
|
4453
|
+
BoxParser.mvhdBox.prototype.print = function(t) {
|
|
4454
|
+
BoxParser.FullBox.prototype.printHeader.call(this, t),
|
|
4455
|
+
t.log(t.indent + "creation_time: " + this.creation_time),
|
|
4456
|
+
t.log(t.indent + "modification_time: " + this.modification_time),
|
|
4457
|
+
t.log(t.indent + "timescale: " + this.timescale),
|
|
4458
|
+
t.log(t.indent + "duration: " + this.duration),
|
|
4459
|
+
t.log(t.indent + "rate: " + this.rate),
|
|
4460
|
+
t.log(t.indent + "volume: " + (this.volume >> 8)),
|
|
4461
|
+
t.log(t.indent + "matrix: " + this.matrix.join(", ")),
|
|
4462
|
+
t.log(t.indent + "next_track_id: " + this.next_track_id)
|
|
4463
|
+
},
|
|
4464
|
+
BoxParser.tkhdBox.prototype.print = function(t) {
|
|
4465
|
+
BoxParser.FullBox.prototype.printHeader.call(this, t),
|
|
4466
|
+
t.log(t.indent + "creation_time: " + this.creation_time),
|
|
4467
|
+
t.log(t.indent + "modification_time: " + this.modification_time),
|
|
4468
|
+
t.log(t.indent + "track_id: " + this.track_id),
|
|
4469
|
+
t.log(t.indent + "duration: " + this.duration),
|
|
4470
|
+
t.log(t.indent + "volume: " + (this.volume >> 8)),
|
|
4471
|
+
t.log(t.indent + "matrix: " + this.matrix.join(", ")),
|
|
4472
|
+
t.log(t.indent + "layer: " + this.layer),
|
|
4473
|
+
t.log(t.indent + "alternate_group: " + this.alternate_group),
|
|
4474
|
+
t.log(t.indent + "width: " + this.width),
|
|
4475
|
+
t.log(t.indent + "height: " + this.height)
|
|
4476
|
+
};
|
|
4477
|
+
var MP4Box = {
|
|
4478
|
+
createFile: function(t, e) {
|
|
4479
|
+
t = void 0 === t || t,
|
|
4480
|
+
e = new ISOFile(e);
|
|
4481
|
+
return e.discardMdatData = !t,
|
|
4482
|
+
e
|
|
4483
|
+
}
|
|
4484
|
+
};
|
|
4485
|
+
"undefined" != typeof exports && (exports.createFile = MP4Box.createFile);
|
|
4486
|
+
`
|
|
4487
|
+
|
|
4488
|
+
const workerLogic = `
|
|
4489
|
+
// 显式将变量绑定到self上,确保全局可访问
|
|
4490
|
+
self.abortFlag = false;
|
|
4491
|
+
self.mp4boxfile = null;
|
|
4492
|
+
self.videoDecoder = null;
|
|
4493
|
+
self.samplesInRange = [];
|
|
4494
|
+
self.videoTrack = null;
|
|
4495
|
+
self.arrayBuffer = null;
|
|
4496
|
+
|
|
4497
|
+
onmessage = function(e) {
|
|
4498
|
+
if (e.data.type === 'decode') {
|
|
4499
|
+
self.abortFlag = false;
|
|
4500
|
+
decodeFile(e.data.file, e.data.start, e.data.end, e.data.hardwareAcceleration);
|
|
4501
|
+
} else if (e.data.type === 'abort') {
|
|
4502
|
+
self.abortFlag = true;
|
|
4503
|
+
// 主动销毁所有大对象和引用
|
|
4504
|
+
if (self.videoDecoder) {
|
|
4505
|
+
try {
|
|
4506
|
+
self.videoDecoder.flush();
|
|
4507
|
+
self.videoDecoder.reset();
|
|
4508
|
+
self.videoDecoder.close();
|
|
4509
|
+
} catch (err) {}
|
|
4510
|
+
self.videoDecoder = null;
|
|
4511
|
+
}
|
|
4512
|
+
if (self.mp4boxfile) {
|
|
4513
|
+
try { self.mp4boxfile.flush(); } catch (err) {}
|
|
4514
|
+
self.mp4boxfile = null;
|
|
4515
|
+
}
|
|
4516
|
+
self.samplesInRange = [];
|
|
4517
|
+
self.videoTrack = null;
|
|
4518
|
+
self.arrayBuffer = null;
|
|
4519
|
+
// 关闭worker
|
|
4520
|
+
self.close();
|
|
4521
|
+
}
|
|
4522
|
+
};
|
|
4523
|
+
|
|
4524
|
+
function decodeFile(file, startFrame, endFrame, hardwareAcceleration) {
|
|
4525
|
+
self.arrayBuffer = file.data;
|
|
4526
|
+
self.mp4boxfile = MP4Box.createFile();
|
|
4527
|
+
self.videoTrack = null;
|
|
4528
|
+
let nbSampleTotal = 0;
|
|
4529
|
+
self.samplesInRange = [];
|
|
4530
|
+
self.videoDecoder = null;
|
|
4531
|
+
let frameIndex = 0;
|
|
4532
|
+
let totalFrames = 0;
|
|
4533
|
+
self.mp4boxfile.onReady = function(info) {
|
|
4534
|
+
self.videoTrack = info.videoTracks[0];
|
|
4535
|
+
nbSampleTotal = self.videoTrack.nb_samples;
|
|
4536
|
+
self.mp4boxfile.setExtractionOptions(self.videoTrack.id, null, {
|
|
4537
|
+
nbSamples: nbSampleTotal,
|
|
4538
|
+
rapAlignement: true
|
|
4539
|
+
});
|
|
4540
|
+
self.mp4boxfile.start();
|
|
4541
|
+
};
|
|
4542
|
+
self.mp4boxfile.onSamples = async function(trackId, ref, samples) {
|
|
4543
|
+
if (self.abortFlag) return; // 确保使用self访问
|
|
4544
|
+
// 自动对齐到区间内第一个关键帧
|
|
4545
|
+
let startIdx = Math.min(0, startFrame); // 修复Math.min, 因为仅有第一帧是关键帧
|
|
4546
|
+
let endIdx = Math.min(samples.length - 1, endFrame);
|
|
4547
|
+
while (startIdx <= endIdx && !samples[startIdx].is_sync) {
|
|
4548
|
+
startIdx++;
|
|
4549
|
+
}
|
|
4550
|
+
if (startIdx > endIdx) {
|
|
4551
|
+
// 区间内没有关键帧,直接done
|
|
4552
|
+
postMessage({ type: 'done' });
|
|
4553
|
+
return;
|
|
4554
|
+
}
|
|
4555
|
+
self.samplesInRange = samples.slice(0, endIdx + 1);
|
|
4556
|
+
totalFrames = self.samplesInRange.length;
|
|
4557
|
+
if (!self.videoDecoder) {
|
|
4558
|
+
self.videoDecoder = new VideoDecoder({
|
|
4559
|
+
output: handleFrame,
|
|
4560
|
+
error: err => {
|
|
4561
|
+
postMessage({ type: 'error', error: err.message })
|
|
4562
|
+
}
|
|
4563
|
+
});
|
|
4564
|
+
const entry = self.mp4boxfile.moov.traks[0].mdia.minf.stbl.stsd.entries[0];
|
|
4565
|
+
const box = entry.avcC ?? entry.hvcC ?? entry.vpcC;
|
|
4566
|
+
let description = undefined;
|
|
4567
|
+
if (box) {
|
|
4568
|
+
const stream = new DataStream(undefined, 0, DataStream.BIG_ENDIAN);
|
|
4569
|
+
box.write(stream);
|
|
4570
|
+
description = new Uint8Array(stream.buffer.slice(8));
|
|
4571
|
+
}
|
|
4572
|
+
const isIOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent);
|
|
4573
|
+
const userAgent = (navigator.userAgent || "").toLowerCase();
|
|
4574
|
+
const isAndroid = /android/.test(userAgent) || /openharmony|arkweb/.test(userAgent);
|
|
4575
|
+
const defaultConfig = {
|
|
4576
|
+
codec: self.videoTrack.codec,
|
|
4577
|
+
codedWidth: self.videoTrack.track_width,
|
|
4578
|
+
codedHeight: self.videoTrack.track_height,
|
|
4579
|
+
description,
|
|
4580
|
+
}
|
|
4581
|
+
// Android 系统下,默认配置为 prefer-software 以避免硬件解码问题
|
|
4582
|
+
let config = isAndroid ? { ...defaultConfig, hardwareAcceleration: 'prefer-software' } : hardwareAcceleration === 'default' ? defaultConfig : {
|
|
4583
|
+
...defaultConfig,
|
|
4584
|
+
hardwareAcceleration: hardwareAcceleration,
|
|
4585
|
+
}
|
|
4586
|
+
// let config = hardwareAcceleration === 'default' ? defaultConfig : {
|
|
4587
|
+
// ...defaultConfig,
|
|
4588
|
+
// hardwareAcceleration: hardwareAcceleration,
|
|
4589
|
+
// }
|
|
4590
|
+
const configSupport = (await VideoDecoder.isConfigSupported(config));
|
|
4591
|
+
const isConfigSupported = configSupport.supported;
|
|
4592
|
+
postMessage({ type: 'configSupport', configSupport: { config, configSupport}});
|
|
4593
|
+
let isDefaultConfigSupported = false;
|
|
4594
|
+
if(!isConfigSupported) {
|
|
4595
|
+
const defaultConfigSupport = await VideoDecoder.isConfigSupported(defaultConfig);
|
|
4596
|
+
postMessage({ type: 'configSupport', configSupport: { defaultConfig, configSupport: defaultConfigSupport}});
|
|
4597
|
+
isDefaultConfigSupported = defaultConfigSupport.supported;
|
|
4598
|
+
}
|
|
4599
|
+
if(isConfigSupported) {
|
|
4600
|
+
self.videoDecoder.configure(config);
|
|
4601
|
+
} else if(isDefaultConfigSupported) {
|
|
4602
|
+
self.videoDecoder.configure(defaultConfig);
|
|
4603
|
+
} else {
|
|
4604
|
+
postMessage({ type: 'error', error: '不支持的视频解码配置' });
|
|
4605
|
+
}
|
|
4606
|
+
}
|
|
4607
|
+
for (let i = 0; i < self.samplesInRange.length; i++) {
|
|
4608
|
+
if (self.abortFlag) break; // 确保使用self访问
|
|
4609
|
+
|
|
4610
|
+
const sample = self.samplesInRange[i];
|
|
4611
|
+
const chunk = new EncodedVideoChunk({
|
|
4612
|
+
type: sample.is_sync ? 'key' : 'delta',
|
|
4613
|
+
timestamp: sample.cts,
|
|
4614
|
+
duration: sample.duration,
|
|
4615
|
+
data: sample.data
|
|
4616
|
+
});
|
|
4617
|
+
self.videoDecoder.decode(chunk);
|
|
4618
|
+
}
|
|
4619
|
+
self.videoDecoder.flush().then(() => {
|
|
4620
|
+
postMessage({ type: 'done' });
|
|
4621
|
+
});
|
|
4622
|
+
};
|
|
4623
|
+
function handleFrame(videoFrame) {
|
|
4624
|
+
if (self.abortFlag) { // 确保使用self访问
|
|
4625
|
+
videoFrame.close();
|
|
4626
|
+
return;
|
|
4627
|
+
}
|
|
4628
|
+
postMessage({ type: 'frame', frame: videoFrame, index: frameIndex++, total: totalFrames }, [videoFrame]);
|
|
4629
|
+
}
|
|
4630
|
+
self.arrayBuffer.fileStart = 0;
|
|
4631
|
+
self.mp4boxfile.appendBuffer(self.arrayBuffer);
|
|
4632
|
+
self.mp4boxfile.flush();
|
|
4633
|
+
}
|
|
4634
|
+
`;
|
|
4635
|
+
|
|
4636
|
+
const fullWorkerScript = `
|
|
4637
|
+
try {
|
|
4638
|
+
${mp4boxSource}
|
|
4639
|
+
self.MP4Box = MP4Box;
|
|
4640
|
+
${workerLogic}
|
|
4641
|
+
} catch (error) {
|
|
4642
|
+
console.error('Worker初始化失败:', error);
|
|
4643
|
+
throw error;
|
|
4644
|
+
}
|
|
4645
|
+
`
|
|
4646
|
+
const blob = new Blob([fullWorkerScript], { type: "application/javascript" });
|
|
4647
|
+
export const workerURL = URL.createObjectURL(blob);
|