 Chromium Code Reviews
 Chromium Code Reviews Issue 2630333002:
  Drop frames until specified bitrate is achieved.  (Closed)
    
  
    Issue 2630333002:
  Drop frames until specified bitrate is achieved.  (Closed) 
  | 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/23 08:54:22
Isnt this comment a bit confusing? This will happe
 
kthelgason
2017/01/23 12:39:06
I'm not sure I understand what you mean. This shou
 
perkj_webrtc
2017/01/24 09:06:15
but an encoder is reconfigured every time the reso
 | |
| 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) { | |
| 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 expected_pixel_count = | |
| 
perkj_webrtc
2017/01/23 08:54:22
min_pixel_count?
 
kthelgason
2017/01/23 12:39:06
Shouldn't it rather be max_pixel_count? It's the m
 | |
| 584 MaximumFrameSizeForBitrate(encoder_start_bitrate_bps_ / 1000); | |
| 585 if (initial_rampup_ < kMaxInitialFramedrop && | |
| 
perkj_webrtc
2017/01/23 08:54:22
please name more appropriate. Maybe something like
 
perkj_webrtc
2017/01/23 08:54:22
This will drop frames at anytime time  kMaxInitial
 
perkj_webrtc
2017/01/23 08:54:22
Should kMaxInitilFrameDrop also change change name
 
kthelgason
2017/01/23 12:39:06
I understand what you mean. That should not be how
 | |
| 586 video_frame.size() > expected_pixel_count) { | |
| 587 LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; | |
| 588 ScaleDown(kQuality); | |
| 589 ++initial_rampup_; | |
| 590 return; | |
| 591 } | |
| 592 | |
| 565 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 593 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 
| 566 "Encode"); | 594 "Encode"); | 
| 567 | 595 | 
| 568 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); | 596 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); | 
| 569 | 597 | 
| 570 if (codec_type_ == webrtc::kVideoCodecVP8) { | 598 if (codec_type_ == webrtc::kVideoCodecVP8) { | 
| 571 webrtc::CodecSpecificInfo codec_specific_info; | 599 webrtc::CodecSpecificInfo codec_specific_info; | 
| 572 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 600 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 
| 573 | 601 | 
| 574 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = has_received_rpsi_; | 602 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = has_received_rpsi_; | 
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 RTC_DCHECK(sink_) << "sink_ must be set before the encoder is active."; | 707 RTC_DCHECK(sink_) << "sink_ must be set before the encoder is active."; | 
| 680 | 708 | 
| 681 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps | 709 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps | 
| 682 << " packet loss " << static_cast<int>(fraction_lost) | 710 << " packet loss " << static_cast<int>(fraction_lost) | 
| 683 << " rtt " << round_trip_time_ms; | 711 << " rtt " << round_trip_time_ms; | 
| 684 | 712 | 
| 685 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, | 713 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, | 
| 686 round_trip_time_ms, rate_allocator_.get(), | 714 round_trip_time_ms, rate_allocator_.get(), | 
| 687 bitrate_observer_); | 715 bitrate_observer_); | 
| 688 | 716 | 
| 689 encoder_start_bitrate_bps_ = | 717 encoder_start_bitrate_bps_ = | 
| 
perkj_webrtc
2017/01/23 08:54:22
this is where encoder_start_bitrate_bps_ is set. i
 | |
| 690 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_; | 718 bitrate_bps != 0 ? bitrate_bps : encoder_start_bitrate_bps_; | 
| 691 bool video_is_suspended = bitrate_bps == 0; | 719 bool video_is_suspended = bitrate_bps == 0; | 
| 692 bool video_suspension_changed = video_is_suspended != EncoderPaused(); | 720 bool video_suspension_changed = video_is_suspended != EncoderPaused(); | 
| 693 last_observed_bitrate_bps_ = bitrate_bps; | 721 last_observed_bitrate_bps_ = bitrate_bps; | 
| 694 | 722 | 
| 695 if (stats_proxy_ && video_suspension_changed) { | 723 if (stats_proxy_ && video_suspension_changed) { | 
| 696 LOG(LS_INFO) << "Video suspend state changed to: " | 724 LOG(LS_INFO) << "Video suspend state changed to: " | 
| 697 << (video_is_suspended ? "suspended" : "not suspended"); | 725 << (video_is_suspended ? "suspended" : "not suspended"); | 
| 698 stats_proxy_->OnSuspendChange(video_is_suspended); | 726 stats_proxy_->OnSuspendChange(video_is_suspended); | 
| 699 } | 727 } | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 --scale_counter_[reason]; | 786 --scale_counter_[reason]; | 
| 759 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 787 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | 
| 760 LOG(LS_INFO) << "Scaling up resolution."; | 788 LOG(LS_INFO) << "Scaling up resolution."; | 
| 761 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 789 for (size_t i = 0; i < kScaleReasonSize; ++i) { | 
| 762 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 790 LOG(LS_INFO) << "Scaled " << scale_counter_[i] | 
| 763 << " times for reason: " << (i ? "cpu" : "quality"); | 791 << " times for reason: " << (i ? "cpu" : "quality"); | 
| 764 } | 792 } | 
| 765 } | 793 } | 
| 766 | 794 | 
| 767 } // namespace webrtc | 795 } // namespace webrtc | 
| OLD | NEW |