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,35 +1,235 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OffscreenCanvas
|
|
2
|
+
* OffscreenCanvas Polyfill using skia-canvas
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Provides a Web-compatible OffscreenCanvas API for Node.js,
|
|
5
|
+
* making it easy to port browser code to Node.js.
|
|
6
|
+
*
|
|
7
|
+
* skia-canvas provides:
|
|
8
|
+
* - Metal acceleration on macOS
|
|
9
|
+
* - Vulkan acceleration on Linux/Windows
|
|
10
|
+
* - Automatic CPU fallback
|
|
11
|
+
*/
|
|
12
|
+
import { Canvas as SkiaCanvas } from 'skia-canvas';
|
|
13
|
+
import { VideoFrame } from '../core/VideoFrame.js';
|
|
14
|
+
/**
|
|
15
|
+
* ImageData polyfill compatible with skia-canvas
|
|
6
16
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
export class ImageDataPolyfill {
|
|
18
|
+
data;
|
|
19
|
+
width;
|
|
20
|
+
height;
|
|
21
|
+
colorSpace = 'srgb';
|
|
22
|
+
colorType = 'rgba'; // Required by skia-canvas
|
|
23
|
+
constructor(dataOrWidth, widthOrHeight, height) {
|
|
24
|
+
if (typeof dataOrWidth === 'number') {
|
|
25
|
+
this.width = dataOrWidth;
|
|
26
|
+
this.height = widthOrHeight;
|
|
27
|
+
this.data = new Uint8ClampedArray(this.width * this.height * 4);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.data = dataOrWidth;
|
|
31
|
+
this.width = widthOrHeight;
|
|
32
|
+
this.height = height ?? dataOrWidth.length / 4 / widthOrHeight;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Blob polyfill for convertToBlob
|
|
38
|
+
*/
|
|
39
|
+
class BlobPolyfill {
|
|
40
|
+
_buffer;
|
|
41
|
+
type;
|
|
42
|
+
size;
|
|
43
|
+
constructor(buffer, type) {
|
|
44
|
+
this._buffer = buffer;
|
|
45
|
+
this.type = type;
|
|
46
|
+
this.size = buffer.length;
|
|
47
|
+
}
|
|
48
|
+
async arrayBuffer() {
|
|
49
|
+
return this._buffer.buffer.slice(this._buffer.byteOffset, this._buffer.byteOffset + this._buffer.byteLength);
|
|
50
|
+
}
|
|
51
|
+
async text() {
|
|
52
|
+
return this._buffer.toString('utf-8');
|
|
53
|
+
}
|
|
54
|
+
stream() {
|
|
55
|
+
const buffer = this._buffer;
|
|
56
|
+
return new ReadableStream({
|
|
57
|
+
start(controller) {
|
|
58
|
+
controller.enqueue(new Uint8Array(buffer));
|
|
59
|
+
controller.close();
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
slice(start, end, contentType) {
|
|
64
|
+
const sliced = this._buffer.slice(start, end);
|
|
65
|
+
return new BlobPolyfill(sliced, contentType ?? this.type);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* OffscreenCanvas Polyfill
|
|
70
|
+
*
|
|
71
|
+
* Provides a Web-compatible OffscreenCanvas API using skia-canvas.
|
|
72
|
+
* This makes it easy to port browser canvas code to Node.js.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const canvas = new OffscreenCanvasPolyfill(1920, 1080);
|
|
77
|
+
* const ctx = canvas.getContext('2d');
|
|
78
|
+
* ctx.fillStyle = 'red';
|
|
79
|
+
* ctx.fillRect(0, 0, 1920, 1080);
|
|
80
|
+
*
|
|
81
|
+
* // Create VideoFrame for encoding
|
|
82
|
+
* const frame = new VideoFrame(canvas, { timestamp: 0 });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export class OffscreenCanvasPolyfill {
|
|
86
|
+
_canvas;
|
|
87
|
+
_ctx = null;
|
|
88
|
+
/**
|
|
89
|
+
* Create a new OffscreenCanvas with the specified dimensions
|
|
90
|
+
*/
|
|
91
|
+
constructor(width, height) {
|
|
92
|
+
this._canvas = new SkiaCanvas(width, height);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the width of the canvas
|
|
96
|
+
*/
|
|
97
|
+
get width() {
|
|
98
|
+
return this._canvas.width;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Set the width of the canvas (creates new internal canvas)
|
|
102
|
+
*/
|
|
103
|
+
set width(value) {
|
|
104
|
+
const height = this._canvas.height;
|
|
105
|
+
this._canvas = new SkiaCanvas(value, height);
|
|
106
|
+
this._ctx = null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the height of the canvas
|
|
110
|
+
*/
|
|
111
|
+
get height() {
|
|
112
|
+
return this._canvas.height;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Set the height of the canvas (creates new internal canvas)
|
|
116
|
+
*/
|
|
117
|
+
set height(value) {
|
|
118
|
+
const width = this._canvas.width;
|
|
119
|
+
this._canvas = new SkiaCanvas(width, value);
|
|
120
|
+
this._ctx = null;
|
|
121
|
+
}
|
|
122
|
+
getContext(contextId, options) {
|
|
123
|
+
if (contextId === '2d') {
|
|
124
|
+
if (!this._ctx) {
|
|
125
|
+
this._ctx = this._canvas.getContext('2d');
|
|
126
|
+
}
|
|
127
|
+
return this._ctx;
|
|
128
|
+
}
|
|
129
|
+
// WebGL not supported
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Convert canvas content to a Blob
|
|
134
|
+
*
|
|
135
|
+
* @param options - Optional encoding options
|
|
136
|
+
* @returns Promise resolving to a Blob containing the image data
|
|
137
|
+
*/
|
|
138
|
+
async convertToBlob(options) {
|
|
139
|
+
const type = options?.type ?? 'image/png';
|
|
140
|
+
const quality = options?.quality ?? 0.92;
|
|
141
|
+
let format;
|
|
142
|
+
let mimeType;
|
|
143
|
+
if (type === 'image/jpeg' || type === 'image/jpg') {
|
|
144
|
+
format = 'jpg';
|
|
145
|
+
mimeType = 'image/jpeg';
|
|
146
|
+
}
|
|
147
|
+
else if (type === 'image/webp') {
|
|
148
|
+
format = 'webp';
|
|
149
|
+
mimeType = 'image/webp';
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
format = 'png';
|
|
153
|
+
mimeType = 'image/png';
|
|
154
|
+
}
|
|
155
|
+
const buffer = await this._canvas.toBuffer(format, {
|
|
156
|
+
quality,
|
|
157
|
+
});
|
|
158
|
+
return new BlobPolyfill(buffer, mimeType);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Transfer canvas content to an ImageBitmap
|
|
162
|
+
*
|
|
163
|
+
* Note: This creates a copy of the pixel data, as true zero-copy
|
|
164
|
+
* transfer is not possible in Node.js the same way as in browsers.
|
|
165
|
+
*
|
|
166
|
+
* @returns ImageBitmap-like object with the canvas content
|
|
167
|
+
*/
|
|
168
|
+
transferToImageBitmap() {
|
|
169
|
+
const pixels = this._getImageData();
|
|
170
|
+
return {
|
|
171
|
+
width: this._canvas.width,
|
|
172
|
+
height: this._canvas.height,
|
|
173
|
+
_data: pixels,
|
|
174
|
+
close: () => {
|
|
175
|
+
// No-op in Node.js
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get raw RGBA pixel data from canvas
|
|
181
|
+
* (Internal method for VideoFrame construction)
|
|
182
|
+
*/
|
|
183
|
+
_getImageData() {
|
|
184
|
+
const buffer = this._canvas.toBufferSync('raw', {
|
|
185
|
+
colorType: 'rgba',
|
|
186
|
+
});
|
|
187
|
+
return new Uint8ClampedArray(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get the underlying skia-canvas Canvas
|
|
191
|
+
* (Non-standard, for advanced use cases)
|
|
192
|
+
*/
|
|
193
|
+
get _skiaCanvas() {
|
|
194
|
+
return this._canvas;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Enable/disable GPU acceleration
|
|
198
|
+
* (Non-standard, for performance tuning)
|
|
199
|
+
*/
|
|
200
|
+
get gpu() {
|
|
201
|
+
return this._canvas.gpu;
|
|
202
|
+
}
|
|
203
|
+
set gpu(value) {
|
|
204
|
+
this._canvas.gpu = value;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Re-export core VideoFrame as VideoFramePolyfill for compatibility
|
|
208
|
+
export { VideoFrame as VideoFramePolyfill };
|
|
17
209
|
/**
|
|
18
210
|
* Install the OffscreenCanvas polyfill globally
|
|
211
|
+
*
|
|
212
|
+
* This makes OffscreenCanvas available as a global, matching browser behavior.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* import { installOffscreenCanvasPolyfill } from 'webcodecs-node';
|
|
217
|
+
* installOffscreenCanvasPolyfill();
|
|
218
|
+
*
|
|
219
|
+
* // Now you can use OffscreenCanvas like in a browser
|
|
220
|
+
* const canvas = new OffscreenCanvas(1920, 1080);
|
|
221
|
+
* ```
|
|
19
222
|
*/
|
|
20
223
|
export function installOffscreenCanvasPolyfill() {
|
|
21
224
|
const g = globalThis;
|
|
22
225
|
if (typeof g.OffscreenCanvas === 'undefined') {
|
|
23
226
|
g.OffscreenCanvas = OffscreenCanvasPolyfill;
|
|
24
227
|
}
|
|
25
|
-
if (typeof g.OffscreenCanvasRenderingContext2D === 'undefined') {
|
|
26
|
-
g.OffscreenCanvasRenderingContext2D = OffscreenCanvasRenderingContext2DPolyfill;
|
|
27
|
-
}
|
|
28
228
|
if (typeof g.ImageData === 'undefined') {
|
|
29
229
|
g.ImageData = ImageDataPolyfill;
|
|
30
230
|
}
|
|
31
231
|
if (typeof g.VideoFrame === 'undefined') {
|
|
32
|
-
g.VideoFrame =
|
|
232
|
+
g.VideoFrame = VideoFrame;
|
|
33
233
|
}
|
|
34
234
|
}
|
|
35
235
|
//# sourceMappingURL=OffscreenCanvas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OffscreenCanvas.js","sourceRoot":"","sources":["../../src/polyfills/OffscreenCanvas.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"OffscreenCanvas.js","sourceRoot":"","sources":["../../src/polyfills/OffscreenCanvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACnB,IAAI,CAAoB;IACxB,KAAK,CAAS;I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,CAAC,UAAU,GAAG,UAAU,CAAC;IAC5B,CAAC;AACH,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export { type BufferSource, DOMException, type CodecState, type HardwareAccelera
|
|
|
5
5
|
export { type DOMRectInit, DOMRectReadOnly, type PlaneLayout, } from './geometry.js';
|
|
6
6
|
export { type VideoPixelFormat, type VideoFrameBufferInit, type VideoFrameInit, type VideoFrameCopyToOptions, } from './video.js';
|
|
7
7
|
export { type AudioSampleFormat, type AudioDataInit, type AudioDataCopyToOptions, } from './audio.js';
|
|
8
|
+
export { type NativeFrame, type NativeVideoFrame, type NativeAudioFrame, isNativeFrame, hasUnref, hasClone, } from './native-frame.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,KAAK,YAAY,EACjB,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,KAAK,WAAW,EAChB,eAAe,EACf,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,uBAAuB,GAC7B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,sBAAsB,GAC5B,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,KAAK,YAAY,EACjB,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,KAAK,WAAW,EAChB,eAAe,EACf,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,uBAAuB,GAC7B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,sBAAsB,GAC5B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,aAAa,EACb,QAAQ,EACR,QAAQ,GACT,MAAM,mBAAmB,CAAC"}
|
package/dist/types/index.js
CHANGED
|
@@ -5,4 +5,6 @@
|
|
|
5
5
|
export { DOMException, } from './common.js';
|
|
6
6
|
// Geometry types
|
|
7
7
|
export { DOMRectReadOnly, } from './geometry.js';
|
|
8
|
+
// Native frame types (for node-av integration)
|
|
9
|
+
export { isNativeFrame, hasUnref, hasClone, } from './native-frame.js';
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAe;AACf,OAAO,EAEL,YAAY,GAQb,MAAM,aAAa,CAAC;AAErB,iBAAiB;AACjB,OAAO,EAEL,eAAe,GAEhB,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAe;AACf,OAAO,EAEL,YAAY,GAQb,MAAM,aAAa,CAAC;AAErB,iBAAiB;AACjB,OAAO,EAEL,eAAe,GAEhB,MAAM,eAAe,CAAC;AAiBvB,+CAA+C;AAC/C,OAAO,EAIL,aAAa,EACb,QAAQ,EACR,QAAQ,GACT,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native frame interface for node-av integration
|
|
3
|
+
*
|
|
4
|
+
* Represents a native (non-JavaScript) audio or video frame from the node-av backend.
|
|
5
|
+
* These frames hold references to native memory that must be properly released.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base interface for native frames from node-av
|
|
9
|
+
*/
|
|
10
|
+
export interface NativeFrame {
|
|
11
|
+
/**
|
|
12
|
+
* Convert the native frame data to a JavaScript Buffer.
|
|
13
|
+
* For video frames, returns raw pixel data.
|
|
14
|
+
* For audio frames, returns raw PCM samples.
|
|
15
|
+
*/
|
|
16
|
+
toBuffer(): Buffer;
|
|
17
|
+
/**
|
|
18
|
+
* Release the native resources associated with this frame.
|
|
19
|
+
* Should be called when the frame is no longer needed.
|
|
20
|
+
* Some implementations may not have this method (returns undefined).
|
|
21
|
+
*/
|
|
22
|
+
unref?(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Create a clone of this native frame.
|
|
25
|
+
* Returns a new frame with its own native resources.
|
|
26
|
+
* Some implementations may not support cloning.
|
|
27
|
+
*/
|
|
28
|
+
clone?(): NativeFrame;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Native video frame with additional video-specific properties
|
|
32
|
+
*/
|
|
33
|
+
export interface NativeVideoFrame extends NativeFrame {
|
|
34
|
+
/** Frame width in pixels */
|
|
35
|
+
readonly width?: number;
|
|
36
|
+
/** Frame height in pixels */
|
|
37
|
+
readonly height?: number;
|
|
38
|
+
/** Pixel format (e.g., 'yuv420p', 'rgba') */
|
|
39
|
+
readonly format?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Native audio frame with additional audio-specific properties
|
|
43
|
+
*/
|
|
44
|
+
export interface NativeAudioFrame extends NativeFrame {
|
|
45
|
+
/** Number of audio samples per channel */
|
|
46
|
+
readonly nbSamples?: number;
|
|
47
|
+
/** Sample rate in Hz */
|
|
48
|
+
readonly sampleRate?: number;
|
|
49
|
+
/** Number of audio channels */
|
|
50
|
+
readonly channels?: number;
|
|
51
|
+
/** Sample format (e.g., 'fltp', 's16') */
|
|
52
|
+
readonly format?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Type guard to check if an object is a NativeFrame
|
|
56
|
+
*
|
|
57
|
+
* A NativeFrame must have both toBuffer() and unref() methods.
|
|
58
|
+
* This distinguishes it from objects like skia-canvas Canvas which
|
|
59
|
+
* have toBuffer() but are not native frames from node-av.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isNativeFrame(obj: unknown): obj is NativeFrame;
|
|
62
|
+
/**
|
|
63
|
+
* Type guard to check if a NativeFrame has unref capability
|
|
64
|
+
*/
|
|
65
|
+
export declare function hasUnref(frame: NativeFrame): frame is NativeFrame & {
|
|
66
|
+
unref(): void;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Type guard to check if a NativeFrame has clone capability
|
|
70
|
+
*/
|
|
71
|
+
export declare function hasClone(frame: NativeFrame): frame is NativeFrame & {
|
|
72
|
+
clone(): NativeFrame;
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=native-frame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-frame.d.ts","sourceRoot":"","sources":["../../src/types/native-frame.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,QAAQ,IAAI,MAAM,CAAC;IAEnB;;;;OAIG;IACH,KAAK,CAAC,IAAI,IAAI,CAAC;IAEf;;;;OAIG;IACH,KAAK,CAAC,IAAI,WAAW,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,4BAA4B;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,6BAA6B;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,wBAAwB;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,+BAA+B;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAO9D;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,KAAK,IAAI,WAAW,GAAG;IAAE,KAAK,IAAI,IAAI,CAAA;CAAE,CAErF;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,KAAK,IAAI,WAAW,GAAG;IAAE,KAAK,IAAI,WAAW,CAAA;CAAE,CAE5F"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native frame interface for node-av integration
|
|
3
|
+
*
|
|
4
|
+
* Represents a native (non-JavaScript) audio or video frame from the node-av backend.
|
|
5
|
+
* These frames hold references to native memory that must be properly released.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to check if an object is a NativeFrame
|
|
9
|
+
*
|
|
10
|
+
* A NativeFrame must have both toBuffer() and unref() methods.
|
|
11
|
+
* This distinguishes it from objects like skia-canvas Canvas which
|
|
12
|
+
* have toBuffer() but are not native frames from node-av.
|
|
13
|
+
*/
|
|
14
|
+
export function isNativeFrame(obj) {
|
|
15
|
+
return Boolean(obj &&
|
|
16
|
+
typeof obj === 'object' &&
|
|
17
|
+
typeof obj.toBuffer === 'function' &&
|
|
18
|
+
typeof obj.unref === 'function');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Type guard to check if a NativeFrame has unref capability
|
|
22
|
+
*/
|
|
23
|
+
export function hasUnref(frame) {
|
|
24
|
+
return typeof frame.unref === 'function';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Type guard to check if a NativeFrame has clone capability
|
|
28
|
+
*/
|
|
29
|
+
export function hasClone(frame) {
|
|
30
|
+
return typeof frame.clone === 'function';
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=native-frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-frame.js","sourceRoot":"","sources":["../../src/types/native-frame.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsDH;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,OAAO,OAAO,CACZ,GAAG;QACH,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAQ,GAAmB,CAAC,QAAQ,KAAK,UAAU;QACnD,OAAQ,GAAmB,CAAC,KAAK,KAAK,UAAU,CACjD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAkB;IACzC,OAAO,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAkB;IACzC,OAAO,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,CAAC;AAC3C,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export { toUint8Array, copyToUint8Array, concatUint8Arrays, isReadableStream, readStreamToUint8Array, } from './buffer.js';
|
|
5
5
|
export { validatePositiveInteger, validateNonNegativeInteger, validateFiniteNumber, validateRequired, validateNonEmptyString, validateConfigured, validateNotClosed, } from './validation.js';
|
|
6
6
|
export { Logger, createLogger, setDebugMode, isDebugMode, type LogLevel, type LogEntry, } from './logger.js';
|
|
7
|
-
export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, type ImageDataLike, type CanvasLike, type VideoFrameLike, } from './type-guards.js';
|
|
7
|
+
export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, isSkiaCanvas, extractCanvasPixels, type ImageDataLike, type CanvasLike, type VideoFrameLike, type SkiaCanvasLike, } from './type-guards.js';
|
|
8
8
|
export { parseAvcDecoderConfig, convertAvccToAnnexB, splitAnnexBNals, extractAvcParameterSetsFromAnnexB, buildAvcDecoderConfig, convertAnnexBToAvcc, type AvcConfig, } from './avc.js';
|
|
9
9
|
export { parseHvccDecoderConfig, convertHvccToAnnexB, splitHevcAnnexBNals, extractHevcParameterSetsFromAnnexB, buildHvccDecoderConfig, convertAnnexBToHvcc, type HvccConfig, } from './hevc.js';
|
|
10
10
|
export { parseAudioSpecificConfig, wrapAacFrameWithAdts, buildAudioSpecificConfig, stripAdtsHeader, type AacConfig, } from './aac.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,QAAQ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AoB,CAAC;AAG5B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,QAAQ,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,oBAAoB,EACpB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { validatePositiveInteger, validateNonNegativeInteger, validateFiniteNumb
|
|
|
8
8
|
// Logger
|
|
9
9
|
export { Logger, createLogger, setDebugMode, isDebugMode, } from './logger.js';
|
|
10
10
|
// Type guards
|
|
11
|
-
export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, } from './type-guards.js';
|
|
11
|
+
export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, isSkiaCanvas, extractCanvasPixels, } from './type-guards.js';
|
|
12
12
|
// Codec helpers
|
|
13
13
|
export { parseAvcDecoderConfig, convertAvccToAnnexB, splitAnnexBNals, extractAvcParameterSetsFromAnnexB, buildAvcDecoderConfig, convertAnnexBToAvcc, } from './avc.js';
|
|
14
14
|
export { parseHvccDecoderConfig, convertHvccToAnnexB, splitHevcAnnexBNals, extractHevcParameterSetsFromAnnexB, buildHvccDecoderConfig, convertAnnexBToHvcc, } from './hevc.js';
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mBAAmB;AACnB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,uBAAuB;AACvB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,SAAS;AACT,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,GAGZ,MAAM,aAAa,CAAC;AAErB,cAAc;AACd,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mBAAmB;AACnB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,uBAAuB;AACvB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,SAAS;AACT,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,GAGZ,MAAM,aAAa,CAAC;AAErB,cAAc;AACd,OAAO,EACL,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 @@ export interface CanvasLike {
|
|
|
18
18
|
getContext: (type: string, options?: unknown) => unknown;
|
|
19
19
|
_getImageData?: () => Uint8ClampedArray;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Interface for skia-canvas Canvas objects
|
|
23
|
+
*/
|
|
24
|
+
export interface SkiaCanvasLike {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
gpu: boolean;
|
|
28
|
+
engine: {
|
|
29
|
+
renderer: string;
|
|
30
|
+
api?: string;
|
|
31
|
+
};
|
|
32
|
+
getContext: (type: '2d') => any;
|
|
33
|
+
toBuffer: (format: string, options?: unknown) => Promise<Buffer>;
|
|
34
|
+
toBufferSync: (format: string, options?: unknown) => Buffer;
|
|
35
|
+
}
|
|
21
36
|
/**
|
|
22
37
|
* Interface for VideoFrame-like objects (including our polyfill)
|
|
23
38
|
*/
|
|
@@ -45,10 +60,15 @@ export interface VideoFrameLike {
|
|
|
45
60
|
* Check if object is ImageData-like (has data, width, height)
|
|
46
61
|
*/
|
|
47
62
|
export declare function isImageDataLike(obj: unknown): obj is ImageDataLike;
|
|
63
|
+
/**
|
|
64
|
+
* Check if object is a skia-canvas Canvas
|
|
65
|
+
*/
|
|
66
|
+
export declare function isSkiaCanvas(obj: unknown): obj is SkiaCanvasLike;
|
|
48
67
|
/**
|
|
49
68
|
* Check if object is a canvas-like object with getContext
|
|
69
|
+
* Includes both standard canvas and skia-canvas
|
|
50
70
|
*/
|
|
51
|
-
export declare function isCanvasLike(obj: unknown): obj is CanvasLike;
|
|
71
|
+
export declare function isCanvasLike(obj: unknown): obj is CanvasLike | SkiaCanvasLike;
|
|
52
72
|
/**
|
|
53
73
|
* Check if object is a VideoFrame-like object
|
|
54
74
|
*/
|
|
@@ -57,4 +77,12 @@ export declare function isVideoFrameLike(obj: unknown): obj is VideoFrameLike;
|
|
|
57
77
|
* Check if an object is a CanvasImageSource-like object
|
|
58
78
|
*/
|
|
59
79
|
export declare function isCanvasImageSource(obj: unknown): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Extract raw pixel data from any canvas-like object
|
|
82
|
+
* Returns RGBA Uint8Array
|
|
83
|
+
*
|
|
84
|
+
* @param canvas - Any canvas-like object (skia-canvas, polyfill, or standard)
|
|
85
|
+
* @returns Raw RGBA pixel data as Uint8Array
|
|
86
|
+
*/
|
|
87
|
+
export declare function extractCanvasPixels(canvas: CanvasLike | SkiaCanvasLike): Uint8Array;
|
|
60
88
|
//# sourceMappingURL=type-guards.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,GAAG,UAAU,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;IACzD,aAAa,CAAC,EAAE,MAAM,iBAAiB,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAA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G;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CASpE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAQzD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,CA0BnF"}
|
|
@@ -12,16 +12,34 @@ export function isImageDataLike(obj) {
|
|
|
12
12
|
typeof o.width === 'number' &&
|
|
13
13
|
typeof o.height === 'number');
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if object is a skia-canvas Canvas
|
|
17
|
+
*/
|
|
18
|
+
export function isSkiaCanvas(obj) {
|
|
19
|
+
if (!obj || typeof obj !== 'object')
|
|
20
|
+
return false;
|
|
21
|
+
const o = obj;
|
|
22
|
+
return (typeof o.width === 'number' &&
|
|
23
|
+
typeof o.height === 'number' &&
|
|
24
|
+
typeof o.gpu === 'boolean' &&
|
|
25
|
+
typeof o.getContext === 'function' &&
|
|
26
|
+
typeof o.toBuffer === 'function' &&
|
|
27
|
+
typeof o.toBufferSync === 'function' &&
|
|
28
|
+
typeof o.engine === 'object');
|
|
29
|
+
}
|
|
15
30
|
/**
|
|
16
31
|
* Check if object is a canvas-like object with getContext
|
|
32
|
+
* Includes both standard canvas and skia-canvas
|
|
17
33
|
*/
|
|
18
34
|
export function isCanvasLike(obj) {
|
|
19
35
|
if (!obj || typeof obj !== 'object')
|
|
20
36
|
return false;
|
|
21
37
|
const o = obj;
|
|
22
|
-
|
|
38
|
+
// Standard canvas check
|
|
39
|
+
const isStandardCanvas = typeof o.width === 'number' &&
|
|
23
40
|
typeof o.height === 'number' &&
|
|
24
|
-
typeof o.getContext === 'function'
|
|
41
|
+
typeof o.getContext === 'function';
|
|
42
|
+
return isStandardCanvas;
|
|
25
43
|
}
|
|
26
44
|
/**
|
|
27
45
|
* Check if object is a VideoFrame-like object
|
|
@@ -46,4 +64,31 @@ export function isCanvasImageSource(obj) {
|
|
|
46
64
|
(typeof o.codedWidth === 'number' && typeof o.codedHeight === 'number') ||
|
|
47
65
|
isImageDataLike(obj));
|
|
48
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Extract raw pixel data from any canvas-like object
|
|
69
|
+
* Returns RGBA Uint8Array
|
|
70
|
+
*
|
|
71
|
+
* @param canvas - Any canvas-like object (skia-canvas, polyfill, or standard)
|
|
72
|
+
* @returns Raw RGBA pixel data as Uint8Array
|
|
73
|
+
*/
|
|
74
|
+
export function extractCanvasPixels(canvas) {
|
|
75
|
+
// Try skia-canvas method first (most efficient)
|
|
76
|
+
if ('toBufferSync' in canvas && typeof canvas.toBufferSync === 'function') {
|
|
77
|
+
const buffer = canvas.toBufferSync('raw', { colorType: 'rgba' });
|
|
78
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
79
|
+
}
|
|
80
|
+
// Try polyfill method
|
|
81
|
+
if ('_getImageData' in canvas && typeof canvas._getImageData === 'function') {
|
|
82
|
+
const data = canvas._getImageData();
|
|
83
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
84
|
+
}
|
|
85
|
+
// Standard canvas 2D context
|
|
86
|
+
const ctx = canvas.getContext('2d');
|
|
87
|
+
if (ctx && typeof ctx.getImageData === 'function') {
|
|
88
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
89
|
+
return new Uint8Array(imageData.data.buffer, imageData.data.byteOffset, imageData.data.byteLength);
|
|
90
|
+
}
|
|
91
|
+
// Fallback: empty buffer
|
|
92
|
+
return new Uint8Array(canvas.width * canvas.height * 4);
|
|
93
|
+
}
|
|
49
94
|
//# sourceMappingURL=type-guards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"type-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