Exemple #1
0
        /// <summary>
        /// Gets the RTCP compound packet containing the RTCP reports we send.
        /// </summary>
        /// <returns>An RTCP compound packet.</returns>
        private RTCPCompoundPacket GetRtcpReport()
        {
            ReceptionReportSample rr = (m_receptionReport != null)
                ? m_receptionReport.GetSample(DateTimeToNtpTimestamp32(DateTime.Now))
                : null;
            var sdesReport = new RTCPSDesReport(Ssrc, Cname);

            if (PacketsSentCount > m_previousPacketsSentCount)
            {
                // If we have sent a packet since the last report then we send an RTCP Sender Report.
                var senderReport = new RTCPSenderReport(Ssrc, LastNtpTimestampSent, LastRtpTimestampSent,
                                                        PacketsSentCount, OctetsSentCount, (rr != null) ? new List <ReceptionReportSample> {
                    rr
                } : null);
                return(new RTCPCompoundPacket(senderReport, sdesReport));
            }
            else
            {
                // If we have NOT sent a packet since the last report then we send an RTCP Receiver Report.
                if (rr != null)
                {
                    var receiverReport = new RTCPReceiverReport(Ssrc, new List <ReceptionReportSample> {
                        rr
                    });
                    return(new RTCPCompoundPacket(receiverReport, sdesReport));
                }
                else
                {
                    var receiverReport = new RTCPReceiverReport(Ssrc, null);
                    return(new RTCPCompoundPacket(receiverReport, sdesReport));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the RTCP compound packet containing the RTCP reports we send.
        /// </summary>
        /// <returns>An RTCP compound packet.</returns>
        private RTCPCompoundPacket GetRtcpReport()
        {
            ReceptionReportSample rr = (m_receptionReport != null) ? m_receptionReport.GetSample(DateTimeToNtpTimestamp32(DateTime.Now)) : null;
            var senderReport         = new RTCPSenderReport(Ssrc, LastNtpTimestampSent, LastRtpTimestampSent, PacketsSentCount, OctetsSentCount, (rr != null) ? new List <ReceptionReportSample> {
                rr
            } : null);
            var sdesReport = new RTCPSDesReport(Ssrc, Cname);

            return(new RTCPCompoundPacket(senderReport, sdesReport));
        }
        /// <summary>
        /// Creates a new RTCP compound packet from a serialised buffer.
        /// </summary>
        /// <param name="packet">The serialised RTCP compound packet to parse.</param>
        public RTCPCompoundPacket(byte[] packet)
        {
            // The payload type field is the second byte in the RTCP header.
            int offset = 0;

            while (offset < packet.Length)
            {
                if (packet.Length - offset < RTCPHeader.HEADER_BYTES_LENGTH)
                {
                    // Not enough bytes left for a RTCP header.
                    break;
                }
                else
                {
                    if (offset != 0)
                    {
                        packet = packet.Skip(offset).ToArray();
                    }

                    byte packetTypeID = packet[1];
                    switch (packetTypeID)
                    {
                    case (byte)RTCPReportTypesEnum.SR:
                        SenderReport = new RTCPSenderReport(packet);
                        int srLength = (SenderReport != null) ? SenderReport.GetBytes().Length : Int32.MaxValue;
                        offset += srLength;
                        break;

                    case (byte)RTCPReportTypesEnum.RR:
                        ReceiverReport = new RTCPReceiverReport(packet);
                        int rrLength = (ReceiverReport != null) ? ReceiverReport.GetBytes().Length : Int32.MaxValue;
                        offset += rrLength;
                        break;

                    case (byte)RTCPReportTypesEnum.SDES:
                        SDesReport = new RTCPSDesReport(packet);
                        int sdesLength = (SDesReport != null) ? SDesReport.GetBytes().Length : Int32.MaxValue;
                        offset += sdesLength;
                        break;

                    case (byte)RTCPReportTypesEnum.BYE:
                        Bye = new RTCPBye(packet);
                        int byeLength = (Bye != null) ? Bye.GetBytes().Length : Int32.MaxValue;
                        offset += byeLength;
                        break;

                    default:
                        logger.LogWarning($"RTCPCompoundPacket did not recognise packet type ID {packetTypeID}.");
                        offset = Int32.MaxValue;
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Creates a new RTCP compound packet from a serialised buffer.
        /// </summary>
        /// <param name="packet">The serialised RTCP compound packet to parse.</param>
        public RTCPCompoundPacket(byte[] packet)
        {
            int offset = 0;

            while (offset < packet.Length)
            {
                if (packet.Length - offset < RTCPHeader.HEADER_BYTES_LENGTH)
                {
                    // Not enough bytes left for a RTCP header.
                    break;
                }
                else
                {
                    var buffer = packet.Skip(offset).ToArray();

                    // The payload type field is the second byte in the RTCP header.
                    byte packetTypeID = buffer[1];
                    switch (packetTypeID)
                    {
                    case (byte)RTCPReportTypesEnum.SR:
                        SenderReport = new RTCPSenderReport(buffer);
                        int srLength = (SenderReport != null) ? SenderReport.GetBytes().Length : Int32.MaxValue;
                        offset += srLength;
                        break;

                    case (byte)RTCPReportTypesEnum.RR:
                        ReceiverReport = new RTCPReceiverReport(buffer);
                        int rrLength = (ReceiverReport != null) ? ReceiverReport.GetBytes().Length : Int32.MaxValue;
                        offset += rrLength;
                        break;

                    case (byte)RTCPReportTypesEnum.SDES:
                        SDesReport = new RTCPSDesReport(buffer);
                        int sdesLength = (SDesReport != null) ? SDesReport.GetBytes().Length : Int32.MaxValue;
                        offset += sdesLength;
                        break;

                    case (byte)RTCPReportTypesEnum.BYE:
                        Bye = new RTCPBye(buffer);
                        int byeLength = (Bye != null) ? Bye.GetBytes().Length : Int32.MaxValue;
                        offset += byeLength;
                        break;

                    case (byte)RTCPReportTypesEnum.RTPFB:
                        // TODO: Interpret Generic RTP feedback reports.
                        var rtpfbHeader = new RTCPHeader(buffer);
                        offset += rtpfbHeader.Length * 4 + 4;
                        break;

                    case (byte)RTCPReportTypesEnum.PSFB:
                        // TODO: Interpret Payload specific feedback reports.
                        var psfbHeader = new RTCPHeader(buffer);
                        offset += psfbHeader.Length * 4 + 4;
                        break;

                    default:
                        logger.LogWarning($"RTCPCompoundPacket did not recognise packet type ID {packetTypeID}.");
                        offset = Int32.MaxValue;
                        logger.LogWarning(packet.HexStr());
                        break;
                    }
                }
            }
        }
 public RTCPCompoundPacket(RTCPReceiverReport receiverReport, RTCPSDesReport sdesReport)
 {
     ReceiverReport = receiverReport;
     SDesReport     = sdesReport;
 }
 public RTCPCompoundPacket(RTCPSenderReport senderReport, RTCPSDesReport sdesReport)
 {
     SenderReport = senderReport;
     SDesReport   = sdesReport;
 }