diff --git a/common_types.h b/common_types.h index fb677d67bb..2eb2564951 100644 --- a/common_types.h +++ b/common_types.h @@ -16,72 +16,6 @@ namespace webrtc { -// Statistics for RTCP packet types. -struct RtcpPacketTypeCounter { - RtcpPacketTypeCounter() - : first_packet_time_ms(-1), - nack_packets(0), - fir_packets(0), - pli_packets(0), - nack_requests(0), - unique_nack_requests(0) {} - - void Add(const RtcpPacketTypeCounter& other) { - nack_packets += other.nack_packets; - fir_packets += other.fir_packets; - pli_packets += other.pli_packets; - nack_requests += other.nack_requests; - unique_nack_requests += other.unique_nack_requests; - if (other.first_packet_time_ms != -1 && - (other.first_packet_time_ms < first_packet_time_ms || - first_packet_time_ms == -1)) { - // Use oldest time. - first_packet_time_ms = other.first_packet_time_ms; - } - } - - void Subtract(const RtcpPacketTypeCounter& other) { - nack_packets -= other.nack_packets; - fir_packets -= other.fir_packets; - pli_packets -= other.pli_packets; - nack_requests -= other.nack_requests; - unique_nack_requests -= other.unique_nack_requests; - if (other.first_packet_time_ms != -1 && - (other.first_packet_time_ms > first_packet_time_ms || - first_packet_time_ms == -1)) { - // Use youngest time. - first_packet_time_ms = other.first_packet_time_ms; - } - } - - int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const { - return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms); - } - - int UniqueNackRequestsInPercent() const { - if (nack_requests == 0) { - return 0; - } - return static_cast((unique_nack_requests * 100.0f / nack_requests) + - 0.5f); - } - - int64_t first_packet_time_ms; // Time when first packet is sent/received. - uint32_t nack_packets; // Number of RTCP NACK packets. - uint32_t fir_packets; // Number of RTCP FIR packets. - uint32_t pli_packets; // Number of RTCP PLI packets. - uint32_t nack_requests; // Number of NACKed RTP packets. - uint32_t unique_nack_requests; // Number of unique NACKed RTP packets. -}; - -class RtcpPacketTypeCounterObserver { - public: - virtual ~RtcpPacketTypeCounterObserver() {} - virtual void RtcpPacketTypesCounterUpdated( - uint32_t ssrc, - const RtcpPacketTypeCounter& packet_counter) = 0; -}; - // Callback, used to notify an observer whenever new rates have been estimated. class BitrateStatisticsObserver { public: diff --git a/modules/rtp_rtcp/include/rtcp_statistics.h b/modules/rtp_rtcp/include/rtcp_statistics.h index e1d576de2d..e78a875784 100644 --- a/modules/rtp_rtcp/include/rtcp_statistics.h +++ b/modules/rtp_rtcp/include/rtcp_statistics.h @@ -32,5 +32,71 @@ class RtcpStatisticsCallback { virtual void CNameChanged(const char* cname, uint32_t ssrc) = 0; }; +// Statistics for RTCP packet types. +struct RtcpPacketTypeCounter { + RtcpPacketTypeCounter() + : first_packet_time_ms(-1), + nack_packets(0), + fir_packets(0), + pli_packets(0), + nack_requests(0), + unique_nack_requests(0) {} + + void Add(const RtcpPacketTypeCounter& other) { + nack_packets += other.nack_packets; + fir_packets += other.fir_packets; + pli_packets += other.pli_packets; + nack_requests += other.nack_requests; + unique_nack_requests += other.unique_nack_requests; + if (other.first_packet_time_ms != -1 && + (other.first_packet_time_ms < first_packet_time_ms || + first_packet_time_ms == -1)) { + // Use oldest time. + first_packet_time_ms = other.first_packet_time_ms; + } + } + + void Subtract(const RtcpPacketTypeCounter& other) { + nack_packets -= other.nack_packets; + fir_packets -= other.fir_packets; + pli_packets -= other.pli_packets; + nack_requests -= other.nack_requests; + unique_nack_requests -= other.unique_nack_requests; + if (other.first_packet_time_ms != -1 && + (other.first_packet_time_ms > first_packet_time_ms || + first_packet_time_ms == -1)) { + // Use youngest time. + first_packet_time_ms = other.first_packet_time_ms; + } + } + + int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const { + return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms); + } + + int UniqueNackRequestsInPercent() const { + if (nack_requests == 0) { + return 0; + } + return static_cast((unique_nack_requests * 100.0f / nack_requests) + + 0.5f); + } + + int64_t first_packet_time_ms; // Time when first packet is sent/received. + uint32_t nack_packets; // Number of RTCP NACK packets. + uint32_t fir_packets; // Number of RTCP FIR packets. + uint32_t pli_packets; // Number of RTCP PLI packets. + uint32_t nack_requests; // Number of NACKed RTP packets. + uint32_t unique_nack_requests; // Number of unique NACKed RTP packets. +}; + +class RtcpPacketTypeCounterObserver { + public: + virtual ~RtcpPacketTypeCounterObserver() {} + virtual void RtcpPacketTypesCounterUpdated( + uint32_t ssrc, + const RtcpPacketTypeCounter& packet_counter) = 0; +}; + } // namespace webrtc #endif // MODULES_RTP_RTCP_INCLUDE_RTCP_STATISTICS_H_