blob: cdf4cbadf8cf0da2bf1a27168ba6cb1b5308bd0f [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_
12#define MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +020014#include <list>
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +000015#include <map>
danilchap95321242016-09-27 07:05:32 -070016#include <string>
danilchapb8b6fbb2015-12-10 05:05:27 -080017#include <vector>
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +000018
Ivo Creusen2562cf02021-09-03 14:51:22 +000019#include "absl/types/optional.h"
Danil Chapovalov443f2662020-03-11 12:24:40 +010020#include "api/array_view.h"
Tommi08be9ba2021-06-15 23:01:57 +020021#include "api/sequence_checker.h"
Ivo Creusen2562cf02021-09-03 14:51:22 +000022#include "api/units/time_delta.h"
Henrik Boströmf2047872019-05-16 13:32:20 +020023#include "modules/rtp_rtcp/include/report_block_data.h"
Niels Möller53382cb2018-11-27 14:05:08 +010024#include "modules/rtp_rtcp/include/rtcp_statistics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
26#include "modules/rtp_rtcp/source/rtcp_nack_stats.h"
27#include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
Stephan Hartmann26946722021-05-03 11:06:23 +000028#include "modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h"
Tomas Gunnarssonf25761d2020-06-03 22:55:33 +020029#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
Victor Boivief7156182021-07-06 23:14:51 +020030#include "rtc_base/containers/flat_map.h"
Markus Handelle7c015e2020-07-07 11:44:28 +020031#include "rtc_base/synchronization/mutex.h"
Tommi08be9ba2021-06-15 23:01:57 +020032#include "rtc_base/system/no_unique_address.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "rtc_base/thread_annotations.h"
34#include "system_wrappers/include/ntp_time.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000035
36namespace webrtc {
Tommi08be9ba2021-06-15 23:01:57 +020037
38class ModuleRtpRtcpImpl2;
spranga790d832016-12-02 07:29:44 -080039class VideoBitrateAllocationObserver;
Tommi08be9ba2021-06-15 23:01:57 +020040
danilchap59cb2bd2016-08-29 11:08:47 -070041namespace rtcp {
danilchap1b1863a2016-09-20 01:39:54 -070042class CommonHeader;
danilchap1b1863a2016-09-20 01:39:54 -070043class ReportBlock;
44class Rrtr;
spranga790d832016-12-02 07:29:44 -080045class TargetBitrate;
danilchap59cb2bd2016-08-29 11:08:47 -070046class TmmbItem;
47} // namespace rtcp
pwestin@webrtc.org741da942011-09-20 13:52:04 +000048
Danil Chapovalov443f2662020-03-11 12:24:40 +010049class RTCPReceiver final {
danilchapda161d72016-08-19 07:29:46 -070050 public:
danilchap59cb2bd2016-08-29 11:08:47 -070051 class ModuleRtpRtcp {
52 public:
53 virtual void SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) = 0;
54 virtual void OnRequestSendReport() = 0;
55 virtual void OnReceivedNack(
56 const std::vector<uint16_t>& nack_sequence_numbers) = 0;
57 virtual void OnReceivedRtcpReportBlocks(
58 const ReportBlockList& report_blocks) = 0;
59
60 protected:
61 virtual ~ModuleRtpRtcp() = default;
62 };
Ivo Creusen2562cf02021-09-03 14:51:22 +000063 // Standardized stats derived from the non-sender RTT.
64 class NonSenderRttStats {
65 public:
66 NonSenderRttStats() = default;
67 NonSenderRttStats(const NonSenderRttStats&) = default;
68 NonSenderRttStats& operator=(const NonSenderRttStats&) = default;
69 ~NonSenderRttStats() = default;
70 void Update(TimeDelta non_sender_rtt_seconds) {
71 round_trip_time_ = non_sender_rtt_seconds;
72 total_round_trip_time_ += non_sender_rtt_seconds;
73 round_trip_time_measurements_++;
74 }
75 void Invalidate() { round_trip_time_.reset(); }
76 // https://www.w3.org/TR/webrtc-stats/#dom-rtcremoteoutboundrtpstreamstats-roundtriptime
77 absl::optional<TimeDelta> round_trip_time() const {
78 return round_trip_time_;
79 }
80 // https://www.w3.org/TR/webrtc-stats/#dom-rtcremoteoutboundrtpstreamstats-totalroundtriptime
81 TimeDelta total_round_trip_time() const { return total_round_trip_time_; }
82 // https://www.w3.org/TR/webrtc-stats/#dom-rtcremoteoutboundrtpstreamstats-roundtriptimemeasurements
83 int round_trip_time_measurements() const {
84 return round_trip_time_measurements_;
85 }
86
87 private:
88 absl::optional<TimeDelta> round_trip_time_;
89 TimeDelta total_round_trip_time_ = TimeDelta::Zero();
90 int round_trip_time_measurements_ = 0;
91 };
danilchap59cb2bd2016-08-29 11:08:47 -070092
Tomas Gunnarssonf25761d2020-06-03 22:55:33 +020093 RTCPReceiver(const RtpRtcpInterface::Configuration& config,
94 ModuleRtpRtcp* owner);
Tommi08be9ba2021-06-15 23:01:57 +020095
96 RTCPReceiver(const RtpRtcpInterface::Configuration& config,
97 ModuleRtpRtcpImpl2* owner);
98
Danil Chapovalov443f2662020-03-11 12:24:40 +010099 ~RTCPReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
Danil Chapovalov443f2662020-03-11 12:24:40 +0100101 void IncomingPacket(const uint8_t* packet, size_t packet_size) {
102 IncomingPacket(rtc::MakeArrayView(packet, packet_size));
103 }
104 void IncomingPacket(rtc::ArrayView<const uint8_t> packet);
danilchap59cb2bd2016-08-29 11:08:47 -0700105
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200106 int64_t LastReceivedReportBlockMs() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
Tommi08be9ba2021-06-15 23:01:57 +0200108 void set_local_media_ssrc(uint32_t ssrc);
109 uint32_t local_media_ssrc() const;
110
danilchapda161d72016-08-19 07:29:46 -0700111 void SetRemoteSSRC(uint32_t ssrc);
112 uint32_t RemoteSSRC() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
Tommi08be9ba2021-06-15 23:01:57 +0200114 bool receiver_only() const { return receiver_only_; }
115
danilchap8bab7962016-12-20 02:46:46 -0800116 // Get received NTP.
Alessio Bazzica048adc72021-03-10 15:05:55 +0100117 // The types for the arguments below derive from the specification:
118 // - `remote_sender_packet_count`: `RTCSentRtpStreamStats.packetsSent` [1]
119 // - `remote_sender_octet_count`: `RTCSentRtpStreamStats.bytesSent` [1]
120 // - `remote_sender_reports_count`:
121 // `RTCRemoteOutboundRtpStreamStats.reportsSent` [2]
122 // [1] https://www.w3.org/TR/webrtc-stats/#remoteoutboundrtpstats-dict*
123 // [2] https://www.w3.org/TR/webrtc-stats/#dom-rtcsentrtpstreamstats
danilchap8bab7962016-12-20 02:46:46 -0800124 bool NTP(uint32_t* received_ntp_secs,
125 uint32_t* received_ntp_frac,
126 uint32_t* rtcp_arrival_time_secs,
127 uint32_t* rtcp_arrival_time_frac,
Alessio Bazzica048adc72021-03-10 15:05:55 +0100128 uint32_t* rtcp_timestamp,
129 uint32_t* remote_sender_packet_count,
130 uint64_t* remote_sender_octet_count,
131 uint64_t* remote_sender_reports_count) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +0200133 std::vector<rtcp::ReceiveTimeInfo> ConsumeReceivedXrReferenceTimeInfo();
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000134
danilchap28b03eb2016-10-05 06:59:44 -0700135 // Get rtt.
136 int32_t RTT(uint32_t remote_ssrc,
137 int64_t* last_rtt_ms,
138 int64_t* avg_rtt_ms,
139 int64_t* min_rtt_ms,
140 int64_t* max_rtt_ms) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
Ivo Creusen2562cf02021-09-03 14:51:22 +0000142 // Returns non-sender RTT metrics for the remote SSRC.
143 NonSenderRttStats GetNonSenderRTT() const;
144
Ivo Creusen8c40d512021-07-13 12:53:22 +0000145 void SetNonSenderRttMeasurement(bool enabled);
danilchapda161d72016-08-19 07:29:46 -0700146 bool GetAndResetXrRrRtt(int64_t* rtt_ms);
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000147
Tomas Gunnarssonba0ba712020-07-01 08:53:21 +0200148 // Called once per second on the worker thread to do rtt calculations.
149 // Returns an optional rtt value if one is available.
150 absl::optional<TimeDelta> OnPeriodicRttUpdate(Timestamp newer_than,
151 bool sending);
152
Henrik Boströmf2047872019-05-16 13:32:20 +0200153 // A snapshot of Report Blocks with additional data of interest to statistics.
Danil Chapovalov510c94c2021-07-02 13:51:19 +0200154 // Within this list, the source SSRC is unique and ReportBlockData represents
155 // the latest Report Block that was received for that SSRC.
Henrik Boströmf2047872019-05-16 13:32:20 +0200156 std::vector<ReportBlockData> GetLatestReportBlockData() const;
perkj@webrtc.orgce5990c2012-01-11 13:00:08 +0000157
danilchapda161d72016-08-19 07:29:46 -0700158 // Returns true if we haven't received an RTCP RR for several RTCP
159 // intervals, but only triggers true once.
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800160 bool RtcpRrTimeout();
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000161
danilchapda161d72016-08-19 07:29:46 -0700162 // Returns true if we haven't received an RTCP RR telling the receive side
163 // has not received RTP packets for too long, i.e. extended highest sequence
164 // number hasn't increased for several RTCP intervals. The function only
165 // returns true once until a new RR is received.
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800166 bool RtcpRrSequenceNumberTimeout();
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000167
danilchap7851bda2016-09-29 15:28:07 -0700168 std::vector<rtcp::TmmbItem> TmmbrReceived();
danilchap9bf610e2017-02-20 06:03:01 -0800169 // Return true if new bandwidth should be set.
170 bool UpdateTmmbrTimers();
danilchapda161d72016-08-19 07:29:46 -0700171 std::vector<rtcp::TmmbItem> BoundingSet(bool* tmmbr_owner);
danilchap9bf610e2017-02-20 06:03:01 -0800172 // Set new bandwidth and notify remote clients about it.
173 void NotifyTmmbrUpdated();
niklase@google.com470e71d2011-07-07 08:21:25 +0000174
danilchapdd128922016-09-13 12:23:29 -0700175 private:
Tommi08be9ba2021-06-15 23:01:57 +0200176#if RTC_DCHECK_IS_ON
177 class CustomSequenceChecker : public SequenceChecker {
Victor Boivie306b1392021-04-27 10:33:58 +0200178 public:
Tommi08be9ba2021-06-15 23:01:57 +0200179 explicit CustomSequenceChecker(bool disable_checks)
180 : disable_checks_(disable_checks) {}
181 bool IsCurrent() const {
182 if (disable_checks_)
183 return true;
184 return SequenceChecker::IsCurrent();
Victor Boivie306b1392021-04-27 10:33:58 +0200185 }
186
187 private:
Tommi08be9ba2021-06-15 23:01:57 +0200188 const bool disable_checks_;
189 };
190#else
191 class CustomSequenceChecker : public SequenceChecker {
192 public:
193 explicit CustomSequenceChecker(bool) {}
194 };
195#endif
196
197 // A lightweight inlined set of local SSRCs.
198 class RegisteredSsrcs {
199 public:
200 static constexpr size_t kMediaSsrcIndex = 0;
201 static constexpr size_t kMaxSsrcs = 3;
202 // Initializes the set of registered local SSRCS by extracting them from the
203 // provided `config`. The `disable_sequence_checker` flag is a workaround
204 // to be able to use a sequence checker without breaking downstream
205 // code that currently doesn't follow the same threading rules as webrtc.
206 RegisteredSsrcs(bool disable_sequence_checker,
207 const RtpRtcpInterface::Configuration& config);
208
209 // Indicates if `ssrc` is in the set of registered local SSRCs.
210 bool contains(uint32_t ssrc) const;
211 uint32_t media_ssrc() const;
212 void set_media_ssrc(uint32_t ssrc);
213
214 private:
215 RTC_NO_UNIQUE_ADDRESS CustomSequenceChecker packet_sequence_checker_;
216 absl::InlinedVector<uint32_t, kMaxSsrcs> ssrcs_
217 RTC_GUARDED_BY(packet_sequence_checker_);
Victor Boivie306b1392021-04-27 10:33:58 +0200218 };
219
danilchap92ea6012016-09-23 10:36:03 -0700220 struct PacketInformation;
Stephan Hartmann26946722021-05-03 11:06:23 +0000221
222 // Structure for handing TMMBR and TMMBN rtcp messages (RFC5104,
223 // section 3.5.4).
224 struct TmmbrInformation {
225 struct TimedTmmbrItem {
226 rtcp::TmmbItem tmmbr_item;
227 int64_t last_updated_ms;
228 };
229
230 int64_t last_time_received_ms = 0;
231
232 bool ready_for_delete = false;
233
234 std::vector<rtcp::TmmbItem> tmmbn;
235 std::map<uint32_t, TimedTmmbrItem> tmmbr;
236 };
237
238 // Structure for storing received RRTR RTCP messages (RFC3611, section 4.4).
239 struct RrtrInformation {
240 RrtrInformation(uint32_t ssrc,
241 uint32_t received_remote_mid_ntp_time,
242 uint32_t local_receive_mid_ntp_time)
243 : ssrc(ssrc),
244 received_remote_mid_ntp_time(received_remote_mid_ntp_time),
245 local_receive_mid_ntp_time(local_receive_mid_ntp_time) {}
246
247 uint32_t ssrc;
248 // Received NTP timestamp in compact representation.
249 uint32_t received_remote_mid_ntp_time;
250 // NTP time when the report was received in compact representation.
251 uint32_t local_receive_mid_ntp_time;
252 };
253
254 struct LastFirStatus {
255 LastFirStatus(int64_t now_ms, uint8_t sequence_number)
256 : request_ms(now_ms), sequence_number(sequence_number) {}
257 int64_t request_ms;
258 uint8_t sequence_number;
259 };
Victor Boivie0c563a42021-04-27 10:24:01 +0200260
Danil Chapovalov510c94c2021-07-02 13:51:19 +0200261 class RttStats {
262 public:
263 RttStats() = default;
264 RttStats(const RttStats&) = default;
265 RttStats& operator=(const RttStats&) = default;
Victor Boivie0c563a42021-04-27 10:24:01 +0200266
Danil Chapovalov510c94c2021-07-02 13:51:19 +0200267 void AddRtt(TimeDelta rtt);
268
269 TimeDelta last_rtt() const { return last_rtt_; }
270 TimeDelta min_rtt() const { return min_rtt_; }
271 TimeDelta max_rtt() const { return max_rtt_; }
272 TimeDelta average_rtt() const { return sum_rtt_ / num_rtts_; }
273
274 private:
275 TimeDelta last_rtt_ = TimeDelta::Zero();
276 TimeDelta min_rtt_ = TimeDelta::PlusInfinity();
277 TimeDelta max_rtt_ = TimeDelta::MinusInfinity();
278 TimeDelta sum_rtt_ = TimeDelta::Zero();
279 size_t num_rtts_ = 0;
280 };
danilchapdd128922016-09-13 12:23:29 -0700281
Danil Chapovalov443f2662020-03-11 12:24:40 +0100282 bool ParseCompoundPacket(rtc::ArrayView<const uint8_t> packet,
danilchap92ea6012016-09-23 10:36:03 -0700283 PacketInformation* packet_information);
danilchapdd128922016-09-13 12:23:29 -0700284
danilchap8bab7962016-12-20 02:46:46 -0800285 void TriggerCallbacksFromRtcpPacket(
danilchap92ea6012016-09-23 10:36:03 -0700286 const PacketInformation& packet_information);
danilchapdd128922016-09-13 12:23:29 -0700287
danilchapec067e92017-02-21 05:38:19 -0800288 TmmbrInformation* FindOrCreateTmmbrInfo(uint32_t remote_ssrc)
danilchap56359be2017-09-07 07:53:45 -0700289 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
danilchapec067e92017-02-21 05:38:19 -0800290 // Update TmmbrInformation (if present) is alive.
291 void UpdateTmmbrRemoteIsAlive(uint32_t remote_ssrc)
danilchap56359be2017-09-07 07:53:45 -0700292 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
danilchap9bf610e2017-02-20 06:03:01 -0800293 TmmbrInformation* GetTmmbrInformation(uint32_t remote_ssrc)
danilchap56359be2017-09-07 07:53:45 -0700294 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
danilchap92ea6012016-09-23 10:36:03 -0700296 void HandleSenderReport(const rtcp::CommonHeader& rtcp_block,
297 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700298 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
Danil Chapovalov91511f12016-09-15 16:24:02 +0200299
danilchap92ea6012016-09-23 10:36:03 -0700300 void HandleReceiverReport(const rtcp::CommonHeader& rtcp_block,
301 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700302 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000303
danilchap1b1863a2016-09-20 01:39:54 -0700304 void HandleReportBlock(const rtcp::ReportBlock& report_block,
danilchap92ea6012016-09-23 10:36:03 -0700305 PacketInformation* packet_information,
danilchap8bab7962016-12-20 02:46:46 -0800306 uint32_t remote_ssrc)
danilchap56359be2017-09-07 07:53:45 -0700307 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000308
danilchap8bab7962016-12-20 02:46:46 -0800309 void HandleSdes(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700310 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700311 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000312
danilchap1b1863a2016-09-20 01:39:54 -0700313 void HandleXr(const rtcp::CommonHeader& rtcp_block,
Ivo Creusen2562cf02021-09-03 14:51:22 +0000314 PacketInformation* packet_information,
315 bool& contains_dlrr,
316 uint32_t& ssrc)
danilchap56359be2017-09-07 07:53:45 -0700317 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000318
danilchap92ea6012016-09-23 10:36:03 -0700319 void HandleXrReceiveReferenceTime(uint32_t sender_ssrc,
320 const rtcp::Rrtr& rrtr)
danilchap56359be2017-09-07 07:53:45 -0700321 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000322
Ivo Creusen2562cf02021-09-03 14:51:22 +0000323 void HandleXrDlrrReportBlock(uint32_t ssrc, const rtcp::ReceiveTimeInfo& rti)
danilchap56359be2017-09-07 07:53:45 -0700324 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
danilchapda161d72016-08-19 07:29:46 -0700325
sprangb32aaf92017-08-28 05:49:12 -0700326 void HandleXrTargetBitrate(uint32_t ssrc,
327 const rtcp::TargetBitrate& target_bitrate,
spranga790d832016-12-02 07:29:44 -0800328 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700329 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
spranga790d832016-12-02 07:29:44 -0800330
danilchap8bab7962016-12-20 02:46:46 -0800331 void HandleNack(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700332 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700333 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
danilchapda161d72016-08-19 07:29:46 -0700334
Sebastian Janssone1795f42019-07-24 11:38:03 +0200335 void HandleApp(const rtcp::CommonHeader& rtcp_block,
336 PacketInformation* packet_information)
337 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
338
danilchap8bab7962016-12-20 02:46:46 -0800339 void HandleBye(const rtcp::CommonHeader& rtcp_block)
danilchap56359be2017-09-07 07:53:45 -0700340 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
danilchapda161d72016-08-19 07:29:46 -0700341
danilchap8bab7962016-12-20 02:46:46 -0800342 void HandlePli(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700343 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700344 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
danilchapda161d72016-08-19 07:29:46 -0700345
danilchap1b1863a2016-09-20 01:39:54 -0700346 void HandlePsfbApp(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700347 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700348 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
danilchapda161d72016-08-19 07:29:46 -0700349
danilchap8bab7962016-12-20 02:46:46 -0800350 void HandleTmmbr(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700351 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700352 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000353
danilchap8bab7962016-12-20 02:46:46 -0800354 void HandleTmmbn(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700355 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700356 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000357
danilchap8bab7962016-12-20 02:46:46 -0800358 void HandleSrReq(const rtcp::CommonHeader& rtcp_block,
359 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700360 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000361
danilchap8bab7962016-12-20 02:46:46 -0800362 void HandleFir(const rtcp::CommonHeader& rtcp_block,
danilchap92ea6012016-09-23 10:36:03 -0700363 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700364 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
danilchapda161d72016-08-19 07:29:46 -0700365
danilchap92ea6012016-09-23 10:36:03 -0700366 void HandleTransportFeedback(const rtcp::CommonHeader& rtcp_block,
367 PacketInformation* packet_information)
danilchap56359be2017-09-07 07:53:45 -0700368 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
Erik Språng6b8d3552015-09-24 15:06:57 +0200369
Tomas Gunnarssonba0ba712020-07-01 08:53:21 +0200370 bool RtcpRrTimeoutLocked(Timestamp now)
371 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
372
373 bool RtcpRrSequenceNumberTimeoutLocked(Timestamp now)
374 RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_);
375
danilchap8bab7962016-12-20 02:46:46 -0800376 Clock* const clock_;
Peter Boströmfe7a80c2015-04-23 17:53:17 +0200377 const bool receiver_only_;
danilchap8bab7962016-12-20 02:46:46 -0800378 ModuleRtpRtcp* const rtp_rtcp_;
Victor Boivie306b1392021-04-27 10:33:58 +0200379 // The set of registered local SSRCs.
Tommi08be9ba2021-06-15 23:01:57 +0200380 RegisteredSsrcs registered_ssrcs_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000381
spranga790d832016-12-02 07:29:44 -0800382 RtcpBandwidthObserver* const rtcp_bandwidth_observer_;
383 RtcpIntraFrameObserver* const rtcp_intra_frame_observer_;
Elad Alon0a8562e2019-04-09 11:55:13 +0200384 RtcpLossNotificationObserver* const rtcp_loss_notification_observer_;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200385 NetworkStateEstimateObserver* const network_state_estimate_observer_;
spranga790d832016-12-02 07:29:44 -0800386 TransportFeedbackObserver* const transport_feedback_observer_;
387 VideoBitrateAllocationObserver* const bitrate_allocation_observer_;
Tomas Gunnarssonba0ba712020-07-01 08:53:21 +0200388 const TimeDelta report_interval_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000389
Markus Handelle7c015e2020-07-07 11:44:28 +0200390 mutable Mutex rtcp_receiver_lock_;
danilchap56359be2017-09-07 07:53:45 -0700391 uint32_t remote_ssrc_ RTC_GUARDED_BY(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000392
danilchap8bab7962016-12-20 02:46:46 -0800393 // Received sender report.
danilchap56359be2017-09-07 07:53:45 -0700394 NtpTime remote_sender_ntp_time_ RTC_GUARDED_BY(rtcp_receiver_lock_);
395 uint32_t remote_sender_rtp_time_ RTC_GUARDED_BY(rtcp_receiver_lock_);
danilchap0b4b7272016-10-06 09:24:45 -0700396 // When did we receive the last send report.
danilchap56359be2017-09-07 07:53:45 -0700397 NtpTime last_received_sr_ntp_ RTC_GUARDED_BY(rtcp_receiver_lock_);
Alessio Bazzica048adc72021-03-10 15:05:55 +0100398 uint32_t remote_sender_packet_count_ RTC_GUARDED_BY(rtcp_receiver_lock_);
399 uint64_t remote_sender_octet_count_ RTC_GUARDED_BY(rtcp_receiver_lock_);
400 uint64_t remote_sender_reports_count_ RTC_GUARDED_BY(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000401
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +0200402 // Received RRTR information in ascending receive time order.
403 std::list<RrtrInformation> received_rrtrs_
404 RTC_GUARDED_BY(rtcp_receiver_lock_);
405 // Received RRTR information mapped by remote ssrc.
Victor Boivief7156182021-07-06 23:14:51 +0200406 flat_map<uint32_t, std::list<RrtrInformation>::iterator>
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +0200407 received_rrtrs_ssrc_it_ RTC_GUARDED_BY(rtcp_receiver_lock_);
408
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000409 // Estimated rtt, zero when there is no valid estimate.
Ivo Creusen8c40d512021-07-13 12:53:22 +0000410 bool xr_rrtr_status_ RTC_GUARDED_BY(rtcp_receiver_lock_);
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000411 int64_t xr_rr_rtt_ms_;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000412
danilchap56359be2017-09-07 07:53:45 -0700413 int64_t oldest_tmmbr_info_ms_ RTC_GUARDED_BY(rtcp_receiver_lock_);
danilchap9bf610e2017-02-20 06:03:01 -0800414 // Mapped by remote ssrc.
Victor Boivief7156182021-07-06 23:14:51 +0200415 flat_map<uint32_t, TmmbrInformation> tmmbr_infos_
danilchap56359be2017-09-07 07:53:45 -0700416 RTC_GUARDED_BY(rtcp_receiver_lock_);
danilchap9bf610e2017-02-20 06:03:01 -0800417
Danil Chapovalov510c94c2021-07-02 13:51:19 +0200418 // Round-Trip Time per remote sender ssrc.
Victor Boivief7156182021-07-06 23:14:51 +0200419 flat_map<uint32_t, RttStats> rtts_ RTC_GUARDED_BY(rtcp_receiver_lock_);
Ivo Creusen2562cf02021-09-03 14:51:22 +0000420 // Non-sender Round-trip time per remote ssrc.
421 flat_map<uint32_t, NonSenderRttStats> non_sender_rtts_
422 RTC_GUARDED_BY(rtcp_receiver_lock_);
Danil Chapovalov510c94c2021-07-02 13:51:19 +0200423
424 // Report blocks per local source ssrc.
Victor Boivief7156182021-07-06 23:14:51 +0200425 flat_map<uint32_t, ReportBlockData> received_report_blocks_
Danil Chapovalov510c94c2021-07-02 13:51:19 +0200426 RTC_GUARDED_BY(rtcp_receiver_lock_);
Victor Boivief7156182021-07-06 23:14:51 +0200427 flat_map<uint32_t, LastFirStatus> last_fir_
danilchap56359be2017-09-07 07:53:45 -0700428 RTC_GUARDED_BY(rtcp_receiver_lock_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000429
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200430 // The last time we received an RTCP Report block for this module.
Tomas Gunnarssonba0ba712020-07-01 08:53:21 +0200431 Timestamp last_received_rb_ RTC_GUARDED_BY(rtcp_receiver_lock_) =
432 Timestamp::PlusInfinity();
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000433
asapersson@webrtc.orgcb791412014-12-18 14:30:32 +0000434 // The time we last received an RTCP RR telling we have successfully
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000435 // delivered RTP packet to the remote side.
Tomas Gunnarssonba0ba712020-07-01 08:53:21 +0200436 Timestamp last_increased_sequence_number_ = Timestamp::PlusInfinity();
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000437
Danil Chapovalovbd74d5c2020-03-12 09:22:44 +0100438 RtcpCnameCallback* const cname_callback_;
Danil Chapovalovbd74d5c2020-03-12 09:22:44 +0100439 ReportBlockDataObserver* const report_block_data_observer_;
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000440
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000441 RtcpPacketTypeCounterObserver* const packet_type_counter_observer_;
asapersson@webrtc.org8098e072014-02-19 11:59:02 +0000442 RtcpPacketTypeCounter packet_type_counter_;
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000443
danilchap84432382017-02-09 05:21:42 -0800444 RtcpNackStats nack_stats_;
Erik Språng6b8d3552015-09-24 15:06:57 +0200445
446 size_t num_skipped_packets_;
danilchap8bab7962016-12-20 02:46:46 -0800447 int64_t last_skipped_packets_warning_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000448};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000449} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200450#endif // MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_