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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 RTC_DCHECK(param_high_kbps); | 43 RTC_DCHECK(param_high_kbps); |
44 RTC_DCHECK(param_min_low_ms); | 44 RTC_DCHECK(param_min_low_ms); |
45 std::string group = | 45 std::string group = |
46 webrtc::field_trial::FindFullName(kVp8ForceFallbackEncoderFieldTrial); | 46 webrtc::field_trial::FindFullName(kVp8ForceFallbackEncoderFieldTrial); |
47 if (group.empty()) | 47 if (group.empty()) |
48 return; | 48 return; |
49 | 49 |
50 int low_kbps; | 50 int low_kbps; |
51 int high_kbps; | 51 int high_kbps; |
52 int min_low_ms; | 52 int min_low_ms; |
53 if (sscanf(group.c_str(), "Enabled-%d,%d,%d", &low_kbps, &high_kbps, | 53 int min_pixels; |
54 &min_low_ms) != 3) { | 54 if (sscanf(group.c_str(), "Enabled-%d,%d,%d,%d", &low_kbps, &high_kbps, |
| 55 &min_low_ms, &min_pixels) != 4) { |
55 LOG(LS_WARNING) << "Invalid number of forced fallback parameters provided."; | 56 LOG(LS_WARNING) << "Invalid number of forced fallback parameters provided."; |
56 return; | 57 return; |
57 } | 58 } |
58 if (min_low_ms <= 0 || low_kbps <= 0 || high_kbps <= low_kbps) { | 59 if (min_low_ms <= 0 || min_pixels <= 0 || low_kbps <= 0 || |
| 60 high_kbps <= low_kbps) { |
59 LOG(LS_WARNING) << "Invalid forced fallback parameter value provided."; | 61 LOG(LS_WARNING) << "Invalid forced fallback parameter value provided."; |
60 return; | 62 return; |
61 } | 63 } |
62 *param_low_kbps = low_kbps; | 64 *param_low_kbps = low_kbps; |
63 *param_high_kbps = high_kbps; | 65 *param_high_kbps = high_kbps; |
64 *param_min_low_ms = min_low_ms; | 66 *param_min_low_ms = min_low_ms; |
65 } | 67 } |
66 } // namespace | 68 } // namespace |
67 | 69 |
68 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( | 70 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 240 } |
239 | 241 |
240 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { | 242 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { |
241 if (fallback_encoder_) | 243 if (fallback_encoder_) |
242 return fallback_encoder_->SupportsNativeHandle(); | 244 return fallback_encoder_->SupportsNativeHandle(); |
243 return encoder_->SupportsNativeHandle(); | 245 return encoder_->SupportsNativeHandle(); |
244 } | 246 } |
245 | 247 |
246 VideoEncoder::ScalingSettings | 248 VideoEncoder::ScalingSettings |
247 VideoEncoderSoftwareFallbackWrapper::GetScalingSettings() const { | 249 VideoEncoderSoftwareFallbackWrapper::GetScalingSettings() const { |
| 250 if (forced_fallback_possible_ && fallback_encoder_) |
| 251 return fallback_encoder_->GetScalingSettings(); |
248 return encoder_->GetScalingSettings(); | 252 return encoder_->GetScalingSettings(); |
249 } | 253 } |
250 | 254 |
251 const char *VideoEncoderSoftwareFallbackWrapper::ImplementationName() const { | 255 const char *VideoEncoderSoftwareFallbackWrapper::ImplementationName() const { |
252 if (fallback_encoder_) | 256 if (fallback_encoder_) |
253 return fallback_encoder_->ImplementationName(); | 257 return fallback_encoder_->ImplementationName(); |
254 return encoder_->ImplementationName(); | 258 return encoder_->ImplementationName(); |
255 } | 259 } |
256 | 260 |
257 bool VideoEncoderSoftwareFallbackWrapper::IsForcedFallbackActive() const { | 261 bool VideoEncoderSoftwareFallbackWrapper::IsForcedFallbackActive() const { |
258 return (forced_fallback_possible_ && fallback_encoder_ && | 262 return (forced_fallback_possible_ && fallback_encoder_ && |
259 forced_fallback_.start_ms); | 263 forced_fallback_.start_ms); |
260 } | 264 } |
261 | 265 |
262 bool VideoEncoderSoftwareFallbackWrapper::RequestForcedFallback() { | 266 bool VideoEncoderSoftwareFallbackWrapper::RequestForcedFallback() { |
263 if (!forced_fallback_possible_ || fallback_encoder_ || !rates_set_) | 267 if (!forced_fallback_possible_ || fallback_encoder_ || !rates_set_) |
264 return false; | 268 return false; |
265 | 269 |
266 // No fallback encoder. | 270 // No fallback encoder. |
267 return forced_fallback_.ShouldStart(bitrate_allocation_.get_sum_kbps(), | 271 return forced_fallback_.ShouldStart(bitrate_allocation_.get_sum_kbps(), |
268 codec_settings_); | 272 codec_settings_); |
269 } | 273 } |
270 | 274 |
271 bool VideoEncoderSoftwareFallbackWrapper::TryReleaseForcedFallbackEncoder() { | 275 bool VideoEncoderSoftwareFallbackWrapper::TryReleaseForcedFallbackEncoder() { |
272 if (!IsForcedFallbackActive()) | 276 if (!IsForcedFallbackActive()) |
273 return false; | 277 return false; |
274 | 278 |
275 if (!forced_fallback_.ShouldStop(bitrate_allocation_.get_sum_kbps())) | 279 if (!forced_fallback_.ShouldStop(bitrate_allocation_.get_sum_kbps(), |
| 280 codec_settings_)) { |
276 return false; | 281 return false; |
| 282 } |
277 | 283 |
278 // Release the forced fallback encoder. | 284 // Release the forced fallback encoder. |
279 if (encoder_->InitEncode(&codec_settings_, number_of_cores_, | 285 if (encoder_->InitEncode(&codec_settings_, number_of_cores_, |
280 max_payload_size_) == WEBRTC_VIDEO_CODEC_OK) { | 286 max_payload_size_) == WEBRTC_VIDEO_CODEC_OK) { |
281 LOG(LS_INFO) << "Stop forced SW encoder fallback, max bitrate exceeded."; | 287 LOG(LS_INFO) << "Stop forced SW encoder fallback, max bitrate exceeded."; |
282 fallback_encoder_->Release(); | 288 fallback_encoder_->Release(); |
283 fallback_encoder_.reset(); | 289 fallback_encoder_.reset(); |
284 forced_fallback_.Reset(); | 290 forced_fallback_.Reset(); |
285 return true; | 291 return true; |
286 } | 292 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 if ((now_ms - *start_ms) >= min_low_ms) { | 342 if ((now_ms - *start_ms) >= min_low_ms) { |
337 LOG(LS_INFO) << "Request forced SW encoder fallback."; | 343 LOG(LS_INFO) << "Request forced SW encoder fallback."; |
338 // In case the request fails, update time to avoid too frequent requests. | 344 // In case the request fails, update time to avoid too frequent requests. |
339 start_ms.emplace(now_ms); | 345 start_ms.emplace(now_ms); |
340 return true; | 346 return true; |
341 } | 347 } |
342 return false; | 348 return false; |
343 } | 349 } |
344 | 350 |
345 bool VideoEncoderSoftwareFallbackWrapper::ForcedFallbackParams::ShouldStop( | 351 bool VideoEncoderSoftwareFallbackWrapper::ForcedFallbackParams::ShouldStop( |
346 uint32_t bitrate_kbps) const { | 352 uint32_t bitrate_kbps, |
347 return bitrate_kbps >= high_kbps; | 353 const VideoCodec& codec) const { |
| 354 return bitrate_kbps >= high_kbps && |
| 355 (codec.width * codec.height >= kMinPixelsStop); |
348 } | 356 } |
349 | 357 |
350 } // namespace webrtc | 358 } // namespace webrtc |
OLD | NEW |