xref: /aosp_15_r20/external/webrtc/video/report_block_stats.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2014 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 VIDEO_REPORT_BLOCK_STATS_H_
12 #define VIDEO_REPORT_BLOCK_STATS_H_
13 
14 #include <stdint.h>
15 
16 #include <map>
17 
18 namespace webrtc {
19 
20 // TODO(nisse): Usefulness of this class is somewhat unclear. The inputs are
21 // cumulative counters, from which we compute deltas, and then accumulate the
22 // deltas. May be needed on the send side, to handle wraparound in the short
23 // counters received over RTCP, but should not be needed on the receive side
24 // where we can use large enough types for all counters we need.
25 
26 // Helper class for rtcp statistics.
27 class ReportBlockStats {
28  public:
29   ReportBlockStats();
30   ~ReportBlockStats();
31 
32   // Updates stats and stores report block.
33   void Store(uint32_t ssrc,
34              int packets_lost,
35              uint32_t extended_highest_sequence_number);
36 
37   // Returns the total fraction of lost packets (or -1 if less than two report
38   // blocks have been stored).
39   int FractionLostInPercent() const;
40 
41  private:
42   // The information from an RTCP report block that we need.
43   struct Report {
44     uint32_t extended_highest_sequence_number;
45     int32_t packets_lost;
46   };
47 
48   // The total number of packets/lost packets.
49   uint32_t num_sequence_numbers_;
50   uint32_t num_lost_sequence_numbers_;
51 
52   // Map holding the last stored report (mapped by the source SSRC).
53   std::map<uint32_t, Report> prev_reports_;
54 };
55 
56 }  // namespace webrtc
57 
58 #endif  // VIDEO_REPORT_BLOCK_STATS_H_
59