docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class RTCRtpSender

    Inheritance
    object
    RefCountedObject
    RTCRtpSender
    Implements
    IDisposable
    Inherited Members
    RefCountedObject.disposed
    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
    RefCountedObject.Dispose()
    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

    TrackKind value indicating the type of media.

    Returns
    Type Description
    RTCRtpCapabilities

    RTCRtpCapabilities object contains an array of RTCRtpCodecCapability objects.

    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

    RTCRtpSendParameters object containing the current configuration of the RTCRtpSender.

    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
    SetParameters(RTCRtpSendParameters)

    GetStats()

    Asynchronously requests statistics about outgoing traffic on the RTCPeerConnection associated with the RTCRtpSender.

    Declaration
    public RTCStatsReportAsyncOperation GetStats()
    Returns
    Type Description
    RTCStatsReportAsyncOperation

    RTCStatsReportAsyncOperation object containing RTCStatsReport object.

    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 MediaStreamTrack to replace the current source track of the RTCRtpSender. The new track must be the same type as the current one.

    Returns
    Type Description
    bool

    true if the track has been successfully replaced.

    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 RTCRtpSendParameters object previously obtained by calling the sender's GetParameters, includes desired configuration changes and potential codecs for encoding the sender's track.

    Returns
    Type Description
    RTCError

    RTCError value.

    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}");
    }
    See Also
    GetParameters()

    Implements

    IDisposable
    In This Article
    • Properties
      • SyncApplicationFramerate
      • Track
      • Transform
    • Methods
      • Dispose()
      • ~RTCRtpSender()
      • GetCapabilities(TrackKind)
      • GetParameters()
      • GetStats()
      • ReplaceTrack(MediaStreamTrack)
      • SetParameters(RTCRtpSendParameters)
    • Implements
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)