Пример #1
0
        /// <summary>
        /// Updates participant data from SDES items.
        /// </summary>
        /// <param name="sdes">SDES chunk.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>sdes</b> is null reference value.</exception>
        internal void Update(RTCP_Packet_SDES_Chunk sdes)
        {
            if (sdes == null)
            {
                throw new ArgumentNullException("sdes");
            }

            bool changed = false;

            if (!string.IsNullOrEmpty(sdes.Name) && !string.Equals(m_Name, sdes.Name))
            {
                m_Name  = sdes.Name;
                changed = true;
            }
            if (!string.IsNullOrEmpty(sdes.Email) && !string.Equals(m_Email, sdes.Email))
            {
                m_Email = sdes.Email;
                changed = true;
            }
            if (!string.IsNullOrEmpty(sdes.Phone) && !string.Equals(Phone, sdes.Phone))
            {
                m_Phone = sdes.Phone;
                changed = true;
            }
            if (!string.IsNullOrEmpty(sdes.Location) && !string.Equals(m_Location, sdes.Location))
            {
                m_Location = sdes.Location;
                changed    = true;
            }
            if (!string.IsNullOrEmpty(sdes.Tool) && !string.Equals(m_Tool, sdes.Tool))
            {
                m_Tool  = sdes.Tool;
                changed = true;
            }
            if (!string.IsNullOrEmpty(sdes.Note) && !string.Equals(m_Note, sdes.Note))
            {
                m_Note  = sdes.Note;
                changed = true;
            }

            if (changed)
            {
                OnChanged();
            }
        }
        /// <summary>
        /// Adds next(round-robined) optional SDES item to SDES chunk, if any available.
        /// </summary>
        /// <param name="sdes">SDES chunk where to add item.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>sdes</b> is null reference.</exception>
        internal void AddNextOptionalSdesItem(RTCP_Packet_SDES_Chunk sdes)
        {
            if (sdes == null)
            {
                throw new ArgumentNullException("sdes");
            }

            lock (m_pOtionalItemsRoundRobin){
                if (m_pOtionalItemsRoundRobin.Count > 0)
                {
                    string itemName = m_pOtionalItemsRoundRobin.Next();

                    if (itemName == "name")
                    {
                        sdes.Name = m_Name;
                    }
                    else if (itemName == "email")
                    {
                        sdes.Email = m_Email;
                    }
                    else if (itemName == "phone")
                    {
                        sdes.Phone = m_Phone;
                    }
                    else if (itemName == "location")
                    {
                        sdes.Location = m_Location;
                    }
                    else if (itemName == "tool")
                    {
                        sdes.Tool = m_Tool;
                    }
                    else if (itemName == "note")
                    {
                        sdes.Note = m_Note;
                    }
                }
            }
        }
        /// <summary>
        /// Parses Source Description(SDES) packet from data buffer.
        /// </summary>
        /// <param name="buffer">Buffer what contains SDES packet.</param>
        /// <param name="offset">Offset in buffer.</param>
        protected override void ParseInternal(byte[] buffer, ref int offset)
        {
            /* RFC 3550 6.5 SDES: Source Description RTCP Packet.
             *      0                   1                   2                   3
             *      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             * header |V=2|P|    SC   |  PT=SDES=202  |             length            |
             +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
             * chunk  |                          SSRC/CSRC_1                          |
             * 1    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |                           SDES items                          |
             |                              ...                              |
             +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
             | chunk  |                          SSRC/CSRC_2                          |
             | 2    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             |                           SDES items                          |
             |                              ...                              |
             +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
             */

            m_Version = buffer[offset] >> 6;
            bool isPadded    = Convert.ToBoolean((buffer[offset] >> 5) & 0x1);
            int  sourceCount = buffer[offset++] & 0x1F;
            int  type        = buffer[offset++];
            int  length      = buffer[offset++] << 8 | buffer[offset++];

            if (isPadded)
            {
                this.PaddBytesCount = buffer[offset + length];
            }

            // Read chunks
            for (int i = 0; i < sourceCount; i++)
            {
                RTCP_Packet_SDES_Chunk chunk = new RTCP_Packet_SDES_Chunk();
                chunk.Parse(buffer, ref offset);
                m_pChunks.Add(chunk);
            }
        }