Beispiel #1
0
        bool IsRtxCodec(RtpCodecParameters codec) //=>
                                                  //Regex.IsMatch(codec.MimeType, ".+/rtx$");
        {
            var ok = Regex.IsMatch(codec.MimeType, ".+/rtx$");

            return(ok);
        }
Beispiel #2
0
        public RtpParameters GenerateProbatorRtpParameters(RtpParameters inRtpParameters)
        {
            // Clone given reference video RTP parameters.
            var videoRtpParameters = Utils.Clone(inRtpParameters, new RtpParameters());

            // This may throw.
            ValidateRtpParameters(videoRtpParameters);

            RtpCodecParameters codec = videoRtpParameters.Codecs[0];

            codec.PayloadType = RTP_PROBATOR_CODEC_PAYLOAD_TYPE;

            var rtpParameters = new RtpParameters
            {
                Mid              = RTP_PROBATOR_MID, //// new Mid { Id = RTP_PROBATOR_MID },
                Codecs           = new RtpCodecParameters[] { codec },
                HeaderExtensions = videoRtpParameters.HeaderExtensions,
                Encodings        = new RtpEncodingParameters[] { new RtpEncodingParameters {
                                                                     Ssrc = RTP_PROBATOR_SSRC
                                                                 } },
                Rtcp = new RtcpParameters {
                    Cname = RTP_PROBATOR_MID
                }
            };

            return(rtpParameters);
        }
Beispiel #3
0
        protected string GetCodecName(RtpCodecParameters codec)
        {
            var match = Regex.Match(codec.MimeType, "^(audio|video)/(.+)");
            if (!match.Success || match.Groups.Count != 3)
                throw new Exception("invalid codec.mimeType");

	        return match.Groups[2].Value;
        }
Beispiel #4
0
        public void ValidateRtpCodecParameters(RtpCodecParameters codec)
        {
            // MimeType is mandatory.
            if (codec.MimeType is null)
            {
                throw new Exception("missing codec.mimeType");
            }

            var match = Regex.Match(codec.MimeType, "^(audio|video)/(.+)");

            if (!match.Success || match.Groups.Count != 3)
            {
                throw new Exception("invalid codec.mimeType");
            }

            var kind = (MediaKind)Enum.Parse(typeof(MediaKind), match.Groups[1].Value.ToLower(), true);

            // Channels is optional. If unset, set it to 1 (just if audio).
            if (kind == MediaKind.Audio)
            {
                if (!codec.Channels.HasValue)
                {
                    codec.Channels = 1;
                }
            }
            else
            {
                codec.Channels = null;
            }

            // RtcpFeedback is optional. If unset, set it to an empty array.
            if (codec.RtcpFeedback is null)
            {
                codec.RtcpFeedback = new RtcpFeedback[] { }
            }
            ;
            foreach (var fb in codec.RtcpFeedback)
            {
                ValidateRtcpFeedback(fb);
            }
        }
Beispiel #5
0
        bool MatchCodecs(RtpCodecParameters aCodec, RtpCodecCapability bCodec, bool strict = false,
                         bool modify = false)
        {
            var aMimeType = aCodec.MimeType.ToLower();
            var bMimeType = bCodec.MimeType.ToLower();

            if (aMimeType != bMimeType)
            {
                return(false);
            }

            if (aCodec.ClockRate != bCodec.ClockRate)
            {
                return(false);
            }

            if (aCodec.Channels != bCodec.Channels)
            {
                return(false);
            }

            switch (aMimeType)
            {
            case "video/h264":
                var aPacketizationMode = aCodec.Parameters.ContainsKey("packetization-mode") ?
                                         (int)aCodec.Parameters["packetization-mode"] : 0;
                var bPacketizationMode = bCodec.Parameters.ContainsKey("packetization-mode") ?
                                         (int)bCodec.Parameters["packetization-mode"] : 0;

                if (aPacketizationMode != bPacketizationMode)
                {
                    return(false);
                }

                if (strict)
                {
                    if (!H264.IsSameProfile(aCodec.Parameters, bCodec.Parameters))
                    {
                        return(false);
                    }

                    string selectedProfileLevelId;
                    try
                    {
                        selectedProfileLevelId = H264.GenerateProfileLevelIdForAnswer(
                            aCodec.Parameters, bCodec.Parameters);
                    }
                    catch
                    {
                        return(false);
                    }
                    if (modify)
                    {
                        if (selectedProfileLevelId is not null)
                        {
                            aCodec.Parameters["profile-level-id"] = selectedProfileLevelId;
                            bCodec.Parameters["profile-level-id"] = selectedProfileLevelId;
                        }
                        else
                        {
                            aCodec.Parameters.Remove("profile-level-id");
                            bCodec.Parameters.Remove("profile-level-id");
                        }
                    }
                }
                break;

            case "video/vp9":
                if (strict)
                {
                    var aProfileId = aCodec.Parameters.ContainsKey("profile-id") ?
                                     (int)aCodec.Parameters["profile-id"] : 0;
                    var bProfileId = bCodec.Parameters.ContainsKey("profile-id") ?
                                     (int)bCodec.Parameters["profile-id"] : 0;

                    if (aProfileId != bProfileId)
                    {
                        return(false);
                    }
                }
                break;
            }

            return(true);
        }