-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
245 lines (217 loc) · 7.87 KB
/
index.d.ts
File metadata and controls
245 lines (217 loc) · 7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/// <reference types="node" />
import { EventEmitter } from "events";
/**
* Device information returned by camera enumeration
*/
export interface DeviceInfo {
/** Friendly name of the camera device */
friendlyName: string;
/** Symbolic link to the camera device */
symbolicLink: string;
}
/**
* Camera format information including resolution and frame rate
*/
export interface CameraFormat {
/** Native subtype GUID string (round-trippable) */
/** Friendly short subtype name (e.g., 'MJPEG', 'NV12', 'YUY2', 'RGB32') */
subtype: string;
/** Native subtype GUID string (round-trippable); present in getSupportedFormats entries */
guid?: string;
/** Width of the camera format in pixels */
width: number;
/** Height of the camera format in pixels */
height: number;
/** Frame rate of the camera format in frames per second (frameRate) */
frameRate: number;
}
/**
* Camera dimensions (current capture output)
*/
export interface CameraDimensions {
/** Width of the current camera format in pixels */
width: number;
/** Height of the current camera format in pixels */
height: number;
}
/**
* Result of a successful operation
*/
export interface OperationResult {
/** Whether the operation was successful */
success: boolean;
/** Descriptive message about the operation */
message: string;
}
/**
* Result of claiming a device
*/
export interface ClaimDeviceResult extends OperationResult {
/** Symbolic link of the claimed device */
symbolicLink: string;
}
/**
* Result of setting a desired format
*/
export interface SetFormatResult extends OperationResult {
/** Actual width that was set */
actualWidth: number;
/** Actual height that was set */
actualHeight: number;
}
/**
* Camera information returned by getCameraInfo()
* This is a flexible shape; implementations may include grouped `formats` keyed by
* subtype and optional `encoders` information. Use `any` fields for extensibility.
*/
export interface CameraInfo {
friendlyName?: string;
symbolicLink?: string;
/** Optional encoders supported by the camera or driver */
encoders?: string[];
/** Optional grouped formats map: subtype -> { subtype, resolutions: CameraFormat[] } */
formats?: CameraFormat[];
// legacy fields may also be present (supportedResolutions, supportedResolutionsBySubtype)
[k: string]: any;
}
/**
* Camera events interface
*/
export interface CameraEvents {
/** Emitted when a new frame/sample is captured.
*
* The payload is a Node.js Buffer containing the raw contiguous sample bytes
* returned by the OS/driver for the negotiated media subtype. For example:
* - MJPEG/MJPEG frames: JPEG bitstream bytes
* - NV12/YUY2: raw YUV planar/interleaved bytes
* - RGB32/RGB24: raw pixel bytes
*
* The exact layout depends on the chosen CameraFormat (check the `subtype`/`guid`).
*/
frame: (frameData: Buffer) => void;
}
/**
* Main Camera class for interacting with camera devices
* Extends EventEmitter to provide frame events
*/
export declare class Camera extends EventEmitter {
constructor();
/**
* Enumerate all available camera devices
* @returns Promise that resolves to an array of device information
* @throws Error if enumeration fails
*/
enumerateDevices(): Promise<DeviceInfo[]>;
/**
* Claim a specific camera device for exclusive use
* @param symbolicLink - The symbolic link of the device to claim
* @returns Promise that resolves to claim result
* @throws Error if device cannot be claimed
*/
claimDevice(symbolicLink: string): Promise<ClaimDeviceResult>;
/**
* Release the currently claimed camera device
* @returns Promise that resolves to operation result
* @throws Error if device cannot be released
*/
releaseDevice(): Promise<OperationResult>;
/**
* Get all supported camera formats for the claimed device
* @returns Promise that resolves to an array of supported formats
* @throws Error if no device is claimed or if formats cannot be retrieved
*/
getSupportedFormats(): Promise<CameraFormat[]>;
/**
* Get rich camera information for the claimed device.
* Returns a flexible object that includes at least `friendlyName` and `symbolicLink`,
* and may include grouped `formats` or legacy fields.
*/
getCameraInfo(): Promise<CameraInfo>;
/**
* Set the desired camera format (resolution and frame rate)
* The camera will select the closest matching format if exact match is not available
* @param width - Desired width in pixels
* @param height - Desired height in pixels
* @param frameRate - Desired frame rate (frameRate)
* @returns Promise that resolves to the actual format that was set
* @throws Error if format cannot be set
*/
/**
* Set desired format using an explicit native subtype identifier (string) plus resolution and frameRate.
* The subtype may be a common name like 'NV12', 'RGB24', 'RGB32', 'MJPG' or a GUID string.
*/
/**
* Set desired format using an explicit native subtype identifier (string) plus resolution and frameRate.
* The subtype may be a common name like 'NV12', 'RGB24', 'RGB32', 'MJPG' or a GUID string.
*/
// Accept a single CameraFormat object: { subtype, width, height, frameRate }
setFormat(format: CameraFormat): Promise<SetFormatResult>;
/**
* Set the output format for frame conversion using Windows Media Foundation.
* When set, captured frames will be converted from the native camera format
* to the specified output format before being delivered to the 'frame' event.
*
* Supported output formats: 'RGB32', 'RGB24', 'NV12', 'YUY2', 'UYVY', 'IYUV', or a GUID string.
*
* @param format - Output format string (e.g., 'RGB32', 'NV12') or null/undefined to disable conversion
* @returns Promise that resolves when the output format is set
* @throws Error if the format is not supported or conversion cannot be configured
*
* @example
* // Enable conversion to RGB32 (BGRA)
* await camera.setOutputFormat('RGB32');
*
* // Disable conversion (return raw native frames)
* await camera.setOutputFormat(null);
*/
setOutputFormat(format?: string | null): Promise<OperationResult>;
/**
* Get the current camera dimensions
* @returns Current camera dimensions
*/
getDimensions(): CameraDimensions;
/**
* Start capturing frames from the camera.
* Frames are emitted via the 'frame' event with Buffer payloads.
* The JS wrapper passes an internal frame emitter callback into native code,
* so no callback parameter is required here.
* @returns Promise that resolves when capture starts successfully
*/
startCapture(): Promise<OperationResult>;
/**
* Stop capturing frames from the camera
* @returns Promise that resolves when capture stops successfully
* @throws Error if capture cannot be stopped
*/
stopCapture(): Promise<OperationResult>;
/**
* Check if the camera is currently capturing
* @returns true if capturing, false otherwise
*/
isCapturing(): boolean;
// EventEmitter overrides for better TypeScript support
on<K extends keyof CameraEvents>(event: K, listener: CameraEvents[K]): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
once<K extends keyof CameraEvents>(event: K, listener: CameraEvents[K]): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
emit<K extends keyof CameraEvents>(
event: K,
...args: Parameters<CameraEvents[K]>
): boolean;
emit(event: string | symbol, ...args: any[]): boolean;
off<K extends keyof CameraEvents>(event: K, listener: CameraEvents[K]): this;
off(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener<K extends keyof CameraEvents>(
event: K,
listener: CameraEvents[K],
): this;
removeListener(
event: string | symbol,
listener: (...args: any[]) => void,
): this;
}
// For CommonJS usage
declare const Camera: {
new (): Camera;
};
export = Camera;