blob: aaf1822c92f428914036a377329fa62647319b58 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/rtp_rtcp/source/rtp_rtcp_impl.h"
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +000012
pbos@webrtc.orga048d7c2013-05-29 14:27:38 +000013#include <string.h>
sprang168794c2017-07-06 04:38:06 -070014#include <algorithm>
Yves Gerey988cc082018-10-23 12:03:01 +020015#include <cstdint>
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000016#include <set>
Peter Boström9c017252016-02-26 16:26:20 +010017#include <string>
Yves Gerey988cc082018-10-23 12:03:01 +020018#include <utility>
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000019
Niels Möller59ab1cf2019-02-06 22:48:11 +010020#include "absl/memory/memory.h"
Per Kjellandere11b7d22019-02-21 07:55:59 +010021#include "api/transport/field_trial_based_config.h"
Yves Gerey988cc082018-10-23 12:03:01 +020022#include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
23#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_base/checks.h"
25#include "rtc_base/logging.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000026
niklase@google.com470e71d2011-07-07 08:21:25 +000027#ifdef _WIN32
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +000028// Disable warning C4355: 'this' : used in base member initializer list.
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +000029#pragma warning(disable : 4355)
niklase@google.com470e71d2011-07-07 08:21:25 +000030#endif
31
32namespace webrtc {
sprang168794c2017-07-06 04:38:06 -070033namespace {
34const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5;
35const int64_t kRtpRtcpRttProcessTimeMs = 1000;
36const int64_t kRtpRtcpBitrateProcessTimeMs = 10;
spranga8ae6f22017-09-04 07:23:56 -070037const int64_t kDefaultExpectedRetransmissionTimeMs = 125;
Jiawei Ou8b5d9d82018-11-15 16:44:37 -080038constexpr int32_t kDefaultVideoReportInterval = 1000;
39constexpr int32_t kDefaultAudioReportInterval = 5000;
sprang168794c2017-07-06 04:38:06 -070040} // namespace
niklase@google.com470e71d2011-07-07 08:21:25 +000041
danilchapd3f3c342017-07-25 04:20:12 -070042RtpRtcp::Configuration::Configuration() = default;
Erik Språng4580ca22019-07-04 10:38:43 +020043RtpRtcp::Configuration::Configuration(Configuration&& rhs) = default;
phoglund@webrtc.orga22a9bd2013-01-14 10:01:55 +000044
Danil Chapovalovc44f6cc2019-03-06 11:31:09 +010045std::unique_ptr<RtpRtcp> RtpRtcp::Create(const Configuration& configuration) {
46 RTC_DCHECK(configuration.clock);
47 return absl::make_unique<ModuleRtpRtcpImpl>(configuration);
48}
49
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000050RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) {
51 if (configuration.clock) {
52 return new ModuleRtpRtcpImpl(configuration);
henrike@webrtc.orgf5da4da2012-02-15 23:54:59 +000053 } else {
pbos@webrtc.org180e5162014-07-11 15:36:26 +000054 // No clock implementation provided, use default clock.
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000055 RtpRtcp::Configuration configuration_copy;
Yves Gerey665174f2018-06-19 15:03:05 +020056 memcpy(&configuration_copy, &configuration, sizeof(RtpRtcp::Configuration));
stefan@webrtc.org20ed36d2013-01-17 14:01:20 +000057 configuration_copy.clock = Clock::GetRealTimeClock();
pbos@webrtc.org180e5162014-07-11 15:36:26 +000058 return new ModuleRtpRtcpImpl(configuration_copy);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +000059 }
niklase@google.com470e71d2011-07-07 08:21:25 +000060}
61
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000062ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration)
nisse14adba72017-03-20 03:52:39 -070063 : rtcp_sender_(configuration.audio,
stefan@webrtc.orga15fbfd2014-06-17 17:32:05 +000064 configuration.clock,
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000065 configuration.receive_statistics,
sprang86fd9ed2015-09-29 04:45:43 -070066 configuration.rtcp_packet_type_counter_observer,
terelius429c3452016-01-21 05:42:04 -080067 configuration.event_log,
Jiawei Ou3587b832018-01-31 22:08:26 -080068 configuration.outgoing_transport,
Jiawei Ou8b5d9d82018-11-15 16:44:37 -080069 configuration.rtcp_report_interval_ms > 0
70 ? configuration.rtcp_report_interval_ms
71 : (configuration.audio ? kDefaultAudioReportInterval
72 : kDefaultVideoReportInterval)),
Peter Boströmac547a62015-09-17 23:03:57 +020073 rtcp_receiver_(configuration.clock,
Peter Boströmfe7a80c2015-04-23 17:53:17 +020074 configuration.receiver_only,
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000075 configuration.rtcp_packet_type_counter_observer,
mflodman@webrtc.org96abda02015-02-25 13:50:10 +000076 configuration.bandwidth_callback,
77 configuration.intra_frame_callback,
Elad Alon0a8562e2019-04-09 11:55:13 +020078 configuration.rtcp_loss_notification_observer,
Erik Språng6b8d3552015-09-24 15:06:57 +020079 configuration.transport_feedback_callback,
spranga790d832016-12-02 07:29:44 -080080 configuration.bitrate_allocation_observer,
Jiawei Ou8b5d9d82018-11-15 16:44:37 -080081 configuration.rtcp_report_interval_ms > 0
82 ? configuration.rtcp_report_interval_ms
83 : (configuration.audio ? kDefaultAudioReportInterval
84 : kDefaultVideoReportInterval),
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000085 this),
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000086 clock_(configuration.clock),
sprang168794c2017-07-06 04:38:06 -070087 last_bitrate_process_time_(clock_->TimeInMilliseconds()),
88 last_rtt_process_time_(clock_->TimeInMilliseconds()),
89 next_process_time_(clock_->TimeInMilliseconds() +
90 kRtpRtcpMaxIdleTimeProcessMs),
asapersson35151f32016-05-02 23:44:01 -070091 packet_overhead_(28), // IPV4 UDP.
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +010092 nack_last_time_sent_full_ms_(0),
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +000093 nack_last_seq_number_sent_(0),
mflodman@webrtc.org7c894b72012-11-26 12:40:15 +000094 remote_bitrate_(configuration.remote_bitrate_estimator),
Niels Möller5fe95102019-03-04 16:49:25 +010095 ack_observer_(configuration.ack_observer),
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000096 rtt_stats_(configuration.rtt_stats),
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000097 rtt_ms_(0) {
nisse14adba72017-03-20 03:52:39 -070098 if (!configuration.receiver_only) {
Erik Språng4580ca22019-07-04 10:38:43 +020099 rtp_sender_.reset(new RTPSender(configuration));
nisse14adba72017-03-20 03:52:39 -0700100 // Make sure rtcp sender use same timestamp offset as rtp sender.
101 rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset());
102 }
danilchap71fead22016-08-18 02:01:49 -0700103
104 // Set default packet size limit.
nisse284542b2017-01-10 08:58:32 -0800105 // TODO(nisse): Kind-of duplicates
106 // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize.
107 const size_t kTcpOverIpv4HeaderSize = 40;
108 SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize);
niklase@google.com470e71d2011-07-07 08:21:25 +0000109}
110
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100111ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() = default;
112
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000113// Returns the number of milliseconds until the module want a worker thread
114// to call Process.
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000115int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() {
sprang168794c2017-07-06 04:38:06 -0700116 return std::max<int64_t>(0,
117 next_process_time_ - clock_->TimeInMilliseconds());
niklase@google.com470e71d2011-07-07 08:21:25 +0000118}
119
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000120// Process any pending tasks such as timeouts (non time critical events).
pbosa26ac922016-02-25 04:50:01 -0800121void ModuleRtpRtcpImpl::Process() {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000122 const int64_t now = clock_->TimeInMilliseconds();
sprang168794c2017-07-06 04:38:06 -0700123 next_process_time_ = now + kRtpRtcpMaxIdleTimeProcessMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
nisse14adba72017-03-20 03:52:39 -0700125 if (rtp_sender_) {
nisse14adba72017-03-20 03:52:39 -0700126 if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) {
127 rtp_sender_->ProcessBitrate();
128 last_bitrate_process_time_ = now;
sprang168794c2017-07-06 04:38:06 -0700129 next_process_time_ =
130 std::min(next_process_time_, now + kRtpRtcpBitrateProcessTimeMs);
131 }
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000132 }
sprang168794c2017-07-06 04:38:06 -0700133
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000134 bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs;
135 if (rtcp_sender_.Sending()) {
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200136 // Process RTT if we have received a report block and we haven't
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000137 // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds.
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200138 if (rtcp_receiver_.LastReceivedReportBlockMs() > last_rtt_process_time_ &&
139 process_rtt) {
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000140 std::vector<RTCPReportBlock> receive_blocks;
141 rtcp_receiver_.StatisticsReceived(&receive_blocks);
142 int64_t max_rtt = 0;
143 for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin();
144 it != receive_blocks.end(); ++it) {
145 int64_t rtt = 0;
srte3e69e5c2017-08-09 06:13:45 -0700146 rtcp_receiver_.RTT(it->sender_ssrc, &rtt, NULL, NULL, NULL);
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000147 max_rtt = (rtt > max_rtt) ? rtt : max_rtt;
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +0000148 }
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000149 // Report the rtt.
150 if (rtt_stats_ && max_rtt != 0)
151 rtt_stats_->OnRttUpdate(max_rtt);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000152 }
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000153
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000154 // Verify receiver reports are delivered and the reported sequence number
155 // is increasing.
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800156 if (rtcp_receiver_.RtcpRrTimeout()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100157 RTC_LOG_F(LS_WARNING) << "Timeout: No RTCP RR received.";
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800158 } else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100159 RTC_LOG_F(LS_WARNING) << "Timeout: No increase in RTCP RR extended "
160 "highest sequence number.";
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000161 }
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.org7d6bd222013-10-31 12:14:34 +0000175 if (process_rtt) {
Yves Gerey665174f2018-06-19 15:03:05 +0200176 int64_t rtt_ms;
177 if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) {
178 rtt_stats_->OnRttUpdate(rtt_ms);
179 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000180 }
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000181 }
182
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000183 // Get processed rtt.
184 if (process_rtt) {
185 last_rtt_process_time_ = now;
sprang168794c2017-07-06 04:38:06 -0700186 next_process_time_ = std::min(
187 next_process_time_, last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs);
sprange2d83d62016-02-19 09:03:26 -0800188 if (rtt_stats_) {
189 // Make sure we have a valid RTT before setting.
190 int64_t last_rtt = rtt_stats_->LastProcessedRtt();
191 if (last_rtt >= 0)
192 set_rtt_ms(last_rtt);
193 }
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000194 }
195
Danil Chapovalov70ffead2016-07-20 15:26:59 +0200196 if (rtcp_sender_.TimeToSendRTCPReport())
197 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000198
danilchap9bf610e2017-02-20 06:03:01 -0800199 if (TMMBR() && rtcp_receiver_.UpdateTmmbrTimers()) {
200 rtcp_receiver_.NotifyTmmbrUpdated();
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000201 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000202}
203
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000204void ModuleRtpRtcpImpl::SetRtxSendStatus(int mode) {
nisse14adba72017-03-20 03:52:39 -0700205 rtp_sender_->SetRtxStatus(mode);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000206}
207
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000208int ModuleRtpRtcpImpl::RtxSendStatus() const {
nisse14adba72017-03-20 03:52:39 -0700209 return rtp_sender_ ? rtp_sender_->RtxStatus() : kRtxOff;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000210}
211
212void ModuleRtpRtcpImpl::SetRtxSsrc(uint32_t ssrc) {
nisse14adba72017-03-20 03:52:39 -0700213 rtp_sender_->SetRtxSsrc(ssrc);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000214}
215
Shao Changbine62202f2015-04-21 20:24:50 +0800216void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type,
217 int associated_payload_type) {
nisse14adba72017-03-20 03:52:39 -0700218 rtp_sender_->SetRtxPayloadType(payload_type, associated_payload_type);
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000219}
220
Danil Chapovalovd264df52018-06-14 12:59:38 +0200221absl::optional<uint32_t> ModuleRtpRtcpImpl::FlexfecSsrc() const {
brandtr7c7796b2017-07-03 06:02:53 -0700222 if (rtp_sender_)
223 return rtp_sender_->FlexfecSsrc();
Danil Chapovalovd264df52018-06-14 12:59:38 +0200224 return absl::nullopt;
brandtr9dfff292016-11-14 05:14:50 -0800225}
226
nisse479d3d72017-09-13 07:53:37 -0700227void ModuleRtpRtcpImpl::IncomingRtcpPacket(const uint8_t* rtcp_packet,
228 const size_t length) {
229 rtcp_receiver_.IncomingPacket(rtcp_packet, length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000230}
231
Niels Möller5fe95102019-03-04 16:49:25 +0100232void ModuleRtpRtcpImpl::RegisterSendPayloadFrequency(int payload_type,
233 int payload_frequency) {
234 rtcp_sender_.SetRtpClockRate(payload_type, payload_frequency);
Peter Boström8b79b072016-02-26 16:31:37 +0100235}
236
asapersson@webrtc.org9ffd8fe2015-01-21 08:22:50 +0000237int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload(const int8_t payload_type) {
Niels Möller59ab1cf2019-02-06 22:48:11 +0100238 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000239}
240
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000241uint32_t ModuleRtpRtcpImpl::StartTimestamp() const {
nisse14adba72017-03-20 03:52:39 -0700242 return rtp_sender_->TimestampOffset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000243}
244
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000245// Configure start timestamp, default is a random number.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000246void ModuleRtpRtcpImpl::SetStartTimestamp(const uint32_t timestamp) {
danilchap71fead22016-08-18 02:01:49 -0700247 rtcp_sender_.SetTimestampOffset(timestamp);
nisse14adba72017-03-20 03:52:39 -0700248 rtp_sender_->SetTimestampOffset(timestamp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000249}
250
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000251uint16_t ModuleRtpRtcpImpl::SequenceNumber() const {
nisse14adba72017-03-20 03:52:39 -0700252 return rtp_sender_->SequenceNumber();
niklase@google.com470e71d2011-07-07 08:21:25 +0000253}
254
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000255// Set SequenceNumber, default is a random number.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000256void ModuleRtpRtcpImpl::SetSequenceNumber(const uint16_t seq_num) {
nisse14adba72017-03-20 03:52:39 -0700257 rtp_sender_->SetSequenceNumber(seq_num);
niklase@google.com470e71d2011-07-07 08:21:25 +0000258}
259
Per83d09102016-04-15 14:59:13 +0200260void ModuleRtpRtcpImpl::SetRtpState(const RtpState& rtp_state) {
nisse14adba72017-03-20 03:52:39 -0700261 rtp_sender_->SetRtpState(rtp_state);
danilchap71fead22016-08-18 02:01:49 -0700262 rtcp_sender_.SetTimestampOffset(rtp_state.start_timestamp);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000263}
264
Per83d09102016-04-15 14:59:13 +0200265void ModuleRtpRtcpImpl::SetRtxState(const RtpState& rtp_state) {
nisse14adba72017-03-20 03:52:39 -0700266 rtp_sender_->SetRtxRtpState(rtp_state);
Per83d09102016-04-15 14:59:13 +0200267}
268
269RtpState ModuleRtpRtcpImpl::GetRtpState() const {
nisse14adba72017-03-20 03:52:39 -0700270 return rtp_sender_->GetRtpState();
Per83d09102016-04-15 14:59:13 +0200271}
272
273RtpState ModuleRtpRtcpImpl::GetRtxState() const {
nisse14adba72017-03-20 03:52:39 -0700274 return rtp_sender_->GetRtxRtpState();
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000275}
276
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000277uint32_t ModuleRtpRtcpImpl::SSRC() const {
nisse14adba72017-03-20 03:52:39 -0700278 return rtcp_sender_.SSRC();
niklase@google.com470e71d2011-07-07 08:21:25 +0000279}
280
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000281void ModuleRtpRtcpImpl::SetSSRC(const uint32_t ssrc) {
nisse14adba72017-03-20 03:52:39 -0700282 if (rtp_sender_) {
283 rtp_sender_->SetSSRC(ssrc);
284 }
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000285 rtcp_sender_.SetSSRC(ssrc);
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000286 SetRtcpReceiverSsrcs(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000287}
288
Amit Hilbuch77938e62018-12-21 09:23:38 -0800289void ModuleRtpRtcpImpl::SetRid(const std::string& rid) {
290 if (rtp_sender_) {
291 rtp_sender_->SetRid(rid);
292 }
293}
294
Steve Anton296a0ce2018-03-22 15:17:27 -0700295void ModuleRtpRtcpImpl::SetMid(const std::string& mid) {
296 if (rtp_sender_) {
297 rtp_sender_->SetMid(mid);
298 }
299 // TODO(bugs.webrtc.org/4050): If we end up supporting the MID SDES item for
300 // RTCP, this will need to be passed down to the RTCPSender also.
301}
302
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000303void ModuleRtpRtcpImpl::SetCsrcs(const std::vector<uint32_t>& csrcs) {
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000304 rtcp_sender_.SetCsrcs(csrcs);
nisse14adba72017-03-20 03:52:39 -0700305 rtp_sender_->SetCsrcs(csrcs);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000306}
307
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000308// TODO(pbos): Handle media and RTX streams separately (separate RTCP
309// feedbacks).
310RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000311 RTCPSender::FeedbackState state;
nisse14adba72017-03-20 03:52:39 -0700312 // This is called also when receiver_only is true. Hence below
313 // checks that rtp_sender_ exists.
314 if (rtp_sender_) {
315 StreamDataCounters rtp_stats;
316 StreamDataCounters rtx_stats;
317 rtp_sender_->GetDataCounters(&rtp_stats, &rtx_stats);
Yves Gerey665174f2018-06-19 15:03:05 +0200318 state.packets_sent =
319 rtp_stats.transmitted.packets + rtx_stats.transmitted.packets;
nisse14adba72017-03-20 03:52:39 -0700320 state.media_bytes_sent = rtp_stats.transmitted.payload_bytes +
321 rtx_stats.transmitted.payload_bytes;
322 state.send_bitrate = rtp_sender_->BitrateSent();
323 }
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000324 state.module = this;
325
Yves Gerey665174f2018-06-19 15:03:05 +0200326 LastReceivedNTP(&state.last_rr_ntp_secs, &state.last_rr_ntp_frac,
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000327 &state.remote_sr);
328
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +0200329 state.last_xr_rtis = rtcp_receiver_.ConsumeReceivedXrReferenceTimeInfo();
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000330
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000331 return state;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000332}
333
nisse14adba72017-03-20 03:52:39 -0700334// TODO(nisse): This method shouldn't be called for a receive-only
335// stream. Delete rtp_sender_ check as soon as all applications are
336// updated.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000337int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000338 if (rtcp_sender_.Sending() != sending) {
339 // Sends RTCP BYE when going from true to false
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000340 if (rtcp_sender_.SetSendingStatus(GetFeedbackState(), sending) != 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100341 RTC_LOG(LS_WARNING) << "Failed to send RTCP BYE";
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000342 }
nisse14adba72017-03-20 03:52:39 -0700343 if (sending && rtp_sender_) {
nisse7d59f6b2017-02-21 03:40:24 -0800344 // Update Rtcp receiver config, to track Rtx config changes from
345 // the SetRtxStatus and SetRtxSsrc methods.
nisse14adba72017-03-20 03:52:39 -0700346 SetRtcpReceiverSsrcs(rtp_sender_->SSRC());
nisse7d59f6b2017-02-21 03:40:24 -0800347 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000348 }
349 return 0;
350}
351
352bool ModuleRtpRtcpImpl::Sending() const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000353 return rtcp_sender_.Sending();
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000354}
355
nisse14adba72017-03-20 03:52:39 -0700356// 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.orgd16e8392014-12-19 13:49:55 +0000359void ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) {
nisse14adba72017-03-20 03:52:39 -0700360 if (rtp_sender_) {
361 rtp_sender_->SetSendingMediaStatus(sending);
362 } else {
363 RTC_DCHECK(!sending);
364 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000365}
366
367bool ModuleRtpRtcpImpl::SendingMedia() const {
nisse14adba72017-03-20 03:52:39 -0700368 return rtp_sender_ ? rtp_sender_->SendingMedia() : false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000369}
370
Sebastian Jansson1bca65b2018-10-10 09:58:08 +0200371void ModuleRtpRtcpImpl::SetAsPartOfAllocation(bool part_of_allocation) {
372 RTC_CHECK(rtp_sender_);
373 rtp_sender_->SetAsPartOfAllocation(part_of_allocation);
374}
375
Niels Möller5fe95102019-03-04 16:49:25 +0100376bool ModuleRtpRtcpImpl::OnSendingRtpFrame(uint32_t timestamp,
377 int64_t capture_time_ms,
378 int payload_type,
379 bool force_sender_report) {
380 if (!Sending())
381 return false;
382
383 rtcp_sender_.SetLastRtpTime(timestamp, capture_time_ms, payload_type);
384 // Make sure an RTCP report isn't queued behind a key frame.
385 if (rtcp_sender_.TimeToSendRTCPReport(force_sender_report))
386 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
387
388 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000389}
390
Erik Språngd2879622019-05-10 08:29:01 -0700391RtpPacketSendResult ModuleRtpRtcpImpl::TimeToSendPacket(
392 uint32_t ssrc,
393 uint16_t sequence_number,
394 int64_t capture_time_ms,
395 bool retransmission,
396 const PacedPacketInfo& pacing_info) {
nisse14adba72017-03-20 03:52:39 -0700397 return rtp_sender_->TimeToSendPacket(ssrc, sequence_number, capture_time_ms,
Yves Gerey665174f2018-06-19 15:03:05 +0200398 retransmission, pacing_info);
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000399}
400
Erik Språng9c771c22019-06-17 16:31:53 +0200401bool ModuleRtpRtcpImpl::TrySendPacket(RtpPacketToSend* packet,
402 const PacedPacketInfo& pacing_info) {
403 return rtp_sender_->TrySendPacket(packet, pacing_info);
404}
405
philipelc7bf32a2017-02-17 03:59:43 -0800406size_t ModuleRtpRtcpImpl::TimeToSendPadding(
407 size_t bytes,
408 const PacedPacketInfo& pacing_info) {
nisse14adba72017-03-20 03:52:39 -0700409 return rtp_sender_->TimeToSendPadding(bytes, pacing_info);
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000410}
411
Erik Språngf6468d22019-07-05 16:53:43 +0200412std::vector<std::unique_ptr<RtpPacketToSend>>
413ModuleRtpRtcpImpl::GeneratePadding(size_t target_size_bytes) {
414 return rtp_sender_->GeneratePadding(target_size_bytes);
Erik Språng478cb462019-06-26 15:49:27 +0200415}
416
nisse284542b2017-01-10 08:58:32 -0800417size_t ModuleRtpRtcpImpl::MaxRtpPacketSize() const {
nisse14adba72017-03-20 03:52:39 -0700418 return rtp_sender_->MaxRtpPacketSize();
niklase@google.com470e71d2011-07-07 08:21:25 +0000419}
420
nisse284542b2017-01-10 08:58:32 -0800421void ModuleRtpRtcpImpl::SetMaxRtpPacketSize(size_t rtp_packet_size) {
422 RTC_DCHECK_LE(rtp_packet_size, IP_PACKET_SIZE)
423 << "rtp packet size too large: " << rtp_packet_size;
424 RTC_DCHECK_GT(rtp_packet_size, packet_overhead_)
425 << "rtp packet size too small: " << rtp_packet_size;
niklase@google.com470e71d2011-07-07 08:21:25 +0000426
nisse284542b2017-01-10 08:58:32 -0800427 rtcp_sender_.SetMaxRtpPacketSize(rtp_packet_size);
nisse14adba72017-03-20 03:52:39 -0700428 if (rtp_sender_)
429 rtp_sender_->SetMaxRtpPacketSize(rtp_packet_size);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000430}
431
pbosda903ea2015-10-02 02:36:56 -0700432RtcpMode ModuleRtpRtcpImpl::RTCP() const {
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700433 return rtcp_sender_.Status();
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000434}
435
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000436// Configure RTCP status i.e on/off.
pbosda903ea2015-10-02 02:36:56 -0700437void ModuleRtpRtcpImpl::SetRTCPStatus(const RtcpMode method) {
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000438 rtcp_sender_.SetRTCPStatus(method);
niklase@google.com470e71d2011-07-07 08:21:25 +0000439}
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000440
Peter Boström9ba52f82015-06-01 14:12:28 +0200441int32_t ModuleRtpRtcpImpl::SetCNAME(const char* c_name) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000442 return rtcp_sender_.SetCNAME(c_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000443}
444
Erik Språng0ea42d32015-06-25 14:46:16 +0200445int32_t ModuleRtpRtcpImpl::AddMixedCNAME(uint32_t ssrc, const char* c_name) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000446 return rtcp_sender_.AddMixedCNAME(ssrc, c_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000447}
448
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000449int32_t ModuleRtpRtcpImpl::RemoveMixedCNAME(const uint32_t ssrc) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000450 return rtcp_sender_.RemoveMixedCNAME(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000451}
452
Yves Gerey665174f2018-06-19 15:03:05 +0200453int32_t ModuleRtpRtcpImpl::RemoteCNAME(const uint32_t remote_ssrc,
454 char c_name[RTCP_CNAME_SIZE]) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000455 return rtcp_receiver_.CNAME(remote_ssrc, c_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000456}
457
Yves Gerey665174f2018-06-19 15:03:05 +0200458int32_t ModuleRtpRtcpImpl::RemoteNTP(uint32_t* received_ntpsecs,
459 uint32_t* received_ntpfrac,
460 uint32_t* rtcp_arrival_time_secs,
461 uint32_t* rtcp_arrival_time_frac,
462 uint32_t* rtcp_timestamp) const {
463 return rtcp_receiver_.NTP(received_ntpsecs, received_ntpfrac,
464 rtcp_arrival_time_secs, rtcp_arrival_time_frac,
pbos@webrtc.org376b4ea2014-07-15 15:51:33 +0000465 rtcp_timestamp)
466 ? 0
467 : -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000468}
469
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000470// Get RoundTripTime.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000471int32_t ModuleRtpRtcpImpl::RTT(const uint32_t remote_ssrc,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000472 int64_t* rtt,
473 int64_t* avg_rtt,
474 int64_t* min_rtt,
475 int64_t* max_rtt) const {
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000476 int32_t ret = rtcp_receiver_.RTT(remote_ssrc, rtt, avg_rtt, min_rtt, max_rtt);
477 if (rtt && *rtt == 0) {
478 // Try to get RTT from RtcpRttStats class.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000479 *rtt = rtt_ms();
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000480 }
481 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +0000482}
483
Niels Möller5fe95102019-03-04 16:49:25 +0100484int64_t ModuleRtpRtcpImpl::ExpectedRetransmissionTimeMs() const {
485 int64_t expected_retransmission_time_ms = rtt_ms();
486 if (expected_retransmission_time_ms > 0) {
487 return expected_retransmission_time_ms;
488 }
489 // No rtt available (|kRtpRtcpRttProcessTimeMs| not yet passed?), so try to
490 // poll avg_rtt_ms directly from rtcp receiver.
491 if (rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), nullptr,
492 &expected_retransmission_time_ms, nullptr,
493 nullptr) == 0) {
494 return expected_retransmission_time_ms;
495 }
496 return kDefaultExpectedRetransmissionTimeMs;
497}
498
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000499// Force a send of an RTCP packet.
500// Normal SR and RR are triggered via the process function.
Erik Språng242e22b2015-05-11 10:17:43 +0200501int32_t ModuleRtpRtcpImpl::SendRTCP(RTCPPacketType packet_type) {
502 return rtcp_sender_.SendRTCP(GetFeedbackState(), packet_type);
503}
504
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000505int32_t ModuleRtpRtcpImpl::SetRTCPApplicationSpecificData(
506 const uint8_t sub_type,
507 const uint32_t name,
508 const uint8_t* data,
509 const uint16_t length) {
Yves Gerey665174f2018-06-19 15:03:05 +0200510 return rtcp_sender_.SetApplicationSpecificData(sub_type, name, data, length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000511}
512
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000513void ModuleRtpRtcpImpl::SetRtcpXrRrtrStatus(bool enable) {
Danil Chapovalovc1e55c72016-03-09 15:14:35 +0100514 rtcp_receiver_.SetRtcpXrRrtrStatus(enable);
515 rtcp_sender_.SendRtcpXrReceiverReferenceTime(enable);
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000516}
517
asapersson@webrtc.org8d02f5d2013-11-21 08:57:04 +0000518bool ModuleRtpRtcpImpl::RtcpXrRrtrStatus() const {
519 return rtcp_sender_.RtcpXrReceiverReferenceTime();
520}
521
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000522// TODO(asapersson): Replace this method with the one below.
Yves Gerey665174f2018-06-19 15:03:05 +0200523int32_t ModuleRtpRtcpImpl::DataCountersRTP(size_t* bytes_sent,
524 uint32_t* packets_sent) const {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000525 StreamDataCounters rtp_stats;
526 StreamDataCounters rtx_stats;
nisse14adba72017-03-20 03:52:39 -0700527 rtp_sender_->GetDataCounters(&rtp_stats, &rtx_stats);
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000528
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000529 if (bytes_sent) {
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200530 // TODO(http://crbug.com/webrtc/10525): Bytes sent should only include
531 // payload bytes, not header and padding bytes.
asapersson@webrtc.orgcfd82df2015-01-22 09:39:59 +0000532 *bytes_sent = rtp_stats.transmitted.payload_bytes +
533 rtp_stats.transmitted.padding_bytes +
534 rtp_stats.transmitted.header_bytes +
535 rtx_stats.transmitted.payload_bytes +
536 rtx_stats.transmitted.padding_bytes +
537 rtx_stats.transmitted.header_bytes;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000538 }
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000539 if (packets_sent) {
Yves Gerey665174f2018-06-19 15:03:05 +0200540 *packets_sent =
541 rtp_stats.transmitted.packets + rtx_stats.transmitted.packets;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000542 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000543 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000544}
545
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000546void ModuleRtpRtcpImpl::GetSendStreamDataCounters(
547 StreamDataCounters* rtp_counters,
548 StreamDataCounters* rtx_counters) const {
nisse14adba72017-03-20 03:52:39 -0700549 rtp_sender_->GetDataCounters(rtp_counters, rtx_counters);
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000550}
551
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000552// Received RTCP report.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000553int32_t ModuleRtpRtcpImpl::RemoteRTCPStat(
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000554 std::vector<RTCPReportBlock>* receive_blocks) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000555 return rtcp_receiver_.StatisticsReceived(receive_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000556}
557
Henrik Boström6e436d12019-05-27 12:19:33 +0200558std::vector<ReportBlockData> ModuleRtpRtcpImpl::GetLatestReportBlockData()
559 const {
560 return rtcp_receiver_.GetLatestReportBlockData();
561}
562
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000563// (REMB) Receiver Estimated Max Bitrate.
Danil Chapovalov1de4b622017-12-13 13:35:10 +0100564void ModuleRtpRtcpImpl::SetRemb(int64_t bitrate_bps,
565 std::vector<uint32_t> ssrcs) {
566 rtcp_sender_.SetRemb(bitrate_bps, std::move(ssrcs));
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000567}
568
Danil Chapovalov51e21aa2017-10-10 17:46:26 +0200569void ModuleRtpRtcpImpl::UnsetRemb() {
Danil Chapovalovf74d6412017-10-18 13:32:57 +0200570 rtcp_sender_.UnsetRemb();
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000571}
572
Johannes Kron9190b822018-10-29 11:22:05 +0100573void ModuleRtpRtcpImpl::SetExtmapAllowMixed(bool extmap_allow_mixed) {
574 rtp_sender_->SetExtmapAllowMixed(extmap_allow_mixed);
575}
576
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000577int32_t ModuleRtpRtcpImpl::RegisterSendRtpHeaderExtension(
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000578 const RTPExtensionType type,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000579 const uint8_t id) {
nisse14adba72017-03-20 03:52:39 -0700580 return rtp_sender_->RegisterRtpHeaderExtension(type, id);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000581}
582
Danil Chapovalov585d1aa2018-09-14 18:29:32 +0200583bool ModuleRtpRtcpImpl::RegisterRtpHeaderExtension(const std::string& uri,
584 int id) {
585 return rtp_sender_->RegisterRtpHeaderExtension(uri, id);
586}
587
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000588int32_t ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension(
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000589 const RTPExtensionType type) {
nisse14adba72017-03-20 03:52:39 -0700590 return rtp_sender_->DeregisterRtpHeaderExtension(type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000591}
592
stefan53b6cc32017-02-03 08:13:57 -0800593bool ModuleRtpRtcpImpl::HasBweExtensions() const {
nisse14adba72017-03-20 03:52:39 -0700594 return rtp_sender_->IsRtpHeaderExtensionRegistered(
stefan53b6cc32017-02-03 08:13:57 -0800595 kRtpExtensionTransportSequenceNumber) ||
nisse14adba72017-03-20 03:52:39 -0700596 rtp_sender_->IsRtpHeaderExtensionRegistered(
stefan53b6cc32017-02-03 08:13:57 -0800597 kRtpExtensionAbsoluteSendTime) ||
nisse14adba72017-03-20 03:52:39 -0700598 rtp_sender_->IsRtpHeaderExtensionRegistered(
stefan53b6cc32017-02-03 08:13:57 -0800599 kRtpExtensionTransmissionTimeOffset);
600}
601
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000602// (TMMBR) Temporary Max Media Bit Rate.
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000603bool ModuleRtpRtcpImpl::TMMBR() const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000604 return rtcp_sender_.TMMBR();
niklase@google.com470e71d2011-07-07 08:21:25 +0000605}
606
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000607void ModuleRtpRtcpImpl::SetTMMBRStatus(const bool enable) {
608 rtcp_sender_.SetTMMBRStatus(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000609}
610
danilchap853ecb22016-08-22 08:26:15 -0700611void ModuleRtpRtcpImpl::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) {
612 rtcp_sender_.SetTmmbn(std::move(bounding_set));
niklase@google.com470e71d2011-07-07 08:21:25 +0000613}
614
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000615// Send a Negative acknowledgment packet.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000616int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list,
617 const uint16_t size) {
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000618 uint16_t nack_length = size;
619 uint16_t start_id = 0;
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +0100620 int64_t now_ms = clock_->TimeInMilliseconds();
621 if (TimeToSendFullNackList(now_ms)) {
622 nack_last_time_sent_full_ms_ = now_ms;
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000623 } 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
philipel83f831a2016-03-12 03:30:23 -0800646 return rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, nack_length,
647 &nack_list[start_id]);
648}
649
650void 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.orgba8138b2014-12-08 13:29:02 +0000654}
655
656bool ModuleRtpRtcpImpl::TimeToSendFullNackList(int64_t now) const {
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000657 // Use RTT from RtcpRttStats class if provided.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000658 int64_t rtt = rtt_ms();
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000659 if (rtt == 0) {
660 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
661 }
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000662
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000663 const int64_t kStartUpRttMs = 100;
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000664 int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5.
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000665 if (rtt == 0) {
666 wait_time = kStartUpRttMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000667 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000668
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000669 // Send a full NACK list once within every |wait_time|.
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +0100670 return now - nack_last_time_sent_full_ms_ > wait_time;
niklase@google.com470e71d2011-07-07 08:21:25 +0000671}
672
asapersson@webrtc.org9ffd8fe2015-01-21 08:22:50 +0000673// Store the sent packets, needed to answer to Negative acknowledgment requests.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000674void ModuleRtpRtcpImpl::SetStorePacketsStatus(const bool enable,
675 const uint16_t number_to_store) {
nisse14adba72017-03-20 03:52:39 -0700676 rtp_sender_->SetStorePacketsStatus(enable, number_to_store);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000677}
niklase@google.com470e71d2011-07-07 08:21:25 +0000678
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000679bool ModuleRtpRtcpImpl::StorePackets() const {
nisse14adba72017-03-20 03:52:39 -0700680 return rtp_sender_->StorePackets();
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +0000681}
682
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000683void ModuleRtpRtcpImpl::RegisterRtcpStatisticsCallback(
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000684 RtcpStatisticsCallback* callback) {
685 rtcp_receiver_.RegisterRtcpStatisticsCallback(callback);
686}
687
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000688RtcpStatisticsCallback* ModuleRtpRtcpImpl::GetRtcpStatisticsCallback() {
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000689 return rtcp_receiver_.GetRtcpStatisticsCallback();
690}
691
Henrik Boström87e3f9d2019-05-27 10:44:24 +0200692void ModuleRtpRtcpImpl::SetReportBlockDataObserver(
693 ReportBlockDataObserver* observer) {
694 return rtcp_receiver_.SetReportBlockDataObserver(observer);
695}
696
sprang233bd872015-09-08 13:25:16 -0700697bool ModuleRtpRtcpImpl::SendFeedbackPacket(
698 const rtcp::TransportFeedback& packet) {
699 return rtcp_sender_.SendFeedbackPacket(packet);
700}
701
Elad Alon7d6a4c02019-02-25 13:00:51 +0100702int32_t ModuleRtpRtcpImpl::SendLossNotification(uint16_t last_decoded_seq_num,
703 uint16_t last_received_seq_num,
Elad Alone86af2c2019-06-03 14:37:50 +0200704 bool decodability_flag,
705 bool buffering_allowed) {
Elad Alon7d6a4c02019-02-25 13:00:51 +0100706 return rtcp_sender_.SendLossNotification(
707 GetFeedbackState(), last_decoded_seq_num, last_received_seq_num,
Elad Alone86af2c2019-06-03 14:37:50 +0200708 decodability_flag, buffering_allowed);
Elad Alon7d6a4c02019-02-25 13:00:51 +0100709}
710
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000711void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000712 // Inform about the incoming SSRC.
713 rtcp_sender_.SetRemoteSSRC(ssrc);
714 rtcp_receiver_.SetRemoteSSRC(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000715}
716
Niels Möller5fe95102019-03-04 16:49:25 +0100717// TODO(nisse): Delete video_rate amd fec_rate arguments.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000718void ModuleRtpRtcpImpl::BitrateSent(uint32_t* total_rate,
719 uint32_t* video_rate,
720 uint32_t* fec_rate,
721 uint32_t* nack_rate) const {
nisse14adba72017-03-20 03:52:39 -0700722 *total_rate = rtp_sender_->BitrateSent();
Niels Möller5fe95102019-03-04 16:49:25 +0100723 if (video_rate)
724 *video_rate = 0;
725 if (fec_rate)
726 *fec_rate = 0;
nisse14adba72017-03-20 03:52:39 -0700727 *nack_rate = rtp_sender_->NackOverheadRate();
niklase@google.com470e71d2011-07-07 08:21:25 +0000728}
729
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000730void ModuleRtpRtcpImpl::OnRequestSendReport() {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000731 SendRTCP(kRtcpSr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000732}
733
Danil Chapovalov2800d742016-08-26 18:48:46 +0200734void ModuleRtpRtcpImpl::OnReceivedNack(
735 const std::vector<uint16_t>& nack_sequence_numbers) {
nisse14adba72017-03-20 03:52:39 -0700736 if (!rtp_sender_)
737 return;
738
Yves Gerey665174f2018-06-19 15:03:05 +0200739 if (!rtp_sender_->StorePackets() || nack_sequence_numbers.size() == 0) {
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000740 return;
741 }
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000742 // Use RTT from RtcpRttStats class if provided.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000743 int64_t rtt = rtt_ms();
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000744 if (rtt == 0) {
745 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
746 }
nisse14adba72017-03-20 03:52:39 -0700747 rtp_sender_->OnReceivedNack(nack_sequence_numbers, rtt);
niklase@google.com470e71d2011-07-07 08:21:25 +0000748}
749
isheriff6b4b5f32016-06-08 00:24:21 -0700750void ModuleRtpRtcpImpl::OnReceivedRtcpReportBlocks(
751 const ReportBlockList& report_blocks) {
Niels Möller5fe95102019-03-04 16:49:25 +0100752 if (ack_observer_) {
Niels Möller59ab1cf2019-02-06 22:48:11 +0100753 uint32_t ssrc = SSRC();
754
755 for (const RTCPReportBlock& report_block : report_blocks) {
756 if (ssrc == report_block.source_ssrc) {
Niels Möller5fe95102019-03-04 16:49:25 +0100757 ack_observer_->OnReceivedAck(
758 report_block.extended_highest_sequence_number);
Niels Möller59ab1cf2019-02-06 22:48:11 +0100759 }
760 }
761 }
isheriff6b4b5f32016-06-08 00:24:21 -0700762}
763
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000764bool ModuleRtpRtcpImpl::LastReceivedNTP(
765 uint32_t* rtcp_arrival_time_secs, // When we got the last report.
766 uint32_t* rtcp_arrival_time_frac,
767 uint32_t* remote_sr) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000768 // Remote SR: NTP inside the last received (mid 16 bits from sec and frac).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000769 uint32_t ntp_secs = 0;
770 uint32_t ntp_frac = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000771
Yves Gerey665174f2018-06-19 15:03:05 +0200772 if (!rtcp_receiver_.NTP(&ntp_secs, &ntp_frac, rtcp_arrival_time_secs,
773 rtcp_arrival_time_frac, NULL)) {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000774 return false;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000775 }
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000776 *remote_sr =
777 ((ntp_secs & 0x0000ffff) << 16) + ((ntp_frac & 0xffff0000) >> 16);
778 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000779}
780
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000781// Called from RTCPsender.
danilchap2b616392016-08-18 06:17:42 -0700782std::vector<rtcp::TmmbItem> ModuleRtpRtcpImpl::BoundingSet(bool* tmmbr_owner) {
783 return rtcp_receiver_.BoundingSet(tmmbr_owner);
niklase@google.com470e71d2011-07-07 08:21:25 +0000784}
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000785
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000786void ModuleRtpRtcpImpl::SetRtcpReceiverSsrcs(uint32_t main_ssrc) {
787 std::set<uint32_t> ssrcs;
788 ssrcs.insert(main_ssrc);
nisse14adba72017-03-20 03:52:39 -0700789 if (RtxSendStatus() != kRtxOff)
790 ssrcs.insert(rtp_sender_->RtxSsrc());
Danil Chapovalovd264df52018-06-14 12:59:38 +0200791 absl::optional<uint32_t> flexfec_ssrc = FlexfecSsrc();
brandtr7c7796b2017-07-03 06:02:53 -0700792 if (flexfec_ssrc)
793 ssrcs.insert(*flexfec_ssrc);
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000794 rtcp_receiver_.SetSsrcs(main_ssrc, ssrcs);
795}
796
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000797void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) {
danilchap7c9426c2016-04-14 03:05:31 -0700798 rtc::CritScope cs(&critical_section_rtt_);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000799 rtt_ms_ = rtt_ms;
Erik Språng8b101922018-01-18 11:58:05 -0800800 if (rtp_sender_)
801 rtp_sender_->SetRtt(rtt_ms);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000802}
803
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000804int64_t ModuleRtpRtcpImpl::rtt_ms() const {
danilchap7c9426c2016-04-14 03:05:31 -0700805 rtc::CritScope cs(&critical_section_rtt_);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000806 return rtt_ms_;
807}
808
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000809void ModuleRtpRtcpImpl::RegisterSendChannelRtpStatisticsCallback(
810 StreamDataCountersCallback* callback) {
nisse14adba72017-03-20 03:52:39 -0700811 rtp_sender_->RegisterRtpStatisticsCallback(callback);
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000812}
813
814StreamDataCountersCallback*
Yves Gerey665174f2018-06-19 15:03:05 +0200815ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const {
nisse14adba72017-03-20 03:52:39 -0700816 return rtp_sender_->GetRtpStatisticsCallback();
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000817}
sprang5e38c962016-12-01 05:18:09 -0800818
819void ModuleRtpRtcpImpl::SetVideoBitrateAllocation(
Erik Språng566124a2018-04-23 12:32:22 +0200820 const VideoBitrateAllocation& bitrate) {
sprang5e38c962016-12-01 05:18:09 -0800821 rtcp_sender_.SetVideoBitrateAllocation(bitrate);
822}
Niels Möller5fe95102019-03-04 16:49:25 +0100823
824RTPSender* ModuleRtpRtcpImpl::RtpSender() {
825 return rtp_sender_.get();
826}
827
828const RTPSender* ModuleRtpRtcpImpl::RtpSender() const {
829 return rtp_sender_.get();
830}
831
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000832} // namespace webrtc