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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 num_layers_); | 197 num_layers_); |
198 } | 198 } |
199 | 199 |
200 uint32_t MediaOptimization::SetTargetRates( | 200 uint32_t MediaOptimization::SetTargetRates( |
201 uint32_t target_bitrate, | 201 uint32_t target_bitrate, |
202 uint8_t fraction_lost, | 202 uint8_t fraction_lost, |
203 int64_t round_trip_time_ms, | 203 int64_t round_trip_time_ms, |
204 VCMProtectionCallback* protection_callback, | 204 VCMProtectionCallback* protection_callback, |
205 VCMQMSettingsCallback* qmsettings_callback) { | 205 VCMQMSettingsCallback* qmsettings_callback) { |
206 CriticalSectionScoped lock(crit_sect_.get()); | 206 CriticalSectionScoped lock(crit_sect_.get()); |
207 // TODO(holmer): Consider putting this threshold only on the video bitrate, | |
208 // and not on protection. | |
209 if (max_bit_rate_ > 0 && | |
210 target_bitrate > static_cast<uint32_t>(max_bit_rate_)) { | |
211 target_bitrate = max_bit_rate_; | |
212 } | |
213 VCMProtectionMethod* selected_method = loss_prot_logic_->SelectedMethod(); | 207 VCMProtectionMethod* selected_method = loss_prot_logic_->SelectedMethod(); |
214 float target_bitrate_kbps = static_cast<float>(target_bitrate) / 1000.0f; | 208 float target_bitrate_kbps = static_cast<float>(target_bitrate) / 1000.0f; |
215 loss_prot_logic_->UpdateBitRate(target_bitrate_kbps); | 209 loss_prot_logic_->UpdateBitRate(target_bitrate_kbps); |
216 loss_prot_logic_->UpdateRtt(round_trip_time_ms); | 210 loss_prot_logic_->UpdateRtt(round_trip_time_ms); |
217 | 211 |
218 // Get frame rate for encoder: this is the actual/sent frame rate. | 212 // Get frame rate for encoder: this is the actual/sent frame rate. |
219 float actual_frame_rate = SentFrameRateInternal(); | 213 float actual_frame_rate = SentFrameRateInternal(); |
220 | 214 |
221 // Sanity check. | 215 // Sanity check. |
222 if (actual_frame_rate < 1.0) { | 216 if (actual_frame_rate < 1.0) { |
(...skipping 11 matching lines...) Expand all Loading... | |
234 // filtered value (average or max window filter). | 228 // filtered value (average or max window filter). |
235 // Use max window filter for now. | 229 // Use max window filter for now. |
236 FilterPacketLossMode filter_mode = kMaxFilter; | 230 FilterPacketLossMode filter_mode = kMaxFilter; |
237 uint8_t packet_loss_enc = loss_prot_logic_->FilteredLoss( | 231 uint8_t packet_loss_enc = loss_prot_logic_->FilteredLoss( |
238 clock_->TimeInMilliseconds(), filter_mode, fraction_lost); | 232 clock_->TimeInMilliseconds(), filter_mode, fraction_lost); |
239 | 233 |
240 // For now use the filtered loss for computing the robustness settings. | 234 // For now use the filtered loss for computing the robustness settings. |
241 loss_prot_logic_->UpdateFilteredLossPr(packet_loss_enc); | 235 loss_prot_logic_->UpdateFilteredLossPr(packet_loss_enc); |
242 | 236 |
243 // Rate cost of the protection methods. | 237 // Rate cost of the protection methods. |
244 uint32_t protection_overhead_bps = 0; | 238 float protection_overhead_rate = 0.0f; |
245 | 239 |
246 // Update protection settings, when applicable. | 240 // Update protection settings, when applicable. |
247 float sent_video_rate_kbps = 0.0f; | 241 float sent_video_rate_kbps = 0.0f; |
248 if (loss_prot_logic_->SelectedType() != kNone) { | 242 if (loss_prot_logic_->SelectedType() != kNone) { |
249 // Update protection method with content metrics. | 243 // Update protection method with content metrics. |
250 selected_method->UpdateContentMetrics(content_->ShortTermAvgData()); | 244 selected_method->UpdateContentMetrics(content_->ShortTermAvgData()); |
251 | 245 |
252 // Update method will compute the robustness settings for the given | 246 // Update method will compute the robustness settings for the given |
253 // protection method and the overhead cost | 247 // protection method and the overhead cost |
254 // the protection method is set by the user via SetVideoProtection. | 248 // the protection method is set by the user via SetVideoProtection. |
(...skipping 11 matching lines...) Expand all Loading... | |
266 &sent_video_rate_bps, | 260 &sent_video_rate_bps, |
267 &sent_nack_rate_bps, | 261 &sent_nack_rate_bps, |
268 &sent_fec_rate_bps, | 262 &sent_fec_rate_bps, |
269 protection_callback); | 263 protection_callback); |
270 } | 264 } |
271 uint32_t sent_total_rate_bps = | 265 uint32_t sent_total_rate_bps = |
272 sent_video_rate_bps + sent_nack_rate_bps + sent_fec_rate_bps; | 266 sent_video_rate_bps + sent_nack_rate_bps + sent_fec_rate_bps; |
273 // Estimate the overhead costs of the next second as staying the same | 267 // Estimate the overhead costs of the next second as staying the same |
274 // wrt the source bitrate. | 268 // wrt the source bitrate. |
275 if (sent_total_rate_bps > 0) { | 269 if (sent_total_rate_bps > 0) { |
276 protection_overhead_bps = static_cast<uint32_t>( | 270 protection_overhead_rate = |
277 target_bitrate * | 271 static_cast<float>(sent_nack_rate_bps + sent_fec_rate_bps) / |
278 static_cast<double>(sent_nack_rate_bps + sent_fec_rate_bps) / | 272 sent_total_rate_bps; |
279 sent_total_rate_bps + | |
280 0.5); | |
281 } | 273 } |
274 // TODO(pbos): Does this make sense? NACK retransmissions + FEC overhead can | |
275 // go above 50% with FEC maxed out. | |
stefan-webrtc
2015/10/29 07:11:15
I don't think it does. Please remove.
pbos-webrtc
2015/10/29 16:40:42
Done.
| |
282 // Cap the overhead estimate to 50%. | 276 // Cap the overhead estimate to 50%. |
283 if (protection_overhead_bps > target_bitrate / 2) | 277 if (protection_overhead_rate > 0.5) |
284 protection_overhead_bps = target_bitrate / 2; | 278 protection_overhead_rate = 0.5; |
285 | 279 |
286 // Get the effective packet loss for encoder ER when applicable. Should be | 280 // Get the effective packet loss for encoder ER when applicable. Should be |
287 // passed to encoder via fraction_lost. | 281 // passed to encoder via fraction_lost. |
288 packet_loss_enc = selected_method->RequiredPacketLossER(); | 282 packet_loss_enc = selected_method->RequiredPacketLossER(); |
289 sent_video_rate_kbps = static_cast<float>(sent_video_rate_bps) / 1000.0f; | 283 sent_video_rate_kbps = static_cast<float>(sent_video_rate_bps) / 1000.0f; |
290 } | 284 } |
291 | 285 |
292 // Source coding rate: total rate - protection overhead. | 286 // Source coding rate: total rate - protection overhead. |
293 target_bit_rate_ = target_bitrate - protection_overhead_bps; | 287 printf("protection_overhead_bps: %f\n", protection_overhead_rate); |
stefan-webrtc
2015/10/29 07:11:15
Please remove!
pbos-webrtc
2015/10/29 16:40:42
Done.
| |
288 target_bit_rate_ = target_bitrate * (1.0 - protection_overhead_rate); | |
stefan-webrtc
2015/10/29 07:11:15
Name this video_target_bitrate_
pbos-webrtc
2015/10/29 16:40:42
Done.
| |
289 | |
290 // Cap target video bitrate to codec maximum. | |
291 if (max_bit_rate_ > 0 && target_bit_rate_ > max_bit_rate_) { | |
292 target_bit_rate_ = max_bit_rate_; | |
293 } | |
294 | 294 |
295 // Update encoding rates following protection settings. | 295 // Update encoding rates following protection settings. |
296 float target_video_bitrate_kbps = | 296 float target_video_bitrate_kbps = |
297 static_cast<float>(target_bit_rate_) / 1000.0f; | 297 static_cast<float>(target_bit_rate_) / 1000.0f; |
298 frame_dropper_->SetRates(target_video_bitrate_kbps, incoming_frame_rate_); | 298 frame_dropper_->SetRates(target_video_bitrate_kbps, incoming_frame_rate_); |
299 | 299 |
300 if (enable_qm_ && qmsettings_callback) { | 300 if (enable_qm_ && qmsettings_callback) { |
301 // Update QM with rates. | 301 // Update QM with rates. |
302 qm_resolution_->UpdateRates(target_video_bitrate_kbps, | 302 qm_resolution_->UpdateRates(target_video_bitrate_kbps, |
303 sent_video_rate_kbps, | 303 sent_video_rate_kbps, |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 if (target_bit_rate_ > | 641 if (target_bit_rate_ > |
642 suspension_threshold_bps_ + suspension_window_bps_) { | 642 suspension_threshold_bps_ + suspension_window_bps_) { |
643 video_suspended_ = false; | 643 video_suspended_ = false; |
644 } | 644 } |
645 } | 645 } |
646 } | 646 } |
647 } | 647 } |
648 | 648 |
649 } // namespace media_optimization | 649 } // namespace media_optimization |
650 } // namespace webrtc | 650 } // namespace webrtc |
OLD | NEW |