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 #include "modules/rtp_rtcp/include/rtcp_statistics.h"
19 
20 namespace webrtc {
21 
22 // TODO(nisse): Usefulness of this class is somewhat unclear. The inputs are
23 // cumulative counters, from which we compute deltas, and then accumulate the
24 // deltas. May be needed on the send side, to handle wraparound in the short
25 // counters received over RTCP, but should not be needed on the receive side
26 // where we can use large enough types for all counters we need.
27 
28 // Helper class for rtcp statistics.
29 class ReportBlockStats {
30  public:
31   ReportBlockStats();
32   ~ReportBlockStats();
33 
34   // Updates stats and stores report block.
35   void Store(uint32_t ssrc, const RtcpStatistics& rtcp_stats);
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   // Updates the total number of packets/lost packets.
49   // Stores the report.
50   void StoreAndAddPacketIncrement(uint32_t ssrc, const Report& report);
51 
52   // The total number of packets/lost packets.
53   uint32_t num_sequence_numbers_;
54   uint32_t num_lost_sequence_numbers_;
55 
56   // Map holding the last stored report (mapped by the source SSRC).
57   std::map<uint32_t, Report> prev_reports_;
58 };
59 
60 }  // namespace webrtc
61 
62 #endif  // VIDEO_REPORT_BLOCK_STATS_H_
63