Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 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/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" | 11 #include "webrtc/modules/congestion_controller/delay_based_bandwidth_estimator.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/typedefs.h" | 24 #include "webrtc/typedefs.h" |
| 25 | 25 |
| 26 namespace webrtc { | 26 namespace { |
| 27 | |
| 28 enum { | 27 enum { |
| 29 kTimestampGroupLengthMs = 5, | 28 kTimestampGroupLengthMs = 5, |
| 30 kAbsSendTimeFraction = 18, | 29 kAbsSendTimeFraction = 18, |
| 31 kAbsSendTimeInterArrivalUpshift = 8, | 30 kAbsSendTimeInterArrivalUpshift = 8, |
| 32 kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, | 31 kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, |
| 33 kInitialProbingIntervalMs = 2000, | 32 kInitialProbingIntervalMs = 2000, |
| 34 kMinClusterSize = 4, | 33 kMinClusterSize = 4, |
| 35 kMaxProbePackets = 15, | 34 kMaxProbePackets = 15, |
| 36 kExpectedNumberOfProbes = 3 | 35 kExpectedNumberOfProbes = 3 |
| 37 }; | 36 }; |
| 38 | 37 |
| 39 static const double kTimestampToMs = 1000.0 / | |
| 40 static_cast<double>(1 << kInterArrivalShift); | |
| 41 | |
| 42 template<typename K, typename V> | |
| 43 std::vector<K> Keys(const std::map<K, V>& map) { | |
| 44 std::vector<K> keys; | |
| 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) { | 38 uint32_t ConvertMsTo24Bits(int64_t time_ms) { |
| 54 uint32_t time_24_bits = | 39 uint32_t time_24_bits = |
| 55 static_cast<uint32_t>( | 40 static_cast<uint32_t>( |
| 56 ((static_cast<uint64_t>(time_ms) << kAbsSendTimeFraction) + 500) / | 41 ((static_cast<uint64_t>(time_ms) << kAbsSendTimeFraction) + 500) / |
| 57 1000) & | 42 1000) & |
| 58 0x00FFFFFF; | 43 0x00FFFFFF; |
| 59 return time_24_bits; | 44 return time_24_bits; |
| 60 } | 45 } |
| 61 | 46 |
| 62 bool RemoteBitrateEstimatorAbsSendTime::IsWithinClusterBounds( | 47 static const double kTimestampToMs = |
|
danilchap
2016/06/03 16:25:28
to make review easier, try keep the order same as
philipel
2016/06/08 11:46:38
Order fixed.
| |
| 63 int send_delta_ms, | 48 1000.0 / static_cast<double>(1 << kInterArrivalShift); |
| 64 const Cluster& cluster_aggregate) { | 49 |
| 65 if (cluster_aggregate.count == 0) | 50 template <typename K, typename V> |
| 66 return true; | 51 std::vector<K> Keys(const std::map<K, V>& map) { |
| 67 float cluster_mean = cluster_aggregate.send_mean_ms / | 52 std::vector<K> keys; |
| 68 static_cast<float>(cluster_aggregate.count); | 53 keys.reserve(map.size()); |
| 69 return fabs(static_cast<float>(send_delta_ms) - cluster_mean) < 2.5f; | 54 for (typename std::map<K, V>::const_iterator it = map.begin(); |
| 55 it != map.end(); ++it) { | |
| 56 keys.push_back(it->first); | |
| 70 } | 57 } |
| 58 return keys; | |
| 59 } | |
| 60 } // namespace | |
| 71 | 61 |
| 72 void RemoteBitrateEstimatorAbsSendTime::AddCluster( | 62 namespace webrtc { |
| 73 std::list<Cluster>* clusters, | |
| 74 Cluster* cluster) { | |
| 75 cluster->send_mean_ms /= static_cast<float>(cluster->count); | |
| 76 cluster->recv_mean_ms /= static_cast<float>(cluster->count); | |
| 77 cluster->mean_size /= cluster->count; | |
| 78 clusters->push_back(*cluster); | |
| 79 } | |
| 80 | 63 |
| 81 RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime( | 64 void DelayBasedBwe::AddCluster(std::list<Cluster>* clusters, Cluster* cluster) { |
| 82 RemoteBitrateObserver* observer) | 65 cluster->send_mean_ms /= static_cast<float>(cluster->count); |
| 83 : observer_(observer), | 66 cluster->recv_mean_ms /= static_cast<float>(cluster->count); |
| 84 inter_arrival_(), | 67 cluster->mean_size /= cluster->count; |
| 85 estimator_(), | 68 clusters->push_back(*cluster); |
| 86 detector_(OverUseDetectorOptions()), | |
| 87 incoming_bitrate_(kBitrateWindowMs, 8000), | |
| 88 total_probes_received_(0), | |
| 89 first_packet_time_ms_(-1), | |
| 90 last_update_ms_(-1), | |
| 91 ssrcs_() { | |
| 92 RTC_DCHECK(observer_); | |
| 93 LOG(LS_INFO) << "RemoteBitrateEstimatorAbsSendTime: Instantiating."; | |
| 94 network_thread_.DetachFromThread(); | |
| 95 } | 69 } |
| 96 | 70 |
| 97 void RemoteBitrateEstimatorAbsSendTime::ComputeClusters( | 71 DelayBasedBwe::DelayBasedBwe(RemoteBitrateObserver* observer) |
| 98 std::list<Cluster>* clusters) const { | 72 : observer_(observer), |
| 73 inter_arrival_(), | |
| 74 estimator_(), | |
| 75 detector_(OverUseDetectorOptions()), | |
| 76 incoming_bitrate_(kBitrateWindowMs, 8000), | |
| 77 total_probes_received_(0), | |
| 78 first_packet_time_ms_(-1), | |
| 79 last_update_ms_(-1), | |
| 80 ssrcs_() { | |
| 81 RTC_DCHECK(observer_); | |
| 82 // XXX(philipel): The BitrateEstimatorTest relies on this EXACT log line. | |
| 83 LOG(LS_INFO) << "RemoteBitrateEstimatorAbsSendTime: Instantiating."; | |
| 84 network_thread_.DetachFromThread(); | |
| 85 } | |
| 86 | |
| 87 void DelayBasedBwe::ComputeClusters(std::list<Cluster>* clusters) const { | |
| 99 Cluster current; | 88 Cluster current; |
| 100 int64_t prev_send_time = -1; | 89 int64_t prev_send_time = -1; |
| 101 int64_t prev_recv_time = -1; | 90 int64_t prev_recv_time = -1; |
| 91 int last_probe_cluster_id = -1; | |
| 102 for (std::list<Probe>::const_iterator it = probes_.begin(); | 92 for (std::list<Probe>::const_iterator it = probes_.begin(); |
| 103 it != probes_.end(); | 93 it != probes_.end(); ++it) { |
| 104 ++it) { | 94 if (last_probe_cluster_id == -1) |
| 95 last_probe_cluster_id = it->probe_cluster_id; | |
| 105 if (prev_send_time >= 0) { | 96 if (prev_send_time >= 0) { |
| 106 int send_delta_ms = it->send_time_ms - prev_send_time; | 97 int send_delta_ms = it->send_time_ms - prev_send_time; |
| 107 int recv_delta_ms = it->recv_time_ms - prev_recv_time; | 98 int recv_delta_ms = it->recv_time_ms - prev_recv_time; |
| 108 if (send_delta_ms >= 1 && recv_delta_ms >= 1) { | 99 if (send_delta_ms >= 1 && recv_delta_ms >= 1) { |
| 109 ++current.num_above_min_delta; | 100 ++current.num_above_min_delta; |
| 110 } | 101 } |
| 111 if (!IsWithinClusterBounds(send_delta_ms, current)) { | 102 if (it->probe_cluster_id == last_probe_cluster_id) { |
|
stefan-webrtc
2016/06/08 08:57:09
Is this correct? Seems like this is equal to IsWit
philipel
2016/06/08 11:46:38
This is not correct, fixed.
| |
| 112 if (current.count >= kMinClusterSize) | 103 if (current.count >= kMinClusterSize) |
| 113 AddCluster(clusters, ¤t); | 104 AddCluster(clusters, ¤t); |
| 114 current = Cluster(); | 105 current = Cluster(); |
| 115 } | 106 } |
| 116 current.send_mean_ms += send_delta_ms; | 107 current.send_mean_ms += send_delta_ms; |
| 117 current.recv_mean_ms += recv_delta_ms; | 108 current.recv_mean_ms += recv_delta_ms; |
| 118 current.mean_size += it->payload_size; | 109 current.mean_size += it->payload_size; |
| 119 ++current.count; | 110 ++current.count; |
| 120 } | 111 } |
| 121 prev_send_time = it->send_time_ms; | 112 prev_send_time = it->send_time_ms; |
| 122 prev_recv_time = it->recv_time_ms; | 113 prev_recv_time = it->recv_time_ms; |
| 123 } | 114 } |
| 124 if (current.count >= kMinClusterSize) | 115 if (current.count >= kMinClusterSize) |
| 125 AddCluster(clusters, ¤t); | 116 AddCluster(clusters, ¤t); |
| 126 } | 117 } |
| 127 | 118 |
| 128 std::list<Cluster>::const_iterator | 119 std::list<DelayBasedBwe::Cluster>::const_iterator DelayBasedBwe::FindBestProbe( |
| 129 RemoteBitrateEstimatorAbsSendTime::FindBestProbe( | |
| 130 const std::list<Cluster>& clusters) const { | 120 const std::list<Cluster>& clusters) const { |
| 131 int highest_probe_bitrate_bps = 0; | 121 int highest_probe_bitrate_bps = 0; |
| 132 std::list<Cluster>::const_iterator best_it = clusters.end(); | 122 std::list<Cluster>::const_iterator best_it = clusters.end(); |
| 133 for (std::list<Cluster>::const_iterator it = clusters.begin(); | 123 for (std::list<Cluster>::const_iterator it = clusters.begin(); |
| 134 it != clusters.end(); | 124 it != clusters.end(); ++it) { |
| 135 ++it) { | |
| 136 if (it->send_mean_ms == 0 || it->recv_mean_ms == 0) | 125 if (it->send_mean_ms == 0 || it->recv_mean_ms == 0) |
| 137 continue; | 126 continue; |
| 138 int send_bitrate_bps = it->mean_size * 8 * 1000 / it->send_mean_ms; | 127 int send_bitrate_bps = it->mean_size * 8 * 1000 / it->send_mean_ms; |
| 139 int recv_bitrate_bps = it->mean_size * 8 * 1000 / it->recv_mean_ms; | 128 int recv_bitrate_bps = it->mean_size * 8 * 1000 / it->recv_mean_ms; |
| 140 if (it->num_above_min_delta > it->count / 2 && | 129 if (it->num_above_min_delta > it->count / 2 && |
| 141 (it->recv_mean_ms - it->send_mean_ms <= 2.0f && | 130 (it->recv_mean_ms - it->send_mean_ms <= 2.0f && |
| 142 it->send_mean_ms - it->recv_mean_ms <= 5.0f)) { | 131 it->send_mean_ms - it->recv_mean_ms <= 5.0f)) { |
| 143 int probe_bitrate_bps = | 132 int probe_bitrate_bps = |
| 144 std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps()); | 133 std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps()); |
| 145 if (probe_bitrate_bps > highest_probe_bitrate_bps) { | 134 if (probe_bitrate_bps > highest_probe_bitrate_bps) { |
| 146 highest_probe_bitrate_bps = probe_bitrate_bps; | 135 highest_probe_bitrate_bps = probe_bitrate_bps; |
| 147 best_it = it; | 136 best_it = it; |
| 148 } | 137 } |
| 149 } else { | 138 } else { |
| 150 LOG(LS_INFO) << "Probe failed, sent at " << send_bitrate_bps | 139 LOG(LS_INFO) << "Probe failed, sent at " << send_bitrate_bps |
| 151 << " bps, received at " << recv_bitrate_bps | 140 << " bps, received at " << recv_bitrate_bps |
| 152 << " bps. Mean send delta: " << it->send_mean_ms | 141 << " bps. Mean send delta: " << it->send_mean_ms |
| 153 << " ms, mean recv delta: " << it->recv_mean_ms | 142 << " ms, mean recv delta: " << it->recv_mean_ms |
| 154 << " ms, num probes: " << it->count; | 143 << " ms, num probes: " << it->count; |
| 155 break; | 144 break; |
| 156 } | 145 } |
| 157 } | 146 } |
| 158 return best_it; | 147 return best_it; |
| 159 } | 148 } |
| 160 | 149 |
| 161 RemoteBitrateEstimatorAbsSendTime::ProbeResult | 150 DelayBasedBwe::ProbeResult DelayBasedBwe::ProcessClusters(int64_t now_ms) { |
| 162 RemoteBitrateEstimatorAbsSendTime::ProcessClusters(int64_t now_ms) { | |
| 163 std::list<Cluster> clusters; | 151 std::list<Cluster> clusters; |
| 164 ComputeClusters(&clusters); | 152 ComputeClusters(&clusters); |
| 165 if (clusters.empty()) { | 153 if (clusters.empty()) { |
| 166 // If we reach the max number of probe packets and still have no clusters, | 154 // If we reach the max number of probe packets and still have no clusters, |
| 167 // we will remove the oldest one. | 155 // we will remove the oldest one. |
| 168 if (probes_.size() >= kMaxProbePackets) | 156 if (probes_.size() >= kMaxProbePackets) |
| 169 probes_.pop_front(); | 157 probes_.pop_front(); |
| 170 return ProbeResult::kNoUpdate; | 158 return ProbeResult::kNoUpdate; |
| 171 } | 159 } |
| 172 | 160 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 188 } | 176 } |
| 189 } | 177 } |
| 190 | 178 |
| 191 // Not probing and received non-probe packet, or finished with current set | 179 // Not probing and received non-probe packet, or finished with current set |
| 192 // of probes. | 180 // of probes. |
| 193 if (clusters.size() >= kExpectedNumberOfProbes) | 181 if (clusters.size() >= kExpectedNumberOfProbes) |
| 194 probes_.clear(); | 182 probes_.clear(); |
| 195 return ProbeResult::kNoUpdate; | 183 return ProbeResult::kNoUpdate; |
| 196 } | 184 } |
| 197 | 185 |
| 198 bool RemoteBitrateEstimatorAbsSendTime::IsBitrateImproving( | 186 bool DelayBasedBwe::IsBitrateImproving(int new_bitrate_bps) const { |
| 199 int new_bitrate_bps) const { | |
| 200 bool initial_probe = !remote_rate_.ValidEstimate() && new_bitrate_bps > 0; | 187 bool initial_probe = !remote_rate_.ValidEstimate() && new_bitrate_bps > 0; |
| 201 bool bitrate_above_estimate = | 188 bool bitrate_above_estimate = |
| 202 remote_rate_.ValidEstimate() && | 189 remote_rate_.ValidEstimate() && |
| 203 new_bitrate_bps > static_cast<int>(remote_rate_.LatestEstimate()); | 190 new_bitrate_bps > static_cast<int>(remote_rate_.LatestEstimate()); |
| 204 return initial_probe || bitrate_above_estimate; | 191 return initial_probe || bitrate_above_estimate; |
| 205 } | 192 } |
| 206 | 193 |
| 207 void RemoteBitrateEstimatorAbsSendTime::IncomingPacketFeedbackVector( | 194 void DelayBasedBwe::IncomingPacketFeedbackVector( |
| 208 const std::vector<PacketInfo>& packet_feedback_vector) { | 195 const std::vector<PacketInfo>& packet_feedback_vector) { |
| 209 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 196 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
| 210 for (const auto& packet_info : packet_feedback_vector) { | 197 for (const auto& packet_info : packet_feedback_vector) { |
| 211 IncomingPacketInfo(packet_info.arrival_time_ms, | 198 IncomingPacketInfo(packet_info.arrival_time_ms, |
| 212 ConvertMsTo24Bits(packet_info.send_time_ms), | 199 ConvertMsTo24Bits(packet_info.send_time_ms), |
| 213 packet_info.payload_size, 0, packet_info.was_paced); | 200 packet_info.payload_size, 0, packet_info.was_paced, |
| 201 packet_info.probe_cluster_id); | |
| 214 } | 202 } |
| 215 } | 203 } |
| 216 | 204 |
| 217 void RemoteBitrateEstimatorAbsSendTime::IncomingPacket(int64_t arrival_time_ms, | 205 void DelayBasedBwe::IncomingPacket(int64_t arrival_time_ms, |
| 218 size_t payload_size, | 206 size_t payload_size, |
| 219 const RTPHeader& header, | 207 const RTPHeader& header, |
| 220 bool was_paced) { | 208 bool was_paced) { |
| 221 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 209 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
| 222 if (!header.extension.hasAbsoluteSendTime) { | 210 if (!header.extension.hasAbsoluteSendTime) { |
| 223 LOG(LS_WARNING) << "RemoteBitrateEstimatorAbsSendTimeImpl: Incoming packet " | 211 // XXX(philipel): The BitrateEstimatorTest relies on this EXACT log line. |
| 212 LOG(LS_WARNING) << "RemoteBitrateEstimatorAbsSendTime: Incoming packet " | |
| 224 "is missing absolute send time extension!"; | 213 "is missing absolute send time extension!"; |
| 225 return; | 214 return; |
| 226 } | 215 } |
| 227 IncomingPacketInfo(arrival_time_ms, header.extension.absoluteSendTime, | 216 IncomingPacketInfo(arrival_time_ms, header.extension.absoluteSendTime, |
| 228 payload_size, header.ssrc, was_paced); | 217 payload_size, header.ssrc, was_paced, |
| 218 PacketInfo::kNotAProbe); | |
| 229 } | 219 } |
| 230 | 220 |
| 231 void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo( | 221 void DelayBasedBwe::IncomingPacketInfo(int64_t arrival_time_ms, |
| 232 int64_t arrival_time_ms, | 222 uint32_t send_time_24bits, |
| 233 uint32_t send_time_24bits, | 223 size_t payload_size, |
| 234 size_t payload_size, | 224 uint32_t ssrc, |
| 235 uint32_t ssrc, | 225 bool was_paced, |
| 236 bool was_paced) { | 226 int probe_cluster_id) { |
| 237 assert(send_time_24bits < (1ul << 24)); | 227 assert(send_time_24bits < (1ul << 24)); |
| 238 // Shift up send time to use the full 32 bits that inter_arrival works with, | 228 // Shift up send time to use the full 32 bits that inter_arrival works with, |
| 239 // so wrapping works properly. | 229 // so wrapping works properly. |
| 240 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; | 230 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; |
| 241 int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs; | 231 int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs; |
| 242 | 232 |
| 243 int64_t now_ms = arrival_time_ms; | 233 int64_t now_ms = arrival_time_ms; |
| 244 // TODO(holmer): SSRCs are only needed for REMB, should be broken out from | 234 // TODO(holmer): SSRCs are only needed for REMB, should be broken out from |
| 245 // here. | 235 // here. |
| 246 incoming_bitrate_.Update(payload_size, now_ms); | 236 incoming_bitrate_.Update(payload_size, now_ms); |
| 247 | 237 |
| 248 if (first_packet_time_ms_ == -1) | 238 if (first_packet_time_ms_ == -1) |
| 249 first_packet_time_ms_ = arrival_time_ms; | 239 first_packet_time_ms_ = arrival_time_ms; |
| 250 | 240 |
| 251 uint32_t ts_delta = 0; | 241 uint32_t ts_delta = 0; |
| 252 int64_t t_delta = 0; | 242 int64_t t_delta = 0; |
| 253 int size_delta = 0; | 243 int size_delta = 0; |
| 254 // For now only try to detect probes while we don't have a valid estimate, and | 244 |
| 255 // make sure the packet was paced. We currently assume that only packets | |
| 256 // larger than 200 bytes are paced by the sender. | |
|
stefan-webrtc
2016/06/08 08:57:09
Should we keep this comment at line 255?
philipel
2016/06/08 11:46:38
Done.
| |
| 257 was_paced = was_paced && payload_size > PacedSender::kMinProbePacketSize; | |
| 258 bool update_estimate = false; | 245 bool update_estimate = false; |
| 259 uint32_t target_bitrate_bps = 0; | 246 uint32_t target_bitrate_bps = 0; |
| 260 std::vector<uint32_t> ssrcs; | 247 std::vector<uint32_t> ssrcs; |
| 261 { | 248 { |
| 262 rtc::CritScope lock(&crit_); | 249 rtc::CritScope lock(&crit_); |
| 263 | 250 |
| 264 TimeoutStreams(now_ms); | 251 TimeoutStreams(now_ms); |
| 265 RTC_DCHECK(inter_arrival_.get()); | 252 RTC_DCHECK(inter_arrival_.get()); |
| 266 RTC_DCHECK(estimator_.get()); | 253 RTC_DCHECK(estimator_.get()); |
| 267 ssrcs_[ssrc] = now_ms; | 254 ssrcs_[ssrc] = now_ms; |
| 268 | 255 |
| 269 if (was_paced && | 256 if (probe_cluster_id != PacketInfo::kNotAProbe && |
| 257 payload_size > PacedSender::kMinProbePacketSize && | |
| 270 (!remote_rate_.ValidEstimate() || | 258 (!remote_rate_.ValidEstimate() || |
| 271 now_ms - first_packet_time_ms_ < kInitialProbingIntervalMs)) { | 259 now_ms - first_packet_time_ms_ < kInitialProbingIntervalMs)) { |
| 272 // TODO(holmer): Use a map instead to get correct order? | 260 // TODO(holmer): Use a map instead to get correct order? |
| 273 if (total_probes_received_ < kMaxProbePackets) { | 261 if (total_probes_received_ < kMaxProbePackets) { |
| 274 int send_delta_ms = -1; | 262 int send_delta_ms = -1; |
| 275 int recv_delta_ms = -1; | 263 int recv_delta_ms = -1; |
| 276 if (!probes_.empty()) { | 264 if (!probes_.empty()) { |
| 277 send_delta_ms = send_time_ms - probes_.back().send_time_ms; | 265 send_delta_ms = send_time_ms - probes_.back().send_time_ms; |
| 278 recv_delta_ms = arrival_time_ms - probes_.back().recv_time_ms; | 266 recv_delta_ms = arrival_time_ms - probes_.back().recv_time_ms; |
| 279 } | 267 } |
| 280 LOG(LS_INFO) << "Probe packet received: send time=" << send_time_ms | 268 LOG(LS_INFO) << "Probe packet received: send time=" << send_time_ms |
| 281 << " ms, recv time=" << arrival_time_ms | 269 << " ms, recv time=" << arrival_time_ms |
| 282 << " ms, send delta=" << send_delta_ms | 270 << " ms, send delta=" << send_delta_ms |
| 283 << " ms, recv delta=" << recv_delta_ms << " ms."; | 271 << " ms, recv delta=" << recv_delta_ms << " ms."; |
| 284 } | 272 } |
| 285 probes_.push_back(Probe(send_time_ms, arrival_time_ms, payload_size)); | 273 probes_.push_back( |
| 274 Probe(send_time_ms, arrival_time_ms, payload_size, probe_cluster_id)); | |
| 286 ++total_probes_received_; | 275 ++total_probes_received_; |
| 287 // Make sure that a probe which updated the bitrate immediately has an | 276 // Make sure that a probe which updated the bitrate immediately has an |
| 288 // effect by calling the OnReceiveBitrateChanged callback. | 277 // effect by calling the OnReceiveBitrateChanged callback. |
| 289 if (ProcessClusters(now_ms) == ProbeResult::kBitrateUpdated) | 278 if (ProcessClusters(now_ms) == ProbeResult::kBitrateUpdated) |
| 290 update_estimate = true; | 279 update_estimate = true; |
| 291 } | 280 } |
| 292 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, payload_size, | 281 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, payload_size, |
| 293 &ts_delta, &t_delta, &size_delta)) { | 282 &ts_delta, &t_delta, &size_delta)) { |
| 294 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); | 283 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); |
| 295 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State()); | 284 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 322 update_estimate = remote_rate_.ValidEstimate(); | 311 update_estimate = remote_rate_.ValidEstimate(); |
| 323 ssrcs = Keys(ssrcs_); | 312 ssrcs = Keys(ssrcs_); |
| 324 } | 313 } |
| 325 } | 314 } |
| 326 if (update_estimate) { | 315 if (update_estimate) { |
| 327 last_update_ms_ = now_ms; | 316 last_update_ms_ = now_ms; |
| 328 observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate_bps); | 317 observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate_bps); |
| 329 } | 318 } |
| 330 } | 319 } |
| 331 | 320 |
| 332 void RemoteBitrateEstimatorAbsSendTime::Process() {} | 321 void DelayBasedBwe::Process() {} |
| 333 | 322 |
| 334 int64_t RemoteBitrateEstimatorAbsSendTime::TimeUntilNextProcess() { | 323 int64_t DelayBasedBwe::TimeUntilNextProcess() { |
| 335 const int64_t kDisabledModuleTime = 1000; | 324 const int64_t kDisabledModuleTime = 1000; |
| 336 return kDisabledModuleTime; | 325 return kDisabledModuleTime; |
| 337 } | 326 } |
| 338 | 327 |
| 339 void RemoteBitrateEstimatorAbsSendTime::TimeoutStreams(int64_t now_ms) { | 328 void DelayBasedBwe::TimeoutStreams(int64_t now_ms) { |
| 340 for (Ssrcs::iterator it = ssrcs_.begin(); it != ssrcs_.end();) { | 329 for (Ssrcs::iterator it = ssrcs_.begin(); it != ssrcs_.end();) { |
| 341 if ((now_ms - it->second) > kStreamTimeOutMs) { | 330 if ((now_ms - it->second) > kStreamTimeOutMs) { |
| 342 ssrcs_.erase(it++); | 331 ssrcs_.erase(it++); |
| 343 } else { | 332 } else { |
| 344 ++it; | 333 ++it; |
| 345 } | 334 } |
| 346 } | 335 } |
| 347 if (ssrcs_.empty()) { | 336 if (ssrcs_.empty()) { |
| 348 // We can't update the estimate if we don't have any active streams. | 337 // We can't update the estimate if we don't have any active streams. |
| 349 inter_arrival_.reset( | 338 inter_arrival_.reset( |
| 350 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, | 339 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, |
| 351 kTimestampToMs, true)); | 340 kTimestampToMs, true)); |
| 352 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); | 341 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); |
| 353 // We deliberately don't reset the first_packet_time_ms_ here for now since | 342 // We deliberately don't reset the first_packet_time_ms_ here for now since |
| 354 // we only probe for bandwidth in the beginning of a call right now. | 343 // we only probe for bandwidth in the beginning of a call right now. |
| 355 } | 344 } |
| 356 } | 345 } |
| 357 | 346 |
| 358 void RemoteBitrateEstimatorAbsSendTime::OnRttUpdate(int64_t avg_rtt_ms, | 347 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
| 359 int64_t max_rtt_ms) { | |
| 360 rtc::CritScope lock(&crit_); | 348 rtc::CritScope lock(&crit_); |
| 361 remote_rate_.SetRtt(avg_rtt_ms); | 349 remote_rate_.SetRtt(avg_rtt_ms); |
| 362 } | 350 } |
| 363 | 351 |
| 364 void RemoteBitrateEstimatorAbsSendTime::RemoveStream(uint32_t ssrc) { | 352 void DelayBasedBwe::RemoveStream(uint32_t ssrc) { |
| 365 rtc::CritScope lock(&crit_); | 353 rtc::CritScope lock(&crit_); |
| 366 ssrcs_.erase(ssrc); | 354 ssrcs_.erase(ssrc); |
| 367 } | 355 } |
| 368 | 356 |
| 369 bool RemoteBitrateEstimatorAbsSendTime::LatestEstimate( | 357 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
| 370 std::vector<uint32_t>* ssrcs, | 358 uint32_t* bitrate_bps) const { |
| 371 uint32_t* bitrate_bps) const { | |
| 372 // Currently accessed from both the process thread (see | 359 // Currently accessed from both the process thread (see |
| 373 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see | 360 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see |
| 374 // Call::GetStats()). Should in the future only be accessed from a single | 361 // Call::GetStats()). Should in the future only be accessed from a single |
| 375 // thread. | 362 // thread. |
| 376 RTC_DCHECK(ssrcs); | 363 RTC_DCHECK(ssrcs); |
| 377 RTC_DCHECK(bitrate_bps); | 364 RTC_DCHECK(bitrate_bps); |
| 378 rtc::CritScope lock(&crit_); | 365 rtc::CritScope lock(&crit_); |
| 379 if (!remote_rate_.ValidEstimate()) { | 366 if (!remote_rate_.ValidEstimate()) { |
| 380 return false; | 367 return false; |
| 381 } | 368 } |
| 382 *ssrcs = Keys(ssrcs_); | 369 *ssrcs = Keys(ssrcs_); |
| 383 if (ssrcs_.empty()) { | 370 if (ssrcs_.empty()) { |
| 384 *bitrate_bps = 0; | 371 *bitrate_bps = 0; |
| 385 } else { | 372 } else { |
| 386 *bitrate_bps = remote_rate_.LatestEstimate(); | 373 *bitrate_bps = remote_rate_.LatestEstimate(); |
| 387 } | 374 } |
| 388 return true; | 375 return true; |
| 389 } | 376 } |
| 390 | 377 |
| 391 void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int min_bitrate_bps) { | 378 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
| 392 // Called from both the configuration thread and the network thread. Shouldn't | 379 // Called from both the configuration thread and the network thread. Shouldn't |
| 393 // be called from the network thread in the future. | 380 // be called from the network thread in the future. |
| 394 rtc::CritScope lock(&crit_); | 381 rtc::CritScope lock(&crit_); |
| 395 remote_rate_.SetMinBitrate(min_bitrate_bps); | 382 remote_rate_.SetMinBitrate(min_bitrate_bps); |
| 396 } | 383 } |
| 397 } // namespace webrtc | 384 } // namespace webrtc |
| OLD | NEW |