longpipe 0.0.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.
@@ -0,0 +1,226 @@
1
+ interface Conv2DWeights {
2
+ weights: ArrayLike<number>;
3
+ bias: ArrayLike<number>;
4
+ }
5
+ interface DepthwiseWeights {
6
+ weights: ArrayLike<number>;
7
+ bias: ArrayLike<number>;
8
+ }
9
+
10
+ type Dtype = 'f32' | 'f16';
11
+ interface Tensor {
12
+ readonly h: number;
13
+ readonly w: number;
14
+ readonly c: number;
15
+ }
16
+ interface MLBuffer {
17
+ }
18
+ interface Op {
19
+ readonly inputs: Tensor[];
20
+ readonly output: Tensor;
21
+ run(): void;
22
+ }
23
+ interface Presenter {
24
+ run(): void;
25
+ }
26
+ type Activation = "none" | "relu6";
27
+ interface Conv2dParams {
28
+ outChannels: number;
29
+ kernel: number;
30
+ stride: number;
31
+ padding: number | "same" | "valid";
32
+ activation: Activation;
33
+ }
34
+ interface DepthwiseParams {
35
+ kernel: number;
36
+ stride: number;
37
+ padding: number | "same" | "valid";
38
+ activation: Activation;
39
+ }
40
+ interface UpsampleParams {
41
+ outH: number;
42
+ outW: number;
43
+ }
44
+ interface UpsampleConv1x1Params {
45
+ outH: number;
46
+ outW: number;
47
+ outChannels: number;
48
+ activation: Activation;
49
+ }
50
+ type ImageSource = ImageBitmap | VideoFrame;
51
+ interface InputOp {
52
+ readonly output: Tensor;
53
+ setSource(src: ImageSource): void;
54
+ run(): void;
55
+ }
56
+ type DataView_ = Float32Array | Uint16Array;
57
+ interface Backend {
58
+ readonly dtype: Dtype;
59
+ readonly canvas: HTMLCanvasElement | OffscreenCanvas;
60
+ tensor(h: number, w: number, c: number, data?: DataView_): Tensor;
61
+ upload(data: DataView_): MLBuffer;
62
+ ops: {
63
+ Conv2d: (input: Tensor, weights: Conv2DWeights, params: Conv2dParams) => Op;
64
+ DepthwiseConv2d: (input: Tensor, weights: DepthwiseWeights, params: DepthwiseParams) => Op;
65
+ Add: (a: Tensor, b: Tensor) => Op;
66
+ Sigmoid: (input: Tensor) => Op;
67
+ BilinearUpsample: (input: Tensor, params: UpsampleParams) => Op;
68
+ BicubicUpsample: (input: Tensor, params: UpsampleParams) => Op;
69
+ ChannelConcat: (a: Tensor, b: Tensor) => Op;
70
+ Conv2dAdd: (input: Tensor, skip: Tensor, weights: Conv2DWeights, params: Conv2dParams) => Op;
71
+ UpsampleConcat: (a: Tensor, b: Tensor, params: UpsampleParams) => Op;
72
+ UpsampleConv1x1: (input: Tensor, weights: Conv2DWeights, params: UpsampleConv1x1Params) => Op;
73
+ UpsampleSigmoid: (input: Tensor, params: UpsampleParams) => Op;
74
+ Input: (h: number, w: number) => InputOp;
75
+ };
76
+ presenters: {
77
+ CompositeSolid: (image: Tensor, alpha: Tensor, bgColor: [number, number, number]) => Presenter;
78
+ CompositeImage: (image: Tensor, alpha: Tensor, bg: Tensor) => Presenter;
79
+ CompositeImageBilinear: (image: Tensor, alpha: Tensor, bg: Tensor) => Presenter;
80
+ CompositePassthrough: (image: Tensor) => Presenter;
81
+ };
82
+ readback(tensor: Tensor): Promise<Float32Array>;
83
+ sync(): Promise<void>;
84
+ destroy(): void;
85
+ }
86
+
87
+ type ModelName = 'xxs' | 'xs' | 'small' | 'compact' | 'medium' | 'large' | 'xl';
88
+ type PresetName = 'fast' | 'balanced' | 'quality' | 'auto';
89
+ interface ManualPreset {
90
+ model: ModelName;
91
+ dtype: Dtype;
92
+ resolution: {
93
+ w: number;
94
+ h: number;
95
+ };
96
+ skipFrames: number;
97
+ }
98
+
99
+ type BackgroundInput = 'blur' | 'none' | string | ImageBitmap | HTMLImageElement | HTMLVideoElement | {
100
+ color: [number, number, number];
101
+ } | {
102
+ blur: BlurInput;
103
+ } | {
104
+ image: ImageInput;
105
+ } | {
106
+ video: VideoInput;
107
+ };
108
+ type BlurInput = true | {
109
+ strength: 'low' | 'medium' | 'high' | number;
110
+ } | {
111
+ sigma: number;
112
+ };
113
+ type ImageInput = ImageBitmap | HTMLImageElement | string | {
114
+ data: ArrayBuffer | Blob | Uint8Array;
115
+ type: string;
116
+ };
117
+ type VideoInput = HTMLVideoElement | string | {
118
+ data: ArrayBuffer | Blob | Uint8Array;
119
+ type: string;
120
+ };
121
+ type Background = {
122
+ kind: 'none';
123
+ } | {
124
+ kind: 'color';
125
+ rgb: [number, number, number];
126
+ } | {
127
+ kind: 'blur';
128
+ sigma: number;
129
+ } | {
130
+ kind: 'image';
131
+ bitmap: ImageBitmap;
132
+ } | {
133
+ kind: 'video';
134
+ port: MessagePort;
135
+ };
136
+
137
+ interface RendererStats {
138
+ fps: number;
139
+ modelFps: number;
140
+ modelMs: number;
141
+ displayMs: number;
142
+ skipped: number;
143
+ preset: string;
144
+ skipFrames: number;
145
+ enabled: boolean;
146
+ inputPath: string;
147
+ outputPath: string;
148
+ }
149
+ type ErrorSource = 'backend-lost' | 'worker' | 'adaptive' | 'background' | 'unknown';
150
+ interface PipelineError {
151
+ message: string;
152
+ source: ErrorSource;
153
+ recoverable: boolean;
154
+ cause?: unknown;
155
+ }
156
+
157
+ type AudioMode = 'passthrough' | 'drop';
158
+
159
+ interface PipelineOptions {
160
+ background?: BackgroundInput;
161
+ preset?: PresetName | ManualPreset;
162
+ weightsBaseUrl?: string;
163
+ audio?: AudioMode;
164
+ enabled?: boolean;
165
+ outputResolution?: {
166
+ w: number;
167
+ h: number;
168
+ };
169
+ adaptive?: boolean;
170
+ onReady?: () => void;
171
+ onError?: (err: PipelineError) => void;
172
+ }
173
+ declare class Pipeline implements PromiseLike<Pipeline> {
174
+ readonly stream: MediaStream;
175
+ readonly ready: Promise<void>;
176
+ private controller;
177
+ private worker;
178
+ private inputCleanup;
179
+ private outputCleanup;
180
+ private adaptive;
181
+ private bgCleanup;
182
+ constructor(inputStream: MediaStream, options: PipelineOptions);
183
+ private bootstrap;
184
+ then<T1 = this, T2 = never>(onFulfilled?: ((value: this) => T1 | PromiseLike<T1>) | null, onRejected?: ((reason: unknown) => T2 | PromiseLike<T2>) | null): PromiseLike<T1 | T2>;
185
+ setBackground(input: BackgroundInput): Promise<void>;
186
+ setPreset(p: PresetName | ManualPreset, weights?: ArrayBuffer): void;
187
+ setEnabled(on: boolean): void;
188
+ getStats(): Promise<RendererStats>;
189
+ destroy(): void;
190
+ }
191
+
192
+ interface WebGPUTensor extends Tensor {
193
+ readonly buffer: GPUBuffer;
194
+ }
195
+ interface WebGPUMLBuffer extends MLBuffer {
196
+ readonly buffer: GPUBuffer;
197
+ }
198
+
199
+ interface WebGPUBackendOptions {
200
+ canvas: HTMLCanvasElement | OffscreenCanvas;
201
+ device?: GPUDevice;
202
+ dtype?: Dtype;
203
+ }
204
+ declare class WebGPUBackend implements Backend {
205
+ readonly device: GPUDevice;
206
+ readonly canvas: HTMLCanvasElement | OffscreenCanvas;
207
+ readonly dtype: Dtype;
208
+ readonly ops: Backend["ops"];
209
+ readonly presenters: Backend["presenters"];
210
+ readonly canvasContext: GPUCanvasContext;
211
+ readonly canvasFormat: GPUTextureFormat;
212
+ readonly bytesPerElement: 2 | 4;
213
+ private constructor();
214
+ static isAvailable(): Promise<boolean>;
215
+ static hasF16Support(): Promise<boolean>;
216
+ static create(opts: WebGPUBackendOptions): Promise<WebGPUBackend>;
217
+ getCurrentDisplayTexture(): GPUTexture;
218
+ tensor(h: number, w: number, c: number, data?: DataView_): WebGPUTensor;
219
+ upload(data: DataView_): WebGPUMLBuffer;
220
+ private writeView;
221
+ readback(tensor: WebGPUTensor): Promise<Float32Array>;
222
+ sync(): Promise<void>;
223
+ destroy(): void;
224
+ }
225
+
226
+ export { type Activation, type AudioMode, type Backend, type Background, type BackgroundInput, type BlurInput, type Conv2dParams, type DepthwiseParams, Pipeline as EffectsPipeline, type ErrorSource, type ImageInput, type ManualPreset, type ModelName, type Op, type PipelineError, type PipelineOptions, type PresetName, type Tensor, type VideoInput, WebGPUBackend };
@@ -0,0 +1,226 @@
1
+ interface Conv2DWeights {
2
+ weights: ArrayLike<number>;
3
+ bias: ArrayLike<number>;
4
+ }
5
+ interface DepthwiseWeights {
6
+ weights: ArrayLike<number>;
7
+ bias: ArrayLike<number>;
8
+ }
9
+
10
+ type Dtype = 'f32' | 'f16';
11
+ interface Tensor {
12
+ readonly h: number;
13
+ readonly w: number;
14
+ readonly c: number;
15
+ }
16
+ interface MLBuffer {
17
+ }
18
+ interface Op {
19
+ readonly inputs: Tensor[];
20
+ readonly output: Tensor;
21
+ run(): void;
22
+ }
23
+ interface Presenter {
24
+ run(): void;
25
+ }
26
+ type Activation = "none" | "relu6";
27
+ interface Conv2dParams {
28
+ outChannels: number;
29
+ kernel: number;
30
+ stride: number;
31
+ padding: number | "same" | "valid";
32
+ activation: Activation;
33
+ }
34
+ interface DepthwiseParams {
35
+ kernel: number;
36
+ stride: number;
37
+ padding: number | "same" | "valid";
38
+ activation: Activation;
39
+ }
40
+ interface UpsampleParams {
41
+ outH: number;
42
+ outW: number;
43
+ }
44
+ interface UpsampleConv1x1Params {
45
+ outH: number;
46
+ outW: number;
47
+ outChannels: number;
48
+ activation: Activation;
49
+ }
50
+ type ImageSource = ImageBitmap | VideoFrame;
51
+ interface InputOp {
52
+ readonly output: Tensor;
53
+ setSource(src: ImageSource): void;
54
+ run(): void;
55
+ }
56
+ type DataView_ = Float32Array | Uint16Array;
57
+ interface Backend {
58
+ readonly dtype: Dtype;
59
+ readonly canvas: HTMLCanvasElement | OffscreenCanvas;
60
+ tensor(h: number, w: number, c: number, data?: DataView_): Tensor;
61
+ upload(data: DataView_): MLBuffer;
62
+ ops: {
63
+ Conv2d: (input: Tensor, weights: Conv2DWeights, params: Conv2dParams) => Op;
64
+ DepthwiseConv2d: (input: Tensor, weights: DepthwiseWeights, params: DepthwiseParams) => Op;
65
+ Add: (a: Tensor, b: Tensor) => Op;
66
+ Sigmoid: (input: Tensor) => Op;
67
+ BilinearUpsample: (input: Tensor, params: UpsampleParams) => Op;
68
+ BicubicUpsample: (input: Tensor, params: UpsampleParams) => Op;
69
+ ChannelConcat: (a: Tensor, b: Tensor) => Op;
70
+ Conv2dAdd: (input: Tensor, skip: Tensor, weights: Conv2DWeights, params: Conv2dParams) => Op;
71
+ UpsampleConcat: (a: Tensor, b: Tensor, params: UpsampleParams) => Op;
72
+ UpsampleConv1x1: (input: Tensor, weights: Conv2DWeights, params: UpsampleConv1x1Params) => Op;
73
+ UpsampleSigmoid: (input: Tensor, params: UpsampleParams) => Op;
74
+ Input: (h: number, w: number) => InputOp;
75
+ };
76
+ presenters: {
77
+ CompositeSolid: (image: Tensor, alpha: Tensor, bgColor: [number, number, number]) => Presenter;
78
+ CompositeImage: (image: Tensor, alpha: Tensor, bg: Tensor) => Presenter;
79
+ CompositeImageBilinear: (image: Tensor, alpha: Tensor, bg: Tensor) => Presenter;
80
+ CompositePassthrough: (image: Tensor) => Presenter;
81
+ };
82
+ readback(tensor: Tensor): Promise<Float32Array>;
83
+ sync(): Promise<void>;
84
+ destroy(): void;
85
+ }
86
+
87
+ type ModelName = 'xxs' | 'xs' | 'small' | 'compact' | 'medium' | 'large' | 'xl';
88
+ type PresetName = 'fast' | 'balanced' | 'quality' | 'auto';
89
+ interface ManualPreset {
90
+ model: ModelName;
91
+ dtype: Dtype;
92
+ resolution: {
93
+ w: number;
94
+ h: number;
95
+ };
96
+ skipFrames: number;
97
+ }
98
+
99
+ type BackgroundInput = 'blur' | 'none' | string | ImageBitmap | HTMLImageElement | HTMLVideoElement | {
100
+ color: [number, number, number];
101
+ } | {
102
+ blur: BlurInput;
103
+ } | {
104
+ image: ImageInput;
105
+ } | {
106
+ video: VideoInput;
107
+ };
108
+ type BlurInput = true | {
109
+ strength: 'low' | 'medium' | 'high' | number;
110
+ } | {
111
+ sigma: number;
112
+ };
113
+ type ImageInput = ImageBitmap | HTMLImageElement | string | {
114
+ data: ArrayBuffer | Blob | Uint8Array;
115
+ type: string;
116
+ };
117
+ type VideoInput = HTMLVideoElement | string | {
118
+ data: ArrayBuffer | Blob | Uint8Array;
119
+ type: string;
120
+ };
121
+ type Background = {
122
+ kind: 'none';
123
+ } | {
124
+ kind: 'color';
125
+ rgb: [number, number, number];
126
+ } | {
127
+ kind: 'blur';
128
+ sigma: number;
129
+ } | {
130
+ kind: 'image';
131
+ bitmap: ImageBitmap;
132
+ } | {
133
+ kind: 'video';
134
+ port: MessagePort;
135
+ };
136
+
137
+ interface RendererStats {
138
+ fps: number;
139
+ modelFps: number;
140
+ modelMs: number;
141
+ displayMs: number;
142
+ skipped: number;
143
+ preset: string;
144
+ skipFrames: number;
145
+ enabled: boolean;
146
+ inputPath: string;
147
+ outputPath: string;
148
+ }
149
+ type ErrorSource = 'backend-lost' | 'worker' | 'adaptive' | 'background' | 'unknown';
150
+ interface PipelineError {
151
+ message: string;
152
+ source: ErrorSource;
153
+ recoverable: boolean;
154
+ cause?: unknown;
155
+ }
156
+
157
+ type AudioMode = 'passthrough' | 'drop';
158
+
159
+ interface PipelineOptions {
160
+ background?: BackgroundInput;
161
+ preset?: PresetName | ManualPreset;
162
+ weightsBaseUrl?: string;
163
+ audio?: AudioMode;
164
+ enabled?: boolean;
165
+ outputResolution?: {
166
+ w: number;
167
+ h: number;
168
+ };
169
+ adaptive?: boolean;
170
+ onReady?: () => void;
171
+ onError?: (err: PipelineError) => void;
172
+ }
173
+ declare class Pipeline implements PromiseLike<Pipeline> {
174
+ readonly stream: MediaStream;
175
+ readonly ready: Promise<void>;
176
+ private controller;
177
+ private worker;
178
+ private inputCleanup;
179
+ private outputCleanup;
180
+ private adaptive;
181
+ private bgCleanup;
182
+ constructor(inputStream: MediaStream, options: PipelineOptions);
183
+ private bootstrap;
184
+ then<T1 = this, T2 = never>(onFulfilled?: ((value: this) => T1 | PromiseLike<T1>) | null, onRejected?: ((reason: unknown) => T2 | PromiseLike<T2>) | null): PromiseLike<T1 | T2>;
185
+ setBackground(input: BackgroundInput): Promise<void>;
186
+ setPreset(p: PresetName | ManualPreset, weights?: ArrayBuffer): void;
187
+ setEnabled(on: boolean): void;
188
+ getStats(): Promise<RendererStats>;
189
+ destroy(): void;
190
+ }
191
+
192
+ interface WebGPUTensor extends Tensor {
193
+ readonly buffer: GPUBuffer;
194
+ }
195
+ interface WebGPUMLBuffer extends MLBuffer {
196
+ readonly buffer: GPUBuffer;
197
+ }
198
+
199
+ interface WebGPUBackendOptions {
200
+ canvas: HTMLCanvasElement | OffscreenCanvas;
201
+ device?: GPUDevice;
202
+ dtype?: Dtype;
203
+ }
204
+ declare class WebGPUBackend implements Backend {
205
+ readonly device: GPUDevice;
206
+ readonly canvas: HTMLCanvasElement | OffscreenCanvas;
207
+ readonly dtype: Dtype;
208
+ readonly ops: Backend["ops"];
209
+ readonly presenters: Backend["presenters"];
210
+ readonly canvasContext: GPUCanvasContext;
211
+ readonly canvasFormat: GPUTextureFormat;
212
+ readonly bytesPerElement: 2 | 4;
213
+ private constructor();
214
+ static isAvailable(): Promise<boolean>;
215
+ static hasF16Support(): Promise<boolean>;
216
+ static create(opts: WebGPUBackendOptions): Promise<WebGPUBackend>;
217
+ getCurrentDisplayTexture(): GPUTexture;
218
+ tensor(h: number, w: number, c: number, data?: DataView_): WebGPUTensor;
219
+ upload(data: DataView_): WebGPUMLBuffer;
220
+ private writeView;
221
+ readback(tensor: WebGPUTensor): Promise<Float32Array>;
222
+ sync(): Promise<void>;
223
+ destroy(): void;
224
+ }
225
+
226
+ export { type Activation, type AudioMode, type Backend, type Background, type BackgroundInput, type BlurInput, type Conv2dParams, type DepthwiseParams, Pipeline as EffectsPipeline, type ErrorSource, type ImageInput, type ManualPreset, type ModelName, type Op, type PipelineError, type PipelineOptions, type PresetName, type Tensor, type VideoInput, WebGPUBackend };