receive_statistics.h (2783B)
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 <cstddef> 15 #include <cstdint> 16 #include <memory> 17 #include <optional> 18 #include <vector> 19 20 #include "call/rtp_packet_sink_interface.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 std::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 // Sets the max reordering threshold in number of packets. 70 virtual void SetMaxReorderingThreshold(uint32_t ssrc, 71 int max_reordering_threshold) = 0; 72 // Detect retransmissions, enabling updates of the retransmitted counters. The 73 // default is false. 74 virtual void EnableRetransmitDetection(uint32_t ssrc, bool enable) = 0; 75 }; 76 77 } // namespace webrtc 78 #endif // MODULES_RTP_RTCP_INCLUDE_RECEIVE_STATISTICS_H_