Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 // TODO(kthelgason): Lower this limit when better testing | 42 // TODO(kthelgason): Lower this limit when better testing |
| 43 // on MediaCodec and fallback implementations are in place. | 43 // on MediaCodec and fallback implementations are in place. |
| 44 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7206 | 44 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7206 |
| 45 const int kMinPixelsPerFrame = 320 * 180; | 45 const int kMinPixelsPerFrame = 320 * 180; |
| 46 const int kMinFramerateFps = 2; | 46 const int kMinFramerateFps = 2; |
| 47 | 47 |
| 48 // The maximum number of frames to drop at beginning of stream | 48 // The maximum number of frames to drop at beginning of stream |
| 49 // to try and achieve desired bitrate. | 49 // to try and achieve desired bitrate. |
| 50 const int kMaxInitialFramedrop = 4; | 50 const int kMaxInitialFramedrop = 4; |
| 51 | 51 |
| 52 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle | |
| 53 // pipelining encoders better (multiple input frames before something comes | |
| 54 // out). This should effectively turn off CPU adaptations for systems that | |
| 55 // remotely cope with the load right now. | |
| 56 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) { | |
| 57 CpuOveruseOptions options; | |
| 58 if (full_overuse_time) { | |
| 59 options.low_encode_usage_threshold_percent = 150; | |
| 60 options.high_encode_usage_threshold_percent = 200; | |
| 61 } | |
| 62 return options; | |
| 63 } | |
| 64 | |
| 65 uint32_t MaximumFrameSizeForBitrate(uint32_t kbps) { | 52 uint32_t MaximumFrameSizeForBitrate(uint32_t kbps) { |
| 66 if (kbps > 0) { | 53 if (kbps > 0) { |
| 67 if (kbps < 300 /* qvga */) { | 54 if (kbps < 300 /* qvga */) { |
| 68 return 320 * 240; | 55 return 320 * 240; |
| 69 } else if (kbps < 500 /* vga */) { | 56 } else if (kbps < 500 /* vga */) { |
| 70 return 640 * 480; | 57 return 640 * 480; |
| 71 } | 58 } |
| 72 } | 59 } |
| 73 return std::numeric_limits<uint32_t>::max(); | 60 return std::numeric_limits<uint32_t>::max(); |
| 74 } | 61 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 pixels_wanted >= sink_wants_.max_pixel_count) { | 229 pixels_wanted >= sink_wants_.max_pixel_count) { |
| 243 return false; | 230 return false; |
| 244 } | 231 } |
| 245 LOG(LS_INFO) << "Scaling down resolution, max pixels: " << pixels_wanted; | 232 LOG(LS_INFO) << "Scaling down resolution, max pixels: " << pixels_wanted; |
| 246 sink_wants_.max_pixel_count = pixels_wanted; | 233 sink_wants_.max_pixel_count = pixels_wanted; |
| 247 sink_wants_.target_pixel_count = rtc::Optional<int>(); | 234 sink_wants_.target_pixel_count = rtc::Optional<int>(); |
| 248 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); | 235 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); |
| 249 return true; | 236 return true; |
| 250 } | 237 } |
| 251 | 238 |
| 252 bool RequestFramerateLowerThan(int fps) { | 239 int RequestFramerateLowerThan(int fps) { |
| 253 // Called on the encoder task queue. | 240 // Called on the encoder task queue. |
| 254 // The input video frame rate will be scaled down to 2/3, rounding down. | 241 // The input video frame rate will be scaled down to 2/3, rounding down. |
| 255 return RestrictFramerate((fps * 2) / 3); | 242 int wanted_framerate = (fps * 2) / 3; |
|
åsapersson
2017/06/13 12:15:09
nit: maybe framerate_wanted for consistency with R
sprang_webrtc
2017/06/14 08:39:16
Done.
| |
| 243 return RestrictFramerate(wanted_framerate) ? wanted_framerate : -1; | |
| 256 } | 244 } |
| 257 | 245 |
| 258 bool RequestHigherResolutionThan(int pixel_count) { | 246 bool RequestHigherResolutionThan(int pixel_count) { |
| 259 // Called on the encoder task queue. | 247 // Called on the encoder task queue. |
| 260 rtc::CritScope lock(&crit_); | 248 rtc::CritScope lock(&crit_); |
| 261 if (!source_ || !IsResolutionScalingEnabled(degradation_preference_)) { | 249 if (!source_ || !IsResolutionScalingEnabled(degradation_preference_)) { |
| 262 // This can happen since |degradation_preference_| is set on libjingle's | 250 // This can happen since |degradation_preference_| is set on libjingle's |
| 263 // worker thread but the adaptation is done on the encoder task queue. | 251 // worker thread but the adaptation is done on the encoder task queue. |
| 264 return false; | 252 return false; |
| 265 } | 253 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 282 // not take a too large step up, we cap the requested pixel count to be at | 270 // not take a too large step up, we cap the requested pixel count to be at |
| 283 // most four time the current number of pixels. | 271 // most four time the current number of pixels. |
| 284 sink_wants_.target_pixel_count = | 272 sink_wants_.target_pixel_count = |
| 285 rtc::Optional<int>((pixel_count * 5) / 3); | 273 rtc::Optional<int>((pixel_count * 5) / 3); |
| 286 } | 274 } |
| 287 LOG(LS_INFO) << "Scaling up resolution, max pixels: " << max_pixels_wanted; | 275 LOG(LS_INFO) << "Scaling up resolution, max pixels: " << max_pixels_wanted; |
| 288 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); | 276 source_->AddOrUpdateSink(vie_encoder_, GetActiveSinkWants()); |
| 289 return true; | 277 return true; |
| 290 } | 278 } |
| 291 | 279 |
| 292 bool RequestHigherFramerateThan(int fps) { | 280 // Request upgrade in framerate. Returns the new requested frame, or -1 if |
| 281 // no change requested. Note that maxint may be returned if limits due to | |
| 282 // adaptation requests are removed completely. In that case, consider | |
| 283 // |max_framerate_| to be the current limit (assuming the capturer complies). | |
| 284 int RequestHigherFramerateThan(int fps) { | |
| 293 // Called on the encoder task queue. | 285 // Called on the encoder task queue. |
| 294 // The input frame rate will be scaled up to the last step, with rounding. | 286 // The input frame rate will be scaled up to the last step, with rounding. |
| 295 int framerate_wanted = fps; | 287 int framerate_wanted = fps; |
| 296 if (fps != std::numeric_limits<int>::max()) | 288 if (fps != std::numeric_limits<int>::max()) |
| 297 framerate_wanted = (fps * 3) / 2; | 289 framerate_wanted = (fps * 3) / 2; |
| 298 | 290 |
| 299 return IncreaseFramerate(framerate_wanted); | 291 return IncreaseFramerate(framerate_wanted) ? framerate_wanted : -1; |
| 300 } | 292 } |
| 301 | 293 |
| 302 bool RestrictFramerate(int fps) { | 294 bool RestrictFramerate(int fps) { |
| 303 // Called on the encoder task queue. | 295 // Called on the encoder task queue. |
| 304 rtc::CritScope lock(&crit_); | 296 rtc::CritScope lock(&crit_); |
| 305 if (!source_ || !IsFramerateScalingEnabled(degradation_preference_)) | 297 if (!source_ || !IsFramerateScalingEnabled(degradation_preference_)) |
| 306 return false; | 298 return false; |
| 307 | 299 |
| 308 const int fps_wanted = std::max(kMinFramerateFps, fps); | 300 const int fps_wanted = std::max(kMinFramerateFps, fps); |
| 309 if (fps_wanted >= sink_wants_.max_framerate_fps) | 301 if (fps_wanted >= sink_wants_.max_framerate_fps) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 EncodedFrameObserver* encoder_timing) | 342 EncodedFrameObserver* encoder_timing) |
| 351 : shutdown_event_(true /* manual_reset */, false), | 343 : shutdown_event_(true /* manual_reset */, false), |
| 352 number_of_cores_(number_of_cores), | 344 number_of_cores_(number_of_cores), |
| 353 initial_rampup_(0), | 345 initial_rampup_(0), |
| 354 source_proxy_(new VideoSourceProxy(this)), | 346 source_proxy_(new VideoSourceProxy(this)), |
| 355 sink_(nullptr), | 347 sink_(nullptr), |
| 356 settings_(settings), | 348 settings_(settings), |
| 357 codec_type_(PayloadNameToCodecType(settings.payload_name) | 349 codec_type_(PayloadNameToCodecType(settings.payload_name) |
| 358 .value_or(VideoCodecType::kVideoCodecUnknown)), | 350 .value_or(VideoCodecType::kVideoCodecUnknown)), |
| 359 video_sender_(Clock::GetRealTimeClock(), this, this), | 351 video_sender_(Clock::GetRealTimeClock(), this, this), |
| 360 overuse_detector_(GetCpuOveruseOptions(settings.full_overuse_time), | 352 overuse_detector_(new OveruseFrameDetector( |
| 361 this, | 353 GetCpuOveruseOptions(settings.full_overuse_time), |
| 362 encoder_timing, | 354 this, |
| 363 stats_proxy), | 355 encoder_timing, |
| 356 stats_proxy)), | |
| 364 stats_proxy_(stats_proxy), | 357 stats_proxy_(stats_proxy), |
| 365 pre_encode_callback_(pre_encode_callback), | 358 pre_encode_callback_(pre_encode_callback), |
| 366 module_process_thread_(nullptr), | 359 module_process_thread_(nullptr), |
| 360 max_framerate_(-1), | |
| 367 pending_encoder_reconfiguration_(false), | 361 pending_encoder_reconfiguration_(false), |
| 368 encoder_start_bitrate_bps_(0), | 362 encoder_start_bitrate_bps_(0), |
| 369 max_data_payload_length_(0), | 363 max_data_payload_length_(0), |
| 370 nack_enabled_(false), | 364 nack_enabled_(false), |
| 371 last_observed_bitrate_bps_(0), | 365 last_observed_bitrate_bps_(0), |
| 372 encoder_paused_and_dropped_frame_(false), | 366 encoder_paused_and_dropped_frame_(false), |
| 373 clock_(Clock::GetRealTimeClock()), | 367 clock_(Clock::GetRealTimeClock()), |
| 374 degradation_preference_( | 368 degradation_preference_( |
| 375 VideoSendStream::DegradationPreference::kDegradationDisabled), | 369 VideoSendStream::DegradationPreference::kDegradationDisabled), |
| 376 last_captured_timestamp_(0), | 370 last_captured_timestamp_(0), |
| 377 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 371 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
| 378 clock_->TimeInMilliseconds()), | 372 clock_->TimeInMilliseconds()), |
| 379 last_frame_log_ms_(clock_->TimeInMilliseconds()), | 373 last_frame_log_ms_(clock_->TimeInMilliseconds()), |
| 380 captured_frame_count_(0), | 374 captured_frame_count_(0), |
| 381 dropped_frame_count_(0), | 375 dropped_frame_count_(0), |
| 382 bitrate_observer_(nullptr), | 376 bitrate_observer_(nullptr), |
| 383 encoder_queue_("EncoderQueue") { | 377 encoder_queue_("EncoderQueue") { |
| 384 RTC_DCHECK(stats_proxy); | 378 RTC_DCHECK(stats_proxy); |
| 385 encoder_queue_.PostTask([this] { | 379 encoder_queue_.PostTask([this] { |
| 386 RTC_DCHECK_RUN_ON(&encoder_queue_); | 380 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 387 overuse_detector_.StartCheckForOveruse(); | 381 overuse_detector_->StartCheckForOveruse(); |
| 388 video_sender_.RegisterExternalEncoder( | 382 video_sender_.RegisterExternalEncoder( |
| 389 settings_.encoder, settings_.payload_type, settings_.internal_source); | 383 settings_.encoder, settings_.payload_type, settings_.internal_source); |
| 390 }); | 384 }); |
| 391 } | 385 } |
| 392 | 386 |
| 393 ViEEncoder::~ViEEncoder() { | 387 ViEEncoder::~ViEEncoder() { |
| 394 RTC_DCHECK_RUN_ON(&thread_checker_); | 388 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 395 RTC_DCHECK(shutdown_event_.Wait(0)) | 389 RTC_DCHECK(shutdown_event_.Wait(0)) |
| 396 << "Must call ::Stop() before destruction."; | 390 << "Must call ::Stop() before destruction."; |
| 397 } | 391 } |
| 398 | 392 |
| 393 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle | |
| 394 // pipelining encoders better (multiple input frames before something comes | |
| 395 // out). This should effectively turn off CPU adaptations for systems that | |
| 396 // remotely cope with the load right now. | |
| 397 CpuOveruseOptions ViEEncoder::GetCpuOveruseOptions(bool full_overuse_time) { | |
| 398 CpuOveruseOptions options; | |
| 399 if (full_overuse_time) { | |
| 400 options.low_encode_usage_threshold_percent = 150; | |
| 401 options.high_encode_usage_threshold_percent = 200; | |
| 402 } | |
| 403 return options; | |
| 404 } | |
| 405 | |
| 406 void ViEEncoder::UpdateOveruseDetector( | |
|
kthelgason
2017/06/12 11:56:47
Is this only used in the test? I'd prefer we not m
sprang_webrtc
2017/06/14 08:39:17
Done.
| |
| 407 std::unique_ptr<OveruseFrameDetector> overuse_detector) { | |
| 408 rtc::Event event(false, false); | |
| 409 encoder_queue_.PostTask([this, &overuse_detector, &event] { | |
| 410 RTC_DCHECK_RUN_ON(&encoder_queue_); | |
| 411 overuse_detector_->StopCheckForOveruse(); | |
| 412 overuse_detector_ = std::move(overuse_detector); | |
| 413 overuse_detector_->StartCheckForOveruse(); | |
| 414 event.Set(); | |
| 415 }); | |
| 416 RTC_DCHECK(event.Wait(5000)); | |
| 417 } | |
| 418 | |
| 399 void ViEEncoder::Stop() { | 419 void ViEEncoder::Stop() { |
| 400 RTC_DCHECK_RUN_ON(&thread_checker_); | 420 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 401 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference()); | 421 source_proxy_->SetSource(nullptr, VideoSendStream::DegradationPreference()); |
| 402 encoder_queue_.PostTask([this] { | 422 encoder_queue_.PostTask([this] { |
| 403 RTC_DCHECK_RUN_ON(&encoder_queue_); | 423 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 404 overuse_detector_.StopCheckForOveruse(); | 424 overuse_detector_->StopCheckForOveruse(); |
| 405 rate_allocator_.reset(); | 425 rate_allocator_.reset(); |
| 406 bitrate_observer_ = nullptr; | 426 bitrate_observer_ = nullptr; |
| 407 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, | 427 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, |
| 408 false); | 428 false); |
| 409 quality_scaler_ = nullptr; | 429 quality_scaler_ = nullptr; |
| 410 shutdown_event_.Set(); | 430 shutdown_event_.Set(); |
| 411 }); | 431 }); |
| 412 | 432 |
| 413 shutdown_event_.Wait(rtc::Event::kForever); | 433 shutdown_event_.Wait(rtc::Event::kForever); |
| 414 } | 434 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 445 RTC_DCHECK_RUN_ON(&encoder_queue_); | 465 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 446 if (degradation_preference_ != degradation_preference) { | 466 if (degradation_preference_ != degradation_preference) { |
| 447 // Reset adaptation state, so that we're not tricked into thinking there's | 467 // Reset adaptation state, so that we're not tricked into thinking there's |
| 448 // an already pending request of the same type. | 468 // an already pending request of the same type. |
| 449 last_adaptation_request_.reset(); | 469 last_adaptation_request_.reset(); |
| 450 } | 470 } |
| 451 degradation_preference_ = degradation_preference; | 471 degradation_preference_ = degradation_preference; |
| 452 bool allow_scaling = IsResolutionScalingEnabled(degradation_preference_); | 472 bool allow_scaling = IsResolutionScalingEnabled(degradation_preference_); |
| 453 initial_rampup_ = allow_scaling ? 0 : kMaxInitialFramedrop; | 473 initial_rampup_ = allow_scaling ? 0 : kMaxInitialFramedrop; |
| 454 ConfigureQualityScaler(); | 474 ConfigureQualityScaler(); |
| 475 if (!IsFramerateScalingEnabled(degradation_preference) && | |
| 476 max_framerate_ != -1) { | |
| 477 // If frame rate scaling is no longer allowed, remove any potential | |
| 478 // allowance for longer frame intervals. | |
| 479 overuse_detector_->OnTargetFramerateUpdated(max_framerate_); | |
| 480 } | |
| 455 }); | 481 }); |
| 456 } | 482 } |
| 457 | 483 |
| 458 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { | 484 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { |
| 459 source_proxy_->SetWantsRotationApplied(rotation_applied); | 485 source_proxy_->SetWantsRotationApplied(rotation_applied); |
| 460 encoder_queue_.PostTask([this, sink] { | 486 encoder_queue_.PostTask([this, sink] { |
| 461 RTC_DCHECK_RUN_ON(&encoder_queue_); | 487 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 462 sink_ = sink; | 488 sink_ = sink; |
| 463 }); | 489 }); |
| 464 } | 490 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 if (!VideoCodecInitializer::SetupCodec(encoder_config_, settings_, streams, | 540 if (!VideoCodecInitializer::SetupCodec(encoder_config_, settings_, streams, |
| 515 nack_enabled_, &codec, | 541 nack_enabled_, &codec, |
| 516 &rate_allocator_)) { | 542 &rate_allocator_)) { |
| 517 LOG(LS_ERROR) << "Failed to create encoder configuration."; | 543 LOG(LS_ERROR) << "Failed to create encoder configuration."; |
| 518 } | 544 } |
| 519 | 545 |
| 520 codec.startBitrate = | 546 codec.startBitrate = |
| 521 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); | 547 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); |
| 522 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); | 548 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); |
| 523 codec.expect_encode_from_texture = last_frame_info_->is_texture; | 549 codec.expect_encode_from_texture = last_frame_info_->is_texture; |
| 550 max_framerate_ = codec.maxFramerate; | |
| 524 | 551 |
| 525 bool success = video_sender_.RegisterSendCodec( | 552 bool success = video_sender_.RegisterSendCodec( |
| 526 &codec, number_of_cores_, | 553 &codec, number_of_cores_, |
| 527 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; | 554 static_cast<uint32_t>(max_data_payload_length_)) == VCM_OK; |
| 528 if (!success) { | 555 if (!success) { |
| 529 LOG(LS_ERROR) << "Failed to configure encoder."; | 556 LOG(LS_ERROR) << "Failed to configure encoder."; |
| 530 rate_allocator_.reset(); | 557 rate_allocator_.reset(); |
| 531 } | 558 } |
| 532 | 559 |
| 533 video_sender_.UpdateChannelParemeters(rate_allocator_.get(), | 560 video_sender_.UpdateChannelParemeters(rate_allocator_.get(), |
| 534 bitrate_observer_); | 561 bitrate_observer_); |
| 535 | 562 |
| 536 int framerate = stats_proxy_->GetSendFrameRate(); | 563 // Get the current actual framerate, as measured by the stats proxy. This is |
| 537 if (framerate == 0) | 564 // used to get the correct bitrate layer allocation. |
| 538 framerate = codec.maxFramerate; | 565 int current_framerate = stats_proxy_->GetSendFrameRate(); |
| 566 if (current_framerate == 0) | |
| 567 current_framerate = codec.maxFramerate; | |
| 539 stats_proxy_->OnEncoderReconfigured( | 568 stats_proxy_->OnEncoderReconfigured( |
| 540 encoder_config_, rate_allocator_.get() | 569 encoder_config_, |
| 541 ? rate_allocator_->GetPreferredBitrateBps(framerate) | 570 rate_allocator_.get() |
| 542 : codec.maxBitrate); | 571 ? rate_allocator_->GetPreferredBitrateBps(current_framerate) |
| 572 : codec.maxBitrate); | |
| 543 | 573 |
| 544 pending_encoder_reconfiguration_ = false; | 574 pending_encoder_reconfiguration_ = false; |
| 545 | 575 |
| 546 sink_->OnEncoderConfigurationChanged( | 576 sink_->OnEncoderConfigurationChanged( |
| 547 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 577 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
| 548 | 578 |
| 579 // Get the current target framerate, ie the maximum framerate as specified by | |
| 580 // the current codec configuration, or any limit imposed by cpu adaption in | |
| 581 // maintain-resolution or balanced mode. This is used to make sure overuse | |
| 582 // detection doesn't needlessly trigger in low and/or variable framerate | |
| 583 // scenarios. | |
| 584 int target_framerate = max_framerate_; | |
| 585 if (last_adaptation_request_ && | |
| 586 last_adaptation_request_->framerate_fps_ > 0) { | |
|
åsapersson
2017/06/13 12:15:09
last_adaptation_request_->framerate_fps_ will not
sprang_webrtc
2017/06/14 08:39:16
Hm, you're right. Guess I'll have to add another f
| |
| 587 target_framerate = | |
| 588 std::min(target_framerate, last_adaptation_request_->framerate_fps_); | |
| 589 } | |
| 590 overuse_detector_->OnTargetFramerateUpdated(target_framerate); | |
| 591 | |
| 549 ConfigureQualityScaler(); | 592 ConfigureQualityScaler(); |
| 550 } | 593 } |
| 551 | 594 |
| 552 void ViEEncoder::ConfigureQualityScaler() { | 595 void ViEEncoder::ConfigureQualityScaler() { |
| 553 RTC_DCHECK_RUN_ON(&encoder_queue_); | 596 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 554 const auto scaling_settings = settings_.encoder->GetScalingSettings(); | 597 const auto scaling_settings = settings_.encoder->GetScalingSettings(); |
| 555 const bool quality_scaling_allowed = | 598 const bool quality_scaling_allowed = |
| 556 IsResolutionScalingEnabled(degradation_preference_) && | 599 IsResolutionScalingEnabled(degradation_preference_) && |
| 557 scaling_settings.enabled; | 600 scaling_settings.enabled; |
| 558 | 601 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 | 730 |
| 688 if (EncoderPaused()) { | 731 if (EncoderPaused()) { |
| 689 TraceFrameDropStart(); | 732 TraceFrameDropStart(); |
| 690 return; | 733 return; |
| 691 } | 734 } |
| 692 TraceFrameDropEnd(); | 735 TraceFrameDropEnd(); |
| 693 | 736 |
| 694 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 737 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| 695 "Encode"); | 738 "Encode"); |
| 696 | 739 |
| 697 overuse_detector_.FrameCaptured(video_frame, time_when_posted_us); | 740 overuse_detector_->FrameCaptured(video_frame, time_when_posted_us); |
| 698 | 741 |
| 699 video_sender_.AddVideoFrame(video_frame, nullptr); | 742 video_sender_.AddVideoFrame(video_frame, nullptr); |
| 700 } | 743 } |
| 701 | 744 |
| 702 void ViEEncoder::SendKeyFrame() { | 745 void ViEEncoder::SendKeyFrame() { |
| 703 if (!encoder_queue_.IsCurrent()) { | 746 if (!encoder_queue_.IsCurrent()) { |
| 704 encoder_queue_.PostTask([this] { SendKeyFrame(); }); | 747 encoder_queue_.PostTask([this] { SendKeyFrame(); }); |
| 705 return; | 748 return; |
| 706 } | 749 } |
| 707 RTC_DCHECK_RUN_ON(&encoder_queue_); | 750 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 718 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); | 761 stats_proxy_->OnSendEncodedImage(encoded_image, codec_specific_info); |
| 719 | 762 |
| 720 EncodedImageCallback::Result result = | 763 EncodedImageCallback::Result result = |
| 721 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); | 764 sink_->OnEncodedImage(encoded_image, codec_specific_info, fragmentation); |
| 722 | 765 |
| 723 int64_t time_sent_us = rtc::TimeMicros(); | 766 int64_t time_sent_us = rtc::TimeMicros(); |
| 724 uint32_t timestamp = encoded_image._timeStamp; | 767 uint32_t timestamp = encoded_image._timeStamp; |
| 725 const int qp = encoded_image.qp_; | 768 const int qp = encoded_image.qp_; |
| 726 encoder_queue_.PostTask([this, timestamp, time_sent_us, qp] { | 769 encoder_queue_.PostTask([this, timestamp, time_sent_us, qp] { |
| 727 RTC_DCHECK_RUN_ON(&encoder_queue_); | 770 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 728 overuse_detector_.FrameSent(timestamp, time_sent_us); | 771 overuse_detector_->FrameSent(timestamp, time_sent_us); |
| 729 if (quality_scaler_ && qp >= 0) | 772 if (quality_scaler_ && qp >= 0) |
| 730 quality_scaler_->ReportQP(qp); | 773 quality_scaler_->ReportQP(qp); |
| 731 }); | 774 }); |
| 732 | 775 |
| 733 return result; | 776 return result; |
| 734 } | 777 } |
| 735 | 778 |
| 736 void ViEEncoder::OnDroppedFrame() { | 779 void ViEEncoder::OnDroppedFrame() { |
| 737 encoder_queue_.PostTask([this] { | 780 encoder_queue_.PostTask([this] { |
| 738 RTC_DCHECK_RUN_ON(&encoder_queue_); | 781 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 case VideoSendStream::DegradationPreference::kBalanced: | 887 case VideoSendStream::DegradationPreference::kBalanced: |
| 845 FALLTHROUGH(); | 888 FALLTHROUGH(); |
| 846 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 889 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
| 847 // Scale down resolution. | 890 // Scale down resolution. |
| 848 if (!source_proxy_->RequestResolutionLowerThan( | 891 if (!source_proxy_->RequestResolutionLowerThan( |
| 849 adaptation_request.input_pixel_count_)) { | 892 adaptation_request.input_pixel_count_)) { |
| 850 return; | 893 return; |
| 851 } | 894 } |
| 852 GetAdaptCounter().IncrementResolution(reason, 1); | 895 GetAdaptCounter().IncrementResolution(reason, 1); |
| 853 break; | 896 break; |
| 854 case VideoSendStream::DegradationPreference::kMaintainResolution: | 897 case VideoSendStream::DegradationPreference::kMaintainResolution: { |
| 855 // Scale down framerate. | 898 // Scale down framerate. |
| 856 if (!source_proxy_->RequestFramerateLowerThan( | 899 int requested_framerate = source_proxy_->RequestFramerateLowerThan( |
|
kthelgason
2017/06/12 11:56:48
const
sprang_webrtc
2017/06/14 08:39:17
Done.
| |
| 857 adaptation_request.framerate_fps_)) { | 900 adaptation_request.framerate_fps_); |
| 901 if (requested_framerate == -1) | |
| 858 return; | 902 return; |
| 859 } | 903 overuse_detector_->OnTargetFramerateUpdated( |
| 904 std::min(max_framerate_, requested_framerate)); | |
| 860 GetAdaptCounter().IncrementFramerate(reason, 1); | 905 GetAdaptCounter().IncrementFramerate(reason, 1); |
| 861 break; | 906 break; |
| 907 } | |
| 862 case VideoSendStream::DegradationPreference::kDegradationDisabled: | 908 case VideoSendStream::DegradationPreference::kDegradationDisabled: |
| 863 RTC_NOTREACHED(); | 909 RTC_NOTREACHED(); |
| 864 } | 910 } |
| 865 | 911 |
| 866 last_adaptation_request_.emplace(adaptation_request); | 912 last_adaptation_request_.emplace(adaptation_request); |
| 867 | 913 |
| 868 UpdateAdaptationStats(reason); | 914 UpdateAdaptationStats(reason); |
| 869 | 915 |
| 870 LOG(LS_INFO) << GetConstAdaptCounter().ToString(); | 916 LOG(LS_INFO) << GetConstAdaptCounter().ToString(); |
| 871 } | 917 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 923 GetAdaptCounter().IncrementResolution(reason, -1); | 969 GetAdaptCounter().IncrementResolution(reason, -1); |
| 924 break; | 970 break; |
| 925 } | 971 } |
| 926 case VideoSendStream::DegradationPreference::kMaintainResolution: { | 972 case VideoSendStream::DegradationPreference::kMaintainResolution: { |
| 927 // Scale up framerate. | 973 // Scale up framerate. |
| 928 int fps = adaptation_request.framerate_fps_; | 974 int fps = adaptation_request.framerate_fps_; |
| 929 if (adapt_counter.FramerateCount() == 1) { | 975 if (adapt_counter.FramerateCount() == 1) { |
| 930 LOG(LS_INFO) << "Removing framerate down-scaling setting."; | 976 LOG(LS_INFO) << "Removing framerate down-scaling setting."; |
| 931 fps = std::numeric_limits<int>::max(); | 977 fps = std::numeric_limits<int>::max(); |
| 932 } | 978 } |
| 933 if (!source_proxy_->RequestHigherFramerateThan(fps)) | 979 |
| 980 int requested_framerate = source_proxy_->RequestHigherFramerateThan(fps); | |
|
kthelgason
2017/06/12 11:56:47
const
sprang_webrtc
2017/06/14 08:39:16
Done.
| |
| 981 if (requested_framerate == -1) { | |
| 982 overuse_detector_->OnTargetFramerateUpdated(max_framerate_); | |
| 934 return; | 983 return; |
| 984 } | |
| 985 overuse_detector_->OnTargetFramerateUpdated( | |
| 986 std::min(max_framerate_, requested_framerate)); | |
| 935 GetAdaptCounter().IncrementFramerate(reason, -1); | 987 GetAdaptCounter().IncrementFramerate(reason, -1); |
| 936 break; | 988 break; |
| 937 } | 989 } |
| 938 case VideoSendStream::DegradationPreference::kDegradationDisabled: | 990 case VideoSendStream::DegradationPreference::kDegradationDisabled: |
| 939 RTC_NOTREACHED(); | 991 RTC_NOTREACHED(); |
| 940 } | 992 } |
| 941 | 993 |
| 942 last_adaptation_request_.emplace(adaptation_request); | 994 last_adaptation_request_.emplace(adaptation_request); |
| 943 | 995 |
| 944 UpdateAdaptationStats(reason); | 996 UpdateAdaptationStats(reason); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1051 std::string ViEEncoder::AdaptCounter::ToString( | 1103 std::string ViEEncoder::AdaptCounter::ToString( |
| 1052 const std::vector<int>& counters) const { | 1104 const std::vector<int>& counters) const { |
| 1053 std::stringstream ss; | 1105 std::stringstream ss; |
| 1054 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { | 1106 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { |
| 1055 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; | 1107 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; |
| 1056 } | 1108 } |
| 1057 return ss.str(); | 1109 return ss.str(); |
| 1058 } | 1110 } |
| 1059 | 1111 |
| 1060 } // namespace webrtc | 1112 } // namespace webrtc |
| OLD | NEW |