alpha2 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/frame-supply.d.ts +28 -0
- package/dist/frame-supply.js +161 -23
- package/dist/hdr-frames.d.ts +16 -6
- package/dist/hdr-frames.js +47 -39
- package/dist/mediabunny.d.ts +3 -1
- package/dist/mediabunny.js +17 -1
- package/package.json +1 -1
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.js +9 -9
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- /package/wasm/snippets/{alpha2-wasm-7f557ec9a60cc69b → alpha2-wasm-c9e145ef5a7999c5}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-7f557ec9a60cc69b → alpha2-wasm-c9e145ef5a7999c5}/inline1.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-7f557ec9a60cc69b → alpha2-wasm-c9e145ef5a7999c5}/inline2.js +0 -0
package/dist/frame-supply.d.ts
CHANGED
|
@@ -105,6 +105,13 @@ export interface FrameSupplyDecodeOptions {
|
|
|
105
105
|
* own), so a host keys what it keeps per source by this, as `liveSourceIds` names sources.
|
|
106
106
|
*/
|
|
107
107
|
readonly sourceId: string;
|
|
108
|
+
/**
|
|
109
|
+
* `"software"`: decode this frame on the CPU, on a cursor of its own beside `consumerId`'s, and
|
|
110
|
+
* resolve with a `VideoFrame`. The supply asks for it when the browser could not read a
|
|
111
|
+
* hardware-decoded frame back; a host that cannot decode the source in software rejects. Absent
|
|
112
|
+
* for every other request.
|
|
113
|
+
*/
|
|
114
|
+
readonly decode?: "software";
|
|
108
115
|
}
|
|
109
116
|
/** Host callbacks and frame geometry for one `supply` call. */
|
|
110
117
|
export interface FrameSupplyOptions {
|
|
@@ -159,6 +166,25 @@ export interface FrameSupplyConfig extends FrameRetentionOptions {
|
|
|
159
166
|
* default), or the browser (`"browser"`); see {@link VideoConversion}.
|
|
160
167
|
*/
|
|
161
168
|
readonly videoConversion?: VideoConversion;
|
|
169
|
+
/**
|
|
170
|
+
* What becomes of a frame whose planes the browser cannot read back, once reading them again
|
|
171
|
+
* has failed: `"redecode"` (the default) decodes it again in software, which decodes the same
|
|
172
|
+
* picture, and fails the supply if that fails too; `"present"` gives it to the browser's
|
|
173
|
+
* conversion instead, unless the engine must convert it (HDR, or color the project declares),
|
|
174
|
+
* for a preview, where a frame shown at once matters more than the engine's conversion.
|
|
175
|
+
*/
|
|
176
|
+
readonly unreadableFrames?: "redecode" | "present";
|
|
177
|
+
}
|
|
178
|
+
/** How a {@link FrameSupply} recovered frames the browser could not read back; cumulative. */
|
|
179
|
+
export interface ReadbackRecoveryStats {
|
|
180
|
+
/** Frames whose planes the browser still could not read back after the repeated reads. */
|
|
181
|
+
readonly unreadableFrames: number;
|
|
182
|
+
/** Reads repeated on the same frame. */
|
|
183
|
+
readonly readbackRetries: number;
|
|
184
|
+
/** Frames decoded again in software and copied from that decode. */
|
|
185
|
+
readonly redecodedFrames: number;
|
|
186
|
+
/** Frames given to the browser's conversion (`unreadableFrames: "present"`). */
|
|
187
|
+
readonly presentedFrames: number;
|
|
162
188
|
}
|
|
163
189
|
/**
|
|
164
190
|
* Keeps completed source upload generations resident within a byte budget, releasing the oldest
|
|
@@ -298,6 +324,8 @@ export declare class FrameSupply {
|
|
|
298
324
|
* source-side cost, apart from any output readback.
|
|
299
325
|
*/
|
|
300
326
|
get sourceTransfer(): SourceTransferStats;
|
|
327
|
+
/** Frames the browser could not read back, and how they were recovered; cumulative. */
|
|
328
|
+
get readbackRecovery(): ReadbackRecoveryStats;
|
|
301
329
|
/**
|
|
302
330
|
* Uploads every source the engine asks for at one timestamp. Browser video stays as a
|
|
303
331
|
* `VideoFrame` until the WebGPU external-image copy consumes it.
|
package/dist/frame-supply.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The engine's immutable project snapshot is the sole authority for frame keys. The host must not
|
|
2
2
|
// derive them itself, for example by rounding (timelineSeconds - clip.start).
|
|
3
|
-
import {
|
|
3
|
+
import { isHdrVideoFrame, isPlanarVideoFrame, PlanarCopyPool, readPlanarYuvFrame, uploadPlanarYuvFrame, } from "./hdr-frames.js";
|
|
4
4
|
import { decoderConsumerId } from "./media.js";
|
|
5
5
|
import { sendsBitmaps, uploadPresentedFrame, } from "./presented-frames.js";
|
|
6
6
|
import { PhysicalFrameAliases, } from "./physical-frames.js";
|
|
@@ -91,8 +91,15 @@ export class FrameSupply {
|
|
|
91
91
|
#decodeWaiters = [];
|
|
92
92
|
#cachedImageBytes = 0;
|
|
93
93
|
#videoConversion;
|
|
94
|
+
#unreadableFrames;
|
|
94
95
|
#planarCopyFrames = 0;
|
|
95
96
|
#planarCopyBytes = 0;
|
|
97
|
+
#readback = {
|
|
98
|
+
unreadableFrames: 0,
|
|
99
|
+
readbackRetries: 0,
|
|
100
|
+
redecodedFrames: 0,
|
|
101
|
+
presentedFrames: 0,
|
|
102
|
+
};
|
|
96
103
|
/** Buffers the planar copies reuse; each is given back once its upload has taken it. */
|
|
97
104
|
#planarCopies = new PlanarCopyPool();
|
|
98
105
|
#imageUse = 0n;
|
|
@@ -123,6 +130,10 @@ export class FrameSupply {
|
|
|
123
130
|
if (videoConversion !== "engine" && videoConversion !== "browser")
|
|
124
131
|
throw new RangeError('videoConversion must be "engine" or "browser"');
|
|
125
132
|
this.#videoConversion = videoConversion;
|
|
133
|
+
const unreadableFrames = options.unreadableFrames ?? "redecode";
|
|
134
|
+
if (unreadableFrames !== "redecode" && unreadableFrames !== "present")
|
|
135
|
+
throw new RangeError('unreadableFrames must be "redecode" or "present"');
|
|
136
|
+
this.#unreadableFrames = unreadableFrames;
|
|
126
137
|
this.#retainer = new FrameGenerationRetainer((generation) => this.#engine.releaseFrameGeneration(generation), options);
|
|
127
138
|
}
|
|
128
139
|
/** Bytes of rendered source textures kept resident; see {@link FrameRetentionOptions}. */
|
|
@@ -144,6 +155,10 @@ export class FrameSupply {
|
|
|
144
155
|
planarCopyBytes: this.#planarCopyBytes,
|
|
145
156
|
};
|
|
146
157
|
}
|
|
158
|
+
/** Frames the browser could not read back, and how they were recovered; cumulative. */
|
|
159
|
+
get readbackRecovery() {
|
|
160
|
+
return { ...this.#readback };
|
|
161
|
+
}
|
|
147
162
|
#trace(sourceId, mediaTimeTicks, pixels) {
|
|
148
163
|
if (!this.onUpload)
|
|
149
164
|
return;
|
|
@@ -267,18 +282,24 @@ export class FrameSupply {
|
|
|
267
282
|
}
|
|
268
283
|
let upload;
|
|
269
284
|
if (planar !== undefined) {
|
|
270
|
-
// The copy takes the frame over and closes it,
|
|
285
|
+
// The copy takes the frame over and closes it, unless it hands it back for the
|
|
286
|
+
// browser's own upload below (`unreadableFrames: "present"`).
|
|
271
287
|
decoded[decodedIndex] = { need, layer, source: null };
|
|
272
|
-
const copied = await this.#copyPlanar(videoFrame, planar
|
|
273
|
-
|
|
274
|
-
|
|
288
|
+
const copied = await this.#copyPlanar(need, layer, videoFrame, planar, pixelsFor);
|
|
289
|
+
if (copied === undefined) {
|
|
290
|
+
decoded[decodedIndex] = { need, layer, source: videoFrame };
|
|
275
291
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
292
|
+
else {
|
|
293
|
+
try {
|
|
294
|
+
upload = uploadPlanarYuvFrame(this.#planarEngine(), need.sourceId, sourceTicks, copied, width, height);
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
// The upload copied the planes into the engine before it returned.
|
|
298
|
+
this.#planarCopies.release(copied.data);
|
|
299
|
+
}
|
|
279
300
|
}
|
|
280
301
|
}
|
|
281
|
-
|
|
302
|
+
if (upload === undefined) {
|
|
282
303
|
const engine = this.#presentedEngine();
|
|
283
304
|
const presented = [
|
|
284
305
|
need.sourceId,
|
|
@@ -414,24 +435,111 @@ export class FrameSupply {
|
|
|
414
435
|
isHdrVideoFrame(source.frame) ||
|
|
415
436
|
(this.#videoConversion === "engine" && isPlanarVideoFrame(source.frame))))
|
|
416
437
|
return { need, layer, source };
|
|
417
|
-
return {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
438
|
+
return {
|
|
439
|
+
need,
|
|
440
|
+
layer,
|
|
441
|
+
source,
|
|
442
|
+
planar: {
|
|
443
|
+
declared,
|
|
444
|
+
required: enginesColor || isHdrVideoFrame(source.frame),
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Copies a frame out planar for the engine to convert, and closes it.
|
|
450
|
+
*
|
|
451
|
+
* A frame whose planes the browser cannot read back (Chrome, now and then, for hardware-decoded
|
|
452
|
+
* frames) is read again, then decoded again in software and copied from that decode: the codecs
|
|
453
|
+
* define their decoding exactly, so the engine converts the planes it would have. With
|
|
454
|
+
* `unreadableFrames: "present"`, a frame the engine need not convert resolves `undefined`
|
|
455
|
+
* instead, left open for the browser's conversion. Rejects, the frame closed, when the copy
|
|
456
|
+
* fails otherwise or the software decode cannot serve it.
|
|
457
|
+
*/
|
|
458
|
+
async #copyPlanar(need, layer, source, planar, pixelsFor) {
|
|
459
|
+
let copied;
|
|
460
|
+
try {
|
|
461
|
+
copied = await this.#readPlanes(source, planar.declared);
|
|
462
|
+
}
|
|
463
|
+
catch (error) {
|
|
464
|
+
if (!isUnreadableFrame(error)) {
|
|
465
|
+
source.frame.close();
|
|
466
|
+
throw error;
|
|
467
|
+
}
|
|
468
|
+
this.#readback.unreadableFrames += 1;
|
|
469
|
+
if (this.#unreadableFrames === "present" &&
|
|
470
|
+
!planar.required &&
|
|
471
|
+
takesPresentedFrames(this.#engine)) {
|
|
472
|
+
this.#readback.presentedFrames += 1;
|
|
473
|
+
return undefined;
|
|
474
|
+
}
|
|
475
|
+
const timestamp = source.physicalTimeMicroseconds ?? source.frame.timestamp;
|
|
476
|
+
source.frame.close();
|
|
477
|
+
copied = await this.#redecodePlanar(need, layer, planar, timestamp, pixelsFor, error);
|
|
478
|
+
}
|
|
479
|
+
source.frame.close();
|
|
431
480
|
this.#planarCopyFrames += 1;
|
|
432
481
|
this.#planarCopyBytes += copied.data.byteLength;
|
|
433
482
|
return copied;
|
|
434
483
|
}
|
|
484
|
+
/**
|
|
485
|
+
* The frame's planes, read again up to {@link READBACK_RETRIES} times, a task apart, while the
|
|
486
|
+
* browser fails to read them back. Leaves the frame open.
|
|
487
|
+
*/
|
|
488
|
+
async #readPlanes(source, declared) {
|
|
489
|
+
const color = declared === undefined ? null : JSON.parse(declared);
|
|
490
|
+
for (let retry = 0;; retry += 1) {
|
|
491
|
+
try {
|
|
492
|
+
return await readPlanarYuvFrame(source.frame, color, planarIdentity(source), this.#planarCopies);
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
if (retry >= READBACK_RETRIES || !isUnreadableFrame(error))
|
|
496
|
+
throw error;
|
|
497
|
+
this.#readback.readbackRetries += 1;
|
|
498
|
+
await nextTask();
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Decodes `need` again in software and copies that frame out planar. Rejects with `cause` when
|
|
504
|
+
* the host cannot decode it in software, decodes another picture (another timestamp), or that
|
|
505
|
+
* copy fails too.
|
|
506
|
+
*/
|
|
507
|
+
async #redecodePlanar(need, layer, planar, timestamp, pixelsFor, cause) {
|
|
508
|
+
const unrecovered = (reason, error = cause) => new Error(`the browser could not read back the frame of ${need.sourceId} at ${need.mediaTimeTicks}, and ${reason}`, { cause: error });
|
|
509
|
+
let decoded;
|
|
510
|
+
try {
|
|
511
|
+
decoded = await this.#decodeCursor(`${keyForNeed(need, layer)}\u0000software`, () => pixelsFor(layer, Number(BigInt(need.mediaTimeTicks)) / TICKS_PER_SECOND, {
|
|
512
|
+
preferVideoFrame: true,
|
|
513
|
+
consumerId: consumerOf(need),
|
|
514
|
+
sourceId: need.sourceId,
|
|
515
|
+
decode: "software",
|
|
516
|
+
}));
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
throw unrecovered("decoding it again in software failed", error);
|
|
520
|
+
}
|
|
521
|
+
if (decoded === null ||
|
|
522
|
+
!("kind" in decoded) ||
|
|
523
|
+
decoded.kind !== "video-frame")
|
|
524
|
+
throw unrecovered("decoding it again in software gave no VideoFrame");
|
|
525
|
+
const again = decoded;
|
|
526
|
+
try {
|
|
527
|
+
const at = again.physicalTimeMicroseconds ?? again.frame.timestamp;
|
|
528
|
+
if (at !== timestamp)
|
|
529
|
+
throw unrecovered(`decoding it again in software gave the frame at ${at} us`);
|
|
530
|
+
const copied = await this.#readPlanes(again, planar.declared);
|
|
531
|
+
this.#readback.redecodedFrames += 1;
|
|
532
|
+
return copied;
|
|
533
|
+
}
|
|
534
|
+
catch (error) {
|
|
535
|
+
throw error instanceof Error && error.cause === cause
|
|
536
|
+
? error
|
|
537
|
+
: unrecovered("the software decode's frame could not be copied either", error);
|
|
538
|
+
}
|
|
539
|
+
finally {
|
|
540
|
+
again.frame.close();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
435
543
|
/** The engine's presented RGBA uploads, called on the engine. */
|
|
436
544
|
#presenter() {
|
|
437
545
|
const engine = this.#engine;
|
|
@@ -726,6 +834,36 @@ function validatePositiveInteger(value, name) {
|
|
|
726
834
|
throw new RangeError(`${name} must be a positive safe integer`);
|
|
727
835
|
}
|
|
728
836
|
}
|
|
837
|
+
/** Reads repeated on a frame whose planes the browser could not read back, before decoding again. */
|
|
838
|
+
const READBACK_RETRIES = 2;
|
|
839
|
+
/**
|
|
840
|
+
* Whether a planar copy failed because the browser could not read a GPU-backed frame back: Chrome
|
|
841
|
+
* rejects `copyTo` with `InvalidStateError` ("Failed to read VideoFrame data."), now and then, for
|
|
842
|
+
* hardware-decoded frames. A closed frame rejects with the same name, but the supply owns the
|
|
843
|
+
* frames it copies and has not closed them.
|
|
844
|
+
*/
|
|
845
|
+
function isUnreadableFrame(error) {
|
|
846
|
+
return (typeof DOMException !== "undefined" &&
|
|
847
|
+
error instanceof DOMException &&
|
|
848
|
+
error.name === "InvalidStateError");
|
|
849
|
+
}
|
|
850
|
+
/** What a planar copy of `source` carries beyond the frame (see `PlanarFrameIdentity`). */
|
|
851
|
+
function planarIdentity(source) {
|
|
852
|
+
return {
|
|
853
|
+
...(source.physicalTimeMicroseconds === undefined
|
|
854
|
+
? {}
|
|
855
|
+
: { physicalTimeMicroseconds: source.physicalTimeMicroseconds }),
|
|
856
|
+
...(source.rotation === undefined ? {} : { rotation: source.rotation }),
|
|
857
|
+
...(source.mirror === undefined ? {} : { mirror: source.mirror }),
|
|
858
|
+
...(source.chromaSiting === undefined
|
|
859
|
+
? {}
|
|
860
|
+
: { chromaSiting: source.chromaSiting }),
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
/** Resolves once the browser has run other tasks, such as the GPU process's replies. */
|
|
864
|
+
function nextTask() {
|
|
865
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
866
|
+
}
|
|
729
867
|
/** Whether `engine` takes presented `VideoFrame` uploads (`uploadPresentedVideoFrame`). */
|
|
730
868
|
function takesPresentedFrames(engine) {
|
|
731
869
|
return typeof engine.uploadPresentedVideoFrame === "function";
|
package/dist/hdr-frames.d.ts
CHANGED
|
@@ -2,6 +2,13 @@ import type { ChromaSiting } from "./chroma-siting.js";
|
|
|
2
2
|
import type { FrameUploadReceipt } from "./effects.js";
|
|
3
3
|
import type { ColorMetadata } from "./generated/project-schema.js";
|
|
4
4
|
export { type ChromaSiting, chromaSitingForCodec, chromaSitingForStream, type SampleAspect, sampleAspectForStream, } from "./chroma-siting.js";
|
|
5
|
+
/** What a planar copy carries of its frame's identity beyond the frame itself. */
|
|
6
|
+
export interface PlanarFrameIdentity {
|
|
7
|
+
readonly physicalTimeMicroseconds?: number;
|
|
8
|
+
readonly rotation?: 0 | 90 | 180 | 270;
|
|
9
|
+
readonly mirror?: boolean;
|
|
10
|
+
readonly chromaSiting?: ChromaSiting;
|
|
11
|
+
}
|
|
5
12
|
/** A decoded frame copied out as planar YUV, with the color it carries. */
|
|
6
13
|
export interface PlanarYuvFrame {
|
|
7
14
|
readonly kind: "yuv-frame";
|
|
@@ -103,12 +110,15 @@ export declare class PlanarCopyPool {
|
|
|
103
110
|
* With `pool`, the copy's `data` is a buffer from it, which the caller gives back with
|
|
104
111
|
* {@link PlanarCopyPool.release} after uploading; a failed copy gives it back itself.
|
|
105
112
|
*/
|
|
106
|
-
export declare function copyPlanarYuvFrame(frame: VideoFrame, declared: ColorMetadata | null, identity?:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
export declare function copyPlanarYuvFrame(frame: VideoFrame, declared: ColorMetadata | null, identity?: PlanarFrameIdentity, pool?: PlanarCopyPool): Promise<PlanarYuvFrame>;
|
|
114
|
+
/**
|
|
115
|
+
* {@link copyPlanarYuvFrame} without closing `frame`: the caller owns it whether the copy succeeds
|
|
116
|
+
* or not, so a frame whose planes the browser could not read back can be read again. Rejects as
|
|
117
|
+
* {@link copyPlanarYuvFrame} does; with `pool`, a failed copy gives its buffer back.
|
|
118
|
+
*
|
|
119
|
+
* @internal For `FrameSupply`.
|
|
120
|
+
*/
|
|
121
|
+
export declare function readPlanarYuvFrame(frame: VideoFrame, declared: ColorMetadata | null, identity?: PlanarFrameIdentity, pool?: PlanarCopyPool): Promise<PlanarYuvFrame>;
|
|
112
122
|
/**
|
|
113
123
|
* Uploads a planar frame for the engine to convert and present at
|
|
114
124
|
* `outputWidth` x `outputHeight`, the size it is shown upright at. Throws what
|
package/dist/hdr-frames.js
CHANGED
|
@@ -146,50 +146,58 @@ export class PlanarCopyPool {
|
|
|
146
146
|
*/
|
|
147
147
|
export async function copyPlanarYuvFrame(frame, declared, identity = {}, pool) {
|
|
148
148
|
try {
|
|
149
|
-
|
|
150
|
-
if (format === null || !isPlanarVideoFrame(frame)) {
|
|
151
|
-
throw new Error(`frame has no planar YUV format the engine reads (${format ?? "opaque"}); decode HDR sources, and sources whose color the project declares, in software`);
|
|
152
|
-
}
|
|
153
|
-
const visible = frame.visibleRect;
|
|
154
|
-
if (!visible)
|
|
155
|
-
throw new Error("frame has no visible rectangle");
|
|
156
|
-
// copyTo copies the visible rectangle by default, so the copy is exactly the picture.
|
|
157
|
-
const size = frame.allocationSize();
|
|
158
|
-
const data = pool?.acquire(size) ?? new Uint8Array(size);
|
|
159
|
-
let planes;
|
|
160
|
-
try {
|
|
161
|
-
planes = await frame.copyTo(data);
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
pool?.release(data);
|
|
165
|
-
throw error;
|
|
166
|
-
}
|
|
167
|
-
return {
|
|
168
|
-
kind: "yuv-frame",
|
|
169
|
-
format,
|
|
170
|
-
codedWidth: visible.width,
|
|
171
|
-
codedHeight: visible.height,
|
|
172
|
-
data,
|
|
173
|
-
layout: planes.flatMap((plane) => [plane.offset, plane.stride]),
|
|
174
|
-
visibleRect: [0, 0, visible.width, visible.height],
|
|
175
|
-
color: declared ?? colorMetadataFromVideoColorSpace(frame.colorSpace),
|
|
176
|
-
chromaSiting: identity.chromaSiting ?? "unspecified",
|
|
177
|
-
displayWidth: frame.displayWidth,
|
|
178
|
-
displayHeight: frame.displayHeight,
|
|
179
|
-
physicalTimeMicroseconds: identity.physicalTimeMicroseconds ?? frame.timestamp,
|
|
180
|
-
...(frame.duration === null
|
|
181
|
-
? {}
|
|
182
|
-
: { durationMicroseconds: frame.duration }),
|
|
183
|
-
...(identity.rotation === undefined
|
|
184
|
-
? {}
|
|
185
|
-
: { rotation: identity.rotation }),
|
|
186
|
-
...(identity.mirror === undefined ? {} : { mirror: identity.mirror }),
|
|
187
|
-
};
|
|
149
|
+
return await readPlanarYuvFrame(frame, declared, identity, pool);
|
|
188
150
|
}
|
|
189
151
|
finally {
|
|
190
152
|
frame.close();
|
|
191
153
|
}
|
|
192
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* {@link copyPlanarYuvFrame} without closing `frame`: the caller owns it whether the copy succeeds
|
|
157
|
+
* or not, so a frame whose planes the browser could not read back can be read again. Rejects as
|
|
158
|
+
* {@link copyPlanarYuvFrame} does; with `pool`, a failed copy gives its buffer back.
|
|
159
|
+
*
|
|
160
|
+
* @internal For `FrameSupply`.
|
|
161
|
+
*/
|
|
162
|
+
export async function readPlanarYuvFrame(frame, declared, identity = {}, pool) {
|
|
163
|
+
const format = frame.format;
|
|
164
|
+
if (format === null || !isPlanarVideoFrame(frame)) {
|
|
165
|
+
throw new Error(`frame has no planar YUV format the engine reads (${format ?? "opaque"}); decode HDR sources, and sources whose color the project declares, in software`);
|
|
166
|
+
}
|
|
167
|
+
const visible = frame.visibleRect;
|
|
168
|
+
if (!visible)
|
|
169
|
+
throw new Error("frame has no visible rectangle");
|
|
170
|
+
// copyTo copies the visible rectangle by default, so the copy is exactly the picture.
|
|
171
|
+
const size = frame.allocationSize();
|
|
172
|
+
const data = pool?.acquire(size) ?? new Uint8Array(size);
|
|
173
|
+
let planes;
|
|
174
|
+
try {
|
|
175
|
+
planes = await frame.copyTo(data);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
pool?.release(data);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
kind: "yuv-frame",
|
|
183
|
+
format,
|
|
184
|
+
codedWidth: visible.width,
|
|
185
|
+
codedHeight: visible.height,
|
|
186
|
+
data,
|
|
187
|
+
layout: planes.flatMap((plane) => [plane.offset, plane.stride]),
|
|
188
|
+
visibleRect: [0, 0, visible.width, visible.height],
|
|
189
|
+
color: declared ?? colorMetadataFromVideoColorSpace(frame.colorSpace),
|
|
190
|
+
chromaSiting: identity.chromaSiting ?? "unspecified",
|
|
191
|
+
displayWidth: frame.displayWidth,
|
|
192
|
+
displayHeight: frame.displayHeight,
|
|
193
|
+
physicalTimeMicroseconds: identity.physicalTimeMicroseconds ?? frame.timestamp,
|
|
194
|
+
...(frame.duration === null
|
|
195
|
+
? {}
|
|
196
|
+
: { durationMicroseconds: frame.duration }),
|
|
197
|
+
...(identity.rotation === undefined ? {} : { rotation: identity.rotation }),
|
|
198
|
+
...(identity.mirror === undefined ? {} : { mirror: identity.mirror }),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
193
201
|
/**
|
|
194
202
|
* Uploads a planar frame for the engine to convert and present at
|
|
195
203
|
* `outputWidth` x `outputHeight`, the size it is shown upright at. Throws what
|
package/dist/mediabunny.d.ts
CHANGED
|
@@ -40,7 +40,9 @@ export declare class MediabunnyVideoDecoder implements BrowserVideoDecoder {
|
|
|
40
40
|
private constructor();
|
|
41
41
|
/**
|
|
42
42
|
* Opens `resource`'s primary video track. Rejects when it has none, or when this browser cannot
|
|
43
|
-
* decode it, so a host can fall back before the first request.
|
|
43
|
+
* decode it, so a host can fall back before the first request. With `hardwareAcceleration:
|
|
44
|
+
* "prefer-software"`, a track the browser has no software decoder for rejects with `code:
|
|
45
|
+
* "software_decode_unavailable"`.
|
|
44
46
|
*/
|
|
45
47
|
static open(sourceId: string, resource: MediabunnyInput, options?: MediabunnyVideoDecoderOptions): Promise<MediabunnyVideoDecoder>;
|
|
46
48
|
/** Bytes both windows hold: decoder frames and reverse copies. */
|
package/dist/mediabunny.js
CHANGED
|
@@ -113,7 +113,9 @@ export class MediabunnyVideoDecoder {
|
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* Opens `resource`'s primary video track. Rejects when it has none, or when this browser cannot
|
|
116
|
-
* decode it, so a host can fall back before the first request.
|
|
116
|
+
* decode it, so a host can fall back before the first request. With `hardwareAcceleration:
|
|
117
|
+
* "prefer-software"`, a track the browser has no software decoder for rejects with `code:
|
|
118
|
+
* "software_decode_unavailable"`.
|
|
117
119
|
*/
|
|
118
120
|
static async open(sourceId, resource, options = {}) {
|
|
119
121
|
const limits = {
|
|
@@ -139,6 +141,20 @@ export class MediabunnyVideoDecoder {
|
|
|
139
141
|
throw new Error("mediabunny input has no video track");
|
|
140
142
|
if (!(await track.canDecode()))
|
|
141
143
|
throw new Error("this browser cannot decode the video track");
|
|
144
|
+
// `canDecode` does not ask for a software decoder: a codec only hardware decodes would open
|
|
145
|
+
// and fail on its first read. Without WebCodecs only mediabunny's own decoders decode.
|
|
146
|
+
if (options.hardwareAcceleration === "prefer-software" &&
|
|
147
|
+
typeof VideoDecoder !== "undefined") {
|
|
148
|
+
const config = await track.getDecoderConfig();
|
|
149
|
+
const support = config === null
|
|
150
|
+
? { supported: false }
|
|
151
|
+
: await VideoDecoder.isConfigSupported({
|
|
152
|
+
...config,
|
|
153
|
+
hardwareAcceleration: "prefer-software",
|
|
154
|
+
});
|
|
155
|
+
if (support.supported !== true)
|
|
156
|
+
throw Object.assign(new Error(`this browser has no software decoder for ${config?.codec ?? track.codec ?? "the video track"}`), { code: "software_decode_unavailable" });
|
|
157
|
+
}
|
|
142
158
|
// mediabunny reports a turn but not a mirror, and reads a mirroring matrix's angle otherwise
|
|
143
159
|
// than native decoding does.
|
|
144
160
|
const orientation = (await readVideoOrientation(resource, track.id)) ?? {
|
package/package.json
CHANGED
|
Binary file
|
package/wasm/alpha2_wasm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* @ts-self-types="./alpha2_wasm.d.ts" */
|
|
2
|
-
import { alpha2BitmapUploadsPremultiplied, alpha2FrameBitmap } from './snippets/alpha2-wasm-
|
|
3
|
-
import { alpha2CopyExternalImage } from './snippets/alpha2-wasm-
|
|
4
|
-
import * as import1 from "./snippets/alpha2-wasm-
|
|
5
|
-
import * as import2 from "./snippets/alpha2-wasm-
|
|
2
|
+
import { alpha2BitmapUploadsPremultiplied, alpha2FrameBitmap } from './snippets/alpha2-wasm-c9e145ef5a7999c5/inline1.js';
|
|
3
|
+
import { alpha2CopyExternalImage } from './snippets/alpha2-wasm-c9e145ef5a7999c5/inline2.js';
|
|
4
|
+
import * as import1 from "./snippets/alpha2-wasm-c9e145ef5a7999c5/inline0.js"
|
|
5
|
+
import * as import2 from "./snippets/alpha2-wasm-c9e145ef5a7999c5/inline0.js"
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -2876,14 +2876,14 @@ function __wbg_get_imports() {
|
|
|
2876
2876
|
__wbg_addEventListener_9534e2dc12044ee4: function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
2877
2877
|
arg0.addEventListener(getStringFromWasm0(arg1, arg2), arg3);
|
|
2878
2878
|
}, arguments); },
|
|
2879
|
-
|
|
2879
|
+
__wbg_alpha2BitmapUploadsPremultiplied_78b4ac5141445048: function() { return handleError(function () {
|
|
2880
2880
|
const ret = alpha2BitmapUploadsPremultiplied();
|
|
2881
2881
|
return ret;
|
|
2882
2882
|
}, arguments); },
|
|
2883
|
-
|
|
2883
|
+
__wbg_alpha2CopyExternalImage_987d554cbab531aa: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
|
|
2884
2884
|
alpha2CopyExternalImage(arg0, arg1, arg2, arg3 >>> 0, arg4 >>> 0);
|
|
2885
2885
|
}, arguments); },
|
|
2886
|
-
|
|
2886
|
+
__wbg_alpha2FrameBitmap_3a79d75f6a0c8918: function() { return handleError(function (arg0, arg1, arg2) {
|
|
2887
2887
|
const ret = alpha2FrameBitmap(arg0, arg1 >>> 0, arg2 >>> 0);
|
|
2888
2888
|
return ret;
|
|
2889
2889
|
}, arguments); },
|
|
@@ -5180,8 +5180,8 @@ function __wbg_get_imports() {
|
|
|
5180
5180
|
return {
|
|
5181
5181
|
__proto__: null,
|
|
5182
5182
|
"./alpha2_wasm_bg.js": import0,
|
|
5183
|
-
"./snippets/alpha2-wasm-
|
|
5184
|
-
"./snippets/alpha2-wasm-
|
|
5183
|
+
"./snippets/alpha2-wasm-c9e145ef5a7999c5/inline0.js": import1,
|
|
5184
|
+
"./snippets/alpha2-wasm-c9e145ef5a7999c5/inline0.js": import2,
|
|
5185
5185
|
};
|
|
5186
5186
|
}
|
|
5187
5187
|
|
package/wasm/alpha2_wasm_bg.wasm
CHANGED
|
Binary file
|
/package/wasm/snippets/{alpha2-wasm-7f557ec9a60cc69b → alpha2-wasm-c9e145ef5a7999c5}/inline0.js
RENAMED
|
File without changes
|
/package/wasm/snippets/{alpha2-wasm-7f557ec9a60cc69b → alpha2-wasm-c9e145ef5a7999c5}/inline1.js
RENAMED
|
File without changes
|
/package/wasm/snippets/{alpha2-wasm-7f557ec9a60cc69b → alpha2-wasm-c9e145ef5a7999c5}/inline2.js
RENAMED
|
File without changes
|