blob: 13f1b354e1986f82e6f051dab03b43ea7df7b95c [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;
Mirko Bonadei4d683142019-07-12 08:36:29 +000039constexpr int32_t kDefaultVideoReportInterval = 1000;
40constexpr int32_t kDefaultAudioReportInterval = 5000;
sprang168794c2017-07-06 04:38:06 -070041} // namespace
niklase@google.com470e71d2011-07-07 08:21:25 +000042
danilchapd3f3c342017-07-25 04:20:12 -070043RtpRtcp::Configuration::Configuration() = default;
Erik Språng4580ca22019-07-04 10:38:43 +020044RtpRtcp::Configuration::Configuration(Configuration&& rhs) = default;
phoglund@webrtc.orga22a9bd2013-01-14 10:01:55 +000045
Danil Chapovalovc44f6cc2019-03-06 11:31:09 +010046std::unique_ptr<RtpRtcp> RtpRtcp::Create(const Configuration& configuration) {
47 RTC_DCHECK(configuration.clock);
48 return absl::make_unique<ModuleRtpRtcpImpl>(configuration);
49}
50
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000051RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) {
52 if (configuration.clock) {
53 return new ModuleRtpRtcpImpl(configuration);
henrike@webrtc.orgf5da4da2012-02-15 23:54:59 +000054 } else {
pbos@webrtc.org180e5162014-07-11 15:36:26 +000055 // No clock implementation provided, use default clock.
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000056 RtpRtcp::Configuration configuration_copy;
Yves Gerey665174f2018-06-19 15:03:05 +020057 memcpy(&configuration_copy, &configuration, sizeof(RtpRtcp::Configuration));
stefan@webrtc.org20ed36d2013-01-17 14:01:20 +000058 configuration_copy.clock = Clock::GetRealTimeClock();
pbos@webrtc.org180e5162014-07-11 15:36:26 +000059 return new ModuleRtpRtcpImpl(configuration_copy);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +000060 }
niklase@google.com470e71d2011-07-07 08:21:25 +000061}
62
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000063ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration)
Erik Språng6f420e42019-07-09 20:06:30 +020064 : rtcp_sender_(configuration),
Mirko Bonadei4d683142019-07-12 08:36:29 +000065 rtcp_receiver_(configuration.clock,
66 configuration.receiver_only,
67 configuration.rtcp_packet_type_counter_observer,
68 configuration.bandwidth_callback,
69 configuration.intra_frame_callback,
70 configuration.rtcp_loss_notification_observer,
71 configuration.transport_feedback_callback,
72 configuration.bitrate_allocation_observer,
73 configuration.rtcp_report_interval_ms > 0
74 ? configuration.rtcp_report_interval_ms
75 : (configuration.audio ? kDefaultAudioReportInterval
76 : kDefaultVideoReportInterval),
77 this),
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000078 clock_(configuration.clock),
sprang168794c2017-07-06 04:38:06 -070079 last_bitrate_process_time_(clock_->TimeInMilliseconds()),
80 last_rtt_process_time_(clock_->TimeInMilliseconds()),
81 next_process_time_(clock_->TimeInMilliseconds() +
82 kRtpRtcpMaxIdleTimeProcessMs),
asapersson35151f32016-05-02 23:44:01 -070083 packet_overhead_(28), // IPV4 UDP.
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +010084 nack_last_time_sent_full_ms_(0),
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +000085 nack_last_seq_number_sent_(0),
mflodman@webrtc.org7c894b72012-11-26 12:40:15 +000086 remote_bitrate_(configuration.remote_bitrate_estimator),
Niels Möller5fe95102019-03-04 16:49:25 +010087 ack_observer_(configuration.ack_observer),
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000088 rtt_stats_(configuration.rtt_stats),
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000089 rtt_ms_(0) {
nisse14adba72017-03-20 03:52:39 -070090 if (!configuration.receiver_only) {
Erik Språng4580ca22019-07-04 10:38:43 +020091 rtp_sender_.reset(new RTPSender(configuration));
nisse14adba72017-03-20 03:52:39 -070092 // Make sure rtcp sender use same timestamp offset as rtp sender.
93 rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset());
94 }
danilchap71fead22016-08-18 02:01:49 -070095
96 // Set default packet size limit.
nisse284542b2017-01-10 08:58:32 -080097 // TODO(nisse): Kind-of duplicates
98 // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize.
99 const size_t kTcpOverIpv4HeaderSize = 40;
100 SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101}
102
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100103ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() = default;
104
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000105// Returns the number of milliseconds until the module want a worker thread
106// to call Process.
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000107int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() {
sprang168794c2017-07-06 04:38:06 -0700108 return std::max<int64_t>(0,
109 next_process_time_ - clock_->TimeInMilliseconds());
niklase@google.com470e71d2011-07-07 08:21:25 +0000110}
111
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000112// Process any pending tasks such as timeouts (non time critical events).
pbosa26ac922016-02-25 04:50:01 -0800113void ModuleRtpRtcpImpl::Process() {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000114 const int64_t now = clock_->TimeInMilliseconds();
sprang168794c2017-07-06 04:38:06 -0700115 next_process_time_ = now + kRtpRtcpMaxIdleTimeProcessMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
nisse14adba72017-03-20 03:52:39 -0700117 if (rtp_sender_) {
nisse14adba72017-03-20 03:52:39 -0700118 if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) {
119 rtp_sender_->ProcessBitrate();
120 last_bitrate_process_time_ = now;
sprang168794c2017-07-06 04:38:06 -0700121 next_process_time_ =
122 std::min(next_process_time_, now + kRtpRtcpBitrateProcessTimeMs);
123 }
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000124 }
sprang168794c2017-07-06 04:38:06 -0700125
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000126 bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs;
127 if (rtcp_sender_.Sending()) {
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200128 // Process RTT if we have received a report block and we haven't
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000129 // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds.
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200130 if (rtcp_receiver_.LastReceivedReportBlockMs() > last_rtt_process_time_ &&
131 process_rtt) {
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000132 std::vector<RTCPReportBlock> receive_blocks;
133 rtcp_receiver_.StatisticsReceived(&receive_blocks);
134 int64_t max_rtt = 0;
135 for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin();
136 it != receive_blocks.end(); ++it) {
137 int64_t rtt = 0;
srte3e69e5c2017-08-09 06:13:45 -0700138 rtcp_receiver_.RTT(it->sender_ssrc, &rtt, NULL, NULL, NULL);
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000139 max_rtt = (rtt > max_rtt) ? rtt : max_rtt;
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +0000140 }
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000141 // Report the rtt.
142 if (rtt_stats_ && max_rtt != 0)
143 rtt_stats_->OnRttUpdate(max_rtt);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000144 }
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000145
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000146 // Verify receiver reports are delivered and the reported sequence number
147 // is increasing.
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800148 if (rtcp_receiver_.RtcpRrTimeout()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100149 RTC_LOG_F(LS_WARNING) << "Timeout: No RTCP RR received.";
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800150 } else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100151 RTC_LOG_F(LS_WARNING) << "Timeout: No increase in RTCP RR extended "
152 "highest sequence number.";
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000153 }
154
155 if (remote_bitrate_ && rtcp_sender_.TMMBR()) {
156 unsigned int target_bitrate = 0;
157 std::vector<unsigned int> ssrcs;
158 if (remote_bitrate_->LatestEstimate(&ssrcs, &target_bitrate)) {
159 if (!ssrcs.empty()) {
160 target_bitrate = target_bitrate / ssrcs.size();
161 }
162 rtcp_sender_.SetTargetBitrate(target_bitrate);
163 }
164 }
165 } else {
166 // Report rtt from receiver.
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000167 if (process_rtt) {
Yves Gerey665174f2018-06-19 15:03:05 +0200168 int64_t rtt_ms;
169 if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) {
170 rtt_stats_->OnRttUpdate(rtt_ms);
171 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000172 }
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000173 }
174
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000175 // Get processed rtt.
176 if (process_rtt) {
177 last_rtt_process_time_ = now;
sprang168794c2017-07-06 04:38:06 -0700178 next_process_time_ = std::min(
179 next_process_time_, last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs);
sprange2d83d62016-02-19 09:03:26 -0800180 if (rtt_stats_) {
181 // Make sure we have a valid RTT before setting.
182 int64_t last_rtt = rtt_stats_->LastProcessedRtt();
183 if (last_rtt >= 0)
184 set_rtt_ms(last_rtt);
185 }
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000186 }
187
Danil Chapovalov70ffead2016-07-20 15:26:59 +0200188 if (rtcp_sender_.TimeToSendRTCPReport())
189 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000190
danilchap9bf610e2017-02-20 06:03:01 -0800191 if (TMMBR() && rtcp_receiver_.UpdateTmmbrTimers()) {
192 rtcp_receiver_.NotifyTmmbrUpdated();
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000193 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000194}
195
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000196void ModuleRtpRtcpImpl::SetRtxSendStatus(int mode) {
nisse14adba72017-03-20 03:52:39 -0700197 rtp_sender_->SetRtxStatus(mode);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000198}
199
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000200int ModuleRtpRtcpImpl::RtxSendStatus() const {
nisse14adba72017-03-20 03:52:39 -0700201 return rtp_sender_ ? rtp_sender_->RtxStatus() : kRtxOff;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000202}
203
204void ModuleRtpRtcpImpl::SetRtxSsrc(uint32_t ssrc) {
nisse14adba72017-03-20 03:52:39 -0700205 rtp_sender_->SetRtxSsrc(ssrc);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000206}
207
Shao Changbine62202f2015-04-21 20:24:50 +0800208void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type,
209 int associated_payload_type) {
nisse14adba72017-03-20 03:52:39 -0700210 rtp_sender_->SetRtxPayloadType(payload_type, associated_payload_type);
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000211}
212
Danil Chapovalovd264df52018-06-14 12:59:38 +0200213absl::optional<uint32_t> ModuleRtpRtcpImpl::FlexfecSsrc() const {
brandtr7c7796b2017-07-03 06:02:53 -0700214 if (rtp_sender_)
215 return rtp_sender_->FlexfecSsrc();
Danil Chapovalovd264df52018-06-14 12:59:38 +0200216 return absl::nullopt;
brandtr9dfff292016-11-14 05:14:50 -0800217}
218
nisse479d3d72017-09-13 07:53:37 -0700219void ModuleRtpRtcpImpl::IncomingRtcpPacket(const uint8_t* rtcp_packet,
220 const size_t length) {
221 rtcp_receiver_.IncomingPacket(rtcp_packet, length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000222}
223
Niels Möller5fe95102019-03-04 16:49:25 +0100224void ModuleRtpRtcpImpl::RegisterSendPayloadFrequency(int payload_type,
225 int payload_frequency) {
226 rtcp_sender_.SetRtpClockRate(payload_type, payload_frequency);
Peter Boström8b79b072016-02-26 16:31:37 +0100227}
228
asapersson@webrtc.org9ffd8fe2015-01-21 08:22:50 +0000229int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload(const int8_t payload_type) {
Niels Möller59ab1cf2019-02-06 22:48:11 +0100230 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000231}
232
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000233uint32_t ModuleRtpRtcpImpl::StartTimestamp() const {
nisse14adba72017-03-20 03:52:39 -0700234 return rtp_sender_->TimestampOffset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000235}
236
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000237// Configure start timestamp, default is a random number.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000238void ModuleRtpRtcpImpl::SetStartTimestamp(const uint32_t timestamp) {
danilchap71fead22016-08-18 02:01:49 -0700239 rtcp_sender_.SetTimestampOffset(timestamp);
nisse14adba72017-03-20 03:52:39 -0700240 rtp_sender_->SetTimestampOffset(timestamp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000241}
242
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000243uint16_t ModuleRtpRtcpImpl::SequenceNumber() const {
nisse14adba72017-03-20 03:52:39 -0700244 return rtp_sender_->SequenceNumber();
niklase@google.com470e71d2011-07-07 08:21:25 +0000245}
246
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000247// Set SequenceNumber, default is a random number.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000248void ModuleRtpRtcpImpl::SetSequenceNumber(const uint16_t seq_num) {
nisse14adba72017-03-20 03:52:39 -0700249 rtp_sender_->SetSequenceNumber(seq_num);
niklase@google.com470e71d2011-07-07 08:21:25 +0000250}
251
Per83d09102016-04-15 14:59:13 +0200252void ModuleRtpRtcpImpl::SetRtpState(const RtpState& rtp_state) {
nisse14adba72017-03-20 03:52:39 -0700253 rtp_sender_->SetRtpState(rtp_state);
danilchap71fead22016-08-18 02:01:49 -0700254 rtcp_sender_.SetTimestampOffset(rtp_state.start_timestamp);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000255}
256
Per83d09102016-04-15 14:59:13 +0200257void ModuleRtpRtcpImpl::SetRtxState(const RtpState& rtp_state) {
nisse14adba72017-03-20 03:52:39 -0700258 rtp_sender_->SetRtxRtpState(rtp_state);
Per83d09102016-04-15 14:59:13 +0200259}
260
261RtpState ModuleRtpRtcpImpl::GetRtpState() const {
nisse14adba72017-03-20 03:52:39 -0700262 return rtp_sender_->GetRtpState();
Per83d09102016-04-15 14:59:13 +0200263}
264
265RtpState ModuleRtpRtcpImpl::GetRtxState() const {
nisse14adba72017-03-20 03:52:39 -0700266 return rtp_sender_->GetRtxRtpState();
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000267}
268
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000269uint32_t ModuleRtpRtcpImpl::SSRC() const {
nisse14adba72017-03-20 03:52:39 -0700270 return rtcp_sender_.SSRC();
niklase@google.com470e71d2011-07-07 08:21:25 +0000271}
272
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000273void ModuleRtpRtcpImpl::SetSSRC(const uint32_t ssrc) {
nisse14adba72017-03-20 03:52:39 -0700274 if (rtp_sender_) {
275 rtp_sender_->SetSSRC(ssrc);
276 }
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000277 rtcp_sender_.SetSSRC(ssrc);
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000278 SetRtcpReceiverSsrcs(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000279}
280
Amit Hilbuch77938e62018-12-21 09:23:38 -0800281void ModuleRtpRtcpImpl::SetRid(const std::string& rid) {
282 if (rtp_sender_) {
283 rtp_sender_->SetRid(rid);
284 }
285}
286
Steve Anton296a0ce2018-03-22 15:17:27 -0700287void ModuleRtpRtcpImpl::SetMid(const std::string& mid) {
288 if (rtp_sender_) {
289 rtp_sender_->SetMid(mid);
290 }
291 // TODO(bugs.webrtc.org/4050): If we end up supporting the MID SDES item for
292 // RTCP, this will need to be passed down to the RTCPSender also.
293}
294
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000295void ModuleRtpRtcpImpl::SetCsrcs(const std::vector<uint32_t>& csrcs) {
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000296 rtcp_sender_.SetCsrcs(csrcs);
nisse14adba72017-03-20 03:52:39 -0700297 rtp_sender_->SetCsrcs(csrcs);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000298}
299
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000300// TODO(pbos): Handle media and RTX streams separately (separate RTCP
301// feedbacks).
302RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000303 RTCPSender::FeedbackState state;
nisse14adba72017-03-20 03:52:39 -0700304 // This is called also when receiver_only is true. Hence below
305 // checks that rtp_sender_ exists.
306 if (rtp_sender_) {
307 StreamDataCounters rtp_stats;
308 StreamDataCounters rtx_stats;
309 rtp_sender_->GetDataCounters(&rtp_stats, &rtx_stats);
Yves Gerey665174f2018-06-19 15:03:05 +0200310 state.packets_sent =
311 rtp_stats.transmitted.packets + rtx_stats.transmitted.packets;
nisse14adba72017-03-20 03:52:39 -0700312 state.media_bytes_sent = rtp_stats.transmitted.payload_bytes +
313 rtx_stats.transmitted.payload_bytes;
314 state.send_bitrate = rtp_sender_->BitrateSent();
315 }
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000316 state.module = this;
317
Yves Gerey665174f2018-06-19 15:03:05 +0200318 LastReceivedNTP(&state.last_rr_ntp_secs, &state.last_rr_ntp_frac,
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000319 &state.remote_sr);
320
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +0200321 state.last_xr_rtis = rtcp_receiver_.ConsumeReceivedXrReferenceTimeInfo();
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000322
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000323 return state;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000324}
325
nisse14adba72017-03-20 03:52:39 -0700326// TODO(nisse): This method shouldn't be called for a receive-only
327// stream. Delete rtp_sender_ check as soon as all applications are
328// updated.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000329int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000330 if (rtcp_sender_.Sending() != sending) {
331 // Sends RTCP BYE when going from true to false
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000332 if (rtcp_sender_.SetSendingStatus(GetFeedbackState(), sending) != 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100333 RTC_LOG(LS_WARNING) << "Failed to send RTCP BYE";
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000334 }
nisse14adba72017-03-20 03:52:39 -0700335 if (sending && rtp_sender_) {
nisse7d59f6b2017-02-21 03:40:24 -0800336 // Update Rtcp receiver config, to track Rtx config changes from
337 // the SetRtxStatus and SetRtxSsrc methods.
nisse14adba72017-03-20 03:52:39 -0700338 SetRtcpReceiverSsrcs(rtp_sender_->SSRC());
nisse7d59f6b2017-02-21 03:40:24 -0800339 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000340 }
341 return 0;
342}
343
344bool ModuleRtpRtcpImpl::Sending() const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000345 return rtcp_sender_.Sending();
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000346}
347
nisse14adba72017-03-20 03:52:39 -0700348// TODO(nisse): This method shouldn't be called for a receive-only
349// stream. Delete rtp_sender_ check as soon as all applications are
350// updated.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000351void ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) {
nisse14adba72017-03-20 03:52:39 -0700352 if (rtp_sender_) {
353 rtp_sender_->SetSendingMediaStatus(sending);
354 } else {
355 RTC_DCHECK(!sending);
356 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000357}
358
359bool ModuleRtpRtcpImpl::SendingMedia() const {
nisse14adba72017-03-20 03:52:39 -0700360 return rtp_sender_ ? rtp_sender_->SendingMedia() : false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000361}
362
Sebastian Jansson1bca65b2018-10-10 09:58:08 +0200363void ModuleRtpRtcpImpl::SetAsPartOfAllocation(bool part_of_allocation) {
364 RTC_CHECK(rtp_sender_);
365 rtp_sender_->SetAsPartOfAllocation(part_of_allocation);
366}
367
Niels Möller5fe95102019-03-04 16:49:25 +0100368bool ModuleRtpRtcpImpl::OnSendingRtpFrame(uint32_t timestamp,
369 int64_t capture_time_ms,
370 int payload_type,
371 bool force_sender_report) {
372 if (!Sending())
373 return false;
374
375 rtcp_sender_.SetLastRtpTime(timestamp, capture_time_ms, payload_type);
376 // Make sure an RTCP report isn't queued behind a key frame.
377 if (rtcp_sender_.TimeToSendRTCPReport(force_sender_report))
378 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
379
380 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000381}
382
Erik Språngd2879622019-05-10 08:29:01 -0700383RtpPacketSendResult ModuleRtpRtcpImpl::TimeToSendPacket(
384 uint32_t ssrc,
385 uint16_t sequence_number,
386 int64_t capture_time_ms,
387 bool retransmission,
388 const PacedPacketInfo& pacing_info) {
nisse14adba72017-03-20 03:52:39 -0700389 return rtp_sender_->TimeToSendPacket(ssrc, sequence_number, capture_time_ms,
Yves Gerey665174f2018-06-19 15:03:05 +0200390 retransmission, pacing_info);
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000391}
392
Erik Språng9c771c22019-06-17 16:31:53 +0200393bool ModuleRtpRtcpImpl::TrySendPacket(RtpPacketToSend* packet,
394 const PacedPacketInfo& pacing_info) {
395 return rtp_sender_->TrySendPacket(packet, pacing_info);
396}
397
Erik Språng6f129b32019-07-11 13:01:58 +0200398bool ModuleRtpRtcpImpl::SupportsPadding() const {
399 return rtp_sender_->SupportsPadding();
400}
401
402bool ModuleRtpRtcpImpl::SupportsRtxPayloadPadding() const {
403 return rtp_sender_->SupportsRtxPayloadPadding();
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
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000593// (TMMBR) Temporary Max Media Bit Rate.
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000594bool ModuleRtpRtcpImpl::TMMBR() const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000595 return rtcp_sender_.TMMBR();
niklase@google.com470e71d2011-07-07 08:21:25 +0000596}
597
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000598void ModuleRtpRtcpImpl::SetTMMBRStatus(const bool enable) {
599 rtcp_sender_.SetTMMBRStatus(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000600}
601
danilchap853ecb22016-08-22 08:26:15 -0700602void ModuleRtpRtcpImpl::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) {
603 rtcp_sender_.SetTmmbn(std::move(bounding_set));
niklase@google.com470e71d2011-07-07 08:21:25 +0000604}
605
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000606// Send a Negative acknowledgment packet.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000607int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list,
608 const uint16_t size) {
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000609 uint16_t nack_length = size;
610 uint16_t start_id = 0;
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +0100611 int64_t now_ms = clock_->TimeInMilliseconds();
612 if (TimeToSendFullNackList(now_ms)) {
613 nack_last_time_sent_full_ms_ = now_ms;
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000614 } else {
615 // Only send extended list.
616 if (nack_last_seq_number_sent_ == nack_list[size - 1]) {
617 // Last sequence number is the same, do not send list.
618 return 0;
619 }
620 // Send new sequence numbers.
621 for (int i = 0; i < size; ++i) {
622 if (nack_last_seq_number_sent_ == nack_list[i]) {
623 start_id = i + 1;
624 break;
625 }
626 }
627 nack_length = size - start_id;
628 }
629
630 // Our RTCP NACK implementation is limited to kRtcpMaxNackFields sequence
631 // numbers per RTCP packet.
632 if (nack_length > kRtcpMaxNackFields) {
633 nack_length = kRtcpMaxNackFields;
634 }
635 nack_last_seq_number_sent_ = nack_list[start_id + nack_length - 1];
636
philipel83f831a2016-03-12 03:30:23 -0800637 return rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, nack_length,
638 &nack_list[start_id]);
639}
640
641void ModuleRtpRtcpImpl::SendNack(
642 const std::vector<uint16_t>& sequence_numbers) {
643 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, sequence_numbers.size(),
644 sequence_numbers.data());
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000645}
646
647bool ModuleRtpRtcpImpl::TimeToSendFullNackList(int64_t now) const {
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000648 // Use RTT from RtcpRttStats class if provided.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000649 int64_t rtt = rtt_ms();
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000650 if (rtt == 0) {
651 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
652 }
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000653
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000654 const int64_t kStartUpRttMs = 100;
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000655 int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5.
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000656 if (rtt == 0) {
657 wait_time = kStartUpRttMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000658 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000659
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000660 // Send a full NACK list once within every |wait_time|.
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +0100661 return now - nack_last_time_sent_full_ms_ > wait_time;
niklase@google.com470e71d2011-07-07 08:21:25 +0000662}
663
asapersson@webrtc.org9ffd8fe2015-01-21 08:22:50 +0000664// Store the sent packets, needed to answer to Negative acknowledgment requests.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000665void ModuleRtpRtcpImpl::SetStorePacketsStatus(const bool enable,
666 const uint16_t number_to_store) {
nisse14adba72017-03-20 03:52:39 -0700667 rtp_sender_->SetStorePacketsStatus(enable, number_to_store);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000668}
niklase@google.com470e71d2011-07-07 08:21:25 +0000669
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000670bool ModuleRtpRtcpImpl::StorePackets() const {
nisse14adba72017-03-20 03:52:39 -0700671 return rtp_sender_->StorePackets();
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +0000672}
673
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000674void ModuleRtpRtcpImpl::RegisterRtcpStatisticsCallback(
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000675 RtcpStatisticsCallback* callback) {
676 rtcp_receiver_.RegisterRtcpStatisticsCallback(callback);
677}
678
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000679RtcpStatisticsCallback* ModuleRtpRtcpImpl::GetRtcpStatisticsCallback() {
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000680 return rtcp_receiver_.GetRtcpStatisticsCallback();
681}
682
Henrik Boström87e3f9d2019-05-27 10:44:24 +0200683void ModuleRtpRtcpImpl::SetReportBlockDataObserver(
684 ReportBlockDataObserver* observer) {
685 return rtcp_receiver_.SetReportBlockDataObserver(observer);
686}
687
sprang233bd872015-09-08 13:25:16 -0700688bool ModuleRtpRtcpImpl::SendFeedbackPacket(
689 const rtcp::TransportFeedback& packet) {
690 return rtcp_sender_.SendFeedbackPacket(packet);
691}
692
Elad Alon7d6a4c02019-02-25 13:00:51 +0100693int32_t ModuleRtpRtcpImpl::SendLossNotification(uint16_t last_decoded_seq_num,
694 uint16_t last_received_seq_num,
Elad Alone86af2c2019-06-03 14:37:50 +0200695 bool decodability_flag,
696 bool buffering_allowed) {
Elad Alon7d6a4c02019-02-25 13:00:51 +0100697 return rtcp_sender_.SendLossNotification(
698 GetFeedbackState(), last_decoded_seq_num, last_received_seq_num,
Elad Alone86af2c2019-06-03 14:37:50 +0200699 decodability_flag, buffering_allowed);
Elad Alon7d6a4c02019-02-25 13:00:51 +0100700}
701
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000702void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000703 // Inform about the incoming SSRC.
704 rtcp_sender_.SetRemoteSSRC(ssrc);
705 rtcp_receiver_.SetRemoteSSRC(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000706}
707
Niels Möller5fe95102019-03-04 16:49:25 +0100708// TODO(nisse): Delete video_rate amd fec_rate arguments.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000709void ModuleRtpRtcpImpl::BitrateSent(uint32_t* total_rate,
710 uint32_t* video_rate,
711 uint32_t* fec_rate,
712 uint32_t* nack_rate) const {
nisse14adba72017-03-20 03:52:39 -0700713 *total_rate = rtp_sender_->BitrateSent();
Niels Möller5fe95102019-03-04 16:49:25 +0100714 if (video_rate)
715 *video_rate = 0;
716 if (fec_rate)
717 *fec_rate = 0;
nisse14adba72017-03-20 03:52:39 -0700718 *nack_rate = rtp_sender_->NackOverheadRate();
niklase@google.com470e71d2011-07-07 08:21:25 +0000719}
720
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000721void ModuleRtpRtcpImpl::OnRequestSendReport() {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000722 SendRTCP(kRtcpSr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000723}
724
Danil Chapovalov2800d742016-08-26 18:48:46 +0200725void ModuleRtpRtcpImpl::OnReceivedNack(
726 const std::vector<uint16_t>& nack_sequence_numbers) {
nisse14adba72017-03-20 03:52:39 -0700727 if (!rtp_sender_)
728 return;
729
Yves Gerey665174f2018-06-19 15:03:05 +0200730 if (!rtp_sender_->StorePackets() || nack_sequence_numbers.size() == 0) {
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000731 return;
732 }
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000733 // Use RTT from RtcpRttStats class if provided.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000734 int64_t rtt = rtt_ms();
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000735 if (rtt == 0) {
736 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
737 }
nisse14adba72017-03-20 03:52:39 -0700738 rtp_sender_->OnReceivedNack(nack_sequence_numbers, rtt);
niklase@google.com470e71d2011-07-07 08:21:25 +0000739}
740
isheriff6b4b5f32016-06-08 00:24:21 -0700741void ModuleRtpRtcpImpl::OnReceivedRtcpReportBlocks(
742 const ReportBlockList& report_blocks) {
Niels Möller5fe95102019-03-04 16:49:25 +0100743 if (ack_observer_) {
Niels Möller59ab1cf2019-02-06 22:48:11 +0100744 uint32_t ssrc = SSRC();
745
746 for (const RTCPReportBlock& report_block : report_blocks) {
747 if (ssrc == report_block.source_ssrc) {
Niels Möller5fe95102019-03-04 16:49:25 +0100748 ack_observer_->OnReceivedAck(
749 report_block.extended_highest_sequence_number);
Niels Möller59ab1cf2019-02-06 22:48:11 +0100750 }
751 }
752 }
isheriff6b4b5f32016-06-08 00:24:21 -0700753}
754
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000755bool ModuleRtpRtcpImpl::LastReceivedNTP(
756 uint32_t* rtcp_arrival_time_secs, // When we got the last report.
757 uint32_t* rtcp_arrival_time_frac,
758 uint32_t* remote_sr) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000759 // Remote SR: NTP inside the last received (mid 16 bits from sec and frac).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000760 uint32_t ntp_secs = 0;
761 uint32_t ntp_frac = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000762
Yves Gerey665174f2018-06-19 15:03:05 +0200763 if (!rtcp_receiver_.NTP(&ntp_secs, &ntp_frac, rtcp_arrival_time_secs,
764 rtcp_arrival_time_frac, NULL)) {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000765 return false;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000766 }
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000767 *remote_sr =
768 ((ntp_secs & 0x0000ffff) << 16) + ((ntp_frac & 0xffff0000) >> 16);
769 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000770}
771
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000772// Called from RTCPsender.
danilchap2b616392016-08-18 06:17:42 -0700773std::vector<rtcp::TmmbItem> ModuleRtpRtcpImpl::BoundingSet(bool* tmmbr_owner) {
774 return rtcp_receiver_.BoundingSet(tmmbr_owner);
niklase@google.com470e71d2011-07-07 08:21:25 +0000775}
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000776
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000777void ModuleRtpRtcpImpl::SetRtcpReceiverSsrcs(uint32_t main_ssrc) {
778 std::set<uint32_t> ssrcs;
779 ssrcs.insert(main_ssrc);
nisse14adba72017-03-20 03:52:39 -0700780 if (RtxSendStatus() != kRtxOff)
781 ssrcs.insert(rtp_sender_->RtxSsrc());
Danil Chapovalovd264df52018-06-14 12:59:38 +0200782 absl::optional<uint32_t> flexfec_ssrc = FlexfecSsrc();
brandtr7c7796b2017-07-03 06:02:53 -0700783 if (flexfec_ssrc)
784 ssrcs.insert(*flexfec_ssrc);
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000785 rtcp_receiver_.SetSsrcs(main_ssrc, ssrcs);
786}
787
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000788void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) {
danilchap7c9426c2016-04-14 03:05:31 -0700789 rtc::CritScope cs(&critical_section_rtt_);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000790 rtt_ms_ = rtt_ms;
Erik Språng8b101922018-01-18 11:58:05 -0800791 if (rtp_sender_)
792 rtp_sender_->SetRtt(rtt_ms);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000793}
794
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000795int64_t ModuleRtpRtcpImpl::rtt_ms() const {
danilchap7c9426c2016-04-14 03:05:31 -0700796 rtc::CritScope cs(&critical_section_rtt_);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000797 return rtt_ms_;
798}
799
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000800void ModuleRtpRtcpImpl::RegisterSendChannelRtpStatisticsCallback(
801 StreamDataCountersCallback* callback) {
nisse14adba72017-03-20 03:52:39 -0700802 rtp_sender_->RegisterRtpStatisticsCallback(callback);
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000803}
804
805StreamDataCountersCallback*
Yves Gerey665174f2018-06-19 15:03:05 +0200806ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const {
nisse14adba72017-03-20 03:52:39 -0700807 return rtp_sender_->GetRtpStatisticsCallback();
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000808}
sprang5e38c962016-12-01 05:18:09 -0800809
810void ModuleRtpRtcpImpl::SetVideoBitrateAllocation(
Erik Språng566124a2018-04-23 12:32:22 +0200811 const VideoBitrateAllocation& bitrate) {
sprang5e38c962016-12-01 05:18:09 -0800812 rtcp_sender_.SetVideoBitrateAllocation(bitrate);
813}
Niels Möller5fe95102019-03-04 16:49:25 +0100814
815RTPSender* ModuleRtpRtcpImpl::RtpSender() {
816 return rtp_sender_.get();
817}
818
819const RTPSender* ModuleRtpRtcpImpl::RtpSender() const {
820 return rtp_sender_.get();
821}
822
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000823} // namespace webrtc