Skip to main content

Class: Engine<ResultT, ParamsT, ProcessorT>

@geenee/armature.Engine

Core generic engine

Engine is a core of any app and organizer of a pipeline. It's responsible to interact with lower-level instances and at the same time provide simple and user-friendly interface. Engine combines together data (video) capturing, processing and rendering. It's created for particular Processor. Processor's constructor or instance is provided to the engine and former initializes and controls state of processor during life-circle of the application. Results of processing and captured image are passed to a Renderer attached to the Engine. Notable feature is fast rescaling of images for processing down to the requested resolution in cases when available camera output is bigger. Engine parameters have an option to limit processed image size. Original video stream can be preserved on request, this is useful when processing cannot handle high resolution images but you still want to render high quality video in your app. All core components: Engine, Processor, and Renderer are generics parametrized by type of processing results and optionally tuning parameters.

Type parameters

NameTypeDescription
ResultTextends ObjectType of processing results
ParamsTextends ProcParamsType of processor parameters
ProcessorTextends Processor<ResultT, ParamsT>Type of processor

Hierarchy

Constructors

constructor

new Engine<ResultT, ParamsT, ProcessorT>(Processor, engineParams?, Source?)

Constructor

Type parameters

NameTypeDescription
ResultTextends ObjectType of processing results
ParamsTextends ProcParamsType of processor parameters
ProcessorTextends Processor<ResultT, ParamsT>Type of processor

Parameters

NameTypeDefault valueDescription
ProcessorProcessorT | () => ProcessorTundefinedProcessor class or instance
engineParams?EngineParamsundefinedParameters of the engine
SourceVideoSource | () => VideoSourceVideoCaptureVideo source class or instance

Overrides

EventEmitterT.constructor

Properties

engineParams

Protected Optional engineParams: EngineParams

Parameters of the engine


processCanvas

Protected Optional processCanvas: HTMLCanvasElement

Shallow copy of canvas with video for processors


processSize

Protected processSize: Size

Size of video for processors


processor

Protected processor: ProcessorT

Processor utilized by the engine


renderers

Protected renderers: Renderer<ResultT>[] = []

Renderer attached to the engine


resizeBuffer

Protected Optional resizeBuffer: ImageBuffer

Buffer to resize frames


resizeEnabled

Protected resizeEnabled: boolean = false

Original stream is resized


streamCanvas

Protected Optional streamCanvas: HTMLCanvasElement

Shallow copy of canvas with video for renderers


streamSize

Protected streamSize: Size

Size of video for renderers


video

Protected video: VideoSource

Video source instance


videoRatio

Protected videoRatio: number

Ratio of video stream

Methods

addListener

addListener<E>(event, listener): Engine<ResultT, ParamsT, ProcessorT>

Adds the listener function to the end of the listeners array

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerEngineEvents[E]The callback function

Returns

Engine<ResultT, ParamsT, ProcessorT>

This EventEmitter

Inherited from

EventEmitterT.addListener


addRenderer

addRenderer(renderer): Promise<void>

Attach Renderer to the engine

Parameters

NameTypeDescription
rendererRenderer<ResultT>Object to be attached

Returns

Promise<void>


emit

emit<E>(event, ...args): boolean

Synchronously calls each of the listeners registered for the event

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event
...argsArgs<EngineEvents[E]>Arguments passed to the listeners

Returns

boolean

True if the event had listeners, False otherwise

Inherited from

EventEmitterT.emit


enqueue

Protected enqueue(): void

Enqueue the next iteration

Returns

void


eventNames

eventNames(): (string | symbol)[]

List of emitter's events

Returns

(string | symbol)[]

List of emitter's events

Inherited from

EventEmitterT.eventNames


getMaxListeners

getMaxListeners(): number

Maximum number of listeners per event

Returns

number

Maximum number of listeners per event

Inherited from

EventEmitterT.getMaxListeners


init

init(procParams): Promise<boolean>

Initialize engine. Sets up processor.

The SDK access token is required parameter that authenticates the user and enables the SDK on the current url. By default, path to required wasm modules provided with SDK packages is the current url. You can change the root path to wasms passing root parameter.

Parameters

NameTypeDescription
procParamsParamsTParameters of the processor

Returns

Promise<boolean>

Status of initialization


iterate

Protected iterate(): Promise<void>

Iterate

Returns

Promise<void>


listenerCount

listenerCount<E>(event): number

The number of listeners listening to the event

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event

Returns

number

Number of listeners

Inherited from

EventEmitterT.listenerCount


listeners

listeners<E>(event): Function[]

