Class RTCRtpTransceiver
Describes a permanent pairing of an RTCRtpSender and an RTCRtpReceiver.
Implements
Inherited Members
Namespace: Unity.WebRTC
Assembly: Unity.WebRTC.dll
Syntax
public class RTCRtpTransceiver : RefCountedObject, IDisposable
Remarks
RTCRtpTransceiver
class is used to represent a permanent pairing of an RTCRtpSender
and an RTCRtpReceiver
, along with shared state.
Examples
RTCRtpCapabilities capabilities = RTCRtpSender.GetCapabilities(TrackKind.Video);
RTCRtpTransceiver transceiver = peerConnection.GetTransceivers().First();
RTCErrorType error = transceiver.SetCodecPreferences(capabilities.codecs);
if (error.errorType != RTCErrorType.None)
{
Debug.LogError($"Failed to set codec preferences: {error.message}");
}
Properties
CurrentDirection
This property indicates the transceiver's current directionality, or null if the transceiver is stopped or has never participated in an exchange of offers and answers. To change the transceiver's directionality, set the value of the Direction property.
Declaration
public RTCRtpTransceiverDirection? CurrentDirection { get; }
Property Value
Type | Description |
---|---|
RTCRtpTransceiverDirection? |
See Also
Direction
This is used to set the transceiver's desired direction and will be used in calls to CreateOffer and CreateAnswer.
Declaration
public RTCRtpTransceiverDirection Direction { get; set; }
Property Value
Type | Description |
---|---|
RTCRtpTransceiverDirection |
See Also
Mid
Specifies the negotiated media ID (mid) that uniquely identifies the pairing of the sender and receiver agreed upon by local and remote peers.
Declaration
public string Mid { get; }
Property Value
Type | Description |
---|---|
string |
See Also
Receiver
RTCRtpReceiver object that handles receiving and decoding incoming media data for the transceiver's stream.
Declaration
public RTCRtpReceiver Receiver { get; }
Property Value
Type | Description |
---|---|
RTCRtpReceiver |
See Also
Sender
RTCRtpSender object that handles encoding and sending outgoing media data for the transceiver's stream.
Declaration
public RTCRtpSender Sender { get; }
Property Value
Type | Description |
---|---|
RTCRtpSender |
See Also
Methods
Dispose()
Disposes of RTCRtpTransceiver.
Declaration
public override void Dispose()
Overrides
Remarks
Dispose
method disposes of the RTCRtpTransceiver
and releases the associated resources.
Examples
transceiver.Dispose();
See Also
~RTCRtpTransceiver()
Finalizer for RTCRtpTransceiver.
Declaration
protected ~RTCRtpTransceiver()
Remarks
Ensures that resources are released by calling the Dispose
method
See Also
SetCodecPreferences(RTCRtpCodecCapability[])
Specifies the codecs for decoding received data on this transceiver, arranged in order of decreasing preference.
Declaration
public RTCErrorType SetCodecPreferences(RTCRtpCodecCapability[] codecs)
Parameters
Type | Name | Description |
---|---|---|
RTCRtpCodecCapability[] | codecs | An array of |
Returns
Type | Description |
---|---|
RTCErrorType |
|
Remarks
SetCodecPreferences
method sets codec preferences for negotiating data encoding with a remote peer.
It requires reordering supported codecs by preference and applying them to influence the negotiation process.
When initiating an RTCPeerConnection
, set codecs before calling CreateOffer
or CreateAnswer
.
Changing codecs during a session requires a new negotiation but does not automatically trigger the OnNegotiationNeeded
event.
Examples
RTCRtpCapabilities capabilities = RTCRtpSender.GetCapabilities(TrackKind.Video);
RTCRtpTransceiver transceiver = peerConnection.GetTransceivers().First();
RTCErrorType error = transceiver.SetCodecPreferences(capabilities.codecs);
if (error.errorType != RTCErrorType.None)
{
Debug.LogError($"Failed to set codec preferences: {error.message}");
}
See Also
Stop()
Stops the transceiver permanently by stopping both the associated RTCRtpSender and RTCRtpReceiver.
Declaration
public RTCErrorType Stop()
Returns
Type | Description |
---|---|
RTCErrorType |
|
Remarks
Calling Stop
method stops the sender from sending media immediately, closes RTP streams with an RTCP "BYE" message, and the receiver stops receiving media.
The receiver's track ceases, and the transceiver's direction changes to Stopped
.
Examples
RTCErrorType error = transceiver.Stop();
if (error.errorType != RTCErrorType.None)
{
Debug.LogError($"Failed to stop transceiver: {error.message}");
}