rpi-cam-lib
Version:
A lightweight library to control CSI-2 camera modules via any raspberry pi can read camera module but is dependent to shell.
181 lines (180 loc) • 10 kB
TypeScript
import type { ICameraDescriptor, ICameraOptions, ICameraStillOptions, ICameraVideoOptions, IOutputException } from "./interfaces/index";
import { ChildProcessWithoutNullStreams } from "node:child_process";
import { EventEmitter } from "node:events";
import { Taskman } from "./common";
declare class LiveMode extends EventEmitter {
constructor();
}
export declare class RPICam extends Taskman {
private camera;
private options?;
private reserved;
/**
* @type {boolean}
* @prop `waiting` has two usage, first is forcing `wait` method to stop, seconds is checking process is waiting or not.
*/
waiting: boolean;
/** @type {{ id: string; pid: number }[]} */
/**@prop `tasks` is current async opreations running on camera with pid and id.*/
tasks: {
id: string;
pid: number;
}[];
/** @type {LiveMode} */
/** @prop live streaming of camera comes to `live` event emitter of class.*/
live: LiveMode;
/**
* @constructor constructor of `RPICam`.
* @param {number} camera is number of camera to get in use.
* @param {ICameraOptions} options is avail options and formatting and setting camera by manual and method of capturing.
*/
constructor(camera: number, options?: ICameraOptions);
/**
* Reserve the camera to prevent it from being used by other processes by opening an infinite and cancellable recording stream.
* @returns {Promise<IOutputException>} reservation status.
*/
reserve(): Promise<IOutputException>;
/**
* Kills process of reservation of camera and make it free.
* @returns {IOutputException} status of unlocking camera.
*/
unlockReserve(): IOutputException;
/**
* Check reservation of camera by this process.
* @returns {boolean} is reserved or not.
*/
isReserved(): boolean;
/**
* Same as `serveStill` but is sync.
* @param {string} filename is path of saving image, also is okay set it to empty string for streaming options and everything like stream should not be outputed on a file or use `serveStillCutomSync` to set everything manually.
* @param {number} width (no description needed)
* @param {number} height (no description needed)
* @param { ICameraStillOptions & { stream?: boolean }} options of serving (full settings and options of camera and rpicam).
* @returns {IOutputException} capturing status or stream event emitter output.
*/
serveStillSync(filename: string, width: number, height: number, options?: ICameraStillOptions & {
stream?: boolean;
}): IOutputException;
/**
* Same as `serveStillCustom` but is sync.
* @param {number} width (no description needed)
* @param {number} height (no description needed)
* @param { ICameraStillOptions & {stream?: boolean,output?: string,format?: string}} options of serving (full settings and options of camera and rpicam).
* @returns {IOutputException} capturing status or stream event emitter output.
*/
serveStillCustomSync(width: number, height: number, options?: ICameraStillOptions & {
stream?: boolean;
output?: string;
format?: string;
}): IOutputException;
/**
* Same as `serveStill` But everything except some required things must setted manually.
* @param {number} width (no description needed)
* @param {number} height (no description needed)
* @param {string} id of task for managing.
* @param {ICameraStillOptions & {stream?: boolean,output?: string,format?: string}} options of serving (full settings and options of camera and rpicam).
* @returns { Promise<IOutputException>} capturing status or stream event emitter output (as a `Promise`).
*/
serveStillCustom(width: number, height: number, id: string, options?: ICameraStillOptions & {
stream?: boolean;
output?: string;
format?: string;
}): Promise<IOutputException>;
/**
* Same as `serveVideoCustom` but is sync.
* @param {number} timeout of capturing or time argument of streams and other stuff needs time.
* @param {number} width (no description needed)
* @param {number} height (no description needed)
* @param {ICameraVideoOptions & { stream?: boolean, output?: string }} options of serving (full settings and options of camera and rpicam).
* @returns {IOutputException} capturing status or stream event emitter output.
*/
serveVideoCustomSync(timeout: number, width: number, height: number, options?: ICameraVideoOptions & {
stream?: boolean;
output?: string;
}): IOutputException;
/**
* Same as `serveVideo` But everything except some required things must setted manually.
* @param {number} timeout of capturing or time argument of streams and other stuff needs time.
* @param {number} width (no description needed)
* @param {number} height (no description needed)
* @param {string} id of task for managing.
* @param {ICameraVideoOptions & { stream?: boolean, output?: string }} options of serving (full settings and options of camera and rpicam).
* @returns {Promise<IOutputException>} capturing status or stream event emitter output (as a `Promise`).
*/
serveVideoCustom(timeout: number, width: number, height: number, id: string, options?: ICameraVideoOptions & {
stream?: boolean;
output?: string;
}): Promise<IOutputException>;
/**
* It takes a photo and saves it to a file (powered by rpicam-still).
* @param {string} filename is path of saving image, also is okay set it to empty string for streaming options and everything like stream should not be outputed on a file or use `serveStillCutomSync` to set everything manually.
* @param {number} width of resolution.
* @param {number} height of resolution.
* @param {string} id of task for managing.
* @param { ICameraStillOptions & { stream?: boolean }} options of serving (full settings and options of camera and rpicam).
* @returns {Promise<IOutputException>} capturing status or stream event emitter output (as a `Promise`).
*/
serveStill(filename: string, width: number, height: number, id: string, options?: ICameraStillOptions & {
stream?: boolean;
}): Promise<IOutputException>;
/**
* Same as `serveVideo` but is sync.
* @param {string} filename is path of saving video, also is okay set it to empty string for streaming options and everything like stream should not be outputed on a file or use `serveVideoCutomSync` to set everything manually.
* @param {number} width of resolution.
* @param {number} height of resolution.
* @param { ICameraStillOptions & { stream?: boolean }} options of serving (full settings and options of camera and rpicam).
* @returns {Promise<IOutputException>} capturing status or stream event emitter output.
*/
serveVideoSync(filename: string, timeout: number, width: number, height: number, options?: ICameraVideoOptions & {
stream?: boolean;
}): IOutputException;
/**
* Capture a video and save it to a file (powered by rpicam-vid).
* @param {string} filename is path of saving video, also is okay set it to empty string for streaming options and everything like stream should not be outputed on a file or use `serveVideoCutomSync` to set everything manually.
* @param {number} width of resolution.
* @param {number} height of resolution.
* @param {string} id of task for managing.
* @param { ICameraStillOptions & { stream?: boolean }} options of serving (full settings and options of camera and rpicam).
* @returns {Promise<IOutputException>} capturing status or stream event emitter output (as a `Promise`).
*/
serveVideo(filename: string, timeout: number, width: number, height: number, id: string, options?: ICameraVideoOptions & {
stream?: boolean;
}): Promise<IOutputException>;
/**
* Start a live stream, load the stream to the `live` property or access it via the return value (this is similar to an event emitter and is powered by `serveVideo`).
* @param width (no description needed)
* @param height (no description needed)
* @param id of task for managing.
* @param options of serving (full settings and options of camera and rpicam).
* @returns {ChildProcessWithoutNullStreams } spawn stream of node:child_process.
*/
serveLive(width: number, height: number, id: string, options: ICameraVideoOptions): ChildProcessWithoutNullStreams;
/**
* Gets list of available camera (connected cameras).
* @returns {ICameraDescriptor[]} list of cameras, must be empty if nothing connected.
*/
static getAvailCameras(): ICameraDescriptor[];
/**
* Same as `isReady` but is sync.
* @returns {Promise<boolean>} ready status by boolean.
*/
isReadySync(): boolean;
/**
* Checks is Camera ready or not by testing a simple rpicam-still on camera (purpose of testing is to check is connected okay or is free or not).
* @returns {Promise<boolean>} ready status by boolean (as a`Promise`).
*/
isReady(): Promise<boolean>;
/**
* Wait Asynchronously until camera being free.
* @param {number} timeout is waiting time for releasing camera, is optional and default values is `Infinity`.
* @returns {Promise<IOutputException>} when camera is free, always success of return value is `true` but output value means camera is free or not.
*/
wait(timeout?: number): Promise<IOutputException>;
/**
* is same to wait but is sync.
* @param {number} timeout is waiting time for releasing camera, is optional and default values is `Infinity`.
* @returns {IOutputException} when camera is free, always success of return value is `true` but output value means camera is free or not.
*/
waitSync(timeout?: number): IOutputException;
}
export {};