1 /* 2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_RTP_RTCP_INCLUDE_RTCP_STATISTICS_H_ 12 #define MODULES_RTP_RTCP_INCLUDE_RTCP_STATISTICS_H_ 13 14 #include <stdint.h> 15 16 #include "absl/strings/string_view.h" 17 18 namespace webrtc { 19 20 // Statistics for RTCP packet types. 21 struct RtcpPacketTypeCounter { RtcpPacketTypeCounterRtcpPacketTypeCounter22 RtcpPacketTypeCounter() 23 : nack_packets(0), 24 fir_packets(0), 25 pli_packets(0), 26 nack_requests(0), 27 unique_nack_requests(0) {} 28 AddRtcpPacketTypeCounter29 void Add(const RtcpPacketTypeCounter& other) { 30 nack_packets += other.nack_packets; 31 fir_packets += other.fir_packets; 32 pli_packets += other.pli_packets; 33 nack_requests += other.nack_requests; 34 unique_nack_requests += other.unique_nack_requests; 35 } 36 SubtractRtcpPacketTypeCounter37 void Subtract(const RtcpPacketTypeCounter& other) { 38 nack_packets -= other.nack_packets; 39 fir_packets -= other.fir_packets; 40 pli_packets -= other.pli_packets; 41 nack_requests -= other.nack_requests; 42 unique_nack_requests -= other.unique_nack_requests; 43 } 44 UniqueNackRequestsInPercentRtcpPacketTypeCounter45 int UniqueNackRequestsInPercent() const { 46 if (nack_requests == 0) { 47 return 0; 48 } 49 return static_cast<int>((unique_nack_requests * 100.0f / nack_requests) + 50 0.5f); 51 } 52 53 uint32_t nack_packets; // Number of RTCP NACK packets. 54 uint32_t fir_packets; // Number of RTCP FIR packets. 55 uint32_t pli_packets; // Number of RTCP PLI packets. 56 uint32_t nack_requests; // Number of NACKed RTP packets. 57 uint32_t unique_nack_requests; // Number of unique NACKed RTP packets. 58 }; 59 60 class RtcpPacketTypeCounterObserver { 61 public: ~RtcpPacketTypeCounterObserver()62 virtual ~RtcpPacketTypeCounterObserver() {} 63 virtual void RtcpPacketTypesCounterUpdated( 64 uint32_t ssrc, 65 const RtcpPacketTypeCounter& packet_counter) = 0; 66 }; 67 68 // Invoked for each cname passed in RTCP SDES blocks. 69 class RtcpCnameCallback { 70 public: 71 virtual ~RtcpCnameCallback() = default; 72 73 virtual void OnCname(uint32_t ssrc, absl::string_view cname) = 0; 74 }; 75 76 } // namespace webrtc 77 #endif // MODULES_RTP_RTCP_INCLUDE_RTCP_STATISTICS_H_ 78