Class: AsyncEngine<ResultT, ParamsT, ProcessorT>
@geenee/armature.AsyncEngine
Generic asynchronous engine
AsyncEngine is extension of the Engine that does processing in the background. Its pipeline provides for better performance and more stable frames per second. By using async engine you can achieve smoother and faster experience. AsyncEngine and Engine are compatible, you can use any of them without additional code adjustments.
Type parameters
Name | Type | Description |
---|---|---|
ResultT | extends Object | Type of processing results |
ParamsT | extends ProcParams | Type of processor parameters |
ProcessorT | extends Processor <ResultT , ParamsT > | Type of processor |
Hierarchy
Engine
<ResultT
,ParamsT
,ProcessorT
>↳
AsyncEngine
Constructors
constructor
• new AsyncEngine<ResultT
, ParamsT
, ProcessorT
>(Processor
, engineParams?
, Source?
)
Constructor
Type parameters
Name | Type | Description |
---|---|---|
ResultT | extends Object | Type of processing results |
ParamsT | extends ProcParams | Type of processor parameters |
ProcessorT | extends Processor <ResultT , ParamsT , ProcessorT > | Type of processor |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
Processor | () => ProcessorT | undefined | Processor class or its constructor |
engineParams? | EngineParams | undefined | Parameters of the engine |
Source | () => VideoSource | VideoCapture | Video source class or its constructor |
Inherited from
Properties
engineParams
• Protected
Optional
engineParams: EngineParams
Inherited from
processCanvas
• Protected
Optional
processCanvas: HTMLCanvasElement
Shallow copy of canvas with video for processors
Inherited from
processSize
• Protected
processSize: Size
Size of video for processors
Inherited from
processor
• Protected
processor: ProcessorT
Processor utilized by the engine
Inherited from
renderers
• Protected
renderers: Renderer
<ResultT
>[] = []
Renderer attached to the engine
Inherited from
resizeBuffer
• Protected
Optional
resizeBuffer: ImageBuffer
Buffer to resize frames
Inherited from
resizeEnabled
• Protected
resizeEnabled: boolean
= false
Original stream is resized
Inherited from
streamCanvas
• Protected
Optional
streamCanvas: HTMLCanvasElement
Shallow copy of canvas with video for renderers
Inherited from
streamSize
• Protected
streamSize: Size
Size of video for renderers
Inherited from
video
• Protected
video: VideoSource
Video source instance
Inherited from
videoRatio
• Protected
videoRatio: number
Ratio of video stream
Inherited from
Methods
addListener
▸ addListener<E
>(event
, listener
): AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Adds the listener function to the end of the listeners array
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | EngineEvents [E ] | The callback function |
Returns
AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
This EventEmitter
Inherited from
addRenderer
▸ addRenderer(renderer
): Promise
<void
>
Attach Renderer to the engine
Parameters
Name | Type | Description |
---|---|---|
renderer | Renderer <ResultT > | Object to be attached |
Returns
Promise
<void
>
Inherited from
emit
▸ emit<E
>(event
, ...args
): boolean
Synchronously calls each of the listeners registered for the event
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
...args | Args <EngineEvents [E ]> | Arguments passed to the listeners |
Returns
boolean
True if the event had listeners, False otherwise
Inherited from
enqueue
▸ Protected
enqueue(): void
Enqueue the next iteration
Returns
void
Inherited from
eventNames
▸ eventNames(): (string
| symbol
)[]
List of emitter's events
Returns
(string
| symbol
)[]
List of emitter's events
Inherited from
getMaxListeners
▸ getMaxListeners(): number
Maximum number of listeners per event
Returns
number
Maximum number of listeners per event
Inherited from
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
Name | Type |
---|---|
procParams | ParamsT |
Returns
Promise
<boolean
>
Status of initialization
Inherited from
iterate
▸ Protected
iterate(): Promise
<void
>
Iterate
Overridden for asynchronous processing.
Returns
Promise
<void
>
Overrides
listenerCount
▸ listenerCount<E
>(event
): number
The number of listeners listening to the event
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
Returns
number
Number of listeners
Inherited from
listeners
▸ listeners<E
>(event
): Function
[]
Copy of the array of listeners for the event
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
Returns
Function
[]
Copy of the listeners array
Inherited from
off
▸ off<E
>(event
, listener
): AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Removes the listener from the listener array for the event
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | EngineEvents [E ] | The callback function |
Returns
AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
This EventEmitter
Inherited from
on
▸ on<E
>(event
, listener
): AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Adds the listener function to the event
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | EngineEvents [E ] | The callback function |
Returns
AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
This EventEmitter
Inherited from
once
▸ once<E
>(event
, listener
): AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Adds a one-time listener function for the event
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | EngineEvents [E ] | The callback function |
Returns
AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
This EventEmitter
Inherited from
pause
▸ pause(): void
Pause pipeline.
Nothing happens if pipeline is not started yet.
Returns
void
Inherited from
prependListener
▸ prependListener<E
>(event
, listener
): AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Adds the listener function to the beginning of the listeners array
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | EngineEvents [E ] | The callback function |
Returns
AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
This EventEmitter
Inherited from
prependOnceListener
▸ prependOnceListener<E
>(event
, listener
): AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Adds a one-time listener function to the beginning of the listeners array
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | EngineEvents [E ] | The callback function |
Returns
AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Inherited from
rawListeners
▸ rawListeners<E
>(event
): Function
[]
Copy of the array of listeners for the event including wrappers
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
Returns
Function
[]
Copy of the listeners array
Inherited from
removeAllListeners
▸ removeAllListeners<E
>(event?
): AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Removes all listeners, or those of the specified event
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event? | E | The name of the event |
Returns
AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
This EventEmitter
Inherited from
removeListener
▸ removeListener<E
>(event
, listener
): AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Removes the specified listener from the listener array
Type parameters
Name | Type |
---|---|
E | extends keyof EngineEvents |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event |
listener | EngineEvents [E ] | The callback function |
Returns
AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
This EventEmitter
Inherited from
removeRenderer
▸ removeRenderer(renderer
): void
Remove attached Renderer
Parameters
Name | Type | Description |
---|---|---|
renderer | Renderer <ResultT > | Renderer to be removed |
Returns
void
Inherited from
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
Inherited from
resizeVideo
▸ Protected
resizeVideo(size
): void
Callback called when video resolution is changed
Parameters
Name | Type | Description |
---|---|---|
size | Size | Size of the video |
Returns
void
Inherited from
setMaxListeners
▸ setMaxListeners(n
): AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
Sets maximum number of listeners per event
Parameters
Name | Type | Description |
---|---|---|
n | number | Maximum number of listeners |
Returns
AsyncEngine
<ResultT
, ParamsT
, ProcessorT
>
This EventEmitter
Inherited from
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
Name | Type | Description |
---|---|---|
videoParams? | VideoSourceParams | Parameters of video capture |
Returns
Promise
<boolean
>
Status of initialization
Inherited from
setupProcessor
▸ Protected
setupProcessor(procParams
): Promise
<boolean
>
Setup processor
Parameters
Name | Type |
---|---|
procParams | ParamsT |
Returns
Promise
<boolean
>
Inherited from
setupSize
▸ Protected
setupSize(size
): Promise
<void
>
Setup video size
Parameters
Name | Type |
---|---|
size | Size |
Returns
Promise
<void
>
Inherited from
setupVideo
▸ Protected
setupVideo(videoParams?
): Promise
<boolean
>
Setup video capture
Parameters
Name | Type |
---|---|
videoParams? | VideoSourceParams |
Returns
Promise
<boolean
>
Inherited from
start
▸ start(): Promise
<void
>
Start pipeline.
Pipeline can be started only after successful init and setup.
Returns
Promise
<void
>