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 |
(...skipping 27 matching lines...) Expand all Loading... | |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 namespace webrtc { | 40 namespace webrtc { |
41 | 41 |
42 DelayBasedBwe::DelayBasedBwe(Clock* clock) | 42 DelayBasedBwe::DelayBasedBwe(Clock* clock) |
43 : clock_(clock), | 43 : clock_(clock), |
44 inter_arrival_(), | 44 inter_arrival_(), |
45 estimator_(), | 45 estimator_(), |
46 detector_(OverUseDetectorOptions()), | 46 detector_(OverUseDetectorOptions()), |
47 receiver_incoming_bitrate_(kBitrateWindowMs, 8000), | 47 receiver_incoming_bitrate_(kBitrateWindowMs, 8000), |
48 last_update_ms_(-1), | |
49 last_seen_packet_ms_(-1), | 48 last_seen_packet_ms_(-1), |
50 uma_recorded_(false) { | 49 uma_recorded_(false) { |
51 network_thread_.DetachFromThread(); | 50 network_thread_.DetachFromThread(); |
52 } | 51 } |
53 | 52 |
54 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( | 53 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( |
55 const std::vector<PacketInfo>& packet_feedback_vector) { | 54 const std::vector<PacketInfo>& packet_feedback_vector) { |
56 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 55 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
57 if (!uma_recorded_) { | 56 if (!uma_recorded_) { |
58 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, | 57 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, |
59 BweNames::kSendSideTransportSeqNum, | 58 BweNames::kSendSideTransportSeqNum, |
60 BweNames::kBweNamesMax); | 59 BweNames::kBweNamesMax); |
61 uma_recorded_ = true; | 60 uma_recorded_ = true; |
62 } | 61 } |
62 | |
63 int64_t now_ms = clock_->TimeInMilliseconds(); | |
63 Result aggregated_result; | 64 Result aggregated_result; |
64 for (const auto& packet_info : packet_feedback_vector) { | 65 for (const auto& packet_info : packet_feedback_vector) { |
65 Result result = IncomingPacketInfo(packet_info); | 66 aggregated_result = IncomingPacketInfo(packet_info, now_ms); |
66 if (result.updated) | |
67 aggregated_result = result; | |
68 } | 67 } |
68 aggregated_result.target_bitrate_bps = | |
69 rate_control_.UpdateBandwidthEstimate(now_ms); | |
70 aggregated_result.updated = rate_control_.ValidEstimate(); | |
69 return aggregated_result; | 71 return aggregated_result; |
70 } | 72 } |
71 | 73 |
72 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( | 74 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo(const PacketInfo& info, |
73 const PacketInfo& info) { | 75 int64_t now_ms) { |
74 int64_t now_ms = clock_->TimeInMilliseconds(); | |
75 | |
76 receiver_incoming_bitrate_.Update(info.payload_size, info.arrival_time_ms); | 76 receiver_incoming_bitrate_.Update(info.payload_size, info.arrival_time_ms); |
77 Result result; | |
78 // Reset if the stream has timed out. | 77 // Reset if the stream has timed out. |
79 if (last_seen_packet_ms_ == -1 || | 78 if (last_seen_packet_ms_ == -1 || |
80 now_ms - last_seen_packet_ms_ > kStreamTimeOutMs) { | 79 now_ms - last_seen_packet_ms_ > kStreamTimeOutMs) { |
81 inter_arrival_.reset( | 80 inter_arrival_.reset( |
82 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, | 81 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, |
83 kTimestampToMs, true)); | 82 kTimestampToMs, true)); |
84 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); | 83 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); |
85 } | 84 } |
86 last_seen_packet_ms_ = now_ms; | 85 last_seen_packet_ms_ = now_ms; |
87 | 86 |
(...skipping 17 matching lines...) Expand all Loading... | |
105 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State(), | 104 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State(), |
106 info.arrival_time_ms); | 105 info.arrival_time_ms); |
107 detector_.Detect(estimator_->offset(), ts_delta_ms, | 106 detector_.Detect(estimator_->offset(), ts_delta_ms, |
108 estimator_->num_of_deltas(), info.arrival_time_ms); | 107 estimator_->num_of_deltas(), info.arrival_time_ms); |
109 } | 108 } |
110 | 109 |
111 int probing_bps = 0; | 110 int probing_bps = 0; |
112 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { | 111 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { |
113 probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); | 112 probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); |
114 } | 113 } |
115 | 114 if (detector_.State() != kBwOverusing && probing_bps > 0) { |
116 // Currently overusing the bandwidth. | |
117 if (detector_.State() == kBwOverusing) { | |
118 rtc::Optional<uint32_t> incoming_rate = | |
119 receiver_incoming_bitrate_.Rate(info.arrival_time_ms); | |
120 if (incoming_rate && | |
121 rate_control_.TimeToReduceFurther(now_ms, *incoming_rate)) { | |
stefan-webrtc
2016/10/26 15:19:20
Isn't this check still desirable? We shouldn't red
michaelt
2016/10/27 14:42:59
I removed it because it seamed strange to increase
stefan-webrtc
2016/10/31 15:08:49
I don't think I agree. Increasing is fine to do in
| |
122 result.updated = UpdateEstimate(info.arrival_time_ms, now_ms, | |
123 &result.target_bitrate_bps); | |
124 } | |
125 } else if (probing_bps > 0) { | |
126 // No overuse, but probing measured a bitrate. | 115 // No overuse, but probing measured a bitrate. |
127 rate_control_.SetEstimate(probing_bps, info.arrival_time_ms); | 116 rate_control_.SetEstimate(probing_bps, info.arrival_time_ms); |
128 result.probe = true; | 117 UpdateEstimate(info.arrival_time_ms, now_ms); |
129 result.updated = UpdateEstimate(info.arrival_time_ms, now_ms, | 118 return Result(true, 0); |
130 &result.target_bitrate_bps); | |
131 } | 119 } |
132 if (!result.updated && | 120 UpdateEstimate(info.arrival_time_ms, now_ms); |
133 (last_update_ms_ == -1 || | 121 return Result(); |
stefan-webrtc
2016/10/26 15:19:20
I find this method a bit strange now. It basically
michaelt
2016/10/27 14:42:59
Since we work with a vector of packets, it seamed
stefan-webrtc
2016/10/31 15:08:49
I agree with that. Seems odd to me that we return
| |
134 now_ms - last_update_ms_ > rate_control_.GetFeedbackInterval())) { | |
135 result.updated = UpdateEstimate(info.arrival_time_ms, now_ms, | |
136 &result.target_bitrate_bps); | |
137 } | |
138 if (result.updated) | |
139 last_update_ms_ = now_ms; | |
140 | |
141 return result; | |
142 } | 122 } |
143 | 123 |
144 bool DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms, | 124 void DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms, int64_t now_ms) { |
145 int64_t now_ms, | |
146 uint32_t* target_bitrate_bps) { | |
147 // The first overuse should immediately trigger a new estimate. | 125 // The first overuse should immediately trigger a new estimate. |
148 // We also have to update the estimate immediately if we are overusing | 126 // We also have to update the estimate immediately if we are overusing |
149 // and the target bitrate is too high compared to what we are receiving. | 127 // and the target bitrate is too high compared to what we are receiving. |
150 const RateControlInput input(detector_.State(), | 128 const RateControlInput input(detector_.State(), |
151 receiver_incoming_bitrate_.Rate(arrival_time_ms), | 129 receiver_incoming_bitrate_.Rate(arrival_time_ms), |
152 estimator_->var_noise()); | 130 estimator_->var_noise()); |
153 rate_control_.Update(&input, now_ms); | 131 rate_control_.Update(&input, now_ms); |
154 *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); | |
155 return rate_control_.ValidEstimate(); | |
156 } | 132 } |
157 | 133 |
158 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 134 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
159 rate_control_.SetRtt(avg_rtt_ms); | 135 rate_control_.SetRtt(avg_rtt_ms); |
160 } | 136 } |
161 | 137 |
162 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, | 138 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
163 uint32_t* bitrate_bps) const { | 139 uint32_t* bitrate_bps) const { |
164 // Currently accessed from both the process thread (see | 140 // Currently accessed from both the process thread (see |
165 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see | 141 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see |
166 // Call::GetStats()). Should in the future only be accessed from a single | 142 // Call::GetStats()). Should in the future only be accessed from a single |
167 // thread. | 143 // thread. |
168 RTC_DCHECK(ssrcs); | 144 RTC_DCHECK(ssrcs); |
169 RTC_DCHECK(bitrate_bps); | 145 RTC_DCHECK(bitrate_bps); |
170 if (!rate_control_.ValidEstimate()) | 146 if (!rate_control_.ValidEstimate()) |
171 return false; | 147 return false; |
172 | 148 |
173 *ssrcs = {kFixedSsrc}; | 149 *ssrcs = {kFixedSsrc}; |
174 *bitrate_bps = rate_control_.LatestEstimate(); | 150 *bitrate_bps = rate_control_.LatestEstimate(); |
175 return true; | 151 return true; |
176 } | 152 } |
177 | 153 |
178 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { | 154 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
179 // Called from both the configuration thread and the network thread. Shouldn't | 155 // Called from both the configuration thread and the network thread. Shouldn't |
180 // be called from the network thread in the future. | 156 // be called from the network thread in the future. |
181 rate_control_.SetMinBitrate(min_bitrate_bps); | 157 rate_control_.SetMinBitrate(min_bitrate_bps); |
182 } | 158 } |
183 } // namespace webrtc | 159 } // namespace webrtc |
OLD | NEW |