From 04a6529c86ad7cc5337dc4c69ab2efcb92c4207a Mon Sep 17 00:00:00 2001 From: Jerome Jiang Date: Thu, 18 Feb 2021 15:21:39 -0800 Subject: [PATCH] AV1: set superblock to 64x64 for 720p 4 threads. Multithreading is more effective. Change-Id: Ic850de4ee6affe3c0f623deb0318f991675c4351 Bug: None Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/208300 Reviewed-by: Marco Paniconi Commit-Queue: Jerome Jiang Cr-Commit-Position: refs/heads/master@{#33306} --- .../codecs/av1/libaom_av1_encoder.cc | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc index 06b46989c6..113c2568f6 100644 --- a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc +++ b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc @@ -41,9 +41,9 @@ namespace { // Encoder configuration parameters constexpr int kQpMin = 10; -constexpr int kUsageProfile = 1; // 0 = good quality; 1 = real-time. -constexpr int kMinQindex = 58; // Min qindex threshold for QP scaling. -constexpr int kMaxQindex = 180; // Max qindex threshold for QP scaling. +constexpr int kUsageProfile = 1; // 0 = good quality; 1 = real-time. +constexpr int kMinQindex = 58; // Min qindex threshold for QP scaling. +constexpr int kMaxQindex = 180; // Max qindex threshold for QP scaling. constexpr int kBitDepth = 8; constexpr int kLagInFrames = 0; // No look ahead. constexpr int kRtpTicksPerSecond = 90000; @@ -64,6 +64,14 @@ int GetCpuSpeed(int width, int height, int number_of_cores) { return 7; } +aom_superblock_size_t GetSuperblockSize(int width, int height, int threads) { + int resolution = width * height; + if (threads >= 4 && resolution >= 960 * 540 && resolution < 1920 * 1080) + return AOM_SUPERBLOCK_SIZE_64X64; + else + return AOM_SUPERBLOCK_SIZE_DYNAMIC; +} + class LibaomAv1Encoder final : public VideoEncoder { public: LibaomAv1Encoder(); @@ -353,6 +361,15 @@ int LibaomAv1Encoder::InitEncode(const VideoCodec* codec_settings, return WEBRTC_VIDEO_CODEC_ERROR; } + ret = + aom_codec_control(&ctx_, AV1E_SET_SUPERBLOCK_SIZE, + GetSuperblockSize(cfg_.g_w, cfg_.g_h, cfg_.g_threads)); + if (ret != AOM_CODEC_OK) { + RTC_LOG(LS_WARNING) << "LibaomAv1Encoder::EncodeInit returned " << ret + << " on control AV1E_SET_SUPERBLOCK_SIZE."; + return WEBRTC_VIDEO_CODEC_ERROR; + } + return WEBRTC_VIDEO_CODEC_OK; }