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 24 matching lines...) Expand all Loading... | |
| 35 const int64_t kFrameLogIntervalMs = 60000; | 35 const int64_t kFrameLogIntervalMs = 60000; |
| 36 // We will never ask for a resolution lower than this. | 36 // We will never ask for a resolution lower than this. |
| 37 #if defined(WEBRTC_ANDROID) | 37 #if defined(WEBRTC_ANDROID) |
| 38 // TODO(kthelgason): Lower this limit when better testing | 38 // TODO(kthelgason): Lower this limit when better testing |
| 39 // on MediaCodec and fallback implementations are in place. | 39 // on MediaCodec and fallback implementations are in place. |
| 40 const int kMinPixelsPerFrame = 320 * 180; | 40 const int kMinPixelsPerFrame = 320 * 180; |
| 41 #else | 41 #else |
| 42 const int kMinPixelsPerFrame = 120 * 90; | 42 const int kMinPixelsPerFrame = 120 * 90; |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 // The maximum number of frames to drop at beginning of stream | |
|
perkj_webrtc
2017/01/24 09:06:16
same here. It happens every time the resolution ch
kthelgason
2017/01/24 10:53:10
Acknowledged.
| |
| 46 // to try and achieve desired bitrate. | |
| 47 const int kMaxInitialFramedrop = 4; | |
| 48 | |
| 45 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle | 49 // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle |
| 46 // pipelining encoders better (multiple input frames before something comes | 50 // pipelining encoders better (multiple input frames before something comes |
| 47 // out). This should effectively turn off CPU adaptations for systems that | 51 // out). This should effectively turn off CPU adaptations for systems that |
| 48 // remotely cope with the load right now. | 52 // remotely cope with the load right now. |
| 49 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) { | 53 CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) { |
| 50 CpuOveruseOptions options; | 54 CpuOveruseOptions options; |
| 51 if (full_overuse_time) { | 55 if (full_overuse_time) { |
| 52 options.low_encode_usage_threshold_percent = 150; | 56 options.low_encode_usage_threshold_percent = 150; |
| 53 options.high_encode_usage_threshold_percent = 200; | 57 options.high_encode_usage_threshold_percent = 200; |
| 54 } | 58 } |
| 55 return options; | 59 return options; |
| 56 } | 60 } |
| 57 | 61 |
| 62 uint32_t MaximumFrameSizeForBitrate(uint32_t kbps) { | |
| 63 if (kbps > 0) { | |
|
perkj_webrtc
2017/01/24 09:06:16
kbps can never be 0 right?
RTC_DCHECK(kbps >0) in
kthelgason
2017/01/24 10:53:10
It can actually be zero. |encoder_start_bitrate_|
| |
| 64 if (kbps < 300 /* qvga */) { | |
| 65 return 320 * 240; | |
| 66 } else if (kbps < 500 /* vga */) { | |
| 67 return 640 * 480; | |
| 68 } | |
| 69 } | |
| 70 return std::numeric_limits<uint32_t>::max(); | |
| 71 } | |
| 72 | |
| 58 } // namespace | 73 } // namespace |
| 59 | 74 |
| 60 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { | 75 class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { |
| 61 public: | 76 public: |
| 62 ConfigureEncoderTask(ViEEncoder* vie_encoder, | 77 ConfigureEncoderTask(ViEEncoder* vie_encoder, |
| 63 VideoEncoderConfig config, | 78 VideoEncoderConfig config, |
| 64 size_t max_data_payload_length, | 79 size_t max_data_payload_length, |
| 65 bool nack_enabled) | 80 bool nack_enabled) |
| 66 : vie_encoder_(vie_encoder), | 81 : vie_encoder_(vie_encoder), |
| 67 config_(std::move(config)), | 82 config_(std::move(config)), |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); | 252 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); |
| 238 }; | 253 }; |
| 239 | 254 |
| 240 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 255 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
| 241 SendStatisticsProxy* stats_proxy, | 256 SendStatisticsProxy* stats_proxy, |
| 242 const VideoSendStream::Config::EncoderSettings& settings, | 257 const VideoSendStream::Config::EncoderSettings& settings, |
| 243 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 258 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
| 244 EncodedFrameObserver* encoder_timing) | 259 EncodedFrameObserver* encoder_timing) |
| 245 : shutdown_event_(true /* manual_reset */, false), | 260 : shutdown_event_(true /* manual_reset */, false), |
| 246 number_of_cores_(number_of_cores), | 261 number_of_cores_(number_of_cores), |
| 262 initial_rampup_(kMaxInitialFramedrop), | |
| 247 source_proxy_(new VideoSourceProxy(this)), | 263 source_proxy_(new VideoSourceProxy(this)), |
| 248 sink_(nullptr), | 264 sink_(nullptr), |
| 249 settings_(settings), | 265 settings_(settings), |
| 250 codec_type_(PayloadNameToCodecType(settings.payload_name) | 266 codec_type_(PayloadNameToCodecType(settings.payload_name) |
| 251 .value_or(VideoCodecType::kVideoCodecUnknown)), | 267 .value_or(VideoCodecType::kVideoCodecUnknown)), |
| 252 video_sender_(Clock::GetRealTimeClock(), this, this), | 268 video_sender_(Clock::GetRealTimeClock(), this, this), |
| 253 overuse_detector_(Clock::GetRealTimeClock(), | 269 overuse_detector_(Clock::GetRealTimeClock(), |
| 254 GetCpuOveruseOptions(settings.full_overuse_time), | 270 GetCpuOveruseOptions(settings.full_overuse_time), |
| 255 this, | 271 this, |
| 256 encoder_timing, | 272 encoder_timing, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); | 448 encoder_config_, rate_allocator_->GetPreferredBitrateBps(framerate)); |
| 433 } | 449 } |
| 434 | 450 |
| 435 pending_encoder_reconfiguration_ = false; | 451 pending_encoder_reconfiguration_ = false; |
| 436 | 452 |
| 437 sink_->OnEncoderConfigurationChanged( | 453 sink_->OnEncoderConfigurationChanged( |
| 438 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 454 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
| 439 | 455 |
| 440 const auto scaling_settings = settings_.encoder->GetScalingSettings(); | 456 const auto scaling_settings = settings_.encoder->GetScalingSettings(); |
| 441 if (scaling_enabled_ && scaling_settings.enabled) { | 457 if (scaling_enabled_ && scaling_settings.enabled) { |
| 458 // Drop frames and scale down until desired quality is achieved. | |
| 459 initial_rampup_ = 0; | |
| 442 if (scaling_settings.thresholds) { | 460 if (scaling_settings.thresholds) { |
| 443 quality_scaler_.reset( | 461 quality_scaler_.reset( |
| 444 new QualityScaler(this, *(scaling_settings.thresholds))); | 462 new QualityScaler(this, *(scaling_settings.thresholds))); |
| 445 } else { | 463 } else { |
| 446 quality_scaler_.reset(new QualityScaler(this, codec_type_)); | 464 quality_scaler_.reset(new QualityScaler(this, codec_type_)); |
| 447 } | 465 } |
| 448 } else { | 466 } else { |
| 449 quality_scaler_.reset(nullptr); | 467 quality_scaler_.reset(nullptr); |
| 450 stats_proxy_->SetResolutionRestrictionStats( | 468 stats_proxy_->SetResolutionRestrictionStats( |
| 451 false, scale_counter_[kCpu] > 0, scale_counter_[kQuality]); | 469 false, scale_counter_[kCpu] > 0, scale_counter_[kQuality]); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 bitrate_observer_); | 573 bitrate_observer_); |
| 556 } | 574 } |
| 557 last_parameters_update_ms_.emplace(now_ms); | 575 last_parameters_update_ms_.emplace(now_ms); |
| 558 | 576 |
| 559 if (EncoderPaused()) { | 577 if (EncoderPaused()) { |
| 560 TraceFrameDropStart(); | 578 TraceFrameDropStart(); |
| 561 return; | 579 return; |
| 562 } | 580 } |
| 563 TraceFrameDropEnd(); | 581 TraceFrameDropEnd(); |
| 564 | 582 |
| 583 uint32_t max_pixel_count = | |
|
perkj_webrtc
2017/01/24 09:06:16
Move all this to above the check for if(pending_en
kthelgason
2017/01/24 10:53:10
Done.
| |
| 584 MaximumFrameSizeForBitrate(encoder_start_bitrate_bps_ / 1000); | |
| 585 if (initial_rampup_ < kMaxInitialFramedrop && | |
| 586 video_frame.size() > max_pixel_count) { | |
| 587 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; | |
| 588 ScaleDown(kQuality); | |
| 589 ++initial_rampup_; | |
| 590 return; | |
| 591 } | |
| 592 initial_rampup_ = kMaxInitialFramedrop; | |
| 593 | |
| 565 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 594 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| 566 "Encode"); | 595 "Encode"); |
| 567 | 596 |
| 568 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); | 597 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); |
| 569 | 598 |
| 570 if (codec_type_ == webrtc::kVideoCodecVP8) { | 599 if (codec_type_ == webrtc::kVideoCodecVP8) { |
| 571 webrtc::CodecSpecificInfo codec_specific_info; | 600 webrtc::CodecSpecificInfo codec_specific_info; |
| 572 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 601 codec_specific_info.codecType = webrtc::kVideoCodecVP8; |
| 573 | 602 |
| 574 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = has_received_rpsi_; | 603 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = has_received_rpsi_; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 --scale_counter_[reason]; | 787 --scale_counter_[reason]; |
| 759 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 788 source_proxy_->RequestHigherResolutionThan(current_pixel_count); |
| 760 LOG(LS_INFO) << "Scaling up resolution."; | 789 LOG(LS_INFO) << "Scaling up resolution."; |
| 761 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 790 for (size_t i = 0; i < kScaleReasonSize; ++i) { |
| 762 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 791 LOG(LS_INFO) << "Scaled " << scale_counter_[i] |
| 763 << " times for reason: " << (i ? "cpu" : "quality"); | 792 << " times for reason: " << (i ? "cpu" : "quality"); |
| 764 } | 793 } |
| 765 } | 794 } |
| 766 | 795 |
| 767 } // namespace webrtc | 796 } // namespace webrtc |
| OLD | NEW |