Chromium Code Reviews| Index: webrtc/video/vie_encoder.cc |
| diff --git a/webrtc/video/vie_encoder.cc b/webrtc/video/vie_encoder.cc |
| index eaf693af169392883496a2f7fff370029248b433..4d3ec09f49d6d3dba6593db164d6b1ab951786c5 100644 |
| --- a/webrtc/video/vie_encoder.cc |
| +++ b/webrtc/video/vie_encoder.cc |
| @@ -42,6 +42,10 @@ const int kMinPixelsPerFrame = 320 * 180; |
| const int kMinPixelsPerFrame = 120 * 90; |
| #endif |
| +// 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
|
| +// to try and achieve desired bitrate. |
| +const int kMaxInitialFramedrop = 4; |
| + |
| // TODO(pbos): Lower these thresholds (to closer to 100%) when we handle |
| // pipelining encoders better (multiple input frames before something comes |
| // out). This should effectively turn off CPU adaptations for systems that |
| @@ -55,6 +59,17 @@ CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) { |
| return options; |
| } |
| +uint32_t MaximumFrameSizeForBitrate(uint32_t kbps) { |
| + if (kbps > 0) { |
| + if (kbps < 300 /* qvga */) { |
| + return 320 * 240; |
| + } else if (kbps < 500 /* vga */) { |
| + return 640 * 480; |
| + } |
| + } |
| + return std::numeric_limits<uint32_t>::max(); |
| +} |
| + |
| } // namespace |
| class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask { |
| @@ -244,6 +259,7 @@ ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
| EncodedFrameObserver* encoder_timing) |
| : shutdown_event_(true /* manual_reset */, false), |
| number_of_cores_(number_of_cores), |
| + initial_rampup_(kMaxInitialFramedrop), |
| source_proxy_(new VideoSourceProxy(this)), |
| sink_(nullptr), |
| settings_(settings), |
| @@ -439,6 +455,8 @@ void ViEEncoder::ReconfigureEncoder() { |
| const auto scaling_settings = settings_.encoder->GetScalingSettings(); |
| if (scaling_enabled_ && scaling_settings.enabled) { |
| + // Drop frames and scale down until desired quality is achieved. |
| + initial_rampup_ = 0; |
| if (scaling_settings.thresholds) { |
| quality_scaler_.reset( |
| new QualityScaler(this, *(scaling_settings.thresholds))); |
| @@ -562,6 +580,16 @@ void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame, |
| } |
| TraceFrameDropEnd(); |
| + 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
|
| + MaximumFrameSizeForBitrate(encoder_start_bitrate_bps_ / 1000); |
| + 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
|
| + video_frame.size() > expected_pixel_count) { |
| + LOG(LS_INFO) << "Dropping frame. Too large for target bitrate."; |
| + ScaleDown(kQuality); |
| + ++initial_rampup_; |
| + return; |
| + } |
| + |
| TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| "Encode"); |