/// <summary>
        /// Parses media from "c" SDP message field.
        /// </summary>
        /// <param name="cValue">"m" SDP message field.</param>
        /// <returns></returns>
        public static SDP_ConnectionData Parse(string cValue)
        {
            // c=<nettype> <addrtype> <connection-address>

            SDP_ConnectionData connectionInfo = new SDP_ConnectionData();

            // Remove c=
            StringReader r = new StringReader(cValue);
            r.QuotedReadToDelimiter('=');

            //--- <nettype> ------------------------------------------------------------
            string word = r.ReadWord();
            if(word == null){
                throw new Exception("SDP message \"c\" field <nettype> value is missing !");
            }
            connectionInfo.m_NetType = word;

            //--- <addrtype> -----------------------------------------------------------
            word = r.ReadWord();
            if(word == null){
                throw new Exception("SDP message \"c\" field <addrtype> value is missing !");
            }
            connectionInfo.m_AddressType = word;

            //--- <connection-address> -------------------------------------------------
            word = r.ReadWord();
            if(word == null){
                throw new Exception("SDP message \"c\" field <connection-address> value is missing !");
            }
            connectionInfo.m_Address = word;

            return connectionInfo;
        }
Exemple #2
0
        /// <summary>
        /// Parses media from "c" SDP message field.
        /// </summary>
        /// <param name="cValue">"m" SDP message field.</param>
        /// <returns></returns>
        public static SDP_ConnectionData Parse(string cValue)
        {
            // c=<nettype> <addrtype> <connection-address>

            SDP_ConnectionData connectionInfo = new SDP_ConnectionData();

            // Remove c=
            StringReader r = new StringReader(cValue);

            r.QuotedReadToDelimiter('=');

            //--- <nettype> ------------------------------------------------------------
            string word = r.ReadWord();

            if (word == null)
            {
                throw new Exception("SDP message \"c\" field <nettype> value is missing !");
            }
            connectionInfo.m_NetType = word;

            //--- <addrtype> -----------------------------------------------------------
            word = r.ReadWord();
            if (word == null)
            {
                throw new Exception("SDP message \"c\" field <addrtype> value is missing !");
            }
            connectionInfo.m_AddressType = word;

            //--- <connection-address> -------------------------------------------------
            word = r.ReadWord();
            if (word == null)
            {
                throw new Exception("SDP message \"c\" field <connection-address> value is missing !");
            }
            connectionInfo.m_Address = word;

            return(connectionInfo);
        }
        /// <summary>
        /// Parses SDP from raw data.
        /// </summary>
        /// <param name="data">Raw SDP data.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>data</b> is null reference.</exception>
        public static SDP_Message Parse(string data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            SDP_Message sdp = new SDP_Message();

            System.IO.StringReader r = new System.IO.StringReader(data);

            string line = r.ReadLine();

            //--- Read global fields ---------------------------------------------
            while (line != null)
            {
                line = line.Trim();

                // We reached to media descriptions
                if (line.ToLower().StartsWith("m"))
                {
                    /*
                     *  m=  (media name and transport address)
                     *  i=* (media title)
                     *  c=* (connection information -- optional if included at session level)
                     *  b=* (zero or more bandwidth information lines)
                     *  k=* (encryption key)
                     *  a=* (zero or more media attribute lines)
                     */

                    SDP_Media media = new SDP_Media();
                    media.MediaDescription = SDP_MediaDescription.Parse(line);
                    sdp.Media.Add(media);
                    line = r.ReadLine();
                    // Pasrse media fields and attributes
                    while (line != null)
                    {
                        line = line.Trim();

                        // Next media descrition, just stop active media description parsing,
                        // fall through main while, allow next while loop to process it.
                        if (line.ToLower().StartsWith("m"))
                        {
                            break;
                        }
                        // i media title
                        else if (line.ToLower().StartsWith("i"))
                        {
                            media.Title = line.Split(new char[] { '=' }, 2)[1].Trim();
                        }
                        // c connection information
                        else if (line.ToLower().StartsWith("c"))
                        {
                            media.ConnectionData = SDP_ConnectionData.Parse(line);
                        }
                        // a Attributes
                        else if (line.ToLower().StartsWith("a"))
                        {
                            media.Attributes.Add(SDP_Attribute.Parse(line));
                        }

                        line = r.ReadLine();
                    }
                    break;
                }
                // v Protocol Version
                else if (line.ToLower().StartsWith("v"))
                {
                    sdp.Version = line.Split(new char[] { '=' }, 2)[1].Trim();
                }
                // o Origin
                else if (line.ToLower().StartsWith("o"))
                {
                    sdp.Originator = line.Split(new char[] { '=' }, 2)[1].Trim();
                }
                // s Session Name
                else if (line.ToLower().StartsWith("s"))
                {
                    sdp.SessionName = line.Split(new char[] { '=' }, 2)[1].Trim();
                }
                // i Session Information
                else if (line.ToLower().StartsWith("i"))
                {
                    sdp.SessionDescription = line.Split(new char[] { '=' }, 2)[1].Trim();
                }
                // u URI
                else if (line.ToLower().StartsWith("u"))
                {
                    sdp.Uri = line.Split(new char[] { '=' }, 2)[1].Trim();
                }
                // c Connection Data
                else if (line.ToLower().StartsWith("c"))
                {
                    sdp.ConnectionData = SDP_ConnectionData.Parse(line);
                }
                // t Timing
                else if (line.ToLower().StartsWith("t"))
                {
                    sdp.Times.Add(SDP_Time.Parse(line));
                }
                // a Attributes
                else if (line.ToLower().StartsWith("a"))
                {
                    sdp.Attributes.Add(SDP_Attribute.Parse(line));
                }

                line = r.ReadLine().Trim();
            }

            return(sdp);
        }