Reduce libvpx VP9 complexity setting on <= 2 core machines.

This CL sets speed 9 for all resolutions when two or less cores are
available, as a heuristic for a "slow" machine.
This gives a large speed bost at a relatively small quality loss.

A field-trial kill-switch is available to override this behavior.

Bug: webrtc:13888
Change-Id: I24278a45de000ad7984d0525c47d9eb6b9ab6b60
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/257421
Reviewed-by: Emil Lundmark <lndmrk@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36466}
This commit is contained in:
Erik Språng
2022-04-06 16:44:30 +02:00
committed by WebRTC LUCI CQ
parent 8d4e9fba21
commit e4589cb55e
8 changed files with 147 additions and 19 deletions

View File

@ -1874,14 +1874,30 @@ LibvpxVp9Encoder::ParseQualityScalerConfig(const FieldTrialsView& trials) {
}
void LibvpxVp9Encoder::UpdatePerformanceFlags() {
flat_map<int, PerformanceFlags::ParameterSet> params_by_resolution;
if (codec_.GetVideoEncoderComplexity() ==
VideoCodecComplexity::kComplexityLow) {
// For low tier devices, always use speed 9. Only disable upper
// layer deblocking below QCIF.
params_by_resolution[0] = {.base_layer_speed = 9,
.high_layer_speed = 9,
.deblock_mode = 1,
.allow_denoising = true};
params_by_resolution[352 * 288] = {.base_layer_speed = 9,
.high_layer_speed = 9,
.deblock_mode = 0,
.allow_denoising = true};
} else {
params_by_resolution = performance_flags_.settings_by_resolution;
}
const auto find_speed = [&](int min_pixel_count) {
RTC_DCHECK(!performance_flags_.settings_by_resolution.empty());
auto it =
performance_flags_.settings_by_resolution.upper_bound(min_pixel_count);
RTC_DCHECK(!params_by_resolution.empty());
auto it = params_by_resolution.upper_bound(min_pixel_count);
return std::prev(it)->second;
};
performance_flags_by_spatial_index_.clear();
if (is_svc_) {
for (int si = 0; si < num_spatial_layers_; ++si) {
performance_flags_by_spatial_index_.push_back(find_speed(
@ -1952,24 +1968,38 @@ LibvpxVp9Encoder::GetDefaultPerformanceFlags() {
flags.use_per_layer_speed = true;
#if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64) || defined(ANDROID)
// Speed 8 on all layers for all resolutions.
flags.settings_by_resolution[0] = {8, 8, 0, true};
flags.settings_by_resolution[0] = {.base_layer_speed = 8,
.high_layer_speed = 8,
.deblock_mode = 0,
.allow_denoising = true};
#else
// For smaller resolutions, use lower speed setting for the temporal base
// layer (get some coding gain at the cost of increased encoding complexity).
// Set encoder Speed 5 for TL0, encoder Speed 8 for upper temporal layers, and
// disable deblocking for upper-most temporal layers.
flags.settings_by_resolution[0] = {5, 8, 1, true};
flags.settings_by_resolution[0] = {.base_layer_speed = 5,
.high_layer_speed = 8,
.deblock_mode = 1,
.allow_denoising = true};
// Use speed 7 for QCIF and above.
// Set encoder Speed 7 for TL0, encoder Speed 8 for upper temporal layers, and
// enable deblocking for all temporal layers.
flags.settings_by_resolution[352 * 288] = {7, 8, 0, true};
flags.settings_by_resolution[352 * 288] = {.base_layer_speed = 7,
.high_layer_speed = 8,
.deblock_mode = 0,
.allow_denoising = true};
// For very high resolution (1080p and up), turn the speed all the way up
// since this is very CPU intensive. Also disable denoising to save CPU, at
// these resolutions denoising appear less effective and hopefully you also
// have a less noisy video source at this point.
flags.settings_by_resolution[1920 * 1080] = {9, 9, 0, false};
flags.settings_by_resolution[1920 * 1080] = {.base_layer_speed = 9,
.high_layer_speed = 9,
.deblock_mode = 0,
.allow_denoising = false};
#endif
return flags;
}

View File

@ -14,7 +14,6 @@
#ifdef RTC_ENABLE_VP9
#include <map>
#include <memory>
#include <vector>
@ -28,6 +27,7 @@
#include "modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h"
#include "modules/video_coding/svc/scalable_video_controller.h"
#include "modules/video_coding/utility/framerate_controller_deprecated.h"
#include "rtc_base/containers/flat_map.h"
#include "rtc_base/experiments/encoder_info_settings.h"
#include "vpx/vp8cx.h"
@ -172,7 +172,7 @@ class LibvpxVp9Encoder : public VP9Encoder {
size_t spatial_layer_id = 0;
size_t temporal_layer_id = 0;
};
std::map<size_t, RefFrameBuffer> ref_buf_;
flat_map<size_t, RefFrameBuffer> ref_buf_;
std::vector<ScalableVideoController::LayerFrameConfig> layer_frames_;
// Variable frame-rate related fields and methods.
@ -225,7 +225,7 @@ class LibvpxVp9Encoder : public VP9Encoder {
// Map from min pixel count to settings for that resolution and above.
// E.g. if you want some settings A if below wvga (640x360) and some other
// setting B at wvga and above, you'd use map {{0, A}, {230400, B}}.
std::map<int, ParameterSet> settings_by_resolution;
flat_map<int, ParameterSet> settings_by_resolution;
};
// Performance flags, ordered by `min_pixel_count`.
const PerformanceFlags performance_flags_;