MediaCaptureBackend Class

The capture devices plugged into the browsing contexts (BrowsingContextOptions.MediaCapture): the cameras and the microphones of navigator.mediaDevices.getUserMedia() and enumerateDevices(), and the screen of getDisplayMedia(). The backend lists the devices and their capabilities, and produces the video frames and the audio samples of the devices it starts. The library implements Media Capture and Streams on top of it (https://w3c.github.io/mediacapture-main/): the permissions, the device identifiers, the constraint processing, the tracks and the streams.

public abstract class MediaCaptureBackend

Remarks

Without a backend (the default), there is no capture device: enumerateDevices() returns an empty list, getUserMedia() is rejected with a NotFoundError and getDisplayMedia() with a NotAllowedError.

A backend can be shared by several browsing contexts. Its methods are called on the thread of the event loop of the browsing context that uses them; MediaCaptureBackend.NotifyDevicesChanged can be called from any thread.

Constructors

NameDescription
MediaCaptureBackend()

MediaCaptureBackend()

MediaCaptureBackend.cs
protected MediaCaptureBackend()

No documentation is available.

Methods

NameDescription
GetDevices()Returns the capture devices (cameras, microphones and audio outputs). The first device of each kind is the default device of the system. The identifiers of the devices are not exposed to the documents: each origin sees its own identifiers, derived from them.
NotifyDevicesChanged()Notifies the documents that the list of devices changed (a device was plugged in or removed, or the default device changed): the documents that can see the change get a devicechange event. Can be called from any thread.
SelectDisplaySurface(DisplayCaptureRequest)Chooses the display surface to capture for getDisplayMedia() (https://w3c.github.io/mediacapture-screen-share/): a browser asks the user to pick a screen, a window or a tab. Returns null when the user cancels the request, which is rejected with a NotAllowedError. The default implementation returns null.
StartCapture(MediaCaptureRequest)Starts the capture of a device (a camera or a microphone returned by MediaCaptureBackend.GetDevices, or a display surface returned by MediaCaptureBackend.SelectDisplaySurface) with the settings selected by the constraints. The capture stops when the library disposes the source (when its last track stops). An exception fails the request with a NotReadableError (the device cannot be used, e.g. another application uses it).

GetDevices()

Returns the capture devices (cameras, microphones and audio outputs). The first device of each kind is the default device of the system. The identifiers of the devices are not exposed to the documents: each origin sees its own identifiers, derived from them.

public abstract IReadOnlyList<MediaCaptureDevice> GetDevices()

NotifyDevicesChanged()

MediaCaptureBackend.cs

Notifies the documents that the list of devices changed (a device was plugged in or removed, or the default device changed): the documents that can see the change get a devicechange event. Can be called from any thread.

protected void NotifyDevicesChanged()

SelectDisplaySurface(DisplayCaptureRequest)

MediaCaptureBackend.cs

Chooses the display surface to capture for getDisplayMedia() (https://w3c.github.io/mediacapture-screen-share/): a browser asks the user to pick a screen, a window or a tab. Returns null when the user cancels the request, which is rejected with a NotAllowedError. The default implementation returns null.

public virtual DisplayCaptureSelection? SelectDisplaySurface(DisplayCaptureRequest request)

Parameters

request DisplayCaptureRequest
The request of the document.

Returns

DisplayCaptureSelection?

StartCapture(MediaCaptureRequest)

Starts the capture of a device (a camera or a microphone returned by MediaCaptureBackend.GetDevices, or a display surface returned by MediaCaptureBackend.SelectDisplaySurface) with the settings selected by the constraints. The capture stops when the library disposes the source (when its last track stops). An exception fails the request with a NotReadableError (the device cannot be used, e.g. another application uses it).

public abstract MediaCaptureSource StartCapture(MediaCaptureRequest request)

Parameters

request MediaCaptureRequest
The device, its settings and the clock of the event loop.

Returns

MediaCaptureSource