Track constraints

Settings, capabilities and constraints of tracks.

See MDN: Media_Capture_and_Streams_API/Constraints.

class webrtc.models.media_track_constraints.ULongRange(min=None, max=None)

A range of integers a source supports, in MediaTrackCapabilities.

Parameters:
  • min (int, optional) – The lowest value, inclusive.

  • max (int, optional) – The highest value, inclusive.

class webrtc.models.media_track_constraints.DoubleRange(min=None, max=None)

A range of numbers a source supports, in MediaTrackCapabilities.

Parameters:
  • min (float, optional) – The lowest value, inclusive.

  • max (float, optional) – The highest value, inclusive.

class webrtc.models.media_track_constraints.ConstrainULongRange(min=None, max=None, exact=None, ideal=None)

A constraint on an integer, with required bounds or a required value, and a preferred value.

The required members fail the constraints when the source’s range doesn’t allow them.

Parameters:
  • min (int, optional) – The lowest value allowed, as a requirement.

  • max (int, optional) – The highest value allowed, as a requirement.

  • exact (int, optional) – The only value allowed, as a requirement.

  • ideal (int, optional) – The value to get as near as possible to. It never fails the constraints.

class webrtc.models.media_track_constraints.ConstrainDoubleRange(min=None, max=None, exact=None, ideal=None)

A constraint on a number, with required bounds or a required value, and a preferred value.

The required members fail the constraints when the source’s range doesn’t allow them.

Parameters:
  • min (float, optional) – The lowest value allowed, as a requirement.

  • max (float, optional) – The highest value allowed, as a requirement.

  • exact (float, optional) – The only value allowed, as a requirement.

  • ideal (float, optional) – The value to get as near as possible to. It never fails the constraints.

class webrtc.models.media_track_constraints.ConstrainBooleanParameters(exact=None, ideal=None)

A constraint on a boolean, with a required value or a preferred one.

Parameters:
  • exact (bool, optional) – The only value allowed, as a requirement.

  • ideal (bool, optional) – The value to get if possible. It never fails the constraints.

class webrtc.models.media_track_constraints.ConstrainDOMStringParameters(exact=None, ideal=None)

A constraint on a string, with required values or preferred ones.

Parameters:
  • exact (str or list of str, optional) – The value or values allowed, as a requirement.

  • ideal (str or list of str, optional) – The value or values to get if possible. They never fail the constraints.

class webrtc.models.media_track_constraints.ConstrainBooleanOrDOMStringParameters(exact=None, ideal=None)

A constraint on a boolean or a string, with a required value or a preferred one.

Parameters:
  • exact (bool or str, optional) – The only value allowed, as a requirement.

  • ideal (bool or str, optional) – The value to get if possible. It never fails the constraints.

webrtc.models.media_track_constraints.ConstrainULong

A constraint on an integer, where a bare value is an ideal one

alias of int | ConstrainULongRange

webrtc.models.media_track_constraints.ConstrainDouble

A constraint on a number, where a bare value is an ideal one

alias of float | ConstrainDoubleRange

webrtc.models.media_track_constraints.ConstrainBoolean

A constraint on a boolean, where a bare value is an ideal one

alias of bool | ConstrainBooleanParameters

webrtc.models.media_track_constraints.ConstrainDOMString

A constraint on a string, where a bare string or a list of them is ideal

alias of str | list[str] | ConstrainDOMStringParameters

webrtc.models.media_track_constraints.ConstrainBooleanOrDOMString

A constraint on a boolean or a string, where a bare value is an ideal one

alias of bool | str | ConstrainBooleanOrDOMStringParameters

class webrtc.models.media_track_constraints.MediaTrackSupportedConstraints(width=True, height=True, aspect_ratio=True, frame_rate=True, facing_mode=True, resize_mode=True, sample_rate=True, sample_size=True, echo_cancellation=True, auto_gain_control=True, noise_suppression=True, latency=True, channel_count=True, device_id=True, group_id=True, background_blur=True, voice_isolation=True)

The constraints the library recognizes, as webrtc.MediaDevices.get_supported_constraints() returns.

Every member is True. A recognized constraint that the source has no capability or setting for (like facing_mode on the synthetic camera) is ignored when ideal and fails when required.

See MDN: MediaDevices/getSupportedConstraints.

Parameters:
  • width (bool, optional) – Whether width is recognized.

  • height (bool, optional) – Whether height is recognized.

  • aspect_ratio (bool, optional) – Whether aspect_ratio is recognized.

  • frame_rate (bool, optional) – Whether frame_rate is recognized.

  • facing_mode (bool, optional) – Whether facing_mode is recognized.

  • resize_mode (bool, optional) – Whether resize_mode is recognized.

  • sample_rate (bool, optional) – Whether sample_rate is recognized.

  • sample_size (bool, optional) – Whether sample_size is recognized.

  • echo_cancellation (bool, optional) – Whether echo_cancellation is recognized.

  • auto_gain_control (bool, optional) – Whether auto_gain_control is recognized.

  • noise_suppression (bool, optional) – Whether noise_suppression is recognized.

  • latency (bool, optional) – Whether latency is recognized.

  • channel_count (bool, optional) – Whether channel_count is recognized.

  • device_id (bool, optional) – Whether device_id is recognized.

  • group_id (bool, optional) – Whether group_id is recognized.

  • background_blur (bool, optional) – Whether background_blur is recognized.

  • voice_isolation (bool, optional) – Whether voice_isolation is recognized.

