Skip to main content

Class: VideoSource

@geenee/armature.VideoSource

Video source

General class of video capture objects providing functionality to grab images from various sources. It implements basic interfaces like setup, start, stop of the video capture, and grabbing of frames. Internally utilizes ImageBuffer as storages.

Hierarchy

Constructors

constructor

new VideoSource()

Constructor

Overrides

EventEmitterT.constructor

Properties

buffer

buffer: ImageBuffer

Context of original stream


captureTime

captureTime: number = 0

Timestamp of the last captured frame


sizeMax

Protected Optional sizeMax: number

Maximum capture resolutions


timer

Private Optional timer: number

Timer to emulate timestamps

Methods

addListener

addListener<E>(event, listener): VideoSource

Adds the listener function to the end of the listeners array

Type parameters

NameType
Eextends "resize"

Parameters

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

Returns

VideoSource

This EventEmitter

Inherited from

EventEmitterT.addListener


capture

capture(): boolean

Grab the next video frame

VideoSource grabs the static image permanently stored in embedded ImageBuffer object.

Returns

boolean

True if next frame was available and grabbed


dispose

dispose(): void

Dispose video source object

Returns

void


emit

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

Synchronously calls each of the listeners registered for the event

Type parameters

NameType
Eextends "resize"

Parameters

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

Returns

boolean

True if the event had listeners, False otherwise

Inherited from

EventEmitterT.emit


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


listenerCount

listenerCount<E>(event): number

The number of listeners listening to the event

Type parameters

NameType
Eextends "resize"

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 "resize"

Parameters

NameTypeDescription
eventEThe name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

EventEmitterT.listeners


off

off<E>(event, listener): VideoSource

Removes the listener from the listener array for the event

Type parameters

NameType
Eextends "resize"

Parameters

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

Returns

VideoSource

This EventEmitter

Inherited from

EventEmitterT.off


on

on<E>(event, listener): VideoSource

Adds the listener function to the event

Type parameters

NameType
Eextends "resize"

Parameters

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

Returns

VideoSource

This EventEmitter

Inherited from

EventEmitterT.on


once

once<E>(event, listener): VideoSource

Adds a one-time listener function for the event

Type parameters

NameType
Eextends "resize"

Parameters

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

Returns

VideoSource

This EventEmitter

Inherited from

EventEmitterT.once


pause

pause(): void

Pause video capture

Returns

void


prependListener

prependListener<E>(event, listener): VideoSource

Adds the listener function to the beginning of the listeners array

Type parameters

NameType
Eextends "resize"

Parameters

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

Returns

VideoSource

This EventEmitter

Inherited from

EventEmitterT.prependListener


prependOnceListener

prependOnceListener<E>(event, listener): VideoSource

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

Type parameters

NameType
Eextends "resize"

Parameters

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

Returns

VideoSource

Inherited from

EventEmitterT.prependOnceListener


ratio

ratio(): number

Aspect ratio of the video stream

Returns

number

Aspect ratio of the video stream


rawListeners

rawListeners<E>(event): Function[]

Copy of the array of listeners for the event including wrappers

Type parameters

NameType
Eextends "resize"

Parameters

NameTypeDescription
eventEThe name of the event

Returns

Function[]

Copy of the listeners array

Inherited from

EventEmitterT.rawListeners


removeAllListeners

removeAllListeners<E>(event?): VideoSource

Removes all listeners, or those of the specified event

Type parameters

NameType
Eextends "resize"

Parameters

NameTypeDescription
event?EThe name of the event

Returns

VideoSource

This EventEmitter

Inherited from

EventEmitterT.removeAllListeners


removeListener

removeListener<E>(event, listener): VideoSource

Removes the specified listener from the listener array

Type parameters

NameType
Eextends "resize"

Parameters

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

Returns

VideoSource

This EventEmitter

Inherited from

EventEmitterT.removeListener


reset

reset(): void

Reset video capture

After reset() capture may be started again only after setup().

Returns

void


setMaxListeners

setMaxListeners(n): VideoSource

Sets maximum number of listeners per event

Parameters

NameTypeDescription
nnumberMaximum number of listeners

Returns

VideoSource

This EventEmitter

Inherited from

EventEmitterT.setMaxListeners


setup

setup(params?): Promise<boolean>

Setup video source

Sets up capture, overridden for particular video source. Video source 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). Video source can also be a media file provided by url or FileParams that additionally allows to set maximum capture size in cases resolution is too big for a device. Default implementation sets video resolution according to size in VideoParams or 1920x1080 as the fallback. It captures static image, canvas is filled by white color.

Parameters

NameTypeDescription
params?VideoSourceParamsParameters of video capture

Returns

Promise<boolean>

Promise resolved to the status of setup when done


size

size(): Size

Resolution of the video stream

Returns

Size

Resolution of the video stream


start

start(): Promise<void>

Start video capture

Video capture can be started only after successful setup().

Returns

Promise<void>

Promise resolved when capture is started


updateSize

Protected updateSize(size): void

Update callback on video resize

Parameters

NameTypeDescription
sizeSizeNew size of the video stream

Returns

void