コード例 #1
0
ファイル: SdpParser.cs プロジェクト: ztittle/Subspace
        public SdpSessionDescription Parse(string sdp)
        {
            var sessionDescription = new SdpSessionDescription();

            using var sr = new StringReader(sdp);

            ParseSessionDescription(sessionDescription, sr);

            return(sessionDescription);
        }
コード例 #2
0
ファイル: SdpParser.cs プロジェクト: ztittle/Subspace
        private void ParseSessionAttribute(SdpSessionDescription sessionDescription, string attribute)
        {
            ParseAttributeKeyValue(attribute, out var key, out var value);

            switch (key)
            {
            case "bundle" when value != null:
                sessionDescription.Bundles = value.Split(' ').ToList();
                break;

            case "msid-semantic" when value != null:
                sessionDescription.WebRtcMediaStreamId = value.Substring(value.IndexOf(" WMS ", StringComparison.Ordinal) + 1);
                break;
            }
        }
コード例 #3
0
ファイル: SdpParser.cs プロジェクト: ztittle/Subspace
        private void ParseSessionDescription(SdpSessionDescription sessionDescription, StringReader stringReader)
        {
            var line = stringReader.ReadLine();

            if (line is null)
            {
                return;
            }

            ParseSdpLine(line, out var key, out var value);

            switch (key)
            {
            case "v":
                sessionDescription.Version = byte.Parse(value);
                break;

            case "o":
                sessionDescription.Origin = ParseOriginLine(value);
                break;

            case "s":
                sessionDescription.SessionName = value;
                break;

            case "t":
                var timeParts = value.Split(' ');
                sessionDescription.StartTime = long.Parse(timeParts[0]);
                sessionDescription.EndTime   = long.Parse(timeParts[1]);
                break;

            case "m":
                ParseMediaDescription(sessionDescription, value, stringReader);
                break;

            case "a":
                ParseSessionAttribute(sessionDescription, value);
                break;
            }

            ParseSessionDescription(sessionDescription, stringReader);
        }
コード例 #4
0
ファイル: SdpParser.cs プロジェクト: ztittle/Subspace
        private void ParseMediaDescription(SdpSessionDescription sessionDescription, string medialine, TextReader stringReader)
        {
            var mediaDescription = new SdpMediaDescription();

            var parts = medialine.Split(' ');

            mediaDescription.Media    = TryGet(parts, 0);
            mediaDescription.Port     = int.Parse(TryGet(parts, 1));
            mediaDescription.Protocol = TryGet(parts, 2);
            mediaDescription.MediaFormatDescriptions = parts.Skip(3)
                                                       .Select(int.Parse)
                                                       .ToDictionary(pt => pt, pt => new SdpMediaFormatDescription
            {
                PayloadType = pt
            });

            var line = stringReader.ReadLine();

            while (line != null)
            {
                ParseSdpLine(line, out var key, out var value);
                switch (key)
                {
                case "c":
                    mediaDescription.Connection = ParseConnectionLine(value);
                    break;

                case "a":
                    ParseMediaDescriptionAttribute(mediaDescription, value);
                    break;

                case "m":
                    ParseMediaDescription(sessionDescription, value, stringReader);
                    break;
                }

                line = stringReader.ReadLine();
            }

            sessionDescription.MediaDescriptions.Add(mediaDescription);
        }