MediaStreamTrackProcessor Class

Reads the media of a track as a stream (https://w3c.github.io/mediacapture-transform/#track-processor): the readable stream of the scripts gives a VideoFrame for each frame of a video track, or an AudioData for each block of samples of an audio track. The frames that arrive while no read is pending are buffered (MediaStreamTrackProcessorInit.MaxBufferSize, 1 by default): the oldest one is closed and discarded when the buffer is full. The stream is closed when the track ends.

public sealed class MediaStreamTrackProcessor

Remarks

The specification exposes the interface in the dedicated workers only; it is also exposed in the windows, with the constructor that takes a track (the legacy API of Chromium, https://github.com/w3c/mediacapture-transform/blob/main/explainer.md#mediastreamtrackprocessor). The frames of a source that produces them (a VideoTrackGenerator, a track transferred from another thread) are read as they arrive; the other sources (a camera, a canvas, a media element...) are sampled on the clock of the event loop, at the frame rate of the track (30 frames per second when it has none), and by blocks of 10 ms for the audio.

See also

Constructors

NameDescription
MediaStreamTrackProcessor(MediaStreamTrack, ushort?)Creates a processor of a track (the legacy constructor of Chromium).
MediaStreamTrackProcessor(MediaStreamTrackProcessorInit)Creates a processor of a track (https://w3c.github.io/mediacapture-transform/#dom-mediastreamtrackprocessor-mediastreamtrackprocessor).

MediaStreamTrackProcessor overloads

MediaStreamTrackProcessor(MediaStreamTrack, ushort?)

InsertableStreams.cs

Creates a processor of a track (the legacy constructor of Chromium).

public MediaStreamTrackProcessor(MediaStreamTrack track, ushort? maxBufferSize = null)
Parameters
track MediaStreamTrack
The track to read.
maxBufferSize ushort?
The number of frames buffered while no read is pending (1 by default).
Exceptions
TypeErrorException
The track is ended or transferred.
See also

MediaStreamTrackProcessor(MediaStreamTrackProcessorInit)

InsertableStreams.cs

Creates a processor of a track (https://w3c.github.io/mediacapture-transform/#dom-mediastreamtrackprocessor-mediastreamtrackprocessor).

public MediaStreamTrackProcessor(MediaStreamTrackProcessorInit init)
Parameters
init MediaStreamTrackProcessorInit
The track and the size of the buffer.
Exceptions
TypeErrorException
The track is not a track or a handle, or it is ended or transferred.
See also

Properties

NameDescription
DiscardedFramesGets the number of frames discarded because the buffer was full.
ReadableGets the ReadableStream of the frames (an object of the realm of the scripts: the frames are read by the scripts).
TotalFramesGets the number of frames received from the track (including the discarded ones).

DiscardedFrames

InsertableStreams.cs

Gets the number of frames discarded because the buffer was full.

public ulong DiscardedFrames { get; }

Gets the ReadableStream of the frames (an object of the realm of the scripts: the frames are read by the scripts).

public object Readable { get; }

Gets the number of frames received from the track (including the discarded ones).

public ulong TotalFrames { get; }