Chromium Code Reviews| 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 |
| 11 #include <webrtc/modules/video_coding/protection_bitrate_calculator.h> | 11 #include "webrtc/modules/video_coding/protection_bitrate_calculator.h" |
| 12 | 12 |
| 13 namespace webrtc { | 13 namespace webrtc { |
| 14 | 14 |
| 15 using rtc::CritScope; | 15 using rtc::CritScope; |
| 16 | 16 |
| 17 struct ProtectionBitrateCalculator::EncodedFrameSample { | 17 struct ProtectionBitrateCalculator::EncodedFrameSample { |
| 18 EncodedFrameSample(size_t size_bytes, | 18 EncodedFrameSample(size_t size_bytes, |
| 19 uint32_t timestamp, | 19 uint32_t timestamp, |
| 20 int64_t time_complete_ms) | 20 int64_t time_complete_ms) |
| 21 : size_bytes(size_bytes), | 21 : size_bytes(size_bytes), |
| 22 timestamp(timestamp), | 22 timestamp(timestamp), |
| 23 time_complete_ms(time_complete_ms) {} | 23 time_complete_ms(time_complete_ms) {} |
| 24 size_t size_bytes; | 24 size_t size_bytes; |
| 25 uint32_t timestamp; | 25 uint32_t timestamp; |
| 26 int64_t time_complete_ms; | 26 int64_t time_complete_ms; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 ProtectionBitrateCalculator::ProtectionBitrateCalculator( | 29 ProtectionBitrateCalculator::ProtectionBitrateCalculator( |
| 30 Clock* clock, | 30 Clock* clock, |
| 31 VCMProtectionCallback* protection_callback) | 31 VCMProtectionCallback* protection_callback) |
| 32 : clock_(clock), | 32 : clock_(clock), |
| 33 protection_callback_(protection_callback), | 33 protection_callback_(protection_callback), |
| 34 loss_prot_logic_(new media_optimization::VCMLossProtectionLogic( | 34 loss_prot_logic_(new media_optimization::VCMLossProtectionLogic( |
| 35 clock_->TimeInMilliseconds())), | 35 clock_->TimeInMilliseconds())), |
| 36 max_payload_size_(1460) {} | 36 max_payload_size_(1460), |
| 37 last_encoder_target_rate_(0) {} | |
| 37 | 38 |
| 38 ProtectionBitrateCalculator::~ProtectionBitrateCalculator(void) { | 39 ProtectionBitrateCalculator::~ProtectionBitrateCalculator(void) { |
| 39 loss_prot_logic_->Release(); | 40 loss_prot_logic_->Release(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void ProtectionBitrateCalculator::SetEncodingData(uint32_t target_bitrate, | 43 void ProtectionBitrateCalculator::SetEncodingData(uint32_t target_bitrate, |
| 43 uint16_t width, | 44 uint16_t width, |
| 44 uint16_t height, | 45 uint16_t height, |
| 45 uint32_t frame_rate, | 46 uint32_t frame_rate, |
| 46 size_t num_temporal_layers, | 47 size_t num_temporal_layers, |
| 47 size_t max_payload_size) { | 48 size_t max_payload_size) { |
| 48 CritScope lock(&crit_sect_); | 49 CritScope lock(&crit_sect_); |
| 49 // Everything codec specific should be reset here since this means the codec | 50 // Everything codec specific should be reset here since this means the codec |
| 50 // has changed. | 51 // has changed. |
| 51 float target_bitrate_kbps = static_cast<float>(target_bitrate) / 1000.0f; | 52 float target_bitrate_kbps = static_cast<float>(target_bitrate) / 1000.0f; |
| 52 loss_prot_logic_->UpdateBitRate(target_bitrate_kbps); | 53 loss_prot_logic_->UpdateBitRate(target_bitrate_kbps); |
| 53 loss_prot_logic_->UpdateFrameRate(static_cast<float>(frame_rate)); | 54 loss_prot_logic_->UpdateFrameRate(static_cast<float>(frame_rate)); |
| 54 loss_prot_logic_->UpdateFrameSize(width, height); | 55 loss_prot_logic_->UpdateFrameSize(width, height); |
| 55 loss_prot_logic_->UpdateNumLayers(num_temporal_layers); | 56 loss_prot_logic_->UpdateNumLayers(num_temporal_layers); |
| 56 max_payload_size_ = max_payload_size; | 57 max_payload_size_ = max_payload_size; |
| 57 } | 58 } |
| 58 | 59 |
| 59 uint32_t ProtectionBitrateCalculator::SetTargetRates( | 60 uint32_t ProtectionBitrateCalculator::SetTargetRates( |
|
pbos-webrtc
2016/06/16 13:16:28
This part of the code should be run synchronously
perkj_webrtc
2016/06/16 18:42:17
I wish but not yet. If you have two VideoSendStrea
| |
| 60 uint32_t estimated_bitrate_bps, | 61 uint32_t estimated_bitrate_bps, |
| 61 int actual_framerate_fps, | 62 int actual_framerate_fps, |
| 62 uint8_t fraction_lost, | 63 uint8_t fraction_lost, |
| 63 int64_t round_trip_time_ms) { | 64 int64_t round_trip_time_ms) { |
| 64 float target_bitrate_kbps = | 65 float target_bitrate_kbps = |
| 65 static_cast<float>(estimated_bitrate_bps) / 1000.0f; | 66 static_cast<float>(estimated_bitrate_bps) / 1000.0f; |
| 66 // Sanity check. | 67 // Sanity check. |
| 67 if (actual_framerate_fps < 1.0) { | 68 if (actual_framerate_fps < 1.0) { |
| 68 actual_framerate_fps = 1.0; | 69 actual_framerate_fps = 1.0; |
| 69 } | 70 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 86 // Use max window filter for now. | 87 // Use max window filter for now. |
| 87 media_optimization::FilterPacketLossMode filter_mode = | 88 media_optimization::FilterPacketLossMode filter_mode = |
| 88 media_optimization::kMaxFilter; | 89 media_optimization::kMaxFilter; |
| 89 uint8_t packet_loss_enc = loss_prot_logic_->FilteredLoss( | 90 uint8_t packet_loss_enc = loss_prot_logic_->FilteredLoss( |
| 90 clock_->TimeInMilliseconds(), filter_mode, fraction_lost); | 91 clock_->TimeInMilliseconds(), filter_mode, fraction_lost); |
| 91 | 92 |
| 92 // For now use the filtered loss for computing the robustness settings. | 93 // For now use the filtered loss for computing the robustness settings. |
| 93 loss_prot_logic_->UpdateFilteredLossPr(packet_loss_enc); | 94 loss_prot_logic_->UpdateFilteredLossPr(packet_loss_enc); |
| 94 | 95 |
| 95 if (loss_prot_logic_->SelectedType() == media_optimization::kNone) { | 96 if (loss_prot_logic_->SelectedType() == media_optimization::kNone) { |
| 97 last_encoder_target_rate_ = estimated_bitrate_bps; | |
| 96 return estimated_bitrate_bps; | 98 return estimated_bitrate_bps; |
| 97 } | 99 } |
| 98 | 100 |
| 99 // Update method will compute the robustness settings for the given | 101 // Update method will compute the robustness settings for the given |
| 100 // protection method and the overhead cost | 102 // protection method and the overhead cost |
| 101 // the protection method is set by the user via SetVideoProtection. | 103 // the protection method is set by the user via SetVideoProtection. |
| 102 loss_prot_logic_->UpdateMethod(); | 104 loss_prot_logic_->UpdateMethod(); |
| 103 | 105 |
| 104 // Get the bit cost of protection method, based on the amount of | 106 // Get the bit cost of protection method, based on the amount of |
| 105 // overhead data actually transmitted (including headers) the last | 107 // overhead data actually transmitted (including headers) the last |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 if (sent_total_rate_bps > 0) { | 149 if (sent_total_rate_bps > 0) { |
| 148 protection_overhead_rate = | 150 protection_overhead_rate = |
| 149 static_cast<float>(sent_nack_rate_bps + sent_fec_rate_bps) / | 151 static_cast<float>(sent_nack_rate_bps + sent_fec_rate_bps) / |
| 150 sent_total_rate_bps; | 152 sent_total_rate_bps; |
| 151 } | 153 } |
| 152 // Cap the overhead estimate to 50%. | 154 // Cap the overhead estimate to 50%. |
| 153 if (protection_overhead_rate > 0.5) | 155 if (protection_overhead_rate > 0.5) |
| 154 protection_overhead_rate = 0.5; | 156 protection_overhead_rate = 0.5; |
| 155 | 157 |
| 156 // Source coding rate: total rate - protection overhead. | 158 // Source coding rate: total rate - protection overhead. |
| 157 return estimated_bitrate_bps * (1.0 - protection_overhead_rate); | 159 CritScope lock(&crit_sect_); |
| 160 last_encoder_target_rate_ = | |
| 161 estimated_bitrate_bps * (1.0 - protection_overhead_rate); | |
| 162 return last_encoder_target_rate_; | |
| 163 } | |
| 164 | |
| 165 uint32_t ProtectionBitrateCalculator::GetEncoderTargetRate() const { | |
| 166 CritScope lock(&crit_sect_); | |
| 167 return last_encoder_target_rate_; | |
| 158 } | 168 } |
| 159 | 169 |
| 160 void ProtectionBitrateCalculator::SetProtectionMethod(bool enable_fec, | 170 void ProtectionBitrateCalculator::SetProtectionMethod(bool enable_fec, |
| 161 bool enable_nack) { | 171 bool enable_nack) { |
| 162 media_optimization::VCMProtectionMethodEnum method(media_optimization::kNone); | 172 media_optimization::VCMProtectionMethodEnum method(media_optimization::kNone); |
| 163 if (enable_fec && enable_nack) { | 173 if (enable_fec && enable_nack) { |
| 164 method = media_optimization::kNackFec; | 174 method = media_optimization::kNackFec; |
| 165 } else if (enable_nack) { | 175 } else if (enable_nack) { |
| 166 method = media_optimization::kNack; | 176 method = media_optimization::kNack; |
| 167 } else if (enable_fec) { | 177 } else if (enable_fec) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 189 min_packets_per_frame, clock_->TimeInMilliseconds()); | 199 min_packets_per_frame, clock_->TimeInMilliseconds()); |
| 190 } | 200 } |
| 191 } | 201 } |
| 192 if (!delta_frame && encoded_length > 0) { | 202 if (!delta_frame && encoded_length > 0) { |
| 193 loss_prot_logic_->UpdateKeyFrameSize(static_cast<float>(encoded_length)); | 203 loss_prot_logic_->UpdateKeyFrameSize(static_cast<float>(encoded_length)); |
| 194 } | 204 } |
| 195 } | 205 } |
| 196 } | 206 } |
| 197 | 207 |
| 198 } // namespace webrtc | 208 } // namespace webrtc |
| OLD | NEW |