From 30ec725b6ef252c7b7d87765d67c251db8211cf6 Mon Sep 17 00:00:00 2001 From: philipel Date: Wed, 4 May 2022 11:20:04 +0200 Subject: [PATCH] Auxiliary liboam AV1 encoder settings. Bug: none Change-Id: I03e01ffbed2ec98953650847600016e4f80fdb50 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/260861 Reviewed-by: Sergey Silkin Commit-Queue: Philip Eliasson Cr-Commit-Position: refs/heads/main@{#36758} --- .../codecs/av1/libaom_av1_encoder.cc | 83 ++++++++++++------- .../codecs/av1/libaom_av1_encoder.h | 9 ++ 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc index 61a5db174a..0e1703ae1f 100644 --- a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc +++ b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc @@ -66,7 +66,8 @@ aom_superblock_size_t GetSuperblockSize(int width, int height, int threads) { class LibaomAv1Encoder final : public VideoEncoder { public: - LibaomAv1Encoder(); + explicit LibaomAv1Encoder( + const absl::optional& aux_config); ~LibaomAv1Encoder(); int InitEncode(const VideoCodec* codec_settings, @@ -111,6 +112,7 @@ class LibaomAv1Encoder final : public VideoEncoder { bool rates_configured_; absl::optional svc_params_; VideoCodec encoder_settings_; + absl::optional aux_config_; aom_image_t* frame_for_encode_; aom_codec_ctx_t ctx_; aom_codec_enc_cfg_t cfg_; @@ -142,9 +144,11 @@ int32_t VerifyCodecSettings(const VideoCodec& codec_settings) { return WEBRTC_VIDEO_CODEC_OK; } -LibaomAv1Encoder::LibaomAv1Encoder() +LibaomAv1Encoder::LibaomAv1Encoder( + const absl::optional& aux_config) : inited_(false), rates_configured_(false), + aux_config_(aux_config), frame_for_encode_(nullptr), encoded_image_callback_(nullptr) {} @@ -325,36 +329,46 @@ bool LibaomAv1Encoder::SetEncoderControlParameters(int param_id, // Only positive speeds, range for real-time coding currently is: 6 - 8. // Lower means slower/better quality, higher means fastest/lower quality. int LibaomAv1Encoder::GetCpuSpeed(int width, int height) { - // For smaller resolutions, use lower speed setting (get some coding gain at - // the cost of increased encoding complexity). - switch (encoder_settings_.GetVideoEncoderComplexity()) { - case VideoCodecComplexity::kComplexityHigh: - if (width * height <= 320 * 180) - return 8; - else if (width * height <= 640 * 360) - return 9; - else + if (aux_config_) { + if (auto it = aux_config_->max_pixel_count_to_cpu_speed.lower_bound(width * + height); + it != aux_config_->max_pixel_count_to_cpu_speed.end()) { + return it->second; + } + + return 10; + } else { + // For smaller resolutions, use lower speed setting (get some coding gain at + // the cost of increased encoding complexity). + switch (encoder_settings_.GetVideoEncoderComplexity()) { + case VideoCodecComplexity::kComplexityHigh: + if (width * height <= 320 * 180) + return 8; + else if (width * height <= 640 * 360) + return 9; + else + return 10; + case VideoCodecComplexity::kComplexityHigher: + if (width * height <= 320 * 180) + return 7; + else if (width * height <= 640 * 360) + return 8; + else if (width * height <= 1280 * 720) + return 9; + else + return 10; + case VideoCodecComplexity::kComplexityMax: + if (width * height <= 320 * 180) + return 6; + else if (width * height <= 640 * 360) + return 7; + else if (width * height <= 1280 * 720) + return 8; + else + return 9; + default: return 10; - case VideoCodecComplexity::kComplexityHigher: - if (width * height <= 320 * 180) - return 7; - else if (width * height <= 640 * 360) - return 8; - else if (width * height <= 1280 * 720) - return 9; - else - return 10; - case VideoCodecComplexity::kComplexityMax: - if (width * height <= 320 * 180) - return 6; - else if (width * height <= 640 * 360) - return 7; - else if (width * height <= 1280 * 720) - return 8; - else - return 9; - default: - return 10; + } } } @@ -793,7 +807,12 @@ VideoEncoder::EncoderInfo LibaomAv1Encoder::GetEncoderInfo() const { } // namespace std::unique_ptr CreateLibaomAv1Encoder() { - return std::make_unique(); + return std::make_unique(absl::nullopt); +} + +std::unique_ptr CreateLibaomAv1Encoder( + const LibaomAv1EncoderAuxConfig& aux_config) { + return std::make_unique(aux_config); } } // namespace webrtc diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder.h b/modules/video_coding/codecs/av1/libaom_av1_encoder.h index e69df9e8bb..2fd1d5a754 100644 --- a/modules/video_coding/codecs/av1/libaom_av1_encoder.h +++ b/modules/video_coding/codecs/av1/libaom_av1_encoder.h @@ -10,13 +10,22 @@ #ifndef MODULES_VIDEO_CODING_CODECS_AV1_LIBAOM_AV1_ENCODER_H_ #define MODULES_VIDEO_CODING_CODECS_AV1_LIBAOM_AV1_ENCODER_H_ +#include #include #include "absl/strings/string_view.h" #include "api/video_codecs/video_encoder.h" namespace webrtc { +struct LibaomAv1EncoderAuxConfig { + // A map of max pixel count --> cpu speed. + std::map max_pixel_count_to_cpu_speed; +}; + std::unique_ptr CreateLibaomAv1Encoder(); +std::unique_ptr CreateLibaomAv1Encoder( + const LibaomAv1EncoderAuxConfig& aux_config); + } // namespace webrtc #endif // MODULES_VIDEO_CODING_CODECS_AV1_LIBAOM_AV1_ENCODER_H_