| Index: webrtc/video/vie_encoder.cc
|
| diff --git a/webrtc/video/vie_encoder.cc b/webrtc/video/vie_encoder.cc
|
| index f78633d532f438f809dce7453fb57accfeff0dd7..c407dcba6e9867ff5e761f332d2c72e15fc47519 100644
|
| --- a/webrtc/video/vie_encoder.cc
|
| +++ b/webrtc/video/vie_encoder.cc
|
| @@ -55,6 +55,17 @@ CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time) {
|
| return options;
|
| }
|
|
|
| +int MaximumFrameSizeForBitrate(int kbps) {
|
| + if (kbps > 0) {
|
| + if (kbps < 300 /* qvga */) {
|
| + return 320 * 240;
|
| + } else if (kbps < 500 /* vga */) {
|
| + return 640 * 480;
|
| + }
|
| + }
|
| + return std::numeric_limits<int>::max();
|
| +}
|
| +
|
| } // namespace
|
|
|
| class ViEEncoder::ConfigureEncoderTask : public rtc::QueuedTask {
|
| @@ -441,6 +452,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_ = true;
|
| if (scaling_settings.thresholds) {
|
| quality_scaler_.reset(
|
| new QualityScaler(this, *(scaling_settings.thresholds)));
|
| @@ -560,6 +573,15 @@ void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame,
|
| last_frame_height_ = video_frame.height();
|
| last_frame_width_ = video_frame.width();
|
|
|
| + int expected_pixel_count =
|
| + MaximumFrameSizeForBitrate(encoder_start_bitrate_bps_ / 1000);
|
| + if (initial_rampup_ && video_frame.size() > expected_pixel_count) {
|
| + LOG(LS_INFO) << "Dropping frame. Too large for target bitrate.";
|
| + ScaleDown(kQuality);
|
| + return;
|
| + }
|
| + initial_rampup_ = false;
|
| +
|
| TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(),
|
| "Encode");
|
|
|
| @@ -725,7 +747,7 @@ void ViEEncoder::ScaleDown(ScaleReason reason) {
|
| LOG(LS_INFO) << "Scaling down resolution.";
|
| for (size_t i = 0; i < kScaleReasonSize; ++i) {
|
| LOG(LS_INFO) << "Scaled " << scale_counter_[i]
|
| - << " times for reason: " << (i ? "quality" : "cpu");
|
| + << " times for reason: " << (i ? "cpu" : "quality");
|
| }
|
| }
|
|
|
|
|