MediaStreamTrack
MediaStreamTrack of Media Capture and Streams, and the constraints of its synthetic sources.
- webrtc.interfaces.media_stream_track.CAMERA_DEVICE_ID = 'synthetic-camera'
The device ID of the synthetic camera, which feeds the video tracks of
webrtc.MediaDevices.get_user_media()
- webrtc.interfaces.media_stream_track.MICROPHONE_DEVICE_ID = 'synthetic-microphone'
The device ID of the synthetic microphone, which feeds the audio tracks of
webrtc.MediaDevices.get_user_media()
- class webrtc.interfaces.media_stream_track.MediaStreamTrack(native_obj=None)
A single audio or video track. It comes from a synthetic device or a generator, or from a remote peer.
- Events:
mute and unmute (
webrtc.Event) – The value ofmutedchanged. A remote track is muted until media arrives, and again when it’s no longer negotiated.ended (
webrtc.Event) – The track ended for a reason other thanstop(), for example because the remote peer stopped sending it.
A live track with handlers stays alive until it ends or its event loop closes.
Events
Handlers are registered with
on().- property enabled: bool
Whether the track carries its source. A disabled track carries silence or black frames.
It can still be set after the track has ended, but that has no effect.
See MDN: MediaStreamTrack/enabled.
- Type:
- property id: str
The ID of the track. A remote track gets a random UUID and doesn’t use the ID its peer gave.
- Type:
- property label: str
The label of the source. It’s empty for a generated track.
A track of
webrtc.MediaDevices.get_user_media()has the label of its device, and a remote track has'remote audio'or'remote video'. A clone keeps the label.See MDN: MediaStreamTrack/label.
- Type:
- property kind: webrtc.MediaType
Whether the track carries audio or video. It stays set after the track ends.
See MDN: MediaStreamTrack/kind.
- Type:
- property ready_state: webrtc.MediaStreamTrackState
Whether the track is
liveor hasended. Ending is final.
- property muted: bool
Whether the source can’t provide media for now. A remote track is muted until media arrives.
Unlike
enabled, the application can’t change it.See MDN: MediaStreamTrack/muted.
- Type:
- property content_hint: str
What the track carries, so encoders can optimize for it. The default is empty, for unknown.
Audio accepts
'speech','speaking'and'music'. Video accepts'motion','detail'and'text'. Other values are ignored, as are the values meant for the other kind.See MDN: MediaStreamTrack/contentHint.
- Type:
- get_settings()
Returns what the track carries now.
The settings hold the size and frame rate of the last frames seen and the format of the audio. Tracks of
webrtc.MediaDevices.get_user_media()also report the device, and its format before media flows. Members that aren’t known yet areNone.See MDN: MediaStreamTrack/getSettings.
- Returns:
webrtc.MediaTrackSettings– The settings.- Return type:
- get_capabilities()
Returns what the source of the track can do.
Only the synthetic camera and microphone of
webrtc.MediaDevices.get_user_media()have capabilities. For remote and generated tracks every member isNone.See MDN: MediaStreamTrack/getCapabilities.
- Returns:
webrtc.MediaTrackCapabilities– The capabilities.- Return type:
- get_constraints()
Returns the last constraints of
apply_constraints()orget_user_media().See MDN: MediaStreamTrack/getConstraints.
- Returns:
webrtc.MediaTrackConstraints– The constraints, none by default.- Return type:
- apply_constraints(constraints=None)
Applies constraints to the track, checking them against
get_capabilities()or the current settings.Only the synthetic camera of
webrtc.MediaDevices.get_user_media()reacts, by changing its size and frame rate. The sources of other tracks stay as they are, and the constraints are only checked and kept. On an ended track, only the numbers are checked and the constraints aren’t kept.See MDN: MediaStreamTrack/applyConstraints.
- Parameters:
constraints (
webrtc.MediaTrackConstraints, optional) – The constraints, none to remove them.- Returns:
asyncio.Future– Done once applied. It fails withwebrtc.OverconstrainedErrorif a required constraint can’t be satisfied, or withTypeErrorif a double isn’t finite. A failure leaves the track as it was.- Return type:
Future[None]
- clone()
Returns a new track with a new
id, sharing the source of this one.The clone keeps
label,enabled,content_hint, the constraints and the device, and ends if this does.See MDN: MediaStreamTrack/clone.
- Returns:
webrtc.MediaStreamTrack– The clone.- Return type:
- stop()
Stops the track and detaches it from its source.
ready_statebecomesendedwith no event.Its sender sends silence or a black frame a second; clones keep their media. See MDN: MediaStreamTrack/stop.