blob: f8a0d709aea2a813c6b8263138aa468533fbf1b7 [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;
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)
nisse14adba72017-03-20 03:52:39 -070062 : rtcp_sender_(configuration.audio,
stefan@webrtc.orga15fbfd2014-06-17 17:32:05 +000063 configuration.clock,
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000064 configuration.receive_statistics,
sprang86fd9ed2015-09-29 04:45:43 -070065 configuration.rtcp_packet_type_counter_observer,
terelius429c3452016-01-21 05:42:04 -080066 configuration.event_log,
Jiawei Ou3587b832018-01-31 22:08:26 -080067 configuration.outgoing_transport,
Jiawei Ou8b5d9d82018-11-15 16:44:37 -080068 configuration.rtcp_report_interval_ms > 0
69 ? configuration.rtcp_report_interval_ms
70 : (configuration.audio ? kDefaultAudioReportInterval
71 : kDefaultVideoReportInterval)),
Peter Boströmac547a62015-09-17 23:03:57 +020072 rtcp_receiver_(configuration.clock,
Peter Boströmfe7a80c2015-04-23 17:53:17 +020073 configuration.receiver_only,
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000074 configuration.rtcp_packet_type_counter_observer,
mflodman@webrtc.org96abda02015-02-25 13:50:10 +000075 configuration.bandwidth_callback,
76 configuration.intra_frame_callback,
Elad Alon0a8562e2019-04-09 11:55:13 +020077 configuration.rtcp_loss_notification_observer,
Erik Språng6b8d3552015-09-24 15:06:57 +020078 configuration.transport_feedback_callback,
spranga790d832016-12-02 07:29:44 -080079 configuration.bitrate_allocation_observer,
Jiawei Ou8b5d9d82018-11-15 16:44:37 -080080 configuration.rtcp_report_interval_ms > 0
81 ? configuration.rtcp_report_interval_ms
82 : (configuration.audio ? kDefaultAudioReportInterval
83 : kDefaultVideoReportInterval),
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +000084 this),
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000085 clock_(configuration.clock),
sprang168794c2017-07-06 04:38:06 -070086 last_bitrate_process_time_(clock_->TimeInMilliseconds()),
87 last_rtt_process_time_(clock_->TimeInMilliseconds()),
88 next_process_time_(clock_->TimeInMilliseconds() +
89 kRtpRtcpMaxIdleTimeProcessMs),
asapersson35151f32016-05-02 23:44:01 -070090 packet_overhead_(28), // IPV4 UDP.
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +010091 nack_last_time_sent_full_ms_(0),
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +000092 nack_last_seq_number_sent_(0),
mflodman@webrtc.org7c894b72012-11-26 12:40:15 +000093 remote_bitrate_(configuration.remote_bitrate_estimator),
Niels Möller5fe95102019-03-04 16:49:25 +010094 ack_observer_(configuration.ack_observer),
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000095 rtt_stats_(configuration.rtt_stats),
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +000096 rtt_ms_(0) {
Per Kjellandere11b7d22019-02-21 07:55:59 +010097 FieldTrialBasedConfig default_trials;
nisse14adba72017-03-20 03:52:39 -070098 if (!configuration.receiver_only) {
99 rtp_sender_.reset(new RTPSender(
Erik Språng7b52f102018-02-07 14:37:37 +0100100 configuration.audio, configuration.clock,
101 configuration.outgoing_transport, configuration.paced_sender,
Niels Möller59ab1cf2019-02-06 22:48:11 +0100102 configuration.flexfec_sender
103 ? absl::make_optional(configuration.flexfec_sender->ssrc())
104 : absl::nullopt,
nisse14adba72017-03-20 03:52:39 -0700105 configuration.transport_sequence_number_allocator,
106 configuration.transport_feedback_callback,
107 configuration.send_bitrate_observer,
Erik Språng7b52f102018-02-07 14:37:37 +0100108 configuration.send_side_delay_observer, configuration.event_log,
nisse14adba72017-03-20 03:52:39 -0700109 configuration.send_packet_observer,
110 configuration.retransmission_rate_limiter,
Erik Språng7b52f102018-02-07 14:37:37 +0100111 configuration.overhead_observer,
Benjamin Wright192eeec2018-10-17 17:27:25 -0700112 configuration.populate_network2_timestamp,
Johannes Kron9190b822018-10-29 11:22:05 +0100113 configuration.frame_encryptor, configuration.require_frame_encryption,
Per Kjellandere11b7d22019-02-21 07:55:59 +0100114 configuration.extmap_allow_mixed,
115 configuration.field_trials ? *configuration.field_trials
116 : default_trials));
Niels Mölleree5ccbc2019-03-06 16:47:29 +0100117
nisse14adba72017-03-20 03:52:39 -0700118 // Make sure rtcp sender use same timestamp offset as rtp sender.
119 rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset());
120 }
danilchap71fead22016-08-18 02:01:49 -0700121
122 // Set default packet size limit.
nisse284542b2017-01-10 08:58:32 -0800123 // TODO(nisse): Kind-of duplicates
124 // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize.
125 const size_t kTcpOverIpv4HeaderSize = 40;
126 SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize);
niklase@google.com470e71d2011-07-07 08:21:25 +0000127}
128
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100129ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() = default;
130
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000131// Returns the number of milliseconds until the module want a worker thread
132// to call Process.
pkasting@chromium.org0b1534c2014-12-15 22:09:40 +0000133int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() {
sprang168794c2017-07-06 04:38:06 -0700134 return std::max<int64_t>(0,
135 next_process_time_ - clock_->TimeInMilliseconds());
niklase@google.com470e71d2011-07-07 08:21:25 +0000136}
137
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000138// Process any pending tasks such as timeouts (non time critical events).
pbosa26ac922016-02-25 04:50:01 -0800139void ModuleRtpRtcpImpl::Process() {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000140 const int64_t now = clock_->TimeInMilliseconds();
sprang168794c2017-07-06 04:38:06 -0700141 next_process_time_ = now + kRtpRtcpMaxIdleTimeProcessMs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
nisse14adba72017-03-20 03:52:39 -0700143 if (rtp_sender_) {
nisse14adba72017-03-20 03:52:39 -0700144 if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) {
145 rtp_sender_->ProcessBitrate();
146 last_bitrate_process_time_ = now;
sprang168794c2017-07-06 04:38:06 -0700147 next_process_time_ =
148 std::min(next_process_time_, now + kRtpRtcpBitrateProcessTimeMs);
149 }
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000150 }
sprang168794c2017-07-06 04:38:06 -0700151
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000152 bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs;
153 if (rtcp_sender_.Sending()) {
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200154 // Process RTT if we have received a report block and we haven't
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000155 // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds.
Danil Chapovalov760c4b42017-09-27 13:25:24 +0200156 if (rtcp_receiver_.LastReceivedReportBlockMs() > last_rtt_process_time_ &&
157 process_rtt) {
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000158 std::vector<RTCPReportBlock> receive_blocks;
159 rtcp_receiver_.StatisticsReceived(&receive_blocks);
160 int64_t max_rtt = 0;
161 for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin();
162 it != receive_blocks.end(); ++it) {
163 int64_t rtt = 0;
srte3e69e5c2017-08-09 06:13:45 -0700164 rtcp_receiver_.RTT(it->sender_ssrc, &rtt, NULL, NULL, NULL);
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000165 max_rtt = (rtt > max_rtt) ? rtt : max_rtt;
mflodman@webrtc.orgd7d46882012-02-14 12:49:59 +0000166 }
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000167 // Report the rtt.
168 if (rtt_stats_ && max_rtt != 0)
169 rtt_stats_->OnRttUpdate(max_rtt);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000170 }
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000171
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000172 // Verify receiver reports are delivered and the reported sequence number
173 // is increasing.
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800174 if (rtcp_receiver_.RtcpRrTimeout()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100175 RTC_LOG_F(LS_WARNING) << "Timeout: No RTCP RR received.";
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800176 } else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100177 RTC_LOG_F(LS_WARNING) << "Timeout: No increase in RTCP RR extended "
178 "highest sequence number.";
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000179 }
180
181 if (remote_bitrate_ && rtcp_sender_.TMMBR()) {
182 unsigned int target_bitrate = 0;
183 std::vector<unsigned int> ssrcs;
184 if (remote_bitrate_->LatestEstimate(&ssrcs, &target_bitrate)) {
185 if (!ssrcs.empty()) {
186 target_bitrate = target_bitrate / ssrcs.size();
187 }
188 rtcp_sender_.SetTargetBitrate(target_bitrate);
189 }
190 }
191 } else {
192 // Report rtt from receiver.
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000193 if (process_rtt) {
Yves Gerey665174f2018-06-19 15:03:05 +0200194 int64_t rtt_ms;
195 if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) {
196 rtt_stats_->OnRttUpdate(rtt_ms);
197 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000198 }
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000199 }
200
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000201 // Get processed rtt.
202 if (process_rtt) {
203 last_rtt_process_time_ = now;
sprang168794c2017-07-06 04:38:06 -0700204 next_process_time_ = std::min(
205 next_process_time_, last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs);
sprange2d83d62016-02-19 09:03:26 -0800206 if (rtt_stats_) {
207 // Make sure we have a valid RTT before setting.
208 int64_t last_rtt = rtt_stats_->LastProcessedRtt();
209 if (last_rtt >= 0)
210 set_rtt_ms(last_rtt);
211 }
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000212 }
213
Danil Chapovalov70ffead2016-07-20 15:26:59 +0200214 if (rtcp_sender_.TimeToSendRTCPReport())
215 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
mflodman@webrtc.org9dd0ebc2015-02-26 12:57:47 +0000216
danilchap9bf610e2017-02-20 06:03:01 -0800217 if (TMMBR() && rtcp_receiver_.UpdateTmmbrTimers()) {
218 rtcp_receiver_.NotifyTmmbrUpdated();
asapersson@webrtc.org0b3c35a2012-01-16 11:06:31 +0000219 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000220}
221
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000222void ModuleRtpRtcpImpl::SetRtxSendStatus(int mode) {
nisse14adba72017-03-20 03:52:39 -0700223 rtp_sender_->SetRtxStatus(mode);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000224}
225
pbos@webrtc.org0b0c2412015-01-13 14:15:15 +0000226int ModuleRtpRtcpImpl::RtxSendStatus() const {
nisse14adba72017-03-20 03:52:39 -0700227 return rtp_sender_ ? rtp_sender_->RtxStatus() : kRtxOff;
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000228}
229
230void ModuleRtpRtcpImpl::SetRtxSsrc(uint32_t ssrc) {
nisse14adba72017-03-20 03:52:39 -0700231 rtp_sender_->SetRtxSsrc(ssrc);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000232}
233
Shao Changbine62202f2015-04-21 20:24:50 +0800234void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type,
235 int associated_payload_type) {
nisse14adba72017-03-20 03:52:39 -0700236 rtp_sender_->SetRtxPayloadType(payload_type, associated_payload_type);
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000237}
238
Danil Chapovalovd264df52018-06-14 12:59:38 +0200239absl::optional<uint32_t> ModuleRtpRtcpImpl::FlexfecSsrc() const {
brandtr7c7796b2017-07-03 06:02:53 -0700240 if (rtp_sender_)
241 return rtp_sender_->FlexfecSsrc();
Danil Chapovalovd264df52018-06-14 12:59:38 +0200242 return absl::nullopt;
brandtr9dfff292016-11-14 05:14:50 -0800243}
244
nisse479d3d72017-09-13 07:53:37 -0700245void ModuleRtpRtcpImpl::IncomingRtcpPacket(const uint8_t* rtcp_packet,
246 const size_t length) {
247 rtcp_receiver_.IncomingPacket(rtcp_packet, length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000248}
249
Niels Möller5fe95102019-03-04 16:49:25 +0100250void ModuleRtpRtcpImpl::RegisterSendPayloadFrequency(int payload_type,
251 int payload_frequency) {
252 rtcp_sender_.SetRtpClockRate(payload_type, payload_frequency);
Peter Boström8b79b072016-02-26 16:31:37 +0100253}
254
asapersson@webrtc.org9ffd8fe2015-01-21 08:22:50 +0000255int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload(const int8_t payload_type) {
Niels Möller59ab1cf2019-02-06 22:48:11 +0100256 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000257}
258
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000259uint32_t ModuleRtpRtcpImpl::StartTimestamp() const {
nisse14adba72017-03-20 03:52:39 -0700260 return rtp_sender_->TimestampOffset();
niklase@google.com470e71d2011-07-07 08:21:25 +0000261}
262
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000263// Configure start timestamp, default is a random number.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000264void ModuleRtpRtcpImpl::SetStartTimestamp(const uint32_t timestamp) {
danilchap71fead22016-08-18 02:01:49 -0700265 rtcp_sender_.SetTimestampOffset(timestamp);
nisse14adba72017-03-20 03:52:39 -0700266 rtp_sender_->SetTimestampOffset(timestamp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000267}
268
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000269uint16_t ModuleRtpRtcpImpl::SequenceNumber() const {
nisse14adba72017-03-20 03:52:39 -0700270 return rtp_sender_->SequenceNumber();
niklase@google.com470e71d2011-07-07 08:21:25 +0000271}
272
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000273// Set SequenceNumber, default is a random number.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000274void ModuleRtpRtcpImpl::SetSequenceNumber(const uint16_t seq_num) {
nisse14adba72017-03-20 03:52:39 -0700275 rtp_sender_->SetSequenceNumber(seq_num);
niklase@google.com470e71d2011-07-07 08:21:25 +0000276}
277
Per83d09102016-04-15 14:59:13 +0200278void ModuleRtpRtcpImpl::SetRtpState(const RtpState& rtp_state) {
nisse14adba72017-03-20 03:52:39 -0700279 rtp_sender_->SetRtpState(rtp_state);
danilchap71fead22016-08-18 02:01:49 -0700280 rtcp_sender_.SetTimestampOffset(rtp_state.start_timestamp);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000281}
282
Per83d09102016-04-15 14:59:13 +0200283void ModuleRtpRtcpImpl::SetRtxState(const RtpState& rtp_state) {
nisse14adba72017-03-20 03:52:39 -0700284 rtp_sender_->SetRtxRtpState(rtp_state);
Per83d09102016-04-15 14:59:13 +0200285}
286
287RtpState ModuleRtpRtcpImpl::GetRtpState() const {
nisse14adba72017-03-20 03:52:39 -0700288 return rtp_sender_->GetRtpState();
Per83d09102016-04-15 14:59:13 +0200289}
290
291RtpState ModuleRtpRtcpImpl::GetRtxState() const {
nisse14adba72017-03-20 03:52:39 -0700292 return rtp_sender_->GetRtxRtpState();
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000293}
294
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000295uint32_t ModuleRtpRtcpImpl::SSRC() const {
nisse14adba72017-03-20 03:52:39 -0700296 return rtcp_sender_.SSRC();
niklase@google.com470e71d2011-07-07 08:21:25 +0000297}
298
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000299void ModuleRtpRtcpImpl::SetSSRC(const uint32_t ssrc) {
nisse14adba72017-03-20 03:52:39 -0700300 if (rtp_sender_) {
301 rtp_sender_->SetSSRC(ssrc);
302 }
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000303 rtcp_sender_.SetSSRC(ssrc);
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000304 SetRtcpReceiverSsrcs(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000305}
306
Amit Hilbuch77938e62018-12-21 09:23:38 -0800307void ModuleRtpRtcpImpl::SetRid(const std::string& rid) {
308 if (rtp_sender_) {
309 rtp_sender_->SetRid(rid);
310 }
311}
312
Steve Anton296a0ce2018-03-22 15:17:27 -0700313void ModuleRtpRtcpImpl::SetMid(const std::string& mid) {
314 if (rtp_sender_) {
315 rtp_sender_->SetMid(mid);
316 }
317 // TODO(bugs.webrtc.org/4050): If we end up supporting the MID SDES item for
318 // RTCP, this will need to be passed down to the RTCPSender also.
319}
320
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000321void ModuleRtpRtcpImpl::SetCsrcs(const std::vector<uint32_t>& csrcs) {
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000322 rtcp_sender_.SetCsrcs(csrcs);
nisse14adba72017-03-20 03:52:39 -0700323 rtp_sender_->SetCsrcs(csrcs);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000324}
325
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000326// TODO(pbos): Handle media and RTX streams separately (separate RTCP
327// feedbacks).
328RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000329 RTCPSender::FeedbackState state;
nisse14adba72017-03-20 03:52:39 -0700330 // This is called also when receiver_only is true. Hence below
331 // checks that rtp_sender_ exists.
332 if (rtp_sender_) {
333 StreamDataCounters rtp_stats;
334 StreamDataCounters rtx_stats;
335 rtp_sender_->GetDataCounters(&rtp_stats, &rtx_stats);
Yves Gerey665174f2018-06-19 15:03:05 +0200336 state.packets_sent =
337 rtp_stats.transmitted.packets + rtx_stats.transmitted.packets;
nisse14adba72017-03-20 03:52:39 -0700338 state.media_bytes_sent = rtp_stats.transmitted.payload_bytes +
339 rtx_stats.transmitted.payload_bytes;
340 state.send_bitrate = rtp_sender_->BitrateSent();
341 }
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000342 state.module = this;
343
Yves Gerey665174f2018-06-19 15:03:05 +0200344 LastReceivedNTP(&state.last_rr_ntp_secs, &state.last_rr_ntp_frac,
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000345 &state.remote_sr);
346
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +0200347 state.last_xr_rtis = rtcp_receiver_.ConsumeReceivedXrReferenceTimeInfo();
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000348
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000349 return state;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000350}
351
nisse14adba72017-03-20 03:52:39 -0700352// TODO(nisse): This method shouldn't be called for a receive-only
353// stream. Delete rtp_sender_ check as soon as all applications are
354// updated.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000355int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000356 if (rtcp_sender_.Sending() != sending) {
357 // Sends RTCP BYE when going from true to false
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000358 if (rtcp_sender_.SetSendingStatus(GetFeedbackState(), sending) != 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100359 RTC_LOG(LS_WARNING) << "Failed to send RTCP BYE";
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000360 }
nisse14adba72017-03-20 03:52:39 -0700361 if (sending && rtp_sender_) {
nisse7d59f6b2017-02-21 03:40:24 -0800362 // Update Rtcp receiver config, to track Rtx config changes from
363 // the SetRtxStatus and SetRtxSsrc methods.
nisse14adba72017-03-20 03:52:39 -0700364 SetRtcpReceiverSsrcs(rtp_sender_->SSRC());
nisse7d59f6b2017-02-21 03:40:24 -0800365 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000366 }
367 return 0;
368}
369
370bool ModuleRtpRtcpImpl::Sending() const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000371 return rtcp_sender_.Sending();
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000372}
373
nisse14adba72017-03-20 03:52:39 -0700374// TODO(nisse): This method shouldn't be called for a receive-only
375// stream. Delete rtp_sender_ check as soon as all applications are
376// updated.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000377void ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) {
nisse14adba72017-03-20 03:52:39 -0700378 if (rtp_sender_) {
379 rtp_sender_->SetSendingMediaStatus(sending);
380 } else {
381 RTC_DCHECK(!sending);
382 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000383}
384
385bool ModuleRtpRtcpImpl::SendingMedia() const {
nisse14adba72017-03-20 03:52:39 -0700386 return rtp_sender_ ? rtp_sender_->SendingMedia() : false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000387}
388
Sebastian Jansson1bca65b2018-10-10 09:58:08 +0200389void ModuleRtpRtcpImpl::SetAsPartOfAllocation(bool part_of_allocation) {
390 RTC_CHECK(rtp_sender_);
391 rtp_sender_->SetAsPartOfAllocation(part_of_allocation);
392}
393
Niels Möller5fe95102019-03-04 16:49:25 +0100394bool ModuleRtpRtcpImpl::OnSendingRtpFrame(uint32_t timestamp,
395 int64_t capture_time_ms,
396 int payload_type,
397 bool force_sender_report) {
398 if (!Sending())
399 return false;
400
401 rtcp_sender_.SetLastRtpTime(timestamp, capture_time_ms, payload_type);
402 // Make sure an RTCP report isn't queued behind a key frame.
403 if (rtcp_sender_.TimeToSendRTCPReport(force_sender_report))
404 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
405
406 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000407}
408
Erik Språngd2879622019-05-10 08:29:01 -0700409RtpPacketSendResult ModuleRtpRtcpImpl::TimeToSendPacket(
410 uint32_t ssrc,
411 uint16_t sequence_number,
412 int64_t capture_time_ms,
413 bool retransmission,
414 const PacedPacketInfo& pacing_info) {
nisse14adba72017-03-20 03:52:39 -0700415 return rtp_sender_->TimeToSendPacket(ssrc, sequence_number, capture_time_ms,
Yves Gerey665174f2018-06-19 15:03:05 +0200416 retransmission, pacing_info);
stefan@webrtc.org508a84b2013-06-17 12:53:37 +0000417}
418
Erik Språng9c771c22019-06-17 16:31:53 +0200419bool ModuleRtpRtcpImpl::TrySendPacket(RtpPacketToSend* packet,
420 const PacedPacketInfo& pacing_info) {
421 return rtp_sender_->TrySendPacket(packet, pacing_info);
422}
423
philipelc7bf32a2017-02-17 03:59:43 -0800424size_t ModuleRtpRtcpImpl::TimeToSendPadding(
425 size_t bytes,
426 const PacedPacketInfo& pacing_info) {
nisse14adba72017-03-20 03:52:39 -0700427 return rtp_sender_->TimeToSendPadding(bytes, pacing_info);
pwestin@webrtc.org571a1c02012-11-13 21:12:39 +0000428}
429
Erik Språng478cb462019-06-26 15:49:27 +0200430void ModuleRtpRtcpImpl::GeneratePadding(size_t target_size_bytes) {
431 rtp_sender_->GeneratePadding(target_size_bytes);
432}
433
nisse284542b2017-01-10 08:58:32 -0800434size_t ModuleRtpRtcpImpl::MaxRtpPacketSize() const {
nisse14adba72017-03-20 03:52:39 -0700435 return rtp_sender_->MaxRtpPacketSize();
niklase@google.com470e71d2011-07-07 08:21:25 +0000436}
437
nisse284542b2017-01-10 08:58:32 -0800438void ModuleRtpRtcpImpl::SetMaxRtpPacketSize(size_t rtp_packet_size) {
439 RTC_DCHECK_LE(rtp_packet_size, IP_PACKET_SIZE)
440 << "rtp packet size too large: " << rtp_packet_size;
441 RTC_DCHECK_GT(rtp_packet_size, packet_overhead_)
442 << "rtp packet size too small: " << rtp_packet_size;
niklase@google.com470e71d2011-07-07 08:21:25 +0000443
nisse284542b2017-01-10 08:58:32 -0800444 rtcp_sender_.SetMaxRtpPacketSize(rtp_packet_size);
nisse14adba72017-03-20 03:52:39 -0700445 if (rtp_sender_)
446 rtp_sender_->SetMaxRtpPacketSize(rtp_packet_size);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000447}
448
pbosda903ea2015-10-02 02:36:56 -0700449RtcpMode ModuleRtpRtcpImpl::RTCP() const {
Taylor Brandstetter5f0b83b2016-03-18 15:02:07 -0700450 return rtcp_sender_.Status();
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000451}
452
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000453// Configure RTCP status i.e on/off.
pbosda903ea2015-10-02 02:36:56 -0700454void ModuleRtpRtcpImpl::SetRTCPStatus(const RtcpMode method) {
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000455 rtcp_sender_.SetRTCPStatus(method);
niklase@google.com470e71d2011-07-07 08:21:25 +0000456}
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000457
Peter Boström9ba52f82015-06-01 14:12:28 +0200458int32_t ModuleRtpRtcpImpl::SetCNAME(const char* c_name) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000459 return rtcp_sender_.SetCNAME(c_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000460}
461
Erik Språng0ea42d32015-06-25 14:46:16 +0200462int32_t ModuleRtpRtcpImpl::AddMixedCNAME(uint32_t ssrc, const char* c_name) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000463 return rtcp_sender_.AddMixedCNAME(ssrc, c_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000464}
465
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000466int32_t ModuleRtpRtcpImpl::RemoveMixedCNAME(const uint32_t ssrc) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000467 return rtcp_sender_.RemoveMixedCNAME(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000468}
469
Yves Gerey665174f2018-06-19 15:03:05 +0200470int32_t ModuleRtpRtcpImpl::RemoteCNAME(const uint32_t remote_ssrc,
471 char c_name[RTCP_CNAME_SIZE]) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000472 return rtcp_receiver_.CNAME(remote_ssrc, c_name);
niklase@google.com470e71d2011-07-07 08:21:25 +0000473}
474
Yves Gerey665174f2018-06-19 15:03:05 +0200475int32_t ModuleRtpRtcpImpl::RemoteNTP(uint32_t* received_ntpsecs,
476 uint32_t* received_ntpfrac,
477 uint32_t* rtcp_arrival_time_secs,
478 uint32_t* rtcp_arrival_time_frac,
479 uint32_t* rtcp_timestamp) const {
480 return rtcp_receiver_.NTP(received_ntpsecs, received_ntpfrac,
481 rtcp_arrival_time_secs, rtcp_arrival_time_frac,
pbos@webrtc.org376b4ea2014-07-15 15:51:33 +0000482 rtcp_timestamp)
483 ? 0
484 : -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000485}
486
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000487// Get RoundTripTime.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000488int32_t ModuleRtpRtcpImpl::RTT(const uint32_t remote_ssrc,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000489 int64_t* rtt,
490 int64_t* avg_rtt,
491 int64_t* min_rtt,
492 int64_t* max_rtt) const {
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000493 int32_t ret = rtcp_receiver_.RTT(remote_ssrc, rtt, avg_rtt, min_rtt, max_rtt);
494 if (rtt && *rtt == 0) {
495 // Try to get RTT from RtcpRttStats class.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000496 *rtt = rtt_ms();
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000497 }
498 return ret;
niklase@google.com470e71d2011-07-07 08:21:25 +0000499}
500
Niels Möller5fe95102019-03-04 16:49:25 +0100501int64_t ModuleRtpRtcpImpl::ExpectedRetransmissionTimeMs() const {
502 int64_t expected_retransmission_time_ms = rtt_ms();
503 if (expected_retransmission_time_ms > 0) {
504 return expected_retransmission_time_ms;
505 }
506 // No rtt available (|kRtpRtcpRttProcessTimeMs| not yet passed?), so try to
507 // poll avg_rtt_ms directly from rtcp receiver.
508 if (rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), nullptr,
509 &expected_retransmission_time_ms, nullptr,
510 nullptr) == 0) {
511 return expected_retransmission_time_ms;
512 }
513 return kDefaultExpectedRetransmissionTimeMs;
514}
515
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000516// Force a send of an RTCP packet.
517// Normal SR and RR are triggered via the process function.
Erik Språng242e22b2015-05-11 10:17:43 +0200518int32_t ModuleRtpRtcpImpl::SendRTCP(RTCPPacketType packet_type) {
519 return rtcp_sender_.SendRTCP(GetFeedbackState(), packet_type);
520}
521
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000522int32_t ModuleRtpRtcpImpl::SetRTCPApplicationSpecificData(
523 const uint8_t sub_type,
524 const uint32_t name,
525 const uint8_t* data,
526 const uint16_t length) {
Yves Gerey665174f2018-06-19 15:03:05 +0200527 return rtcp_sender_.SetApplicationSpecificData(sub_type, name, data, length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000528}
529
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000530void ModuleRtpRtcpImpl::SetRtcpXrRrtrStatus(bool enable) {
Danil Chapovalovc1e55c72016-03-09 15:14:35 +0100531 rtcp_receiver_.SetRtcpXrRrtrStatus(enable);
532 rtcp_sender_.SendRtcpXrReceiverReferenceTime(enable);
asapersson@webrtc.org7d6bd222013-10-31 12:14:34 +0000533}
534
asapersson@webrtc.org8d02f5d2013-11-21 08:57:04 +0000535bool ModuleRtpRtcpImpl::RtcpXrRrtrStatus() const {
536 return rtcp_sender_.RtcpXrReceiverReferenceTime();
537}
538
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000539// TODO(asapersson): Replace this method with the one below.
Yves Gerey665174f2018-06-19 15:03:05 +0200540int32_t ModuleRtpRtcpImpl::DataCountersRTP(size_t* bytes_sent,
541 uint32_t* packets_sent) const {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000542 StreamDataCounters rtp_stats;
543 StreamDataCounters rtx_stats;
nisse14adba72017-03-20 03:52:39 -0700544 rtp_sender_->GetDataCounters(&rtp_stats, &rtx_stats);
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000545
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000546 if (bytes_sent) {
Henrik Boströmcf96e0f2019-04-17 13:51:53 +0200547 // TODO(http://crbug.com/webrtc/10525): Bytes sent should only include
548 // payload bytes, not header and padding bytes.
asapersson@webrtc.orgcfd82df2015-01-22 09:39:59 +0000549 *bytes_sent = rtp_stats.transmitted.payload_bytes +
550 rtp_stats.transmitted.padding_bytes +
551 rtp_stats.transmitted.header_bytes +
552 rtx_stats.transmitted.payload_bytes +
553 rtx_stats.transmitted.padding_bytes +
554 rtx_stats.transmitted.header_bytes;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000555 }
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000556 if (packets_sent) {
Yves Gerey665174f2018-06-19 15:03:05 +0200557 *packets_sent =
558 rtp_stats.transmitted.packets + rtx_stats.transmitted.packets;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000559 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000560 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000561}
562
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000563void ModuleRtpRtcpImpl::GetSendStreamDataCounters(
564 StreamDataCounters* rtp_counters,
565 StreamDataCounters* rtx_counters) const {
nisse14adba72017-03-20 03:52:39 -0700566 rtp_sender_->GetDataCounters(rtp_counters, rtx_counters);
asapersson@webrtc.org97d04892014-12-09 09:47:53 +0000567}
568
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000569// Received RTCP report.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000570int32_t ModuleRtpRtcpImpl::RemoteRTCPStat(
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000571 std::vector<RTCPReportBlock>* receive_blocks) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000572 return rtcp_receiver_.StatisticsReceived(receive_blocks);
niklase@google.com470e71d2011-07-07 08:21:25 +0000573}
574
Henrik Boström6e436d12019-05-27 12:19:33 +0200575std::vector<ReportBlockData> ModuleRtpRtcpImpl::GetLatestReportBlockData()
576 const {
577 return rtcp_receiver_.GetLatestReportBlockData();
578}
579
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000580// (REMB) Receiver Estimated Max Bitrate.
Danil Chapovalov1de4b622017-12-13 13:35:10 +0100581void ModuleRtpRtcpImpl::SetRemb(int64_t bitrate_bps,
582 std::vector<uint32_t> ssrcs) {
583 rtcp_sender_.SetRemb(bitrate_bps, std::move(ssrcs));
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000584}
585
Danil Chapovalov51e21aa2017-10-10 17:46:26 +0200586void ModuleRtpRtcpImpl::UnsetRemb() {
Danil Chapovalovf74d6412017-10-18 13:32:57 +0200587 rtcp_sender_.UnsetRemb();
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000588}
589
Johannes Kron9190b822018-10-29 11:22:05 +0100590void ModuleRtpRtcpImpl::SetExtmapAllowMixed(bool extmap_allow_mixed) {
591 rtp_sender_->SetExtmapAllowMixed(extmap_allow_mixed);
592}
593
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000594int32_t ModuleRtpRtcpImpl::RegisterSendRtpHeaderExtension(
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000595 const RTPExtensionType type,
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000596 const uint8_t id) {
nisse14adba72017-03-20 03:52:39 -0700597 return rtp_sender_->RegisterRtpHeaderExtension(type, id);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000598}
599
Danil Chapovalov585d1aa2018-09-14 18:29:32 +0200600bool ModuleRtpRtcpImpl::RegisterRtpHeaderExtension(const std::string& uri,
601 int id) {
602 return rtp_sender_->RegisterRtpHeaderExtension(uri, id);
603}
604
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000605int32_t ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension(
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000606 const RTPExtensionType type) {
nisse14adba72017-03-20 03:52:39 -0700607 return rtp_sender_->DeregisterRtpHeaderExtension(type);
asapersson@webrtc.org5249cc82011-12-16 14:31:37 +0000608}
609
stefan53b6cc32017-02-03 08:13:57 -0800610bool ModuleRtpRtcpImpl::HasBweExtensions() const {
nisse14adba72017-03-20 03:52:39 -0700611 return rtp_sender_->IsRtpHeaderExtensionRegistered(
stefan53b6cc32017-02-03 08:13:57 -0800612 kRtpExtensionTransportSequenceNumber) ||
nisse14adba72017-03-20 03:52:39 -0700613 rtp_sender_->IsRtpHeaderExtensionRegistered(
stefan53b6cc32017-02-03 08:13:57 -0800614 kRtpExtensionAbsoluteSendTime) ||
nisse14adba72017-03-20 03:52:39 -0700615 rtp_sender_->IsRtpHeaderExtensionRegistered(
stefan53b6cc32017-02-03 08:13:57 -0800616 kRtpExtensionTransmissionTimeOffset);
617}
618
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000619// (TMMBR) Temporary Max Media Bit Rate.
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000620bool ModuleRtpRtcpImpl::TMMBR() const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000621 return rtcp_sender_.TMMBR();
niklase@google.com470e71d2011-07-07 08:21:25 +0000622}
623
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000624void ModuleRtpRtcpImpl::SetTMMBRStatus(const bool enable) {
625 rtcp_sender_.SetTMMBRStatus(enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000626}
627
danilchap853ecb22016-08-22 08:26:15 -0700628void ModuleRtpRtcpImpl::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) {
629 rtcp_sender_.SetTmmbn(std::move(bounding_set));
niklase@google.com470e71d2011-07-07 08:21:25 +0000630}
631
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000632// Send a Negative acknowledgment packet.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000633int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list,
634 const uint16_t size) {
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000635 uint16_t nack_length = size;
636 uint16_t start_id = 0;
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +0100637 int64_t now_ms = clock_->TimeInMilliseconds();
638 if (TimeToSendFullNackList(now_ms)) {
639 nack_last_time_sent_full_ms_ = now_ms;
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000640 } else {
641 // Only send extended list.
642 if (nack_last_seq_number_sent_ == nack_list[size - 1]) {
643 // Last sequence number is the same, do not send list.
644 return 0;
645 }
646 // Send new sequence numbers.
647 for (int i = 0; i < size; ++i) {
648 if (nack_last_seq_number_sent_ == nack_list[i]) {
649 start_id = i + 1;
650 break;
651 }
652 }
653 nack_length = size - start_id;
654 }
655
656 // Our RTCP NACK implementation is limited to kRtcpMaxNackFields sequence
657 // numbers per RTCP packet.
658 if (nack_length > kRtcpMaxNackFields) {
659 nack_length = kRtcpMaxNackFields;
660 }
661 nack_last_seq_number_sent_ = nack_list[start_id + nack_length - 1];
662
philipel83f831a2016-03-12 03:30:23 -0800663 return rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, nack_length,
664 &nack_list[start_id]);
665}
666
667void ModuleRtpRtcpImpl::SendNack(
668 const std::vector<uint16_t>& sequence_numbers) {
669 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, sequence_numbers.size(),
670 sequence_numbers.data());
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000671}
672
673bool ModuleRtpRtcpImpl::TimeToSendFullNackList(int64_t now) const {
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000674 // Use RTT from RtcpRttStats class if provided.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000675 int64_t rtt = rtt_ms();
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000676 if (rtt == 0) {
677 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
678 }
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000679
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000680 const int64_t kStartUpRttMs = 100;
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000681 int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5.
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000682 if (rtt == 0) {
683 wait_time = kStartUpRttMs;
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000684 }
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000685
asapersson@webrtc.orgba8138b2014-12-08 13:29:02 +0000686 // Send a full NACK list once within every |wait_time|.
Danil Chapovalov9eb6ce12017-12-15 12:25:01 +0100687 return now - nack_last_time_sent_full_ms_ > wait_time;
niklase@google.com470e71d2011-07-07 08:21:25 +0000688}
689
asapersson@webrtc.org9ffd8fe2015-01-21 08:22:50 +0000690// Store the sent packets, needed to answer to Negative acknowledgment requests.
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000691void ModuleRtpRtcpImpl::SetStorePacketsStatus(const bool enable,
692 const uint16_t number_to_store) {
nisse14adba72017-03-20 03:52:39 -0700693 rtp_sender_->SetStorePacketsStatus(enable, number_to_store);
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000694}
niklase@google.com470e71d2011-07-07 08:21:25 +0000695
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000696bool ModuleRtpRtcpImpl::StorePackets() const {
nisse14adba72017-03-20 03:52:39 -0700697 return rtp_sender_->StorePackets();
tnakamura@webrtc.orgaa4d96a2013-07-16 19:25:04 +0000698}
699
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000700void ModuleRtpRtcpImpl::RegisterRtcpStatisticsCallback(
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000701 RtcpStatisticsCallback* callback) {
702 rtcp_receiver_.RegisterRtcpStatisticsCallback(callback);
703}
704
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000705RtcpStatisticsCallback* ModuleRtpRtcpImpl::GetRtcpStatisticsCallback() {
sprang@webrtc.orga6ad6e52013-12-05 09:48:44 +0000706 return rtcp_receiver_.GetRtcpStatisticsCallback();
707}
708
Henrik Boström87e3f9d2019-05-27 10:44:24 +0200709void ModuleRtpRtcpImpl::SetReportBlockDataObserver(
710 ReportBlockDataObserver* observer) {
711 return rtcp_receiver_.SetReportBlockDataObserver(observer);
712}
713
sprang233bd872015-09-08 13:25:16 -0700714bool ModuleRtpRtcpImpl::SendFeedbackPacket(
715 const rtcp::TransportFeedback& packet) {
716 return rtcp_sender_.SendFeedbackPacket(packet);
717}
718
Elad Alon7d6a4c02019-02-25 13:00:51 +0100719int32_t ModuleRtpRtcpImpl::SendLossNotification(uint16_t last_decoded_seq_num,
720 uint16_t last_received_seq_num,
Elad Alone86af2c2019-06-03 14:37:50 +0200721 bool decodability_flag,
722 bool buffering_allowed) {
Elad Alon7d6a4c02019-02-25 13:00:51 +0100723 return rtcp_sender_.SendLossNotification(
724 GetFeedbackState(), last_decoded_seq_num, last_received_seq_num,
Elad Alone86af2c2019-06-03 14:37:50 +0200725 decodability_flag, buffering_allowed);
Elad Alon7d6a4c02019-02-25 13:00:51 +0100726}
727
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000728void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000729 // Inform about the incoming SSRC.
730 rtcp_sender_.SetRemoteSSRC(ssrc);
731 rtcp_receiver_.SetRemoteSSRC(ssrc);
niklase@google.com470e71d2011-07-07 08:21:25 +0000732}
733
Niels Möller5fe95102019-03-04 16:49:25 +0100734// TODO(nisse): Delete video_rate amd fec_rate arguments.
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000735void ModuleRtpRtcpImpl::BitrateSent(uint32_t* total_rate,
736 uint32_t* video_rate,
737 uint32_t* fec_rate,
738 uint32_t* nack_rate) const {
nisse14adba72017-03-20 03:52:39 -0700739 *total_rate = rtp_sender_->BitrateSent();
Niels Möller5fe95102019-03-04 16:49:25 +0100740 if (video_rate)
741 *video_rate = 0;
742 if (fec_rate)
743 *fec_rate = 0;
nisse14adba72017-03-20 03:52:39 -0700744 *nack_rate = rtp_sender_->NackOverheadRate();
niklase@google.com470e71d2011-07-07 08:21:25 +0000745}
746
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000747void ModuleRtpRtcpImpl::OnRequestSendReport() {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000748 SendRTCP(kRtcpSr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000749}
750
Danil Chapovalov2800d742016-08-26 18:48:46 +0200751void ModuleRtpRtcpImpl::OnReceivedNack(
752 const std::vector<uint16_t>& nack_sequence_numbers) {
nisse14adba72017-03-20 03:52:39 -0700753 if (!rtp_sender_)
754 return;
755
Yves Gerey665174f2018-06-19 15:03:05 +0200756 if (!rtp_sender_->StorePackets() || nack_sequence_numbers.size() == 0) {
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000757 return;
758 }
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000759 // Use RTT from RtcpRttStats class if provided.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000760 int64_t rtt = rtt_ms();
asapersson@webrtc.orge7b1e112013-12-16 14:40:36 +0000761 if (rtt == 0) {
762 rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
763 }
nisse14adba72017-03-20 03:52:39 -0700764 rtp_sender_->OnReceivedNack(nack_sequence_numbers, rtt);
niklase@google.com470e71d2011-07-07 08:21:25 +0000765}
766
isheriff6b4b5f32016-06-08 00:24:21 -0700767void ModuleRtpRtcpImpl::OnReceivedRtcpReportBlocks(
768 const ReportBlockList& report_blocks) {
Niels Möller5fe95102019-03-04 16:49:25 +0100769 if (ack_observer_) {
Niels Möller59ab1cf2019-02-06 22:48:11 +0100770 uint32_t ssrc = SSRC();
771
772 for (const RTCPReportBlock& report_block : report_blocks) {
773 if (ssrc == report_block.source_ssrc) {
Niels Möller5fe95102019-03-04 16:49:25 +0100774 ack_observer_->OnReceivedAck(
775 report_block.extended_highest_sequence_number);
Niels Möller59ab1cf2019-02-06 22:48:11 +0100776 }
777 }
778 }
isheriff6b4b5f32016-06-08 00:24:21 -0700779}
780
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000781bool ModuleRtpRtcpImpl::LastReceivedNTP(
782 uint32_t* rtcp_arrival_time_secs, // When we got the last report.
783 uint32_t* rtcp_arrival_time_frac,
784 uint32_t* remote_sr) const {
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000785 // Remote SR: NTP inside the last received (mid 16 bits from sec and frac).
pbos@webrtc.org2f446732013-04-08 11:08:41 +0000786 uint32_t ntp_secs = 0;
787 uint32_t ntp_frac = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000788
Yves Gerey665174f2018-06-19 15:03:05 +0200789 if (!rtcp_receiver_.NTP(&ntp_secs, &ntp_frac, rtcp_arrival_time_secs,
790 rtcp_arrival_time_frac, NULL)) {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000791 return false;
henrike@webrtc.orgd5657c22012-02-08 23:41:49 +0000792 }
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +0000793 *remote_sr =
794 ((ntp_secs & 0x0000ffff) << 16) + ((ntp_frac & 0xffff0000) >> 16);
795 return true;
niklase@google.com470e71d2011-07-07 08:21:25 +0000796}
797
phoglund@webrtc.orgacfdd962013-01-16 10:27:33 +0000798// Called from RTCPsender.
danilchap2b616392016-08-18 06:17:42 -0700799std::vector<rtcp::TmmbItem> ModuleRtpRtcpImpl::BoundingSet(bool* tmmbr_owner) {
800 return rtcp_receiver_.BoundingSet(tmmbr_owner);
niklase@google.com470e71d2011-07-07 08:21:25 +0000801}
mflodman@webrtc.org2f225ca2013-01-09 13:54:43 +0000802
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000803void ModuleRtpRtcpImpl::SetRtcpReceiverSsrcs(uint32_t main_ssrc) {
804 std::set<uint32_t> ssrcs;
805 ssrcs.insert(main_ssrc);
nisse14adba72017-03-20 03:52:39 -0700806 if (RtxSendStatus() != kRtxOff)
807 ssrcs.insert(rtp_sender_->RtxSsrc());
Danil Chapovalovd264df52018-06-14 12:59:38 +0200808 absl::optional<uint32_t> flexfec_ssrc = FlexfecSsrc();
brandtr7c7796b2017-07-03 06:02:53 -0700809 if (flexfec_ssrc)
810 ssrcs.insert(*flexfec_ssrc);
stefan@webrtc.org28a331e2013-09-17 07:49:56 +0000811 rtcp_receiver_.SetSsrcs(main_ssrc, ssrcs);
812}
813
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000814void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) {
danilchap7c9426c2016-04-14 03:05:31 -0700815 rtc::CritScope cs(&critical_section_rtt_);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000816 rtt_ms_ = rtt_ms;
Erik Språng8b101922018-01-18 11:58:05 -0800817 if (rtp_sender_)
818 rtp_sender_->SetRtt(rtt_ms);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000819}
820
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000821int64_t ModuleRtpRtcpImpl::rtt_ms() const {
danilchap7c9426c2016-04-14 03:05:31 -0700822 rtc::CritScope cs(&critical_section_rtt_);
asapersson@webrtc.org1ae1d0c2013-11-20 12:46:11 +0000823 return rtt_ms_;
824}
825
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000826void ModuleRtpRtcpImpl::RegisterSendChannelRtpStatisticsCallback(
827 StreamDataCountersCallback* callback) {
nisse14adba72017-03-20 03:52:39 -0700828 rtp_sender_->RegisterRtpStatisticsCallback(callback);
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000829}
830
831StreamDataCountersCallback*
Yves Gerey665174f2018-06-19 15:03:05 +0200832ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const {
nisse14adba72017-03-20 03:52:39 -0700833 return rtp_sender_->GetRtpStatisticsCallback();
sprang@webrtc.orgebad7652013-12-05 14:29:02 +0000834}
sprang5e38c962016-12-01 05:18:09 -0800835
836void ModuleRtpRtcpImpl::SetVideoBitrateAllocation(
Erik Språng566124a2018-04-23 12:32:22 +0200837 const VideoBitrateAllocation& bitrate) {
sprang5e38c962016-12-01 05:18:09 -0800838 rtcp_sender_.SetVideoBitrateAllocation(bitrate);
839}
Niels Möller5fe95102019-03-04 16:49:25 +0100840
841RTPSender* ModuleRtpRtcpImpl::RtpSender() {
842 return rtp_sender_.get();
843}
844
845const RTPSender* ModuleRtpRtcpImpl::RtpSender() const {
846 return rtp_sender_.get();
847}
848
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000849} // namespace webrtc