Copy of the array of listeners for the event

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

EventEmitterT.listeners


off

off<E>(event, listener): Engine<ResultT, ParamsT, ProcessorT>

Removes the listener from the listener array for the event

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerEngineEvents[E]The callback function

Returns

Engine<ResultT, ParamsT, ProcessorT>

This EventEmitter

Inherited from

EventEmitterT.off


on

on<E>(event, listener): Engine<ResultT, ParamsT, ProcessorT>

Adds the listener function to the event

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerEngineEvents[E]The callback function

Returns

Engine<ResultT, ParamsT, ProcessorT>

This EventEmitter

Inherited from

EventEmitterT.on


once

once<E>(event, listener): Engine<ResultT, ParamsT, ProcessorT>

Adds a one-time listener function for the event

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerEngineEvents[E]The callback function

Returns

Engine<ResultT, ParamsT, ProcessorT>

This EventEmitter

Inherited from

EventEmitterT.once


pause

pause(): void

Pause pipeline.

Nothing happens if pipeline is not started yet.

Returns

void


prependListener

prependListener<E>(event, listener): Engine<ResultT, ParamsT, ProcessorT>

Adds the listener function to the beginning of the listeners array

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerEngineEvents[E]The callback function

Returns

Engine<ResultT, ParamsT, ProcessorT>

This EventEmitter

Inherited from

EventEmitterT.prependListener


prependOnceListener

prependOnceListener<E>(event, listener): Engine<ResultT, ParamsT, ProcessorT>

Adds a one-time listener function to the beginning of the listeners array

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerEngineEvents[E]The callback function

Returns

Engine<ResultT, ParamsT, ProcessorT>

Inherited from

EventEmitterT.prependOnceListener


rawListeners

rawListeners<E>(event): Function[]

Copy of the array of listeners for the event including wrappers

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

EventEmitterT.rawListeners


removeAllListeners

removeAllListeners<E>(event?): Engine<ResultT, ParamsT, ProcessorT>

Removes all listeners, or those of the specified event

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
event?EThe name of the event

Returns

Engine<ResultT, ParamsT, ProcessorT>

This EventEmitter

Inherited from

EventEmitterT.removeAllListeners


removeListener

removeListener<E>(event, listener): Engine<ResultT, ParamsT, ProcessorT>

Removes the specified listener from the listener array

Type parameters

NameType
Eextends keyof EngineEvents

Parameters

NameTypeDescription
eventEThe name of the event
listenerEngineEvents[E]The callback function

Returns

Engine<ResultT, ParamsT, ProcessorT>

This EventEmitter

Inherited from

EventEmitterT.removeListener


removeRenderer

removeRenderer(renderer): void

Remove attached Renderer

Parameters

NameTypeDescription
rendererRenderer<ResultT>Renderer to be removed

Returns

void


reset

reset(): void

Reset pipeline

Stops pipeline, resets video capture and processor. After reset one needs to reinitialize video capture calling setup() before pipeline can be started again.

Returns

void


resizeVideo

Protected resizeVideo(size): void

Callback called when video resolution is changed

Parameters

NameTypeDescription
sizeSizeSize of the video

Returns

void


setMaxListeners

setMaxListeners(n): Engine<ResultT, ParamsT, ProcessorT>

Sets maximum number of listeners per event

Parameters

NameTypeDescription
nnumberMaximum number of listeners

Returns

Engine<ResultT, ParamsT, ProcessorT>

This EventEmitter

Inherited from

EventEmitterT.setMaxListeners


setup

setup(videoParams?): Promise<boolean>

Setup engine. Initializes video capture.

Video capture can be setup by simplified VideoParams opening default front/rear camera with provided resolution, custom MediaStreamConstraints providing the most flexible way to setup video stream (e.g. set deviceId), or external MediaStream allowing custom video sources (e.g. from file).

Parameters

NameTypeDescription
videoParams?VideoSourceParamsParameters of video capture

Returns

Promise<boolean>

Status of initialization


setupProcessor

Protected setupProcessor(procParams): Promise<boolean>

Setup processor

Parameters

NameType
procParamsParamsT

Returns

Promise<boolean>


setupSize

Protected setupSize(size): Promise<void>

Setup video size

Parameters

NameType
sizeSize

Returns

Promise<void>


setupVideo

Protected setupVideo(videoParams?): Promise<boolean>

Setup video capture

Parameters

NameType
videoParams?VideoSourceParams

Returns

Promise<boolean>


start

start(): Promise<void>

Start pipeline.

Pipeline can be started only after successful init and setup.

Returns

Promise<void>