class webrtc.models.media_track_constraints.MediaTrackSettings(width=None, height=None, aspect_ratio=None, frame_rate=None, resize_mode=None, device_id=None, group_id=None, sample_rate=None, sample_size=None, channel_count=None, echo_cancellation=None, auto_gain_control=None, noise_suppression=None, facing_mode=None, latency=None, background_blur=None, voice_isolation=None)

What a track carries now, as webrtc.MediaStreamTrack.get_settings() returns.

Members are None when they don’t apply to the track or aren’t known yet. The library never fills facing_mode or background_blur.

See MDN: MediaTrackSettings.

Parameters:
  • width (int, optional) – The width of the video.

  • height (int, optional) – The height of the video.

  • aspect_ratio (float, optional) – The width divided by the height.

  • frame_rate (float, optional) – The frames per second: a camera’s selected one, otherwise measured over the last frames.

  • resize_mode (str, optional) – How the source is resized. It’s 'none' for the synthetic camera.

  • device_id (str, optional) – The device of a track of webrtc.MediaDevices.get_user_media().

  • group_id (str, optional) – The group ID of the device.

  • sample_rate (int, optional) – The samples per second of the audio.

  • sample_size (int, optional) – The bits per sample of the audio.

  • channel_count (int, optional) – The channels of the audio.

  • echo_cancellation (bool or str, optional) – Whether echo is cancelled. It’s False for the synthetic microphone.

  • auto_gain_control (bool, optional) – Whether the gain is controlled automatically.

  • noise_suppression (bool, optional) – Whether noise is suppressed.

  • facing_mode (str, optional) – Where the camera faces, like 'user'.

  • latency (float, optional) – The latency of the audio in seconds.

  • background_blur (bool, optional) – Whether the background is blurred.

  • voice_isolation (bool, optional) – Whether voices are isolated from other sounds.

class webrtc.models.media_track_constraints.MediaTrackCapabilities(width=None, height=None, aspect_ratio=None, frame_rate=None, resize_mode=None, device_id=None, group_id=None, sample_rate=None, sample_size=None, channel_count=None, echo_cancellation=None, auto_gain_control=None, noise_suppression=None, facing_mode=None, latency=None, background_blur=None, voice_isolation=None)

What the source of a track can do, as webrtc.MediaStreamTrack.get_capabilities() returns.

Only the synthetic camera and microphone of webrtc.MediaDevices.get_user_media() have capabilities. The camera supports 1 to 4096 pixels each way at 1 to 120 frames per second, and faces no known way. The microphone is 48 kHz 16-bit mono in 10 ms frames, with no processing. For other tracks every member is None, because the library doesn’t control their source.

See MDN: MediaStreamTrack/getCapabilities.

Parameters:
  • width (ULongRange, optional) – The widths of the video.

  • height (ULongRange, optional) – The heights of the video.

  • aspect_ratio (DoubleRange, optional) – The aspect ratios of the video.

  • frame_rate (DoubleRange, optional) – The frame rates of the video.

  • resize_mode (list of str, optional) – The ways the source can be resized.

  • device_id (str, optional) – The device of the track.

  • group_id (str, optional) – The group ID of the device.

  • sample_rate (ULongRange, optional) – The sample rates of the audio.

  • sample_size (ULongRange, optional) – The bits per sample of the audio.

  • channel_count (ULongRange, optional) – The channels of the audio.

  • echo_cancellation (list of bool or str, optional) – Whether echo can be cancelled.

  • auto_gain_control (list of bool, optional) – Whether the gain can be controlled.

  • noise_suppression (list of bool, optional) – Whether noise can be suppressed.

  • facing_mode (list of str, optional) – Where the camera can face.

  • latency (DoubleRange, optional) – The latencies of the audio in seconds.

  • background_blur (list of bool, optional) – Whether the background can be blurred.

  • voice_isolation (list of bool, optional) – Whether voices can be isolated.

class webrtc.models.media_track_constraints.MediaTrackConstraintSet(width=None, height=None, aspect_ratio=None, frame_rate=None, resize_mode=None, device_id=None, group_id=None, sample_rate=None, sample_size=None, channel_count=None, echo_cancellation=None, auto_gain_control=None, noise_suppression=None, facing_mode=None, latency=None, background_blur=None, voice_isolation=None)

A set of constraints on a track. It’s the base of MediaTrackConstraints and of its advanced sets.

Each member is either a bare value, which is ideal, or a constraint object with exact, ideal, min and max. The required parts fail the constraints if the source can’t satisfy them, but the ideal ones never do.

Parameters:
class webrtc.models.media_track_constraints.MediaTrackConstraints(width=None, height=None, aspect_ratio=None, frame_rate=None, resize_mode=None, device_id=None, group_id=None, sample_rate=None, sample_size=None, channel_count=None, echo_cancellation=None, auto_gain_control=None, noise_suppression=None, facing_mode=None, latency=None, background_blur=None, voice_isolation=None, advanced=None)

The constraints of a track, as given to webrtc.MediaStreamTrack.apply_constraints().

They’re also given per track to webrtc.MediaDevices.get_user_media(). The members are the ones of MediaTrackConstraintSet, plus advanced.

See MDN: MediaTrackConstraints.

Parameters:

advanced (list of MediaTrackConstraintSet, optional) – More sets to try in order after the basic one. A set is applied only if all of it can be satisfied. A set that can’t be satisfied is skipped and doesn’t fail the constraints.

class webrtc.models.media_track_constraints.MediaStreamConstraints(video=False, audio=False)

Which tracks webrtc.MediaDevices.get_user_media() returns, and their constraints.

At least one of the two must be requested. See MDN: MediaDevices/getUserMedia.

Parameters: