nisse | cae45d0 | 2017-04-24 12:53:20 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 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 | */ |
Sebastian Jansson | 91bb667 | 2018-02-21 12:02:51 | [diff] [blame] | 10 | #include <utility> |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 11 | #include <vector> |
nisse | cae45d0 | 2017-04-24 12:53:20 | [diff] [blame] | 12 | |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 13 | #include "absl/memory/memory.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 14 | #include "absl/types/optional.h" |
| 15 | #include "api/transport/network_types.h" |
| 16 | #include "api/units/data_rate.h" |
| 17 | #include "api/units/time_delta.h" |
| 18 | #include "api/units/timestamp.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 19 | #include "call/rtp_transport_controller_send.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 20 | #include "call/rtp_video_sender.h" |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 21 | #include "modules/congestion_controller/include/send_side_congestion_controller.h" |
Sebastian Jansson | 19bea51 | 2018-03-13 18:07:46 | [diff] [blame] | 22 | #include "modules/congestion_controller/rtp/include/send_side_congestion_controller.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 23 | #include "rtc_base/checks.h" |
Sebastian Jansson | c33c0fc | 2018-02-22 10:10:18 | [diff] [blame] | 24 | #include "rtc_base/location.h" |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 25 | #include "rtc_base/logging.h" |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 26 | #include "rtc_base/rate_limiter.h" |
Sebastian Jansson | 19bea51 | 2018-03-13 18:07:46 | [diff] [blame] | 27 | #include "system_wrappers/include/field_trial.h" |
nisse | cae45d0 | 2017-04-24 12:53:20 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
Sebastian Jansson | 19bea51 | 2018-03-13 18:07:46 | [diff] [blame] | 30 | namespace { |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 31 | static const int64_t kRetransmitWindowSizeMs = 500; |
Stefan Holmer | 64be7fa | 2018-10-04 13:21:55 | [diff] [blame] | 32 | static const size_t kMaxOverheadBytes = 500; |
Sebastian Jansson | 19bea51 | 2018-03-13 18:07:46 | [diff] [blame] | 33 | const char kTaskQueueExperiment[] = "WebRTC-TaskQueueCongestionControl"; |
| 34 | using TaskQueueController = webrtc::webrtc_cc::SendSideCongestionController; |
| 35 | |
Sebastian Jansson | 19bea51 | 2018-03-13 18:07:46 | [diff] [blame] | 36 | std::unique_ptr<SendSideCongestionControllerInterface> CreateController( |
| 37 | Clock* clock, |
Sebastian Jansson | bd9fe09 | 2018-05-07 14:33:50 | [diff] [blame] | 38 | rtc::TaskQueue* task_queue, |
Sebastian Jansson | 19bea51 | 2018-03-13 18:07:46 | [diff] [blame] | 39 | webrtc::RtcEventLog* event_log, |
| 40 | PacedSender* pacer, |
| 41 | const BitrateConstraints& bitrate_config, |
Sebastian Jansson | dfce03a | 2018-05-18 16:05:10 | [diff] [blame] | 42 | bool task_queue_controller, |
| 43 | NetworkControllerFactoryInterface* controller_factory) { |
Sebastian Jansson | 19bea51 | 2018-03-13 18:07:46 | [diff] [blame] | 44 | if (task_queue_controller) { |
Sebastian Jansson | 4e140da | 2018-04-13 11:25:19 | [diff] [blame] | 45 | RTC_LOG(LS_INFO) << "Using TaskQueue based SSCC"; |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 46 | return absl::make_unique<webrtc::webrtc_cc::SendSideCongestionController>( |
Sebastian Jansson | bd9fe09 | 2018-05-07 14:33:50 | [diff] [blame] | 47 | clock, task_queue, event_log, pacer, bitrate_config.start_bitrate_bps, |
Sebastian Jansson | dfce03a | 2018-05-18 16:05:10 | [diff] [blame] | 48 | bitrate_config.min_bitrate_bps, bitrate_config.max_bitrate_bps, |
| 49 | controller_factory); |
Sebastian Jansson | 19bea51 | 2018-03-13 18:07:46 | [diff] [blame] | 50 | } |
Sebastian Jansson | 4e140da | 2018-04-13 11:25:19 | [diff] [blame] | 51 | RTC_LOG(LS_INFO) << "Using Legacy SSCC"; |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 52 | auto cc = absl::make_unique<webrtc::SendSideCongestionController>( |
Sebastian Jansson | 19bea51 | 2018-03-13 18:07:46 | [diff] [blame] | 53 | clock, nullptr /* observer */, event_log, pacer); |
| 54 | cc->SignalNetworkState(kNetworkDown); |
| 55 | cc->SetBweBitrates(bitrate_config.min_bitrate_bps, |
| 56 | bitrate_config.start_bitrate_bps, |
| 57 | bitrate_config.max_bitrate_bps); |
| 58 | return std::move(cc); |
| 59 | } |
| 60 | } // namespace |
nisse | cae45d0 | 2017-04-24 12:53:20 | [diff] [blame] | 61 | |
| 62 | RtpTransportControllerSend::RtpTransportControllerSend( |
| 63 | Clock* clock, |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 64 | webrtc::RtcEventLog* event_log, |
Sebastian Jansson | dfce03a | 2018-05-18 16:05:10 | [diff] [blame] | 65 | NetworkControllerFactoryInterface* controller_factory, |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 66 | const BitrateConstraints& bitrate_config) |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 67 | : clock_(clock), |
| 68 | pacer_(clock, &packet_router_, event_log), |
Sebastian Jansson | 317a522 | 2018-03-16 14:36:37 | [diff] [blame] | 69 | bitrate_configurator_(bitrate_config), |
| 70 | process_thread_(ProcessThread::Create("SendControllerThread")), |
| 71 | observer_(nullptr), |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 72 | retransmission_rate_limiter_(clock, kRetransmitWindowSizeMs), |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 73 | task_queue_("rtp_send_controller") { |
Sebastian Jansson | bd9fe09 | 2018-05-07 14:33:50 | [diff] [blame] | 74 | // Created after task_queue to be able to post to the task queue internally. |
Sebastian Jansson | 4ff7214 | 2018-10-08 09:15:04 | [diff] [blame] | 75 | send_side_cc_ = CreateController( |
| 76 | clock, &task_queue_, event_log, &pacer_, bitrate_config, |
| 77 | !field_trial::IsDisabled(kTaskQueueExperiment), controller_factory); |
Sebastian Jansson | bd9fe09 | 2018-05-07 14:33:50 | [diff] [blame] | 78 | |
Sebastian Jansson | c33c0fc | 2018-02-22 10:10:18 | [diff] [blame] | 79 | process_thread_->RegisterModule(&pacer_, RTC_FROM_HERE); |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 80 | process_thread_->RegisterModule(send_side_cc_.get(), RTC_FROM_HERE); |
Sebastian Jansson | c33c0fc | 2018-02-22 10:10:18 | [diff] [blame] | 81 | process_thread_->Start(); |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 82 | } |
Sebastian Jansson | c33c0fc | 2018-02-22 10:10:18 | [diff] [blame] | 83 | |
| 84 | RtpTransportControllerSend::~RtpTransportControllerSend() { |
| 85 | process_thread_->Stop(); |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 86 | process_thread_->DeRegisterModule(send_side_cc_.get()); |
Sebastian Jansson | c33c0fc | 2018-02-22 10:10:18 | [diff] [blame] | 87 | process_thread_->DeRegisterModule(&pacer_); |
| 88 | } |
nisse | cae45d0 | 2017-04-24 12:53:20 | [diff] [blame] | 89 | |
Stefan Holmer | 9416ef8 | 2018-07-19 08:34:38 | [diff] [blame] | 90 | RtpVideoSenderInterface* RtpTransportControllerSend::CreateRtpVideoSender( |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 91 | const std::vector<uint32_t>& ssrcs, |
| 92 | std::map<uint32_t, RtpState> suspended_ssrcs, |
| 93 | const std::map<uint32_t, RtpPayloadState>& states, |
| 94 | const RtpConfig& rtp_config, |
Jiawei Ou | 5571812 | 2018-11-09 21:17:39 | [diff] [blame] | 95 | int rtcp_report_interval_ms, |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 96 | Transport* send_transport, |
| 97 | const RtpSenderObservers& observers, |
Stefan Holmer | 64be7fa | 2018-10-04 13:21:55 | [diff] [blame] | 98 | RtcEventLog* event_log, |
Benjamin Wright | 192eeec | 2018-10-18 00:27:25 | [diff] [blame] | 99 | std::unique_ptr<FecController> fec_controller, |
| 100 | const RtpSenderFrameEncryptionConfig& frame_encryption_config) { |
Stefan Holmer | 9416ef8 | 2018-07-19 08:34:38 | [diff] [blame] | 101 | video_rtp_senders_.push_back(absl::make_unique<RtpVideoSender>( |
Jiawei Ou | 5571812 | 2018-11-09 21:17:39 | [diff] [blame] | 102 | ssrcs, suspended_ssrcs, states, rtp_config, rtcp_report_interval_ms, |
| 103 | send_transport, observers, |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 104 | // TODO(holmer): Remove this circular dependency by injecting |
| 105 | // the parts of RtpTransportControllerSendInterface that are really used. |
Benjamin Wright | 192eeec | 2018-10-18 00:27:25 | [diff] [blame] | 106 | this, event_log, &retransmission_rate_limiter_, std::move(fec_controller), |
| 107 | frame_encryption_config.frame_encryptor, |
| 108 | frame_encryption_config.crypto_options)); |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 109 | return video_rtp_senders_.back().get(); |
| 110 | } |
| 111 | |
Stefan Holmer | 9416ef8 | 2018-07-19 08:34:38 | [diff] [blame] | 112 | void RtpTransportControllerSend::DestroyRtpVideoSender( |
| 113 | RtpVideoSenderInterface* rtp_video_sender) { |
| 114 | std::vector<std::unique_ptr<RtpVideoSenderInterface>>::iterator it = |
Stefan Holmer | 5ed25af | 2018-07-18 13:17:14 | [diff] [blame] | 115 | video_rtp_senders_.end(); |
| 116 | for (it = video_rtp_senders_.begin(); it != video_rtp_senders_.end(); ++it) { |
| 117 | if (it->get() == rtp_video_sender) { |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | RTC_DCHECK(it != video_rtp_senders_.end()); |
| 122 | video_rtp_senders_.erase(it); |
| 123 | } |
| 124 | |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 125 | void RtpTransportControllerSend::OnNetworkChanged(uint32_t bitrate_bps, |
| 126 | uint8_t fraction_loss, |
| 127 | int64_t rtt_ms, |
| 128 | int64_t probing_interval_ms) { |
| 129 | // TODO(srte): Skip this step when old SendSideCongestionController is |
| 130 | // deprecated. |
| 131 | TargetTransferRate msg; |
| 132 | msg.at_time = Timestamp::ms(clock_->TimeInMilliseconds()); |
| 133 | msg.target_rate = DataRate::bps(bitrate_bps); |
| 134 | msg.network_estimate.at_time = msg.at_time; |
| 135 | msg.network_estimate.bwe_period = TimeDelta::ms(probing_interval_ms); |
| 136 | uint32_t bandwidth_bps; |
Sebastian Jansson | bd9fe09 | 2018-05-07 14:33:50 | [diff] [blame] | 137 | if (send_side_cc_->AvailableBandwidth(&bandwidth_bps)) |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 138 | msg.network_estimate.bandwidth = DataRate::bps(bandwidth_bps); |
| 139 | msg.network_estimate.loss_rate_ratio = fraction_loss / 255.0; |
| 140 | msg.network_estimate.round_trip_time = TimeDelta::ms(rtt_ms); |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 141 | |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 142 | retransmission_rate_limiter_.SetMaxRate(bandwidth_bps); |
| 143 | |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 144 | if (!task_queue_.IsCurrent()) { |
| 145 | task_queue_.PostTask([this, msg] { |
| 146 | rtc::CritScope cs(&observer_crit_); |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 147 | // We won't register as observer until we have an observers. |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 148 | RTC_DCHECK(observer_ != nullptr); |
| 149 | observer_->OnTargetTransferRate(msg); |
| 150 | }); |
| 151 | } else { |
| 152 | rtc::CritScope cs(&observer_crit_); |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 153 | // We won't register as observer until we have an observers. |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 154 | RTC_DCHECK(observer_ != nullptr); |
| 155 | observer_->OnTargetTransferRate(msg); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | rtc::TaskQueue* RtpTransportControllerSend::GetWorkerQueue() { |
| 160 | return &task_queue_; |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 161 | } |
| 162 | |
nisse | 76e62b0 | 2017-05-31 09:24:52 | [diff] [blame] | 163 | PacketRouter* RtpTransportControllerSend::packet_router() { |
| 164 | return &packet_router_; |
| 165 | } |
| 166 | |
nisse | 76e62b0 | 2017-05-31 09:24:52 | [diff] [blame] | 167 | TransportFeedbackObserver* |
| 168 | RtpTransportControllerSend::transport_feedback_observer() { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 169 | return send_side_cc_.get(); |
nisse | 76e62b0 | 2017-05-31 09:24:52 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | RtpPacketSender* RtpTransportControllerSend::packet_sender() { |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 173 | return &pacer_; |
nisse | 76e62b0 | 2017-05-31 09:24:52 | [diff] [blame] | 174 | } |
| 175 | |
sprang | db2a9fc | 2017-08-09 13:42:32 | [diff] [blame] | 176 | const RtpKeepAliveConfig& RtpTransportControllerSend::keepalive_config() const { |
| 177 | return keepalive_; |
| 178 | } |
| 179 | |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 180 | void RtpTransportControllerSend::SetAllocatedSendBitrateLimits( |
| 181 | int min_send_bitrate_bps, |
philipel | 832b1c8 | 2018-02-28 16:04:18 | [diff] [blame] | 182 | int max_padding_bitrate_bps, |
philipel | db4fa4b | 2018-03-06 17:29:22 | [diff] [blame] | 183 | int max_total_bitrate_bps) { |
Sebastian Jansson | 68ee465 | 2018-03-13 10:40:34 | [diff] [blame] | 184 | send_side_cc_->SetAllocatedSendBitrateLimits( |
| 185 | min_send_bitrate_bps, max_padding_bitrate_bps, max_total_bitrate_bps); |
Stefan Holmer | 5c8942a | 2017-08-22 14:16:44 | [diff] [blame] | 186 | } |
| 187 | |
sprang | db2a9fc | 2017-08-09 13:42:32 | [diff] [blame] | 188 | void RtpTransportControllerSend::SetKeepAliveConfig( |
| 189 | const RtpKeepAliveConfig& config) { |
| 190 | keepalive_ = config; |
| 191 | } |
Sebastian Jansson | 4c1ffb8 | 2018-02-15 15:51:58 | [diff] [blame] | 192 | void RtpTransportControllerSend::SetPacingFactor(float pacing_factor) { |
Sebastian Jansson | 68ee465 | 2018-03-13 10:40:34 | [diff] [blame] | 193 | send_side_cc_->SetPacingFactor(pacing_factor); |
Sebastian Jansson | 4c1ffb8 | 2018-02-15 15:51:58 | [diff] [blame] | 194 | } |
| 195 | void RtpTransportControllerSend::SetQueueTimeLimit(int limit_ms) { |
| 196 | pacer_.SetQueueTimeLimit(limit_ms); |
| 197 | } |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 198 | CallStatsObserver* RtpTransportControllerSend::GetCallStatsObserver() { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 199 | return send_side_cc_.get(); |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 200 | } |
| 201 | void RtpTransportControllerSend::RegisterPacketFeedbackObserver( |
| 202 | PacketFeedbackObserver* observer) { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 203 | send_side_cc_->RegisterPacketFeedbackObserver(observer); |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 204 | } |
| 205 | void RtpTransportControllerSend::DeRegisterPacketFeedbackObserver( |
| 206 | PacketFeedbackObserver* observer) { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 207 | send_side_cc_->DeRegisterPacketFeedbackObserver(observer); |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 208 | } |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 209 | |
| 210 | void RtpTransportControllerSend::RegisterTargetTransferRateObserver( |
| 211 | TargetTransferRateObserver* observer) { |
| 212 | { |
| 213 | rtc::CritScope cs(&observer_crit_); |
| 214 | RTC_DCHECK(observer_ == nullptr); |
| 215 | observer_ = observer; |
| 216 | } |
| 217 | send_side_cc_->RegisterNetworkObserver(this); |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 218 | } |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 219 | void RtpTransportControllerSend::OnNetworkRouteChanged( |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 220 | const std::string& transport_name, |
| 221 | const rtc::NetworkRoute& network_route) { |
Sebastian Jansson | 91bb667 | 2018-02-21 12:02:51 | [diff] [blame] | 222 | // Check if the network route is connected. |
| 223 | if (!network_route.connected) { |
| 224 | RTC_LOG(LS_INFO) << "Transport " << transport_name << " is disconnected"; |
| 225 | // TODO(honghaiz): Perhaps handle this in SignalChannelNetworkState and |
| 226 | // consider merging these two methods. |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | // Check whether the network route has changed on each transport. |
| 231 | auto result = |
| 232 | network_routes_.insert(std::make_pair(transport_name, network_route)); |
| 233 | auto kv = result.first; |
| 234 | bool inserted = result.second; |
| 235 | if (inserted) { |
| 236 | // No need to reset BWE if this is the first time the network connects. |
| 237 | return; |
| 238 | } |
| 239 | if (kv->second != network_route) { |
| 240 | kv->second = network_route; |
| 241 | BitrateConstraints bitrate_config = bitrate_configurator_.GetConfig(); |
| 242 | RTC_LOG(LS_INFO) << "Network route changed on transport " << transport_name |
| 243 | << ": new local network id " |
| 244 | << network_route.local_network_id |
| 245 | << " new remote network id " |
| 246 | << network_route.remote_network_id |
| 247 | << " Reset bitrates to min: " |
| 248 | << bitrate_config.min_bitrate_bps |
| 249 | << " bps, start: " << bitrate_config.start_bitrate_bps |
| 250 | << " bps, max: " << bitrate_config.max_bitrate_bps |
| 251 | << " bps."; |
| 252 | RTC_DCHECK_GT(bitrate_config.start_bitrate_bps, 0); |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 253 | send_side_cc_->OnNetworkRouteChanged( |
Sebastian Jansson | 91bb667 | 2018-02-21 12:02:51 | [diff] [blame] | 254 | network_route, bitrate_config.start_bitrate_bps, |
| 255 | bitrate_config.min_bitrate_bps, bitrate_config.max_bitrate_bps); |
| 256 | } |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 257 | } |
| 258 | void RtpTransportControllerSend::OnNetworkAvailability(bool network_available) { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 259 | send_side_cc_->SignalNetworkState(network_available ? kNetworkUp |
| 260 | : kNetworkDown); |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 261 | for (auto& rtp_sender : video_rtp_senders_) { |
| 262 | rtp_sender->OnNetworkAvailability(network_available); |
| 263 | } |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 264 | } |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 265 | RtcpBandwidthObserver* RtpTransportControllerSend::GetBandwidthObserver() { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 266 | return send_side_cc_->GetBandwidthObserver(); |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 267 | } |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 268 | int64_t RtpTransportControllerSend::GetPacerQueuingDelayMs() const { |
Sebastian Jansson | a06e919 | 2018-03-07 17:49:55 | [diff] [blame] | 269 | return pacer_.QueueInMs(); |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 270 | } |
| 271 | int64_t RtpTransportControllerSend::GetFirstPacketTimeMs() const { |
Sebastian Jansson | a06e919 | 2018-03-07 17:49:55 | [diff] [blame] | 272 | return pacer_.FirstSentPacketTimeMs(); |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 273 | } |
Sebastian Jansson | 12130bb | 2018-03-21 11:48:43 | [diff] [blame] | 274 | void RtpTransportControllerSend::SetPerPacketFeedbackAvailable(bool available) { |
| 275 | send_side_cc_->SetPerPacketFeedbackAvailable(available); |
| 276 | } |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 277 | void RtpTransportControllerSend::EnablePeriodicAlrProbing(bool enable) { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 278 | send_side_cc_->EnablePeriodicAlrProbing(enable); |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 279 | } |
| 280 | void RtpTransportControllerSend::OnSentPacket( |
| 281 | const rtc::SentPacket& sent_packet) { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 282 | send_side_cc_->OnSentPacket(sent_packet); |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 283 | } |
sprang | db2a9fc | 2017-08-09 13:42:32 | [diff] [blame] | 284 | |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 285 | void RtpTransportControllerSend::SetSdpBitrateParameters( |
| 286 | const BitrateConstraints& constraints) { |
Danil Chapovalov | b9b146c | 2018-06-15 10:28:07 | [diff] [blame] | 287 | absl::optional<BitrateConstraints> updated = |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 288 | bitrate_configurator_.UpdateWithSdpParameters(constraints); |
| 289 | if (updated.has_value()) { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 290 | send_side_cc_->SetBweBitrates(updated->min_bitrate_bps, |
| 291 | updated->start_bitrate_bps, |
| 292 | updated->max_bitrate_bps); |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 293 | } else { |
| 294 | RTC_LOG(LS_VERBOSE) |
Sebastian Jansson | 8f83b42 | 2018-02-21 12:07:13 | [diff] [blame] | 295 | << "WebRTC.RtpTransportControllerSend.SetSdpBitrateParameters: " |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 296 | << "nothing to update"; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void RtpTransportControllerSend::SetClientBitratePreferences( |
Niels Möller | 0c4f7be | 2018-05-07 12:01:37 | [diff] [blame] | 301 | const BitrateSettings& preferences) { |
Danil Chapovalov | b9b146c | 2018-06-15 10:28:07 | [diff] [blame] | 302 | absl::optional<BitrateConstraints> updated = |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 303 | bitrate_configurator_.UpdateWithClientPreferences(preferences); |
| 304 | if (updated.has_value()) { |
Sebastian Jansson | 10211e9 | 2018-02-28 15:48:26 | [diff] [blame] | 305 | send_side_cc_->SetBweBitrates(updated->min_bitrate_bps, |
| 306 | updated->start_bitrate_bps, |
| 307 | updated->max_bitrate_bps); |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 308 | } else { |
| 309 | RTC_LOG(LS_VERBOSE) |
Sebastian Jansson | 8f83b42 | 2018-02-21 12:07:13 | [diff] [blame] | 310 | << "WebRTC.RtpTransportControllerSend.SetClientBitratePreferences: " |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 311 | << "nothing to update"; |
| 312 | } |
| 313 | } |
Alex Narest | bcf9180 | 2018-06-25 14:08:36 | [diff] [blame] | 314 | |
| 315 | void RtpTransportControllerSend::SetAllocatedBitrateWithoutFeedback( |
| 316 | uint32_t bitrate_bps) { |
Sebastian Jansson | 35fa280 | 2018-10-01 07:16:12 | [diff] [blame] | 317 | // Audio transport feedback will not be reported in this mode, instead update |
| 318 | // acknowledged bitrate estimator with the bitrate allocated for audio. |
| 319 | if (field_trial::IsEnabled("WebRTC-Audio-ABWENoTWCC")) { |
| 320 | // TODO(srte): Make sure it's safe to always report this and remove the |
| 321 | // field trial check. |
| 322 | send_side_cc_->SetAllocatedBitrateWithoutFeedback(bitrate_bps); |
| 323 | } |
Alex Narest | bcf9180 | 2018-06-25 14:08:36 | [diff] [blame] | 324 | } |
Stefan Holmer | 64be7fa | 2018-10-04 13:21:55 | [diff] [blame] | 325 | |
| 326 | void RtpTransportControllerSend::OnTransportOverheadChanged( |
| 327 | size_t transport_overhead_bytes_per_packet) { |
| 328 | if (transport_overhead_bytes_per_packet >= kMaxOverheadBytes) { |
| 329 | RTC_LOG(LS_ERROR) << "Transport overhead exceeds " << kMaxOverheadBytes; |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | // TODO(holmer): Call AudioRtpSenders when they have been moved to |
| 334 | // RtpTransportControllerSend. |
| 335 | for (auto& rtp_video_sender : video_rtp_senders_) { |
| 336 | rtp_video_sender->OnTransportOverheadChanged( |
| 337 | transport_overhead_bytes_per_packet); |
| 338 | } |
| 339 | } |
nisse | cae45d0 | 2017-04-24 12:53:20 | [diff] [blame] | 340 | } // namespace webrtc |