niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 +0000 | [diff] [blame] | 13 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 15 | #include <algorithm> |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 16 | #include <cstdint> |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 17 | #include <set> |
Peter Boström | 9c01725 | 2016-02-26 16:26:20 +0100 | [diff] [blame] | 18 | #include <string> |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 19 | #include <utility> |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 20 | |
Niels Möller | 59ab1cf | 2019-02-06 22:48:11 +0100 | [diff] [blame] | 21 | #include "absl/memory/memory.h" |
Per Kjellander | e11b7d2 | 2019-02-21 07:55:59 +0100 | [diff] [blame] | 22 | #include "api/transport/field_trial_based_config.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 23 | #include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h" |
| 24 | #include "modules/rtp_rtcp/source/rtp_rtcp_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "rtc_base/checks.h" |
| 26 | #include "rtc_base/logging.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | #ifdef _WIN32 |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 29 | // Disable warning C4355: 'this' : used in base member initializer list. |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 30 | #pragma warning(disable : 4355) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | namespace webrtc { |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 34 | namespace { |
| 35 | const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5; |
| 36 | const int64_t kRtpRtcpRttProcessTimeMs = 1000; |
| 37 | const int64_t kRtpRtcpBitrateProcessTimeMs = 10; |
sprang | a8ae6f2 | 2017-09-04 07:23:56 -0700 | [diff] [blame] | 38 | const int64_t kDefaultExpectedRetransmissionTimeMs = 125; |
Jiawei Ou | 8b5d9d8 | 2018-11-15 16:44:37 -0800 | [diff] [blame] | 39 | constexpr int32_t kDefaultVideoReportInterval = 1000; |
| 40 | constexpr int32_t kDefaultAudioReportInterval = 5000; |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 41 | } // namespace |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
danilchap | d3f3c34 | 2017-07-25 04:20:12 -0700 | [diff] [blame] | 43 | RtpRtcp::Configuration::Configuration() = default; |
Erik Språng | 4580ca2 | 2019-07-04 10:38:43 +0200 | [diff] [blame] | 44 | RtpRtcp::Configuration::Configuration(Configuration&& rhs) = default; |
phoglund@webrtc.org | a22a9bd | 2013-01-14 10:01:55 +0000 | [diff] [blame] | 45 | |
Danil Chapovalov | c44f6cc | 2019-03-06 11:31:09 +0100 | [diff] [blame] | 46 | std::unique_ptr<RtpRtcp> RtpRtcp::Create(const Configuration& configuration) { |
| 47 | RTC_DCHECK(configuration.clock); |
| 48 | return absl::make_unique<ModuleRtpRtcpImpl>(configuration); |
| 49 | } |
| 50 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 51 | RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) { |
| 52 | if (configuration.clock) { |
| 53 | return new ModuleRtpRtcpImpl(configuration); |
henrike@webrtc.org | f5da4da | 2012-02-15 23:54:59 +0000 | [diff] [blame] | 54 | } else { |
pbos@webrtc.org | 180e516 | 2014-07-11 15:36:26 +0000 | [diff] [blame] | 55 | // No clock implementation provided, use default clock. |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 56 | RtpRtcp::Configuration configuration_copy; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 57 | memcpy(&configuration_copy, &configuration, sizeof(RtpRtcp::Configuration)); |
stefan@webrtc.org | 20ed36d | 2013-01-17 14:01:20 +0000 | [diff] [blame] | 58 | configuration_copy.clock = Clock::GetRealTimeClock(); |
pbos@webrtc.org | 180e516 | 2014-07-11 15:36:26 +0000 | [diff] [blame] | 59 | return new ModuleRtpRtcpImpl(configuration_copy); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 60 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | } |
| 62 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 63 | ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration) |
Erik Språng | 6f420e4 | 2019-07-09 20:06:30 +0200 | [diff] [blame] | 64 | : rtcp_sender_(configuration), |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 65 | rtcp_receiver_(configuration.clock, |
Peter Boström | fe7a80c | 2015-04-23 17:53:17 +0200 | [diff] [blame] | 66 | configuration.receiver_only, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 67 | configuration.rtcp_packet_type_counter_observer, |
mflodman@webrtc.org | 96abda0 | 2015-02-25 13:50:10 +0000 | [diff] [blame] | 68 | configuration.bandwidth_callback, |
| 69 | configuration.intra_frame_callback, |
Elad Alon | 0a8562e | 2019-04-09 11:55:13 +0200 | [diff] [blame] | 70 | configuration.rtcp_loss_notification_observer, |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 71 | configuration.transport_feedback_callback, |
sprang | a790d83 | 2016-12-02 07:29:44 -0800 | [diff] [blame] | 72 | configuration.bitrate_allocation_observer, |
Jiawei Ou | 8b5d9d8 | 2018-11-15 16:44:37 -0800 | [diff] [blame] | 73 | configuration.rtcp_report_interval_ms > 0 |
| 74 | ? configuration.rtcp_report_interval_ms |
| 75 | : (configuration.audio ? kDefaultAudioReportInterval |
| 76 | : kDefaultVideoReportInterval), |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 77 | this), |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 78 | clock_(configuration.clock), |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 79 | last_bitrate_process_time_(clock_->TimeInMilliseconds()), |
| 80 | last_rtt_process_time_(clock_->TimeInMilliseconds()), |
| 81 | next_process_time_(clock_->TimeInMilliseconds() + |
| 82 | kRtpRtcpMaxIdleTimeProcessMs), |
asapersson | 35151f3 | 2016-05-02 23:44:01 -0700 | [diff] [blame] | 83 | packet_overhead_(28), // IPV4 UDP. |
Danil Chapovalov | 9eb6ce1 | 2017-12-15 12:25:01 +0100 | [diff] [blame] | 84 | nack_last_time_sent_full_ms_(0), |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 85 | nack_last_seq_number_sent_(0), |
mflodman@webrtc.org | 7c894b7 | 2012-11-26 12:40:15 +0000 | [diff] [blame] | 86 | remote_bitrate_(configuration.remote_bitrate_estimator), |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 87 | ack_observer_(configuration.ack_observer), |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 88 | rtt_stats_(configuration.rtt_stats), |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 89 | rtt_ms_(0) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 90 | if (!configuration.receiver_only) { |
Erik Språng | 4580ca2 | 2019-07-04 10:38:43 +0200 | [diff] [blame] | 91 | rtp_sender_.reset(new RTPSender(configuration)); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 92 | // Make sure rtcp sender use same timestamp offset as rtp sender. |
| 93 | rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset()); |
| 94 | } |
danilchap | 71fead2 | 2016-08-18 02:01:49 -0700 | [diff] [blame] | 95 | |
| 96 | // Set default packet size limit. |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 97 | // 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 103 | ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() = default; |
| 104 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 105 | // Returns the number of milliseconds until the module want a worker thread |
| 106 | // to call Process. |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 +0000 | [diff] [blame] | 107 | int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() { |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 108 | return std::max<int64_t>(0, |
| 109 | next_process_time_ - clock_->TimeInMilliseconds()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | } |
| 111 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 112 | // Process any pending tasks such as timeouts (non time critical events). |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 113 | void ModuleRtpRtcpImpl::Process() { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 114 | const int64_t now = clock_->TimeInMilliseconds(); |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 115 | next_process_time_ = now + kRtpRtcpMaxIdleTimeProcessMs; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 117 | if (rtp_sender_) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 118 | if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) { |
| 119 | rtp_sender_->ProcessBitrate(); |
| 120 | last_bitrate_process_time_ = now; |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 121 | next_process_time_ = |
| 122 | std::min(next_process_time_, now + kRtpRtcpBitrateProcessTimeMs); |
| 123 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 124 | } |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 125 | |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 126 | bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs; |
| 127 | if (rtcp_sender_.Sending()) { |
Danil Chapovalov | 760c4b4 | 2017-09-27 13:25:24 +0200 | [diff] [blame] | 128 | // Process RTT if we have received a report block and we haven't |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 129 | // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds. |
Danil Chapovalov | 760c4b4 | 2017-09-27 13:25:24 +0200 | [diff] [blame] | 130 | if (rtcp_receiver_.LastReceivedReportBlockMs() > last_rtt_process_time_ && |
| 131 | process_rtt) { |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 132 | 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; |
srte | 3e69e5c | 2017-08-09 06:13:45 -0700 | [diff] [blame] | 138 | rtcp_receiver_.RTT(it->sender_ssrc, &rtt, NULL, NULL, NULL); |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 139 | max_rtt = (rtt > max_rtt) ? rtt : max_rtt; |
mflodman@webrtc.org | d7d4688 | 2012-02-14 12:49:59 +0000 | [diff] [blame] | 140 | } |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 141 | // Report the rtt. |
| 142 | if (rtt_stats_ && max_rtt != 0) |
| 143 | rtt_stats_->OnRttUpdate(max_rtt); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 144 | } |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 145 | |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 146 | // Verify receiver reports are delivered and the reported sequence number |
| 147 | // is increasing. |
Jiawei Ou | 8b5d9d8 | 2018-11-15 16:44:37 -0800 | [diff] [blame] | 148 | if (rtcp_receiver_.RtcpRrTimeout()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 149 | RTC_LOG_F(LS_WARNING) << "Timeout: No RTCP RR received."; |
Jiawei Ou | 8b5d9d8 | 2018-11-15 16:44:37 -0800 | [diff] [blame] | 150 | } else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 151 | RTC_LOG_F(LS_WARNING) << "Timeout: No increase in RTCP RR extended " |
| 152 | "highest sequence number."; |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 153 | } |
| 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.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 167 | if (process_rtt) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 168 | int64_t rtt_ms; |
| 169 | if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) { |
| 170 | rtt_stats_->OnRttUpdate(rtt_ms); |
| 171 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 172 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 173 | } |
| 174 | |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 175 | // Get processed rtt. |
| 176 | if (process_rtt) { |
| 177 | last_rtt_process_time_ = now; |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 178 | next_process_time_ = std::min( |
| 179 | next_process_time_, last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs); |
sprang | e2d83d6 | 2016-02-19 09:03:26 -0800 | [diff] [blame] | 180 | 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.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Danil Chapovalov | 70ffead | 2016-07-20 15:26:59 +0200 | [diff] [blame] | 188 | if (rtcp_sender_.TimeToSendRTCPReport()) |
| 189 | rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport); |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 +0000 | [diff] [blame] | 190 | |
danilchap | 9bf610e | 2017-02-20 06:03:01 -0800 | [diff] [blame] | 191 | if (TMMBR() && rtcp_receiver_.UpdateTmmbrTimers()) { |
| 192 | rtcp_receiver_.NotifyTmmbrUpdated(); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 +0000 | [diff] [blame] | 193 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 194 | } |
| 195 | |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 +0000 | [diff] [blame] | 196 | void ModuleRtpRtcpImpl::SetRtxSendStatus(int mode) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 197 | rtp_sender_->SetRtxStatus(mode); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 198 | } |
| 199 | |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 +0000 | [diff] [blame] | 200 | int ModuleRtpRtcpImpl::RtxSendStatus() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 201 | return rtp_sender_ ? rtp_sender_->RtxStatus() : kRtxOff; |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | void ModuleRtpRtcpImpl::SetRtxSsrc(uint32_t ssrc) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 205 | rtp_sender_->SetRtxSsrc(ssrc); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 208 | void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type, |
| 209 | int associated_payload_type) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 210 | rtp_sender_->SetRtxPayloadType(payload_type, associated_payload_type); |
mflodman@webrtc.org | 9f5ebb5 | 2013-04-12 14:55:46 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Danil Chapovalov | d264df5 | 2018-06-14 12:59:38 +0200 | [diff] [blame] | 213 | absl::optional<uint32_t> ModuleRtpRtcpImpl::FlexfecSsrc() const { |
brandtr | 7c7796b | 2017-07-03 06:02:53 -0700 | [diff] [blame] | 214 | if (rtp_sender_) |
| 215 | return rtp_sender_->FlexfecSsrc(); |
Danil Chapovalov | d264df5 | 2018-06-14 12:59:38 +0200 | [diff] [blame] | 216 | return absl::nullopt; |
brandtr | 9dfff29 | 2016-11-14 05:14:50 -0800 | [diff] [blame] | 217 | } |
| 218 | |
nisse | 479d3d7 | 2017-09-13 07:53:37 -0700 | [diff] [blame] | 219 | void ModuleRtpRtcpImpl::IncomingRtcpPacket(const uint8_t* rtcp_packet, |
| 220 | const size_t length) { |
| 221 | rtcp_receiver_.IncomingPacket(rtcp_packet, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 224 | void ModuleRtpRtcpImpl::RegisterSendPayloadFrequency(int payload_type, |
| 225 | int payload_frequency) { |
| 226 | rtcp_sender_.SetRtpClockRate(payload_type, payload_frequency); |
Peter Boström | 8b79b07 | 2016-02-26 16:31:37 +0100 | [diff] [blame] | 227 | } |
| 228 | |
asapersson@webrtc.org | 9ffd8fe | 2015-01-21 08:22:50 +0000 | [diff] [blame] | 229 | int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload(const int8_t payload_type) { |
Niels Möller | 59ab1cf | 2019-02-06 22:48:11 +0100 | [diff] [blame] | 230 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 231 | } |
| 232 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 233 | uint32_t ModuleRtpRtcpImpl::StartTimestamp() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 234 | return rtp_sender_->TimestampOffset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 235 | } |
| 236 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 237 | // Configure start timestamp, default is a random number. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 238 | void ModuleRtpRtcpImpl::SetStartTimestamp(const uint32_t timestamp) { |
danilchap | 71fead2 | 2016-08-18 02:01:49 -0700 | [diff] [blame] | 239 | rtcp_sender_.SetTimestampOffset(timestamp); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 240 | rtp_sender_->SetTimestampOffset(timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 241 | } |
| 242 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 243 | uint16_t ModuleRtpRtcpImpl::SequenceNumber() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 244 | return rtp_sender_->SequenceNumber(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 245 | } |
| 246 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 247 | // Set SequenceNumber, default is a random number. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 248 | void ModuleRtpRtcpImpl::SetSequenceNumber(const uint16_t seq_num) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 249 | rtp_sender_->SetSequenceNumber(seq_num); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 252 | void ModuleRtpRtcpImpl::SetRtpState(const RtpState& rtp_state) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 253 | rtp_sender_->SetRtpState(rtp_state); |
danilchap | 71fead2 | 2016-08-18 02:01:49 -0700 | [diff] [blame] | 254 | rtcp_sender_.SetTimestampOffset(rtp_state.start_timestamp); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 257 | void ModuleRtpRtcpImpl::SetRtxState(const RtpState& rtp_state) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 258 | rtp_sender_->SetRtxRtpState(rtp_state); |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | RtpState ModuleRtpRtcpImpl::GetRtpState() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 262 | return rtp_sender_->GetRtpState(); |
Per | 83d0910 | 2016-04-15 14:59:13 +0200 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | RtpState ModuleRtpRtcpImpl::GetRtxState() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 266 | return rtp_sender_->GetRtxRtpState(); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 267 | } |
| 268 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 269 | uint32_t ModuleRtpRtcpImpl::SSRC() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 270 | return rtcp_sender_.SSRC(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 271 | } |
| 272 | |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 +0000 | [diff] [blame] | 273 | void ModuleRtpRtcpImpl::SetSSRC(const uint32_t ssrc) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 274 | if (rtp_sender_) { |
| 275 | rtp_sender_->SetSSRC(ssrc); |
| 276 | } |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 277 | rtcp_sender_.SetSSRC(ssrc); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 278 | SetRtcpReceiverSsrcs(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Amit Hilbuch | 77938e6 | 2018-12-21 09:23:38 -0800 | [diff] [blame] | 281 | void ModuleRtpRtcpImpl::SetRid(const std::string& rid) { |
| 282 | if (rtp_sender_) { |
| 283 | rtp_sender_->SetRid(rid); |
| 284 | } |
| 285 | } |
| 286 | |
Steve Anton | 296a0ce | 2018-03-22 15:17:27 -0700 | [diff] [blame] | 287 | void 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.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 295 | void ModuleRtpRtcpImpl::SetCsrcs(const std::vector<uint32_t>& csrcs) { |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 +0000 | [diff] [blame] | 296 | rtcp_sender_.SetCsrcs(csrcs); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 297 | rtp_sender_->SetCsrcs(csrcs); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 298 | } |
| 299 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 300 | // TODO(pbos): Handle media and RTX streams separately (separate RTCP |
| 301 | // feedbacks). |
| 302 | RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() { |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 303 | RTCPSender::FeedbackState state; |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 304 | // 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 310 | state.packets_sent = |
| 311 | rtp_stats.transmitted.packets + rtx_stats.transmitted.packets; |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 312 | 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.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 316 | state.module = this; |
| 317 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 318 | LastReceivedNTP(&state.last_rr_ntp_secs, &state.last_rr_ntp_frac, |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 319 | &state.remote_sr); |
| 320 | |
Mirta Dvornicic | b1f063d | 2018-04-16 11:16:21 +0200 | [diff] [blame] | 321 | state.last_xr_rtis = rtcp_receiver_.ConsumeReceivedXrReferenceTimeInfo(); |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 322 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 323 | return state; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 324 | } |
| 325 | |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 326 | // 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.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 329 | int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 330 | if (rtcp_sender_.Sending() != sending) { |
| 331 | // Sends RTCP BYE when going from true to false |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 332 | if (rtcp_sender_.SetSendingStatus(GetFeedbackState(), sending) != 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 333 | RTC_LOG(LS_WARNING) << "Failed to send RTCP BYE"; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 334 | } |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 335 | if (sending && rtp_sender_) { |
nisse | 7d59f6b | 2017-02-21 03:40:24 -0800 | [diff] [blame] | 336 | // Update Rtcp receiver config, to track Rtx config changes from |
| 337 | // the SetRtxStatus and SetRtxSsrc methods. |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 338 | SetRtcpReceiverSsrcs(rtp_sender_->SSRC()); |
nisse | 7d59f6b | 2017-02-21 03:40:24 -0800 | [diff] [blame] | 339 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 340 | } |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | bool ModuleRtpRtcpImpl::Sending() const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 345 | return rtcp_sender_.Sending(); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 346 | } |
| 347 | |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 348 | // 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.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 351 | void ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 352 | if (rtp_sender_) { |
| 353 | rtp_sender_->SetSendingMediaStatus(sending); |
| 354 | } else { |
| 355 | RTC_DCHECK(!sending); |
| 356 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | bool ModuleRtpRtcpImpl::SendingMedia() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 360 | return rtp_sender_ ? rtp_sender_->SendingMedia() : false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Sebastian Jansson | 1bca65b | 2018-10-10 09:58:08 +0200 | [diff] [blame] | 363 | void ModuleRtpRtcpImpl::SetAsPartOfAllocation(bool part_of_allocation) { |
| 364 | RTC_CHECK(rtp_sender_); |
| 365 | rtp_sender_->SetAsPartOfAllocation(part_of_allocation); |
| 366 | } |
| 367 | |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 368 | bool 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Erik Språng | d287962 | 2019-05-10 08:29:01 -0700 | [diff] [blame] | 383 | RtpPacketSendResult 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) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 389 | return rtp_sender_->TimeToSendPacket(ssrc, sequence_number, capture_time_ms, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 390 | retransmission, pacing_info); |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Erik Språng | 9c771c2 | 2019-06-17 16:31:53 +0200 | [diff] [blame] | 393 | bool ModuleRtpRtcpImpl::TrySendPacket(RtpPacketToSend* packet, |
| 394 | const PacedPacketInfo& pacing_info) { |
| 395 | return rtp_sender_->TrySendPacket(packet, pacing_info); |
| 396 | } |
| 397 | |
Erik Språng | 6f129b3 | 2019-07-11 13:01:58 +0200 | [diff] [blame^] | 398 | bool ModuleRtpRtcpImpl::SupportsPadding() const { |
| 399 | return rtp_sender_->SupportsPadding(); |
| 400 | } |
| 401 | |
| 402 | bool ModuleRtpRtcpImpl::SupportsRtxPayloadPadding() const { |
| 403 | return rtp_sender_->SupportsRtxPayloadPadding(); |
| 404 | } |
| 405 | |
philipel | c7bf32a | 2017-02-17 03:59:43 -0800 | [diff] [blame] | 406 | size_t ModuleRtpRtcpImpl::TimeToSendPadding( |
| 407 | size_t bytes, |
| 408 | const PacedPacketInfo& pacing_info) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 409 | return rtp_sender_->TimeToSendPadding(bytes, pacing_info); |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Erik Språng | f6468d2 | 2019-07-05 16:53:43 +0200 | [diff] [blame] | 412 | std::vector<std::unique_ptr<RtpPacketToSend>> |
| 413 | ModuleRtpRtcpImpl::GeneratePadding(size_t target_size_bytes) { |
| 414 | return rtp_sender_->GeneratePadding(target_size_bytes); |
Erik Språng | 478cb46 | 2019-06-26 15:49:27 +0200 | [diff] [blame] | 415 | } |
| 416 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 417 | size_t ModuleRtpRtcpImpl::MaxRtpPacketSize() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 418 | return rtp_sender_->MaxRtpPacketSize(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 419 | } |
| 420 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 421 | void 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 426 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 427 | rtcp_sender_.SetMaxRtpPacketSize(rtp_packet_size); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 428 | if (rtp_sender_) |
| 429 | rtp_sender_->SetMaxRtpPacketSize(rtp_packet_size); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 430 | } |
| 431 | |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 432 | RtcpMode ModuleRtpRtcpImpl::RTCP() const { |
Taylor Brandstetter | 5f0b83b | 2016-03-18 15:02:07 -0700 | [diff] [blame] | 433 | return rtcp_sender_.Status(); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 434 | } |
| 435 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 436 | // Configure RTCP status i.e on/off. |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 437 | void ModuleRtpRtcpImpl::SetRTCPStatus(const RtcpMode method) { |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 438 | rtcp_sender_.SetRTCPStatus(method); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 439 | } |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 440 | |
Peter Boström | 9ba52f8 | 2015-06-01 14:12:28 +0200 | [diff] [blame] | 441 | int32_t ModuleRtpRtcpImpl::SetCNAME(const char* c_name) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 442 | return rtcp_sender_.SetCNAME(c_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Erik Språng | 0ea42d3 | 2015-06-25 14:46:16 +0200 | [diff] [blame] | 445 | int32_t ModuleRtpRtcpImpl::AddMixedCNAME(uint32_t ssrc, const char* c_name) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 446 | return rtcp_sender_.AddMixedCNAME(ssrc, c_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 447 | } |
| 448 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 449 | int32_t ModuleRtpRtcpImpl::RemoveMixedCNAME(const uint32_t ssrc) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 450 | return rtcp_sender_.RemoveMixedCNAME(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 453 | int32_t ModuleRtpRtcpImpl::RemoteCNAME(const uint32_t remote_ssrc, |
| 454 | char c_name[RTCP_CNAME_SIZE]) const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 455 | return rtcp_receiver_.CNAME(remote_ssrc, c_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 458 | int32_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.org | 376b4ea | 2014-07-15 15:51:33 +0000 | [diff] [blame] | 465 | rtcp_timestamp) |
| 466 | ? 0 |
| 467 | : -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 468 | } |
| 469 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 470 | // Get RoundTripTime. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 471 | int32_t ModuleRtpRtcpImpl::RTT(const uint32_t remote_ssrc, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 472 | int64_t* rtt, |
| 473 | int64_t* avg_rtt, |
| 474 | int64_t* min_rtt, |
| 475 | int64_t* max_rtt) const { |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 476 | 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.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 479 | *rtt = rtt_ms(); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 480 | } |
| 481 | return ret; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 484 | int64_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.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 499 | // Force a send of an RTCP packet. |
| 500 | // Normal SR and RR are triggered via the process function. |
Erik Språng | 242e22b | 2015-05-11 10:17:43 +0200 | [diff] [blame] | 501 | int32_t ModuleRtpRtcpImpl::SendRTCP(RTCPPacketType packet_type) { |
| 502 | return rtcp_sender_.SendRTCP(GetFeedbackState(), packet_type); |
| 503 | } |
| 504 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 505 | int32_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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 510 | return rtcp_sender_.SetApplicationSpecificData(sub_type, name, data, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 511 | } |
| 512 | |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 513 | void ModuleRtpRtcpImpl::SetRtcpXrRrtrStatus(bool enable) { |
Danil Chapovalov | c1e55c7 | 2016-03-09 15:14:35 +0100 | [diff] [blame] | 514 | rtcp_receiver_.SetRtcpXrRrtrStatus(enable); |
| 515 | rtcp_sender_.SendRtcpXrReceiverReferenceTime(enable); |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 +0000 | [diff] [blame] | 516 | } |
| 517 | |
asapersson@webrtc.org | 8d02f5d | 2013-11-21 08:57:04 +0000 | [diff] [blame] | 518 | bool ModuleRtpRtcpImpl::RtcpXrRrtrStatus() const { |
| 519 | return rtcp_sender_.RtcpXrReceiverReferenceTime(); |
| 520 | } |
| 521 | |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 522 | // TODO(asapersson): Replace this method with the one below. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 523 | int32_t ModuleRtpRtcpImpl::DataCountersRTP(size_t* bytes_sent, |
| 524 | uint32_t* packets_sent) const { |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 525 | StreamDataCounters rtp_stats; |
| 526 | StreamDataCounters rtx_stats; |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 527 | rtp_sender_->GetDataCounters(&rtp_stats, &rtx_stats); |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 528 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 529 | if (bytes_sent) { |
Henrik Boström | cf96e0f | 2019-04-17 13:51:53 +0200 | [diff] [blame] | 530 | // TODO(http://crbug.com/webrtc/10525): Bytes sent should only include |
| 531 | // payload bytes, not header and padding bytes. |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 532 | *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.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 538 | } |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 539 | if (packets_sent) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 540 | *packets_sent = |
| 541 | rtp_stats.transmitted.packets + rtx_stats.transmitted.packets; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 542 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 543 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 544 | } |
| 545 | |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 546 | void ModuleRtpRtcpImpl::GetSendStreamDataCounters( |
| 547 | StreamDataCounters* rtp_counters, |
| 548 | StreamDataCounters* rtx_counters) const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 549 | rtp_sender_->GetDataCounters(rtp_counters, rtx_counters); |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 550 | } |
| 551 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 552 | // Received RTCP report. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 553 | int32_t ModuleRtpRtcpImpl::RemoteRTCPStat( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 554 | std::vector<RTCPReportBlock>* receive_blocks) const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 555 | return rtcp_receiver_.StatisticsReceived(receive_blocks); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Henrik Boström | 6e436d1 | 2019-05-27 12:19:33 +0200 | [diff] [blame] | 558 | std::vector<ReportBlockData> ModuleRtpRtcpImpl::GetLatestReportBlockData() |
| 559 | const { |
| 560 | return rtcp_receiver_.GetLatestReportBlockData(); |
| 561 | } |
| 562 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 563 | // (REMB) Receiver Estimated Max Bitrate. |
Danil Chapovalov | 1de4b62 | 2017-12-13 13:35:10 +0100 | [diff] [blame] | 564 | void ModuleRtpRtcpImpl::SetRemb(int64_t bitrate_bps, |
| 565 | std::vector<uint32_t> ssrcs) { |
| 566 | rtcp_sender_.SetRemb(bitrate_bps, std::move(ssrcs)); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Danil Chapovalov | 51e21aa | 2017-10-10 17:46:26 +0200 | [diff] [blame] | 569 | void ModuleRtpRtcpImpl::UnsetRemb() { |
Danil Chapovalov | f74d641 | 2017-10-18 13:32:57 +0200 | [diff] [blame] | 570 | rtcp_sender_.UnsetRemb(); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Johannes Kron | 9190b82 | 2018-10-29 11:22:05 +0100 | [diff] [blame] | 573 | void ModuleRtpRtcpImpl::SetExtmapAllowMixed(bool extmap_allow_mixed) { |
| 574 | rtp_sender_->SetExtmapAllowMixed(extmap_allow_mixed); |
| 575 | } |
| 576 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 577 | int32_t ModuleRtpRtcpImpl::RegisterSendRtpHeaderExtension( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 578 | const RTPExtensionType type, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 579 | const uint8_t id) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 580 | return rtp_sender_->RegisterRtpHeaderExtension(type, id); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Danil Chapovalov | 585d1aa | 2018-09-14 18:29:32 +0200 | [diff] [blame] | 583 | bool ModuleRtpRtcpImpl::RegisterRtpHeaderExtension(const std::string& uri, |
| 584 | int id) { |
| 585 | return rtp_sender_->RegisterRtpHeaderExtension(uri, id); |
| 586 | } |
| 587 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 588 | int32_t ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 589 | const RTPExtensionType type) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 590 | return rtp_sender_->DeregisterRtpHeaderExtension(type); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 +0000 | [diff] [blame] | 591 | } |
| 592 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 593 | // (TMMBR) Temporary Max Media Bit Rate. |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 594 | bool ModuleRtpRtcpImpl::TMMBR() const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 595 | return rtcp_sender_.TMMBR(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 596 | } |
| 597 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 598 | void ModuleRtpRtcpImpl::SetTMMBRStatus(const bool enable) { |
| 599 | rtcp_sender_.SetTMMBRStatus(enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 600 | } |
| 601 | |
danilchap | 853ecb2 | 2016-08-22 08:26:15 -0700 | [diff] [blame] | 602 | void ModuleRtpRtcpImpl::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) { |
| 603 | rtcp_sender_.SetTmmbn(std::move(bounding_set)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 604 | } |
| 605 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 606 | // Send a Negative acknowledgment packet. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 607 | int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list, |
| 608 | const uint16_t size) { |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 609 | uint16_t nack_length = size; |
| 610 | uint16_t start_id = 0; |
Danil Chapovalov | 9eb6ce1 | 2017-12-15 12:25:01 +0100 | [diff] [blame] | 611 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 612 | if (TimeToSendFullNackList(now_ms)) { |
| 613 | nack_last_time_sent_full_ms_ = now_ms; |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 614 | } 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 | |
philipel | 83f831a | 2016-03-12 03:30:23 -0800 | [diff] [blame] | 637 | return rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, nack_length, |
| 638 | &nack_list[start_id]); |
| 639 | } |
| 640 | |
| 641 | void 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.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | bool ModuleRtpRtcpImpl::TimeToSendFullNackList(int64_t now) const { |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 648 | // Use RTT from RtcpRttStats class if provided. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 649 | int64_t rtt = rtt_ms(); |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 650 | if (rtt == 0) { |
| 651 | rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); |
| 652 | } |
stefan@webrtc.org | 8ca8a71 | 2013-04-23 16:48:32 +0000 | [diff] [blame] | 653 | |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 654 | const int64_t kStartUpRttMs = 100; |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 655 | int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5. |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 656 | if (rtt == 0) { |
| 657 | wait_time = kStartUpRttMs; |
stefan@webrtc.org | 8ca8a71 | 2013-04-23 16:48:32 +0000 | [diff] [blame] | 658 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 659 | |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 +0000 | [diff] [blame] | 660 | // Send a full NACK list once within every |wait_time|. |
Danil Chapovalov | 9eb6ce1 | 2017-12-15 12:25:01 +0100 | [diff] [blame] | 661 | return now - nack_last_time_sent_full_ms_ > wait_time; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 662 | } |
| 663 | |
asapersson@webrtc.org | 9ffd8fe | 2015-01-21 08:22:50 +0000 | [diff] [blame] | 664 | // Store the sent packets, needed to answer to Negative acknowledgment requests. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 +0000 | [diff] [blame] | 665 | void ModuleRtpRtcpImpl::SetStorePacketsStatus(const bool enable, |
| 666 | const uint16_t number_to_store) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 667 | rtp_sender_->SetStorePacketsStatus(enable, number_to_store); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 668 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 669 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 670 | bool ModuleRtpRtcpImpl::StorePackets() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 671 | return rtp_sender_->StorePackets(); |
tnakamura@webrtc.org | aa4d96a | 2013-07-16 19:25:04 +0000 | [diff] [blame] | 672 | } |
| 673 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 674 | void ModuleRtpRtcpImpl::RegisterRtcpStatisticsCallback( |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 675 | RtcpStatisticsCallback* callback) { |
| 676 | rtcp_receiver_.RegisterRtcpStatisticsCallback(callback); |
| 677 | } |
| 678 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 679 | RtcpStatisticsCallback* ModuleRtpRtcpImpl::GetRtcpStatisticsCallback() { |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 +0000 | [diff] [blame] | 680 | return rtcp_receiver_.GetRtcpStatisticsCallback(); |
| 681 | } |
| 682 | |
Henrik Boström | 87e3f9d | 2019-05-27 10:44:24 +0200 | [diff] [blame] | 683 | void ModuleRtpRtcpImpl::SetReportBlockDataObserver( |
| 684 | ReportBlockDataObserver* observer) { |
| 685 | return rtcp_receiver_.SetReportBlockDataObserver(observer); |
| 686 | } |
| 687 | |
sprang | 233bd87 | 2015-09-08 13:25:16 -0700 | [diff] [blame] | 688 | bool ModuleRtpRtcpImpl::SendFeedbackPacket( |
| 689 | const rtcp::TransportFeedback& packet) { |
| 690 | return rtcp_sender_.SendFeedbackPacket(packet); |
| 691 | } |
| 692 | |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 693 | int32_t ModuleRtpRtcpImpl::SendLossNotification(uint16_t last_decoded_seq_num, |
| 694 | uint16_t last_received_seq_num, |
Elad Alon | e86af2c | 2019-06-03 14:37:50 +0200 | [diff] [blame] | 695 | bool decodability_flag, |
| 696 | bool buffering_allowed) { |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 697 | return rtcp_sender_.SendLossNotification( |
| 698 | GetFeedbackState(), last_decoded_seq_num, last_received_seq_num, |
Elad Alon | e86af2c | 2019-06-03 14:37:50 +0200 | [diff] [blame] | 699 | decodability_flag, buffering_allowed); |
Elad Alon | 7d6a4c0 | 2019-02-25 13:00:51 +0100 | [diff] [blame] | 700 | } |
| 701 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 702 | void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 703 | // Inform about the incoming SSRC. |
| 704 | rtcp_sender_.SetRemoteSSRC(ssrc); |
| 705 | rtcp_receiver_.SetRemoteSSRC(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 708 | // TODO(nisse): Delete video_rate amd fec_rate arguments. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 709 | void ModuleRtpRtcpImpl::BitrateSent(uint32_t* total_rate, |
| 710 | uint32_t* video_rate, |
| 711 | uint32_t* fec_rate, |
| 712 | uint32_t* nack_rate) const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 713 | *total_rate = rtp_sender_->BitrateSent(); |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 714 | if (video_rate) |
| 715 | *video_rate = 0; |
| 716 | if (fec_rate) |
| 717 | *fec_rate = 0; |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 718 | *nack_rate = rtp_sender_->NackOverheadRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 719 | } |
| 720 | |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 721 | void ModuleRtpRtcpImpl::OnRequestSendReport() { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 722 | SendRTCP(kRtcpSr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Danil Chapovalov | 2800d74 | 2016-08-26 18:48:46 +0200 | [diff] [blame] | 725 | void ModuleRtpRtcpImpl::OnReceivedNack( |
| 726 | const std::vector<uint16_t>& nack_sequence_numbers) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 727 | if (!rtp_sender_) |
| 728 | return; |
| 729 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 730 | if (!rtp_sender_->StorePackets() || nack_sequence_numbers.size() == 0) { |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 731 | return; |
| 732 | } |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 733 | // Use RTT from RtcpRttStats class if provided. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 734 | int64_t rtt = rtt_ms(); |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 +0000 | [diff] [blame] | 735 | if (rtt == 0) { |
| 736 | rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); |
| 737 | } |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 738 | rtp_sender_->OnReceivedNack(nack_sequence_numbers, rtt); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 739 | } |
| 740 | |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 741 | void ModuleRtpRtcpImpl::OnReceivedRtcpReportBlocks( |
| 742 | const ReportBlockList& report_blocks) { |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 743 | if (ack_observer_) { |
Niels Möller | 59ab1cf | 2019-02-06 22:48:11 +0100 | [diff] [blame] | 744 | uint32_t ssrc = SSRC(); |
| 745 | |
| 746 | for (const RTCPReportBlock& report_block : report_blocks) { |
| 747 | if (ssrc == report_block.source_ssrc) { |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 748 | ack_observer_->OnReceivedAck( |
| 749 | report_block.extended_highest_sequence_number); |
Niels Möller | 59ab1cf | 2019-02-06 22:48:11 +0100 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | } |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 753 | } |
| 754 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 755 | bool 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.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 759 | // Remote SR: NTP inside the last received (mid 16 bits from sec and frac). |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 +0000 | [diff] [blame] | 760 | uint32_t ntp_secs = 0; |
| 761 | uint32_t ntp_frac = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 762 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 763 | if (!rtcp_receiver_.NTP(&ntp_secs, &ntp_frac, rtcp_arrival_time_secs, |
| 764 | rtcp_arrival_time_frac, NULL)) { |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 765 | return false; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 +0000 | [diff] [blame] | 766 | } |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 767 | *remote_sr = |
| 768 | ((ntp_secs & 0x0000ffff) << 16) + ((ntp_frac & 0xffff0000) >> 16); |
| 769 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 770 | } |
| 771 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 +0000 | [diff] [blame] | 772 | // Called from RTCPsender. |
danilchap | 2b61639 | 2016-08-18 06:17:42 -0700 | [diff] [blame] | 773 | std::vector<rtcp::TmmbItem> ModuleRtpRtcpImpl::BoundingSet(bool* tmmbr_owner) { |
| 774 | return rtcp_receiver_.BoundingSet(tmmbr_owner); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 775 | } |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 +0000 | [diff] [blame] | 776 | |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 777 | void ModuleRtpRtcpImpl::SetRtcpReceiverSsrcs(uint32_t main_ssrc) { |
| 778 | std::set<uint32_t> ssrcs; |
| 779 | ssrcs.insert(main_ssrc); |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 780 | if (RtxSendStatus() != kRtxOff) |
| 781 | ssrcs.insert(rtp_sender_->RtxSsrc()); |
Danil Chapovalov | d264df5 | 2018-06-14 12:59:38 +0200 | [diff] [blame] | 782 | absl::optional<uint32_t> flexfec_ssrc = FlexfecSsrc(); |
brandtr | 7c7796b | 2017-07-03 06:02:53 -0700 | [diff] [blame] | 783 | if (flexfec_ssrc) |
| 784 | ssrcs.insert(*flexfec_ssrc); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 +0000 | [diff] [blame] | 785 | rtcp_receiver_.SetSsrcs(main_ssrc, ssrcs); |
| 786 | } |
| 787 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 788 | void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 789 | rtc::CritScope cs(&critical_section_rtt_); |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 790 | rtt_ms_ = rtt_ms; |
Erik Språng | 8b10192 | 2018-01-18 11:58:05 -0800 | [diff] [blame] | 791 | if (rtp_sender_) |
| 792 | rtp_sender_->SetRtt(rtt_ms); |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 793 | } |
| 794 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 795 | int64_t ModuleRtpRtcpImpl::rtt_ms() const { |
danilchap | 7c9426c | 2016-04-14 03:05:31 -0700 | [diff] [blame] | 796 | rtc::CritScope cs(&critical_section_rtt_); |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 +0000 | [diff] [blame] | 797 | return rtt_ms_; |
| 798 | } |
| 799 | |
sprang@webrtc.org | ebad765 | 2013-12-05 14:29:02 +0000 | [diff] [blame] | 800 | void ModuleRtpRtcpImpl::RegisterSendChannelRtpStatisticsCallback( |
| 801 | StreamDataCountersCallback* callback) { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 802 | rtp_sender_->RegisterRtpStatisticsCallback(callback); |
sprang@webrtc.org | ebad765 | 2013-12-05 14:29:02 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | StreamDataCountersCallback* |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 806 | ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const { |
nisse | 14adba7 | 2017-03-20 03:52:39 -0700 | [diff] [blame] | 807 | return rtp_sender_->GetRtpStatisticsCallback(); |
sprang@webrtc.org | ebad765 | 2013-12-05 14:29:02 +0000 | [diff] [blame] | 808 | } |
sprang | 5e38c96 | 2016-12-01 05:18:09 -0800 | [diff] [blame] | 809 | |
| 810 | void ModuleRtpRtcpImpl::SetVideoBitrateAllocation( |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 811 | const VideoBitrateAllocation& bitrate) { |
sprang | 5e38c96 | 2016-12-01 05:18:09 -0800 | [diff] [blame] | 812 | rtcp_sender_.SetVideoBitrateAllocation(bitrate); |
| 813 | } |
Niels Möller | 5fe9510 | 2019-03-04 16:49:25 +0100 | [diff] [blame] | 814 | |
| 815 | RTPSender* ModuleRtpRtcpImpl::RtpSender() { |
| 816 | return rtp_sender_.get(); |
| 817 | } |
| 818 | |
| 819 | const RTPSender* ModuleRtpRtcpImpl::RtpSender() const { |
| 820 | return rtp_sender_.get(); |
| 821 | } |
| 822 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame] | 823 | } // namespace webrtc |