/// <summary>
        /// Sets SDP media stream mode.
        /// </summary>
        /// <param name="streamMode">Stream mode.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>streamMode</b> is null reference.</exception>
        public void SetStreamMode(string streamMode)
        {
            if (streamMode == null)
            {
                throw new ArgumentNullException("streamMode");
            }

            // Remove all old stream mode attributes.
            for (int i = 0; i < m_pAttributes.Count; i++)
            {
                SDP_Attribute sdpAttribute = m_pAttributes[i];
                if (string.Equals(sdpAttribute.Name, "sendrecv", StringComparison.InvariantCultureIgnoreCase))
                {
                    m_pAttributes.RemoveAt(i);
                    i--;
                }
                else if (string.Equals(sdpAttribute.Name, "sendonly", StringComparison.InvariantCultureIgnoreCase))
                {
                    m_pAttributes.RemoveAt(i);
                    i--;
                }
                else if (string.Equals(sdpAttribute.Name, "recvonly", StringComparison.InvariantCultureIgnoreCase))
                {
                    m_pAttributes.RemoveAt(i);
                    i--;
                }
                else if (string.Equals(sdpAttribute.Name, "inactive", StringComparison.InvariantCultureIgnoreCase))
                {
                    m_pAttributes.RemoveAt(i);
                    i--;
                }
            }

            if (streamMode != "")
            {
                m_pAttributes.Add(new SDP_Attribute(streamMode, ""));
            }
        }
예제 #2
0
        /// <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_MediaDescription media = SDP_MediaDescription.Parse(line);
                    sdp.m_pMediaDescriptions.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.Information = line.Split(new char[] { '=' }, 2)[1].Trim();
                        }
                        // c connection information
                        else if (line.ToLower().StartsWith("c"))
                        {
                            media.Connection = SDP_Connection.Parse(line);
                        }
                        // a Attributes
                        else if (line.ToLower().StartsWith("a"))
                        {
                            media.Attributes.Add(SDP_Attribute.Parse(line));
                        }

                        line = r.ReadLine();
                    }

                    if (line == null)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                // 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.Origin = SDP_Origin.Parse(line);
                }
                // 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.Connection = SDP_Connection.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);
        }