Пример #1
0
        /// <summary>
        /// Gets the raw bytes for the Goodbye packet.
        /// </summary>
        /// <returns>A byte array.</returns>
        public byte[] GetBytes()
        {
            byte[] reasonBytes  = (Reason != null) ? Encoding.UTF8.GetBytes(Reason) : null;
            int    reasonLength = (reasonBytes != null) ? reasonBytes.Length : 0;

            byte[] buffer = new byte[RTCPHeader.HEADER_BYTES_LENGTH + GetPaddedLength(reasonLength)];
            Header.SetLength((ushort)(buffer.Length / 4 - 1));

            Buffer.BlockCopy(Header.GetBytes(), 0, buffer, 0, RTCPHeader.HEADER_BYTES_LENGTH);
            int payloadIndex = RTCPHeader.HEADER_BYTES_LENGTH;

            if (BitConverter.IsLittleEndian)
            {
                Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(SSRC)), 0, buffer, payloadIndex, 4);
            }
            else
            {
                Buffer.BlockCopy(BitConverter.GetBytes(SSRC), 0, buffer, payloadIndex, 4);
            }

            if (reasonLength > 0)
            {
                buffer[payloadIndex + 4] = (byte)reasonLength;
                Buffer.BlockCopy(reasonBytes, 0, buffer, payloadIndex + 5, reasonBytes.Length);
            }

            return(buffer);
        }
Пример #2
0
        /// <summary>
        /// Gets the raw bytes for the SDES item. This packet is ready to be included
        /// directly in an RTCP packet.
        /// </summary>
        /// <returns>A byte array containing the serialised SDES item.</returns>
        public byte[] GetBytes()
        {
            byte[] cnameBytes = Encoding.UTF8.GetBytes(CNAME);
            byte[] buffer     =
                new byte[RTCPHeader.HEADER_BYTES_LENGTH +
                         GetPaddedLength(cnameBytes.Length)]; // Array automatically initialised with 0x00 values.
            Header.SetLength((ushort)(buffer.Length / 4 - 1));

            Buffer.BlockCopy(Header.GetBytes(), 0, buffer, 0, RTCPHeader.HEADER_BYTES_LENGTH);
            int payloadIndex = RTCPHeader.HEADER_BYTES_LENGTH;

            if (BitConverter.IsLittleEndian)
            {
                Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(SSRC)), 0, buffer, payloadIndex, 4);
            }
            else
            {
                Buffer.BlockCopy(BitConverter.GetBytes(SSRC), 0, buffer, payloadIndex, 4);
            }

            buffer[payloadIndex + 4] = CNAME_ID;
            buffer[payloadIndex + 5] = (byte)cnameBytes.Length;
            Buffer.BlockCopy(cnameBytes, 0, buffer, payloadIndex + 6, cnameBytes.Length);

            return(buffer);
        }
Пример #3
0
        /// <summary>
        /// Gets the serialised bytes for this Receiver Report.
        /// </summary>
        /// <returns>A byte array.</returns>
        public byte[] GetBytes()
        {
            int rrCount = (ReceptionReports != null) ? ReceptionReports.Count : 0;

            byte[] buffer = new byte[RTCPHeader.HEADER_BYTES_LENGTH + 4 + rrCount * ReceptionReportSample.PAYLOAD_SIZE];
            Header.SetLength((ushort)(buffer.Length / 4 - 1));

            Buffer.BlockCopy(Header.GetBytes(), 0, buffer, 0, RTCPHeader.HEADER_BYTES_LENGTH);
            int payloadIndex = RTCPHeader.HEADER_BYTES_LENGTH;

            if (BitConverter.IsLittleEndian)
            {
                Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(SSRC)), 0, buffer, payloadIndex, 4);
            }
            else
            {
                Buffer.BlockCopy(BitConverter.GetBytes(SSRC), 0, buffer, payloadIndex, 4);
            }

            int bufferIndex = payloadIndex + 4;

            for (int i = 0; i < rrCount; i++)
            {
                var receptionReportBytes = ReceptionReports[i].GetBytes();
                Buffer.BlockCopy(receptionReportBytes, 0, buffer, bufferIndex, ReceptionReportSample.PAYLOAD_SIZE);
                bufferIndex += ReceptionReportSample.PAYLOAD_SIZE;
            }

            return(buffer);
        }
Пример #4
0
        public byte[] GetBytes()
        {
            byte[] buffer = new byte[RTCPHeader.HEADER_BYTES_LENGTH + SENDER_PAYLOAD_SIZE];
            Header.SetLength((ushort)(buffer.Length / 4 - 1));

            Buffer.BlockCopy(Header.GetBytes(), 0, buffer, 0, RTCPHeader.HEADER_BYTES_LENGTH);
            int payloadIndex = RTCPHeader.HEADER_BYTES_LENGTH;

            // All feedback packets require the Sender and Media SSRC's to be set.
            if (BitConverter.IsLittleEndian)
            {
                Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(SenderSSRC)), 0, buffer, payloadIndex,
                                 4);
                Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(MediaSSRC)), 0, buffer,
                                 payloadIndex + 4, 4);
            }
            else
            {
                Buffer.BlockCopy(BitConverter.GetBytes(SenderSSRC), 0, buffer, payloadIndex, 4);
                Buffer.BlockCopy(BitConverter.GetBytes(MediaSSRC), 0, buffer, payloadIndex + 4, 4);
            }

            switch (Header)
            {
            case var x when x.PacketType == RTCPReportTypesEnum.RTPFB &&
                x.FeedbackMessageType == RTCPFeedbackTypesEnum.RTCP_SR_REQ:
                // PLI feedback reports do no have any additional parameters.
                break;

            case var x when x.PacketType == RTCPReportTypesEnum.RTPFB:
                if (BitConverter.IsLittleEndian)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(PID)), 0, buffer,
                                     payloadIndex + 6, 2);
                    Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(BLP)), 0, buffer,
                                     payloadIndex + 8, 2);
                }
                else
                {
                    Buffer.BlockCopy(BitConverter.GetBytes(PID), 0, buffer, payloadIndex + 6, 2);
                    Buffer.BlockCopy(BitConverter.GetBytes(BLP), 0, buffer, payloadIndex + 8, 2);
                }

                break;

            case var x when x.PacketType == RTCPReportTypesEnum.PSFB &&
                x.PayloadFeedbackMessageType == PSFBFeedbackTypesEnum.PLI:
                break;

            default:
                throw new NotImplementedException(
                          $"Serialisation for feedback report {Header.PacketType} not yet implemented.");
            }

            return(buffer);
        }