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