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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 wants.target_pixel_count.reset(); | 206 wants.target_pixel_count.reset(); |
207 wants.max_framerate_fps = std::numeric_limits<int>::max(); | 207 wants.max_framerate_fps = std::numeric_limits<int>::max(); |
208 } | 208 } |
209 return wants; | 209 return wants; |
210 } | 210 } |
211 | 211 |
212 void RequestResolutionLowerThan(int pixel_count) { | 212 void RequestResolutionLowerThan(int pixel_count) { |
213 // Called on the encoder task queue. | 213 // Called on the encoder task queue. |
214 rtc::CritScope lock(&crit_); | 214 rtc::CritScope lock(&crit_); |
215 if (!IsResolutionScalingEnabledLocked()) { | 215 if (!IsResolutionScalingEnabledLocked()) { |
216 // This can happen since |degradation_preference_| is set on | 216 // This can happen since |degradation_preference_| is set on libjingle's |
217 // libjingle's worker thread but the adaptation is done on the encoder | 217 // worker thread but the adaptation is done on the encoder task queue. |
218 // task queue. | |
219 return; | 218 return; |
220 } | 219 } |
221 // The input video frame size will have a resolution with less than or | 220 // The input video frame size will have a resolution with less than or |
222 // equal to |max_pixel_count| depending on how the source can scale the | 221 // equal to |max_pixel_count| depending on how the source can scale the |
223 // input frame size. | 222 // input frame size. |
224 const int pixels_wanted = (pixel_count * 3) / 5; | 223 const int pixels_wanted = (pixel_count * 3) / 5; |
225 if (pixels_wanted < kMinPixelsPerFrame) | 224 if (pixels_wanted < kMinPixelsPerFrame) |
226 return; | 225 return; |
227 sink_wants_.max_pixel_count = pixels_wanted; | 226 sink_wants_.max_pixel_count = pixels_wanted; |
228 sink_wants_.target_pixel_count = rtc::Optional<int>(); | 227 sink_wants_.target_pixel_count = rtc::Optional<int>(); |
229 if (source_) | 228 if (source_) |
230 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); | 229 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); |
231 } | 230 } |
232 | 231 |
233 void RequestFramerateLowerThan(int framerate_fps) { | 232 void RequestFramerateLowerThan(int framerate_fps) { |
234 // Called on the encoder task queue. | 233 // Called on the encoder task queue. |
235 rtc::CritScope lock(&crit_); | 234 rtc::CritScope lock(&crit_); |
236 if (!IsFramerateScalingEnabledLocked()) { | 235 if (!IsFramerateScalingEnabledLocked()) { |
237 // This can happen since |degradation_preference_| is set on | 236 // This can happen since |degradation_preference_| is set on libjingle's |
238 // libjingle's worker thread but the adaptation is done on the encoder | 237 // worker thread but the adaptation is done on the encoder task queue. |
239 // task queue. | |
240 return; | 238 return; |
241 } | 239 } |
242 // The input video frame rate will be scaled down to 2/3 of input fps, | 240 // The input video frame rate will be scaled down to 2/3 of input fps, |
243 // rounding down. | 241 // rounding down. |
244 const int framerate_wanted = | 242 const int framerate_wanted = |
245 std::max(kMinFramerateFps, (framerate_fps * 2) / 3); | 243 std::max(kMinFramerateFps, (framerate_fps * 2) / 3); |
246 sink_wants_.max_framerate_fps = framerate_wanted; | 244 sink_wants_.max_framerate_fps = framerate_wanted; |
247 if (source_) | 245 if (source_) |
248 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); | 246 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); |
249 } | 247 } |
250 | 248 |
251 void RequestHigherResolutionThan(int pixel_count) { | 249 void RequestHigherResolutionThan(int pixel_count) { |
252 rtc::CritScope lock(&crit_); | 250 rtc::CritScope lock(&crit_); |
253 if (!IsResolutionScalingEnabledLocked()) { | 251 if (!IsResolutionScalingEnabledLocked()) { |
254 // This can happen since |degradation_preference_| is set on | 252 // This can happen since |degradation_preference_| is set on libjingle's |
255 // libjingle's worker thread but the adaptation is done on the encoder | 253 // worker thread but the adaptation is done on the encoder task queue. |
256 // task queue. | |
257 return; | 254 return; |
258 } | 255 } |
259 | 256 |
260 if (pixel_count == std::numeric_limits<int>::max()) { | 257 if (pixel_count == std::numeric_limits<int>::max()) { |
261 // Remove any constraints. | 258 // Remove any constraints. |
262 sink_wants_.target_pixel_count.reset(); | 259 sink_wants_.target_pixel_count.reset(); |
263 sink_wants_.max_pixel_count = std::numeric_limits<int>::max(); | 260 sink_wants_.max_pixel_count = std::numeric_limits<int>::max(); |
264 } else { | 261 } else { |
265 // On step down we request at most 3/5 the pixel count of the previous | 262 // On step down we request at most 3/5 the pixel count of the previous |
266 // resolution, so in order to take "one step up" we request a resolution | 263 // resolution, so in order to take "one step up" we request a resolution |
267 // as close as possible to 5/3 of the current resolution. The actual pixel | 264 // as close as possible to 5/3 of the current resolution. The actual pixel |
268 // count selected depends on the capabilities of the source. In order to | 265 // count selected depends on the capabilities of the source. In order to |
269 // not take a too large step up, we cap the requested pixel count to be at | 266 // not take a too large step up, we cap the requested pixel count to be at |
270 // most four time the current number of pixels. | 267 // most four time the current number of pixels. |
271 sink_wants_.target_pixel_count = | 268 sink_wants_.target_pixel_count = |
272 rtc::Optional<int>((pixel_count * 5) / 3); | 269 rtc::Optional<int>((pixel_count * 5) / 3); |
273 sink_wants_.max_pixel_count = pixel_count * 4; | 270 sink_wants_.max_pixel_count = pixel_count * 4; |
274 } | 271 } |
275 if (source_) | 272 if (source_) |
276 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); | 273 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); |
277 } | 274 } |
278 | 275 |
279 void RequestHigherFramerateThan(int framerate_fps) { | 276 void RequestHigherFramerateThan(int framerate_fps) { |
280 // Called on the encoder task queue. | 277 // Called on the encoder task queue. |
281 rtc::CritScope lock(&crit_); | 278 rtc::CritScope lock(&crit_); |
282 if (!IsFramerateScalingEnabledLocked()) { | 279 if (!IsFramerateScalingEnabledLocked()) { |
283 // This can happen since |degradation_preference_| is set on | 280 // This can happen since |degradation_preference_| is set on libjingle's |
284 // libjingle's worker thread but the adaptation is done on the encoder | 281 // worker thread but the adaptation is done on the encoder task queue. |
285 // task queue. | |
286 return; | 282 return; |
287 } | 283 } |
288 if (framerate_fps == std::numeric_limits<int>::max()) { | 284 if (framerate_fps == std::numeric_limits<int>::max()) { |
289 // Remove any restrains. | 285 // Remove any restrains. |
290 sink_wants_.max_framerate_fps = std::numeric_limits<int>::max(); | 286 sink_wants_.max_framerate_fps = std::numeric_limits<int>::max(); |
291 } else { | 287 } else { |
292 // The input video frame rate will be scaled up to the last step, with | 288 // The input video frame rate will be scaled up to the last step, with |
293 // rounding. | 289 // rounding. |
294 const int framerate_wanted = (framerate_fps * 3) / 2; | 290 const int framerate_wanted = (framerate_fps * 3) / 2; |
295 sink_wants_.max_framerate_fps = framerate_wanted; | 291 sink_wants_.max_framerate_fps = framerate_wanted; |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 void ViEEncoder::IncrementScaleCounter(int reason, int delta) { | 967 void ViEEncoder::IncrementScaleCounter(int reason, int delta) { |
972 // Get the counters and validate. This may also lazily initialize the state. | 968 // Get the counters and validate. This may also lazily initialize the state. |
973 const std::vector<int>& counter = GetScaleCounters(); | 969 const std::vector<int>& counter = GetScaleCounters(); |
974 if (delta < 0) { | 970 if (delta < 0) { |
975 RTC_DCHECK_GE(counter[reason], delta); | 971 RTC_DCHECK_GE(counter[reason], delta); |
976 } | 972 } |
977 scale_counters_[degradation_preference_][reason] += delta; | 973 scale_counters_[degradation_preference_][reason] += delta; |
978 } | 974 } |
979 | 975 |
980 } // namespace webrtc | 976 } // namespace webrtc |
OLD | NEW |