OLD | NEW |
---|---|
(Empty) | |
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 */ | |
10 | |
11 #include "webrtc/modules/congestion_controller/include/receive_side_congestion_c ontroller.h" | |
12 | |
13 #include "webrtc/base/logging.h" | |
14 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" | |
15 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" | |
16 | |
17 namespace webrtc { | |
18 | |
19 namespace { | |
20 static const uint32_t kTimeOffsetSwitchThreshold = 30; | |
21 } // namespace | |
22 | |
23 ReceiveSideCongestionController::WrappingBitrateEstimator:: | |
24 WrappingBitrateEstimator(RemoteBitrateObserver* observer, | |
25 const Clock* clock) | |
26 : observer_(observer), | |
27 clock_(clock), | |
28 rbe_(new RemoteBitrateEstimatorSingleStream(observer_, clock_)), | |
29 using_absolute_send_time_(false), | |
30 packets_since_absolute_send_time_(0), | |
31 min_bitrate_bps_(congestion_controller::GetMinBitrateBps()) {} | |
32 | |
33 void ReceiveSideCongestionController::WrappingBitrateEstimator::IncomingPacket( | |
34 int64_t arrival_time_ms, | |
35 size_t payload_size, | |
36 const RTPHeader& header) { | |
37 rtc::CritScope cs(&crit_sect_); | |
38 PickEstimatorFromHeader(header); | |
39 rbe_->IncomingPacket(arrival_time_ms, payload_size, header); | |
40 } | |
41 | |
42 void ReceiveSideCongestionController::WrappingBitrateEstimator::Process() { | |
43 rtc::CritScope cs(&crit_sect_); | |
44 rbe_->Process(); | |
45 } | |
46 | |
47 int64_t ReceiveSideCongestionController::WrappingBitrateEstimator:: | |
48 TimeUntilNextProcess() { | |
49 rtc::CritScope cs(&crit_sect_); | |
50 return rbe_->TimeUntilNextProcess(); | |
51 } | |
52 | |
53 void ReceiveSideCongestionController::WrappingBitrateEstimator::OnRttUpdate( | |
54 int64_t avg_rtt_ms, | |
55 int64_t max_rtt_ms) { | |
56 rtc::CritScope cs(&crit_sect_); | |
57 rbe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | |
58 } | |
59 | |
60 void ReceiveSideCongestionController::WrappingBitrateEstimator::RemoveStream( | |
61 unsigned int ssrc) { | |
62 rtc::CritScope cs(&crit_sect_); | |
63 rbe_->RemoveStream(ssrc); | |
64 } | |
65 | |
66 bool ReceiveSideCongestionController::WrappingBitrateEstimator::LatestEstimate( | |
67 std::vector<unsigned int>* ssrcs, | |
68 unsigned int* bitrate_bps) const { | |
69 rtc::CritScope cs(&crit_sect_); | |
70 return rbe_->LatestEstimate(ssrcs, bitrate_bps); | |
71 } | |
72 | |
73 void ReceiveSideCongestionController::WrappingBitrateEstimator::SetMinBitrate( | |
74 int min_bitrate_bps) { | |
75 rtc::CritScope cs(&crit_sect_); | |
76 rbe_->SetMinBitrate(min_bitrate_bps); | |
77 min_bitrate_bps_ = min_bitrate_bps; | |
78 } | |
79 | |
80 void ReceiveSideCongestionController::WrappingBitrateEstimator:: | |
81 PickEstimatorFromHeader(const RTPHeader& header) { | |
82 if (header.extension.hasAbsoluteSendTime) { | |
83 // If we see AST in header, switch RBE strategy immediately. | |
84 if (!using_absolute_send_time_) { | |
85 LOG(LS_INFO) | |
86 << "WrappingBitrateEstimator: Switching to absolute send time RBE."; | |
87 using_absolute_send_time_ = true; | |
88 PickEstimator(); | |
89 } | |
90 packets_since_absolute_send_time_ = 0; | |
91 } else { | |
92 // When we don't see AST, wait for a few packets before going back to TOF. | |
93 if (using_absolute_send_time_) { | |
94 ++packets_since_absolute_send_time_; | |
95 if (packets_since_absolute_send_time_ >= kTimeOffsetSwitchThreshold) { | |
96 LOG(LS_INFO) << "WrappingBitrateEstimator: Switching to transmission " | |
97 << "time offset RBE."; | |
98 using_absolute_send_time_ = false; | |
99 PickEstimator(); | |
100 } | |
101 } | |
102 } | |
103 } | |
104 | |
105 // Instantiate RBE for Time Offset or Absolute Send Time extensions. | |
106 void ReceiveSideCongestionController::WrappingBitrateEstimator:: | |
107 PickEstimator() { | |
108 if (using_absolute_send_time_) { | |
109 rbe_.reset(new RemoteBitrateEstimatorAbsSendTime(observer_, clock_)); | |
110 } else { | |
111 rbe_.reset(new RemoteBitrateEstimatorSingleStream(observer_, clock_)); | |
112 } | |
113 rbe_->SetMinBitrate(min_bitrate_bps_); | |
114 } | |
115 | |
116 ReceiveSideCongestionController::ReceiveSideCongestionController( | |
117 const Clock* clock, | |
118 RemoteBitrateObserver* remote_bitrate_observer, | |
119 PacketRouter* packet_router) | |
120 : remote_bitrate_estimator_(remote_bitrate_observer, clock), | |
121 remote_estimator_proxy_(clock, packet_router) {} | |
122 | |
123 void ReceiveSideCongestionController::OnReceivedPacket( | |
124 int64_t arrival_time_ms, | |
125 size_t payload_size, | |
126 const RTPHeader& header) { | |
127 // Send-side BWE. | |
128 if (header.extension.hasTransportSequenceNumber) { | |
129 remote_estimator_proxy_.IncomingPacket(arrival_time_ms, payload_size, | |
130 header); | |
131 } else { | |
132 // Receive-side BWE. | |
133 remote_bitrate_estimator_.IncomingPacket(arrival_time_ms, payload_size, | |
134 header); | |
135 } | |
136 } | |
137 | |
138 RemoteBitrateEstimator* | |
139 ReceiveSideCongestionController::GetRemoteBitrateEstimator(bool send_side_bwe) { | |
140 if (send_side_bwe) { | |
141 return &remote_estimator_proxy_; | |
142 } else { | |
143 return &remote_bitrate_estimator_; | |
144 } | |
145 } | |
146 | |
147 const RemoteBitrateEstimator* | |
148 ReceiveSideCongestionController::GetRemoteBitrateEstimator( | |
149 bool send_side_bwe) const { | |
150 if (send_side_bwe) { | |
151 return &remote_estimator_proxy_; | |
152 } else { | |
153 return &remote_bitrate_estimator_; | |
154 } | |
155 } | |
156 | |
157 // TODO(nisse): When this code was part of CongestionController, the | |
158 // method MaybeTriggerOnNetworkChanged called | |
159 // remote_estimator_proxy_.OnBitrateChanged(bitrate_bps), and this was | |
160 // called by both OnNetworkRouteChanged and Process. Do we need any | |
161 // calls to OnBitRateChanged here? | |
162 | |
163 void ReceiveSideCongestionController::OnNetworkRouteChanged( | |
164 int min_bitrate_bps) { | |
stefan-webrtc
2017/03/17 08:03:32
I doubt there's much value in this as I don't thin
nisse-webrtc
2017/03/17 10:49:23
Sounds good to me. Deleted.
| |
165 // TODO(nisse): Do we need to clamp using | |
166 // webrtc::congestion_controller::GetMinBitrateBps? | |
167 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is | |
168 // no longer exposed outside CongestionController. | |
169 remote_bitrate_estimator_.SetMinBitrate(min_bitrate_bps); | |
170 } | |
171 | |
172 void ReceiveSideCongestionController::OnRttUpdate(int64_t avg_rtt_ms, | |
173 int64_t max_rtt_ms) { | |
174 remote_bitrate_estimator_.OnRttUpdate(avg_rtt_ms, max_rtt_ms); | |
175 } | |
176 | |
177 int64_t ReceiveSideCongestionController::TimeUntilNextProcess() { | |
178 return remote_bitrate_estimator_.TimeUntilNextProcess(); | |
179 } | |
180 | |
181 void ReceiveSideCongestionController::Process() { | |
182 remote_bitrate_estimator_.Process(); | |
183 } | |
184 | |
185 } // namespace webrtc | |
OLD | NEW |