OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 framesize_kbits / large_frame_accumulation_count_; | 122 framesize_kbits / large_frame_accumulation_count_; |
123 framesize_kbits = 0; | 123 framesize_kbits = 0; |
124 } else { | 124 } else { |
125 delta_frame_size_avg_kbits_.Apply(1, framesize_kbits); | 125 delta_frame_size_avg_kbits_.Apply(1, framesize_kbits); |
126 } | 126 } |
127 key_frame_ratio_.Apply(1.0, 0.0); | 127 key_frame_ratio_.Apply(1.0, 0.0); |
128 } | 128 } |
129 // Change the level of the accumulator (bucket) | 129 // Change the level of the accumulator (bucket) |
130 accumulator_ += framesize_kbits; | 130 accumulator_ += framesize_kbits; |
131 CapAccumulator(); | 131 CapAccumulator(); |
132 LOG(LS_VERBOSE) << "FILL acc " << accumulator_ << " max " << accumulator_max_ | |
133 << " count " << large_frame_accumulation_count_ << " chunk " | |
134 << large_frame_accumulation_chunk_size_ << " spread " | |
135 << large_frame_accumulation_spread_ << " delta avg " | |
136 << delta_frame_size_avg_kbits_.filtered() << " SIZE " | |
137 << framesize_kbits << "key frame ratio " | |
138 << key_frame_ratio_.filtered(); | |
139 } | 132 } |
140 | 133 |
141 void FrameDropper::Leak(uint32_t input_framerate) { | 134 void FrameDropper::Leak(uint32_t input_framerate) { |
142 if (!enabled_) { | 135 if (!enabled_) { |
143 return; | 136 return; |
144 } | 137 } |
145 if (input_framerate < 1) { | 138 if (input_framerate < 1) { |
146 return; | 139 return; |
147 } | 140 } |
148 if (target_bitrate_ < 0.0f) { | 141 if (target_bitrate_ < 0.0f) { |
149 return; | 142 return; |
150 } | 143 } |
151 // Add lower bound for large frame accumulation spread. | 144 // Add lower bound for large frame accumulation spread. |
152 large_frame_accumulation_spread_ = std::max(0.5 * input_framerate, 5.0); | 145 large_frame_accumulation_spread_ = std::max(0.5 * input_framerate, 5.0); |
153 // Expected bits per frame based on current input frame rate. | 146 // Expected bits per frame based on current input frame rate. |
154 float expected_bits_per_frame = target_bitrate_ / input_framerate; | 147 float expected_bits_per_frame = target_bitrate_ / input_framerate; |
155 if (large_frame_accumulation_count_ > 0) { | 148 if (large_frame_accumulation_count_ > 0) { |
156 expected_bits_per_frame -= large_frame_accumulation_chunk_size_; | 149 expected_bits_per_frame -= large_frame_accumulation_chunk_size_; |
157 --large_frame_accumulation_count_; | 150 --large_frame_accumulation_count_; |
158 } | 151 } |
159 accumulator_ -= expected_bits_per_frame; | 152 accumulator_ -= expected_bits_per_frame; |
160 if (accumulator_ < 0.0f) { | 153 if (accumulator_ < 0.0f) { |
161 accumulator_ = 0.0f; | 154 accumulator_ = 0.0f; |
162 } | 155 } |
163 LOG(LS_VERBOSE) << "LEAK acc " << accumulator_ << " max " << accumulator_max_ | |
164 << " count " << large_frame_accumulation_count_ << " spread " | |
165 << large_frame_accumulation_spread_ << " delta avg " | |
166 << delta_frame_size_avg_kbits_.filtered(); | |
167 UpdateRatio(); | 156 UpdateRatio(); |
168 } | 157 } |
169 | 158 |
170 void FrameDropper::UpdateRatio() { | 159 void FrameDropper::UpdateRatio() { |
171 if (accumulator_ > 1.3f * accumulator_max_) { | 160 if (accumulator_ > 1.3f * accumulator_max_) { |
172 // Too far above accumulator max, react faster | 161 // Too far above accumulator max, react faster |
173 drop_ratio_.UpdateBase(0.8f); | 162 drop_ratio_.UpdateBase(0.8f); |
174 } else { | 163 } else { |
175 // Go back to normal reaction | 164 // Go back to normal reaction |
176 drop_ratio_.UpdateBase(0.9f); | 165 drop_ratio_.UpdateBase(0.9f); |
(...skipping 17 matching lines...) Expand all Loading... |
194 // dropRatio | 183 // dropRatio |
195 // to smooth out the drops over time. | 184 // to smooth out the drops over time. |
196 bool FrameDropper::DropFrame() { | 185 bool FrameDropper::DropFrame() { |
197 if (!enabled_) { | 186 if (!enabled_) { |
198 return false; | 187 return false; |
199 } | 188 } |
200 if (drop_next_) { | 189 if (drop_next_) { |
201 drop_next_ = false; | 190 drop_next_ = false; |
202 drop_count_ = 0; | 191 drop_count_ = 0; |
203 } | 192 } |
204 LOG(LS_VERBOSE) << " drop_ratio_ " << drop_ratio_.filtered() | |
205 << " drop_count_ " << drop_count_; | |
206 | 193 |
207 if (drop_ratio_.filtered() >= 0.5f) { // Drops per keep | 194 if (drop_ratio_.filtered() >= 0.5f) { // Drops per keep |
208 // limit is the number of frames we should drop between each kept frame | 195 // limit is the number of frames we should drop between each kept frame |
209 // to keep our drop ratio. limit is positive in this case. | 196 // to keep our drop ratio. limit is positive in this case. |
210 float denom = 1.0f - drop_ratio_.filtered(); | 197 float denom = 1.0f - drop_ratio_.filtered(); |
211 if (denom < 1e-5) { | 198 if (denom < 1e-5) { |
212 denom = 1e-5f; | 199 denom = 1e-5f; |
213 } | 200 } |
214 int32_t limit = static_cast<int32_t>(1.0f / denom - 1.0f + 0.5f); | 201 int32_t limit = static_cast<int32_t>(1.0f / denom - 1.0f + 0.5f); |
215 // Put a bound on the max amount of dropped frames between each kept | 202 // Put a bound on the max amount of dropped frames between each kept |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 // This is a temporary fix for screencasting where very large frames from | 270 // This is a temporary fix for screencasting where very large frames from |
284 // encoder will cause very slow response (too many frame drops). | 271 // encoder will cause very slow response (too many frame drops). |
285 // TODO(isheriff): Remove this now that large delta frames are also spread out ? | 272 // TODO(isheriff): Remove this now that large delta frames are also spread out ? |
286 void FrameDropper::CapAccumulator() { | 273 void FrameDropper::CapAccumulator() { |
287 float max_accumulator = target_bitrate_ * kAccumulatorCapBufferSizeSecs; | 274 float max_accumulator = target_bitrate_ * kAccumulatorCapBufferSizeSecs; |
288 if (accumulator_ > max_accumulator) { | 275 if (accumulator_ > max_accumulator) { |
289 accumulator_ = max_accumulator; | 276 accumulator_ = max_accumulator; |
290 } | 277 } |
291 } | 278 } |
292 } // namespace webrtc | 279 } // namespace webrtc |
OLD | NEW |