Esempio n. 1
0
        /// <summary>
        /// Sends specified application packet to the RTP session target(s).
        /// </summary>
        /// <exception cref="ObjectDisposedException">Is raised when this class is Disposed and this method is accessed.</exception>
        /// <param name="packet">Is raised when <b>packet</b> is null reference.</param>
        public void SendApplicationPacket(RTCP_Packet_APP packet)
        {
            if(this.State == RTP_SourceState.Disposed){
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if(packet == null){
                throw new ArgumentNullException("packet");
            }

            packet.Source = this.SSRC;

            RTCP_CompoundPacket p = new RTCP_CompoundPacket();
            RTCP_Packet_RR rr = new RTCP_Packet_RR();
            rr.SSRC = this.SSRC;
            p.Packets.Add(packet);

            // Send APP packet.
            this.Session.SendRtcpPacket(p);
        }
Esempio n. 2
0
        /// <summary>
        /// Raises <b>ApplicationPacket</b> event.
        /// </summary>
        /// <exception cref="ArgumentNullException">Is raised when <b>packet</b> is null reference.</exception>
        private void OnApplicationPacket(RTCP_Packet_APP packet)
        {
            if(packet == null){
                throw new ArgumentNullException("packet");
            }

            if(this.ApplicationPacket != null){
                this.ApplicationPacket(this,new EventArgs<RTCP_Packet_APP>(packet));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This method is called when this source got RTCP APP apcket.
        /// </summary>
        /// <param name="packet">RTCP APP packet.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>packet</b> is null reference.</exception>
        internal void OnAppPacket(RTCP_Packet_APP packet)
        {
            if(packet == null){
                throw new ArgumentNullException("packet");
            }

            OnApplicationPacket(packet);
        }
Esempio n. 4
0
        /// <summary>
        /// Parses 1 RTCP packet from the specified buffer.
        /// </summary>
        /// <param name="buffer">Buffer which contains RTCP packet.</param>
        /// <param name="offset">Offset in buffer.</param>
        /// <param name="noException">If true and parsing failed, no exception is raised.</param>
        /// <returns>Returns parsed RTCP packet or null if parsing is failed and <b>noException=true</b>.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
        public static RTCP_Packet Parse(byte[] buffer,ref int offset,bool noException)
        {
            if(buffer == null){
                throw new ArgumentNullException("buffer");
            }
            if(offset < 0){
                throw new ArgumentException("Argument 'offset' value must be >= 0.");
            }

            /* RFC 3550 RTCP header.
                    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|    XX   |   type        |             length            |
                   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
            */

            int type = buffer[offset + 1];

            // SR
            if(type == RTCP_PacketType.SR){
                RTCP_Packet_SR packet = new RTCP_Packet_SR();
                packet.ParseInternal(buffer,ref offset);

                return packet;
            }
            // RR
            else if(type == RTCP_PacketType.RR){
                RTCP_Packet_RR packet = new RTCP_Packet_RR();
                packet.ParseInternal(buffer,ref offset);

                return packet;
            }
            // SDES
            else if(type == RTCP_PacketType.SDES){
                RTCP_Packet_SDES packet = new RTCP_Packet_SDES();
                packet.ParseInternal(buffer,ref offset);

                return packet;
            }
            // BYE
            else if(type == RTCP_PacketType.BYE){
                RTCP_Packet_BYE packet = new RTCP_Packet_BYE();
                packet.ParseInternal(buffer,ref offset);

                return packet;
            }
            // APP
            else if(type == RTCP_PacketType.APP){
                RTCP_Packet_APP packet = new RTCP_Packet_APP();
                packet.ParseInternal(buffer,ref offset);

                return packet;
            }
            else{
                // We need to move offset.
                offset += 2;
                int length = buffer[offset++] << 8 | buffer[offset++];
                offset += length;

                if(noException){
                    return null;
                }
                else{
                    throw new ArgumentException("Unknown RTCP packet type '" + type + "'.");
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Parses 1 RTCP packet from the specified buffer.
        /// </summary>
        /// <param name="buffer">Buffer which contains RTCP packet.</param>
        /// <param name="offset">Offset in buffer.</param>
        /// <param name="noException">If true and parsing failed, no exception is raised.</param>
        /// <returns>Returns parsed RTCP packet or null if parsing is failed and <b>noException=true</b>.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>buffer</b> is null.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception>
        public static RTCP_Packet Parse(byte[] buffer, ref int offset, bool noException)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0)
            {
                throw new ArgumentException("Argument 'offset' value must be >= 0.");
            }

            /* RFC 3550 RTCP header.
             *      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|    XX   |   type        |             length            |
             +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
             */

            int type = buffer[offset + 1];

            // SR
            if (type == RTCP_PacketType.SR)
            {
                RTCP_Packet_SR packet = new RTCP_Packet_SR();
                packet.ParseInternal(buffer, ref offset);

                return(packet);
            }
            // RR
            else if (type == RTCP_PacketType.RR)
            {
                RTCP_Packet_RR packet = new RTCP_Packet_RR();
                packet.ParseInternal(buffer, ref offset);

                return(packet);
            }
            // SDES
            else if (type == RTCP_PacketType.SDES)
            {
                RTCP_Packet_SDES packet = new RTCP_Packet_SDES();
                packet.ParseInternal(buffer, ref offset);

                return(packet);
            }
            // BYE
            else if (type == RTCP_PacketType.BYE)
            {
                RTCP_Packet_BYE packet = new RTCP_Packet_BYE();
                packet.ParseInternal(buffer, ref offset);

                return(packet);
            }
            // APP
            else if (type == RTCP_PacketType.APP)
            {
                RTCP_Packet_APP packet = new RTCP_Packet_APP();
                packet.ParseInternal(buffer, ref offset);

                return(packet);
            }
            else
            {
                // We need to move offset.
                offset += 2;
                int length = buffer[offset++] << 8 | buffer[offset++];
                offset += length;

                if (noException)
                {
                    return(null);
                }
                else
                {
                    throw new ArgumentException("Unknown RTCP packet type '" + type + "'.");
                }
            }
        }