# RTCRtpSender

The sender that encodes and sends the media of a track.

### *class* webrtc.interfaces.rtc_rtp_sender.RTCRtpSender(native_obj=None)

Encodes the media of a track and sends it to the remote peer, and controls how it’s sent.

Each [`webrtc.RTCRtpTransceiver`](rtc_rtp_transceiver.md#webrtc.interfaces.rtc_rtp_transceiver.RTCRtpTransceiver) of an [`webrtc.RTCPeerConnection`](rtc_peer_connection.md#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection) has one.

See [MDN: RTCRtpSender](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender).

#### *property* track *: [MediaStreamTrack](media_stream_track.md#webrtc.interfaces.media_stream_track.MediaStreamTrack) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The track being sent, or [`None`](https://docs.python.org/3/builtins/constants.html#None) if nothing is.

Change it with [`replace_track()`](#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender.replace_track).

See [MDN: RTCRtpSender/track](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/track).

* **Type:**
  [`webrtc.MediaStreamTrack`](media_stream_track.md#webrtc.interfaces.media_stream_track.MediaStreamTrack), optional

#### *property* transport *: [RTCDtlsTransport](rtc_dtls_transport.md#webrtc.interfaces.rtc_dtls_transport.RTCDtlsTransport) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The transport the packets go over.

It’s [`None`](https://docs.python.org/3/builtins/constants.html#None) until there’s one.
See [MDN: RTCRtpSender/transport](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/transport).

* **Type:**
  [`webrtc.RTCDtlsTransport`](rtc_dtls_transport.md#webrtc.interfaces.rtc_dtls_transport.RTCDtlsTransport), optional

#### *property* dtmf *: [RTCDTMFSender](rtc_dtmf_sender.md#webrtc.interfaces.rtc_dtmf_sender.RTCDTMFSender) | [None](https://docs.python.org/3/builtins/constants.html#None)*

Sends DTMF tones, or is [`None`](https://docs.python.org/3/builtins/constants.html#None) for a video sender.

See [MDN: RTCRtpSender/dtmf](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/dtmf).

* **Type:**
  [`webrtc.RTCDTMFSender`](rtc_dtmf_sender.md#webrtc.interfaces.rtc_dtmf_sender.RTCDTMFSender), optional

#### *property* transform *: [RTCRtpScriptTransform](rtc_rtp_script_transform.md#webrtc.interfaces.rtc_rtp_script_transform.RTCRtpScriptTransform) | [RTCRtpSFrameEncryptor](sframe_transform.md#webrtc.interfaces.sframe_transform.RTCRtpSFrameEncryptor) | [None](https://docs.python.org/3/builtins/constants.html#None)*

The frame transform.

It changes the encoded frames before they’re sent. With [`None`](https://docs.python.org/3/builtins/constants.html#None), frames are sent as encoded.
A transform serves one sender or receiver for its lifetime, so once attached it can’t be set elsewhere.
Setting the first transform on a video sender that is already sending restarts its encoder (a short glitch and
a key frame); set it before negotiation to avoid that.

See [MDN: RTCRtpSender/transform](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/transform).

* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the value set isn’t a transform of a sender.
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the transform set had a sender or receiver.
* **Type:**
  [`webrtc.RTCRtpScriptTransform`](rtc_rtp_script_transform.md#webrtc.interfaces.rtc_rtp_script_transform.RTCRtpScriptTransform) or [`webrtc.RTCRtpSFrameEncryptor`](sframe_transform.md#webrtc.interfaces.sframe_transform.RTCRtpSFrameEncryptor), optional

#### get_parameters()

Returns the parameters the sender sends with.

To change them, modify the result and pass it to [`set_parameters()`](#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender.set_parameters), which takes the last ones returned
until it succeeds. A later task of the event loop gets new ones. Video encodings without
`scale_resolution_down_by` get the effective value filled in.

See [MDN: RTCRtpSender/getParameters](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/getParameters).

* **Returns:**
  [`webrtc.RTCRtpSendParameters`](../models/rtp_parameters.md#webrtc.models.rtp_parameters.RTCRtpSendParameters) – The parameters, with a new `transaction_id`.
* **Return type:**
  [*RTCRtpSendParameters*](../models/rtp_parameters.md#webrtc.models.rtp_parameters.RTCRtpSendParameters)

#### *async* set_parameters(parameters, set_parameter_options=None)

Changes the encodings and the degradation preference the sender sends with.

See [MDN: RTCRtpSender/setParameters](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/setParameters).

* **Parameters:**
  * **parameters** ([`webrtc.RTCRtpSendParameters`](../models/rtp_parameters.md#webrtc.models.rtp_parameters.RTCRtpSendParameters)) – The parameters [`get_parameters()`](#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender.get_parameters) returned last,
    with the changes made.
  * **set_parameter_options** ([`webrtc.RTCSetParameterOptions`](../models/rtp_parameters.md#webrtc.models.rtp_parameters.RTCSetParameterOptions), optional) – How to change the encodings,
    like sending a key frame right away.
* **Raises:**
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If [`get_parameters()`](#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender.get_parameters) wasn’t called since parameters were last set, or the
        transceiver of the sender is stopped.
  * [**webrtc.InvalidModificationError**](../exceptions.md#webrtc.exceptions.InvalidModificationError) – If the `transaction_id`, the codecs, the header extensions,
        the RTCP parameters, the number of encodings or their `rid` changed, the codec of an encoding
        isn’t negotiated, or `encoding_options` isn’t empty or one per encoding.
  * [**webrtc.InvalidRangeError**](../exceptions.md#webrtc.exceptions.InvalidRangeError) – If a value is out of range, like `scale_resolution_down_by` below 1.
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If `max_bitrate` isn’t an unsigned 32-bit integer, or a video value isn’t a finite number.

#### *async* replace_track(with_track)

Replaces the track the sender sends, without renegotiating.

It runs in the operations chain of the connection, after the operations queued before it (like setting a
description), and never before the calling code continues.

See [MDN: RTCRtpSender/replaceTrack](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/replaceTrack).

* **Parameters:**
  **with_track** ([`webrtc.MediaStreamTrack`](media_stream_track.md#webrtc.interfaces.media_stream_track.MediaStreamTrack), optional) – The new track of the same kind, or [`None`](https://docs.python.org/3/builtins/constants.html#None)
  to stop sending.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the track is of another kind.
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the transceiver of the sender is stopped, or the connection is closed.

#### set_streams(\*streams)

Sets the streams the remote peer puts the track of the sender in, from the next negotiation.

Repeated streams count once.

See [MDN: RTCRtpSender/setStreams](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/setStreams).

* **Parameters:**
  **\*streams** ([`webrtc.MediaStream`](media_stream.md#webrtc.interfaces.media_stream.MediaStream)) – The streams. Pass none to put the track in no stream.

#### *static* get_capabilities(kind)

Returns the codecs and header extensions senders of a kind support.

See [MDN: RTCRtpSender/getCapabilities_static](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/getCapabilities_static).

* **Parameters:**
  **kind** ([`webrtc.MediaType`](../enums.md#webrtc.enums.MediaType)) – Audio or video.
* **Returns:**
  [`webrtc.RTCRtpCapabilities`](../models/rtp_parameters.md#webrtc.models.rtp_parameters.RTCRtpCapabilities), optional – The capabilities, or [`None`](https://docs.python.org/3/builtins/constants.html#None) for another kind.
* **Return type:**
  [*RTCRtpCapabilities*](../models/rtp_parameters.md#webrtc.models.rtp_parameters.RTCRtpCapabilities) | None

#### *async* get_stats()

Collects the stats of the sender and of the objects they refer to.

Calls in the same loop iteration, like those one [`asyncio.gather()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.gather) starts, share one collection.

See [MDN: RTCRtpSender/getStats](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/getStats).

* **Returns:**
  [`webrtc.RTCStatsReport`](../models/rtc_stats.md#webrtc.models.rtc_stats.RTCStatsReport) – The stats.
* **Raises:**
  [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the connection is closed.
* **Return type:**
  [*RTCStatsReport*](../models/rtc_stats.md#webrtc.models.rtc_stats.RTCStatsReport)
