Beispiel #1
0
        // Validates RtcpFeedback. It may modify given data by adding missing
        // fields with default values.
        // It throws if invalid.
        public void ValidateRtcpFeedback(RtcpFeedback fb)
        {
            // Type is mandatory.
            if (fb.Type is null)
            {
                throw new Exception("missing fb.type");
            }

            // Parameter is optional. If unset set it to an empty string.
            if (fb.Parameter is null)
            {
                fb.Parameter = string.Empty;
            }
        }
Beispiel #2
0
        public RtpParameters GetSendingRemoteRtpParameters(MediaKind kind,
                                                           ExtendedRtpCapabilities extendedRtpCapabilities)
        {
            List <RtpCodecParameters> codecs = new();

            foreach (var extendedCodec in extendedRtpCapabilities.Codecs)
            {
                if (extendedCodec.Kind != kind)
                {
                    continue;
                }

                RtpCodecParameters codec = new()
                {
                    MimeType     = extendedCodec.MimeType,
                    PayloadType  = extendedCodec.LocalPayloadType,
                    ClockRate    = extendedCodec.ClockRate,
                    Channels     = extendedCodec.Channels,
                    Parameters   = extendedCodec.RemoteParameters,
                    RtcpFeedback = extendedCodec.RtcpFeedback
                };
                codecs.Add(codec);

                if (extendedCodec.LocalRtxPayloadType.HasValue)
                {
                    RtpCodecParameters rtxCodec = new()
                    {
                        MimeType    = $"{extendedCodec.Kind.DisplayName()}/rtx",
                        PayloadType = (int)extendedCodec.LocalRtxPayloadType,
                        ClockRate   = extendedCodec.ClockRate,
                        Parameters  = new Dictionary <string, object>
                        {
                            { "apt", extendedCodec.LocalPayloadType }
                        },
                        RtcpFeedback = new RtcpFeedback[] { }
                    };
                    codecs.Add(rtxCodec);
                }
            }

            List <RtpHeaderExtensionParameters> headerExtensions = new();

            foreach (var extendedExtendion in extendedRtpCapabilities.HeaderExtensions)
            {
                // Ignore RTP extensions of a different kind and those not valid for sending.
                if ((extendedExtendion.Kind != kind) ||
                    (extendedExtendion.Direction != Direction.SendRecv &&
                     extendedExtendion.Direction != Direction.SendOnly))
                {
                    continue;
                }

                RtpHeaderExtensionParameters ext = new()
                {
                    Uri     = extendedExtendion.Uri,
                    Id      = extendedExtendion.SendId,
                    Encrypt = (bool)extendedExtendion.PreferredEncrypt,
                };
                headerExtensions.Add(ext);
            }

            // Reduce codecs' RTCP feedback. Use Transport-CC if available, REMB otherwise.
            if (headerExtensions.Any(ext =>
                                     ext.Uri == "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"))
            {
                foreach (var codec in codecs)
                {
                    codec.RtcpFeedback = codec.RtcpFeedback
                                         .Where(fb => fb.Type != "goog-remb").ToArray();
                }
            }
            else if (headerExtensions.Any(ext =>
                                          ext.Uri == "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"))
            {
                foreach (var codec in codecs)
                {
                    codec.RtcpFeedback = codec.RtcpFeedback
                                         .Where(fb => fb.Type != "transport-cc").ToArray();
                }
            }
            else
            {
                foreach (var codec in codecs)
                {
                    codec.RtcpFeedback = codec.RtcpFeedback
                                         .Where(fb => fb.Type != "transport-cc" && fb.Type != "goog-remb").ToArray();
                }
            }

            return(new RtpParameters
            {
                Codecs = codecs.ToArray(),
                HeaderExtensions = headerExtensions.ToArray(),
                Encodings = new RtpEncodingParameters[] { },
                Rtcp = new()
            });
        }
