コード例 #1
0
ファイル: SdpFile.cs プロジェクト: whble/rtsp-h264
        static Media ReadMedia(TextReader sdpStream, ref KeyValuePair <string, string> value)
        {
            Media returnValue = new Media(value.Value);

            value = GetKeyValue(sdpStream);

            // Media title
            if (value.Key == "i")
            {
                value = GetKeyValue(sdpStream);
            }

            // Connexion optional
            if (value.Key == "c")
            {
                returnValue.Connection = Connection.Parse(value.Value);
                value = GetKeyValue(sdpStream);
            }

            // bandwidth optional
            if (value.Key == "b")
            {
                returnValue.Bandwidth = Bandwidth.Parse(value.Value);
                value = GetKeyValue(sdpStream);
            }

            // enkription key optional
            if (value.Key == "k")
            {
                returnValue.EncriptionKey = EncriptionKey.ParseInvariant(value.Value);
                value = GetKeyValue(sdpStream);
            }

            //Attribut optional multiple
            while (value.Key == "a")
            {
                returnValue.Attributs.Add(Attribute.ParseInvariant(value.Value));
                value = GetKeyValue(sdpStream);
            }

            return(returnValue);
        }
コード例 #2
0
ファイル: SdpFile.cs プロジェクト: whble/rtsp-h264
        /// <summary>
        /// Reads the specified SDP stream.
        /// As define in RFC 4566
        /// </summary>
        /// <param name="sdpStream">The SDP stream.</param>
        /// <returns></returns>
        public static SdpFile Read(TextReader sdpStream)
        {
            SdpFile returnValue = new SdpFile();
            KeyValuePair <string, string> value = GetKeyValue(sdpStream);

            // Version mandatory
            if (value.Key == "v")
            {
                returnValue.Version = int.Parse(value.Value, CultureInfo.InvariantCulture);
            }
            else
            {
                throw new InvalidDataException();
            }
            value = GetKeyValue(sdpStream);

            // Origin mandatory
            if (value.Key == "o")
            {
                returnValue.Origin = Origin.Parse(value.Value);
            }
            else
            {
                throw new InvalidDataException();
            }
            value = GetKeyValue(sdpStream);

            // Session mandatory
            if (value.Key == "s")
            {
                returnValue.Session = value.Value;
            }
            else
            {
                throw new InvalidDataException();
            }
            value = GetKeyValue(sdpStream);

            // Session optional
            if (value.Key == "i")
            {
                returnValue.SessionInformation = value.Value;
                value = GetKeyValue(sdpStream);
            }

            // Uri optional
            if (value.Key == "u")
            {
                returnValue.Url = new Uri(value.Value);
                value           = GetKeyValue(sdpStream);
            }

            // Email optional
            if (value.Key == "e")
            {
                returnValue.Email = value.Value;
                value             = GetKeyValue(sdpStream);
            }

            // Phone optional
            if (value.Key == "p")
            {
                returnValue.Phone = value.Value;
                value             = GetKeyValue(sdpStream);
            }

            // Connexion optional
            if (value.Key == "c")
            {
                returnValue.Connection = Connection.Parse(value.Value);
                value = GetKeyValue(sdpStream);
            }

            // bandwidth optional
            if (value.Key == "b")
            {
                returnValue.Bandwidth = Bandwidth.Parse(value.Value);
                value = GetKeyValue(sdpStream);
            }

            // Timing (ignored)
            while (value.Key == "t")
            {
                string timing = value.Value;
                string repeat = string.Empty;

                value = GetKeyValue(sdpStream);

                if (value.Key == "r")
                {
                    repeat = value.Value;
                    value  = GetKeyValue(sdpStream);
                }
            }

            // timezone optional
            if (value.Key == "z")
            {
                returnValue.TimeZone = SdpTimeZone.ParseInvariant(value.Value);
                value = GetKeyValue(sdpStream);
            }

            // enkription key optional
            if (value.Key == "k")
            {
                returnValue.EncriptionKey = EncriptionKey.ParseInvariant(value.Value);
                value = GetKeyValue(sdpStream);
            }

            //Attribut optional multiple
            while (value.Key == "a")
            {
                returnValue.Attributs.Add(Attribute.ParseInvariant(value.Value));
                value = GetKeyValue(sdpStream);
            }

            while (value.Key == "m")
            {
                Media newMedia = ReadMedia(sdpStream, ref value);
                returnValue.Medias.Add(newMedia);
            }


            return(returnValue);
        }