| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" | 11 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
| 12 | 12 |
| 13 #include <math.h> | 13 #include <math.h> |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 | 16 |
| 17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 20 #include "webrtc/base/thread_annotations.h" | 20 #include "webrtc/base/thread_annotations.h" |
| 21 #include "webrtc/modules/pacing/paced_sender.h" | 21 #include "webrtc/modules/pacing/paced_sender.h" |
| 22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
| 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 24 #include "webrtc/system_wrappers/include/metrics.h" | 24 #include "webrtc/system_wrappers/include/metrics.h" |
| 25 #include "webrtc/typedefs.h" | 25 #include "webrtc/typedefs.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 enum { | 28 constexpr int kTimestampGroupLengthMs = 5; |
| 29 kTimestampGroupLengthMs = 5, | 29 constexpr int kAbsSendTimeFraction = 18; |
| 30 kAbsSendTimeFraction = 18, | 30 constexpr int kAbsSendTimeInterArrivalUpshift = 8; |
| 31 kAbsSendTimeInterArrivalUpshift = 8, | 31 constexpr int kInterArrivalShift = |
| 32 kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, | 32 kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift; |
| 33 kInitialProbingIntervalMs = 2000, | 33 constexpr double kTimestampToMs = |
| 34 kMinClusterSize = 4, | |
| 35 kMaxProbePackets = 15, | |
| 36 kExpectedNumberOfProbes = 3 | |
| 37 }; | |
| 38 | |
| 39 static const double kTimestampToMs = | |
| 40 1000.0 / static_cast<double>(1 << kInterArrivalShift); | 34 1000.0 / static_cast<double>(1 << kInterArrivalShift); |
| 41 | 35 |
| 42 template <typename K, typename V> | 36 // This ssrc is used to fulfill the current API but will be removed |
| 43 std::vector<K> Keys(const std::map<K, V>& map) { | 37 // after the API has been changed. |
| 44 std::vector<K> keys; | 38 constexpr uint32_t kFixedSsrc = 0; |
| 45 keys.reserve(map.size()); | |
| 46 for (typename std::map<K, V>::const_iterator it = map.begin(); | |
| 47 it != map.end(); ++it) { | |
| 48 keys.push_back(it->first); | |
| 49 } | |
| 50 return keys; | |
| 51 } | |
| 52 | |
| 53 uint32_t ConvertMsTo24Bits(int64_t time_ms) { | |
| 54 uint32_t time_24_bits = | |
| 55 static_cast<uint32_t>( | |
| 56 ((static_cast<uint64_t>(time_ms) << kAbsSendTimeFraction) + 500) / | |
| 57 1000) & | |
| 58 0x00FFFFFF; | |
| 59 return time_24_bits; | |
| 60 } | |
| 61 } // namespace | 39 } // namespace |
| 62 | 40 |
| 63 namespace webrtc { | 41 namespace webrtc { |
| 64 | 42 |
| 65 void DelayBasedBwe::AddCluster(std::list<Cluster>* clusters, Cluster* cluster) { | |
| 66 cluster->send_mean_ms /= static_cast<float>(cluster->count); | |
| 67 cluster->recv_mean_ms /= static_cast<float>(cluster->count); | |
| 68 cluster->mean_size /= cluster->count; | |
| 69 clusters->push_back(*cluster); | |
| 70 } | |
| 71 | |
| 72 DelayBasedBwe::DelayBasedBwe(RemoteBitrateObserver* observer, Clock* clock) | 43 DelayBasedBwe::DelayBasedBwe(RemoteBitrateObserver* observer, Clock* clock) |
| 73 : clock_(clock), | 44 : clock_(clock), |
| 74 observer_(observer), | 45 observer_(observer), |
| 75 inter_arrival_(), | 46 inter_arrival_(), |
| 76 estimator_(), | 47 estimator_(), |
| 77 detector_(OverUseDetectorOptions()), | 48 detector_(OverUseDetectorOptions()), |
| 78 incoming_bitrate_(kBitrateWindowMs, 8000), | 49 incoming_bitrate_(kBitrateWindowMs, 8000), |
| 79 total_probes_received_(0), | |
| 80 first_packet_time_ms_(-1), | 50 first_packet_time_ms_(-1), |
| 81 last_update_ms_(-1), | 51 last_update_ms_(-1), |
| 52 last_seen_packet_ms_(-1), |
| 82 uma_recorded_(false) { | 53 uma_recorded_(false) { |
| 83 RTC_DCHECK(observer_); | 54 RTC_DCHECK(observer_); |
| 84 // NOTE! The BitrateEstimatorTest relies on this EXACT log line. | |
| 85 LOG(LS_INFO) << "RemoteBitrateEstimatorAbsSendTime: Instantiating."; | |
| 86 network_thread_.DetachFromThread(); | 55 network_thread_.DetachFromThread(); |
| 87 } | 56 } |
| 88 | 57 |
| 89 void DelayBasedBwe::ComputeClusters(std::list<Cluster>* clusters) const { | |
| 90 Cluster current; | |
| 91 int64_t prev_send_time = -1; | |
| 92 int64_t prev_recv_time = -1; | |
| 93 int last_probe_cluster_id = -1; | |
| 94 for (std::list<Probe>::const_iterator it = probes_.begin(); | |
| 95 it != probes_.end(); ++it) { | |
| 96 if (last_probe_cluster_id == -1) | |
| 97 last_probe_cluster_id = it->cluster_id; | |
| 98 if (prev_send_time >= 0) { | |
| 99 int send_delta_ms = it->send_time_ms - prev_send_time; | |
| 100 int recv_delta_ms = it->recv_time_ms - prev_recv_time; | |
| 101 if (send_delta_ms >= 1 && recv_delta_ms >= 1) { | |
| 102 ++current.num_above_min_delta; | |
| 103 } | |
| 104 if (it->cluster_id != last_probe_cluster_id) { | |
| 105 if (current.count >= kMinClusterSize) | |
| 106 AddCluster(clusters, ¤t); | |
| 107 current = Cluster(); | |
| 108 } | |
| 109 current.send_mean_ms += send_delta_ms; | |
| 110 current.recv_mean_ms += recv_delta_ms; | |
| 111 current.mean_size += it->payload_size; | |
| 112 ++current.count; | |
| 113 last_probe_cluster_id = it->cluster_id; | |
| 114 } | |
| 115 prev_send_time = it->send_time_ms; | |
| 116 prev_recv_time = it->recv_time_ms; | |
| 117 } | |
| 118 if (current.count >= kMinClusterSize) | |
| 119 AddCluster(clusters, ¤t); | |
| 120 } | |
| 121 | |
| 122 std::list<DelayBasedBwe::Cluster>::const_iterator DelayBasedBwe::FindBestProbe( | |
| 123 const std::list<Cluster>& clusters) const { | |
| 124 int highest_probe_bitrate_bps = 0; | |
| 125 std::list<Cluster>::const_iterator best_it = clusters.end(); | |
| 126 for (std::list<Cluster>::const_iterator it = clusters.begin(); | |
| 127 it != clusters.end(); ++it) { | |
| 128 if (it->send_mean_ms == 0 || it->recv_mean_ms == 0) | |
| 129 continue; | |
| 130 int send_bitrate_bps = it->mean_size * 8 * 1000 / it->send_mean_ms; | |
| 131 int recv_bitrate_bps = it->mean_size * 8 * 1000 / it->recv_mean_ms; | |
| 132 if (it->num_above_min_delta > it->count / 2 && | |
| 133 (it->recv_mean_ms - it->send_mean_ms <= 2.0f && | |
| 134 it->send_mean_ms - it->recv_mean_ms <= 5.0f)) { | |
| 135 int probe_bitrate_bps = | |
| 136 std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps()); | |
| 137 if (probe_bitrate_bps > highest_probe_bitrate_bps) { | |
| 138 highest_probe_bitrate_bps = probe_bitrate_bps; | |
| 139 best_it = it; | |
| 140 } | |
| 141 } else { | |
| 142 LOG(LS_INFO) << "Probe failed, sent at " << send_bitrate_bps | |
| 143 << " bps, received at " << recv_bitrate_bps | |
| 144 << " bps. Mean send delta: " << it->send_mean_ms | |
| 145 << " ms, mean recv delta: " << it->recv_mean_ms | |
| 146 << " ms, num probes: " << it->count; | |
| 147 break; | |
| 148 } | |
| 149 } | |
| 150 return best_it; | |
| 151 } | |
| 152 | |
| 153 DelayBasedBwe::ProbeResult DelayBasedBwe::ProcessClusters(int64_t now_ms) { | |
| 154 std::list<Cluster> clusters; | |
| 155 ComputeClusters(&clusters); | |
| 156 if (clusters.empty()) { | |
| 157 // If we reach the max number of probe packets and still have no clusters, | |
| 158 // we will remove the oldest one. | |
| 159 if (probes_.size() >= kMaxProbePackets) | |
| 160 probes_.pop_front(); | |
| 161 return ProbeResult::kNoUpdate; | |
| 162 } | |
| 163 | |
| 164 std::list<Cluster>::const_iterator best_it = FindBestProbe(clusters); | |
| 165 if (best_it != clusters.end()) { | |
| 166 int probe_bitrate_bps = | |
| 167 std::min(best_it->GetSendBitrateBps(), best_it->GetRecvBitrateBps()); | |
| 168 // Make sure that a probe sent on a lower bitrate than our estimate can't | |
| 169 // reduce the estimate. | |
| 170 if (IsBitrateImproving(probe_bitrate_bps)) { | |
| 171 LOG(LS_INFO) << "Probe successful, sent at " | |
| 172 << best_it->GetSendBitrateBps() << " bps, received at " | |
| 173 << best_it->GetRecvBitrateBps() | |
| 174 << " bps. Mean send delta: " << best_it->send_mean_ms | |
| 175 << " ms, mean recv delta: " << best_it->recv_mean_ms | |
| 176 << " ms, num probes: " << best_it->count; | |
| 177 remote_rate_.SetEstimate(probe_bitrate_bps, now_ms); | |
| 178 return ProbeResult::kBitrateUpdated; | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 // Not probing and received non-probe packet, or finished with current set | |
| 183 // of probes. | |
| 184 if (clusters.size() >= kExpectedNumberOfProbes) | |
| 185 probes_.clear(); | |
| 186 return ProbeResult::kNoUpdate; | |
| 187 } | |
| 188 | |
| 189 bool DelayBasedBwe::IsBitrateImproving(int new_bitrate_bps) const { | |
| 190 bool initial_probe = !remote_rate_.ValidEstimate() && new_bitrate_bps > 0; | |
| 191 bool bitrate_above_estimate = | |
| 192 remote_rate_.ValidEstimate() && | |
| 193 new_bitrate_bps > static_cast<int>(remote_rate_.LatestEstimate()); | |
| 194 return initial_probe || bitrate_above_estimate; | |
| 195 } | |
| 196 | |
| 197 void DelayBasedBwe::IncomingPacketFeedbackVector( | 58 void DelayBasedBwe::IncomingPacketFeedbackVector( |
| 198 const std::vector<PacketInfo>& packet_feedback_vector) { | 59 const std::vector<PacketInfo>& packet_feedback_vector) { |
| 199 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 60 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
| 200 if (!uma_recorded_) { | 61 if (!uma_recorded_) { |
| 201 RTC_LOGGED_HISTOGRAM_ENUMERATION(kBweTypeHistogram, | 62 RTC_LOGGED_HISTOGRAM_ENUMERATION(kBweTypeHistogram, |
| 202 BweNames::kSendSideTransportSeqNum, | 63 BweNames::kSendSideTransportSeqNum, |
| 203 BweNames::kBweNamesMax); | 64 BweNames::kBweNamesMax); |
| 204 uma_recorded_ = true; | 65 uma_recorded_ = true; |
| 205 } | 66 } |
| 206 for (const auto& packet_info : packet_feedback_vector) { | 67 for (const auto& packet_info : packet_feedback_vector) { |
| 207 IncomingPacketInfo(packet_info.arrival_time_ms, | 68 IncomingPacketInfo(packet_info); |
| 208 ConvertMsTo24Bits(packet_info.send_time_ms), | |
| 209 packet_info.payload_size, 0, | |
| 210 packet_info.probe_cluster_id); | |
| 211 } | 69 } |
| 212 } | 70 } |
| 213 | 71 |
| 214 void DelayBasedBwe::IncomingPacketInfo(int64_t arrival_time_ms, | 72 void DelayBasedBwe::IncomingPacketInfo(const PacketInfo& info) { |
| 215 uint32_t send_time_24bits, | |
| 216 size_t payload_size, | |
| 217 uint32_t ssrc, | |
| 218 int probe_cluster_id) { | |
| 219 assert(send_time_24bits < (1ul << 24)); | |
| 220 // Shift up send time to use the full 32 bits that inter_arrival works with, | |
| 221 // so wrapping works properly. | |
| 222 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; | |
| 223 int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs; | |
| 224 | |
| 225 int64_t now_ms = clock_->TimeInMilliseconds(); | 73 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 226 // TODO(holmer): SSRCs are only needed for REMB, should be broken out from | |
| 227 // here. | |
| 228 incoming_bitrate_.Update(payload_size, arrival_time_ms); | |
| 229 | 74 |
| 230 if (first_packet_time_ms_ == -1) | 75 if (first_packet_time_ms_ == -1) |
| 231 first_packet_time_ms_ = now_ms; | 76 first_packet_time_ms_ = now_ms; |
| 232 | 77 |
| 233 uint32_t ts_delta = 0; | 78 incoming_bitrate_.Update(info.payload_size, info.arrival_time_ms); |
| 234 int64_t t_delta = 0; | |
| 235 int size_delta = 0; | |
| 236 | |
| 237 bool update_estimate = false; | 79 bool update_estimate = false; |
| 238 uint32_t target_bitrate_bps = 0; | 80 uint32_t target_bitrate_bps = 0; |
| 239 std::vector<uint32_t> ssrcs; | |
| 240 { | 81 { |
| 241 rtc::CritScope lock(&crit_); | 82 rtc::CritScope lock(&crit_); |
| 242 | 83 |
| 243 TimeoutStreams(now_ms); | 84 // Reset if the stream has timed out. |
| 244 RTC_DCHECK(inter_arrival_.get()); | 85 if (last_seen_packet_ms_ == -1 || |
| 245 RTC_DCHECK(estimator_.get()); | 86 now_ms - last_seen_packet_ms_ > kStreamTimeOutMs) { |
| 246 ssrcs_[ssrc] = now_ms; | 87 inter_arrival_.reset(new InterArrival( |
| 88 (kTimestampGroupLengthMs << kInterArrivalShift) / 1000, |
| 89 kTimestampToMs, true)); |
| 90 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); |
| 91 } |
| 92 last_seen_packet_ms_ = now_ms; |
| 247 | 93 |
| 248 // For now only try to detect probes while we don't have a valid estimate, | 94 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { |
| 249 // and make sure the packet was paced. We currently assume that only packets | 95 ProbingResult probe_result = |
| 250 // larger than 200 bytes are paced by the sender. | 96 probe_bitrate_estimator_.PacketFeedback(info); |
| 251 if (probe_cluster_id != PacketInfo::kNotAProbe && | 97 if (probe_result.valid()) { |
| 252 payload_size > PacedSender::kMinProbePacketSize && | 98 remote_rate_.SetEstimate(probe_result.bps, probe_result.timestamp); |
| 253 (!remote_rate_.ValidEstimate() || | 99 update_estimate = true; |
| 254 now_ms - first_packet_time_ms_ < kInitialProbingIntervalMs)) { | |
| 255 // TODO(holmer): Use a map instead to get correct order? | |
| 256 if (total_probes_received_ < kMaxProbePackets) { | |
| 257 int send_delta_ms = -1; | |
| 258 int recv_delta_ms = -1; | |
| 259 if (!probes_.empty()) { | |
| 260 send_delta_ms = send_time_ms - probes_.back().send_time_ms; | |
| 261 recv_delta_ms = arrival_time_ms - probes_.back().recv_time_ms; | |
| 262 } | |
| 263 LOG(LS_INFO) << "Probe packet received: send time=" << send_time_ms | |
| 264 << " ms, recv time=" << arrival_time_ms | |
| 265 << " ms, send delta=" << send_delta_ms | |
| 266 << " ms, recv delta=" << recv_delta_ms << " ms."; | |
| 267 } | 100 } |
| 268 probes_.push_back( | |
| 269 Probe(send_time_ms, arrival_time_ms, payload_size, probe_cluster_id)); | |
| 270 ++total_probes_received_; | |
| 271 // Make sure that a probe which updated the bitrate immediately has an | |
| 272 // effect by calling the OnReceiveBitrateChanged callback. | |
| 273 if (ProcessClusters(now_ms) == ProbeResult::kBitrateUpdated) | |
| 274 update_estimate = true; | |
| 275 } | 101 } |
| 276 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, now_ms, | 102 |
| 277 payload_size, &ts_delta, &t_delta, | 103 uint32_t send_time_24bits = |
| 104 static_cast<uint32_t>(((static_cast<uint64_t>(info.send_time_ms) |
| 105 << kAbsSendTimeFraction) + |
| 106 500) / |
| 107 1000) & |
| 108 0x00FFFFFF; |
| 109 // Shift up send time to use the full 32 bits that inter_arrival works with, |
| 110 // so wrapping works properly. |
| 111 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; |
| 112 |
| 113 uint32_t ts_delta = 0; |
| 114 int64_t t_delta = 0; |
| 115 int size_delta = 0; |
| 116 if (inter_arrival_->ComputeDeltas(timestamp, info.arrival_time_ms, now_ms, |
| 117 info.payload_size, &ts_delta, &t_delta, |
| 278 &size_delta)) { | 118 &size_delta)) { |
| 279 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); | 119 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); |
| 280 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State()); | 120 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State()); |
| 281 detector_.Detect(estimator_->offset(), ts_delta_ms, | 121 detector_.Detect(estimator_->offset(), ts_delta_ms, |
| 282 estimator_->num_of_deltas(), arrival_time_ms); | 122 estimator_->num_of_deltas(), info.arrival_time_ms); |
| 283 } | 123 } |
| 284 | 124 |
| 285 if (!update_estimate) { | 125 if (!update_estimate) { |
| 286 // Check if it's time for a periodic update or if we should update because | 126 // Check if it's time for a periodic update or if we should update because |
| 287 // of an over-use. | 127 // of an over-use. |
| 288 if (last_update_ms_ == -1 || | 128 if (last_update_ms_ == -1 || |
| 289 now_ms - last_update_ms_ > remote_rate_.GetFeedbackInterval()) { | 129 now_ms - last_update_ms_ > remote_rate_.GetFeedbackInterval()) { |
| 290 update_estimate = true; | 130 update_estimate = true; |
| 291 } else if (detector_.State() == kBwOverusing) { | 131 } else if (detector_.State() == kBwOverusing) { |
| 292 rtc::Optional<uint32_t> incoming_rate = | 132 rtc::Optional<uint32_t> incoming_rate = |
| 293 incoming_bitrate_.Rate(arrival_time_ms); | 133 incoming_bitrate_.Rate(info.arrival_time_ms); |
| 294 if (incoming_rate && | 134 if (incoming_rate && |
| 295 remote_rate_.TimeToReduceFurther(now_ms, *incoming_rate)) { | 135 remote_rate_.TimeToReduceFurther(now_ms, *incoming_rate)) { |
| 296 update_estimate = true; | 136 update_estimate = true; |
| 297 } | 137 } |
| 298 } | 138 } |
| 299 } | 139 } |
| 300 | 140 |
| 301 if (update_estimate) { | 141 if (update_estimate) { |
| 302 // The first overuse should immediately trigger a new estimate. | 142 // The first overuse should immediately trigger a new estimate. |
| 303 // We also have to update the estimate immediately if we are overusing | 143 // We also have to update the estimate immediately if we are overusing |
| 304 // and the target bitrate is too high compared to what we are receiving. | 144 // and the target bitrate is too high compared to what we are receiving. |
| 305 const RateControlInput input(detector_.State(), | 145 const RateControlInput input(detector_.State(), |
| 306 incoming_bitrate_.Rate(arrival_time_ms), | 146 incoming_bitrate_.Rate(info.arrival_time_ms), |
| 307 estimator_->var_noise()); | 147 estimator_->var_noise()); |
| 308 remote_rate_.Update(&input, now_ms); | 148 remote_rate_.Update(&input, now_ms); |
| 309 target_bitrate_bps = remote_rate_.UpdateBandwidthEstimate(now_ms); | 149 target_bitrate_bps = remote_rate_.UpdateBandwidthEstimate(now_ms); |
| 310 update_estimate = remote_rate_.ValidEstimate(); | 150 update_estimate = remote_rate_.ValidEstimate(); |
| 311 ssrcs = Keys(ssrcs_); | |
| 312 } | 151 } |
| 313 } | 152 } |
| 153 |
| 314 if (update_estimate) { | 154 if (update_estimate) { |
| 315 last_update_ms_ = now_ms; | 155 last_update_ms_ = now_ms; |
| 316 observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate_bps); | 156 observer_->OnReceiveBitrateChanged({kFixedSsrc}, target_bitrate_bps); |
| 317 } | 157 } |
| 318 } | 158 } |
| 319 | 159 |
| 320 void DelayBasedBwe::Process() {} | 160 void DelayBasedBwe::Process() {} |
| 321 | 161 |
| 322 int64_t DelayBasedBwe::TimeUntilNextProcess() { | 162 int64_t DelayBasedBwe::TimeUntilNextProcess() { |
| 323 const int64_t kDisabledModuleTime = 1000; | 163 const int64_t kDisabledModuleTime = 1000; |
| 324 return kDisabledModuleTime; | 164 return kDisabledModuleTime; |
| 325 } | 165 } |
| 326 | 166 |
| 327 void DelayBasedBwe::TimeoutStreams(int64_t now_ms) { | |
| 328 for (Ssrcs::iterator it = ssrcs_.begin(); it != ssrcs_.end();) { | |
| 329 if ((now_ms - it->second) > kStreamTimeOutMs) { | |
| 330 ssrcs_.erase(it++); | |
| 331 } else { | |
| 332 ++it; | |
| 333 } | |
| 334 } | |
| 335 if (ssrcs_.empty()) { | |
| 336 // We can't update the estimate if we don't have any active streams. | |
| 337 inter_arrival_.reset( | |
| 338 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, | |
| 339 kTimestampToMs, true)); | |
| 340 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); | |
| 341 // We deliberately don't reset the first_packet_time_ms_ here for now since | |
| 342 // we only probe for bandwidth in the beginning of a call right now. | |
| 343 } | |
| 344 } | |
| 345 | |
| 346 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 167 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
| 347 rtc::CritScope lock(&crit_); | 168 rtc::CritScope lock(&crit_); |
| 348 remote_rate_.SetRtt(avg_rtt_ms); | 169 remote_rate_.SetRtt(avg_rtt_ms); |
| 349 } | 170 } |
| 350 | 171 |
| 351 void DelayBasedBwe::RemoveStream(uint32_t ssrc) { | 172 void DelayBasedBwe::RemoveStream(uint32_t ssrc) {} |
| 352 rtc::CritScope lock(&crit_); | |
| 353 ssrcs_.erase(ssrc); | |
| 354 } | |
| 355 | 173 |
| 356 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, | 174 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
| 357 uint32_t* bitrate_bps) const { | 175 uint32_t* bitrate_bps) const { |
| 358 // Currently accessed from both the process thread (see | 176 // Currently accessed from both the process thread (see |
| 359 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see | 177 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see |
| 360 // Call::GetStats()). Should in the future only be accessed from a single | 178 // Call::GetStats()). Should in the future only be accessed from a single |
| 361 // thread. | 179 // thread. |
| 362 RTC_DCHECK(ssrcs); | 180 RTC_DCHECK(ssrcs); |
| 363 RTC_DCHECK(bitrate_bps); | 181 RTC_DCHECK(bitrate_bps); |
| 364 rtc::CritScope lock(&crit_); | 182 rtc::CritScope lock(&crit_); |
| 365 if (!remote_rate_.ValidEstimate()) { | 183 if (!remote_rate_.ValidEstimate()) |
| 366 return false; | 184 return false; |
| 367 } | 185 |
| 368 *ssrcs = Keys(ssrcs_); | 186 *ssrcs = {kFixedSsrc}; |
| 369 if (ssrcs_.empty()) { | 187 *bitrate_bps = remote_rate_.LatestEstimate(); |
| 370 *bitrate_bps = 0; | |
| 371 } else { | |
| 372 *bitrate_bps = remote_rate_.LatestEstimate(); | |
| 373 } | |
| 374 return true; | 188 return true; |
| 375 } | 189 } |
| 376 | 190 |
| 377 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { | 191 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
| 378 // Called from both the configuration thread and the network thread. Shouldn't | 192 // Called from both the configuration thread and the network thread. Shouldn't |
| 379 // be called from the network thread in the future. | 193 // be called from the network thread in the future. |
| 380 rtc::CritScope lock(&crit_); | 194 rtc::CritScope lock(&crit_); |
| 381 remote_rate_.SetMinBitrate(min_bitrate_bps); | 195 remote_rate_.SetMinBitrate(min_bitrate_bps); |
| 382 } | 196 } |
| 383 } // namespace webrtc | 197 } // namespace webrtc |
| OLD | NEW |