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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 RTC_NOTREACHED(); | 125 RTC_NOTREACHED(); |
126 break; | 126 break; |
127 } | 127 } |
128 stats_proxy_->SetContentType(content_type); | 128 stats_proxy_->SetContentType(content_type); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 int ViEEncoder::GetPaddingNeededBps() const { | 132 int ViEEncoder::GetPaddingNeededBps() const { |
133 int64_t time_of_last_frame_activity_ms; | 133 int64_t time_of_last_frame_activity_ms; |
134 int min_transmit_bitrate_bps; | 134 int min_transmit_bitrate_bps; |
135 int bitrate_bps; | |
136 VideoCodec send_codec; | 135 VideoCodec send_codec; |
| 136 bool video_is_suspended; |
137 { | 137 { |
138 rtc::CritScope lock(&data_cs_); | 138 rtc::CritScope lock(&data_cs_); |
139 bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 || | 139 bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 || |
140 video_suspended_ || min_transmit_bitrate_bps_ > 0; | 140 video_suspended_ || min_transmit_bitrate_bps_ > 0; |
141 if (!send_padding) | 141 if (!send_padding) |
142 return 0; | 142 return 0; |
143 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; | 143 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; |
144 min_transmit_bitrate_bps = min_transmit_bitrate_bps_; | 144 min_transmit_bitrate_bps = min_transmit_bitrate_bps_; |
145 bitrate_bps = last_observed_bitrate_bps_; | |
146 send_codec = encoder_config_; | 145 send_codec = encoder_config_; |
| 146 video_is_suspended = video_suspended_; |
147 } | 147 } |
148 | 148 |
149 bool video_is_suspended = video_sender_.VideoSuspended(); | |
150 | |
151 // Find the max amount of padding we can allow ourselves to send at this | 149 // Find the max amount of padding we can allow ourselves to send at this |
152 // point, based on which streams are currently active and what our current | 150 // point, based on which streams are currently active and what our current |
153 // available bandwidth is. | 151 // available bandwidth is. |
154 int pad_up_to_bitrate_bps = 0; | 152 int pad_up_to_bitrate_bps = 0; |
155 if (send_codec.numberOfSimulcastStreams == 0) { | 153 if (send_codec.numberOfSimulcastStreams == 0) { |
156 pad_up_to_bitrate_bps = send_codec.minBitrate * 1000; | 154 pad_up_to_bitrate_bps = send_codec.minBitrate * 1000; |
157 } else { | 155 } else { |
158 SimulcastStream* stream_configs = send_codec.simulcastStream; | 156 SimulcastStream* stream_configs = send_codec.simulcastStream; |
159 pad_up_to_bitrate_bps = | 157 pad_up_to_bitrate_bps = |
160 stream_configs[send_codec.numberOfSimulcastStreams - 1].minBitrate * | 158 stream_configs[send_codec.numberOfSimulcastStreams - 1].minBitrate * |
(...skipping 11 matching lines...) Expand all Loading... |
172 // The amount of padding should decay to zero if no frames are being | 170 // The amount of padding should decay to zero if no frames are being |
173 // captured/encoded unless a min-transmit bitrate is used. | 171 // captured/encoded unless a min-transmit bitrate is used. |
174 int64_t now_ms = rtc::TimeMillis(); | 172 int64_t now_ms = rtc::TimeMillis(); |
175 if (now_ms - time_of_last_frame_activity_ms > kStopPaddingThresholdMs) | 173 if (now_ms - time_of_last_frame_activity_ms > kStopPaddingThresholdMs) |
176 pad_up_to_bitrate_bps = 0; | 174 pad_up_to_bitrate_bps = 0; |
177 | 175 |
178 // Pad up to min bitrate. | 176 // Pad up to min bitrate. |
179 if (pad_up_to_bitrate_bps < min_transmit_bitrate_bps) | 177 if (pad_up_to_bitrate_bps < min_transmit_bitrate_bps) |
180 pad_up_to_bitrate_bps = min_transmit_bitrate_bps; | 178 pad_up_to_bitrate_bps = min_transmit_bitrate_bps; |
181 | 179 |
182 // Padding may never exceed bitrate estimate. | |
183 if (pad_up_to_bitrate_bps > bitrate_bps) | |
184 pad_up_to_bitrate_bps = bitrate_bps; | |
185 | |
186 return pad_up_to_bitrate_bps; | 180 return pad_up_to_bitrate_bps; |
187 } | 181 } |
188 | 182 |
189 bool ViEEncoder::EncoderPaused() const { | 183 bool ViEEncoder::EncoderPaused() const { |
190 // Pause video if paused by caller or as long as the network is down or the | 184 // Pause video if paused by caller or as long as the network is down or the |
191 // pacer queue has grown too large in buffered mode. | 185 // pacer queue has grown too large in buffered mode. |
192 // If the pacer queue has grown to large or the network is down, | 186 // If the pacer queue has grown to large or the network is down, |
193 // last_observed_bitrate_bps_ will be 0. | 187 // last_observed_bitrate_bps_ will be 0. |
194 return encoder_paused_ || video_suspended_ || last_observed_bitrate_bps_ == 0; | 188 return encoder_paused_ || video_suspended_ || last_observed_bitrate_bps_ == 0; |
195 } | 189 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } | 307 } |
314 | 308 |
315 void ViEEncoder::OnBitrateUpdated(uint32_t bitrate_bps, | 309 void ViEEncoder::OnBitrateUpdated(uint32_t bitrate_bps, |
316 uint8_t fraction_lost, | 310 uint8_t fraction_lost, |
317 int64_t round_trip_time_ms) { | 311 int64_t round_trip_time_ms) { |
318 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps | 312 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps |
319 << " packet loss " << static_cast<int>(fraction_lost) | 313 << " packet loss " << static_cast<int>(fraction_lost) |
320 << " rtt " << round_trip_time_ms; | 314 << " rtt " << round_trip_time_ms; |
321 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, | 315 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, |
322 round_trip_time_ms); | 316 round_trip_time_ms); |
323 bool video_is_suspended = video_sender_.VideoSuspended(); | |
324 bool video_suspension_changed; | 317 bool video_suspension_changed; |
| 318 bool video_is_suspended = bitrate_bps == 0; |
325 { | 319 { |
326 rtc::CritScope lock(&data_cs_); | 320 rtc::CritScope lock(&data_cs_); |
327 last_observed_bitrate_bps_ = bitrate_bps; | 321 last_observed_bitrate_bps_ = bitrate_bps; |
328 video_suspension_changed = video_suspended_ != video_is_suspended; | 322 video_suspension_changed = video_suspended_ != video_is_suspended; |
329 video_suspended_ = video_is_suspended; | 323 video_suspended_ = video_is_suspended; |
330 } | 324 } |
331 | 325 |
332 if (!video_suspension_changed) | 326 if (stats_proxy_ && video_suspension_changed) { |
333 return; | 327 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended; |
334 // Video suspend-state changed, inform codec observer. | |
335 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended; | |
336 | |
337 if (stats_proxy_) | |
338 stats_proxy_->OnSuspendChange(video_is_suspended); | 328 stats_proxy_->OnSuspendChange(video_is_suspended); |
| 329 } |
339 } | 330 } |
340 | 331 |
341 } // namespace webrtc | 332 } // namespace webrtc |
OLD | NEW |