Class RTCRtpSender
Implements
Inherited Members
Namespace: Unity.WebRTC
Assembly: Unity.WebRTC.dll
Syntax
public class RTCRtpSender : RefCountedObject, IDisposable
Properties
SyncApplicationFramerate
Indicates if the video track's framerate is synchronized with the application's framerate.
Declaration
public bool SyncApplicationFramerate { get; set; }
Property Value
Type | Description |
---|---|
bool |
Track
MediaStreamTrack managed by RTCRtpSender. If it is null, no transmission occurs.
Declaration
public MediaStreamTrack Track { get; }
Property Value
Type | Description |
---|---|
MediaStreamTrack |
Transform
RTCRtpScriptTransform used to insert a transform stream in a worker thread into the sender pipeline, enabling transformations on encoded video and audio frames after output by a codec but before transmission.
Declaration
public RTCRtpTransform Transform { get; set; }
Property Value
Type | Description |
---|---|
RTCRtpTransform |
Methods
Dispose()
Disposes of RTCRtpSender.
Declaration
public override void Dispose()
Overrides
Remarks
Dispose
method disposes of the RTCRtpSender
and releases the associated resources.
Examples
sender.Dispose();
~RTCRtpSender()
Finalizer for RTCRtpSender.
Declaration
protected ~RTCRtpSender()
Remarks
Ensures that resources are released by calling the Dispose
method
GetCapabilities(TrackKind)
Provides a RTCRtpCapabilities
object describing the codec and header extension capabilities.
Declaration
public static RTCRtpCapabilities GetCapabilities(TrackKind kind)
Parameters
Type | Name | Description |
---|---|---|
TrackKind | kind |
|
Returns
Type | Description |
---|---|
RTCRtpCapabilities |
|
Remarks
GetCapabilities
method provides a RTCRtpCapabilities
object that describes the codec and header extension capabilities supported by RTCRtpSender
.
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}");
}
GetParameters()
Retrieves the current configuration of the RTCRtpSender.
Declaration
public RTCRtpSendParameters GetParameters()
Returns
Type | Description |
---|---|
RTCRtpSendParameters |
|
Remarks
GetParameters
method retrieves RTCRtpSendParameters
object describing the current configuration of the RTCRtpSender
.
Examples
RTCRtpSender sender = peerConnection.GetSenders().First();
RTCRtpSendParameters parameters = sender.GetParameters();
parameters.encodings[0].maxBitrate = bandwidth * 1000;
RTCError error = sender.SetParameters(parameters);
if (error.errorType != RTCErrorType.None)
{
Debug.LogError($"Failed to set parameters: {error.message}");
}
See Also
GetStats()
Asynchronously requests statistics about outgoing traffic on the RTCPeerConnection associated with the RTCRtpSender.
Declaration
public RTCStatsReportAsyncOperation GetStats()
Returns
Type | Description |
---|---|
RTCStatsReportAsyncOperation |
|
Remarks
GetStats
method asynchronously requests an RTCStatsReport
containing statistics about the outgoing traffic for the RTCPeerConnection
associated with the RTCRtpSender
.
Examples
RTCStatsReportAsyncOperation asyncOperation = sender.GetStats();
yield return asyncOperation;
if (!asyncOperation.IsError)
{
RTCStatsReport statsReport = asyncOperation.Value;
RTCStats stats = statsReport.Stats.ElementAt(0).Value;
string statsText = "Id:" + stats.Id + "\n";
statsText += "Timestamp:" + stats.Timestamp + "\n";
statsText += stats.Dict.Aggregate(string.Empty, (str, next) =>
str + next.Key + ":" + (next.Value == null ? string.Empty : next.Value.ToString()) + "\n");
Debug.Log(statsText);
statsReport.Dispose();
}
ReplaceTrack(MediaStreamTrack)
Replaces the current source track with a new MediaStreamTrack.
Declaration
public bool ReplaceTrack(MediaStreamTrack track)
Parameters
Type | Name | Description |
---|---|---|
MediaStreamTrack | track | A |
Returns
Type | Description |
---|---|
bool |
|
Remarks
ReplaceTrack
method replaces the track currently being used as the sender's source with a new MediaStreamTrack
.
It is often used to switch between two cameras.
Examples
RTCRtpTransceiver transceiver = peerConnection.GetTransceivers().First();
transceiver.Sender.ReplaceTrack(newTrack);
SetParameters(RTCRtpSendParameters)
Updates the configuration of the sender's track.
Declaration
public RTCError SetParameters(RTCRtpSendParameters parameters)
Parameters
Type | Name | Description |
---|---|---|
RTCRtpSendParameters | parameters | A |
Returns
Type | Description |
---|---|
RTCError |
|
Remarks
SetParameters
method updates the configuration of the sender's MediaStreamTrack
by applying changes the RTP transmission and the encoding parameters for a specific outgoing media on the connection.
Examples
RTCRtpSender sender = peerConnection.GetSenders().First();
RTCRtpSendParameters parameters = sender.GetParameters();
parameters.encodings[0].maxBitrate = bandwidth * 1000;
RTCError error = sender.SetParameters(parameters);
if (error.errorType != RTCErrorType.None)
{
Debug.LogError($"Failed to set parameters: {error.message}");
}