Beispiel #3
0
        public RtpParameters GetSendingRtpParameters(MediaKind kind, ExtendedRtpCapabilities extendedRtpCapabilities)
        {
            List <RtpCodecParameters> codecs = new();

            foreach (var extendedCodec in extendedRtpCapabilities.Codecs)
            {
                if (extendedCodec.Kind != kind)
                {
                    continue;
                }

                RtpCodecParameters codec = new()
                {
                    MimeType     = extendedCodec.MimeType,
                    PayloadType  = extendedCodec.LocalPayloadType,
                    ClockRate    = extendedCodec.ClockRate,
                    Channels     = extendedCodec.Channels,
                    Parameters   = extendedCodec.LocalParameters,
                    RtcpFeedback = extendedCodec.RtcpFeedback
                };
                codecs.Add(codec);

                if (extendedCodec.LocalRtxPayloadType.HasValue)
                {
                    RtpCodecParameters rtxCodec = new()
                    {
                        MimeType    = $"{extendedCodec.Kind.DisplayName()}/rtx",
                        PayloadType = (int)extendedCodec.LocalRtxPayloadType,
                        ClockRate   = extendedCodec.ClockRate,
                        Parameters  = new Dictionary <string, object>
                        {
                            { "apt", extendedCodec.LocalPayloadType }
                        },
                        RtcpFeedback = new RtcpFeedback[] { }
                    };
                    codecs.Add(rtxCodec);
                }
            }

            List <RtpHeaderExtensionParameters> headerExtensions = new();

            foreach (var extendedExtendion in extendedRtpCapabilities.HeaderExtensions)
            {
                // Ignore RTP extensions of a different kind and those not valid for sending.
                if ((extendedExtendion.Kind != kind) ||
                    (extendedExtendion.Direction != Direction.SendRecv &&
                     extendedExtendion.Direction != Direction.SendOnly))
                {
                    continue;
                }

                RtpHeaderExtensionParameters ext = new()
                {
                    Uri        = extendedExtendion.Uri,
                    Id         = extendedExtendion.SendId,
                    Encrypt    = (bool)extendedExtendion.PreferredEncrypt,
                    Parameters = new()
                };
                headerExtensions.Add(ext);
            }

            return(new RtpParameters
            {
                Codecs = codecs.ToArray(),
                HeaderExtensions = headerExtensions.ToArray(),
                Encodings = new RtpEncodingParameters[] { },
                Rtcp = new()
            });
        }
Beispiel #4
0
        public RtpCapabilities GetRecvRtpCapabilities(ExtendedRtpCapabilities extendedRtpCapabilities)
        {
            List <RtpCodecCapability> codecs = new();

            foreach (var extendedCodec in extendedRtpCapabilities.Codecs)
            {
                RtpCodecCapability codec = new()
                {
                    MimeType             = extendedCodec.MimeType,
                    Kind                 = extendedCodec.Kind,
                    PreferredPayloadType = extendedCodec.RemotePayloadType,
                    ClockRate            = extendedCodec.ClockRate,
                    Channels             = extendedCodec.Channels,
                    Parameters           = extendedCodec.LocalParameters,
                    RtcpFeedback         = extendedCodec.RtcpFeedback
                };
                codecs.Add(codec);

                if (extendedCodec.RemoteRtxPayloadType is null)
                {
                    continue;
                }

                RtpCodecCapability rtxCodec = new()
                {
                    MimeType             = $"{extendedCodec.Kind.DisplayName()}/rtx",
                    Kind                 = extendedCodec.Kind,
                    PreferredPayloadType = (int)extendedCodec.RemoteRtxPayloadType,
                    ClockRate            = extendedCodec.ClockRate,
                    //Parameters = new RtxParameters
                    //{
                    //    Apt = extendedCodec.RemotePayloadType
                    //},
                    Parameters = new Dictionary <string, object /*string*/>()
                    {
                        { "apt", extendedCodec.RemotePayloadType /*.ToString()*/ }
                    },
                    RtcpFeedback = new RtcpFeedback[] { }
                };
                codecs.Add(rtxCodec);
            }

            List <RtpHeaderExtension> headerExtensions = new();

            foreach (var extendedExtensions in extendedRtpCapabilities.HeaderExtensions)
            {
                if (extendedExtensions.Direction != Direction.SendRecv &&
                    extendedExtensions.Direction != Direction.RecvOnly)
                {
                    continue;
                }

                RtpHeaderExtension ext = new()
                {
                    Kind             = extendedExtensions.Kind,
                    Uri              = extendedExtensions.Uri,
                    PreferredId      = extendedExtensions.RecvId,
                    PreferredEncrypt = extendedExtensions.PreferredEncrypt,
                    Direction        = extendedExtensions.Direction
                };
                headerExtensions.Add(ext);
            }

            return(new RtpCapabilities
            {
                Codecs = codecs.ToArray(),
                HeaderExtensions = headerExtensions.ToArray()
            });
        }