niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_ |
| 12 | #define MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Mirta Dvornicic | b1f063d | 2018-04-16 11:16:21 +0200 | [diff] [blame] | 14 | #include <list> |
pwestin@webrtc.org | 26f8d9c | 2012-01-19 15:53:09 +0000 | [diff] [blame] | 15 | #include <map> |
danilchap | 9532124 | 2016-09-27 07:05:32 -0700 | [diff] [blame] | 16 | #include <string> |
danilchap | b8b6fbb | 2015-12-10 05:05:27 -0800 | [diff] [blame] | 17 | #include <vector> |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 18 | |
Ivo Creusen | 2562cf0 | 2021-09-03 14:51:22 +0000 | [diff] [blame] | 19 | #include "absl/types/optional.h" |
Danil Chapovalov | 443f266 | 2020-03-11 12:24:40 +0100 | [diff] [blame] | 20 | #include "api/array_view.h" |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 21 | #include "api/sequence_checker.h" |
Ivo Creusen | 2562cf0 | 2021-09-03 14:51:22 +0000 | [diff] [blame] | 22 | #include "api/units/time_delta.h" |
Henrik Boström | f204787 | 2019-05-16 13:32:20 +0200 | [diff] [blame] | 23 | #include "modules/rtp_rtcp/include/report_block_data.h" |
Niels Möller | 53382cb | 2018-11-27 14:05:08 +0100 | [diff] [blame] | 24 | #include "modules/rtp_rtcp/include/rtcp_statistics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #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 Hartmann | 2694672 | 2021-05-03 11:06:23 +0000 | [diff] [blame] | 28 | #include "modules/rtp_rtcp/source/rtcp_packet/tmmb_item.h" |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 29 | #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" |
Victor Boivie | f715618 | 2021-07-06 23:14:51 +0200 | [diff] [blame] | 30 | #include "rtc_base/containers/flat_map.h" |
Markus Handell | e7c015e | 2020-07-07 11:44:28 +0200 | [diff] [blame] | 31 | #include "rtc_base/synchronization/mutex.h" |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 32 | #include "rtc_base/system/no_unique_address.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "rtc_base/thread_annotations.h" |
| 34 | #include "system_wrappers/include/ntp_time.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
| 36 | namespace webrtc { |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 37 | |
| 38 | class ModuleRtpRtcpImpl2; |
sprang | a790d83 | 2016-12-02 07:29:44 -0800 | [diff] [blame] | 39 | class VideoBitrateAllocationObserver; |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 40 | |
danilchap | 59cb2bd | 2016-08-29 11:08:47 -0700 | [diff] [blame] | 41 | namespace rtcp { |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 42 | class CommonHeader; |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 43 | class ReportBlock; |
| 44 | class Rrtr; |
sprang | a790d83 | 2016-12-02 07:29:44 -0800 | [diff] [blame] | 45 | class TargetBitrate; |
danilchap | 59cb2bd | 2016-08-29 11:08:47 -0700 | [diff] [blame] | 46 | class TmmbItem; |
| 47 | } // namespace rtcp |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 48 | |
Danil Chapovalov | 443f266 | 2020-03-11 12:24:40 +0100 | [diff] [blame] | 49 | class RTCPReceiver final { |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 50 | public: |
danilchap | 59cb2bd | 2016-08-29 11:08:47 -0700 | [diff] [blame] | 51 | 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 Creusen | 2562cf0 | 2021-09-03 14:51:22 +0000 | [diff] [blame] | 63 | // 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 | }; |
danilchap | 59cb2bd | 2016-08-29 11:08:47 -0700 | [diff] [blame] | 92 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 93 | RTCPReceiver(const RtpRtcpInterface::Configuration& config, |
| 94 | ModuleRtpRtcp* owner); |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 95 | |
| 96 | RTCPReceiver(const RtpRtcpInterface::Configuration& config, |
| 97 | ModuleRtpRtcpImpl2* owner); |
| 98 | |
Danil Chapovalov | 443f266 | 2020-03-11 12:24:40 +0100 | [diff] [blame] | 99 | ~RTCPReceiver(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
Harald Alvestrand | 1f206b8 | 2023-02-01 11:12:46 +0000 | [diff] [blame^] | 101 | [[deprecated("Use ArrayView verwsion")]] void IncomingPacket( |
| 102 | const uint8_t* packet, |
| 103 | size_t packet_size) { |
Danil Chapovalov | 443f266 | 2020-03-11 12:24:40 +0100 | [diff] [blame] | 104 | IncomingPacket(rtc::MakeArrayView(packet, packet_size)); |
| 105 | } |
| 106 | void IncomingPacket(rtc::ArrayView<const uint8_t> packet); |
danilchap | 59cb2bd | 2016-08-29 11:08:47 -0700 | [diff] [blame] | 107 | |
Danil Chapovalov | 760c4b4 | 2017-09-27 13:25:24 +0200 | [diff] [blame] | 108 | int64_t LastReceivedReportBlockMs() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 110 | void set_local_media_ssrc(uint32_t ssrc); |
| 111 | uint32_t local_media_ssrc() const; |
| 112 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 113 | void SetRemoteSSRC(uint32_t ssrc); |
| 114 | uint32_t RemoteSSRC() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 116 | bool receiver_only() const { return receiver_only_; } |
| 117 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 118 | // Get received NTP. |
Alessio Bazzica | 048adc7 | 2021-03-10 15:05:55 +0100 | [diff] [blame] | 119 | // The types for the arguments below derive from the specification: |
| 120 | // - `remote_sender_packet_count`: `RTCSentRtpStreamStats.packetsSent` [1] |
| 121 | // - `remote_sender_octet_count`: `RTCSentRtpStreamStats.bytesSent` [1] |
| 122 | // - `remote_sender_reports_count`: |
| 123 | // `RTCRemoteOutboundRtpStreamStats.reportsSent` [2] |
| 124 | // [1] https://www.w3.org/TR/webrtc-stats/#remoteoutboundrtpstats-dict* |
| 125 | // [2] https://www.w3.org/TR/webrtc-stats/#dom-rtcsentrtpstreamstats |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 126 | bool NTP(uint32_t* received_ntp_secs, |
| 127 | uint32_t* received_ntp_frac, |
| 128 | uint32_t* rtcp_arrival_time_secs, |
| 129 | uint32_t* rtcp_arrival_time_frac, |
Alessio Bazzica | 048adc7 | 2021-03-10 15:05:55 +0100 | [diff] [blame] | 130 | uint32_t* rtcp_timestamp, |
| 131 | uint32_t* remote_sender_packet_count, |
| 132 | uint64_t* remote_sender_octet_count, |
| 133 | uint64_t* remote_sender_reports_count) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | |
Mirta Dvornicic | b1f063d | 2018-04-16 11:16:21 +0200 | [diff] [blame] | 135 | std::vector<rtcp::ReceiveTimeInfo> ConsumeReceivedXrReferenceTimeInfo(); |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 136 | |
danilchap | 28b03eb | 2016-10-05 06:59:44 -0700 | [diff] [blame] | 137 | // Get rtt. |
| 138 | int32_t RTT(uint32_t remote_ssrc, |
| 139 | int64_t* last_rtt_ms, |
| 140 | int64_t* avg_rtt_ms, |
| 141 | int64_t* min_rtt_ms, |
| 142 | int64_t* max_rtt_ms) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 143 | |
Ivo Creusen | 2562cf0 | 2021-09-03 14:51:22 +0000 | [diff] [blame] | 144 | // Returns non-sender RTT metrics for the remote SSRC. |
| 145 | NonSenderRttStats GetNonSenderRTT() const; |
| 146 | |
Ivo Creusen | 8c40d51 | 2021-07-13 12:53:22 +0000 | [diff] [blame] | 147 | void SetNonSenderRttMeasurement(bool enabled); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 148 | bool GetAndResetXrRrRtt(int64_t* rtt_ms); |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 149 | |
Tomas Gunnarsson | ba0ba71 | 2020-07-01 08:53:21 +0200 | [diff] [blame] | 150 | // Called once per second on the worker thread to do rtt calculations. |
| 151 | // Returns an optional rtt value if one is available. |
| 152 | absl::optional<TimeDelta> OnPeriodicRttUpdate(Timestamp newer_than, |
| 153 | bool sending); |
| 154 | |
Henrik Boström | f204787 | 2019-05-16 13:32:20 +0200 | [diff] [blame] | 155 | // A snapshot of Report Blocks with additional data of interest to statistics. |
Danil Chapovalov | 510c94c | 2021-07-02 13:51:19 +0200 | [diff] [blame] | 156 | // Within this list, the source SSRC is unique and ReportBlockData represents |
| 157 | // the latest Report Block that was received for that SSRC. |
Henrik Boström | f204787 | 2019-05-16 13:32:20 +0200 | [diff] [blame] | 158 | std::vector<ReportBlockData> GetLatestReportBlockData() const; |
perkj@webrtc.org | ce5990c | 2012-01-11 13:00:08 +0000 | [diff] [blame] | 159 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 160 | // Returns true if we haven't received an RTCP RR for several RTCP |
| 161 | // intervals, but only triggers true once. |
Jiawei Ou | 8b5d9d8 | 2018-11-15 16:44:37 -0800 | [diff] [blame] | 162 | bool RtcpRrTimeout(); |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 163 | |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 164 | // Returns true if we haven't received an RTCP RR telling the receive side |
| 165 | // has not received RTP packets for too long, i.e. extended highest sequence |
| 166 | // number hasn't increased for several RTCP intervals. The function only |
| 167 | // returns true once until a new RR is received. |
Jiawei Ou | 8b5d9d8 | 2018-11-15 16:44:37 -0800 | [diff] [blame] | 168 | bool RtcpRrSequenceNumberTimeout(); |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 169 | |
danilchap | 7851bda | 2016-09-29 15:28:07 -0700 | [diff] [blame] | 170 | std::vector<rtcp::TmmbItem> TmmbrReceived(); |
danilchap | 9bf610e | 2017-02-20 06:03:01 -0800 | [diff] [blame] | 171 | // Return true if new bandwidth should be set. |
| 172 | bool UpdateTmmbrTimers(); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 173 | std::vector<rtcp::TmmbItem> BoundingSet(bool* tmmbr_owner); |
danilchap | 9bf610e | 2017-02-20 06:03:01 -0800 | [diff] [blame] | 174 | // Set new bandwidth and notify remote clients about it. |
| 175 | void NotifyTmmbrUpdated(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 176 | |
danilchap | dd12892 | 2016-09-13 12:23:29 -0700 | [diff] [blame] | 177 | private: |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 178 | #if RTC_DCHECK_IS_ON |
| 179 | class CustomSequenceChecker : public SequenceChecker { |
Victor Boivie | 306b139 | 2021-04-27 10:33:58 +0200 | [diff] [blame] | 180 | public: |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 181 | explicit CustomSequenceChecker(bool disable_checks) |
| 182 | : disable_checks_(disable_checks) {} |
| 183 | bool IsCurrent() const { |
| 184 | if (disable_checks_) |
| 185 | return true; |
| 186 | return SequenceChecker::IsCurrent(); |
Victor Boivie | 306b139 | 2021-04-27 10:33:58 +0200 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | private: |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 190 | const bool disable_checks_; |
| 191 | }; |
| 192 | #else |
| 193 | class CustomSequenceChecker : public SequenceChecker { |
| 194 | public: |
| 195 | explicit CustomSequenceChecker(bool) {} |
| 196 | }; |
| 197 | #endif |
| 198 | |
| 199 | // A lightweight inlined set of local SSRCs. |
| 200 | class RegisteredSsrcs { |
| 201 | public: |
| 202 | static constexpr size_t kMediaSsrcIndex = 0; |
| 203 | static constexpr size_t kMaxSsrcs = 3; |
| 204 | // Initializes the set of registered local SSRCS by extracting them from the |
| 205 | // provided `config`. The `disable_sequence_checker` flag is a workaround |
| 206 | // to be able to use a sequence checker without breaking downstream |
| 207 | // code that currently doesn't follow the same threading rules as webrtc. |
| 208 | RegisteredSsrcs(bool disable_sequence_checker, |
| 209 | const RtpRtcpInterface::Configuration& config); |
| 210 | |
| 211 | // Indicates if `ssrc` is in the set of registered local SSRCs. |
| 212 | bool contains(uint32_t ssrc) const; |
| 213 | uint32_t media_ssrc() const; |
| 214 | void set_media_ssrc(uint32_t ssrc); |
| 215 | |
| 216 | private: |
| 217 | RTC_NO_UNIQUE_ADDRESS CustomSequenceChecker packet_sequence_checker_; |
| 218 | absl::InlinedVector<uint32_t, kMaxSsrcs> ssrcs_ |
| 219 | RTC_GUARDED_BY(packet_sequence_checker_); |
Victor Boivie | 306b139 | 2021-04-27 10:33:58 +0200 | [diff] [blame] | 220 | }; |
| 221 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 222 | struct PacketInformation; |
Stephan Hartmann | 2694672 | 2021-05-03 11:06:23 +0000 | [diff] [blame] | 223 | |
| 224 | // Structure for handing TMMBR and TMMBN rtcp messages (RFC5104, |
| 225 | // section 3.5.4). |
| 226 | struct TmmbrInformation { |
| 227 | struct TimedTmmbrItem { |
| 228 | rtcp::TmmbItem tmmbr_item; |
| 229 | int64_t last_updated_ms; |
| 230 | }; |
| 231 | |
| 232 | int64_t last_time_received_ms = 0; |
| 233 | |
| 234 | bool ready_for_delete = false; |
| 235 | |
| 236 | std::vector<rtcp::TmmbItem> tmmbn; |
| 237 | std::map<uint32_t, TimedTmmbrItem> tmmbr; |
| 238 | }; |
| 239 | |
| 240 | // Structure for storing received RRTR RTCP messages (RFC3611, section 4.4). |
| 241 | struct RrtrInformation { |
| 242 | RrtrInformation(uint32_t ssrc, |
| 243 | uint32_t received_remote_mid_ntp_time, |
| 244 | uint32_t local_receive_mid_ntp_time) |
| 245 | : ssrc(ssrc), |
| 246 | received_remote_mid_ntp_time(received_remote_mid_ntp_time), |
| 247 | local_receive_mid_ntp_time(local_receive_mid_ntp_time) {} |
| 248 | |
| 249 | uint32_t ssrc; |
| 250 | // Received NTP timestamp in compact representation. |
| 251 | uint32_t received_remote_mid_ntp_time; |
| 252 | // NTP time when the report was received in compact representation. |
| 253 | uint32_t local_receive_mid_ntp_time; |
| 254 | }; |
| 255 | |
| 256 | struct LastFirStatus { |
| 257 | LastFirStatus(int64_t now_ms, uint8_t sequence_number) |
| 258 | : request_ms(now_ms), sequence_number(sequence_number) {} |
| 259 | int64_t request_ms; |
| 260 | uint8_t sequence_number; |
| 261 | }; |
Victor Boivie | 0c563a4 | 2021-04-27 10:24:01 +0200 | [diff] [blame] | 262 | |
Danil Chapovalov | 510c94c | 2021-07-02 13:51:19 +0200 | [diff] [blame] | 263 | class RttStats { |
| 264 | public: |
| 265 | RttStats() = default; |
| 266 | RttStats(const RttStats&) = default; |
| 267 | RttStats& operator=(const RttStats&) = default; |
Victor Boivie | 0c563a4 | 2021-04-27 10:24:01 +0200 | [diff] [blame] | 268 | |
Danil Chapovalov | 510c94c | 2021-07-02 13:51:19 +0200 | [diff] [blame] | 269 | void AddRtt(TimeDelta rtt); |
| 270 | |
| 271 | TimeDelta last_rtt() const { return last_rtt_; } |
| 272 | TimeDelta min_rtt() const { return min_rtt_; } |
| 273 | TimeDelta max_rtt() const { return max_rtt_; } |
| 274 | TimeDelta average_rtt() const { return sum_rtt_ / num_rtts_; } |
| 275 | |
| 276 | private: |
| 277 | TimeDelta last_rtt_ = TimeDelta::Zero(); |
| 278 | TimeDelta min_rtt_ = TimeDelta::PlusInfinity(); |
| 279 | TimeDelta max_rtt_ = TimeDelta::MinusInfinity(); |
| 280 | TimeDelta sum_rtt_ = TimeDelta::Zero(); |
| 281 | size_t num_rtts_ = 0; |
| 282 | }; |
danilchap | dd12892 | 2016-09-13 12:23:29 -0700 | [diff] [blame] | 283 | |
Danil Chapovalov | 443f266 | 2020-03-11 12:24:40 +0100 | [diff] [blame] | 284 | bool ParseCompoundPacket(rtc::ArrayView<const uint8_t> packet, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 285 | PacketInformation* packet_information); |
danilchap | dd12892 | 2016-09-13 12:23:29 -0700 | [diff] [blame] | 286 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 287 | void TriggerCallbacksFromRtcpPacket( |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 288 | const PacketInformation& packet_information); |
danilchap | dd12892 | 2016-09-13 12:23:29 -0700 | [diff] [blame] | 289 | |
danilchap | ec067e9 | 2017-02-21 05:38:19 -0800 | [diff] [blame] | 290 | TmmbrInformation* FindOrCreateTmmbrInfo(uint32_t remote_ssrc) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 291 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
danilchap | ec067e9 | 2017-02-21 05:38:19 -0800 | [diff] [blame] | 292 | // Update TmmbrInformation (if present) is alive. |
| 293 | void UpdateTmmbrRemoteIsAlive(uint32_t remote_ssrc) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 294 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
danilchap | 9bf610e | 2017-02-20 06:03:01 -0800 | [diff] [blame] | 295 | TmmbrInformation* GetTmmbrInformation(uint32_t remote_ssrc) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 296 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 297 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 298 | void HandleSenderReport(const rtcp::CommonHeader& rtcp_block, |
| 299 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 300 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
Danil Chapovalov | 91511f1 | 2016-09-15 16:24:02 +0200 | [diff] [blame] | 301 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 302 | void HandleReceiverReport(const rtcp::CommonHeader& rtcp_block, |
| 303 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 304 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 305 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 306 | void HandleReportBlock(const rtcp::ReportBlock& report_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 307 | PacketInformation* packet_information, |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 308 | uint32_t remote_ssrc) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 309 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 310 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 311 | void HandleSdes(const rtcp::CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 312 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 313 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 314 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 315 | void HandleXr(const rtcp::CommonHeader& rtcp_block, |
Ivo Creusen | 2562cf0 | 2021-09-03 14:51:22 +0000 | [diff] [blame] | 316 | PacketInformation* packet_information, |
| 317 | bool& contains_dlrr, |
| 318 | uint32_t& ssrc) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 319 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 320 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 321 | void HandleXrReceiveReferenceTime(uint32_t sender_ssrc, |
| 322 | const rtcp::Rrtr& rrtr) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 323 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 324 | |
Ivo Creusen | 2562cf0 | 2021-09-03 14:51:22 +0000 | [diff] [blame] | 325 | void HandleXrDlrrReportBlock(uint32_t ssrc, const rtcp::ReceiveTimeInfo& rti) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 326 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 327 | |
sprang | b32aaf9 | 2017-08-28 05:49:12 -0700 | [diff] [blame] | 328 | void HandleXrTargetBitrate(uint32_t ssrc, |
| 329 | const rtcp::TargetBitrate& target_bitrate, |
sprang | a790d83 | 2016-12-02 07:29:44 -0800 | [diff] [blame] | 330 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 331 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
sprang | a790d83 | 2016-12-02 07:29:44 -0800 | [diff] [blame] | 332 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 333 | void HandleNack(const rtcp::CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 334 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 335 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 336 | |
Sebastian Jansson | e1795f4 | 2019-07-24 11:38:03 +0200 | [diff] [blame] | 337 | void HandleApp(const rtcp::CommonHeader& rtcp_block, |
| 338 | PacketInformation* packet_information) |
| 339 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
| 340 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 341 | void HandleBye(const rtcp::CommonHeader& rtcp_block) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 342 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 343 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 344 | void HandlePli(const rtcp::CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 345 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 346 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 347 | |
danilchap | 1b1863a | 2016-09-20 01:39:54 -0700 | [diff] [blame] | 348 | void HandlePsfbApp(const rtcp::CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 349 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 350 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 351 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 352 | void HandleTmmbr(const rtcp::CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 353 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 354 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 355 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 356 | void HandleTmmbn(const rtcp::CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 357 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 358 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 359 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 360 | void HandleSrReq(const rtcp::CommonHeader& rtcp_block, |
| 361 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 362 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 363 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 364 | void HandleFir(const rtcp::CommonHeader& rtcp_block, |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 365 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 366 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
danilchap | da161d7 | 2016-08-19 07:29:46 -0700 | [diff] [blame] | 367 | |
danilchap | 92ea601 | 2016-09-23 10:36:03 -0700 | [diff] [blame] | 368 | void HandleTransportFeedback(const rtcp::CommonHeader& rtcp_block, |
| 369 | PacketInformation* packet_information) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 370 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 371 | |
Tomas Gunnarsson | ba0ba71 | 2020-07-01 08:53:21 +0200 | [diff] [blame] | 372 | bool RtcpRrTimeoutLocked(Timestamp now) |
| 373 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
| 374 | |
| 375 | bool RtcpRrSequenceNumberTimeoutLocked(Timestamp now) |
| 376 | RTC_EXCLUSIVE_LOCKS_REQUIRED(rtcp_receiver_lock_); |
| 377 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 378 | Clock* const clock_; |
Peter Boström | fe7a80c | 2015-04-23 17:53:17 +0200 | [diff] [blame] | 379 | const bool receiver_only_; |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 380 | ModuleRtpRtcp* const rtp_rtcp_; |
Victor Boivie | 306b139 | 2021-04-27 10:33:58 +0200 | [diff] [blame] | 381 | // The set of registered local SSRCs. |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 382 | RegisteredSsrcs registered_ssrcs_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 383 | |
sprang | a790d83 | 2016-12-02 07:29:44 -0800 | [diff] [blame] | 384 | RtcpBandwidthObserver* const rtcp_bandwidth_observer_; |
| 385 | RtcpIntraFrameObserver* const rtcp_intra_frame_observer_; |
Elad Alon | 0a8562e | 2019-04-09 11:55:13 +0200 | [diff] [blame] | 386 | RtcpLossNotificationObserver* const rtcp_loss_notification_observer_; |
Sebastian Jansson | e1795f4 | 2019-07-24 11:38:03 +0200 | [diff] [blame] | 387 | NetworkStateEstimateObserver* const network_state_estimate_observer_; |
sprang | a790d83 | 2016-12-02 07:29:44 -0800 | [diff] [blame] | 388 | TransportFeedbackObserver* const transport_feedback_observer_; |
| 389 | VideoBitrateAllocationObserver* const bitrate_allocation_observer_; |
Tomas Gunnarsson | ba0ba71 | 2020-07-01 08:53:21 +0200 | [diff] [blame] | 390 | const TimeDelta report_interval_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 391 | |
Markus Handell | e7c015e | 2020-07-07 11:44:28 +0200 | [diff] [blame] | 392 | mutable Mutex rtcp_receiver_lock_; |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 393 | uint32_t remote_ssrc_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 394 | |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 395 | // Received sender report. |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 396 | NtpTime remote_sender_ntp_time_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
| 397 | uint32_t remote_sender_rtp_time_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
danilchap | 0b4b727 | 2016-10-06 09:24:45 -0700 | [diff] [blame] | 398 | // When did we receive the last send report. |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 399 | NtpTime last_received_sr_ntp_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
Alessio Bazzica | 048adc7 | 2021-03-10 15:05:55 +0100 | [diff] [blame] | 400 | uint32_t remote_sender_packet_count_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
| 401 | uint64_t remote_sender_octet_count_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
| 402 | uint64_t remote_sender_reports_count_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 403 | |
Mirta Dvornicic | b1f063d | 2018-04-16 11:16:21 +0200 | [diff] [blame] | 404 | // Received RRTR information in ascending receive time order. |
| 405 | std::list<RrtrInformation> received_rrtrs_ |
| 406 | RTC_GUARDED_BY(rtcp_receiver_lock_); |
| 407 | // Received RRTR information mapped by remote ssrc. |
Victor Boivie | f715618 | 2021-07-06 23:14:51 +0200 | [diff] [blame] | 408 | flat_map<uint32_t, std::list<RrtrInformation>::iterator> |
Mirta Dvornicic | b1f063d | 2018-04-16 11:16:21 +0200 | [diff] [blame] | 409 | received_rrtrs_ssrc_it_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
| 410 | |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 411 | // Estimated rtt, zero when there is no valid estimate. |
Ivo Creusen | 8c40d51 | 2021-07-13 12:53:22 +0000 | [diff] [blame] | 412 | bool xr_rrtr_status_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 413 | int64_t xr_rr_rtt_ms_; |
asapersson@webrtc.org | 8469f7b | 2013-10-02 13:15:34 +0000 | [diff] [blame] | 414 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 415 | int64_t oldest_tmmbr_info_ms_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
danilchap | 9bf610e | 2017-02-20 06:03:01 -0800 | [diff] [blame] | 416 | // Mapped by remote ssrc. |
Victor Boivie | f715618 | 2021-07-06 23:14:51 +0200 | [diff] [blame] | 417 | flat_map<uint32_t, TmmbrInformation> tmmbr_infos_ |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 418 | RTC_GUARDED_BY(rtcp_receiver_lock_); |
danilchap | 9bf610e | 2017-02-20 06:03:01 -0800 | [diff] [blame] | 419 | |
Danil Chapovalov | 510c94c | 2021-07-02 13:51:19 +0200 | [diff] [blame] | 420 | // Round-Trip Time per remote sender ssrc. |
Victor Boivie | f715618 | 2021-07-06 23:14:51 +0200 | [diff] [blame] | 421 | flat_map<uint32_t, RttStats> rtts_ RTC_GUARDED_BY(rtcp_receiver_lock_); |
Ivo Creusen | 2562cf0 | 2021-09-03 14:51:22 +0000 | [diff] [blame] | 422 | // Non-sender Round-trip time per remote ssrc. |
| 423 | flat_map<uint32_t, NonSenderRttStats> non_sender_rtts_ |
| 424 | RTC_GUARDED_BY(rtcp_receiver_lock_); |
Danil Chapovalov | 510c94c | 2021-07-02 13:51:19 +0200 | [diff] [blame] | 425 | |
| 426 | // Report blocks per local source ssrc. |
Victor Boivie | f715618 | 2021-07-06 23:14:51 +0200 | [diff] [blame] | 427 | flat_map<uint32_t, ReportBlockData> received_report_blocks_ |
Danil Chapovalov | 510c94c | 2021-07-02 13:51:19 +0200 | [diff] [blame] | 428 | RTC_GUARDED_BY(rtcp_receiver_lock_); |
Victor Boivie | f715618 | 2021-07-06 23:14:51 +0200 | [diff] [blame] | 429 | flat_map<uint32_t, LastFirStatus> last_fir_ |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 430 | RTC_GUARDED_BY(rtcp_receiver_lock_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 431 | |
Danil Chapovalov | 760c4b4 | 2017-09-27 13:25:24 +0200 | [diff] [blame] | 432 | // The last time we received an RTCP Report block for this module. |
Tomas Gunnarsson | ba0ba71 | 2020-07-01 08:53:21 +0200 | [diff] [blame] | 433 | Timestamp last_received_rb_ RTC_GUARDED_BY(rtcp_receiver_lock_) = |
| 434 | Timestamp::PlusInfinity(); |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 435 | |
asapersson@webrtc.org | cb79141 | 2014-12-18 14:30:32 +0000 | [diff] [blame] | 436 | // The time we last received an RTCP RR telling we have successfully |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 437 | // delivered RTP packet to the remote side. |
Tomas Gunnarsson | ba0ba71 | 2020-07-01 08:53:21 +0200 | [diff] [blame] | 438 | Timestamp last_increased_sequence_number_ = Timestamp::PlusInfinity(); |
stefan@webrtc.org | 8ca8a71 | 2013-04-23 16:48:32 +0000 | [diff] [blame] | 439 | |
Danil Chapovalov | bd74d5c | 2020-03-12 09:22:44 +0100 | [diff] [blame] | 440 | RtcpCnameCallback* const cname_callback_; |
Danil Chapovalov | bd74d5c | 2020-03-12 09:22:44 +0100 | [diff] [blame] | 441 | ReportBlockDataObserver* const report_block_data_observer_; |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 442 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 443 | RtcpPacketTypeCounterObserver* const packet_type_counter_observer_; |
asapersson@webrtc.org | 8098e07 | 2014-02-19 11:59:02 +0000 | [diff] [blame] | 444 | RtcpPacketTypeCounter packet_type_counter_; |
asapersson@webrtc.org | 2dd3134 | 2014-10-29 12:42:30 +0000 | [diff] [blame] | 445 | |
danilchap | 8443238 | 2017-02-09 05:21:42 -0800 | [diff] [blame] | 446 | RtcpNackStats nack_stats_; |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 447 | |
| 448 | size_t num_skipped_packets_; |
danilchap | 8bab796 | 2016-12-20 02:46:46 -0800 | [diff] [blame] | 449 | int64_t last_skipped_packets_warning_ms_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 450 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 451 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 452 | #endif // MODULES_RTP_RTCP_SOURCE_RTCP_RECEIVER_H_ |