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.
Extends
Section titled “Extends”EventEmitterT
<EngineEvents
>
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”ResultT
Section titled “ResultT”ResultT
extends object
Type of processing results
ParamsT
Section titled “ParamsT”ParamsT
extends ProcParams
Type of processor parameters
ProcessorT
Section titled “ProcessorT”ProcessorT
extends Processor
<ResultT
, ParamsT
>
Type of processor
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Engine<
ResultT
,ParamsT
,ProcessorT
>(Processor
,engineParams?
,Source?
):Engine
<ResultT
,ParamsT
,ProcessorT
>
Constructor
Parameters
Section titled “Parameters”Processor
Section titled “Processor”Processor class or instance
ProcessorT
| () => ProcessorT
engineParams?
Section titled “engineParams?”Parameters of the engine
Source?
Section titled “Source?”Video source class or instance
VideoSource
| () => VideoSource
Returns
Section titled “Returns”Engine
<ResultT
, ParamsT
, ProcessorT
>
Overrides
Section titled “Overrides”Properties
Section titled “Properties”engineParams?
Section titled “engineParams?”
protected
optional
engineParams:EngineParams
Parameters of the engine
processCanvas?
Section titled “processCanvas?”
protected
optional
processCanvas:HTMLCanvasElement
Shallow copy of canvas with video for processors
processor
Section titled “processor”
protected
processor:ProcessorT
Processor utilized by the engine
processSize
Section titled “processSize”
protected
processSize:Size
Size of video for processors
renderers
Section titled “renderers”
protected
renderers:Renderer
<ResultT
>[] =[]
Renderer attached to the engine
resizeBuffer?
Section titled “resizeBuffer?”
protected
optional
resizeBuffer:ImageBuffer
Buffer to resize frames
resizeEnabled
Section titled “resizeEnabled”
protected
resizeEnabled:boolean
=false
Original stream is resized
streamCanvas?
Section titled “streamCanvas?”
protected
optional
streamCanvas:HTMLCanvasElement
Shallow copy of canvas with video for renderers
streamSize
Section titled “streamSize”
protected
streamSize:Size
Size of video for renderers
protected
video:VideoSource
Video source instance
videoRatio
Section titled “videoRatio”
protected
videoRatio:number
Ratio of video stream
Methods
Section titled “Methods”addListener()
Section titled “addListener()”addListener<
E
>(event
,listener
):this
Adds the listener function to the end of the listeners array
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
listener
Section titled “listener”EngineEvents
[E
]
The callback function
Returns
Section titled “Returns”this
This EventEmitter
Inherited from
Section titled “Inherited from”addRenderer()
Section titled “addRenderer()”addRenderer(
renderer
):Promise
<void
>
Attach Renderer to the engine
Parameters
Section titled “Parameters”renderer
Section titled “renderer”Renderer
<ResultT
>
Object to be attached
Returns
Section titled “Returns”Promise
<void
>
emit()
Section titled “emit()”emit<
E
>(event
, …args
):boolean
Synchronously calls each of the listeners registered for the event
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
…Args
<EngineEvents
[E
]>
Arguments passed to the listeners
Returns
Section titled “Returns”boolean
True if the event had listeners, False otherwise
Inherited from
Section titled “Inherited from”enqueue()
Section titled “enqueue()”
protected
enqueue():void
Enqueue the next iteration
Returns
Section titled “Returns”void
eventNames()
Section titled “eventNames()”eventNames(): (
string
|symbol
)[]
List of emitter’s events
Returns
Section titled “Returns”(string
| symbol
)[]
List of emitter’s events
Inherited from
Section titled “Inherited from”getMaxListeners()
Section titled “getMaxListeners()”getMaxListeners():
number
Maximum number of listeners per event
Returns
Section titled “Returns”number
Maximum number of listeners per event
Inherited from
Section titled “Inherited from”init()
Section titled “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
Section titled “Parameters”procParams
Section titled “procParams”ParamsT
Parameters of the processor
Returns
Section titled “Returns”Promise
<boolean
>
Status of initialization
iterate()
Section titled “iterate()”
protected
iterate():Promise
<void
>
Iterate
Returns
Section titled “Returns”Promise
<void
>
listenerCount()
Section titled “listenerCount()”listenerCount<
E
>(event
):number
The number of listeners listening to the event
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
Returns
Section titled “Returns”number
Number of listeners
Inherited from
Section titled “Inherited from”listeners()
Section titled “listeners()”listeners<
E
>(event
):Function
[]
Copy of the array of listeners for the event
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
Returns
Section titled “Returns”Function
[]
Copy of the listeners array
Inherited from
Section titled “Inherited from”off<
E
>(event
,listener
):this
Removes the listener from the listener array for the event
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
listener
Section titled “listener”EngineEvents
[E
]
The callback function
Returns
Section titled “Returns”this
This EventEmitter
Inherited from
Section titled “Inherited from”on<
E
>(event
,listener
):this
Adds the listener function to the event
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
listener
Section titled “listener”EngineEvents
[E
]
The callback function
Returns
Section titled “Returns”this
This EventEmitter
Inherited from
Section titled “Inherited from”once()
Section titled “once()”once<
E
>(event
,listener
):this
Adds a one-time listener function for the event
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
listener
Section titled “listener”EngineEvents
[E
]
The callback function
Returns
Section titled “Returns”this
This EventEmitter
Inherited from
Section titled “Inherited from”pause()
Section titled “pause()”pause():
void
Pause pipeline.
Nothing happens if pipeline is not started yet.
Returns
Section titled “Returns”void
prependListener()
Section titled “prependListener()”prependListener<
E
>(event
,listener
):this
Adds the listener function to the beginning of the listeners array
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
listener
Section titled “listener”EngineEvents
[E
]
The callback function
Returns
Section titled “Returns”this
This EventEmitter
Inherited from
Section titled “Inherited from”prependOnceListener()
Section titled “prependOnceListener()”prependOnceListener<
E
>(event
,listener
):this
Adds a one-time listener function to the beginning of the listeners array
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
listener
Section titled “listener”EngineEvents
[E
]
The callback function
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”EventEmitterT
.prependOnceListener
rawListeners()
Section titled “rawListeners()”rawListeners<
E
>(event
):Function
[]
Copy of the array of listeners for the event including wrappers
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
Returns
Section titled “Returns”Function
[]
Copy of the listeners array
Inherited from
Section titled “Inherited from”removeAllListeners()
Section titled “removeAllListeners()”removeAllListeners<
E
>(event?
):this
Removes all listeners, or those of the specified event
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”event?
Section titled “event?”E
The name of the event
Returns
Section titled “Returns”this
This EventEmitter
Inherited from
Section titled “Inherited from”EventEmitterT
.removeAllListeners
removeListener()
Section titled “removeListener()”removeListener<
E
>(event
,listener
):this
Removes the specified listener from the listener array
Type Parameters
Section titled “Type Parameters”E
extends keyof EngineEvents
Parameters
Section titled “Parameters”E
The name of the event
listener
Section titled “listener”EngineEvents
[E
]
The callback function
Returns
Section titled “Returns”this
This EventEmitter
Inherited from
Section titled “Inherited from”removeRenderer()
Section titled “removeRenderer()”removeRenderer(
renderer
):void
Remove attached Renderer
Parameters
Section titled “Parameters”renderer
Section titled “renderer”Renderer
<ResultT
>
Renderer to be removed
Returns
Section titled “Returns”void
reset()
Section titled “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
Section titled “Returns”void
resizeVideo()
Section titled “resizeVideo()”
protected
resizeVideo(size
):void
Callback called when video resolution is changed
Parameters
Section titled “Parameters”Size of the video
Returns
Section titled “Returns”void
setMaxListeners()
Section titled “setMaxListeners()”setMaxListeners(
n
):this
Sets maximum number of listeners per event
Parameters
Section titled “Parameters”number
Maximum number of listeners
Returns
Section titled “Returns”this
This EventEmitter
Inherited from
Section titled “Inherited from”setup()
Section titled “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.
Additional fine-grained MediaStreamConstraints can be passed
via opts
field providing the most flexible way to setup
video stream (for example, by requesting specific deviceId).
Stream constraints have higher priority than rest or params.
Another options are an external MediaStream allowing custom
video sources (e.g. remote stream) or a media file defined
by url or FileParams that allows to limit maximum
capture size in cases resolution is too big for a device.
Parameters
Section titled “Parameters”videoParams?
Section titled “videoParams?”Parameters of video capture
Returns
Section titled “Returns”Promise
<boolean
>
Status of initialization
setupProcessor()
Section titled “setupProcessor()”
protected
setupProcessor(procParams
):Promise
<boolean
>
Setup processor
Parameters
Section titled “Parameters”procParams
Section titled “procParams”ParamsT
Returns
Section titled “Returns”Promise
<boolean
>
setupSize()
Section titled “setupSize()”
protected
setupSize(size
):Promise
<void
>
Setup video size
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise
<void
>
setupVideo()
Section titled “setupVideo()”
protected
setupVideo(videoParams?
):Promise
<boolean
>
Setup video capture
Parameters
Section titled “Parameters”videoParams?
Section titled “videoParams?”Returns
Section titled “Returns”Promise
<boolean
>
start()
Section titled “start()”start():
Promise
<void
>
Start pipeline.
Pipeline can be started only after successful init and setup.
Returns
Section titled “Returns”Promise
<void
>