@moq/watch 0.2.13 → 0.2.15
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 +10 -9
- package/audio/source.d.ts.map +1 -1
- package/broadcast-jtLUfuyL.js +4291 -0
- package/broadcast-jtLUfuyL.js.map +1 -0
- package/broadcast.d.ts.map +1 -1
- package/dom-Yz3UT5ap.js +29 -0
- package/dom-Yz3UT5ap.js.map +1 -0
- package/element.js +162 -178
- package/element.js.map +1 -1
- package/index.d.ts +1 -3
- package/index.d.ts.map +1 -1
- package/index.js +5 -254
- package/libav-opus-af-CzuaKpJb.js +252 -0
- package/libav-opus-af-CzuaKpJb.js.map +1 -0
- package/main-bFFHfuX4.js +1999 -0
- package/main-bFFHfuX4.js.map +1 -0
- package/package.json +5 -4
- package/support/element.js +122 -172
- package/support/element.js.map +1 -1
- package/support/index.js +52 -53
- package/support/index.js.map +1 -1
- package/ui/element.js +335 -359
- package/ui/element.js.map +1 -1
- package/video/source.d.ts.map +1 -1
- package/broadcast-CLjMphZS.js +0 -5000
- package/broadcast-CLjMphZS.js.map +0 -1
- package/chat/index.d.ts +0 -17
- package/chat/index.d.ts.map +0 -1
- package/chat/message.d.ts +0 -16
- package/chat/message.d.ts.map +0 -1
- package/chat/typing.d.ts +0 -16
- package/chat/typing.d.ts.map +0 -1
- package/dom-BsFrLb_F.js +0 -35
- package/dom-BsFrLb_F.js.map +0 -1
- package/index.js.map +0 -1
- package/libav-opus-af-BlMWboA7.js +0 -368
- package/libav-opus-af-BlMWboA7.js.map +0 -1
- package/location/index.d.ts +0 -17
- package/location/index.d.ts.map +0 -1
- package/location/peers.d.ts +0 -16
- package/location/peers.d.ts.map +0 -1
- package/location/window.d.ts +0 -17
- package/location/window.d.ts.map +0 -1
- package/main-DGBFe0O7.js +0 -2301
- package/main-DGBFe0O7.js.map +0 -1
- package/preview.d.ts +0 -23
- package/preview.d.ts.map +0 -1
- package/user.d.ts +0 -17
- package/user.d.ts.map +0 -1
package/main-bFFHfuX4.js
ADDED
|
@@ -0,0 +1,1999 @@
|
|
|
1
|
+
//#region ../../node_modules/@kixelated/libavjs-webcodecs-polyfill/dist/encoded-audio-chunk.js
|
|
2
|
+
var e = class {
|
|
3
|
+
constructor(e) {
|
|
4
|
+
{
|
|
5
|
+
this.type = e.type, this.timestamp = e.timestamp, typeof e.duration == "number" ? this.duration = e.duration : this.duration = null, this.byteLength = e.data.byteLength;
|
|
6
|
+
let t = !1;
|
|
7
|
+
if (e.transfer) {
|
|
8
|
+
let n;
|
|
9
|
+
n = e.data.buffer ? e.data.buffer : e.data;
|
|
10
|
+
let r;
|
|
11
|
+
r = e.transfer instanceof Array ? e.transfer : Array.from(e.transfer);
|
|
12
|
+
for (let e of r) if (e === n) {
|
|
13
|
+
t = !0;
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
let n = new Uint8Array(e.data.buffer || e.data, e.data.byteOffset || 0, e.data.BYTES_PER_ELEMENT ? e.data.BYTES_PER_ELEMENT * e.data.length : e.data.byteLength);
|
|
18
|
+
t ? this._data = n : this._data = n.slice(0);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
_libavGetData() {
|
|
22
|
+
return this._data;
|
|
23
|
+
}
|
|
24
|
+
copyTo(e) {
|
|
25
|
+
new Uint8Array(e.buffer || e, e.byteOffset || 0).set(this._data);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region ../../node_modules/@ungap/global-this/esm/index.js
|
|
30
|
+
(function(e) {
|
|
31
|
+
typeof globalThis != "object" && (this ? t() : (e.defineProperty(e.prototype, "_T_", {
|
|
32
|
+
configurable: !0,
|
|
33
|
+
get: t
|
|
34
|
+
}), _T_));
|
|
35
|
+
function t() {
|
|
36
|
+
var t = this || self;
|
|
37
|
+
t.globalThis = t, delete e.prototype._T_;
|
|
38
|
+
}
|
|
39
|
+
})(Object);
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region ../../node_modules/@kixelated/libavjs-webcodecs-polyfill/dist/audio-data.js
|
|
42
|
+
var t = class e {
|
|
43
|
+
constructor(t) {
|
|
44
|
+
e._checkValidAudioDataInit(t);
|
|
45
|
+
{
|
|
46
|
+
this.format = t.format, this.sampleRate = t.sampleRate, this.numberOfFrames = t.numberOfFrames, this.numberOfChannels = t.numberOfChannels, this.timestamp = t.timestamp;
|
|
47
|
+
let e = !1;
|
|
48
|
+
if (t.transfer) {
|
|
49
|
+
let n;
|
|
50
|
+
n = t.data.buffer ? t.data.buffer : t.data;
|
|
51
|
+
let r;
|
|
52
|
+
r = t.transfer instanceof Array ? t.transfer : Array.from(t.transfer);
|
|
53
|
+
for (let t of r) if (t === n) {
|
|
54
|
+
e = !0;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
let r, i = 0;
|
|
59
|
+
e ? (r = t.data, i = t.data.byteOffset || 0) : r = t.data.slice(0);
|
|
60
|
+
let a = n(t.format, r.buffer || r, i);
|
|
61
|
+
this._data = a;
|
|
62
|
+
}
|
|
63
|
+
this.duration = t.numberOfFrames / t.sampleRate * 1e6;
|
|
64
|
+
}
|
|
65
|
+
toNative(e = {}) {
|
|
66
|
+
let t = new globalThis.AudioData({
|
|
67
|
+
data: this._data,
|
|
68
|
+
format: this.format,
|
|
69
|
+
sampleRate: this.sampleRate,
|
|
70
|
+
numberOfFrames: this.numberOfFrames,
|
|
71
|
+
numberOfChannels: this.numberOfChannels,
|
|
72
|
+
timestamp: this.timestamp,
|
|
73
|
+
transfer: e.transfer ? [this._data.buffer] : []
|
|
74
|
+
});
|
|
75
|
+
return e.transfer && this.close(), t;
|
|
76
|
+
}
|
|
77
|
+
static fromNative(t) {
|
|
78
|
+
let n = t, r = i(n.format) ? 1 : n.numberOfChannels, a = n.allocationSize({
|
|
79
|
+
format: n.format,
|
|
80
|
+
planeIndex: 0
|
|
81
|
+
}), o = new Uint8Array(a * r);
|
|
82
|
+
for (let e = 0; e < r; e++) n.copyTo(o.subarray(e * a), {
|
|
83
|
+
format: n.format,
|
|
84
|
+
planeIndex: e
|
|
85
|
+
});
|
|
86
|
+
return new e({
|
|
87
|
+
data: o,
|
|
88
|
+
format: n.format,
|
|
89
|
+
sampleRate: n.sampleRate,
|
|
90
|
+
numberOfFrames: n.numberOfFrames,
|
|
91
|
+
numberOfChannels: n.numberOfChannels,
|
|
92
|
+
timestamp: n.timestamp,
|
|
93
|
+
transfer: [o.buffer]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
_libavGetData() {
|
|
97
|
+
return this._data;
|
|
98
|
+
}
|
|
99
|
+
static _checkValidAudioDataInit(e) {
|
|
100
|
+
if (e.sampleRate <= 0) throw TypeError(`Invalid sample rate ${e.sampleRate}`);
|
|
101
|
+
if (e.numberOfFrames <= 0) throw TypeError(`Invalid number of frames ${e.numberOfFrames}`);
|
|
102
|
+
if (e.numberOfChannels <= 0) throw TypeError(`Invalid number of channels ${e.numberOfChannels}`);
|
|
103
|
+
{
|
|
104
|
+
let t = e.numberOfFrames * e.numberOfChannels, n = r(e.format) * t;
|
|
105
|
+
if (e.data.byteLength < n) throw TypeError(`This audio data must be at least ${n} bytes`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
allocationSize(e) {
|
|
109
|
+
if (this._data === null) throw new DOMException("Detached", "InvalidStateError");
|
|
110
|
+
let t = this._computeCopyElementCount(e), n = this.format;
|
|
111
|
+
return e.format && (n = e.format), r(n) * t;
|
|
112
|
+
}
|
|
113
|
+
_computeCopyElementCount(e) {
|
|
114
|
+
let t = this.format;
|
|
115
|
+
e.format && (t = e.format);
|
|
116
|
+
let n = i(t);
|
|
117
|
+
if (n) {
|
|
118
|
+
if (e.planeIndex > 0) throw RangeError("Invalid plane");
|
|
119
|
+
} else if (e.planeIndex >= this.numberOfChannels) throw RangeError("Invalid plane");
|
|
120
|
+
if (this.format !== t && t !== "f32-planar") throw new DOMException("Only conversion to f32-planar is supported", "NotSupportedError");
|
|
121
|
+
let r = this.numberOfFrames, a = e.frameOffset || 0;
|
|
122
|
+
if (a >= r) throw RangeError("Frame offset out of range");
|
|
123
|
+
let o = r - a;
|
|
124
|
+
if (typeof e.frameCount == "number") {
|
|
125
|
+
if (e.frameCount >= o) throw RangeError("Frame count out of range");
|
|
126
|
+
o = e.frameCount;
|
|
127
|
+
}
|
|
128
|
+
let s = o;
|
|
129
|
+
return n && (s *= this.numberOfChannels), s;
|
|
130
|
+
}
|
|
131
|
+
copyTo(e, t) {
|
|
132
|
+
if (this._data === null) throw new DOMException("Detached", "InvalidStateError");
|
|
133
|
+
let a = this._computeCopyElementCount(t), o = this.format;
|
|
134
|
+
if (t.format && (o = t.format), r(o) * a > e.byteLength) throw RangeError("Buffer too small");
|
|
135
|
+
let s = this._data.subarray(t.planeIndex * this.numberOfFrames), c = t.frameOffset || 0, l = this.numberOfChannels;
|
|
136
|
+
if (this.format === o) {
|
|
137
|
+
let t = n(o, e.buffer || e, e.byteOffset || 0);
|
|
138
|
+
i(o) ? t.set(s.subarray(c * l, c * l + a)) : t.set(s.subarray(c, c + a));
|
|
139
|
+
} else {
|
|
140
|
+
let r = n(o, e.buffer || e, e.byteOffset || 0), u = 0, d = 1;
|
|
141
|
+
switch (this.format) {
|
|
142
|
+
case "u8":
|
|
143
|
+
case "u8-planar":
|
|
144
|
+
u = 128, d = 128;
|
|
145
|
+
break;
|
|
146
|
+
case "s16":
|
|
147
|
+
case "s16-planar":
|
|
148
|
+
d = 32768;
|
|
149
|
+
break;
|
|
150
|
+
case "s32":
|
|
151
|
+
case "s32-planar":
|
|
152
|
+
d = 2147483648;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
if (i(this.format)) for (let e = t.planeIndex + c * l, n = 0; n < a; e += l, n++) r[n] = (s[e] - u) / d;
|
|
156
|
+
else for (let e = c, t = 0; t < a; e++, t++) r[t] = (s[e] - u) / d;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
clone() {
|
|
160
|
+
if (this._data === null) throw new DOMException("Detached", "InvalidStateError");
|
|
161
|
+
return new e({
|
|
162
|
+
format: this.format,
|
|
163
|
+
sampleRate: this.sampleRate,
|
|
164
|
+
numberOfFrames: this.numberOfFrames,
|
|
165
|
+
numberOfChannels: this.numberOfChannels,
|
|
166
|
+
timestamp: this.timestamp,
|
|
167
|
+
data: this._data
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
close() {
|
|
171
|
+
this._data = null;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
function n(e, t, n) {
|
|
175
|
+
switch (e) {
|
|
176
|
+
case "u8":
|
|
177
|
+
case "u8-planar": return new Uint8Array(t, n);
|
|
178
|
+
case "s16":
|
|
179
|
+
case "s16-planar": return new Int16Array(t, n);
|
|
180
|
+
case "s32":
|
|
181
|
+
case "s32-planar": return new Int32Array(t, n);
|
|
182
|
+
case "f32":
|
|
183
|
+
case "f32-planar": return new Float32Array(t, n);
|
|
184
|
+
default: throw TypeError("Invalid AudioSampleFormat");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function r(e) {
|
|
188
|
+
switch (e) {
|
|
189
|
+
case "u8":
|
|
190
|
+
case "u8-planar": return 1;
|
|
191
|
+
case "s16":
|
|
192
|
+
case "s16-planar": return 2;
|
|
193
|
+
case "s32":
|
|
194
|
+
case "s32-planar":
|
|
195
|
+
case "f32":
|
|
196
|
+
case "f32-planar": return 4;
|
|
197
|
+
default: throw TypeError("Invalid AudioSampleFormat");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function i(e) {
|
|
201
|
+
switch (e) {
|
|
202
|
+
case "u8":
|
|
203
|
+
case "s16":
|
|
204
|
+
case "s32":
|
|
205
|
+
case "f32": return !0;
|
|
206
|
+
case "u8-planar":
|
|
207
|
+
case "s16-planar":
|
|
208
|
+
case "s32-planar":
|
|
209
|
+
case "f32-planar": return !1;
|
|
210
|
+
default: throw TypeError("Invalid AudioSampleFormat");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region ../../node_modules/@kixelated/libavjs-webcodecs-polyfill/dist/event-target.js
|
|
215
|
+
var a = class {
|
|
216
|
+
constructor() {
|
|
217
|
+
let e = this._eventer = new EventTarget();
|
|
218
|
+
this.addEventListener = e.addEventListener.bind(e), this.removeEventListener = e.removeEventListener.bind(e), this.dispatchEvent = e.dispatchEvent.bind(e);
|
|
219
|
+
}
|
|
220
|
+
}, o = class extends a {
|
|
221
|
+
constructor() {
|
|
222
|
+
super(), this.addEventListener("dequeue", (e) => {
|
|
223
|
+
this.ondequeue && this.ondequeue(e);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}, s = function(e, t, n, r) {
|
|
227
|
+
function i(e) {
|
|
228
|
+
return e instanceof n ? e : new n(function(t) {
|
|
229
|
+
t(e);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return new (n ||= Promise)(function(n, a) {
|
|
233
|
+
function o(e) {
|
|
234
|
+
try {
|
|
235
|
+
c(r.next(e));
|
|
236
|
+
} catch (e) {
|
|
237
|
+
a(e);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function s(e) {
|
|
241
|
+
try {
|
|
242
|
+
c(r.throw(e));
|
|
243
|
+
} catch (e) {
|
|
244
|
+
a(e);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function c(e) {
|
|
248
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
249
|
+
}
|
|
250
|
+
c((r = r.apply(e, t || [])).next());
|
|
251
|
+
});
|
|
252
|
+
}, c = null, l = [], u = {}, d = null, f = null;
|
|
253
|
+
function p(e) {
|
|
254
|
+
c = e;
|
|
255
|
+
}
|
|
256
|
+
function m(e) {
|
|
257
|
+
u = e;
|
|
258
|
+
}
|
|
259
|
+
function h() {
|
|
260
|
+
return s(this, void 0, void 0, function* () {
|
|
261
|
+
return l.length ? l.shift() : yield c.LibAV(u);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
function g(e) {
|
|
265
|
+
l.push(e);
|
|
266
|
+
}
|
|
267
|
+
function _(e) {
|
|
268
|
+
return s(this, void 0, void 0, function* () {
|
|
269
|
+
let t = yield h(), n = [];
|
|
270
|
+
for (let [r, i] of [
|
|
271
|
+
["flac", "flac"],
|
|
272
|
+
["libopus", "opus"],
|
|
273
|
+
["libvorbis", "vorbis"],
|
|
274
|
+
["libaom-av1", "av01"],
|
|
275
|
+
["libvpx-vp9", "vp09"],
|
|
276
|
+
["libvpx", "vp8"]
|
|
277
|
+
]) e ? (yield t.avcodec_find_encoder_by_name(r)) && n.push(i) : (yield t.avcodec_find_decoder_by_name(r)) && n.push(i);
|
|
278
|
+
return g(t), n;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
function v() {
|
|
282
|
+
return s(this, void 0, void 0, function* () {
|
|
283
|
+
c ||= LibAV, d = yield _(!1), f = yield _(!0);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function y(e, t) {
|
|
287
|
+
if (typeof e == "string") {
|
|
288
|
+
e = e.replace(/\..*/, "");
|
|
289
|
+
let n = e;
|
|
290
|
+
switch (e) {
|
|
291
|
+
case "flac":
|
|
292
|
+
if (t.description === void 0) return null;
|
|
293
|
+
break;
|
|
294
|
+
case "opus":
|
|
295
|
+
if (t.description !== void 0) return null;
|
|
296
|
+
n = "libopus";
|
|
297
|
+
break;
|
|
298
|
+
case "vorbis":
|
|
299
|
+
if (t.description === void 0) return null;
|
|
300
|
+
n = "libvorbis";
|
|
301
|
+
break;
|
|
302
|
+
case "av01":
|
|
303
|
+
n = "libaom-av1";
|
|
304
|
+
break;
|
|
305
|
+
case "vp09":
|
|
306
|
+
n = "libvpx-vp9";
|
|
307
|
+
break;
|
|
308
|
+
case "vp8":
|
|
309
|
+
n = "libvpx";
|
|
310
|
+
break;
|
|
311
|
+
case "mp3":
|
|
312
|
+
case "mp4a":
|
|
313
|
+
case "ulaw":
|
|
314
|
+
case "alaw":
|
|
315
|
+
case "avc1":
|
|
316
|
+
case "avc3":
|
|
317
|
+
case "hev1":
|
|
318
|
+
case "hvc1": return null;
|
|
319
|
+
default: throw TypeError("Unrecognized codec");
|
|
320
|
+
}
|
|
321
|
+
return d.indexOf(e) >= 0 ? { codec: n } : null;
|
|
322
|
+
} else return e.libavjs;
|
|
323
|
+
}
|
|
324
|
+
function b(e, t) {
|
|
325
|
+
if (typeof e == "string") {
|
|
326
|
+
let n = e.split(".");
|
|
327
|
+
e = n[0];
|
|
328
|
+
let r = e, i = {}, a = {}, o = !1;
|
|
329
|
+
switch (e) {
|
|
330
|
+
case "flac":
|
|
331
|
+
if (i.sample_fmt = 2, i.bit_rate = 0, typeof t.flac == "object" && t.flac !== null) {
|
|
332
|
+
let e = t.flac;
|
|
333
|
+
if (typeof e.blockSize == "number" && (i.frame_size = e.blockSize), typeof e.compressLevel == "number") return null;
|
|
334
|
+
}
|
|
335
|
+
break;
|
|
336
|
+
case "opus":
|
|
337
|
+
if (r = "libopus", i.sample_fmt = 3, i.sample_rate = 48e3, typeof t.opus == "object" && t.opus !== null) {
|
|
338
|
+
let e = t.opus;
|
|
339
|
+
if (typeof e.frameDuration == "number" && (a.frame_duration = "" + e.frameDuration / 1e3), e.complexity !== void 0) return null;
|
|
340
|
+
if (typeof e.packetlossperc == "number") {
|
|
341
|
+
if (e.packetlossperc < 0 || e.packetlossperc > 100) return null;
|
|
342
|
+
a.packet_loss = "" + e.packetlossperc;
|
|
343
|
+
}
|
|
344
|
+
if (typeof e.useinbandfec == "boolean" && (a.fec = e.useinbandfec ? "1" : "0"), typeof e.usedtx == "boolean" || typeof e.format == "string" && e.format !== "opus") return null;
|
|
345
|
+
}
|
|
346
|
+
break;
|
|
347
|
+
case "vorbis":
|
|
348
|
+
r = "libvorbis", i.sample_fmt = 8;
|
|
349
|
+
break;
|
|
350
|
+
case "av01":
|
|
351
|
+
if (o = !0, r = "libaom-av1", t.latencyMode === "realtime" && (a.usage = "realtime", a["cpu-used"] = "8"), !x(n, i)) return null;
|
|
352
|
+
break;
|
|
353
|
+
case "vp09":
|
|
354
|
+
if (o = !0, r = "libvpx-vp9", t.latencyMode === "realtime" && (a.quality = "realtime", a["cpu-used"] = "8"), !S(n, i)) return null;
|
|
355
|
+
break;
|
|
356
|
+
case "vp8":
|
|
357
|
+
o = !0, r = "libvpx", t.latencyMode === "realtime" && (a.quality = "realtime", a["cpu-used"] = "8");
|
|
358
|
+
break;
|
|
359
|
+
case "mp3":
|
|
360
|
+
case "mp4a":
|
|
361
|
+
case "ulaw":
|
|
362
|
+
case "alaw":
|
|
363
|
+
case "avc1": return null;
|
|
364
|
+
default: throw TypeError("Unrecognized codec");
|
|
365
|
+
}
|
|
366
|
+
if (!(f.indexOf(e) >= 0)) return null;
|
|
367
|
+
if (o) {
|
|
368
|
+
typeof i.pix_fmt != "number" && (i.pix_fmt = 0);
|
|
369
|
+
let e = i.width = t.width, n = i.height = t.height;
|
|
370
|
+
t.framerate && (i.framerate_num = Math.round(t.framerate), i.framerate_den = 1);
|
|
371
|
+
let r = t.displayWidth || t.width, a = t.displayHeight || t.height;
|
|
372
|
+
(r !== e || a !== n) && (i.sample_aspect_ratio_num = r * n, i.sample_aspect_ratio_den = a * e);
|
|
373
|
+
} else if (i.sample_rate ||= t.sampleRate || 48e3, t.numberOfChannels) {
|
|
374
|
+
let e = t.numberOfChannels;
|
|
375
|
+
i.channel_layout = e === 1 ? 4 : (1 << e) - 1;
|
|
376
|
+
}
|
|
377
|
+
return typeof i.bit_rate != "number" && t.bitrate && (i.bit_rate = t.bitrate), {
|
|
378
|
+
codec: r,
|
|
379
|
+
ctx: i,
|
|
380
|
+
options: a
|
|
381
|
+
};
|
|
382
|
+
} else return e.libavjs;
|
|
383
|
+
}
|
|
384
|
+
function x(e, t) {
|
|
385
|
+
if (e[1]) {
|
|
386
|
+
let n = +e[1];
|
|
387
|
+
if (n >= 0 && n <= 2) t.profile = n;
|
|
388
|
+
else throw TypeError("Invalid AV1 profile");
|
|
389
|
+
}
|
|
390
|
+
if (e[2]) {
|
|
391
|
+
let n = +e[2];
|
|
392
|
+
if (n >= 0 && n <= 23) t.level = n;
|
|
393
|
+
else throw TypeError("Invalid AV1 level");
|
|
394
|
+
}
|
|
395
|
+
if (e[3]) switch (e[3]) {
|
|
396
|
+
case "M": break;
|
|
397
|
+
case "H":
|
|
398
|
+
if (t.level && t.level >= 8) return !1;
|
|
399
|
+
throw TypeError("The AV1 high tier is only available for level 4.0 and up");
|
|
400
|
+
default: throw TypeError("Invalid AV1 tier");
|
|
401
|
+
}
|
|
402
|
+
if (e[4]) {
|
|
403
|
+
let t = +e[3];
|
|
404
|
+
if (t === 10 || t === 12) return !1;
|
|
405
|
+
if (t !== 8) throw TypeError("Invalid AV1 bit depth");
|
|
406
|
+
}
|
|
407
|
+
if (e[5]) switch (e[5]) {
|
|
408
|
+
case "0": break;
|
|
409
|
+
case "1": return !1;
|
|
410
|
+
default: throw TypeError("Invalid AV1 monochrome flag");
|
|
411
|
+
}
|
|
412
|
+
if (e[6]) switch (e[6]) {
|
|
413
|
+
case "000":
|
|
414
|
+
t.pix_fmt = 5;
|
|
415
|
+
break;
|
|
416
|
+
case "100":
|
|
417
|
+
t.pix_fmt = 4;
|
|
418
|
+
break;
|
|
419
|
+
case "110":
|
|
420
|
+
t.pix_fmt = 0;
|
|
421
|
+
break;
|
|
422
|
+
case "111": return !1;
|
|
423
|
+
default: throw TypeError("Invalid AV1 subsampling mode");
|
|
424
|
+
}
|
|
425
|
+
return !0;
|
|
426
|
+
}
|
|
427
|
+
function S(e, t) {
|
|
428
|
+
if (e[1]) {
|
|
429
|
+
let n = +e[1];
|
|
430
|
+
if (n >= 0 && n <= 3) t.profile = n;
|
|
431
|
+
else throw TypeError("Invalid VP9 profile");
|
|
432
|
+
}
|
|
433
|
+
if (e[2]) {
|
|
434
|
+
let n = [+e[2][0], +e[2][1]];
|
|
435
|
+
if (n[0] >= 1 && n[0] <= 4) {
|
|
436
|
+
if (!(n[1] >= 0 && n[1] <= 1)) throw TypeError("Invalid VP9 level");
|
|
437
|
+
} else if (n[0] >= 5 && n[0] <= 6) {
|
|
438
|
+
if (!(n[1] >= 0 && n[1] <= 2)) throw TypeError("Invalid VP9 level");
|
|
439
|
+
} else throw TypeError("Invalid VP9 level");
|
|
440
|
+
t.level = +e[2];
|
|
441
|
+
}
|
|
442
|
+
if (e[3]) {
|
|
443
|
+
let t = +e[3];
|
|
444
|
+
if (t === 10 || t === 12) return !1;
|
|
445
|
+
if (t !== 8) throw TypeError("Invalid VP9 bit depth");
|
|
446
|
+
}
|
|
447
|
+
if (e[4]) switch (+e[4]) {
|
|
448
|
+
case 0:
|
|
449
|
+
case 1:
|
|
450
|
+
t.pix_fmt = 0;
|
|
451
|
+
break;
|
|
452
|
+
case 2:
|
|
453
|
+
t.pix_fmt = 4;
|
|
454
|
+
break;
|
|
455
|
+
case 3:
|
|
456
|
+
t.pix_fmt = 5;
|
|
457
|
+
break;
|
|
458
|
+
default: throw TypeError("Invalid VP9 chroma subsampling format");
|
|
459
|
+
}
|
|
460
|
+
return !0;
|
|
461
|
+
}
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region ../../node_modules/@kixelated/libavjs-webcodecs-polyfill/dist/misc.js
|
|
464
|
+
function C(e, t) {
|
|
465
|
+
let n = {};
|
|
466
|
+
for (let r of t) r in e && (n[r] = e[r]);
|
|
467
|
+
return n;
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region ../../node_modules/@kixelated/libavjs-webcodecs-polyfill/dist/audio-decoder.js
|
|
471
|
+
var w = function(e, t, n, r) {
|
|
472
|
+
function i(e) {
|
|
473
|
+
return e instanceof n ? e : new n(function(t) {
|
|
474
|
+
t(e);
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
return new (n ||= Promise)(function(n, a) {
|
|
478
|
+
function o(e) {
|
|
479
|
+
try {
|
|
480
|
+
c(r.next(e));
|
|
481
|
+
} catch (e) {
|
|
482
|
+
a(e);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function s(e) {
|
|
486
|
+
try {
|
|
487
|
+
c(r.throw(e));
|
|
488
|
+
} catch (e) {
|
|
489
|
+
a(e);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function c(e) {
|
|
493
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
494
|
+
}
|
|
495
|
+
c((r = r.apply(e, t || [])).next());
|
|
496
|
+
});
|
|
497
|
+
}, T = class extends o {
|
|
498
|
+
constructor(e) {
|
|
499
|
+
super(), this._p = Promise.all([]), this._libav = null, this._codec = this._c = this._pkt = this._frame = 0, this._output = e.output, this._error = e.error, this.state = "unconfigured", this.decodeQueueSize = 0;
|
|
500
|
+
}
|
|
501
|
+
configure(e) {
|
|
502
|
+
if (this.state === "closed") throw new DOMException("Decoder is closed", "InvalidStateError");
|
|
503
|
+
this._libav && (this._p = this._p.then(() => this._free())), this.state = "configured", this._p = this._p.then(() => w(this, void 0, void 0, function* () {
|
|
504
|
+
let t;
|
|
505
|
+
if (e.description) if (ArrayBuffer.isView(e.description)) {
|
|
506
|
+
let n = e.description;
|
|
507
|
+
t = new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
|
|
508
|
+
} else {
|
|
509
|
+
let n = e.description;
|
|
510
|
+
t = new Uint8Array(n);
|
|
511
|
+
}
|
|
512
|
+
let n = y(e.codec, e);
|
|
513
|
+
if (!n) {
|
|
514
|
+
this._closeAudioDecoder(new DOMException("Unsupported codec", "NotSupportedError"));
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
let r = this._libav = yield h(), i = yield r.avcodec_parameters_alloc(), a = [
|
|
518
|
+
r.AVCodecParameters_channels_s(i, e.numberOfChannels),
|
|
519
|
+
r.AVCodecParameters_sample_rate_s(i, e.sampleRate),
|
|
520
|
+
r.AVCodecParameters_codec_type_s(i, 1)
|
|
521
|
+
], o = 0;
|
|
522
|
+
t ? (a.push(r.AVCodecParameters_extradata_size_s(i, t.byteLength)), o = yield r.calloc(t.byteLength + 64, 1), a.push(r.copyin_u8(o, t)), a.push(r.AVCodecParameters_extradata_s(i, o))) : (a.push(r.AVCodecParameters_extradata_s(i, 0)), a.push(r.AVCodecParameters_extradata_size_s(i, 0))), yield Promise.all(a), [this._codec, this._c, this._pkt, this._frame] = yield r.ff_init_decoder(n.codec, i);
|
|
523
|
+
let s = [r.AVCodecContext_time_base_s(this._c, 1, 1e3), r.avcodec_parameters_free_js(i)];
|
|
524
|
+
o && s.push(r.free(o)), yield Promise.all(s);
|
|
525
|
+
})).catch(this._error);
|
|
526
|
+
}
|
|
527
|
+
_free() {
|
|
528
|
+
return w(this, void 0, void 0, function* () {
|
|
529
|
+
this._c && (yield this._libav.ff_free_decoder(this._c, this._pkt, this._frame), this._codec = this._c = this._pkt = this._frame = 0), this._libav &&= (g(this._libav), null);
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
_closeAudioDecoder(e) {
|
|
533
|
+
this._resetAudioDecoder(e), this.state = "closed", this._p = this._p.then(() => this._free()), e.name !== "AbortError" && (this._p = this._p.then(() => {
|
|
534
|
+
this._error(e);
|
|
535
|
+
}));
|
|
536
|
+
}
|
|
537
|
+
_resetAudioDecoder(e) {
|
|
538
|
+
if (this.state === "closed") throw new DOMException("Decoder closed", "InvalidStateError");
|
|
539
|
+
this.state = "unconfigured", this._p = this._p.then(() => this._free());
|
|
540
|
+
}
|
|
541
|
+
decode(e) {
|
|
542
|
+
if (this.state !== "configured") throw new DOMException("Unconfigured", "InvalidStateError");
|
|
543
|
+
this.decodeQueueSize++, this._p = this._p.then(() => w(this, void 0, void 0, function* () {
|
|
544
|
+
let t = this._libav, n = this._c, r = this._pkt, i = this._frame, a = null;
|
|
545
|
+
this.decodeQueueSize--, this.dispatchEvent(new CustomEvent("dequeue"));
|
|
546
|
+
try {
|
|
547
|
+
let o = Math.floor(e.timestamp / 1e3), [s, c] = t.f64toi64(o), l = {
|
|
548
|
+
data: e._libavGetData(),
|
|
549
|
+
pts: s,
|
|
550
|
+
ptshi: c,
|
|
551
|
+
dts: s,
|
|
552
|
+
dtshi: c
|
|
553
|
+
};
|
|
554
|
+
e.duration && (l.duration = Math.floor(e.duration / 1e3), l.durationhi = 0), a = yield t.ff_decode_multi(n, r, i, [l]);
|
|
555
|
+
} catch (e) {
|
|
556
|
+
this._p = this._p.then(() => {
|
|
557
|
+
this._closeAudioDecoder(e);
|
|
558
|
+
});
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
a && this._outputAudioData(a);
|
|
562
|
+
})).catch(this._error);
|
|
563
|
+
}
|
|
564
|
+
_outputAudioData(e) {
|
|
565
|
+
let n = this._libav;
|
|
566
|
+
for (let r of e) {
|
|
567
|
+
let e, i = !1;
|
|
568
|
+
switch (r.format) {
|
|
569
|
+
case n.AV_SAMPLE_FMT_U8:
|
|
570
|
+
e = "u8";
|
|
571
|
+
break;
|
|
572
|
+
case n.AV_SAMPLE_FMT_S16:
|
|
573
|
+
e = "s16";
|
|
574
|
+
break;
|
|
575
|
+
case n.AV_SAMPLE_FMT_S32:
|
|
576
|
+
e = "s32";
|
|
577
|
+
break;
|
|
578
|
+
case n.AV_SAMPLE_FMT_FLT:
|
|
579
|
+
e = "f32";
|
|
580
|
+
break;
|
|
581
|
+
case n.AV_SAMPLE_FMT_U8P:
|
|
582
|
+
e = "u8", i = !0;
|
|
583
|
+
break;
|
|
584
|
+
case n.AV_SAMPLE_FMT_S16P:
|
|
585
|
+
e = "s16", i = !0;
|
|
586
|
+
break;
|
|
587
|
+
case n.AV_SAMPLE_FMT_S32P:
|
|
588
|
+
e = "s32", i = !0;
|
|
589
|
+
break;
|
|
590
|
+
case n.AV_SAMPLE_FMT_FLTP:
|
|
591
|
+
e = "f32", i = !0;
|
|
592
|
+
break;
|
|
593
|
+
default: throw new DOMException("Unsupported libav format!", "EncodingError");
|
|
594
|
+
}
|
|
595
|
+
let a = r.sample_rate, o = r.nb_samples, s = r.channels, c = n.i64tof64(r.pts, r.ptshi) * 1e3, l;
|
|
596
|
+
if (i) {
|
|
597
|
+
let e = 0;
|
|
598
|
+
for (let t = 0; t < r.data.length; t++) e += r.data[t].length;
|
|
599
|
+
l = new r.data[0].constructor(e), e = 0;
|
|
600
|
+
for (let t = 0; t < r.data.length; t++) {
|
|
601
|
+
let n = r.data[t];
|
|
602
|
+
l.set(n, e), e += n.length;
|
|
603
|
+
}
|
|
604
|
+
} else l = r.data;
|
|
605
|
+
let u = new t({
|
|
606
|
+
format: e,
|
|
607
|
+
sampleRate: a,
|
|
608
|
+
numberOfFrames: o,
|
|
609
|
+
numberOfChannels: s,
|
|
610
|
+
timestamp: c,
|
|
611
|
+
data: l
|
|
612
|
+
});
|
|
613
|
+
this._output(u);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
flush() {
|
|
617
|
+
if (this.state !== "configured") throw new DOMException("Invalid state", "InvalidStateError");
|
|
618
|
+
let e = this._p.then(() => w(this, void 0, void 0, function* () {
|
|
619
|
+
if (!this._c) return;
|
|
620
|
+
let e = this._libav, t = this._c, n = this._pkt, r = this._frame, i = null;
|
|
621
|
+
try {
|
|
622
|
+
i = yield e.ff_decode_multi(t, n, r, [], !0);
|
|
623
|
+
} catch (e) {
|
|
624
|
+
this._p = this._p.then(() => {
|
|
625
|
+
this._closeAudioDecoder(e);
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
i && this._outputAudioData(i);
|
|
629
|
+
}));
|
|
630
|
+
return this._p = e, e;
|
|
631
|
+
}
|
|
632
|
+
reset() {
|
|
633
|
+
this._resetAudioDecoder(new DOMException("Reset", "AbortError"));
|
|
634
|
+
}
|
|
635
|
+
close() {
|
|
636
|
+
this._closeAudioDecoder(new DOMException("Close", "AbortError"));
|
|
637
|
+
}
|
|
638
|
+
static isConfigSupported(e) {
|
|
639
|
+
return w(this, void 0, void 0, function* () {
|
|
640
|
+
let t = y(e.codec, e), n = !1;
|
|
641
|
+
if (t) {
|
|
642
|
+
let e = yield h();
|
|
643
|
+
try {
|
|
644
|
+
let [, r, i, a] = yield e.ff_init_decoder(t.codec);
|
|
645
|
+
yield e.ff_free_decoder(r, i, a), n = !0;
|
|
646
|
+
} catch {}
|
|
647
|
+
yield g(e);
|
|
648
|
+
}
|
|
649
|
+
return {
|
|
650
|
+
supported: n,
|
|
651
|
+
config: C(e, [
|
|
652
|
+
"codec",
|
|
653
|
+
"sampleRate",
|
|
654
|
+
"numberOfChannels"
|
|
655
|
+
])
|
|
656
|
+
};
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
}, E = function(e, t, n, r) {
|
|
660
|
+
function i(e) {
|
|
661
|
+
return e instanceof n ? e : new n(function(t) {
|
|
662
|
+
t(e);
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
return new (n ||= Promise)(function(n, a) {
|
|
666
|
+
function o(e) {
|
|
667
|
+
try {
|
|
668
|
+
c(r.next(e));
|
|
669
|
+
} catch (e) {
|
|
670
|
+
a(e);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
function s(e) {
|
|
674
|
+
try {
|
|
675
|
+
c(r.throw(e));
|
|
676
|
+
} catch (e) {
|
|
677
|
+
a(e);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
function c(e) {
|
|
681
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
682
|
+
}
|
|
683
|
+
c((r = r.apply(e, t || [])).next());
|
|
684
|
+
});
|
|
685
|
+
}, D = class extends o {
|
|
686
|
+
constructor(e) {
|
|
687
|
+
super(), this._outputMetadata = null, this._outputMetadataFilled = !1, this._pts = null, this._p = Promise.all([]), this._libav = null, this._codec = this._c = this._frame = this._pkt = 0, this._filter_in_ctx = this._filter_out_ctx = null, this._filter_graph = this._buffersrc_ctx = this._buffersink_ctx = 0, this._output = e.output, this._error = e.error, this.state = "unconfigured", this.encodeQueueSize = 0;
|
|
688
|
+
}
|
|
689
|
+
configure(e) {
|
|
690
|
+
let t = this;
|
|
691
|
+
if (this.state === "closed") throw new DOMException("Encoder is closed", "InvalidStateError");
|
|
692
|
+
this._libav && (this._p = this._p.then(() => this._free())), this.state = "configured", this._p = this._p.then(function() {
|
|
693
|
+
return E(this, void 0, void 0, function* () {
|
|
694
|
+
let n = b(e.codec, e);
|
|
695
|
+
if (t._outputMetadata = { decoderConfig: {
|
|
696
|
+
codec: e.codec,
|
|
697
|
+
sampleRate: 0,
|
|
698
|
+
numberOfChannels: 0
|
|
699
|
+
} }, t._outputMetadataFilled = !1, !n) {
|
|
700
|
+
t._closeAudioEncoder(new DOMException("Unsupported codec", "NotSupportedError"));
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
let r = t._libav = yield h(), i;
|
|
704
|
+
[t._codec, t._c, t._frame, t._pkt, i] = yield r.ff_init_encoder(n.codec, n), t._pts = null, yield r.AVCodecContext_time_base_s(t._c, 1, n.ctx.sample_rate), t._filter_out_ctx = {
|
|
705
|
+
sample_rate: n.ctx.sample_rate,
|
|
706
|
+
sample_fmt: n.ctx.sample_fmt,
|
|
707
|
+
channel_layout: n.ctx.channel_layout,
|
|
708
|
+
frame_size: i
|
|
709
|
+
};
|
|
710
|
+
});
|
|
711
|
+
}).catch(this._error);
|
|
712
|
+
}
|
|
713
|
+
_free() {
|
|
714
|
+
return E(this, void 0, void 0, function* () {
|
|
715
|
+
this._filter_graph &&= (yield this._libav.avfilter_graph_free_js(this._filter_graph), this._filter_in_ctx = this._filter_out_ctx = null, this._buffersrc_ctx = this._buffersink_ctx = 0), this._c && (yield this._libav.ff_free_encoder(this._c, this._frame, this._pkt), this._codec = this._c = this._frame = this._pkt = 0), this._libav &&= (g(this._libav), null);
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
_closeAudioEncoder(e) {
|
|
719
|
+
this._resetAudioEncoder(e), this.state = "closed", this._p = this._p.then(() => this._free()), e.name !== "AbortError" && (this._p = this._p.then(() => {
|
|
720
|
+
this._error(e);
|
|
721
|
+
}));
|
|
722
|
+
}
|
|
723
|
+
_resetAudioEncoder(e) {
|
|
724
|
+
if (this.state === "closed") throw new DOMException("Encoder closed", "InvalidStateError");
|
|
725
|
+
this.state = "unconfigured", this._p = this._p.then(() => this._free());
|
|
726
|
+
}
|
|
727
|
+
encode(e) {
|
|
728
|
+
if (e._libavGetData() === null) throw TypeError("Detached");
|
|
729
|
+
if (this.state !== "configured") throw new DOMException("Unconfigured", "InvalidStateError");
|
|
730
|
+
let t = e.clone();
|
|
731
|
+
this.encodeQueueSize++, this._p = this._p.then(() => E(this, void 0, void 0, function* () {
|
|
732
|
+
let e = this._libav, n = this._c, r = this._pkt, a = this._frame, o = null;
|
|
733
|
+
this.encodeQueueSize--, this.dispatchEvent(new CustomEvent("dequeue"));
|
|
734
|
+
try {
|
|
735
|
+
let s = t._libavGetData(), c = t.numberOfFrames;
|
|
736
|
+
if (!i(t.format)) {
|
|
737
|
+
let e = [];
|
|
738
|
+
for (let n = 0; n < t.numberOfChannels; n++) e.push(s.subarray(n * c, (n + 1) * c));
|
|
739
|
+
s = e;
|
|
740
|
+
}
|
|
741
|
+
let l;
|
|
742
|
+
switch (t.format) {
|
|
743
|
+
case "u8":
|
|
744
|
+
l = e.AV_SAMPLE_FMT_U8;
|
|
745
|
+
break;
|
|
746
|
+
case "s16":
|
|
747
|
+
l = e.AV_SAMPLE_FMT_S16;
|
|
748
|
+
break;
|
|
749
|
+
case "s32":
|
|
750
|
+
l = e.AV_SAMPLE_FMT_S32;
|
|
751
|
+
break;
|
|
752
|
+
case "f32":
|
|
753
|
+
l = e.AV_SAMPLE_FMT_FLT;
|
|
754
|
+
break;
|
|
755
|
+
case "u8-planar":
|
|
756
|
+
l = e.AV_SAMPLE_FMT_U8P;
|
|
757
|
+
break;
|
|
758
|
+
case "s16-planar":
|
|
759
|
+
l = e.AV_SAMPLE_FMT_S16P;
|
|
760
|
+
break;
|
|
761
|
+
case "s32-planar":
|
|
762
|
+
l = e.AV_SAMPLE_FMT_S32P;
|
|
763
|
+
break;
|
|
764
|
+
case "f32-planar":
|
|
765
|
+
l = e.AV_SAMPLE_FMT_FLTP;
|
|
766
|
+
break;
|
|
767
|
+
default: throw TypeError("Invalid AudioSampleFormat");
|
|
768
|
+
}
|
|
769
|
+
let u = Math.floor(t.timestamp / 1e3), [d, f] = e.f64toi64(u), p = t.numberOfChannels, m = p === 1 ? 4 : (1 << p) - 1, h = t.sampleRate, g = {
|
|
770
|
+
data: s,
|
|
771
|
+
format: l,
|
|
772
|
+
pts: d,
|
|
773
|
+
ptshi: f,
|
|
774
|
+
channel_layout: m,
|
|
775
|
+
sample_rate: h
|
|
776
|
+
}, _ = null;
|
|
777
|
+
if (this._filter_in_ctx) {
|
|
778
|
+
let t = this._filter_in_ctx;
|
|
779
|
+
if (t.sample_fmt !== g.format || t.channel_layout !== g.channel_layout || t.sample_rate !== g.sample_rate) {
|
|
780
|
+
let t = yield this._filter([], !0);
|
|
781
|
+
t = t.filter((e) => {
|
|
782
|
+
let t;
|
|
783
|
+
return t = e.data[0].length ? e.data[0].length : e.data.length / e.channels, t === this._filter_out_ctx.frame_size;
|
|
784
|
+
}), t.length && (_ = yield e.ff_encode_multi(n, a, r, t)), yield e.avfilter_graph_free_js(this._filter_graph), this._filter_in_ctx = null, this._filter_graph = this._buffersrc_ctx = this._buffersink_ctx = 0;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
if (!this._filter_graph) {
|
|
788
|
+
let t = this._filter_in_ctx = {
|
|
789
|
+
sample_rate: g.sample_rate,
|
|
790
|
+
sample_fmt: g.format,
|
|
791
|
+
channel_layout: g.channel_layout
|
|
792
|
+
};
|
|
793
|
+
[this._filter_graph, this._buffersrc_ctx, this._buffersink_ctx] = yield e.ff_init_filter_graph("aresample", t, this._filter_out_ctx);
|
|
794
|
+
}
|
|
795
|
+
let v = yield this._filter([g]);
|
|
796
|
+
o = yield e.ff_encode_multi(n, a, r, v), _ && (o = _.concat(o)), o.length && !this._outputMetadataFilled && v && v.length && (yield this._getOutputMetadata(v[0]));
|
|
797
|
+
} catch (e) {
|
|
798
|
+
this._p = this._p.then(() => {
|
|
799
|
+
this._closeAudioEncoder(e);
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
o && this._outputEncodedAudioChunks(o);
|
|
803
|
+
})).catch(this._error);
|
|
804
|
+
}
|
|
805
|
+
_filter(e, t = !1) {
|
|
806
|
+
return E(this, void 0, void 0, function* () {
|
|
807
|
+
e.length && this._pts === null && (this._pts = e[0].pts || 0);
|
|
808
|
+
let n = yield this._libav.ff_filter_multi(this._buffersrc_ctx, this._buffersink_ctx, this._frame, e, t);
|
|
809
|
+
for (let e of n) e.pts = this._pts, e.ptshi = 0, this._pts += e.nb_samples;
|
|
810
|
+
return n;
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
_getOutputMetadata(e) {
|
|
814
|
+
return E(this, void 0, void 0, function* () {
|
|
815
|
+
let t = this._libav, n = this._c, r = yield t.AVCodecContext_extradata(n), i = yield t.AVCodecContext_extradata_size(n), a = null;
|
|
816
|
+
r && i && (a = yield t.copyout_u8(r, i)), this._outputMetadata.decoderConfig.sampleRate = e.sample_rate, this._outputMetadata.decoderConfig.numberOfChannels = e.channels, a && (this._outputMetadata.decoderConfig.description = a), this._outputMetadataFilled = !0;
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
_outputEncodedAudioChunks(t) {
|
|
820
|
+
let n = this._libav, r = this._filter_out_ctx.sample_rate;
|
|
821
|
+
for (let i of t) {
|
|
822
|
+
let t = i.data, a = i.flags & 1 ? "key" : "delta", o = n.i64tof64(i.pts, i.ptshi);
|
|
823
|
+
o = Math.floor(o / r * 1e6);
|
|
824
|
+
let s;
|
|
825
|
+
i.duration !== void 0 && (s = n.i64tof64(i.duration, i.durationhi || 0), s = Math.floor(s / r * 1e6));
|
|
826
|
+
let c = new e({
|
|
827
|
+
data: t,
|
|
828
|
+
type: a,
|
|
829
|
+
timestamp: o,
|
|
830
|
+
duration: s
|
|
831
|
+
});
|
|
832
|
+
this._outputMetadataFilled ? this._output(c, this._outputMetadata || void 0) : this._output(c);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
flush() {
|
|
836
|
+
if (this.state !== "configured") throw new DOMException("Invalid state", "InvalidStateError");
|
|
837
|
+
let e = this._p.then(() => E(this, void 0, void 0, function* () {
|
|
838
|
+
if (!this._c) return;
|
|
839
|
+
let e = this._libav, t = this._c, n = this._frame, r = this._pkt, i = this._buffersrc_ctx;
|
|
840
|
+
this._buffersink_ctx;
|
|
841
|
+
let a = null;
|
|
842
|
+
try {
|
|
843
|
+
let o = null;
|
|
844
|
+
i && (o = yield this._filter([], !0)), a = yield e.ff_encode_multi(t, n, r, o || [], !0), !this._outputMetadataFilled && o && o.length && (yield this._getOutputMetadata(o[0]));
|
|
845
|
+
} catch (e) {
|
|
846
|
+
this._p = this._p.then(() => {
|
|
847
|
+
this._closeAudioEncoder(e);
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
a && this._outputEncodedAudioChunks(a);
|
|
851
|
+
}));
|
|
852
|
+
return this._p = e, e;
|
|
853
|
+
}
|
|
854
|
+
reset() {
|
|
855
|
+
this._resetAudioEncoder(new DOMException("Reset", "AbortError"));
|
|
856
|
+
}
|
|
857
|
+
close() {
|
|
858
|
+
this._closeAudioEncoder(new DOMException("Close", "AbortError"));
|
|
859
|
+
}
|
|
860
|
+
static isConfigSupported(e) {
|
|
861
|
+
return E(this, void 0, void 0, function* () {
|
|
862
|
+
let t = b(e.codec, e), n = !1;
|
|
863
|
+
if (t) {
|
|
864
|
+
let e = yield h();
|
|
865
|
+
try {
|
|
866
|
+
let [, r, i, a] = yield e.ff_init_encoder(t.codec, t);
|
|
867
|
+
yield e.ff_free_encoder(r, i, a), n = !0;
|
|
868
|
+
} catch {}
|
|
869
|
+
yield g(e);
|
|
870
|
+
}
|
|
871
|
+
return {
|
|
872
|
+
supported: n,
|
|
873
|
+
config: C(e, [
|
|
874
|
+
"codec",
|
|
875
|
+
"sampleRate",
|
|
876
|
+
"numberOfChannels",
|
|
877
|
+
"bitrate"
|
|
878
|
+
])
|
|
879
|
+
};
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
}, O = e, k = function(e, t, n, r) {
|
|
883
|
+
function i(e) {
|
|
884
|
+
return e instanceof n ? e : new n(function(t) {
|
|
885
|
+
t(e);
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
return new (n ||= Promise)(function(n, a) {
|
|
889
|
+
function o(e) {
|
|
890
|
+
try {
|
|
891
|
+
c(r.next(e));
|
|
892
|
+
} catch (e) {
|
|
893
|
+
a(e);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
function s(e) {
|
|
897
|
+
try {
|
|
898
|
+
c(r.throw(e));
|
|
899
|
+
} catch (e) {
|
|
900
|
+
a(e);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
function c(e) {
|
|
904
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
905
|
+
}
|
|
906
|
+
c((r = r.apply(e, t || [])).next());
|
|
907
|
+
});
|
|
908
|
+
}, A = null, j = class e {
|
|
909
|
+
constructor(t, n) {
|
|
910
|
+
if (this.format = "I420", this.codedWidth = 0, this.codedHeight = 0, this.codedRect = null, this.visibleRect = null, this.displayWidth = 0, this.displayHeight = 0, this.timestamp = 0, this._layout = null, this._data = null, this._nonSquarePixels = !1, this._sar_num = 1, this._sar_den = 1, t instanceof ArrayBuffer || t.buffer instanceof ArrayBuffer) this._constructBuffer(t, n);
|
|
911
|
+
else if (t instanceof e || globalThis.VideoFrame && t instanceof globalThis.VideoFrame) {
|
|
912
|
+
let e = new Uint8Array(t.allocationSize());
|
|
913
|
+
t.copyTo(e), this._constructBuffer(e, {
|
|
914
|
+
transfer: [e.buffer],
|
|
915
|
+
format: t.format,
|
|
916
|
+
codedHeight: t.codedHeight,
|
|
917
|
+
codedWidth: t.codedWidth,
|
|
918
|
+
colorSpace: t.colorSpace,
|
|
919
|
+
visibleRect: n?.visibleRect || t.visibleRect,
|
|
920
|
+
displayHeight: n?.displayHeight || t.displayHeight,
|
|
921
|
+
displayWidth: n?.displayWidth || t.displayWidth,
|
|
922
|
+
duration: n?.duration || t.duration,
|
|
923
|
+
timestamp: n?.timestamp || t.timestamp,
|
|
924
|
+
metadata: JSON.parse(JSON.stringify(n?.metadata))
|
|
925
|
+
});
|
|
926
|
+
} else if (t instanceof HTMLVideoElement) {
|
|
927
|
+
if (t.readyState === HTMLVideoElement.prototype.HAVE_NOTHING || t.readyState === HTMLVideoElement.prototype.HAVE_METADATA) throw new DOMException("Video is not ready for reading frames", "InvalidStateError");
|
|
928
|
+
if (t.networkState === t.NETWORK_EMPTY) throw new DOMException("Video network state is empty", "InvalidStateError");
|
|
929
|
+
this._constructCanvas(t, Object.assign(Object.assign({}, n), { timestamp: n?.timestamp || t.currentTime * 1e6 }));
|
|
930
|
+
} else this._constructCanvas(t, n);
|
|
931
|
+
}
|
|
932
|
+
_constructCanvas(e, t) {
|
|
933
|
+
let n = 0, r = 0;
|
|
934
|
+
if (e.naturalWidth ? (n = e.naturalWidth, r = e.naturalHeight) : e.videoWidth ? (n = e.videoWidth, r = e.videoHeight) : e.width && (n = e.width, r = e.height), !n || !r) throw new DOMException("Could not determine dimensions", "InvalidStateError");
|
|
935
|
+
A === null && (typeof OffscreenCanvas < "u" ? A = new OffscreenCanvas(n, r) : (A = document.createElement("canvas"), A.style.display = "none", document.body.appendChild(A))), A.width = n, A.height = r;
|
|
936
|
+
let i = A.getContext("2d", {
|
|
937
|
+
desynchronized: !0,
|
|
938
|
+
willReadFrequently: !0
|
|
939
|
+
});
|
|
940
|
+
i.clearRect(0, 0, n, r), i.drawImage(e, 0, 0), this._constructBuffer(i.getImageData(0, 0, n, r).data, {
|
|
941
|
+
format: "RGBA",
|
|
942
|
+
codedWidth: n,
|
|
943
|
+
codedHeight: r,
|
|
944
|
+
timestamp: t?.timestamp || 0,
|
|
945
|
+
duration: t?.duration || 0,
|
|
946
|
+
layout: [{
|
|
947
|
+
offset: 0,
|
|
948
|
+
stride: n * 4
|
|
949
|
+
}],
|
|
950
|
+
displayWidth: t?.displayWidth || n,
|
|
951
|
+
displayHeight: t?.displayHeight || r
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
_constructBuffer(t, n) {
|
|
955
|
+
e._checkValidVideoFrameBufferInit(n);
|
|
956
|
+
let r = new DOMRect(0, 0, n.codedWidth, n.codedHeight), i;
|
|
957
|
+
n.visibleRect && (i = DOMRect.fromRect(n.visibleRect)), this.codedWidth = n.codedWidth, this.codedHeight = n.codedHeight;
|
|
958
|
+
let a = this._parseVisibleRect(r, i || null), o;
|
|
959
|
+
n.layout && (o = n.layout instanceof Array ? n.layout : Array.from(n.layout)), this.format = n.format;
|
|
960
|
+
let s = this._computeLayoutAndAllocationSize(a, o || null);
|
|
961
|
+
if (t.byteLength < s.allocationSize) throw TypeError("data is too small for layout");
|
|
962
|
+
let c = !1;
|
|
963
|
+
if (n.transfer) {
|
|
964
|
+
let e;
|
|
965
|
+
e = t.buffer ? t.buffer : t;
|
|
966
|
+
let r;
|
|
967
|
+
r = n.transfer instanceof Array ? n.transfer : Array.from(n.transfer);
|
|
968
|
+
for (let t of r) if (t === e) {
|
|
969
|
+
c = !0;
|
|
970
|
+
break;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
let l = n.format;
|
|
974
|
+
if (n.layout) n.layout instanceof Array ? this._layout = n.layout : this._layout = Array.from(n.layout);
|
|
975
|
+
else {
|
|
976
|
+
let e = N(l), t = [], n = 0;
|
|
977
|
+
for (let r = 0; r < e; r++) {
|
|
978
|
+
let e = F(l, r), i = I(l, r), a = ~~(this.codedWidth / e);
|
|
979
|
+
t.push({
|
|
980
|
+
offset: n,
|
|
981
|
+
stride: a
|
|
982
|
+
}), n += a * ~~(this.codedHeight / i);
|
|
983
|
+
}
|
|
984
|
+
this._layout = t;
|
|
985
|
+
}
|
|
986
|
+
if (this._data = new Uint8Array(t.buffer || t, t.byteOffset || 0), !c) {
|
|
987
|
+
let e = N(l), t = this._layout, n = Infinity, r = 0;
|
|
988
|
+
for (let i = 0; i < e; i++) {
|
|
989
|
+
let e = t[i], a = e.offset;
|
|
990
|
+
a < n && (n = a);
|
|
991
|
+
let o = I(l, i);
|
|
992
|
+
a += e.stride * ~~(this.codedHeight / o), a > r && (r = a);
|
|
993
|
+
}
|
|
994
|
+
n !== 0 && (t = this._layout = t.map((e) => ({
|
|
995
|
+
offset: e.offset - n,
|
|
996
|
+
stride: e.stride
|
|
997
|
+
}))), this._data = this._data.slice(n, r);
|
|
998
|
+
}
|
|
999
|
+
let u = n.codedWidth, d = n.codedHeight;
|
|
1000
|
+
a.left, a.top, this.codedRect = new DOMRect(0, 0, u, d), this.visibleRect = a, n.visibleRect ? this.visibleRect = DOMRect.fromRect(n.visibleRect) : this.visibleRect = new DOMRect(0, 0, u, d), typeof n.displayWidth == "number" ? this.displayWidth = n.displayWidth : this.displayWidth = this.visibleRect.width, typeof n.displayHeight == "number" ? this.displayHeight = n.displayHeight : this.displayHeight = this.visibleRect.height, this.displayWidth !== this.visibleRect.width || this.displayHeight !== this.visibleRect.height ? (this._nonSquarePixels = !0, this._sar_num = this.displayWidth * this.visibleRect.width, this._sar_den = this.displayHeight * this.visibleRect.height) : (this._nonSquarePixels = !1, this._sar_num = this._sar_den = 1), this.timestamp = n.timestamp, this.duration = n.duration;
|
|
1001
|
+
}
|
|
1002
|
+
toNative(e = {}) {
|
|
1003
|
+
let t = new globalThis.VideoFrame(this._data, {
|
|
1004
|
+
layout: this._layout,
|
|
1005
|
+
format: this.format,
|
|
1006
|
+
codedWidth: this.codedWidth,
|
|
1007
|
+
codedHeight: this.codedHeight,
|
|
1008
|
+
visibleRect: this.visibleRect,
|
|
1009
|
+
displayWidth: this.displayWidth,
|
|
1010
|
+
displayHeight: this.displayHeight,
|
|
1011
|
+
duration: this.duration,
|
|
1012
|
+
timestamp: this.timestamp,
|
|
1013
|
+
transfer: e.transfer ? [this._data.buffer] : []
|
|
1014
|
+
});
|
|
1015
|
+
return e.transfer && this.close(), t;
|
|
1016
|
+
}
|
|
1017
|
+
static fromNative(t) {
|
|
1018
|
+
let n = t, r = new Uint8Array(n.allocationSize());
|
|
1019
|
+
return n.copyTo(r), new e(r, {
|
|
1020
|
+
format: n.format,
|
|
1021
|
+
codedWidth: n.codedWidth,
|
|
1022
|
+
codedHeight: n.codedHeight,
|
|
1023
|
+
visibleRect: n.visibleRect,
|
|
1024
|
+
displayWidth: n.displayWidth,
|
|
1025
|
+
displayHeight: n.displayHeight,
|
|
1026
|
+
duration: n.duration,
|
|
1027
|
+
timestamp: n.timestamp
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
_libavGetData() {
|
|
1031
|
+
return this._data;
|
|
1032
|
+
}
|
|
1033
|
+
_libavGetLayout() {
|
|
1034
|
+
return this._layout;
|
|
1035
|
+
}
|
|
1036
|
+
static _checkValidVideoFrameBufferInit(e) {
|
|
1037
|
+
if (!e.codedWidth || !e.codedHeight) throw TypeError("Invalid coded dimensions");
|
|
1038
|
+
if (e.visibleRect) {
|
|
1039
|
+
let t = DOMRect.fromRect(e.visibleRect);
|
|
1040
|
+
if (t.x < 0 || !Number.isFinite(t.x) || t.y < 0 || !Number.isFinite(t.y) || t.width < 0 || !Number.isFinite(t.width) || t.height < 0 || !Number.isFinite(t.height)) throw TypeError("Invalid visible rectangle");
|
|
1041
|
+
if (t.y + t.height > e.codedHeight) throw TypeError("Visible rectangle outside of coded height");
|
|
1042
|
+
if (t.x + t.width > e.codedWidth) throw TypeError("Visible rectangle outside of coded width");
|
|
1043
|
+
if (e.displayWidth && !e.displayHeight || !e.displayWidth && !e.displayHeight || e.displayWidth === 0 || e.displayHeight === 0) throw TypeError("Invalid display dimensions");
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
metadata() {
|
|
1047
|
+
if (this._data === null) throw new DOMException("Detached", "InvalidStateError");
|
|
1048
|
+
return null;
|
|
1049
|
+
}
|
|
1050
|
+
allocationSize(e = {}) {
|
|
1051
|
+
if (this._data === null) throw new DOMException("Detached", "InvalidStateError");
|
|
1052
|
+
if (this.format === null) throw new DOMException("Not supported", "NotSupportedError");
|
|
1053
|
+
return this._parseVideoFrameCopyToOptions(e).allocationSize;
|
|
1054
|
+
}
|
|
1055
|
+
_parseVideoFrameCopyToOptions(e) {
|
|
1056
|
+
let t = this.visibleRect, n = e.rect ? new DOMRect(e.rect.x, e.rect.y, e.rect.width, e.rect.height) : null, r = this._parseVisibleRect(t, n), i = null;
|
|
1057
|
+
return e.layout && (i = e.layout instanceof Array ? e.layout : Array.from(e.layout)), this._computeLayoutAndAllocationSize(r, i);
|
|
1058
|
+
}
|
|
1059
|
+
_parseVisibleRect(e, t) {
|
|
1060
|
+
let n = e;
|
|
1061
|
+
if (t) {
|
|
1062
|
+
if (t.width === 0 || t.height === 0 || t.x + t.width > this.codedWidth || t.y + t.height > this.codedHeight) throw TypeError("Invalid rectangle");
|
|
1063
|
+
n = t;
|
|
1064
|
+
}
|
|
1065
|
+
if (!this._verifyRectOffsetAlignment(n)) throw TypeError("Invalid alignment");
|
|
1066
|
+
return n;
|
|
1067
|
+
}
|
|
1068
|
+
_computeLayoutAndAllocationSize(e, t) {
|
|
1069
|
+
let n = N(this.format);
|
|
1070
|
+
if (t && t.length !== n) throw TypeError("Invalid layout");
|
|
1071
|
+
let r = 0, i = [], a = [], o = 0;
|
|
1072
|
+
for (; o < n;) {
|
|
1073
|
+
let n = P(this.format, o), s = F(this.format, o), c = I(this.format, o), l = {
|
|
1074
|
+
destinationOffset: 0,
|
|
1075
|
+
destinationStride: 0,
|
|
1076
|
+
sourceTop: Math.ceil(~~e.y / c),
|
|
1077
|
+
sourceHeight: Math.ceil(~~e.height / c),
|
|
1078
|
+
sourceLeftBytes: ~~(e.x / s * n),
|
|
1079
|
+
sourceWidthBytes: ~~(e.width / s * n)
|
|
1080
|
+
};
|
|
1081
|
+
if (t) {
|
|
1082
|
+
let e = t[o];
|
|
1083
|
+
if (e.stride < l.sourceWidthBytes) throw TypeError("Invalid stride");
|
|
1084
|
+
l.destinationOffset = e.offset, l.destinationStride = e.stride;
|
|
1085
|
+
} else l.destinationOffset = r, l.destinationStride = l.sourceWidthBytes;
|
|
1086
|
+
let u = l.destinationStride * l.sourceHeight, d = u + l.destinationOffset;
|
|
1087
|
+
if (u >= 4294967296 || d >= 4294967296) throw TypeError("Plane too large");
|
|
1088
|
+
a.push(d), d > r && (r = d);
|
|
1089
|
+
let f = 0;
|
|
1090
|
+
for (; f < o;) {
|
|
1091
|
+
if (!(d <= i[f].destinationOffset || a[f] <= l.destinationOffset)) throw TypeError("Invalid plane layout");
|
|
1092
|
+
f++;
|
|
1093
|
+
}
|
|
1094
|
+
i.push(l), o++;
|
|
1095
|
+
}
|
|
1096
|
+
return {
|
|
1097
|
+
computedLayouts: i,
|
|
1098
|
+
allocationSize: r
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
_verifyRectOffsetAlignment(e) {
|
|
1102
|
+
if (!this.format) return !0;
|
|
1103
|
+
let t = 0, n = N(this.format);
|
|
1104
|
+
for (; t < n;) {
|
|
1105
|
+
let n = F(this.format, t), r = I(this.format, t), i = e.x / n;
|
|
1106
|
+
if (i !== ~~i) return !1;
|
|
1107
|
+
let a = e.y / r;
|
|
1108
|
+
if (a !== ~~a) return !1;
|
|
1109
|
+
t++;
|
|
1110
|
+
}
|
|
1111
|
+
return !0;
|
|
1112
|
+
}
|
|
1113
|
+
copyTo(e, t = {}) {
|
|
1114
|
+
return k(this, void 0, void 0, function* () {
|
|
1115
|
+
let n = new Uint8Array(e.buffer || e, e.byteOffset || 0);
|
|
1116
|
+
if (this._data === null) throw new DOMException("Detached", "InvalidStateError");
|
|
1117
|
+
if (!this.format) throw new DOMException("No format", "NotSupportedError");
|
|
1118
|
+
let r = this._parseVideoFrameCopyToOptions(t);
|
|
1119
|
+
if (e.byteLength < r.allocationSize) throw TypeError("Insufficient space");
|
|
1120
|
+
let i = [];
|
|
1121
|
+
{
|
|
1122
|
+
N(this.format);
|
|
1123
|
+
let e = 0;
|
|
1124
|
+
for (; e < r.computedLayouts.length;) {
|
|
1125
|
+
let t = this._layout[e].stride, a = r.computedLayouts[e], o = a.sourceTop * t;
|
|
1126
|
+
o += a.sourceLeftBytes;
|
|
1127
|
+
let s = a.destinationOffset, c = a.sourceWidthBytes, l = {
|
|
1128
|
+
offset: a.destinationOffset,
|
|
1129
|
+
stride: a.destinationStride
|
|
1130
|
+
}, u = 0;
|
|
1131
|
+
for (; u < a.sourceHeight;) n.set(this._data.subarray(o, o + c), s), o += t, s += a.destinationStride, u++;
|
|
1132
|
+
e++, i.push(l);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
return i;
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
clone() {
|
|
1139
|
+
return new e(this._data, {
|
|
1140
|
+
format: this.format,
|
|
1141
|
+
codedWidth: this.codedWidth,
|
|
1142
|
+
codedHeight: this.codedHeight,
|
|
1143
|
+
timestamp: this.timestamp,
|
|
1144
|
+
duration: this.duration,
|
|
1145
|
+
layout: this._layout,
|
|
1146
|
+
transfer: [this._data.buffer]
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
close() {
|
|
1150
|
+
this._data = null;
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
function M(e, t) {
|
|
1154
|
+
let n = e.AV_PIX_FMT_RGBA;
|
|
1155
|
+
switch (t) {
|
|
1156
|
+
case "I420":
|
|
1157
|
+
n = e.AV_PIX_FMT_YUV420P;
|
|
1158
|
+
break;
|
|
1159
|
+
case "I420P10":
|
|
1160
|
+
n = 62;
|
|
1161
|
+
break;
|
|
1162
|
+
case "I420P12":
|
|
1163
|
+
n = 123;
|
|
1164
|
+
break;
|
|
1165
|
+
case "I420A":
|
|
1166
|
+
n = e.AV_PIX_FMT_YUVA420P;
|
|
1167
|
+
break;
|
|
1168
|
+
case "I420AP10":
|
|
1169
|
+
n = 87;
|
|
1170
|
+
break;
|
|
1171
|
+
case "I420AP12": throw TypeError("YUV420P12 is not supported by libav");
|
|
1172
|
+
case "I422":
|
|
1173
|
+
n = e.AV_PIX_FMT_YUV422P;
|
|
1174
|
+
break;
|
|
1175
|
+
case "I422P10":
|
|
1176
|
+
n = 64;
|
|
1177
|
+
break;
|
|
1178
|
+
case "I422P12":
|
|
1179
|
+
n = 127;
|
|
1180
|
+
break;
|
|
1181
|
+
case "I422A":
|
|
1182
|
+
n = 78;
|
|
1183
|
+
break;
|
|
1184
|
+
case "I422AP10":
|
|
1185
|
+
n = 89;
|
|
1186
|
+
break;
|
|
1187
|
+
case "I422AP10":
|
|
1188
|
+
n = 186;
|
|
1189
|
+
break;
|
|
1190
|
+
case "I444":
|
|
1191
|
+
n = e.AV_PIX_FMT_YUV444P;
|
|
1192
|
+
break;
|
|
1193
|
+
case "I444P10":
|
|
1194
|
+
n = 68;
|
|
1195
|
+
break;
|
|
1196
|
+
case "I444P12":
|
|
1197
|
+
n = 131;
|
|
1198
|
+
break;
|
|
1199
|
+
case "I444A":
|
|
1200
|
+
n = 79;
|
|
1201
|
+
break;
|
|
1202
|
+
case "I444AP10":
|
|
1203
|
+
n = 91;
|
|
1204
|
+
break;
|
|
1205
|
+
case "I444AP12":
|
|
1206
|
+
n = 188;
|
|
1207
|
+
break;
|
|
1208
|
+
case "NV12":
|
|
1209
|
+
n = e.AV_PIX_FMT_NV12;
|
|
1210
|
+
break;
|
|
1211
|
+
case "RGBA":
|
|
1212
|
+
n = e.AV_PIX_FMT_RGBA;
|
|
1213
|
+
break;
|
|
1214
|
+
case "RGBX":
|
|
1215
|
+
n = 119;
|
|
1216
|
+
break;
|
|
1217
|
+
case "BGRA":
|
|
1218
|
+
n = e.AV_PIX_FMT_BGRA;
|
|
1219
|
+
break;
|
|
1220
|
+
case "BGRX":
|
|
1221
|
+
n = 121;
|
|
1222
|
+
break;
|
|
1223
|
+
default: throw TypeError("Invalid VideoPixelFormat");
|
|
1224
|
+
}
|
|
1225
|
+
return n;
|
|
1226
|
+
}
|
|
1227
|
+
function N(e) {
|
|
1228
|
+
switch (e) {
|
|
1229
|
+
case "I420":
|
|
1230
|
+
case "I420P10":
|
|
1231
|
+
case "I420P12":
|
|
1232
|
+
case "I422":
|
|
1233
|
+
case "I422P10":
|
|
1234
|
+
case "I422P12":
|
|
1235
|
+
case "I444":
|
|
1236
|
+
case "I444P10":
|
|
1237
|
+
case "I444P12": return 3;
|
|
1238
|
+
case "I420A":
|
|
1239
|
+
case "I420AP10":
|
|
1240
|
+
case "I420AP12":
|
|
1241
|
+
case "I422A":
|
|
1242
|
+
case "I422AP10":
|
|
1243
|
+
case "I422AP12":
|
|
1244
|
+
case "I444A":
|
|
1245
|
+
case "I444AP10":
|
|
1246
|
+
case "I444AP12": return 4;
|
|
1247
|
+
case "NV12": return 2;
|
|
1248
|
+
case "RGBA":
|
|
1249
|
+
case "RGBX":
|
|
1250
|
+
case "BGRA":
|
|
1251
|
+
case "BGRX": return 1;
|
|
1252
|
+
default: throw new DOMException("Unsupported video pixel format", "NotSupportedError");
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
function P(e, t) {
|
|
1256
|
+
switch (e) {
|
|
1257
|
+
case "I420":
|
|
1258
|
+
case "I420A":
|
|
1259
|
+
case "I422":
|
|
1260
|
+
case "I422A":
|
|
1261
|
+
case "I444":
|
|
1262
|
+
case "I444A": return 1;
|
|
1263
|
+
case "I420P10":
|
|
1264
|
+
case "I420AP10":
|
|
1265
|
+
case "I422P10":
|
|
1266
|
+
case "I422AP10":
|
|
1267
|
+
case "I444P10":
|
|
1268
|
+
case "I444AP10":
|
|
1269
|
+
case "I420P12":
|
|
1270
|
+
case "I420AP12":
|
|
1271
|
+
case "I422P12":
|
|
1272
|
+
case "I422AP12":
|
|
1273
|
+
case "I444P12":
|
|
1274
|
+
case "I444AP12": return 2;
|
|
1275
|
+
case "NV12": return t === 1 ? 2 : 1;
|
|
1276
|
+
case "RGBA":
|
|
1277
|
+
case "RGBX":
|
|
1278
|
+
case "BGRA":
|
|
1279
|
+
case "BGRX": return 4;
|
|
1280
|
+
default: throw new DOMException("Unsupported video pixel format", "NotSupportedError");
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
function F(e, t) {
|
|
1284
|
+
if (t === 0 || t === 3) return 1;
|
|
1285
|
+
switch (e) {
|
|
1286
|
+
case "I420":
|
|
1287
|
+
case "I420P10":
|
|
1288
|
+
case "I420P12":
|
|
1289
|
+
case "I420A":
|
|
1290
|
+
case "I420AP10":
|
|
1291
|
+
case "I420AP12":
|
|
1292
|
+
case "I422":
|
|
1293
|
+
case "I422P10":
|
|
1294
|
+
case "I422P12":
|
|
1295
|
+
case "I422A":
|
|
1296
|
+
case "I422AP10":
|
|
1297
|
+
case "I422AP12": return 2;
|
|
1298
|
+
case "I444":
|
|
1299
|
+
case "I444P10":
|
|
1300
|
+
case "I444P12":
|
|
1301
|
+
case "I444A":
|
|
1302
|
+
case "I444AP10":
|
|
1303
|
+
case "I444AP12": return 1;
|
|
1304
|
+
case "NV12": return 2;
|
|
1305
|
+
case "RGBA":
|
|
1306
|
+
case "RGBX":
|
|
1307
|
+
case "BGRA":
|
|
1308
|
+
case "BGRX": return 1;
|
|
1309
|
+
default: throw new DOMException("Unsupported video pixel format", "NotSupportedError");
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
function I(e, t) {
|
|
1313
|
+
if (t === 0 || t === 3) return 1;
|
|
1314
|
+
switch (e) {
|
|
1315
|
+
case "I420":
|
|
1316
|
+
case "I420P10":
|
|
1317
|
+
case "I420P12":
|
|
1318
|
+
case "I420A":
|
|
1319
|
+
case "I420AP10":
|
|
1320
|
+
case "I420AP12": return 2;
|
|
1321
|
+
case "I422":
|
|
1322
|
+
case "I422P10":
|
|
1323
|
+
case "I422P12":
|
|
1324
|
+
case "I422A":
|
|
1325
|
+
case "I422AP10":
|
|
1326
|
+
case "I422AP12":
|
|
1327
|
+
case "I444":
|
|
1328
|
+
case "I444P10":
|
|
1329
|
+
case "I444P12":
|
|
1330
|
+
case "I444A":
|
|
1331
|
+
case "I444AP10":
|
|
1332
|
+
case "I444AP12": return 1;
|
|
1333
|
+
case "NV12": return 2;
|
|
1334
|
+
case "RGBA":
|
|
1335
|
+
case "RGBX":
|
|
1336
|
+
case "BGRA":
|
|
1337
|
+
case "BGRX": return 1;
|
|
1338
|
+
default: throw new DOMException("Unsupported video pixel format", "NotSupportedError");
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
//#endregion
|
|
1342
|
+
//#region ../../node_modules/@kixelated/libavjs-webcodecs-polyfill/dist/video-decoder.js
|
|
1343
|
+
var L = function(e, t, n, r) {
|
|
1344
|
+
function i(e) {
|
|
1345
|
+
return e instanceof n ? e : new n(function(t) {
|
|
1346
|
+
t(e);
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
return new (n ||= Promise)(function(n, a) {
|
|
1350
|
+
function o(e) {
|
|
1351
|
+
try {
|
|
1352
|
+
c(r.next(e));
|
|
1353
|
+
} catch (e) {
|
|
1354
|
+
a(e);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
function s(e) {
|
|
1358
|
+
try {
|
|
1359
|
+
c(r.throw(e));
|
|
1360
|
+
} catch (e) {
|
|
1361
|
+
a(e);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
function c(e) {
|
|
1365
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
1366
|
+
}
|
|
1367
|
+
c((r = r.apply(e, t || [])).next());
|
|
1368
|
+
});
|
|
1369
|
+
}, R = class extends o {
|
|
1370
|
+
constructor(e) {
|
|
1371
|
+
super(), this._p = Promise.all([]), this._libav = null, this._codec = this._c = this._pkt = this._frame = 0, this._output = e.output, this._error = e.error, this.state = "unconfigured", this.decodeQueueSize = 0;
|
|
1372
|
+
}
|
|
1373
|
+
configure(e) {
|
|
1374
|
+
if (this.state === "closed") throw new DOMException("Decoder is closed", "InvalidStateError");
|
|
1375
|
+
this._libav && (this._p = this._p.then(() => this._free())), this.state = "configured", this._p = this._p.then(() => L(this, void 0, void 0, function* () {
|
|
1376
|
+
let t = y(e.codec, e);
|
|
1377
|
+
if (!t) {
|
|
1378
|
+
this._closeVideoDecoder(new DOMException("Unsupported codec", "NotSupportedError"));
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
let n = this._libav = yield h();
|
|
1382
|
+
[this._codec, this._c, this._pkt, this._frame] = yield n.ff_init_decoder(t.codec), yield n.AVCodecContext_time_base_s(this._c, 1, 1e3);
|
|
1383
|
+
})).catch(this._error);
|
|
1384
|
+
}
|
|
1385
|
+
_free() {
|
|
1386
|
+
return L(this, void 0, void 0, function* () {
|
|
1387
|
+
this._c && (yield this._libav.ff_free_decoder(this._c, this._pkt, this._frame), this._codec = this._c = this._pkt = this._frame = 0), this._libav &&= (g(this._libav), null);
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
_closeVideoDecoder(e) {
|
|
1391
|
+
this._resetVideoDecoder(e), this.state = "closed", this._p = this._p.then(() => this._free()), e.name !== "AbortError" && (this._p = this._p.then(() => {
|
|
1392
|
+
this._error(e);
|
|
1393
|
+
}));
|
|
1394
|
+
}
|
|
1395
|
+
_resetVideoDecoder(e) {
|
|
1396
|
+
if (this.state === "closed") throw new DOMException("Decoder closed", "InvalidStateError");
|
|
1397
|
+
this.state = "unconfigured", this._p = this._p.then(() => this._free());
|
|
1398
|
+
}
|
|
1399
|
+
decode(e) {
|
|
1400
|
+
let t = this;
|
|
1401
|
+
if (this.state !== "configured") throw new DOMException("Unconfigured", "InvalidStateError");
|
|
1402
|
+
this.decodeQueueSize++, this._p = this._p.then(function() {
|
|
1403
|
+
return L(this, void 0, void 0, function* () {
|
|
1404
|
+
let n = t._libav, r = t._c, i = t._pkt, a = t._frame, o = null;
|
|
1405
|
+
t.decodeQueueSize--, t.dispatchEvent(new CustomEvent("dequeue"));
|
|
1406
|
+
try {
|
|
1407
|
+
let t = Math.floor(e.timestamp / 1e3), [s, c] = n.f64toi64(t), l = {
|
|
1408
|
+
data: e._libavGetData(),
|
|
1409
|
+
pts: s,
|
|
1410
|
+
ptshi: c,
|
|
1411
|
+
dts: s,
|
|
1412
|
+
dtshi: c
|
|
1413
|
+
};
|
|
1414
|
+
e.duration && (l.duration = Math.floor(e.duration / 1e3), l.durationhi = 0), o = yield n.ff_decode_multi(r, i, a, [l]);
|
|
1415
|
+
} catch (e) {
|
|
1416
|
+
t._p = t._p.then(() => {
|
|
1417
|
+
t._closeVideoDecoder(e);
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
o && t._outputVideoFrames(o);
|
|
1421
|
+
});
|
|
1422
|
+
}).catch(this._error);
|
|
1423
|
+
}
|
|
1424
|
+
_outputVideoFrames(e) {
|
|
1425
|
+
let t = this._libav;
|
|
1426
|
+
for (let n of e) {
|
|
1427
|
+
let e;
|
|
1428
|
+
switch (n.format) {
|
|
1429
|
+
case t.AV_PIX_FMT_YUV420P:
|
|
1430
|
+
e = "I420";
|
|
1431
|
+
break;
|
|
1432
|
+
case 62:
|
|
1433
|
+
e = "I420P10";
|
|
1434
|
+
break;
|
|
1435
|
+
case 123:
|
|
1436
|
+
e = "I420P12";
|
|
1437
|
+
break;
|
|
1438
|
+
case t.AV_PIX_FMT_YUVA420P:
|
|
1439
|
+
e = "I420A";
|
|
1440
|
+
break;
|
|
1441
|
+
case 87:
|
|
1442
|
+
e = "I420AP10";
|
|
1443
|
+
break;
|
|
1444
|
+
case t.AV_PIX_FMT_YUV422P:
|
|
1445
|
+
e = "I422";
|
|
1446
|
+
break;
|
|
1447
|
+
case 64:
|
|
1448
|
+
e = "I422P10";
|
|
1449
|
+
break;
|
|
1450
|
+
case 127:
|
|
1451
|
+
e = "I422P12";
|
|
1452
|
+
break;
|
|
1453
|
+
case 78:
|
|
1454
|
+
e = "I422A";
|
|
1455
|
+
break;
|
|
1456
|
+
case 89:
|
|
1457
|
+
e = "I422AP10";
|
|
1458
|
+
break;
|
|
1459
|
+
case 186:
|
|
1460
|
+
e = "I422AP12";
|
|
1461
|
+
break;
|
|
1462
|
+
case t.AV_PIX_FMT_YUV444P:
|
|
1463
|
+
e = "I444";
|
|
1464
|
+
break;
|
|
1465
|
+
case 68:
|
|
1466
|
+
e = "I444P10";
|
|
1467
|
+
break;
|
|
1468
|
+
case 131:
|
|
1469
|
+
e = "I444P12";
|
|
1470
|
+
break;
|
|
1471
|
+
case 79:
|
|
1472
|
+
e = "I444A";
|
|
1473
|
+
break;
|
|
1474
|
+
case 91:
|
|
1475
|
+
e = "I444AP10";
|
|
1476
|
+
break;
|
|
1477
|
+
case 188:
|
|
1478
|
+
e = "I444AP12";
|
|
1479
|
+
break;
|
|
1480
|
+
case t.AV_PIX_FMT_NV12:
|
|
1481
|
+
e = "NV12";
|
|
1482
|
+
break;
|
|
1483
|
+
case t.AV_PIX_FMT_RGBA:
|
|
1484
|
+
e = "RGBA";
|
|
1485
|
+
break;
|
|
1486
|
+
case 119:
|
|
1487
|
+
e = "RGBX";
|
|
1488
|
+
break;
|
|
1489
|
+
case t.AV_PIX_FMT_BGRA:
|
|
1490
|
+
e = "BGRA";
|
|
1491
|
+
break;
|
|
1492
|
+
case 121:
|
|
1493
|
+
e = "BGRX";
|
|
1494
|
+
break;
|
|
1495
|
+
default: throw new DOMException("Unsupported libav format!", "EncodingError");
|
|
1496
|
+
}
|
|
1497
|
+
let r = n.width, i = n.height, a;
|
|
1498
|
+
a = n.crop ? new DOMRect(n.crop.left, n.crop.top, r - n.crop.left - n.crop.right, i - n.crop.top - n.crop.bottom) : new DOMRect(0, 0, r, i);
|
|
1499
|
+
let o = r, s = i;
|
|
1500
|
+
if (n.sample_aspect_ratio && n.sample_aspect_ratio[0]) {
|
|
1501
|
+
let e = n.sample_aspect_ratio;
|
|
1502
|
+
e[0] > e[1] ? o = ~~(r * e[0] / e[1]) : s = ~~(i * e[1] / e[0]);
|
|
1503
|
+
}
|
|
1504
|
+
let c = t.i64tof64(n.pts, n.ptshi) * 1e3, l = new j(n.data, {
|
|
1505
|
+
layout: n.layout,
|
|
1506
|
+
format: e,
|
|
1507
|
+
codedWidth: r,
|
|
1508
|
+
codedHeight: i,
|
|
1509
|
+
visibleRect: a,
|
|
1510
|
+
displayWidth: o,
|
|
1511
|
+
displayHeight: s,
|
|
1512
|
+
timestamp: c
|
|
1513
|
+
});
|
|
1514
|
+
this._output(l);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
flush() {
|
|
1518
|
+
if (this.state !== "configured") throw new DOMException("Invalid state", "InvalidStateError");
|
|
1519
|
+
let e = this._p.then(() => L(this, void 0, void 0, function* () {
|
|
1520
|
+
if (!this._c) return;
|
|
1521
|
+
let e = this._libav, t = this._c, n = this._pkt, r = this._frame, i = null;
|
|
1522
|
+
try {
|
|
1523
|
+
i = yield e.ff_decode_multi(t, n, r, [], !0);
|
|
1524
|
+
} catch (e) {
|
|
1525
|
+
this._p = this._p.then(() => {
|
|
1526
|
+
this._closeVideoDecoder(e);
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
i && this._outputVideoFrames(i);
|
|
1530
|
+
}));
|
|
1531
|
+
return this._p = e, e;
|
|
1532
|
+
}
|
|
1533
|
+
reset() {
|
|
1534
|
+
this._resetVideoDecoder(new DOMException("Reset", "AbortError"));
|
|
1535
|
+
}
|
|
1536
|
+
close() {
|
|
1537
|
+
this._closeVideoDecoder(new DOMException("Close", "AbortError"));
|
|
1538
|
+
}
|
|
1539
|
+
static isConfigSupported(e) {
|
|
1540
|
+
return L(this, void 0, void 0, function* () {
|
|
1541
|
+
let t = y(e.codec, e), n = !1;
|
|
1542
|
+
if (t) {
|
|
1543
|
+
let e = yield h();
|
|
1544
|
+
try {
|
|
1545
|
+
let [, r, i, a] = yield e.ff_init_decoder(t.codec);
|
|
1546
|
+
yield e.ff_free_decoder(r, i, a), n = !0;
|
|
1547
|
+
} catch {}
|
|
1548
|
+
yield g(e);
|
|
1549
|
+
}
|
|
1550
|
+
return {
|
|
1551
|
+
supported: n,
|
|
1552
|
+
config: C(e, [
|
|
1553
|
+
"codec",
|
|
1554
|
+
"codedWidth",
|
|
1555
|
+
"codedHeight"
|
|
1556
|
+
])
|
|
1557
|
+
};
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
}, z = function(e, t, n, r) {
|
|
1561
|
+
function i(e) {
|
|
1562
|
+
return e instanceof n ? e : new n(function(t) {
|
|
1563
|
+
t(e);
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
return new (n ||= Promise)(function(n, a) {
|
|
1567
|
+
function o(e) {
|
|
1568
|
+
try {
|
|
1569
|
+
c(r.next(e));
|
|
1570
|
+
} catch (e) {
|
|
1571
|
+
a(e);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
function s(e) {
|
|
1575
|
+
try {
|
|
1576
|
+
c(r.throw(e));
|
|
1577
|
+
} catch (e) {
|
|
1578
|
+
a(e);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function c(e) {
|
|
1582
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
1583
|
+
}
|
|
1584
|
+
c((r = r.apply(e, t || [])).next());
|
|
1585
|
+
});
|
|
1586
|
+
}, B = class extends o {
|
|
1587
|
+
constructor(e) {
|
|
1588
|
+
super(), this._extradataSet = !1, this._extradata = null, this._nonSquarePixels = !1, this._sar_num = 1, this._sar_den = 1, this._p = Promise.all([]), this._libav = null, this._codec = this._c = this._frame = this._pkt = 0, this._output = e.output, this._error = e.error, this._metadata = null, this.state = "unconfigured", this.encodeQueueSize = 0;
|
|
1589
|
+
}
|
|
1590
|
+
configure(e) {
|
|
1591
|
+
if (this.state === "closed") throw new DOMException("Encoder is closed", "InvalidStateError");
|
|
1592
|
+
this._libav && (this._p = this._p.then(() => this._free())), this.state = "configured", this._p = this._p.then(() => z(this, void 0, void 0, function* () {
|
|
1593
|
+
let t = b(e.codec, e);
|
|
1594
|
+
if (!t) {
|
|
1595
|
+
this._closeVideoEncoder(new DOMException("Unsupported codec", "NotSupportedError"));
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
let n = this._libav = yield h();
|
|
1599
|
+
this._metadata = { decoderConfig: { codec: t.codec } }, [this._codec, this._c, this._frame, this._pkt] = yield n.ff_init_encoder(t.codec, t), this._extradataSet = !1, this._extradata = null, yield n.AVCodecContext_time_base_s(this._c, 1, 1e3);
|
|
1600
|
+
let r = e.width, i = e.height;
|
|
1601
|
+
this._sws = 0, this._swsFrame = 0, this._swsOut = {
|
|
1602
|
+
width: r,
|
|
1603
|
+
height: i,
|
|
1604
|
+
format: t.ctx.pix_fmt
|
|
1605
|
+
};
|
|
1606
|
+
let a = e.displayWidth || r, o = e.displayHeight || i;
|
|
1607
|
+
a !== r || o !== i ? (this._nonSquarePixels = !0, this._sar_num = a * i, this._sar_den = o * r) : this._nonSquarePixels = !1;
|
|
1608
|
+
})).catch(this._error);
|
|
1609
|
+
}
|
|
1610
|
+
_free() {
|
|
1611
|
+
return z(this, void 0, void 0, function* () {
|
|
1612
|
+
this._sws && (yield this._libav.av_frame_free_js(this._swsFrame), yield this._libav.sws_freeContext(this._sws), this._sws = this._swsFrame = 0, this._swsIn = this._swsOut = void 0), this._c && (yield this._libav.ff_free_encoder(this._c, this._frame, this._pkt), this._codec = this._c = this._frame = this._pkt = 0), this._libav &&= (g(this._libav), null);
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
_closeVideoEncoder(e) {
|
|
1616
|
+
this._resetVideoEncoder(e), this.state = "closed", this._p = this._p.then(() => this._free()), e.name !== "AbortError" && (this._p = this._p.then(() => {
|
|
1617
|
+
this._error(e);
|
|
1618
|
+
}));
|
|
1619
|
+
}
|
|
1620
|
+
_resetVideoEncoder(e) {
|
|
1621
|
+
if (this.state === "closed") throw new DOMException("Encoder closed", "InvalidStateError");
|
|
1622
|
+
this.state = "unconfigured", this._p = this._p.then(() => this._free());
|
|
1623
|
+
}
|
|
1624
|
+
encode(e, t = {}) {
|
|
1625
|
+
if (e._libavGetData() === null) throw TypeError("Detached");
|
|
1626
|
+
if (this.state !== "configured") throw new DOMException("Unconfigured", "InvalidStateError");
|
|
1627
|
+
let n = e.clone();
|
|
1628
|
+
this.encodeQueueSize++, this._p = this._p.then(() => z(this, void 0, void 0, function* () {
|
|
1629
|
+
let e = this._libav, r = this._c, i = this._pkt, a = this._frame, o = this._swsOut, s = null;
|
|
1630
|
+
this.encodeQueueSize--, this.dispatchEvent(new CustomEvent("dequeue"));
|
|
1631
|
+
try {
|
|
1632
|
+
let c = M(e, n.format), l = n._libavGetData(), u = n._libavGetLayout(), d = Math.floor(n.timestamp / 1e3), [f, p] = e.f64toi64(d), m = {
|
|
1633
|
+
data: l,
|
|
1634
|
+
layout: u,
|
|
1635
|
+
format: c,
|
|
1636
|
+
pts: f,
|
|
1637
|
+
ptshi: p,
|
|
1638
|
+
width: n.codedWidth,
|
|
1639
|
+
height: n.codedHeight,
|
|
1640
|
+
crop: {
|
|
1641
|
+
left: n.visibleRect.left,
|
|
1642
|
+
right: n.visibleRect.right,
|
|
1643
|
+
top: n.visibleRect.top,
|
|
1644
|
+
bottom: n.visibleRect.bottom
|
|
1645
|
+
},
|
|
1646
|
+
key_frame: +!!t.keyFrame,
|
|
1647
|
+
pict_type: +!!t.keyFrame
|
|
1648
|
+
};
|
|
1649
|
+
if (m.width !== o.width || m.height !== o.height || m.format !== o.format) {
|
|
1650
|
+
n._nonSquarePixels && (m.sample_aspect_ratio = [n._sar_num, n._sar_den]);
|
|
1651
|
+
let c = this._sws, l = this._swsIn, u = this._swsFrame;
|
|
1652
|
+
(!c || m.width !== l.width || m.height !== l.height || m.format !== l.format) && (c && (yield e.sws_freeContext(c)), l = {
|
|
1653
|
+
width: m.width,
|
|
1654
|
+
height: m.height,
|
|
1655
|
+
format: m.format
|
|
1656
|
+
}, c = yield e.sws_getContext(l.width, l.height, l.format, o.width, o.height, o.format, 2, 0, 0, 0), this._sws = c, this._swsIn = l, u || (this._swsFrame = u = yield e.av_frame_alloc()));
|
|
1657
|
+
let [, d, , , , , , h] = yield Promise.all([
|
|
1658
|
+
e.ff_copyin_frame(a, m),
|
|
1659
|
+
e.sws_scale_frame(c, u, a),
|
|
1660
|
+
this._nonSquarePixels ? e.AVFrame_sample_aspect_ratio_s(u, this._sar_num, this._sar_den) : null,
|
|
1661
|
+
e.AVFrame_pts_s(u, f),
|
|
1662
|
+
e.AVFrame_ptshi_s(u, p),
|
|
1663
|
+
e.AVFrame_key_frame_s(u, +!!t.keyFrame),
|
|
1664
|
+
e.AVFrame_pict_type_s(u, +!!t.keyFrame),
|
|
1665
|
+
e.avcodec_send_frame(r, u)
|
|
1666
|
+
]);
|
|
1667
|
+
if (d < 0 || h < 0) throw Error("Encoding failed!");
|
|
1668
|
+
for (s = [];;) {
|
|
1669
|
+
let t = yield e.avcodec_receive_packet(r, i);
|
|
1670
|
+
if (t === -e.EAGAIN) break;
|
|
1671
|
+
if (t < 0) throw Error("Encoding failed!");
|
|
1672
|
+
s.push(yield e.ff_copyout_packet(i));
|
|
1673
|
+
}
|
|
1674
|
+
} else this._nonSquarePixels && (m.sample_aspect_ratio = [this._sar_num, this._sar_den]), s = yield e.ff_encode_multi(r, a, i, [m]);
|
|
1675
|
+
s.length && !this._extradataSet && (yield this._getExtradata());
|
|
1676
|
+
} catch (e) {
|
|
1677
|
+
this._p = this._p.then(() => {
|
|
1678
|
+
this._closeVideoEncoder(e);
|
|
1679
|
+
});
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
s && this._outputEncodedVideoChunks(s);
|
|
1683
|
+
})).catch(this._error);
|
|
1684
|
+
}
|
|
1685
|
+
_getExtradata() {
|
|
1686
|
+
return z(this, void 0, void 0, function* () {
|
|
1687
|
+
let e = this._libav, t = this._c, n = yield e.AVCodecContext_extradata(t), r = yield e.AVCodecContext_extradata_size(t);
|
|
1688
|
+
n && r && (this._metadata.decoderConfig.description = this._extradata = yield e.copyout_u8(n, r)), this._extradataSet = !0;
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1691
|
+
_outputEncodedVideoChunks(e) {
|
|
1692
|
+
let t = this._libav;
|
|
1693
|
+
for (let n of e) {
|
|
1694
|
+
let e = new O({
|
|
1695
|
+
type: n.flags & 1 ? "key" : "delta",
|
|
1696
|
+
timestamp: t.i64tof64(n.pts, n.ptshi) * 1e3,
|
|
1697
|
+
data: n.data
|
|
1698
|
+
});
|
|
1699
|
+
this._extradataSet ? this._output(e, this._metadata || void 0) : this._output(e);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
flush() {
|
|
1703
|
+
if (this.state !== "configured") throw new DOMException("Invalid state", "InvalidStateError");
|
|
1704
|
+
let e = this._p.then(() => z(this, void 0, void 0, function* () {
|
|
1705
|
+
if (!this._c) return;
|
|
1706
|
+
let e = this._libav, t = this._c, n = this._frame, r = this._pkt, i = null;
|
|
1707
|
+
try {
|
|
1708
|
+
i = yield e.ff_encode_multi(t, n, r, [], !0), this._extradataSet || (yield this._getExtradata());
|
|
1709
|
+
} catch (e) {
|
|
1710
|
+
this._p = this._p.then(() => {
|
|
1711
|
+
this._closeVideoEncoder(e);
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
i && this._outputEncodedVideoChunks(i);
|
|
1715
|
+
}));
|
|
1716
|
+
return this._p = e, e;
|
|
1717
|
+
}
|
|
1718
|
+
reset() {
|
|
1719
|
+
this._resetVideoEncoder(new DOMException("Reset", "AbortError"));
|
|
1720
|
+
}
|
|
1721
|
+
close() {
|
|
1722
|
+
this._closeVideoEncoder(new DOMException("Close", "AbortError"));
|
|
1723
|
+
}
|
|
1724
|
+
static isConfigSupported(e) {
|
|
1725
|
+
return z(this, void 0, void 0, function* () {
|
|
1726
|
+
let t = b(e.codec, e), n = !1;
|
|
1727
|
+
if (t) {
|
|
1728
|
+
let e = yield h();
|
|
1729
|
+
try {
|
|
1730
|
+
let [, r, i, a] = yield e.ff_init_encoder(t.codec, t);
|
|
1731
|
+
yield e.ff_free_encoder(r, i, a), n = !0;
|
|
1732
|
+
} catch {}
|
|
1733
|
+
yield g(e);
|
|
1734
|
+
}
|
|
1735
|
+
return {
|
|
1736
|
+
supported: n,
|
|
1737
|
+
config: C(e, [
|
|
1738
|
+
"codec",
|
|
1739
|
+
"width",
|
|
1740
|
+
"height",
|
|
1741
|
+
"bitrate",
|
|
1742
|
+
"framerate",
|
|
1743
|
+
"latencyMode"
|
|
1744
|
+
])
|
|
1745
|
+
};
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
}, V = function(e, t, n, r) {
|
|
1749
|
+
function i(e) {
|
|
1750
|
+
return e instanceof n ? e : new n(function(t) {
|
|
1751
|
+
t(e);
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
return new (n ||= Promise)(function(n, a) {
|
|
1755
|
+
function o(e) {
|
|
1756
|
+
try {
|
|
1757
|
+
c(r.next(e));
|
|
1758
|
+
} catch (e) {
|
|
1759
|
+
a(e);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
function s(e) {
|
|
1763
|
+
try {
|
|
1764
|
+
c(r.throw(e));
|
|
1765
|
+
} catch (e) {
|
|
1766
|
+
a(e);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
function c(e) {
|
|
1770
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
1771
|
+
}
|
|
1772
|
+
c((r = r.apply(e, t || [])).next());
|
|
1773
|
+
});
|
|
1774
|
+
}, H = null, U = null, W = null, G = null, K = null;
|
|
1775
|
+
function q(e, t) {
|
|
1776
|
+
return V(this, void 0, void 0, function* () {
|
|
1777
|
+
"importScripts" in globalThis && (c.nolibavworker = !0), H = yield c.LibAV(Object.assign(Object.assign({}, e), {
|
|
1778
|
+
noworker: !0,
|
|
1779
|
+
yesthreads: !1
|
|
1780
|
+
})), U = yield c.LibAV(e), "CanvasRenderingContext2D" in globalThis && (W = CanvasRenderingContext2D.prototype.drawImage, t && (CanvasRenderingContext2D.prototype.drawImage = Y)), "OffscreenCanvasRenderingContext2D" in globalThis && (G = OffscreenCanvasRenderingContext2D.prototype.drawImage, t && (OffscreenCanvasRenderingContext2D.prototype.drawImage = X)), K = globalThis.createImageBitmap, t && (globalThis.createImageBitmap = Z);
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
function J(e, t, n, r, i, a, o, s, c, l) {
|
|
1784
|
+
if (!t._data) return W.apply(e, Array.prototype.slice.call(arguments, 1));
|
|
1785
|
+
i === void 0 ? (o = n, s = r) : o === void 0 && (o = n, s = r, c = i, l = a, i = void 0, a = void 0), c === void 0 && (c = t.displayWidth, l = t.displayHeight);
|
|
1786
|
+
let u = M(H, t.format), d = H.sws_getContext_sync(t.visibleRect.width, t.visibleRect.height, u, c, l, H.AV_PIX_FMT_RGBA, 2, 0, 0, 0), f = H.av_frame_alloc_sync(), p = H.av_frame_alloc_sync(), m, h;
|
|
1787
|
+
t._libavGetData ? (m = t._libavGetData(), h = t._libavGetLayout()) : (m = t._data, h = t._layout), H.ff_copyin_frame_sync(f, {
|
|
1788
|
+
data: m,
|
|
1789
|
+
layout: h,
|
|
1790
|
+
format: u,
|
|
1791
|
+
width: t.codedWidth,
|
|
1792
|
+
height: t.codedHeight,
|
|
1793
|
+
crop: {
|
|
1794
|
+
left: t.visibleRect.left,
|
|
1795
|
+
right: t.visibleRect.right,
|
|
1796
|
+
top: t.visibleRect.top,
|
|
1797
|
+
bottom: t.visibleRect.bottom
|
|
1798
|
+
}
|
|
1799
|
+
}), H.sws_scale_frame_sync(d, p, f);
|
|
1800
|
+
let g = H.ff_copyout_frame_video_imagedata_sync(p);
|
|
1801
|
+
e.putImageData(g, o, s), H.av_frame_free_js_sync(p), H.av_frame_free_js_sync(f), H.sws_freeContext_sync(d);
|
|
1802
|
+
}
|
|
1803
|
+
function Y(e, t, n, r, i, a, o, s, c) {
|
|
1804
|
+
return e instanceof j ? J(this, e, t, n, r, i, a, o, s, c) : W.apply(this, arguments);
|
|
1805
|
+
}
|
|
1806
|
+
function X(e, t, n, r, i, a, o, s, c) {
|
|
1807
|
+
return e instanceof j ? J(this, e, t, n, r, i, a, o, s, c) : G.apply(this, arguments);
|
|
1808
|
+
}
|
|
1809
|
+
function Z(e, t = {}) {
|
|
1810
|
+
if (!e._data) return K.apply(globalThis, arguments);
|
|
1811
|
+
let n = M(U, e.format), r = typeof t.resizeWidth == "number" ? t.resizeWidth : e.displayWidth, i = typeof t.resizeHeight == "number" ? t.resizeHeight : e.displayHeight;
|
|
1812
|
+
return V(this, void 0, void 0, function* () {
|
|
1813
|
+
let [t, a, o] = yield Promise.all([
|
|
1814
|
+
U.sws_getContext(e.visibleRect.width, e.visibleRect.height, n, r, i, U.AV_PIX_FMT_RGBA, 2, 0, 0, 0),
|
|
1815
|
+
U.av_frame_alloc(),
|
|
1816
|
+
U.av_frame_alloc()
|
|
1817
|
+
]), s, c;
|
|
1818
|
+
e._libavGetData ? (s = e._libavGetData(), c = e._libavGetLayout()) : e._data ? (s = e._data, c = e._layout) : (s = new Uint8Array(e.allocationSize()), yield e.copyTo(s)), yield U.ff_copyin_frame(a, {
|
|
1819
|
+
data: s,
|
|
1820
|
+
layout: c,
|
|
1821
|
+
format: n,
|
|
1822
|
+
width: e.codedWidth,
|
|
1823
|
+
height: e.codedHeight,
|
|
1824
|
+
crop: {
|
|
1825
|
+
left: e.visibleRect.left,
|
|
1826
|
+
right: e.visibleRect.right,
|
|
1827
|
+
top: e.visibleRect.top,
|
|
1828
|
+
bottom: e.visibleRect.bottom
|
|
1829
|
+
}
|
|
1830
|
+
}), yield U.sws_scale_frame(t, o, a);
|
|
1831
|
+
let l = yield U.ff_copyout_frame_video_imagedata(o);
|
|
1832
|
+
return yield Promise.all([
|
|
1833
|
+
U.av_frame_free_js(o),
|
|
1834
|
+
U.av_frame_free_js(a),
|
|
1835
|
+
U.sws_freeContext(t)
|
|
1836
|
+
]), yield K(l);
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
//#endregion
|
|
1840
|
+
//#region ../../node_modules/@kixelated/libavjs-webcodecs-polyfill/dist/config.js
|
|
1841
|
+
var Q = function(e, t, n, r) {
|
|
1842
|
+
function i(e) {
|
|
1843
|
+
return e instanceof n ? e : new n(function(t) {
|
|
1844
|
+
t(e);
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
return new (n ||= Promise)(function(n, a) {
|
|
1848
|
+
function o(e) {
|
|
1849
|
+
try {
|
|
1850
|
+
c(r.next(e));
|
|
1851
|
+
} catch (e) {
|
|
1852
|
+
a(e);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
function s(e) {
|
|
1856
|
+
try {
|
|
1857
|
+
c(r.throw(e));
|
|
1858
|
+
} catch (e) {
|
|
1859
|
+
a(e);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
function c(e) {
|
|
1863
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
1864
|
+
}
|
|
1865
|
+
c((r = r.apply(e, t || [])).next());
|
|
1866
|
+
});
|
|
1867
|
+
}, $ = class extends Error {
|
|
1868
|
+
constructor() {
|
|
1869
|
+
super("The requested configuration is not supported");
|
|
1870
|
+
}
|
|
1871
|
+
};
|
|
1872
|
+
function ee(n) {
|
|
1873
|
+
return Q(this, void 0, void 0, function* () {
|
|
1874
|
+
try {
|
|
1875
|
+
if (globalThis.AudioDecoder !== void 0 && (yield globalThis.AudioDecoder.isConfigSupported(n)).supported) return {
|
|
1876
|
+
AudioDecoder: globalThis.AudioDecoder,
|
|
1877
|
+
EncodedAudioChunk: globalThis.EncodedAudioChunk,
|
|
1878
|
+
AudioData: globalThis.AudioData
|
|
1879
|
+
};
|
|
1880
|
+
} catch {}
|
|
1881
|
+
if ((yield T.isConfigSupported(n)).supported) return {
|
|
1882
|
+
AudioDecoder: T,
|
|
1883
|
+
EncodedAudioChunk: e,
|
|
1884
|
+
AudioData: t
|
|
1885
|
+
};
|
|
1886
|
+
throw new $();
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1889
|
+
function te(e) {
|
|
1890
|
+
return Q(this, void 0, void 0, function* () {
|
|
1891
|
+
try {
|
|
1892
|
+
if (globalThis.VideoDecoder !== void 0 && (yield globalThis.VideoDecoder.isConfigSupported(e)).supported) return {
|
|
1893
|
+
VideoDecoder: globalThis.VideoDecoder,
|
|
1894
|
+
EncodedVideoChunk: globalThis.EncodedVideoChunk,
|
|
1895
|
+
VideoFrame: globalThis.VideoFrame
|
|
1896
|
+
};
|
|
1897
|
+
} catch {}
|
|
1898
|
+
if ((yield R.isConfigSupported(e)).supported) return {
|
|
1899
|
+
VideoDecoder: R,
|
|
1900
|
+
EncodedVideoChunk: O,
|
|
1901
|
+
VideoFrame: j
|
|
1902
|
+
};
|
|
1903
|
+
throw new $();
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
function ne(n) {
|
|
1907
|
+
return Q(this, void 0, void 0, function* () {
|
|
1908
|
+
try {
|
|
1909
|
+
if (globalThis.AudioEncoder !== void 0 && (yield globalThis.AudioEncoder.isConfigSupported(n)).supported) return {
|
|
1910
|
+
AudioEncoder: globalThis.AudioEncoder,
|
|
1911
|
+
EncodedAudioChunk: globalThis.EncodedAudioChunk,
|
|
1912
|
+
AudioData: globalThis.AudioData
|
|
1913
|
+
};
|
|
1914
|
+
} catch {}
|
|
1915
|
+
if ((yield D.isConfigSupported(n)).supported) return {
|
|
1916
|
+
AudioEncoder: D,
|
|
1917
|
+
EncodedAudioChunk: e,
|
|
1918
|
+
AudioData: t
|
|
1919
|
+
};
|
|
1920
|
+
throw new $();
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
function re(e) {
|
|
1924
|
+
return Q(this, void 0, void 0, function* () {
|
|
1925
|
+
try {
|
|
1926
|
+
if (globalThis.VideoEncoder !== void 0 && (yield globalThis.VideoEncoder.isConfigSupported(e)).supported) return {
|
|
1927
|
+
VideoEncoder: globalThis.VideoEncoder,
|
|
1928
|
+
EncodedVideoChunk: globalThis.EncodedVideoChunk,
|
|
1929
|
+
VideoFrame: globalThis.VideoFrame
|
|
1930
|
+
};
|
|
1931
|
+
} catch {}
|
|
1932
|
+
if ((yield B.isConfigSupported(e)).supported) return {
|
|
1933
|
+
VideoEncoder: B,
|
|
1934
|
+
EncodedVideoChunk: O,
|
|
1935
|
+
VideoFrame: j
|
|
1936
|
+
};
|
|
1937
|
+
throw new $();
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
//#endregion
|
|
1941
|
+
//#region ../../node_modules/@kixelated/libavjs-webcodecs-polyfill/dist/main.js
|
|
1942
|
+
var ie = function(e, t, n, r) {
|
|
1943
|
+
function i(e) {
|
|
1944
|
+
return e instanceof n ? e : new n(function(t) {
|
|
1945
|
+
t(e);
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
return new (n ||= Promise)(function(n, a) {
|
|
1949
|
+
function o(e) {
|
|
1950
|
+
try {
|
|
1951
|
+
c(r.next(e));
|
|
1952
|
+
} catch (e) {
|
|
1953
|
+
a(e);
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
function s(e) {
|
|
1957
|
+
try {
|
|
1958
|
+
c(r.throw(e));
|
|
1959
|
+
} catch (e) {
|
|
1960
|
+
a(e);
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
function c(e) {
|
|
1964
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
1965
|
+
}
|
|
1966
|
+
c((r = r.apply(e, t || [])).next());
|
|
1967
|
+
});
|
|
1968
|
+
};
|
|
1969
|
+
function ae(n = {}) {
|
|
1970
|
+
return ie(this, void 0, void 0, function* () {
|
|
1971
|
+
let r = {};
|
|
1972
|
+
if (n.libavOptions && Object.assign(r, n.libavOptions), !n.LibAV && globalThis.LibAV === void 0 && (yield new Promise((e, t) => {
|
|
1973
|
+
r.noworker = !0;
|
|
1974
|
+
let n = "https://cdn.jsdelivr.net/npm/@libav.js/variant-webm-vp9@6.7.7/dist";
|
|
1975
|
+
globalThis.LibAV = { base: n };
|
|
1976
|
+
let i = "libav-6.7.7.1.1-webm-vp9.js";
|
|
1977
|
+
if (typeof importScripts < "u") importScripts(`${n}/${i}`), e(void 0);
|
|
1978
|
+
else {
|
|
1979
|
+
let r = document.createElement("script");
|
|
1980
|
+
r.src = `${n}/${i}`, r.onload = e, r.onerror = t, document.body.appendChild(r);
|
|
1981
|
+
}
|
|
1982
|
+
})), n.LibAV && p(n.LibAV), m(r), yield v(), n.polyfill) for (let n of [
|
|
1983
|
+
["EncodedAudioChunk", e],
|
|
1984
|
+
["AudioData", t],
|
|
1985
|
+
["AudioDecoder", T],
|
|
1986
|
+
["AudioEncoder", D],
|
|
1987
|
+
["EncodedVideoChunk", O],
|
|
1988
|
+
["VideoFrame", j],
|
|
1989
|
+
["VideoDecoder", R],
|
|
1990
|
+
["VideoEncoder", B]
|
|
1991
|
+
]) globalThis[n[0]] || (globalThis[n[0]] = n[1]);
|
|
1992
|
+
yield q(r, !!n.polyfill);
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
var oe = e, se = t, ce = T, le = D, ue = O, de = j, fe = R, pe = B, me = J, he = Z, ge = $, _e = ee, ve = te, ye = ne, be = re;
|
|
1996
|
+
//#endregion
|
|
1997
|
+
export { se as AudioData, ce as AudioDecoder, le as AudioEncoder, oe as EncodedAudioChunk, ue as EncodedVideoChunk, ge as UnsupportedException, fe as VideoDecoder, pe as VideoEncoder, de as VideoFrame, me as canvasDrawImage, he as createImageBitmap, _e as getAudioDecoder, ye as getAudioEncoder, ve as getVideoDecoder, be as getVideoEncoder, ae as load };
|
|
1998
|
+
|
|
1999
|
+
//# sourceMappingURL=main-bFFHfuX4.js.map
|