blob: 1fdb35650d9991ecfd21d477cc7b47d599ea89ff [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
sprang168794c2017-07-06 04:38:06 -070015#include <algorithm>
Yves Gerey988cc082018-10-23 12:03:01 +020016#include <cstdint>
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000017#include <set>
Peter Boström9c017252016-02-26 16:26:20 +010018#include <string>
Yves Gerey988cc082018-10-23 12:03:01 +020019#include <utility>
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000020
Niels Möller59ab1cf2019-02-06 22:48:11 +010021#include "absl/memory/memory.h"
Per Kjellandere11b7d22019-02-21 07:55:59 +010022#include "api/transport/field_trial_based_config.h"
Yves Gerey988cc082018-10-23 12:03:01 +020023#include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
24#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "rtc_base/checks.h"
26#include "rtc_base/logging.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000027
niklase@google.com470e71d2011-07-07 08:21:25 +000028#ifdef _WIN32
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +000029// Disable warning C4355: 'this' : used in base member initializer list.
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +000030#pragma warning(disable : 4355)
niklase@google.com470e71d2011-07-07 08:21:25 +000031#endif
32
33namespace webrtc {
sprang168794c2017-07-06 04:38:06 -070034namespace {
35const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5;
36const int64_t kRtpRtcpRttProcessTimeMs = 1000;
37const int64_t kRtpRtcpBitrateProcessTimeMs = 10;
spranga8ae6f22017-09-04 07:23:56 -070038const int64_t kDefaultExpectedRetransmissionTimeMs = 125;
sprang168794c2017-07-06 04:38:06 -070039} // namespace
niklase@google.com470e71d2011-07-07 08:21:25 +000040
danilchapd3f3c342017-07-25 04:20:12 -070041RtpRtcp::Configuration::Configuration() = default;
Erik Språng4580ca22019-07-04 10:38:43 +020042RtpRtcp::Configuration::Configuration(Configuration&& rhs) = default;
phoglund@webrtc.orga22a9bd2013-01-14 10:01:55 +000043
Danil Chapovalovc44f6cc2019-03-06 11:31:09 +010044std::unique_ptr<RtpRtcp> RtpRtcp::Create(const Configuration& configuration) {
45 RTC_DCHECK(configuration.clock);
46 return absl::make_unique<ModuleRtpRtcpImpl>(configuration);
47}
48
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000049RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) {
50 if (configuration.clock) {
51 return new ModuleRtpRtcpImpl(configuration);
henrike@webrtc.orgf5da4da2012-02-15 23:54:59 +000052 } else {
pbos@webrtc.org180e5162014-07-11 15:36:26 +000053 // No clock implementation provided, use default clock.
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000054 RtpRtcp::Configuration configuration_copy;
Yves Gerey665174f2018-06-19 15:03:05 +020055 memcpy(&configuration_copy, &configuration, sizeof(RtpRtcp::Configuration));
stefan@webrtc.org20ed36d2013-01-17 14:01:20 +000056 configuration_copy.clock = Clock::GetRealTimeClock();
pbos@webrtc.org180e5162014-07-11 15:36:26 +000057 return new ModuleRtpRtcpImpl(configuration_copy);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +000058 }
niklase@google.com470e71d2011-07-07 08:21:25 +000059}
60
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000061ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration)
Erik Språng6f420e42019-07-09 20:06:30 +020062 : rtcp_sender_(configuration),
Erik Språng741b96b2019-07-11 13:08:34 +020063 rtcp_receiver_(configuration, this),
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000064 clock_(configuration.clock),
sprang168794c2017-07-06 04:38:06 -070065 last_bitrate_process_time_(clock_->TimeInMilliseconds()),
66 last_rtt_process_time_(clock_->TimeInMilliseconds()),
67 next_process_time_(clock_->TimeInMilliseconds() +
68 kRtpRtcpMaxIdleTimeProcessMs),
asapersson35151f32016-05-02 23:44:01 -070069 packet_overhead_(28), // IPV4 UDP.
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +010070 nack_last_time_sent_full_ms_(0),
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +000071 nack_last_seq_number_sent_(0),
mflodman@webrtc.org7c894b72012-11-26 12:40:15 +000072 remote_bitrate_(configuration.remote_bitrate_estimator),
Niels Möller5fe95102019-03-04 16:49:25 +010073 ack_observer_(configuration.ack_observer),
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000074 rtt_stats_(configuration.rtt_stats),
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000075 rtt_ms_(0) {
nisse14adba72017-03-20 03:52:39 -070076 if (!configuration.receiver_only) {
Erik Språng4580ca22019-07-04 10:38:43 +020077 rtp_sender_.reset(new RTPSender(configuration));
nisse14adba72017-03-20 03:52:39 -070078 // Make sure rtcp sender use same timestamp offset as rtp sender.
79 rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset());
80 }
danilchap71fead22016-08-18 02:01:49 -070081
82 // Set default packet size limit.
nisse284542b2017-01-10 08:58:32 -080083 // TODO(nisse): Kind-of duplicates
84 // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize.
85 const size_t kTcpOverIpv4HeaderSize = 40;
86 SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize);
niklase@google.com470e71d2011-07-07 08:21:25 +000087}
88
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010089ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() = default;
90
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +000091// Returns the number of milliseconds until the module want a worker thread
92// to call Process.
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +000093int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() {
sprang168794c2017-07-06 04:38:06 -070094 return std::max<int64_t>(0,
95 next_process_time_ - clock_->TimeInMilliseconds());
niklase@google.com470e71d2011-07-07 08:21:25 +000096}
97
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +000098// Process any pending tasks such as timeouts (non time critical events).
pbosa26ac922016-02-25 04:50:01 -080099void ModuleRtpRtcpImpl::Process() {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000100 const int64_t now = clock_->TimeInMilliseconds();
sprang168794c2017-07-06 04:38:06 -0700101 next_process_time_ = now + kRtpRtcpMaxIdleTimeProcessMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
nisse14adba72017-03-20 03:52:39 -0700103 if (rtp_sender_) {
nisse14adba72017-03-20 03:52:39 -0700104 if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) {
105 rtp_sender_->ProcessBitrate();
106 last_bitrate_process_time_ = now;
sprang168794c2017-07-06 04:38:06 -0700107 next_process_time_ =
108 std::min(next_process_time_, now + kRtpRtcpBitrateProcessTimeMs);
109 }
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000110 }
sprang168794c2017-07-06 04:38:06 -0700111
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000112 bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs;
113 if (rtcp_sender_.Sending()) {
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200114 // Process RTT if we have received a report block and we haven't
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000115 // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds.
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200116 if (rtcp_receiver_.LastReceivedReportBlockMs() > last_rtt_process_time_ &&
117 process_rtt) {
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000118 std::vector<RTCPReportBlock> receive_blocks;
119 rtcp_receiver_.StatisticsReceived(&receive_blocks);
120 int64_t max_rtt = 0;
121 for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin();
122 it != receive_blocks.end(); ++it) {
123 int64_t rtt = 0;
srte3e69e5c2017-08-09 06:13:45 -0700124 rtcp_receiver_.RTT(it->sender_ssrc, &rtt, NULL, NULL, NULL);
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000125 max_rtt = (rtt > max_rtt) ? rtt : max_rtt;
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +0000126 }
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000127 // Report the rtt.
128 if (rtt_stats_ && max_rtt != 0)
129 rtt_stats_->OnRttUpdate(max_rtt);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000130 }
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000131
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000132 // Verify receiver reports are delivered and the reported sequence number
133 // is increasing.
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800134 if (rtcp_receiver_.RtcpRrTimeout()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100135 RTC_LOG_F(LS_WARNING) << "Timeout: No RTCP RR received.";
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800136 } else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100137 RTC_LOG_F(LS_WARNING) << "Timeout: No increase in RTCP RR extended "
138 "highest sequence number.";
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000139 }
140
141 if (remote_bitrate_ && rtcp_sender_.TMMBR()) {
142 unsigned int target_bitrate = 0;
143 std::vector<unsigned int> ssrcs;
144 if (remote_bitrate_->LatestEstimate(&ssrcs, &target_bitrate)) {
145 if (!ssrcs.empty()) {
146 target_bitrate = target_bitrate / ssrcs.size();
147 }
148 rtcp_sender_.SetTargetBitrate(target_bitrate);
149 }
150 }
151 } else {
152 // Report rtt from receiver.
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000153 if (process_rtt) {
Yves Gerey665174f2018-06-19 15:03:05 +0200154 int64_t rtt_ms;
155 if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) {
156 rtt_stats_->OnRttUpdate(rtt_ms);
157 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000158 }
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000159 }
160
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000161 // Get processed rtt.
162 if (process_rtt) {
163 last_rtt_process_time_ = now;
sprang168794c2017-07-06 04:38:06 -0700164 next_process_time_ = std::min(
165 next_process_time_, last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs);
sprange2d83d62016-02-19 09:03:26 -0800166 if (rtt_stats_) {
167 // Make sure we have a valid RTT before setting.
168 int64_t last_rtt = rtt_stats_->LastProcessedRtt();
169 if (last_rtt >= 0)
170 set_rtt_ms(last_rtt);
171 }
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000172 }
173
Danil Chapovalov70ffead2016-07-20 15:26:59 +0200174 if (rtcp_sender_.TimeToSendRTCPReport())
175 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000176
danilchap9bf610e2017-02-20 06:03:01 -0800177 if (TMMBR() && rtcp_receiver_.UpdateTmmbrTimers()) {
178 rtcp_receiver_.NotifyTmmbrUpdated();
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000179 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000180}
181
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000182void ModuleRtpRtcpImpl::SetRtxSendStatus(int mode) {
nisse14adba72017-03-20 03:52:39 -0700183 rtp_sender_->SetRtxStatus(mode);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000184}
185
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000186int ModuleRtpRtcpImpl::RtxSendStatus() const {
nisse14adba72017-03-20 03:52:39 -0700187 return rtp_sender_ ? rtp_sender_->RtxStatus() : kRtxOff;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000188}
189
190void ModuleRtpRtcpImpl::SetRtxSsrc(uint32_t ssrc) {
nisse14adba72017-03-20 03:52:39 -0700191 rtp_sender_->SetRtxSsrc(ssrc);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000192}
193
Shao Changbine62202f2015-04-21 20:24:50 +0800194void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type,
195 int associated_payload_type) {
nisse14adba72017-03-20 03:52:39 -0700196 rtp_sender_->SetRtxPayloadType(payload_type, associated_payload_type);
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000197}
198
Danil Chapovalovd264df52018-06-14 12:59:38 +0200199absl::optional<uint32_t> ModuleRtpRtcpImpl::FlexfecSsrc() const {
brandtr7c7796b2017-07-03 06:02:53 -0700200 if (rtp_sender_)
201 return rtp_sender_->FlexfecSsrc();
Danil Chapovalovd264df52018-06-14 12:59:38 +0200202 return absl::nullopt;
brandtr9dfff292016-11-14 05:14:50 -0800203}
204
nisse479d3d72017-09-13 07:53:37 -0700205void ModuleRtpRtcpImpl::IncomingRtcpPacket(const uint8_t* rtcp_packet,
206 const size_t length) {
207 rtcp_receiver_.IncomingPacket(rtcp_packet, length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000208}
209
Niels Möller5fe95102019-03-04 16:49:25 +0100210void ModuleRtpRtcpImpl::RegisterSendPayloadFrequency(int payload_type,
211 int payload_frequency) {
212 rtcp_sender_.SetRtpClockRate(payload_type, payload_frequency);
Peter Boström8b79b072016-02-26 16:31:37 +0100213}
214
asapersson@webrtc.org9ffd8fe2015-01-21 08:22:50 +0000215int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload(const int8_t payload_type) {
Niels Möller59ab1cf2019-02-06 22:48:11 +0100216 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000217}
218
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000219uint32_t ModuleRtpRtcpImpl::StartTimestamp() const {
nisse14adba72017-03-20 03:52:39 -0700220 return rtp_sender_->TimestampOffset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000221}
222
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000223// Configure start timestamp, default is a random number.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000224void ModuleRtpRtcpImpl::SetStartTimestamp(const uint32_t timestamp) {
danilchap71fead22016-08-18 02:01:49 -0700225 rtcp_sender_.SetTimestampOffset(timestamp);
nisse14adba72017-03-20 03:52:39 -0700226 rtp_sender_->SetTimestampOffset(timestamp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000227}
228
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000229uint16_t ModuleRtpRtcpImpl::SequenceNumber() const {
nisse14adba72017-03-20 03:52:39 -0700230 return rtp_sender_->SequenceNumber();
niklase@google.com470e71d2011-07-07 08:21:25 +0000231}
232
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000233// Set SequenceNumber, default is a random number.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000234void ModuleRtpRtcpImpl::SetSequenceNumber(const uint16_t seq_num) {
nisse14adba72017-03-20 03:52:39 -0700235 rtp_sender_->SetSequenceNumber(seq_num);
niklase@google.com470e71d2011-07-07 08:21:25 +0000236}
237
Per83d09102016-04-15 14:59:13 +0200238void ModuleRtpRtcpImpl::SetRtpState(const RtpState& rtp_state) {
nisse14adba72017-03-20 03:52:39 -0700239 rtp_sender_->SetRtpState(rtp_state);
danilchap71fead22016-08-18 02:01:49 -0700240 rtcp_sender_.SetTimestampOffset(rtp_state.start_timestamp);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000241}
242
Per83d09102016-04-15 14:59:13 +0200243void ModuleRtpRtcpImpl::SetRtxState(const RtpState& rtp_state) {
nisse14adba72017-03-20 03:52:39 -0700244 rtp_sender_->SetRtxRtpState(rtp_state);
Per83d09102016-04-15 14:59:13 +0200245}
246
247RtpState ModuleRtpRtcpImpl::GetRtpState() const {
nisse14adba72017-03-20 03:52:39 -0700248 return rtp_sender_->GetRtpState();
Per83d09102016-04-15 14:59:13 +0200249}
250
251RtpState ModuleRtpRtcpImpl::GetRtxState() const {
nisse14adba72017-03-20 03:52:39 -0700252 return rtp_sender_->GetRtxRtpState();
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000253}
254
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000255uint32_t ModuleRtpRtcpImpl::SSRC() const {
nisse14adba72017-03-20 03:52:39 -0700256 return rtcp_sender_.SSRC();
niklase@google.com470e71d2011-07-07 08:21:25 +0000257}
258
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000259void ModuleRtpRtcpImpl::SetSSRC(const uint32_t ssrc) {
nisse14adba72017-03-20 03:52:39 -0700260 if (rtp_sender_) {
261 rtp_sender_->SetSSRC(ssrc);
262 }
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000263 rtcp_sender_.SetSSRC(ssrc);
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000264 SetRtcpReceiverSsrcs(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000265}
266
Amit Hilbuch77938e62018-12-21 09:23:38 -0800267void ModuleRtpRtcpImpl::SetRid(const std::string& rid) {
268 if (rtp_sender_) {
269 rtp_sender_->SetRid(rid);
270 }
271}
272
Steve Anton296a0ce2018-03-22 15:17:27 -0700273void ModuleRtpRtcpImpl::SetMid(const std::string& mid) {
274 if (rtp_sender_) {
275 rtp_sender_->SetMid(mid);
276 }
277 // TODO(bugs.webrtc.org/4050): If we end up supporting the MID SDES item for
278 // RTCP, this will need to be passed down to the RTCPSender also.
279}
280
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000281void ModuleRtpRtcpImpl::SetCsrcs(const std::vector<uint32_t>& csrcs) {
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000282 rtcp_sender_.SetCsrcs(csrcs);
nisse14adba72017-03-20 03:52:39 -0700283 rtp_sender_->SetCsrcs(csrcs);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000284}
285
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000286// TODO(pbos): Handle media and RTX streams separately (separate RTCP
287// feedbacks).
288RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000289 RTCPSender::FeedbackState state;
nisse14adba72017-03-20 03:52:39 -0700290 // This is called also when receiver_only is true. Hence below
291 // checks that rtp_sender_ exists.
292 if (rtp_sender_) {
293 StreamDataCounters rtp_stats;
294 StreamDataCounters rtx_stats;
295 rtp_sender_->GetDataCounters(&rtp_stats, &rtx_stats);
Yves Gerey665174f2018-06-19 15:03:05 +0200296 state.packets_sent =
297 rtp_stats.transmitted.packets + rtx_stats.transmitted.packets;
nisse14adba72017-03-20 03:52:39 -0700298 state.media_bytes_sent = rtp_stats.transmitted.payload_bytes +
299 rtx_stats.transmitted.payload_bytes;
300 state.send_bitrate = rtp_sender_->BitrateSent();
301 }
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000302 state.module = this;
303
Yves Gerey665174f2018-06-19 15:03:05 +0200304 LastReceivedNTP(&state.last_rr_ntp_secs, &state.last_rr_ntp_frac,
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000305 &state.remote_sr);
306
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +0200307 state.last_xr_rtis = rtcp_receiver_.ConsumeReceivedXrReferenceTimeInfo();
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000308
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000309 return state;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000310}
311
nisse14adba72017-03-20 03:52:39 -0700312// TODO(nisse): This method shouldn't be called for a receive-only
313// stream. Delete rtp_sender_ check as soon as all applications are
314// updated.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000315int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000316 if (rtcp_sender_.Sending() != sending) {
317 // Sends RTCP BYE when going from true to false
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000318 if (rtcp_sender_.SetSendingStatus(GetFeedbackState(), sending) != 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100319 RTC_LOG(LS_WARNING) << "Failed to send RTCP BYE";
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000320 }
nisse14adba72017-03-20 03:52:39 -0700321 if (sending && rtp_sender_) {
nisse7d59f6b2017-02-21 03:40:24 -0800322 // Update Rtcp receiver config, to track Rtx config changes from
323 // the SetRtxStatus and SetRtxSsrc methods.
nisse14adba72017-03-20 03:52:39 -0700324 SetRtcpReceiverSsrcs(rtp_sender_->SSRC());
nisse7d59f6b2017-02-21 03:40:24 -0800325 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000326 }
327 return 0;
328}
329
330bool ModuleRtpRtcpImpl::Sending() const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000331 return rtcp_sender_.Sending();
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.orgd16e8392014-12-19 13:49:55 +0000337void ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) {
nisse14adba72017-03-20 03:52:39 -0700338 if (rtp_sender_) {
339 rtp_sender_->SetSendingMediaStatus(sending);
340 } else {
341 RTC_DCHECK(!sending);
342 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000343}
344
345bool ModuleRtpRtcpImpl::SendingMedia() const {
nisse14adba72017-03-20 03:52:39 -0700346 return rtp_sender_ ? rtp_sender_->SendingMedia() : false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000347}
348
Sebastian Jansson1bca65b2018-10-10 09:58:08 +0200349void ModuleRtpRtcpImpl::SetAsPartOfAllocation(bool part_of_allocation) {
350 RTC_CHECK(rtp_sender_);
351 rtp_sender_->SetAsPartOfAllocation(part_of_allocation);
352}
353
Niels Möller5fe95102019-03-04 16:49:25 +0100354bool ModuleRtpRtcpImpl::OnSendingRtpFrame(uint32_t timestamp,
355 int64_t capture_time_ms,
356 int payload_type,
357 bool force_sender_report) {
358 if (!Sending())
359 return false;
360
361 rtcp_sender_.SetLastRtpTime(timestamp, capture_time_ms, payload_type);
362 // Make sure an RTCP report isn't queued behind a key frame.
363 if (rtcp_sender_.TimeToSendRTCPReport(force_sender_report))
364 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
365
366 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000367}
368
Erik Språngd2879622019-05-10 08:29:01 -0700369RtpPacketSendResult ModuleRtpRtcpImpl::TimeToSendPacket(
370 uint32_t ssrc,
371 uint16_t sequence_number,
372 int64_t capture_time_ms,
373 bool retransmission,
374 const PacedPacketInfo& pacing_info) {
nisse14adba72017-03-20 03:52:39 -0700375 return rtp_sender_->TimeToSendPacket(ssrc, sequence_number, capture_time_ms,
Yves Gerey665174f2018-06-19 15:03:05 +0200376 retransmission, pacing_info);
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000377}
378
Erik Språng9c771c22019-06-17 16:31:53 +0200379bool ModuleRtpRtcpImpl::TrySendPacket(RtpPacketToSend* packet,
380 const PacedPacketInfo& pacing_info) {
381 return rtp_sender_->TrySendPacket(packet, pacing_info);
382}
383
Erik Språng6f129b32019-07-11 13:01:58 +0200384bool ModuleRtpRtcpImpl::SupportsPadding() const {
385 return rtp_sender_->SupportsPadding();
386}
387
388bool ModuleRtpRtcpImpl::SupportsRtxPayloadPadding() const {
389 return rtp_sender_->SupportsRtxPayloadPadding();
390}
391
philipelc7bf32a2017-02-17 03:59:43 -0800392size_t ModuleRtpRtcpImpl::TimeToSendPadding(
393 size_t bytes,
394 const PacedPacketInfo& pacing_info) {
nisse14adba72017-03-20 03:52:39 -0700395 return rtp_sender_->TimeToSendPadding(bytes, pacing_info);
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000396}
397
Erik Språngf6468d22019-07-05 16:53:43 +0200398std::vector<std::unique_ptr<RtpPacketToSend>>
399ModuleRtpRtcpImpl::GeneratePadding(size_t target_size_bytes) {
400 return rtp_sender_->GeneratePadding(target_size_bytes);
Erik Språng478cb462019-06-26 15:49:27 +0200401}
402
nisse284542b2017-01-10 08:58:32 -0800403size_t ModuleRtpRtcpImpl::MaxRtpPacketSize() const {
nisse14adba72017-03-20 03:52:39 -0700404 return rtp_sender_->MaxRtpPacketSize();
niklase@google.com470e71d2011-07-07 08:21:25 +0000405}
406
nisse284542b2017-01-10 08:58:32 -0800407void ModuleRtpRtcpImpl::SetMaxRtpPacketSize(size_t rtp_packet_size) {
408 RTC_DCHECK_LE(rtp_packet_size, IP_PACKET_SIZE)
409 << "rtp packet size too large: " << rtp_packet_size;
410 RTC_DCHECK_GT(rtp_packet_size, packet_overhead_)
411 << "rtp packet size too small: " << rtp_packet_size;
niklase@google.com470e71d2011-07-07 08:21:25 +0000412
nisse284542b2017-01-10 08:58:32 -0800413 rtcp_sender_.SetMaxRtpPacketSize(rtp_packet_size);
nisse14adba72017-03-20 03:52:39 -0700414 if (rtp_sender_)
415 rtp_sender_->SetMaxRtpPacketSize(rtp_packet_size);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000416}
417
pbosda903ea2015-10-02 02:36:56 -0700418RtcpMode ModuleRtpRtcpImpl::RTCP() const {
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700419 return rtcp_sender_.Status();
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000420}
421
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000422// Configure RTCP status i.e on/off.
pbosda903ea2015-10-02 02:36:56 -0700423void ModuleRtpRtcpImpl::SetRTCPStatus(const RtcpMode method) {
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000424 rtcp_sender_.SetRTCPStatus(method);
niklase@google.com470e71d2011-07-07 08:21:25 +0000425}
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000426
Peter Boström9ba52f82015-06-01 14:12:28 +0200427int32_t ModuleRtpRtcpImpl::SetCNAME(const char* c_name) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000428 return rtcp_sender_.SetCNAME(c_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000429}
430
Erik Språng0ea42d32015-06-25 14:46:16 +0200431int32_t ModuleRtpRtcpImpl::AddMixedCNAME(uint32_t ssrc, const char* c_name) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000432 return rtcp_sender_.AddMixedCNAME(ssrc, c_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000433}
434
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000435int32_t ModuleRtpRtcpImpl::RemoveMixedCNAME(const uint32_t ssrc) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000436 return rtcp_sender_.RemoveMixedCNAME(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000437}
438
Yves Gerey665174f2018-06-19 15:03:05 +0200439int32_t ModuleRtpRtcpImpl::RemoteCNAME(const uint32_t remote_ssrc,
440 char c_name[RTCP_CNAME_SIZE]) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000441 return rtcp_receiver_.CNAME(remote_ssrc, c_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000442}
443
Yves Gerey665174f2018-06-19 15:03:05 +0200444int32_t ModuleRtpRtcpImpl::RemoteNTP(uint32_t* received_ntpsecs,
445 uint32_t* received_ntpfrac,
446 uint32_t* rtcp_arrival_time_secs,
447 uint32_t* rtcp_arrival_time_frac,
448 uint32_t* rtcp_timestamp) const {
449 return rtcp_receiver_.NTP(received_ntpsecs, received_ntpfrac,
450 rtcp_arrival_time_secs, rtcp_arrival_time_frac,
pbos@webrtc.org376b4ea2014-07-15 15:51:33 +0000451 rtcp_timestamp)
452 ? 0
453 : -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000454}
455
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000456// Get RoundTripTime.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000457int32_t ModuleRtpRtcpImpl::RTT(const uint32_t remote_ssrc,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000458 int64_t* rtt,
459 int64_t* avg_rtt,
460 int64_t* min_rtt,
461 int64_t* max_rtt) const {
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000462 int32_t ret = rtcp_receiver_.RTT(remote_ssrc, rtt, avg_rtt, min_rtt, max_rtt);
463 if (rtt && *rtt == 0) {
464 // Try to get RTT from RtcpRttStats class.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000465 *rtt = rtt_ms();
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000466 }
467 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +0000468}
469
Niels Möller5fe95102019-03-04 16:49:25 +0100470int64_t ModuleRtpRtcpImpl::ExpectedRetransmissionTimeMs() const {
471 int64_t expected_retransmission_time_ms = rtt_ms();
472 if (expected_retransmission_time_ms > 0) {
473 return expected_retransmission_time_ms;
474 }
475 // No rtt available (|kRtpRtcpRttProcessTimeMs| not yet passed?), so try to
476 // poll avg_rtt_ms directly from rtcp receiver.
477 if (rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), nullptr,
478 &expected_retransmission_time_ms, nullptr,
479 nullptr) == 0) {
480 return expected_retransmission_time_ms;
481 }
482 return kDefaultExpectedRetransmissionTimeMs;
483}
484
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000485// Force a send of an RTCP packet.
486// Normal SR and RR are triggered via the process function.
Erik Språng242e22b2015-05-11 10:17:43 +0200487int32_t ModuleRtpRtcpImpl::SendRTCP(RTCPPacketType packet_type) {
488 return rtcp_sender_.SendRTCP(GetFeedbackState(), packet_type);
489}
490
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000491int32_t ModuleRtpRtcpImpl::SetRTCPApplicationSpecificData(
492 const uint8_t sub_type,
493 const uint32_t name,
494 const uint8_t* data,
495 const uint16_t length) {
Yves Gerey665174f2018-06-19 15:03:05 +0200496 return rtcp_sender_.SetApplicationSpecificData(sub_type, name, data, length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000497}
498
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000499void ModuleRtpRtcpImpl::SetRtcpXrRrtrStatus(bool enable) {
Danil Chapovalovc1e55c72016-03-09 15:14:35 +0100500 rtcp_receiver_.SetRtcpXrRrtrStatus(enable);
501 rtcp_sender_.SendRtcpXrReceiverReferenceTime(enable);
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000502}
503
asapersson@webrtc.org8d02f5d2013-11-21 08:57:04 +0000504bool ModuleRtpRtcpImpl::RtcpXrRrtrStatus() const {
505 return rtcp_sender_.RtcpXrReceiverReferenceTime();
506}
507
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000508// TODO(asapersson): Replace this method with the one below.
Yves Gerey665174f2018-06-19 15:03:05 +0200509int32_t ModuleRtpRtcpImpl::DataCountersRTP(size_t* bytes_sent,
510 uint32_t* packets_sent) const {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000511 StreamDataCounters rtp_stats;
512 StreamDataCounters rtx_stats;
nisse14adba72017-03-20 03:52:39 -0700513 rtp_sender_->GetDataCounters(&rtp_stats, &rtx_stats);
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000514
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000515 if (bytes_sent) {
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200516 // TODO(http://crbug.com/webrtc/10525): Bytes sent should only include
517 // payload bytes, not header and padding bytes.
asapersson@webrtc.orgcfd82df2015-01-22 09:39:59 +0000518 *bytes_sent = rtp_stats.transmitted.payload_bytes +
519 rtp_stats.transmitted.padding_bytes +
520 rtp_stats.transmitted.header_bytes +
521 rtx_stats.transmitted.payload_bytes +
522 rtx_stats.transmitted.padding_bytes +
523 rtx_stats.transmitted.header_bytes;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000524 }
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000525 if (packets_sent) {
Yves Gerey665174f2018-06-19 15:03:05 +0200526 *packets_sent =
527 rtp_stats.transmitted.packets + rtx_stats.transmitted.packets;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000528 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000529 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000530}
531
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000532void ModuleRtpRtcpImpl::GetSendStreamDataCounters(
533 StreamDataCounters* rtp_counters,
534 StreamDataCounters* rtx_counters) const {
nisse14adba72017-03-20 03:52:39 -0700535 rtp_sender_->GetDataCounters(rtp_counters, rtx_counters);
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000536}
537
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000538// Received RTCP report.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000539int32_t ModuleRtpRtcpImpl::RemoteRTCPStat(
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000540 std::vector<RTCPReportBlock>* receive_blocks) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000541 return rtcp_receiver_.StatisticsReceived(receive_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000542}
543
Henrik Boström6e436d12019-05-27 12:19:33 +0200544std::vector<ReportBlockData> ModuleRtpRtcpImpl::GetLatestReportBlockData()
545 const {
546 return rtcp_receiver_.GetLatestReportBlockData();
547}
548
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000549// (REMB) Receiver Estimated Max Bitrate.
Danil Chapovalov1de4b622017-12-13 13:35:10 +0100550void ModuleRtpRtcpImpl::SetRemb(int64_t bitrate_bps,
551 std::vector<uint32_t> ssrcs) {
552 rtcp_sender_.SetRemb(bitrate_bps, std::move(ssrcs));
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000553}
554
Danil Chapovalov51e21aa2017-10-10 17:46:26 +0200555void ModuleRtpRtcpImpl::UnsetRemb() {
Danil Chapovalovf74d6412017-10-18 13:32:57 +0200556 rtcp_sender_.UnsetRemb();
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000557}
558
Johannes Kron9190b822018-10-29 11:22:05 +0100559void ModuleRtpRtcpImpl::SetExtmapAllowMixed(bool extmap_allow_mixed) {
560 rtp_sender_->SetExtmapAllowMixed(extmap_allow_mixed);
561}
562
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000563int32_t ModuleRtpRtcpImpl::RegisterSendRtpHeaderExtension(
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000564 const RTPExtensionType type,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000565 const uint8_t id) {
nisse14adba72017-03-20 03:52:39 -0700566 return rtp_sender_->RegisterRtpHeaderExtension(type, id);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000567}
568
Danil Chapovalov585d1aa2018-09-14 18:29:32 +0200569bool ModuleRtpRtcpImpl::RegisterRtpHeaderExtension(const std::string& uri,
570 int id) {
571 return rtp_sender_->RegisterRtpHeaderExtension(uri, id);
572}
573
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000574int32_t ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension(
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000575 const RTPExtensionType type) {
nisse14adba72017-03-20 03:52:39 -0700576 return rtp_sender_->DeregisterRtpHeaderExtension(type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000577}
578
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000579// (TMMBR) Temporary Max Media Bit Rate.
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000580bool ModuleRtpRtcpImpl::TMMBR() const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000581 return rtcp_sender_.TMMBR();
niklase@google.com470e71d2011-07-07 08:21:25 +0000582}
583
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000584void ModuleRtpRtcpImpl::SetTMMBRStatus(const bool enable) {
585 rtcp_sender_.SetTMMBRStatus(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000586}
587
danilchap853ecb22016-08-22 08:26:15 -0700588void ModuleRtpRtcpImpl::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) {
589 rtcp_sender_.SetTmmbn(std::move(bounding_set));
niklase@google.com470e71d2011-07-07 08:21:25 +0000590}
591
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000592// Send a Negative acknowledgment packet.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000593int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list,
594 const uint16_t size) {
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000595 uint16_t nack_length = size;
596 uint16_t start_id = 0;
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +0100597 int64_t now_ms = clock_->TimeInMilliseconds();
598 if (TimeToSendFullNackList(now_ms)) {
599 nack_last_time_sent_full_ms_ = now_ms;
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000600 } else {
601 // Only send extended list.
602 if (nack_last_seq_number_sent_ == nack_list[size - 1]) {
603 // Last sequence number is the same, do not send list.
604 return 0;
605 }
606 // Send new sequence numbers.
607 for (int i = 0; i < size; ++i) {
608 if (nack_last_seq_number_sent_ == nack_list[i]) {
609 start_id = i + 1;
610 break;
611 }
612 }
613 nack_length = size - start_id;
614 }
615
616 // Our RTCP NACK implementation is limited to kRtcpMaxNackFields sequence
617 // numbers per RTCP packet.
618 if (nack_length > kRtcpMaxNackFields) {
619 nack_length = kRtcpMaxNackFields;
620 }
621 nack_last_seq_number_sent_ = nack_list[start_id + nack_length - 1];
622
philipel83f831a2016-03-12 03:30:23 -0800623 return rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, nack_length,
624 &nack_list[start_id]);
625}
626
627void ModuleRtpRtcpImpl::SendNack(
628 const std::vector<uint16_t>& sequence_numbers) {
629 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, sequence_numbers.size(),
630 sequence_numbers.data());
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000631}
632
633bool ModuleRtpRtcpImpl::TimeToSendFullNackList(int64_t now) const {
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000634 // Use RTT from RtcpRttStats class if provided.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000635 int64_t rtt = rtt_ms();
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000636 if (rtt == 0) {
637 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
638 }
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000639
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000640 const int64_t kStartUpRttMs = 100;
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000641 int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5.
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000642 if (rtt == 0) {
643 wait_time = kStartUpRttMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000644 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000645
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000646 // Send a full NACK list once within every |wait_time|.
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +0100647 return now - nack_last_time_sent_full_ms_ > wait_time;
niklase@google.com470e71d2011-07-07 08:21:25 +0000648}
649
asapersson@webrtc.org9ffd8fe2015-01-21 08:22:50 +0000650// Store the sent packets, needed to answer to Negative acknowledgment requests.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000651void ModuleRtpRtcpImpl::SetStorePacketsStatus(const bool enable,
652 const uint16_t number_to_store) {
nisse14adba72017-03-20 03:52:39 -0700653 rtp_sender_->SetStorePacketsStatus(enable, number_to_store);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000654}
niklase@google.com470e71d2011-07-07 08:21:25 +0000655
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000656bool ModuleRtpRtcpImpl::StorePackets() const {
nisse14adba72017-03-20 03:52:39 -0700657 return rtp_sender_->StorePackets();
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +0000658}
659
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000660void ModuleRtpRtcpImpl::RegisterRtcpStatisticsCallback(
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000661 RtcpStatisticsCallback* callback) {
662 rtcp_receiver_.RegisterRtcpStatisticsCallback(callback);
663}
664
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000665RtcpStatisticsCallback* ModuleRtpRtcpImpl::GetRtcpStatisticsCallback() {
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000666 return rtcp_receiver_.GetRtcpStatisticsCallback();
667}
668
Henrik Boström87e3f9d2019-05-27 10:44:24 +0200669void ModuleRtpRtcpImpl::SetReportBlockDataObserver(
670 ReportBlockDataObserver* observer) {
671 return rtcp_receiver_.SetReportBlockDataObserver(observer);
672}
673
sprang233bd872015-09-08 13:25:16 -0700674bool ModuleRtpRtcpImpl::SendFeedbackPacket(
675 const rtcp::TransportFeedback& packet) {
676 return rtcp_sender_.SendFeedbackPacket(packet);
677}
678
Elad Alon7d6a4c02019-02-25 13:00:51 +0100679int32_t ModuleRtpRtcpImpl::SendLossNotification(uint16_t last_decoded_seq_num,
680 uint16_t last_received_seq_num,
Elad Alone86af2c2019-06-03 14:37:50 +0200681 bool decodability_flag,
682 bool buffering_allowed) {
Elad Alon7d6a4c02019-02-25 13:00:51 +0100683 return rtcp_sender_.SendLossNotification(
684 GetFeedbackState(), last_decoded_seq_num, last_received_seq_num,
Elad Alone86af2c2019-06-03 14:37:50 +0200685 decodability_flag, buffering_allowed);
Elad Alon7d6a4c02019-02-25 13:00:51 +0100686}
687
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000688void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000689 // Inform about the incoming SSRC.
690 rtcp_sender_.SetRemoteSSRC(ssrc);
691 rtcp_receiver_.SetRemoteSSRC(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000692}
693
Niels Möller5fe95102019-03-04 16:49:25 +0100694// TODO(nisse): Delete video_rate amd fec_rate arguments.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000695void ModuleRtpRtcpImpl::BitrateSent(uint32_t* total_rate,
696 uint32_t* video_rate,
697 uint32_t* fec_rate,
698 uint32_t* nack_rate) const {
nisse14adba72017-03-20 03:52:39 -0700699 *total_rate = rtp_sender_->BitrateSent();
Niels Möller5fe95102019-03-04 16:49:25 +0100700 if (video_rate)
701 *video_rate = 0;
702 if (fec_rate)
703 *fec_rate = 0;
nisse14adba72017-03-20 03:52:39 -0700704 *nack_rate = rtp_sender_->NackOverheadRate();
niklase@google.com470e71d2011-07-07 08:21:25 +0000705}
706
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000707void ModuleRtpRtcpImpl::OnRequestSendReport() {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000708 SendRTCP(kRtcpSr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000709}
710
Danil Chapovalov2800d742016-08-26 18:48:46 +0200711void ModuleRtpRtcpImpl::OnReceivedNack(
712 const std::vector<uint16_t>& nack_sequence_numbers) {
nisse14adba72017-03-20 03:52:39 -0700713 if (!rtp_sender_)
714 return;
715
Yves Gerey665174f2018-06-19 15:03:05 +0200716 if (!rtp_sender_->StorePackets() || nack_sequence_numbers.size() == 0) {
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000717 return;
718 }
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000719 // Use RTT from RtcpRttStats class if provided.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000720 int64_t rtt = rtt_ms();
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000721 if (rtt == 0) {
722 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
723 }
nisse14adba72017-03-20 03:52:39 -0700724 rtp_sender_->OnReceivedNack(nack_sequence_numbers, rtt);
niklase@google.com470e71d2011-07-07 08:21:25 +0000725}
726
isheriff6b4b5f32016-06-08 00:24:21 -0700727void ModuleRtpRtcpImpl::OnReceivedRtcpReportBlocks(
728 const ReportBlockList& report_blocks) {
Niels Möller5fe95102019-03-04 16:49:25 +0100729 if (ack_observer_) {
Niels Möller59ab1cf2019-02-06 22:48:11 +0100730 uint32_t ssrc = SSRC();
731
732 for (const RTCPReportBlock& report_block : report_blocks) {
733 if (ssrc == report_block.source_ssrc) {
Niels Möller5fe95102019-03-04 16:49:25 +0100734 ack_observer_->OnReceivedAck(
735 report_block.extended_highest_sequence_number);
Niels Möller59ab1cf2019-02-06 22:48:11 +0100736 }
737 }
738 }
isheriff6b4b5f32016-06-08 00:24:21 -0700739}
740
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000741bool ModuleRtpRtcpImpl::LastReceivedNTP(
742 uint32_t* rtcp_arrival_time_secs, // When we got the last report.
743 uint32_t* rtcp_arrival_time_frac,
744 uint32_t* remote_sr) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000745 // Remote SR: NTP inside the last received (mid 16 bits from sec and frac).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000746 uint32_t ntp_secs = 0;
747 uint32_t ntp_frac = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000748
Yves Gerey665174f2018-06-19 15:03:05 +0200749 if (!rtcp_receiver_.NTP(&ntp_secs, &ntp_frac, rtcp_arrival_time_secs,
750 rtcp_arrival_time_frac, NULL)) {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000751 return false;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000752 }
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000753 *remote_sr =
754 ((ntp_secs & 0x0000ffff) << 16) + ((ntp_frac & 0xffff0000) >> 16);
755 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000756}
757
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000758// Called from RTCPsender.
danilchap2b616392016-08-18 06:17:42 -0700759std::vector<rtcp::TmmbItem> ModuleRtpRtcpImpl::BoundingSet(bool* tmmbr_owner) {
760 return rtcp_receiver_.BoundingSet(tmmbr_owner);
niklase@google.com470e71d2011-07-07 08:21:25 +0000761}
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000762
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000763void ModuleRtpRtcpImpl::SetRtcpReceiverSsrcs(uint32_t main_ssrc) {
764 std::set<uint32_t> ssrcs;
765 ssrcs.insert(main_ssrc);
nisse14adba72017-03-20 03:52:39 -0700766 if (RtxSendStatus() != kRtxOff)
767 ssrcs.insert(rtp_sender_->RtxSsrc());
Danil Chapovalovd264df52018-06-14 12:59:38 +0200768 absl::optional<uint32_t> flexfec_ssrc = FlexfecSsrc();
brandtr7c7796b2017-07-03 06:02:53 -0700769 if (flexfec_ssrc)
770 ssrcs.insert(*flexfec_ssrc);
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000771 rtcp_receiver_.SetSsrcs(main_ssrc, ssrcs);
772}
773
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000774void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) {
danilchap7c9426c2016-04-14 03:05:31 -0700775 rtc::CritScope cs(&critical_section_rtt_);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000776 rtt_ms_ = rtt_ms;
Erik Språng8b101922018-01-18 11:58:05 -0800777 if (rtp_sender_)
778 rtp_sender_->SetRtt(rtt_ms);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000779}
780
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000781int64_t ModuleRtpRtcpImpl::rtt_ms() const {
danilchap7c9426c2016-04-14 03:05:31 -0700782 rtc::CritScope cs(&critical_section_rtt_);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000783 return rtt_ms_;
784}
785
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000786void ModuleRtpRtcpImpl::RegisterSendChannelRtpStatisticsCallback(
787 StreamDataCountersCallback* callback) {
nisse14adba72017-03-20 03:52:39 -0700788 rtp_sender_->RegisterRtpStatisticsCallback(callback);
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000789}
790
791StreamDataCountersCallback*
Yves Gerey665174f2018-06-19 15:03:05 +0200792ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const {
nisse14adba72017-03-20 03:52:39 -0700793 return rtp_sender_->GetRtpStatisticsCallback();
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000794}
sprang5e38c962016-12-01 05:18:09 -0800795
796void ModuleRtpRtcpImpl::SetVideoBitrateAllocation(
Erik Språng566124a2018-04-23 12:32:22 +0200797 const VideoBitrateAllocation& bitrate) {
sprang5e38c962016-12-01 05:18:09 -0800798 rtcp_sender_.SetVideoBitrateAllocation(bitrate);
799}
Niels Möller5fe95102019-03-04 16:49:25 +0100800
801RTPSender* ModuleRtpRtcpImpl::RtpSender() {
802 return rtp_sender_.get();
803}
804
805const RTPSender* ModuleRtpRtcpImpl::RtpSender() const {
806 return rtp_sender_.get();
807}
808
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000809} // namespace webrtc