xref: /aosp_15_r20/external/webrtc/modules/rtp_rtcp/include/receive_statistics.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2013 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_RECEIVE_STATISTICS_H_
12 #define MODULES_RTP_RTCP_INCLUDE_RECEIVE_STATISTICS_H_
13 
14 #include <map>
15 #include <memory>
16 #include <vector>
17 
18 #include "absl/types/optional.h"
19 #include "call/rtp_packet_sink_interface.h"
20 #include "modules/rtp_rtcp/include/rtcp_statistics.h"
21 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
22 #include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
23 
24 namespace webrtc {
25 
26 class Clock;
27 
28 class ReceiveStatisticsProvider {
29  public:
30   virtual ~ReceiveStatisticsProvider() = default;
31   // Collects receive statistic in a form of rtcp report blocks.
32   // Returns at most `max_blocks` report blocks.
33   virtual std::vector<rtcp::ReportBlock> RtcpReportBlocks(
34       size_t max_blocks) = 0;
35 };
36 
37 class StreamStatistician {
38  public:
39   virtual ~StreamStatistician();
40 
41   virtual RtpReceiveStats GetStats() const = 0;
42 
43   // Returns average over the stream life time.
44   virtual absl::optional<int> GetFractionLostInPercent() const = 0;
45 
46   // TODO(bugs.webrtc.org/10679): Delete, migrate users to the above GetStats
47   // method (and extend RtpReceiveStats if needed).
48   // Gets receive stream data counters.
49   virtual StreamDataCounters GetReceiveStreamDataCounters() const = 0;
50 
51   virtual uint32_t BitrateReceived() const = 0;
52 };
53 
54 class ReceiveStatistics : public ReceiveStatisticsProvider,
55                           public RtpPacketSinkInterface {
56  public:
57   ~ReceiveStatistics() override = default;
58 
59   // Returns a thread-safe instance of ReceiveStatistics.
60   // https://chromium.googlesource.com/chromium/src/+/lkgr/docs/threading_and_tasks.md#threading-lexicon
61   static std::unique_ptr<ReceiveStatistics> Create(Clock* clock);
62   // Returns a thread-compatible instance of ReceiveStatistics.
63   static std::unique_ptr<ReceiveStatistics> CreateThreadCompatible(
64       Clock* clock);
65 
66   // Returns a pointer to the statistician of an ssrc.
67   virtual StreamStatistician* GetStatistician(uint32_t ssrc) const = 0;
68 
69   // TODO(bugs.webrtc.org/10669): Deprecated, delete as soon as downstream
70   // projects are updated. This method sets the max reordering threshold of all
71   // current and future streams.
72   virtual void SetMaxReorderingThreshold(int max_reordering_threshold) = 0;
73 
74   // Sets the max reordering threshold in number of packets.
75   virtual void SetMaxReorderingThreshold(uint32_t ssrc,
76                                          int max_reordering_threshold) = 0;
77   // Detect retransmissions, enabling updates of the retransmitted counters. The
78   // default is false.
79   virtual void EnableRetransmitDetection(uint32_t ssrc, bool enable) = 0;
80 };
81 
82 }  // namespace webrtc
83 #endif  // MODULES_RTP_RTCP_INCLUDE_RECEIVE_STATISTICS_H_
84