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 | #include "modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 +0000 | [diff] [blame] | 13 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 15 | #include <algorithm> |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 16 | #include <cstdint> |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 17 | #include <memory> |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 18 | #include <set> |
Peter Boström | 9c01725 | 2016-02-26 16:26:20 +0100 | [diff] [blame] | 19 | #include <string> |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 20 | #include <utility> |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 21 | |
Per Kjellander | e11b7d2 | 2019-02-21 07:55:59 +0100 | [diff] [blame] | 22 | #include "api/transport/field_trial_based_config.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 23 | #include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h" |
Markus Handell | 2e3edc1 | 2021-06-18 13:44:13 +0200 | [diff] [blame] | 24 | #include "modules/rtp_rtcp/source/rtcp_sender.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 25 | #include "modules/rtp_rtcp/source/rtp_rtcp_config.h" |
Markus Handell | 2e3edc1 | 2021-06-18 13:44:13 +0200 | [diff] [blame] | 26 | #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "rtc_base/checks.h" |
| 28 | #include "rtc_base/logging.h" |
Alessio Bazzica | bc1c93d | 2021-03-12 17:45:26 +0100 | [diff] [blame] | 29 | #include "system_wrappers/include/ntp_time.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | #ifdef _WIN32 |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 32 | // Disable warning C4355: 'this' : used in base member initializer list. |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 33 | #pragma warning(disable : 4355) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
| 36 | namespace webrtc { |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 37 | namespace { |
| 38 | const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5; |
| 39 | const int64_t kRtpRtcpRttProcessTimeMs = 1000; |
| 40 | const int64_t kRtpRtcpBitrateProcessTimeMs = 10; |
sprang | a8ae6f2 | 2017-09-04 07:23:56 -0700 | [diff] [blame] | 41 | const int64_t kDefaultExpectedRetransmissionTimeMs = 125; |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 42 | } // namespace |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 44 | ModuleRtpRtcpImpl::RtpSenderContext::RtpSenderContext( |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 45 | const RtpRtcpInterface::Configuration& config) |
Erik Språng | 641d59b | 2020-03-30 10:01:29 +0200 | [diff] [blame] | 46 | : packet_history(config.clock, config.enable_rtx_padding_prioritization), |
Erik Språng | bfcfe03 | 2021-08-04 14:45:32 +0200 | [diff] [blame] | 47 | sequencer_(config.local_media_ssrc, |
| 48 | config.rtx_send_ssrc, |
| 49 | /*require_marker_before_media_padding=*/!config.audio, |
| 50 | config.clock), |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 51 | packet_sender(config, &packet_history), |
| 52 | non_paced_sender(&packet_sender), |
| 53 | packet_generator( |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 54 | config, |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 55 | &packet_history, |
Erik Språng | bfcfe03 | 2021-08-04 14:45:32 +0200 | [diff] [blame] | 56 | config.paced_sender ? config.paced_sender : &non_paced_sender, |
| 57 | &sequencer_) {} |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 58 | |
Tomas Gunnarsson | fae0562 | 2020-06-03 08:54:39 +0200 | [diff] [blame] | 59 | std::unique_ptr<RtpRtcp> RtpRtcp::DEPRECATED_Create( |
| 60 | const Configuration& configuration) { |
| 61 | RTC_DCHECK(configuration.clock); |
| 62 | RTC_LOG(LS_ERROR) |
| 63 | << "*********** USING WebRTC INTERNAL IMPLEMENTATION DETAILS ***********"; |
| 64 | return std::make_unique<ModuleRtpRtcpImpl>(configuration); |
| 65 | } |
| 66 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 67 | ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration) |
Markus Handell | 2e3edc1 | 2021-06-18 13:44:13 +0200 | [diff] [blame] | 68 | : rtcp_sender_( |
| 69 | RTCPSender::Configuration::FromRtpRtcpConfiguration(configuration)), |
Mirko Bonadei | 3b67672 | 2019-07-12 17:35:05 +0000 | [diff] [blame] | 70 | rtcp_receiver_(configuration, this), |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 71 | clock_(configuration.clock), |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 72 | last_bitrate_process_time_(clock_->TimeInMilliseconds()), |
| 73 | last_rtt_process_time_(clock_->TimeInMilliseconds()), |
| 74 | next_process_time_(clock_->TimeInMilliseconds() + |
| 75 | kRtpRtcpMaxIdleTimeProcessMs), |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 76 | packet_overhead_(28), // IPV4 UDP. |
Danil Chapovalov | 9eb6ce1 | 2017-12-15 12:25:01 +0100 | [diff] [blame] | 77 | nack_last_time_sent_full_ms_(0), |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 78 | nack_last_seq_number_sent_(0), |
mflodman@webrtc.org | 7c894b7 | 2012-11-26 12:40:15 +0000 | [diff] [blame] | 79 | remote_bitrate_(configuration.remote_bitrate_estimator), |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 80 | rtt_stats_(configuration.rtt_stats), |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 81 | rtt_ms_(0) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 82 | if (!configuration.receiver_only) { |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 83 | rtp_sender_ = std::make_unique<RtpSenderContext>(configuration); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 84 | // Make sure rtcp sender use same timestamp offset as rtp sender. |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 85 | rtcp_sender_.SetTimestampOffset( |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 86 | rtp_sender_->packet_generator.TimestampOffset()); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 87 | } |
danilchap | 71fead2 | 2016-08-18 02:01:49 -0700 | [diff] [blame] | 88 | |
| 89 | // Set default packet size limit. |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 90 | // TODO(nisse): Kind-of duplicates |
| 91 | // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize. |
| 92 | const size_t kTcpOverIpv4HeaderSize = 40; |
| 93 | SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 96 | ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() = default; |
| 97 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 98 | // Returns the number of milliseconds until the module want a worker thread |
| 99 | // to call Process. |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 +0000 | [diff] [blame] | 100 | int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() { |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 101 | return std::max<int64_t>(0, |
| 102 | next_process_time_ - clock_->TimeInMilliseconds()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | } |
| 104 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 105 | // Process any pending tasks such as timeouts (non time critical events). |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 106 | void ModuleRtpRtcpImpl::Process() { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 107 | const int64_t now = clock_->TimeInMilliseconds(); |
Tommi | 6af9774 | 2020-05-18 12:47:03 +0200 | [diff] [blame] | 108 | // TODO(bugs.webrtc.org/11581): Figure out why we need to call Process() 200 |
| 109 | // times a second. |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 110 | next_process_time_ = now + kRtpRtcpMaxIdleTimeProcessMs; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 112 | if (rtp_sender_) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 113 | if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 114 | rtp_sender_->packet_sender.ProcessBitrateAndNotifyObservers(); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 115 | last_bitrate_process_time_ = now; |
Tommi | 6af9774 | 2020-05-18 12:47:03 +0200 | [diff] [blame] | 116 | // TODO(bugs.webrtc.org/11581): Is this a bug? At the top of the function, |
| 117 | // next_process_time_ is incremented by 5ms, here we effectively do a |
| 118 | // std::min() of (now + 5ms, now + 10ms). Seems like this is a no-op? |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 119 | next_process_time_ = |
| 120 | std::min(next_process_time_, now + kRtpRtcpBitrateProcessTimeMs); |
| 121 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 122 | } |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 123 | |
Tommi | 6af9774 | 2020-05-18 12:47:03 +0200 | [diff] [blame] | 124 | // TODO(bugs.webrtc.org/11581): We update the RTT once a second, whereas other |
| 125 | // things that run in this method are updated much more frequently. Move the |
| 126 | // RTT checking over to the worker thread, which matches better with where the |
| 127 | // stats are maintained. |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 128 | bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs; |
| 129 | if (rtcp_sender_.Sending()) { |
Danil Chapovalov | 760c4b4 | 2017-09-27 13:25:24 +0200 | [diff] [blame] | 130 | // Process RTT if we have received a report block and we haven't |
Artem Titov | 913cfa7 | 2021-07-28 23:57:33 +0200 | [diff] [blame^] | 131 | // processed RTT for at least `kRtpRtcpRttProcessTimeMs` milliseconds. |
Tommi | 6af9774 | 2020-05-18 12:47:03 +0200 | [diff] [blame] | 132 | // Note that LastReceivedReportBlockMs() grabs a lock, so check |
Artem Titov | 913cfa7 | 2021-07-28 23:57:33 +0200 | [diff] [blame^] | 133 | // `process_rtt` first. |
Danil Chapovalov | ab63350 | 2021-03-15 19:12:16 +0100 | [diff] [blame] | 134 | if (process_rtt && rtt_stats_ != nullptr && |
Tommi | 6af9774 | 2020-05-18 12:47:03 +0200 | [diff] [blame] | 135 | rtcp_receiver_.LastReceivedReportBlockMs() > last_rtt_process_time_) { |
Danil Chapovalov | ab63350 | 2021-03-15 19:12:16 +0100 | [diff] [blame] | 136 | int64_t max_rtt_ms = 0; |
| 137 | for (const auto& block : rtcp_receiver_.GetLatestReportBlockData()) { |
| 138 | if (block.last_rtt_ms() > max_rtt_ms) { |
| 139 | max_rtt_ms = block.last_rtt_ms(); |
| 140 | } |
mflodman@webrtc.org | d7d4688 | 2012-02-14 12:49:59 +0000 | [diff] [blame] | 141 | } |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 142 | // Report the rtt. |
Danil Chapovalov | ab63350 | 2021-03-15 19:12:16 +0100 | [diff] [blame] | 143 | if (max_rtt_ms > 0) { |
| 144 | rtt_stats_->OnRttUpdate(max_rtt_ms); |
| 145 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 146 | } |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 147 | |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 148 | // Verify receiver reports are delivered and the reported sequence number |
| 149 | // is increasing. |
Tommi | 6af9774 | 2020-05-18 12:47:03 +0200 | [diff] [blame] | 150 | // TODO(bugs.webrtc.org/11581): The timeout value needs to be checked every |
| 151 | // few seconds (see internals of RtcpRrTimeout). Here, we may be polling it |
| 152 | // a couple of hundred times a second, which isn't great since it grabs a |
| 153 | // lock. Note also that LastReceivedReportBlockMs() (called above) and |
| 154 | // RtcpRrTimeout() both grab the same lock and check the same timer, so |
| 155 | // it should be possible to consolidate that work somehow. |
Jiawei Ou | 8b5d9d8 | 2018-11-15 16:44:37 -0800 | [diff] [blame] | 156 | if (rtcp_receiver_.RtcpRrTimeout()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 157 | RTC_LOG_F(LS_WARNING) << "Timeout: No RTCP RR received."; |
Jiawei Ou | 8b5d9d8 | 2018-11-15 16:44:37 -0800 | [diff] [blame] | 158 | } else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 159 | RTC_LOG_F(LS_WARNING) << "Timeout: No increase in RTCP RR extended " |
| 160 | "highest sequence number."; |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | if (remote_bitrate_ && rtcp_sender_.TMMBR()) { |
| 164 | unsigned int target_bitrate = 0; |
| 165 | std::vector<unsigned int> ssrcs; |
| 166 | if (remote_bitrate_->LatestEstimate(&ssrcs, &target_bitrate)) { |
| 167 | if (!ssrcs.empty()) { |
| 168 | target_bitrate = target_bitrate / ssrcs.size(); |
| 169 | } |
| 170 | rtcp_sender_.SetTargetBitrate(target_bitrate); |
| 171 | } |
| 172 | } |
| 173 | } else { |
| 174 | // Report rtt from receiver. |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 175 | if (process_rtt) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 176 | int64_t rtt_ms; |
| 177 | if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) { |
| 178 | rtt_stats_->OnRttUpdate(rtt_ms); |
| 179 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 180 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 181 | } |
| 182 | |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 183 | // Get processed rtt. |
| 184 | if (process_rtt) { |
| 185 | last_rtt_process_time_ = now; |
Tommi | 6af9774 | 2020-05-18 12:47:03 +0200 | [diff] [blame] | 186 | // TODO(bugs.webrtc.org/11581): Is this a bug? At the top of the function, |
| 187 | // next_process_time_ is incremented by 5ms, here we effectively do a |
| 188 | // std::min() of (now + 5ms, now + 1000ms). Seems like this is a no-op? |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 189 | next_process_time_ = std::min( |
| 190 | next_process_time_, last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs); |
sprang | e2d83d6 | 2016-02-19 09:03:26 -0800 | [diff] [blame] | 191 | if (rtt_stats_) { |
| 192 | // Make sure we have a valid RTT before setting. |
| 193 | int64_t last_rtt = rtt_stats_->LastProcessedRtt(); |
| 194 | if (last_rtt >= 0) |
| 195 | set_rtt_ms(last_rtt); |
| 196 | } |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Danil Chapovalov | 70ffead | 2016-07-20 15:26:59 +0200 | [diff] [blame] | 199 | if (rtcp_sender_.TimeToSendRTCPReport()) |
| 200 | rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport); |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 201 | |
Danil Chapovalov | 067b050 | 2021-02-05 12:11:56 +0100 | [diff] [blame] | 202 | if (rtcp_sender_.TMMBR() && rtcp_receiver_.UpdateTmmbrTimers()) { |
danilchap | 9bf610e | 2017-02-20 06:03:01 -0800 | [diff] [blame] | 203 | rtcp_receiver_.NotifyTmmbrUpdated(); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 204 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 205 | } |
| 206 | |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 +0000 | [diff] [blame] | 207 | void ModuleRtpRtcpImpl::SetRtxSendStatus(int mode) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 208 | rtp_sender_->packet_generator.SetRtxStatus(mode); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 209 | } |
| 210 | |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 +0000 | [diff] [blame] | 211 | int ModuleRtpRtcpImpl::RtxSendStatus() const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 212 | return rtp_sender_ ? rtp_sender_->packet_generator.RtxStatus() : kRtxOff; |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 215 | void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type, |
| 216 | int associated_payload_type) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 217 | rtp_sender_->packet_generator.SetRtxPayloadType(payload_type, |
| 218 | associated_payload_type); |
mflodman@webrtc.org | 9f5ebb5 | 2013-04-12 14:55:46 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Erik Språng | c06aef2 | 2019-10-17 13:02:27 +0200 | [diff] [blame] | 221 | absl::optional<uint32_t> ModuleRtpRtcpImpl::RtxSsrc() const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 222 | return rtp_sender_ ? rtp_sender_->packet_generator.RtxSsrc() : absl::nullopt; |
Erik Språng | c06aef2 | 2019-10-17 13:02:27 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Danil Chapovalov | d264df5 | 2018-06-14 12:59:38 +0200 | [diff] [blame] | 225 | absl::optional<uint32_t> ModuleRtpRtcpImpl::FlexfecSsrc() const { |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 226 | if (rtp_sender_) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 227 | return rtp_sender_->packet_generator.FlexfecSsrc(); |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 228 | } |
Danil Chapovalov | d264df5 | 2018-06-14 12:59:38 +0200 | [diff] [blame] | 229 | return absl::nullopt; |
brandtr | 9dfff29 | 2016-11-14 05:14:50 -0800 | [diff] [blame] | 230 | } |
| 231 | |
nisse | 479d3d7 | 2017-09-13 07:53:37 -0700 | [diff] [blame] | 232 | void ModuleRtpRtcpImpl::IncomingRtcpPacket(const uint8_t* rtcp_packet, |
| 233 | const size_t length) { |
| 234 | rtcp_receiver_.IncomingPacket(rtcp_packet, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 237 | void ModuleRtpRtcpImpl::RegisterSendPayloadFrequency(int payload_type, |
| 238 | int payload_frequency) { |
| 239 | rtcp_sender_.SetRtpClockRate(payload_type, payload_frequency); |
Peter Boström | 8b79b07 | 2016-02-26 16:31:37 +0100 | [diff] [blame] | 240 | } |
| 241 | |
asapersson@webrtc.org | 9ffd8fe | 2015-01-21 08:22:50 +0000 | [diff] [blame] | 242 | int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload(const int8_t payload_type) { |
Niels Möller | 59ab1cf | 2019-02-06 22:48:11 +0100 | [diff] [blame] | 243 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 244 | } |
| 245 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 246 | uint32_t ModuleRtpRtcpImpl::StartTimestamp() const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 247 | return rtp_sender_->packet_generator.TimestampOffset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 248 | } |
| 249 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 250 | // Configure start timestamp, default is a random number. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 251 | void ModuleRtpRtcpImpl::SetStartTimestamp(const uint32_t timestamp) { |
danilchap | 71fead2 | 2016-08-18 02:01:49 -0700 | [diff] [blame] | 252 | rtcp_sender_.SetTimestampOffset(timestamp); |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 253 | rtp_sender_->packet_generator.SetTimestampOffset(timestamp); |
Erik Språng | 3663f94 | 2020-02-07 10:05:15 +0100 | [diff] [blame] | 254 | rtp_sender_->packet_sender.SetTimestampOffset(timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 255 | } |
| 256 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 257 | uint16_t ModuleRtpRtcpImpl::SequenceNumber() const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 258 | return rtp_sender_->packet_generator.SequenceNumber(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 259 | } |
| 260 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 261 | // Set SequenceNumber, default is a random number. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 262 | void ModuleRtpRtcpImpl::SetSequenceNumber(const uint16_t seq_num) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 263 | rtp_sender_->packet_generator.SetSequenceNumber(seq_num); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 266 | void ModuleRtpRtcpImpl::SetRtpState(const RtpState& rtp_state) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 267 | rtp_sender_->packet_generator.SetRtpState(rtp_state); |
danilchap | 71fead2 | 2016-08-18 02:01:49 -0700 | [diff] [blame] | 268 | rtcp_sender_.SetTimestampOffset(rtp_state.start_timestamp); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 271 | void ModuleRtpRtcpImpl::SetRtxState(const RtpState& rtp_state) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 272 | rtp_sender_->packet_generator.SetRtxRtpState(rtp_state); |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | RtpState ModuleRtpRtcpImpl::GetRtpState() const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 276 | RtpState state = rtp_sender_->packet_generator.GetRtpState(); |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 277 | return state; |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | RtpState ModuleRtpRtcpImpl::GetRtxState() const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 281 | return rtp_sender_->packet_generator.GetRtxRtpState(); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 284 | void ModuleRtpRtcpImpl::SetRid(const std::string& rid) { |
| 285 | if (rtp_sender_) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 286 | rtp_sender_->packet_generator.SetRid(rid); |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
Steve Anton | 296a0ce | 2018-03-22 15:17:27 -0700 | [diff] [blame] | 290 | void ModuleRtpRtcpImpl::SetMid(const std::string& mid) { |
| 291 | if (rtp_sender_) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 292 | rtp_sender_->packet_generator.SetMid(mid); |
Steve Anton | 296a0ce | 2018-03-22 15:17:27 -0700 | [diff] [blame] | 293 | } |
| 294 | // TODO(bugs.webrtc.org/4050): If we end up supporting the MID SDES item for |
| 295 | // RTCP, this will need to be passed down to the RTCPSender also. |
| 296 | } |
| 297 | |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 298 | void ModuleRtpRtcpImpl::SetCsrcs(const std::vector<uint32_t>& csrcs) { |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 299 | rtcp_sender_.SetCsrcs(csrcs); |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 300 | rtp_sender_->packet_generator.SetCsrcs(csrcs); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 301 | } |
| 302 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 303 | // TODO(pbos): Handle media and RTX streams separately (separate RTCP |
| 304 | // feedbacks). |
| 305 | RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() { |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 306 | RTCPSender::FeedbackState state; |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 307 | // This is called also when receiver_only is true. Hence below |
| 308 | // checks that rtp_sender_ exists. |
| 309 | if (rtp_sender_) { |
| 310 | StreamDataCounters rtp_stats; |
| 311 | StreamDataCounters rtx_stats; |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 312 | rtp_sender_->packet_sender.GetDataCounters(&rtp_stats, &rtx_stats); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 313 | state.packets_sent = |
| 314 | rtp_stats.transmitted.packets + rtx_stats.transmitted.packets; |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 315 | state.media_bytes_sent = rtp_stats.transmitted.payload_bytes + |
| 316 | rtx_stats.transmitted.payload_bytes; |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 317 | state.send_bitrate = |
Erik Språng | bf46cfe | 2020-05-11 18:22:02 +0200 | [diff] [blame] | 318 | rtp_sender_->packet_sender.GetSendRates().Sum().bps<uint32_t>(); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 319 | } |
Tommi | 3a5742c | 2020-05-20 09:32:51 +0200 | [diff] [blame] | 320 | state.receiver = &rtcp_receiver_; |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 321 | |
Alessio Bazzica | 79011ef | 2021-03-10 14:52:35 +0100 | [diff] [blame] | 322 | uint32_t received_ntp_secs = 0; |
| 323 | uint32_t received_ntp_frac = 0; |
| 324 | state.remote_sr = 0; |
| 325 | if (rtcp_receiver_.NTP(&received_ntp_secs, &received_ntp_frac, |
| 326 | /*rtcp_arrival_time_secs=*/&state.last_rr_ntp_secs, |
| 327 | /*rtcp_arrival_time_frac=*/&state.last_rr_ntp_frac, |
Alessio Bazzica | 048adc7 | 2021-03-10 15:05:55 +0100 | [diff] [blame] | 328 | /*rtcp_timestamp=*/nullptr, |
| 329 | /*remote_sender_packet_count=*/nullptr, |
| 330 | /*remote_sender_octet_count=*/nullptr, |
| 331 | /*remote_sender_reports_count=*/nullptr)) { |
Alessio Bazzica | 79011ef | 2021-03-10 14:52:35 +0100 | [diff] [blame] | 332 | state.remote_sr = ((received_ntp_secs & 0x0000ffff) << 16) + |
| 333 | ((received_ntp_frac & 0xffff0000) >> 16); |
| 334 | } |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 335 | |
Mirta Dvornicic | b1f063d | 2018-04-16 11:16:21 +0200 | [diff] [blame] | 336 | state.last_xr_rtis = rtcp_receiver_.ConsumeReceivedXrReferenceTimeInfo(); |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 337 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 338 | return state; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 339 | } |
| 340 | |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 341 | // TODO(nisse): This method shouldn't be called for a receive-only |
| 342 | // stream. Delete rtp_sender_ check as soon as all applications are |
| 343 | // updated. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 344 | int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 345 | if (rtcp_sender_.Sending() != sending) { |
| 346 | // Sends RTCP BYE when going from true to false |
Tomas Gunnarsson | dbcf5d3 | 2021-04-23 20:31:08 +0200 | [diff] [blame] | 347 | rtcp_sender_.SetSendingStatus(GetFeedbackState(), sending); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 348 | } |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | bool ModuleRtpRtcpImpl::Sending() const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 353 | return rtcp_sender_.Sending(); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 354 | } |
| 355 | |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 356 | // TODO(nisse): This method shouldn't be called for a receive-only |
| 357 | // stream. Delete rtp_sender_ check as soon as all applications are |
| 358 | // updated. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 359 | void ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 360 | if (rtp_sender_) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 361 | rtp_sender_->packet_generator.SetSendingMediaStatus(sending); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 362 | } else { |
| 363 | RTC_DCHECK(!sending); |
| 364 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | bool ModuleRtpRtcpImpl::SendingMedia() const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 368 | return rtp_sender_ ? rtp_sender_->packet_generator.SendingMedia() : false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Erik Språng | 1e51a38 | 2019-12-11 16:47:09 +0100 | [diff] [blame] | 371 | bool ModuleRtpRtcpImpl::IsAudioConfigured() const { |
| 372 | return rtp_sender_ ? rtp_sender_->packet_generator.IsAudioConfigured() |
| 373 | : false; |
| 374 | } |
| 375 | |
Sebastian Jansson | 1bca65b | 2018-10-10 09:58:08 +0200 | [diff] [blame] | 376 | void ModuleRtpRtcpImpl::SetAsPartOfAllocation(bool part_of_allocation) { |
| 377 | RTC_CHECK(rtp_sender_); |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 378 | rtp_sender_->packet_sender.ForceIncludeSendPacketsInAllocation( |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 379 | part_of_allocation); |
Sebastian Jansson | 1bca65b | 2018-10-10 09:58:08 +0200 | [diff] [blame] | 380 | } |
| 381 | |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 382 | bool ModuleRtpRtcpImpl::OnSendingRtpFrame(uint32_t timestamp, |
| 383 | int64_t capture_time_ms, |
| 384 | int payload_type, |
| 385 | bool force_sender_report) { |
| 386 | if (!Sending()) |
| 387 | return false; |
| 388 | |
Markus Handell | c6b9ac7 | 2021-06-18 13:44:51 +0200 | [diff] [blame] | 389 | // TODO(bugs.webrtc.org/12873): Migrate this method and it's users to use |
| 390 | // optional Timestamps. |
| 391 | absl::optional<Timestamp> capture_time; |
| 392 | if (capture_time_ms > 0) { |
| 393 | capture_time = Timestamp::Millis(capture_time_ms); |
| 394 | } |
| 395 | absl::optional<int> payload_type_optional; |
| 396 | if (payload_type >= 0) |
| 397 | payload_type_optional = payload_type; |
| 398 | rtcp_sender_.SetLastRtpTime(timestamp, capture_time, payload_type_optional); |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 399 | // Make sure an RTCP report isn't queued behind a key frame. |
| 400 | if (rtcp_sender_.TimeToSendRTCPReport(force_sender_report)) |
| 401 | rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport); |
| 402 | |
| 403 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Erik Språng | 9c771c2 | 2019-06-17 16:31:53 +0200 | [diff] [blame] | 406 | bool ModuleRtpRtcpImpl::TrySendPacket(RtpPacketToSend* packet, |
| 407 | const PacedPacketInfo& pacing_info) { |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 408 | RTC_DCHECK(rtp_sender_); |
| 409 | // TODO(sprang): Consider if we can remove this check. |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 410 | if (!rtp_sender_->packet_generator.SendingMedia()) { |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 411 | return false; |
| 412 | } |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 413 | rtp_sender_->packet_sender.SendPacket(packet, pacing_info); |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 414 | return true; |
Erik Språng | 9c771c2 | 2019-06-17 16:31:53 +0200 | [diff] [blame] | 415 | } |
| 416 | |
Erik Språng | 1d50cb6 | 2020-07-02 17:41:32 +0200 | [diff] [blame] | 417 | void ModuleRtpRtcpImpl::SetFecProtectionParams(const FecProtectionParams&, |
| 418 | const FecProtectionParams&) { |
| 419 | // Deferred FEC not supported in deprecated RTP module. |
| 420 | } |
| 421 | |
| 422 | std::vector<std::unique_ptr<RtpPacketToSend>> |
| 423 | ModuleRtpRtcpImpl::FetchFecPackets() { |
| 424 | // Deferred FEC not supported in deprecated RTP module. |
| 425 | return {}; |
| 426 | } |
| 427 | |
Erik Språng | a922904 | 2019-10-24 12:39:32 +0200 | [diff] [blame] | 428 | void ModuleRtpRtcpImpl::OnPacketsAcknowledged( |
| 429 | rtc::ArrayView<const uint16_t> sequence_numbers) { |
| 430 | RTC_DCHECK(rtp_sender_); |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 431 | rtp_sender_->packet_history.CullAcknowledgedPackets(sequence_numbers); |
Erik Språng | a922904 | 2019-10-24 12:39:32 +0200 | [diff] [blame] | 432 | } |
| 433 | |
Mirko Bonadei | 999a72a | 2019-07-12 17:33:46 +0000 | [diff] [blame] | 434 | bool ModuleRtpRtcpImpl::SupportsPadding() const { |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 435 | RTC_DCHECK(rtp_sender_); |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 436 | return rtp_sender_->packet_generator.SupportsPadding(); |
Mirko Bonadei | 999a72a | 2019-07-12 17:33:46 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | bool ModuleRtpRtcpImpl::SupportsRtxPayloadPadding() const { |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 440 | RTC_DCHECK(rtp_sender_); |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 441 | return rtp_sender_->packet_generator.SupportsRtxPayloadPadding(); |
Mirko Bonadei | 999a72a | 2019-07-12 17:33:46 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Erik Språng | f6468d2 | 2019-07-05 16:53:43 +0200 | [diff] [blame] | 444 | std::vector<std::unique_ptr<RtpPacketToSend>> |
| 445 | ModuleRtpRtcpImpl::GeneratePadding(size_t target_size_bytes) { |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 446 | RTC_DCHECK(rtp_sender_); |
Erik Språng | 51e3083 | 2021-08-05 16:15:14 +0200 | [diff] [blame] | 447 | // `can_send_padding_on_media_ssrc` set to false but is ignored at this |
| 448 | // point, RTPSender will internally query `sequencer_` while holding the |
| 449 | // send lock. |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 450 | return rtp_sender_->packet_generator.GeneratePadding( |
Erik Språng | bfcfe03 | 2021-08-04 14:45:32 +0200 | [diff] [blame] | 451 | target_size_bytes, rtp_sender_->packet_sender.MediaHasBeenSent(), |
Erik Språng | 51e3083 | 2021-08-05 16:15:14 +0200 | [diff] [blame] | 452 | /*can_send_padding_on_media_ssrc=*/false); |
Erik Språng | 478cb46 | 2019-06-26 15:49:27 +0200 | [diff] [blame] | 453 | } |
| 454 | |
Erik Språng | 3663f94 | 2020-02-07 10:05:15 +0100 | [diff] [blame] | 455 | std::vector<RtpSequenceNumberMap::Info> |
| 456 | ModuleRtpRtcpImpl::GetSentRtpPacketInfos( |
| 457 | rtc::ArrayView<const uint16_t> sequence_numbers) const { |
| 458 | RTC_DCHECK(rtp_sender_); |
| 459 | return rtp_sender_->packet_sender.GetSentRtpPacketInfos(sequence_numbers); |
| 460 | } |
| 461 | |
Erik Språng | 04e1bab | 2020-05-07 18:18:32 +0200 | [diff] [blame] | 462 | size_t ModuleRtpRtcpImpl::ExpectedPerPacketOverhead() const { |
| 463 | if (!rtp_sender_) { |
| 464 | return 0; |
| 465 | } |
| 466 | return rtp_sender_->packet_generator.ExpectedPerPacketOverhead(); |
| 467 | } |
| 468 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 469 | size_t ModuleRtpRtcpImpl::MaxRtpPacketSize() const { |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 470 | RTC_DCHECK(rtp_sender_); |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 471 | return rtp_sender_->packet_generator.MaxRtpPacketSize(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 472 | } |
| 473 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 474 | void ModuleRtpRtcpImpl::SetMaxRtpPacketSize(size_t rtp_packet_size) { |
| 475 | RTC_DCHECK_LE(rtp_packet_size, IP_PACKET_SIZE) |
| 476 | << "rtp packet size too large: " << rtp_packet_size; |
| 477 | RTC_DCHECK_GT(rtp_packet_size, packet_overhead_) |
| 478 | << "rtp packet size too small: " << rtp_packet_size; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 479 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 480 | rtcp_sender_.SetMaxRtpPacketSize(rtp_packet_size); |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 481 | if (rtp_sender_) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 482 | rtp_sender_->packet_generator.SetMaxRtpPacketSize(rtp_packet_size); |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 483 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 484 | } |
| 485 | |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 486 | RtcpMode ModuleRtpRtcpImpl::RTCP() const { |
Taylor Brandstetter | 5f0b83b | 2016-03-18 15:02:07 -0700 | [diff] [blame] | 487 | return rtcp_sender_.Status(); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 488 | } |
| 489 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 490 | // Configure RTCP status i.e on/off. |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 491 | void ModuleRtpRtcpImpl::SetRTCPStatus(const RtcpMode method) { |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 492 | rtcp_sender_.SetRTCPStatus(method); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 493 | } |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 494 | |
Peter Boström | 9ba52f8 | 2015-06-01 14:12:28 +0200 | [diff] [blame] | 495 | int32_t ModuleRtpRtcpImpl::SetCNAME(const char* c_name) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 496 | return rtcp_sender_.SetCNAME(c_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 499 | int32_t ModuleRtpRtcpImpl::RemoteNTP(uint32_t* received_ntpsecs, |
| 500 | uint32_t* received_ntpfrac, |
| 501 | uint32_t* rtcp_arrival_time_secs, |
| 502 | uint32_t* rtcp_arrival_time_frac, |
| 503 | uint32_t* rtcp_timestamp) const { |
| 504 | return rtcp_receiver_.NTP(received_ntpsecs, received_ntpfrac, |
| 505 | rtcp_arrival_time_secs, rtcp_arrival_time_frac, |
Alessio Bazzica | 048adc7 | 2021-03-10 15:05:55 +0100 | [diff] [blame] | 506 | rtcp_timestamp, |
| 507 | /*remote_sender_packet_count=*/nullptr, |
| 508 | /*remote_sender_octet_count=*/nullptr, |
| 509 | /*remote_sender_reports_count=*/nullptr) |
pbos@webrtc.org | 376b4ea | 2014-07-15 15:51:33 +0000 | [diff] [blame] | 510 | ? 0 |
| 511 | : -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 512 | } |
| 513 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 514 | // Get RoundTripTime. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 515 | int32_t ModuleRtpRtcpImpl::RTT(const uint32_t remote_ssrc, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 516 | int64_t* rtt, |
| 517 | int64_t* avg_rtt, |
| 518 | int64_t* min_rtt, |
| 519 | int64_t* max_rtt) const { |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 520 | int32_t ret = rtcp_receiver_.RTT(remote_ssrc, rtt, avg_rtt, min_rtt, max_rtt); |
| 521 | if (rtt && *rtt == 0) { |
| 522 | // Try to get RTT from RtcpRttStats class. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 523 | *rtt = rtt_ms(); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 524 | } |
| 525 | return ret; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 528 | int64_t ModuleRtpRtcpImpl::ExpectedRetransmissionTimeMs() const { |
| 529 | int64_t expected_retransmission_time_ms = rtt_ms(); |
| 530 | if (expected_retransmission_time_ms > 0) { |
| 531 | return expected_retransmission_time_ms; |
| 532 | } |
Artem Titov | 913cfa7 | 2021-07-28 23:57:33 +0200 | [diff] [blame^] | 533 | // No rtt available (`kRtpRtcpRttProcessTimeMs` not yet passed?), so try to |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 534 | // poll avg_rtt_ms directly from rtcp receiver. |
| 535 | if (rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), nullptr, |
| 536 | &expected_retransmission_time_ms, nullptr, |
| 537 | nullptr) == 0) { |
| 538 | return expected_retransmission_time_ms; |
| 539 | } |
| 540 | return kDefaultExpectedRetransmissionTimeMs; |
| 541 | } |
| 542 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 543 | // Force a send of an RTCP packet. |
| 544 | // Normal SR and RR are triggered via the process function. |
Erik Språng | 242e22b | 2015-05-11 10:17:43 +0200 | [diff] [blame] | 545 | int32_t ModuleRtpRtcpImpl::SendRTCP(RTCPPacketType packet_type) { |
| 546 | return rtcp_sender_.SendRTCP(GetFeedbackState(), packet_type); |
| 547 | } |
| 548 | |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 549 | void ModuleRtpRtcpImpl::GetSendStreamDataCounters( |
| 550 | StreamDataCounters* rtp_counters, |
| 551 | StreamDataCounters* rtx_counters) const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 552 | rtp_sender_->packet_sender.GetDataCounters(rtp_counters, rtx_counters); |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 553 | } |
| 554 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 555 | // Received RTCP report. |
Henrik Boström | 6e436d1 | 2019-05-27 12:19:33 +0200 | [diff] [blame] | 556 | std::vector<ReportBlockData> ModuleRtpRtcpImpl::GetLatestReportBlockData() |
| 557 | const { |
| 558 | return rtcp_receiver_.GetLatestReportBlockData(); |
| 559 | } |
| 560 | |
Alessio Bazzica | bc1c93d | 2021-03-12 17:45:26 +0100 | [diff] [blame] | 561 | absl::optional<RtpRtcpInterface::SenderReportStats> |
| 562 | ModuleRtpRtcpImpl::GetSenderReportStats() const { |
| 563 | SenderReportStats stats; |
| 564 | uint32_t remote_timestamp_secs; |
| 565 | uint32_t remote_timestamp_frac; |
| 566 | uint32_t arrival_timestamp_secs; |
| 567 | uint32_t arrival_timestamp_frac; |
| 568 | if (rtcp_receiver_.NTP(&remote_timestamp_secs, &remote_timestamp_frac, |
| 569 | &arrival_timestamp_secs, &arrival_timestamp_frac, |
| 570 | /*rtcp_timestamp=*/nullptr, &stats.packets_sent, |
| 571 | &stats.bytes_sent, &stats.reports_count)) { |
| 572 | stats.last_remote_timestamp.Set(remote_timestamp_secs, |
| 573 | remote_timestamp_frac); |
| 574 | stats.last_arrival_timestamp.Set(arrival_timestamp_secs, |
| 575 | arrival_timestamp_frac); |
| 576 | return stats; |
| 577 | } |
| 578 | return absl::nullopt; |
| 579 | } |
| 580 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 581 | // (REMB) Receiver Estimated Max Bitrate. |
Danil Chapovalov | 1de4b62 | 2017-12-13 13:35:10 +0100 | [diff] [blame] | 582 | void ModuleRtpRtcpImpl::SetRemb(int64_t bitrate_bps, |
| 583 | std::vector<uint32_t> ssrcs) { |
| 584 | rtcp_sender_.SetRemb(bitrate_bps, std::move(ssrcs)); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Danil Chapovalov | 51e21aa | 2017-10-10 17:46:26 +0200 | [diff] [blame] | 587 | void ModuleRtpRtcpImpl::UnsetRemb() { |
Danil Chapovalov | f74d641 | 2017-10-18 13:32:57 +0200 | [diff] [blame] | 588 | rtcp_sender_.UnsetRemb(); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 591 | void ModuleRtpRtcpImpl::SetExtmapAllowMixed(bool extmap_allow_mixed) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 592 | rtp_sender_->packet_generator.SetExtmapAllowMixed(extmap_allow_mixed); |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 593 | } |
| 594 | |
Sebastian Jansson | f39c815 | 2019-10-14 17:32:21 +0200 | [diff] [blame] | 595 | void ModuleRtpRtcpImpl::RegisterRtpHeaderExtension(absl::string_view uri, |
Danil Chapovalov | 585d1aa | 2018-09-14 18:29:32 +0200 | [diff] [blame] | 596 | int id) { |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 597 | bool registered = |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 598 | rtp_sender_->packet_generator.RegisterRtpHeaderExtension(uri, id); |
Sebastian Jansson | f39c815 | 2019-10-14 17:32:21 +0200 | [diff] [blame] | 599 | RTC_CHECK(registered); |
Danil Chapovalov | 585d1aa | 2018-09-14 18:29:32 +0200 | [diff] [blame] | 600 | } |
| 601 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 602 | int32_t ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 603 | const RTPExtensionType type) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 604 | return rtp_sender_->packet_generator.DeregisterRtpHeaderExtension(type); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 605 | } |
Sebastian Jansson | f39c815 | 2019-10-14 17:32:21 +0200 | [diff] [blame] | 606 | void ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension( |
| 607 | absl::string_view uri) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 608 | rtp_sender_->packet_generator.DeregisterRtpHeaderExtension(uri); |
Sebastian Jansson | f39c815 | 2019-10-14 17:32:21 +0200 | [diff] [blame] | 609 | } |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 610 | |
danilchap | 853ecb2 | 2016-08-22 08:26:15 -0700 | [diff] [blame] | 611 | void ModuleRtpRtcpImpl::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) { |
| 612 | rtcp_sender_.SetTmmbn(std::move(bounding_set)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 613 | } |
| 614 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 615 | // Send a Negative acknowledgment packet. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 616 | int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list, |
| 617 | const uint16_t size) { |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 618 | uint16_t nack_length = size; |
| 619 | uint16_t start_id = 0; |
Danil Chapovalov | 9eb6ce1 | 2017-12-15 12:25:01 +0100 | [diff] [blame] | 620 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 621 | if (TimeToSendFullNackList(now_ms)) { |
| 622 | nack_last_time_sent_full_ms_ = now_ms; |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 623 | } else { |
| 624 | // Only send extended list. |
| 625 | if (nack_last_seq_number_sent_ == nack_list[size - 1]) { |
| 626 | // Last sequence number is the same, do not send list. |
| 627 | return 0; |
| 628 | } |
| 629 | // Send new sequence numbers. |
| 630 | for (int i = 0; i < size; ++i) { |
| 631 | if (nack_last_seq_number_sent_ == nack_list[i]) { |
| 632 | start_id = i + 1; |
| 633 | break; |
| 634 | } |
| 635 | } |
| 636 | nack_length = size - start_id; |
| 637 | } |
| 638 | |
| 639 | // Our RTCP NACK implementation is limited to kRtcpMaxNackFields sequence |
| 640 | // numbers per RTCP packet. |
| 641 | if (nack_length > kRtcpMaxNackFields) { |
| 642 | nack_length = kRtcpMaxNackFields; |
| 643 | } |
| 644 | nack_last_seq_number_sent_ = nack_list[start_id + nack_length - 1]; |
| 645 | |
philipel | 83f831a | 2016-03-12 03:30:23 -0800 | [diff] [blame] | 646 | return rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, nack_length, |
| 647 | &nack_list[start_id]); |
| 648 | } |
| 649 | |
| 650 | void ModuleRtpRtcpImpl::SendNack( |
| 651 | const std::vector<uint16_t>& sequence_numbers) { |
| 652 | rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, sequence_numbers.size(), |
| 653 | sequence_numbers.data()); |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | bool ModuleRtpRtcpImpl::TimeToSendFullNackList(int64_t now) const { |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 657 | // Use RTT from RtcpRttStats class if provided. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 658 | int64_t rtt = rtt_ms(); |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 659 | if (rtt == 0) { |
| 660 | rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); |
| 661 | } |
stefan@webrtc.org | 8ca8a71 | 2013-04-23 16:48:32 +0000 | [diff] [blame] | 662 | |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 663 | const int64_t kStartUpRttMs = 100; |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 664 | int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5. |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 665 | if (rtt == 0) { |
| 666 | wait_time = kStartUpRttMs; |
stefan@webrtc.org | 8ca8a71 | 2013-04-23 16:48:32 +0000 | [diff] [blame] | 667 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 668 | |
Artem Titov | 913cfa7 | 2021-07-28 23:57:33 +0200 | [diff] [blame^] | 669 | // Send a full NACK list once within every `wait_time`. |
Danil Chapovalov | 9eb6ce1 | 2017-12-15 12:25:01 +0100 | [diff] [blame] | 670 | return now - nack_last_time_sent_full_ms_ > wait_time; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 671 | } |
| 672 | |
asapersson@webrtc.org | 9ffd8fe | 2015-01-21 08:22:50 +0000 | [diff] [blame] | 673 | // Store the sent packets, needed to answer to Negative acknowledgment requests. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 674 | void ModuleRtpRtcpImpl::SetStorePacketsStatus(const bool enable, |
| 675 | const uint16_t number_to_store) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 676 | rtp_sender_->packet_history.SetStorePacketsStatus( |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 677 | enable ? RtpPacketHistory::StorageMode::kStoreAndCull |
| 678 | : RtpPacketHistory::StorageMode::kDisabled, |
| 679 | number_to_store); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 680 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 681 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 682 | bool ModuleRtpRtcpImpl::StorePackets() const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 683 | return rtp_sender_->packet_history.GetStorageMode() != |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 684 | RtpPacketHistory::StorageMode::kDisabled; |
tnakamura@webrtc.org | aa4d96a | 2013-07-16 19:25:04 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Per Kjellander | 1699981 | 2019-10-10 12:57:28 +0200 | [diff] [blame] | 687 | void ModuleRtpRtcpImpl::SendCombinedRtcpPacket( |
| 688 | std::vector<std::unique_ptr<rtcp::RtcpPacket>> rtcp_packets) { |
| 689 | rtcp_sender_.SendCombinedRtcpPacket(std::move(rtcp_packets)); |
| 690 | } |
| 691 | |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 692 | int32_t ModuleRtpRtcpImpl::SendLossNotification(uint16_t last_decoded_seq_num, |
| 693 | uint16_t last_received_seq_num, |
Elad Alon | e86af2c | 2019-06-03 14:37:50 +0200 | [diff] [blame] | 694 | bool decodability_flag, |
| 695 | bool buffering_allowed) { |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 696 | return rtcp_sender_.SendLossNotification( |
| 697 | GetFeedbackState(), last_decoded_seq_num, last_received_seq_num, |
Elad Alon | e86af2c | 2019-06-03 14:37:50 +0200 | [diff] [blame] | 698 | decodability_flag, buffering_allowed); |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 699 | } |
| 700 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 701 | void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 702 | // Inform about the incoming SSRC. |
| 703 | rtcp_sender_.SetRemoteSSRC(ssrc); |
| 704 | rtcp_receiver_.SetRemoteSSRC(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Tommi | 08be9ba | 2021-06-15 23:01:57 +0200 | [diff] [blame] | 707 | void ModuleRtpRtcpImpl::SetLocalSsrc(uint32_t local_ssrc) { |
| 708 | rtcp_receiver_.set_local_media_ssrc(local_ssrc); |
| 709 | rtcp_sender_.SetSsrc(local_ssrc); |
| 710 | } |
| 711 | |
Erik Språng | bf46cfe | 2020-05-11 18:22:02 +0200 | [diff] [blame] | 712 | RtpSendRates ModuleRtpRtcpImpl::GetSendRates() const { |
| 713 | return rtp_sender_->packet_sender.GetSendRates(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 714 | } |
| 715 | |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 716 | void ModuleRtpRtcpImpl::OnRequestSendReport() { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 717 | SendRTCP(kRtcpSr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Danil Chapovalov | 2800d74 | 2016-08-26 18:48:46 +0200 | [diff] [blame] | 720 | void ModuleRtpRtcpImpl::OnReceivedNack( |
| 721 | const std::vector<uint16_t>& nack_sequence_numbers) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 722 | if (!rtp_sender_) |
| 723 | return; |
| 724 | |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 725 | if (!StorePackets() || nack_sequence_numbers.empty()) { |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 726 | return; |
| 727 | } |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 728 | // Use RTT from RtcpRttStats class if provided. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 729 | int64_t rtt = rtt_ms(); |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 730 | if (rtt == 0) { |
| 731 | rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); |
| 732 | } |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 733 | rtp_sender_->packet_generator.OnReceivedNack(nack_sequence_numbers, rtt); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 734 | } |
| 735 | |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 736 | void ModuleRtpRtcpImpl::OnReceivedRtcpReportBlocks( |
| 737 | const ReportBlockList& report_blocks) { |
Erik Språng | 56e611b | 2020-02-06 17:10:08 +0100 | [diff] [blame] | 738 | if (rtp_sender_) { |
Niels Möller | 59ab1cf | 2019-02-06 22:48:11 +0100 | [diff] [blame] | 739 | uint32_t ssrc = SSRC(); |
Steve Anton | 2bac7da | 2019-07-21 15:04:21 -0400 | [diff] [blame] | 740 | absl::optional<uint32_t> rtx_ssrc; |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 741 | if (rtp_sender_->packet_generator.RtxStatus() != kRtxOff) { |
| 742 | rtx_ssrc = rtp_sender_->packet_generator.RtxSsrc(); |
Steve Anton | 2bac7da | 2019-07-21 15:04:21 -0400 | [diff] [blame] | 743 | } |
Niels Möller | 59ab1cf | 2019-02-06 22:48:11 +0100 | [diff] [blame] | 744 | |
| 745 | for (const RTCPReportBlock& report_block : report_blocks) { |
| 746 | if (ssrc == report_block.source_ssrc) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 747 | rtp_sender_->packet_generator.OnReceivedAckOnSsrc( |
Steve Anton | 2bac7da | 2019-07-21 15:04:21 -0400 | [diff] [blame] | 748 | report_block.extended_highest_sequence_number); |
Steve Anton | 2bac7da | 2019-07-21 15:04:21 -0400 | [diff] [blame] | 749 | } else if (rtx_ssrc && *rtx_ssrc == report_block.source_ssrc) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 750 | rtp_sender_->packet_generator.OnReceivedAckOnRtxSsrc( |
Steve Anton | 2bac7da | 2019-07-21 15:04:21 -0400 | [diff] [blame] | 751 | report_block.extended_highest_sequence_number); |
Niels Möller | 59ab1cf | 2019-02-06 22:48:11 +0100 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | } |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 755 | } |
| 756 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 757 | void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) { |
Tommi | d7e08c8 | 2020-05-10 11:24:43 +0200 | [diff] [blame] | 758 | { |
Markus Handell | f7303e6 | 2020-07-09 01:34:42 +0200 | [diff] [blame] | 759 | MutexLock lock(&mutex_rtt_); |
Tommi | d7e08c8 | 2020-05-10 11:24:43 +0200 | [diff] [blame] | 760 | rtt_ms_ = rtt_ms; |
| 761 | } |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 762 | if (rtp_sender_) { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 763 | rtp_sender_->packet_history.SetRtt(rtt_ms); |
Erik Språng | 77b7529 | 2019-10-28 15:51:36 +0100 | [diff] [blame] | 764 | } |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 765 | } |
| 766 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 767 | int64_t ModuleRtpRtcpImpl::rtt_ms() const { |
Markus Handell | f7303e6 | 2020-07-09 01:34:42 +0200 | [diff] [blame] | 768 | MutexLock lock(&mutex_rtt_); |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 769 | return rtt_ms_; |
| 770 | } |
| 771 | |
sprang | 5e38c96 | 2016-12-01 05:18:09 -0800 | [diff] [blame] | 772 | void ModuleRtpRtcpImpl::SetVideoBitrateAllocation( |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 773 | const VideoBitrateAllocation& bitrate) { |
sprang | 5e38c96 | 2016-12-01 05:18:09 -0800 | [diff] [blame] | 774 | rtcp_sender_.SetVideoBitrateAllocation(bitrate); |
| 775 | } |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 776 | |
| 777 | RTPSender* ModuleRtpRtcpImpl::RtpSender() { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 778 | return rtp_sender_ ? &rtp_sender_->packet_generator : nullptr; |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | const RTPSender* ModuleRtpRtcpImpl::RtpSender() const { |
Erik Språng | 9cdc9cc | 2019-10-28 18:24:32 +0100 | [diff] [blame] | 782 | return rtp_sender_ ? &rtp_sender_->packet_generator : nullptr; |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 783 | } |
| 784 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 785 | } // namespace webrtc |