/// <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)); } } }
/// <summary> /// Create a new RTCP Sender Report from a serialised byte array. /// </summary> /// <param name="packet">The byte array holding the serialised sender report.</param> public RTCPSenderReport(byte[] packet) { if (packet.Length < MIN_PACKET_SIZE) { throw new ApplicationException("The packet did not contain the minimum number of bytes for an RTCPSenderReport packet."); } Header = new RTCPHeader(packet); ReceptionReports = new List <ReceptionReportSample>(); if (BitConverter.IsLittleEndian) { SSRC = NetConvert.DoReverseEndian(BitConverter.ToUInt32(packet, 4)); NtpTimestamp = NetConvert.DoReverseEndian(BitConverter.ToUInt64(packet, 8)); RtpTimestamp = NetConvert.DoReverseEndian(BitConverter.ToUInt32(packet, 16)); PacketCount = NetConvert.DoReverseEndian(BitConverter.ToUInt32(packet, 20)); OctetCount = NetConvert.DoReverseEndian(BitConverter.ToUInt32(packet, 24)); } else { SSRC = BitConverter.ToUInt32(packet, 4); NtpTimestamp = BitConverter.ToUInt64(packet, 8); RtpTimestamp = BitConverter.ToUInt32(packet, 16); PacketCount = BitConverter.ToUInt32(packet, 20); OctetCount = BitConverter.ToUInt32(packet, 24); } int rrIndex = 28; for (int i = 0; i < Header.ReceptionReportCount; i++) { var rr = new ReceptionReportSample(packet.Skip(rrIndex + i * ReceptionReportSample.PAYLOAD_SIZE).ToArray()); ReceptionReports.Add(rr); } }
/// <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)); }