@volorio/video-compositor 0.2.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 +7 -0
- package/dist/src/index.d.ts +43 -0
- package/dist/src/index.js +82 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { VolorioRoomClient } from "@volorio/rtc";
|
|
2
|
+
export declare const volorioVideoCompositorProductId = "video_compositor";
|
|
3
|
+
export declare const volorioVideoCompositorSessionFeatures: {
|
|
4
|
+
readonly videoCompositor: true;
|
|
5
|
+
};
|
|
6
|
+
export interface VolorioVideoLayer {
|
|
7
|
+
id: string;
|
|
8
|
+
source: unknown;
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
zIndex?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface VolorioVideoCompositorEngine {
|
|
16
|
+
setLayers(layers: VolorioVideoLayer[]): Promise<void>;
|
|
17
|
+
render(): Promise<unknown>;
|
|
18
|
+
stop(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface VolorioVideoCompositorOptions {
|
|
21
|
+
layers: VolorioVideoLayer[];
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
background?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare class VolorioVideoCompositorExtension {
|
|
27
|
+
private readonly engine;
|
|
28
|
+
constructor(engine: VolorioVideoCompositorEngine);
|
|
29
|
+
setLayers(layers: VolorioVideoLayer[]): Promise<void>;
|
|
30
|
+
render(): Promise<unknown>;
|
|
31
|
+
stop(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export declare class VolorioVideoCompositorProcessor {
|
|
34
|
+
readonly name = "volorio_video_compositor";
|
|
35
|
+
private options;
|
|
36
|
+
private readonly canvas;
|
|
37
|
+
private readonly context;
|
|
38
|
+
constructor(options: VolorioVideoCompositorOptions, canvas?: HTMLCanvasElement | OffscreenCanvas);
|
|
39
|
+
update(options: VolorioVideoCompositorOptions): void;
|
|
40
|
+
processFrame(source: CanvasImageSource): HTMLCanvasElement | OffscreenCanvas;
|
|
41
|
+
}
|
|
42
|
+
export declare function createVolorioVideoCompositorProcessor(options: VolorioVideoCompositorOptions): VolorioVideoCompositorProcessor;
|
|
43
|
+
export type { VolorioRoomClient };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VolorioVideoCompositorProcessor = exports.VolorioVideoCompositorExtension = exports.volorioVideoCompositorSessionFeatures = exports.volorioVideoCompositorProductId = void 0;
|
|
4
|
+
exports.createVolorioVideoCompositorProcessor = createVolorioVideoCompositorProcessor;
|
|
5
|
+
exports.volorioVideoCompositorProductId = "video_compositor";
|
|
6
|
+
exports.volorioVideoCompositorSessionFeatures = { videoCompositor: true };
|
|
7
|
+
class VolorioVideoCompositorExtension {
|
|
8
|
+
engine;
|
|
9
|
+
constructor(engine) {
|
|
10
|
+
this.engine = engine;
|
|
11
|
+
}
|
|
12
|
+
async setLayers(layers) {
|
|
13
|
+
await this.engine.setLayers(layers);
|
|
14
|
+
}
|
|
15
|
+
async render() {
|
|
16
|
+
return this.engine.render();
|
|
17
|
+
}
|
|
18
|
+
async stop() {
|
|
19
|
+
await this.engine.stop();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.VolorioVideoCompositorExtension = VolorioVideoCompositorExtension;
|
|
23
|
+
class VolorioVideoCompositorProcessor {
|
|
24
|
+
name = "volorio_video_compositor";
|
|
25
|
+
options;
|
|
26
|
+
canvas;
|
|
27
|
+
context;
|
|
28
|
+
constructor(options, canvas = createCanvas(options.width ?? 1280, options.height ?? 720)) {
|
|
29
|
+
this.options = options;
|
|
30
|
+
this.canvas = canvas;
|
|
31
|
+
const context = canvas.getContext("2d");
|
|
32
|
+
if (context === null) {
|
|
33
|
+
throw new Error("Volorio video compositor requires a 2D canvas context");
|
|
34
|
+
}
|
|
35
|
+
this.context = context;
|
|
36
|
+
}
|
|
37
|
+
update(options) {
|
|
38
|
+
this.options = options;
|
|
39
|
+
}
|
|
40
|
+
processFrame(source) {
|
|
41
|
+
const fallbackSize = readFrameSize(source);
|
|
42
|
+
const width = this.options.width ?? fallbackSize.width;
|
|
43
|
+
const height = this.options.height ?? fallbackSize.height;
|
|
44
|
+
this.canvas.width = width;
|
|
45
|
+
this.canvas.height = height;
|
|
46
|
+
this.context.fillStyle = this.options.background ?? "#000000";
|
|
47
|
+
this.context.fillRect(0, 0, width, height);
|
|
48
|
+
const layers = [...this.options.layers].sort((left, right) => (left.zIndex ?? 0) - (right.zIndex ?? 0));
|
|
49
|
+
if (layers.length === 0) {
|
|
50
|
+
this.context.drawImage(source, 0, 0, width, height);
|
|
51
|
+
}
|
|
52
|
+
for (const layer of layers) {
|
|
53
|
+
const layerSource = layer.source === "local" || layer.source === undefined ? source : layer.source;
|
|
54
|
+
this.context.drawImage(layerSource, layer.x, layer.y, layer.width, layer.height);
|
|
55
|
+
}
|
|
56
|
+
return this.canvas;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.VolorioVideoCompositorProcessor = VolorioVideoCompositorProcessor;
|
|
60
|
+
function createVolorioVideoCompositorProcessor(options) {
|
|
61
|
+
return new VolorioVideoCompositorProcessor(options);
|
|
62
|
+
}
|
|
63
|
+
function createCanvas(width, height) {
|
|
64
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
65
|
+
return new OffscreenCanvas(width, height);
|
|
66
|
+
}
|
|
67
|
+
if (typeof document !== "undefined") {
|
|
68
|
+
const canvas = document.createElement("canvas");
|
|
69
|
+
canvas.width = width;
|
|
70
|
+
canvas.height = height;
|
|
71
|
+
return canvas;
|
|
72
|
+
}
|
|
73
|
+
throw new Error("Volorio video processors require a browser canvas runtime");
|
|
74
|
+
}
|
|
75
|
+
function readFrameSize(source) {
|
|
76
|
+
const candidate = source;
|
|
77
|
+
return {
|
|
78
|
+
width: candidate.videoWidth ?? candidate.naturalWidth ?? (Number(candidate.width) || 1280),
|
|
79
|
+
height: candidate.videoHeight ?? candidate.naturalHeight ?? (Number(candidate.height) || 720),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAoFA,sFAEC;AApFY,QAAA,+BAA+B,GAAG,kBAAkB,CAAC;AACrD,QAAA,qCAAqC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAW,CAAC;AAyBxF,MAAa,+BAA+B;IACb;IAA7B,YAA6B,MAAoC;QAApC,WAAM,GAAN,MAAM,CAA8B;IAAG,CAAC;IAErE,KAAK,CAAC,SAAS,CAAC,MAA2B;QACzC,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;CACF;AAdD,0EAcC;AAED,MAAa,+BAA+B;IACjC,IAAI,GAAG,0BAA0B,CAAC;IACnC,OAAO,CAAgC;IAC9B,MAAM,CAAsC;IAC5C,OAAO,CAA+D;IAEvF,YAAY,OAAsC,EAAE,SAA8C,YAAY,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,EAAE,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC;QAC1J,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,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AC,aAAa,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;KAC9F,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@volorio/video-compositor",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Volorio video compositor extension for RTC layouts and overlays.",
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
|
+
"types": "dist/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/src/index.d.ts",
|
|
11
|
+
"default": "./dist/src/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist/src", "README.md"],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.build.json",
|
|
21
|
+
"test": "pnpm build",
|
|
22
|
+
"pack:local": "pnpm build && npm pack --pack-destination dist"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@volorio/rtc": "^0.2.0"
|
|
26
|
+
}
|
|
27
|
+
}
|