webcodecs-node 0.5.1 → 0.7.0
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 +328 -169
- package/dist/backends/types.d.ts +2 -0
- package/dist/backends/types.d.ts.map +1 -1
- package/dist/backends/types.js.map +1 -1
- package/dist/canvas/canvas-utils.d.ts +115 -0
- package/dist/canvas/canvas-utils.d.ts.map +1 -0
- package/dist/canvas/canvas-utils.js +169 -0
- package/dist/canvas/canvas-utils.js.map +1 -0
- package/dist/canvas/frame-loop.d.ts +113 -0
- package/dist/canvas/frame-loop.d.ts.map +1 -0
- package/dist/canvas/frame-loop.js +291 -0
- package/dist/canvas/frame-loop.js.map +1 -0
- package/dist/canvas/gpu-context.d.ts +61 -0
- package/dist/canvas/gpu-context.d.ts.map +1 -0
- package/dist/canvas/gpu-context.js +134 -0
- package/dist/canvas/gpu-context.js.map +1 -0
- package/dist/canvas/index.d.ts +22 -0
- package/dist/canvas/index.d.ts.map +1 -0
- package/dist/canvas/index.js +25 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/canvas/types.d.ts +101 -0
- package/dist/canvas/types.d.ts.map +1 -0
- package/dist/canvas/types.js +7 -0
- package/dist/canvas/types.js.map +1 -0
- package/dist/codec-utils/formats.d.ts.map +1 -1
- package/dist/codec-utils/formats.js +31 -0
- package/dist/codec-utils/formats.js.map +1 -1
- package/dist/config/ffmpeg-quality.d.ts +14 -0
- package/dist/config/ffmpeg-quality.d.ts.map +1 -0
- package/dist/config/ffmpeg-quality.js +41 -0
- package/dist/config/ffmpeg-quality.js.map +1 -0
- package/dist/containers/Muxer.d.ts.map +1 -1
- package/dist/containers/Muxer.js +4 -1
- package/dist/containers/Muxer.js.map +1 -1
- package/dist/core/AudioData.d.ts +2 -1
- package/dist/core/AudioData.d.ts.map +1 -1
- package/dist/core/AudioData.js.map +1 -1
- package/dist/core/VideoFrame.d.ts +2 -2
- package/dist/core/VideoFrame.d.ts.map +1 -1
- package/dist/core/VideoFrame.js +49 -47
- package/dist/core/VideoFrame.js.map +1 -1
- package/dist/decoders/AudioDecoder.d.ts +1 -0
- package/dist/decoders/AudioDecoder.d.ts.map +1 -1
- package/dist/decoders/AudioDecoder.js +39 -17
- package/dist/decoders/AudioDecoder.js.map +1 -1
- package/dist/decoders/ImageDecoder.d.ts +1 -0
- package/dist/decoders/ImageDecoder.d.ts.map +1 -1
- package/dist/decoders/ImageDecoder.js +40 -3
- package/dist/decoders/ImageDecoder.js.map +1 -1
- package/dist/decoders/VideoDecoder.d.ts +12 -0
- package/dist/decoders/VideoDecoder.d.ts.map +1 -1
- package/dist/decoders/VideoDecoder.js +50 -8
- package/dist/decoders/VideoDecoder.js.map +1 -1
- package/dist/demos/demo-1080p-transcode.js +8 -2
- package/dist/demos/demo-1080p-transcode.js.map +1 -1
- package/dist/demos/demo-audio-visualizer.d.ts +11 -0
- package/dist/demos/demo-audio-visualizer.d.ts.map +1 -0
- package/dist/demos/demo-audio-visualizer.js +281 -0
- package/dist/demos/demo-audio-visualizer.js.map +1 -0
- package/dist/demos/demo-dvd-logo.d.ts +8 -0
- package/dist/demos/demo-dvd-logo.d.ts.map +1 -0
- package/dist/demos/demo-dvd-logo.js +196 -0
- package/dist/demos/demo-dvd-logo.js.map +1 -0
- package/dist/demos/demo-four-corners.js +9 -0
- package/dist/demos/demo-four-corners.js.map +1 -1
- package/dist/demos/demo-streaming.js +6 -0
- package/dist/demos/demo-streaming.js.map +1 -1
- package/dist/demos/demo-webcodecs.js +1 -0
- package/dist/demos/demo-webcodecs.js.map +1 -1
- package/dist/encoders/AudioEncoder.d.ts +3 -0
- package/dist/encoders/AudioEncoder.d.ts.map +1 -1
- package/dist/encoders/AudioEncoder.js +70 -28
- package/dist/encoders/AudioEncoder.js.map +1 -1
- package/dist/encoders/ImageEncoder.d.ts +80 -0
- package/dist/encoders/ImageEncoder.d.ts.map +1 -0
- package/dist/encoders/ImageEncoder.js +156 -0
- package/dist/encoders/ImageEncoder.js.map +1 -0
- package/dist/encoders/VideoEncoder.d.ts +11 -0
- package/dist/encoders/VideoEncoder.d.ts.map +1 -1
- package/dist/encoders/VideoEncoder.js +46 -4
- package/dist/encoders/VideoEncoder.js.map +1 -1
- package/dist/encoders/index.d.ts +1 -0
- package/dist/encoders/index.d.ts.map +1 -1
- package/dist/encoders/index.js +1 -0
- package/dist/encoders/index.js.map +1 -1
- package/dist/formats/color-space.d.ts +88 -0
- package/dist/formats/color-space.d.ts.map +1 -1
- package/dist/formats/color-space.js +55 -1
- package/dist/formats/color-space.js.map +1 -1
- package/dist/formats/pixel-formats.d.ts +17 -1
- package/dist/formats/pixel-formats.d.ts.map +1 -1
- package/dist/formats/pixel-formats.js +74 -4
- package/dist/formats/pixel-formats.js.map +1 -1
- package/dist/hardware/detection.d.ts.map +1 -1
- package/dist/hardware/detection.js +5 -2
- package/dist/hardware/detection.js.map +1 -1
- package/dist/hardware/encoder-args.d.ts.map +1 -1
- package/dist/hardware/encoder-args.js +6 -6
- package/dist/hardware/encoder-args.js.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/node-av/NodeAvAudioDecoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvAudioDecoder.js +3 -0
- package/dist/node-av/NodeAvAudioDecoder.js.map +1 -1
- package/dist/node-av/NodeAvAudioEncoder.d.ts +5 -0
- package/dist/node-av/NodeAvAudioEncoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvAudioEncoder.js +102 -9
- package/dist/node-av/NodeAvAudioEncoder.js.map +1 -1
- package/dist/node-av/NodeAvVideoEncoder.d.ts +2 -0
- package/dist/node-av/NodeAvVideoEncoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvVideoEncoder.js +44 -6
- package/dist/node-av/NodeAvVideoEncoder.js.map +1 -1
- package/dist/node-av/WebPImageDecoder.d.ts +54 -0
- package/dist/node-av/WebPImageDecoder.d.ts.map +1 -0
- package/dist/node-av/WebPImageDecoder.js +176 -0
- package/dist/node-av/WebPImageDecoder.js.map +1 -0
- package/dist/polyfills/OffscreenCanvas.d.ts +141 -7
- package/dist/polyfills/OffscreenCanvas.d.ts.map +1 -1
- package/dist/polyfills/OffscreenCanvas.js +217 -17
- package/dist/polyfills/OffscreenCanvas.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/native-frame.d.ts +74 -0
- package/dist/types/native-frame.d.ts.map +1 -0
- package/dist/types/native-frame.js +32 -0
- package/dist/types/native-frame.js.map +1 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/type-guards.d.ts +29 -1
- package/dist/utils/type-guards.d.ts.map +1 -1
- package/dist/utils/type-guards.js +47 -2
- package/dist/utils/type-guards.js.map +1 -1
- package/docs/api.md +156 -1
- package/docs/configuration.md +30 -14
- package/examples/README.md +28 -1
- package/examples/canvas-encoding.ts +222 -0
- package/examples/offscreen-canvas.ts +230 -0
- package/package.json +10 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/backends/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC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DAAwD;AACxD,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAE7C,2CAA2C;AAC3C,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,2DAA2D;AAC3D,eAAO,MAAM,kBAAkB,SAAU,CAAC;AAE1C,4CAA4C;AAC5C,eAAO,MAAM,YAAY;;;;;;CAMf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/backends/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/backends/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkLH,iDAAiD;AACjD,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAE7C,gDAAgD;AAChD,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAE3C,wDAAwD;AACxD,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAE7C,2CAA2C;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAE1C,4CAA4C;AAC5C,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,EAAE;CACC,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canvas Utilities for skia-canvas
|
|
3
|
+
*
|
|
4
|
+
* Raw buffer utilities for efficient pixel data handling.
|
|
5
|
+
* Always uses toBuffer('raw') - never PNG or other encoded formats.
|
|
6
|
+
*/
|
|
7
|
+
import { Canvas } from 'skia-canvas';
|
|
8
|
+
import type { RawBufferOptions } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Create a pixel buffer for image manipulation
|
|
11
|
+
*
|
|
12
|
+
* Uses Uint8ClampedArray which automatically clamps values to 0-255,
|
|
13
|
+
* preventing overflow bugs in filters and pixel manipulation code.
|
|
14
|
+
*
|
|
15
|
+
* @param width - Image width in pixels
|
|
16
|
+
* @param height - Image height in pixels
|
|
17
|
+
* @returns Uint8ClampedArray of size width * height * 4 (RGBA)
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const pixels = createPixelBuffer(1920, 1080);
|
|
22
|
+
* // Safe manipulation - values auto-clamped to 0-255
|
|
23
|
+
* pixels[0] = 300; // Becomes 255
|
|
24
|
+
* pixels[1] = -50; // Becomes 0
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function createPixelBuffer(width: number, height: number): Uint8ClampedArray;
|
|
28
|
+
/**
|
|
29
|
+
* Create a pixel buffer initialized with a solid color
|
|
30
|
+
*
|
|
31
|
+
* @param width - Image width in pixels
|
|
32
|
+
* @param height - Image height in pixels
|
|
33
|
+
* @param r - Red component (0-255)
|
|
34
|
+
* @param g - Green component (0-255)
|
|
35
|
+
* @param b - Blue component (0-255)
|
|
36
|
+
* @param a - Alpha component (0-255, default 255)
|
|
37
|
+
* @returns Uint8ClampedArray filled with the specified color
|
|
38
|
+
*/
|
|
39
|
+
export declare function createPixelBufferWithColor(width: number, height: number, r: number, g: number, b: number, a?: number): Uint8ClampedArray;
|
|
40
|
+
/**
|
|
41
|
+
* Get raw RGBA pixel data from canvas (synchronous)
|
|
42
|
+
* ALWAYS uses toBufferSync('raw') - never PNG or other encoded formats.
|
|
43
|
+
*
|
|
44
|
+
* @param canvas - The skia-canvas Canvas instance
|
|
45
|
+
* @param options - Optional buffer format options
|
|
46
|
+
* @returns Buffer containing raw RGBA pixel data
|
|
47
|
+
*/
|
|
48
|
+
export declare function getRawPixels(canvas: Canvas, options?: RawBufferOptions): Buffer;
|
|
49
|
+
/**
|
|
50
|
+
* Get raw RGBA pixel data from canvas (asynchronous)
|
|
51
|
+
* ALWAYS uses toBuffer('raw') - never PNG or other encoded formats.
|
|
52
|
+
*
|
|
53
|
+
* @param canvas - The skia-canvas Canvas instance
|
|
54
|
+
* @param options - Optional buffer format options
|
|
55
|
+
* @returns Promise resolving to Buffer containing raw RGBA pixel data
|
|
56
|
+
*/
|
|
57
|
+
export declare function getRawPixelsAsync(canvas: Canvas, options?: RawBufferOptions): Promise<Buffer>;
|
|
58
|
+
/**
|
|
59
|
+
* Reset canvas state for new frame
|
|
60
|
+
*
|
|
61
|
+
* Prevents Skia command history buildup which can cause memory
|
|
62
|
+
* growth and performance degradation over time.
|
|
63
|
+
*
|
|
64
|
+
* @param ctx - The 2D rendering context
|
|
65
|
+
*/
|
|
66
|
+
export declare function resetCanvas(ctx: CanvasRenderingContext2D): void;
|
|
67
|
+
/**
|
|
68
|
+
* Simple ImageData-like object for internal use
|
|
69
|
+
*/
|
|
70
|
+
export interface SimpleImageData {
|
|
71
|
+
data: Uint8ClampedArray;
|
|
72
|
+
width: number;
|
|
73
|
+
height: number;
|
|
74
|
+
colorSpace?: string;
|
|
75
|
+
colorType?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Convert Uint8Array/Buffer to ImageData-like object
|
|
79
|
+
* Compatible with skia-canvas putImageData
|
|
80
|
+
*
|
|
81
|
+
* @param data - Raw pixel data (RGBA format)
|
|
82
|
+
* @param width - Image width in pixels
|
|
83
|
+
* @param height - Image height in pixels
|
|
84
|
+
* @returns ImageData-like object
|
|
85
|
+
*/
|
|
86
|
+
export declare function pixelsToImageData(data: Uint8Array | Buffer, width: number, height: number): SimpleImageData;
|
|
87
|
+
/**
|
|
88
|
+
* Draw raw RGBA pixels to canvas
|
|
89
|
+
*
|
|
90
|
+
* @param canvas - The skia-canvas Canvas instance
|
|
91
|
+
* @param data - Raw pixel data (RGBA format)
|
|
92
|
+
* @param width - Image width in pixels
|
|
93
|
+
* @param height - Image height in pixels
|
|
94
|
+
*/
|
|
95
|
+
export declare function drawPixelsToCanvas(canvas: Canvas, data: Uint8Array | Buffer, width: number, height: number): void;
|
|
96
|
+
/**
|
|
97
|
+
* Create a Uint8Array view of a Buffer without copying
|
|
98
|
+
*
|
|
99
|
+
* @param buffer - Node.js Buffer
|
|
100
|
+
* @returns Uint8Array view of the same memory
|
|
101
|
+
*/
|
|
102
|
+
export declare function bufferToUint8Array(buffer: Buffer): Uint8Array;
|
|
103
|
+
/**
|
|
104
|
+
* Resize raw pixel data using canvas
|
|
105
|
+
*
|
|
106
|
+
* @param data - Source pixel data (RGBA format)
|
|
107
|
+
* @param srcWidth - Source width
|
|
108
|
+
* @param srcHeight - Source height
|
|
109
|
+
* @param dstWidth - Destination width
|
|
110
|
+
* @param dstHeight - Destination height
|
|
111
|
+
* @param canvas - Optional canvas to reuse (for performance)
|
|
112
|
+
* @returns Resized pixel data as Buffer
|
|
113
|
+
*/
|
|
114
|
+
export declare function resizePixels(data: Uint8Array | Buffer, srcWidth: number, srcHeight: number, dstWidth: number, dstHeight: number, canvas?: Canvas): Buffer;
|
|
115
|
+
//# sourceMappingURL=canvas-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-utils.d.ts","sourceRoot":"","sources":["../../src/canvas/canvas-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAElF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CA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+
* Canvas Utilities for skia-canvas
|
|
3
|
+
*
|
|
4
|
+
* Raw buffer utilities for efficient pixel data handling.
|
|
5
|
+
* Always uses toBuffer('raw') - never PNG or other encoded formats.
|
|
6
|
+
*/
|
|
7
|
+
import { Canvas } from 'skia-canvas';
|
|
8
|
+
/**
|
|
9
|
+
* Create a pixel buffer for image manipulation
|
|
10
|
+
*
|
|
11
|
+
* Uses Uint8ClampedArray which automatically clamps values to 0-255,
|
|
12
|
+
* preventing overflow bugs in filters and pixel manipulation code.
|
|
13
|
+
*
|
|
14
|
+
* @param width - Image width in pixels
|
|
15
|
+
* @param height - Image height in pixels
|
|
16
|
+
* @returns Uint8ClampedArray of size width * height * 4 (RGBA)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const pixels = createPixelBuffer(1920, 1080);
|
|
21
|
+
* // Safe manipulation - values auto-clamped to 0-255
|
|
22
|
+
* pixels[0] = 300; // Becomes 255
|
|
23
|
+
* pixels[1] = -50; // Becomes 0
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function createPixelBuffer(width, height) {
|
|
27
|
+
return new Uint8ClampedArray(width * height * 4);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a pixel buffer initialized with a solid color
|
|
31
|
+
*
|
|
32
|
+
* @param width - Image width in pixels
|
|
33
|
+
* @param height - Image height in pixels
|
|
34
|
+
* @param r - Red component (0-255)
|
|
35
|
+
* @param g - Green component (0-255)
|
|
36
|
+
* @param b - Blue component (0-255)
|
|
37
|
+
* @param a - Alpha component (0-255, default 255)
|
|
38
|
+
* @returns Uint8ClampedArray filled with the specified color
|
|
39
|
+
*/
|
|
40
|
+
export function createPixelBufferWithColor(width, height, r, g, b, a = 255) {
|
|
41
|
+
const pixels = new Uint8ClampedArray(width * height * 4);
|
|
42
|
+
for (let i = 0; i < pixels.length; i += 4) {
|
|
43
|
+
pixels[i] = r;
|
|
44
|
+
pixels[i + 1] = g;
|
|
45
|
+
pixels[i + 2] = b;
|
|
46
|
+
pixels[i + 3] = a;
|
|
47
|
+
}
|
|
48
|
+
return pixels;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get raw RGBA pixel data from canvas (synchronous)
|
|
52
|
+
* ALWAYS uses toBufferSync('raw') - never PNG or other encoded formats.
|
|
53
|
+
*
|
|
54
|
+
* @param canvas - The skia-canvas Canvas instance
|
|
55
|
+
* @param options - Optional buffer format options
|
|
56
|
+
* @returns Buffer containing raw RGBA pixel data
|
|
57
|
+
*/
|
|
58
|
+
export function getRawPixels(canvas, options) {
|
|
59
|
+
return canvas.toBufferSync('raw', {
|
|
60
|
+
colorType: options?.colorType ?? 'rgba',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get raw RGBA pixel data from canvas (asynchronous)
|
|
65
|
+
* ALWAYS uses toBuffer('raw') - never PNG or other encoded formats.
|
|
66
|
+
*
|
|
67
|
+
* @param canvas - The skia-canvas Canvas instance
|
|
68
|
+
* @param options - Optional buffer format options
|
|
69
|
+
* @returns Promise resolving to Buffer containing raw RGBA pixel data
|
|
70
|
+
*/
|
|
71
|
+
export async function getRawPixelsAsync(canvas, options) {
|
|
72
|
+
return canvas.toBuffer('raw', {
|
|
73
|
+
colorType: options?.colorType ?? 'rgba',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Reset canvas state for new frame
|
|
78
|
+
*
|
|
79
|
+
* Prevents Skia command history buildup which can cause memory
|
|
80
|
+
* growth and performance degradation over time.
|
|
81
|
+
*
|
|
82
|
+
* @param ctx - The 2D rendering context
|
|
83
|
+
*/
|
|
84
|
+
export function resetCanvas(ctx) {
|
|
85
|
+
// Use reset() if available (Canvas API), otherwise clearRect
|
|
86
|
+
if (typeof ctx.reset === 'function') {
|
|
87
|
+
ctx.reset();
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const canvas = ctx.canvas;
|
|
91
|
+
ctx.save();
|
|
92
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
93
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
94
|
+
ctx.restore();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Convert Uint8Array/Buffer to ImageData-like object
|
|
99
|
+
* Compatible with skia-canvas putImageData
|
|
100
|
+
*
|
|
101
|
+
* @param data - Raw pixel data (RGBA format)
|
|
102
|
+
* @param width - Image width in pixels
|
|
103
|
+
* @param height - Image height in pixels
|
|
104
|
+
* @returns ImageData-like object
|
|
105
|
+
*/
|
|
106
|
+
export function pixelsToImageData(data, width, height) {
|
|
107
|
+
const clampedArray = new Uint8ClampedArray(data.buffer, data.byteOffset, data.byteLength);
|
|
108
|
+
return {
|
|
109
|
+
data: clampedArray,
|
|
110
|
+
width,
|
|
111
|
+
height,
|
|
112
|
+
colorSpace: 'srgb',
|
|
113
|
+
colorType: 'rgba', // Required by skia-canvas
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Draw raw RGBA pixels to canvas
|
|
118
|
+
*
|
|
119
|
+
* @param canvas - The skia-canvas Canvas instance
|
|
120
|
+
* @param data - Raw pixel data (RGBA format)
|
|
121
|
+
* @param width - Image width in pixels
|
|
122
|
+
* @param height - Image height in pixels
|
|
123
|
+
*/
|
|
124
|
+
export function drawPixelsToCanvas(canvas, data, width, height) {
|
|
125
|
+
const ctx = canvas.getContext('2d');
|
|
126
|
+
const imageData = pixelsToImageData(data, width, height);
|
|
127
|
+
ctx.putImageData(imageData, 0, 0);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create a Uint8Array view of a Buffer without copying
|
|
131
|
+
*
|
|
132
|
+
* @param buffer - Node.js Buffer
|
|
133
|
+
* @returns Uint8Array view of the same memory
|
|
134
|
+
*/
|
|
135
|
+
export function bufferToUint8Array(buffer) {
|
|
136
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Resize raw pixel data using canvas
|
|
140
|
+
*
|
|
141
|
+
* @param data - Source pixel data (RGBA format)
|
|
142
|
+
* @param srcWidth - Source width
|
|
143
|
+
* @param srcHeight - Source height
|
|
144
|
+
* @param dstWidth - Destination width
|
|
145
|
+
* @param dstHeight - Destination height
|
|
146
|
+
* @param canvas - Optional canvas to reuse (for performance)
|
|
147
|
+
* @returns Resized pixel data as Buffer
|
|
148
|
+
*/
|
|
149
|
+
export function resizePixels(data, srcWidth, srcHeight, dstWidth, dstHeight, canvas) {
|
|
150
|
+
// Create source canvas
|
|
151
|
+
const srcCanvas = new Canvas(srcWidth, srcHeight);
|
|
152
|
+
const srcCtx = srcCanvas.getContext('2d');
|
|
153
|
+
const srcImageData = pixelsToImageData(data, srcWidth, srcHeight);
|
|
154
|
+
srcCtx.putImageData(srcImageData, 0, 0);
|
|
155
|
+
// Create or reuse destination canvas
|
|
156
|
+
const dstCanvas = canvas ?? new Canvas(dstWidth, dstHeight);
|
|
157
|
+
if (dstCanvas.width !== dstWidth || dstCanvas.height !== dstHeight) {
|
|
158
|
+
// Canvas dimensions don't match, need to create new one
|
|
159
|
+
const newDst = new Canvas(dstWidth, dstHeight);
|
|
160
|
+
const dstCtx = newDst.getContext('2d');
|
|
161
|
+
dstCtx.drawImage(srcCanvas, 0, 0, dstWidth, dstHeight);
|
|
162
|
+
return getRawPixels(newDst);
|
|
163
|
+
}
|
|
164
|
+
const dstCtx = dstCanvas.getContext('2d');
|
|
165
|
+
resetCanvas(dstCtx);
|
|
166
|
+
dstCtx.drawImage(srcCanvas, 0, 0, dstWidth, dstHeight);
|
|
167
|
+
return getRawPixels(dstCanvas);
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=canvas-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-utils.js","sourceRoot":"","sources":["../../src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pB,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IACvD,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FrameLoop - High-performance frame generation with backpressure
|
|
3
|
+
*
|
|
4
|
+
* Manages frame generation with:
|
|
5
|
+
* - Backpressure via maxQueueSize (default: 8)
|
|
6
|
+
* - Automatic canvas reset before each frame
|
|
7
|
+
* - Proper VideoFrame lifecycle management
|
|
8
|
+
* - Async pipelining for optimal throughput
|
|
9
|
+
*
|
|
10
|
+
* Best practices implemented:
|
|
11
|
+
* 1. Memory lifecycle: Explicit frame closing with try...finally
|
|
12
|
+
* 2. Canvas state: ctx.reset() or clearRect at start of every frame
|
|
13
|
+
* 3. Color formats: RGBA output, even dimensions for YUV420
|
|
14
|
+
* 4. Pipeline optimization: Async pipelining with backpressure
|
|
15
|
+
* 5. Raw buffer export: Always uses toBuffer('raw')
|
|
16
|
+
*/
|
|
17
|
+
import { Canvas } from 'skia-canvas';
|
|
18
|
+
import { VideoFrame } from '../core/VideoFrame.js';
|
|
19
|
+
import type { FrameLoopConfig, FrameLoopState } from './types.js';
|
|
20
|
+
type SkiaContext = any;
|
|
21
|
+
/**
|
|
22
|
+
* FrameLoop class for generating video frames with backpressure control
|
|
23
|
+
*/
|
|
24
|
+
export declare class FrameLoop {
|
|
25
|
+
private canvas;
|
|
26
|
+
private ctx;
|
|
27
|
+
private config;
|
|
28
|
+
private state;
|
|
29
|
+
private frameIndex;
|
|
30
|
+
private queueSize;
|
|
31
|
+
private pendingFrames;
|
|
32
|
+
private resolveWaitForDrain;
|
|
33
|
+
private startTime;
|
|
34
|
+
private frameDurationUs;
|
|
35
|
+
constructor(config: FrameLoopConfig);
|
|
36
|
+
/**
|
|
37
|
+
* Get current state
|
|
38
|
+
*/
|
|
39
|
+
getState(): FrameLoopState;
|
|
40
|
+
/**
|
|
41
|
+
* Get current queue size
|
|
42
|
+
*/
|
|
43
|
+
getQueueSize(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Get canvas width
|
|
46
|
+
*/
|
|
47
|
+
getWidth(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Get canvas height
|
|
50
|
+
*/
|
|
51
|
+
getHeight(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get the underlying canvas for direct access
|
|
54
|
+
*/
|
|
55
|
+
getCanvas(): Canvas;
|
|
56
|
+
/**
|
|
57
|
+
* Get the 2D context for direct access
|
|
58
|
+
*/
|
|
59
|
+
getContext(): SkiaContext;
|
|
60
|
+
/**
|
|
61
|
+
* Start frame generation
|
|
62
|
+
*
|
|
63
|
+
* @param totalFrames - Total number of frames to generate (Infinity for continuous)
|
|
64
|
+
*/
|
|
65
|
+
start(totalFrames?: number): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Stop frame generation immediately
|
|
68
|
+
*/
|
|
69
|
+
stop(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Pause frame generation
|
|
72
|
+
*/
|
|
73
|
+
pause(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Resume frame generation
|
|
76
|
+
*/
|
|
77
|
+
resume(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Get the next frame from the loop
|
|
80
|
+
*
|
|
81
|
+
* Called by the encoder to consume frames. The caller takes ownership
|
|
82
|
+
* of the frame and MUST call frame.close() when done.
|
|
83
|
+
*
|
|
84
|
+
* @returns The next VideoFrame, or null if none available
|
|
85
|
+
*/
|
|
86
|
+
takeFrame(): VideoFrame | null;
|
|
87
|
+
/**
|
|
88
|
+
* Signal that a frame has been consumed externally
|
|
89
|
+
*
|
|
90
|
+
* Use this when frames are consumed outside of takeFrame(),
|
|
91
|
+
* to maintain correct backpressure accounting.
|
|
92
|
+
*/
|
|
93
|
+
frameConsumed(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Check if there are frames available
|
|
96
|
+
*/
|
|
97
|
+
hasFrames(): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Get the current frame index
|
|
100
|
+
*/
|
|
101
|
+
getCurrentFrameIndex(): number;
|
|
102
|
+
private generateFrame;
|
|
103
|
+
private waitForDrain;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Create a FrameLoop with the given configuration
|
|
107
|
+
*
|
|
108
|
+
* @param config - FrameLoop configuration
|
|
109
|
+
* @returns A new FrameLoop instance
|
|
110
|
+
*/
|
|
111
|
+
export declare function createFrameLoop(config: FrameLoopConfig): FrameLoop;
|
|
112
|
+
export {};
|
|
113
|
+
//# sourceMappingURL=frame-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-loop.d.ts","sourceRoot":"","sources":["../../src/canvas/frame-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAInD,OAAO,KAAK,EACV,eAAe,EAEf,cAAc,EACf,MAAM,YAAY,CAAC;AAOpB,KAAK,WAAW,GAAG,GAAG,CAAC;AAEvB;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,aAAa,CAAoB;IACzC,OAAO,CAAC,mBAAmB,CAA6B;IAGxD,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,eAAe,CAAS;gBAEpB,MAAM,EAAE,eAAe;IAmCnC;;OAEG;IACH,QAAQ,IAAI,cAAc;IAI1B;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG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