OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 10 matching lines...) Expand all Loading... |
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
22 #include "webrtc/system_wrappers/include/logging.h" | 22 #include "webrtc/system_wrappers/include/logging.h" |
23 #include "webrtc/typedefs.h" | 23 #include "webrtc/typedefs.h" |
24 | 24 |
25 namespace webrtc { | 25 namespace webrtc { |
26 | 26 |
27 enum { kTimestampGroupLengthMs = 5 }; | 27 enum { kTimestampGroupLengthMs = 5 }; |
28 static const double kTimestampToMs = 1.0 / 90.0; | 28 static const double kTimestampToMs = 1.0 / 90.0; |
29 | 29 |
30 struct RemoteBitrateEstimatorSingleStream::Detector { | 30 struct RemoteBitrateEstimatorSingleStream::Detector { |
31 explicit Detector(int64_t last_packet_time_ms, | 31 explicit Detector(int64_t last_packet_time_ms, bool enable_burst_grouping) |
32 const OverUseDetectorOptions& options, | 32 : last_packet_time_ms(last_packet_time_ms), |
33 bool enable_burst_grouping) | 33 inter_arrival(90 * kTimestampGroupLengthMs, |
34 : last_packet_time_ms(last_packet_time_ms), | 34 kTimestampToMs, |
35 inter_arrival(90 * kTimestampGroupLengthMs, kTimestampToMs, | 35 enable_burst_grouping), |
36 enable_burst_grouping), | 36 estimator(), |
37 estimator(options), | 37 detector() {} |
38 detector(options) {} | |
39 int64_t last_packet_time_ms; | 38 int64_t last_packet_time_ms; |
40 InterArrival inter_arrival; | 39 InterArrival inter_arrival; |
41 OveruseEstimator estimator; | 40 OveruseEstimator estimator; |
42 OveruseDetector detector; | 41 OveruseDetector detector; |
43 }; | 42 }; |
44 | 43 |
45 RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream( | 44 RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream( |
46 RemoteBitrateObserver* observer, | 45 RemoteBitrateObserver* observer, |
47 Clock* clock) | 46 Clock* clock) |
48 : clock_(clock), | 47 : clock_(clock), |
(...skipping 26 matching lines...) Expand all Loading... |
75 CriticalSectionScoped cs(crit_sect_.get()); | 74 CriticalSectionScoped cs(crit_sect_.get()); |
76 SsrcOveruseEstimatorMap::iterator it = overuse_detectors_.find(ssrc); | 75 SsrcOveruseEstimatorMap::iterator it = overuse_detectors_.find(ssrc); |
77 if (it == overuse_detectors_.end()) { | 76 if (it == overuse_detectors_.end()) { |
78 // This is a new SSRC. Adding to map. | 77 // This is a new SSRC. Adding to map. |
79 // TODO(holmer): If the channel changes SSRC the old SSRC will still be | 78 // TODO(holmer): If the channel changes SSRC the old SSRC will still be |
80 // around in this map until the channel is deleted. This is OK since the | 79 // around in this map until the channel is deleted. This is OK since the |
81 // callback will no longer be called for the old SSRC. This will be | 80 // callback will no longer be called for the old SSRC. This will be |
82 // automatically cleaned up when we have one RemoteBitrateEstimator per REMB | 81 // automatically cleaned up when we have one RemoteBitrateEstimator per REMB |
83 // group. | 82 // group. |
84 std::pair<SsrcOveruseEstimatorMap::iterator, bool> insert_result = | 83 std::pair<SsrcOveruseEstimatorMap::iterator, bool> insert_result = |
85 overuse_detectors_.insert(std::make_pair( | 84 overuse_detectors_.insert( |
86 ssrc, new Detector(now_ms, OverUseDetectorOptions(), true))); | 85 std::make_pair(ssrc, new Detector(now_ms, true))); |
87 it = insert_result.first; | 86 it = insert_result.first; |
88 } | 87 } |
89 Detector* estimator = it->second; | 88 Detector* estimator = it->second; |
90 estimator->last_packet_time_ms = now_ms; | 89 estimator->last_packet_time_ms = now_ms; |
91 incoming_bitrate_.Update(payload_size, now_ms); | 90 incoming_bitrate_.Update(payload_size, now_ms); |
92 const BandwidthUsage prior_state = estimator->detector.State(); | 91 const BandwidthUsage prior_state = estimator->detector.State(); |
93 uint32_t timestamp_delta = 0; | 92 uint32_t timestamp_delta = 0; |
94 int64_t time_delta = 0; | 93 int64_t time_delta = 0; |
95 int size_delta = 0; | |
96 if (estimator->inter_arrival.ComputeDeltas(rtp_timestamp, arrival_time_ms, | 94 if (estimator->inter_arrival.ComputeDeltas(rtp_timestamp, arrival_time_ms, |
97 payload_size, ×tamp_delta, | 95 ×tamp_delta, &time_delta)) { |
98 &time_delta, &size_delta)) { | |
99 double timestamp_delta_ms = timestamp_delta * kTimestampToMs; | 96 double timestamp_delta_ms = timestamp_delta * kTimestampToMs; |
100 estimator->estimator.Update(time_delta, timestamp_delta_ms, size_delta, | 97 estimator->estimator.Update(time_delta, timestamp_delta_ms, |
101 estimator->detector.State()); | 98 estimator->detector.State()); |
102 estimator->detector.Detect(estimator->estimator.offset(), | 99 estimator->detector.Detect(estimator->estimator.offset(), |
103 timestamp_delta_ms, | 100 timestamp_delta_ms, |
104 estimator->estimator.num_of_deltas(), now_ms); | 101 estimator->estimator.num_of_deltas(), now_ms); |
105 } | 102 } |
106 if (estimator->detector.State() == kBwOverusing) { | 103 if (estimator->detector.State() == kBwOverusing) { |
107 uint32_t incoming_bitrate_bps = incoming_bitrate_.Rate(now_ms); | 104 uint32_t incoming_bitrate_bps = incoming_bitrate_.Rate(now_ms); |
108 if (prior_state != kBwOverusing || | 105 if (prior_state != kBwOverusing || |
109 remote_rate_->TimeToReduceFurther(now_ms, incoming_bitrate_bps)) { | 106 remote_rate_->TimeToReduceFurther(now_ms, incoming_bitrate_bps)) { |
110 // The first overuse should immediately trigger a new estimate. | 107 // The first overuse should immediately trigger a new estimate. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 (*ssrcs)[i] = it->first; | 225 (*ssrcs)[i] = it->first; |
229 } | 226 } |
230 } | 227 } |
231 | 228 |
232 void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int min_bitrate_bps) { | 229 void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int min_bitrate_bps) { |
233 CriticalSectionScoped cs(crit_sect_.get()); | 230 CriticalSectionScoped cs(crit_sect_.get()); |
234 remote_rate_->SetMinBitrate(min_bitrate_bps); | 231 remote_rate_->SetMinBitrate(min_bitrate_bps); |
235 } | 232 } |
236 | 233 |
237 } // namespace webrtc | 234 } // namespace webrtc |
OLD | NEW |