Do not crop to render resolution by default
Disable cropping to render resolution by default. This functionality was added in https://webrtc-review.googlesource.com/c/src/+/381340 and https://webrtc-review.googlesource.com/c/src/+/382241 and was enabled by default to make things work with HW encoders which use render resolution to signal cropping. After discussions with AV1 folks the consensus is that encoders should not use render resolution to signal crop. Currently there is no way to signal crop in AV1 bitstream. There is a proposal for adding this info to AV1 metadata: https://github.com/AOMediaCodec/av1-spec/pull/346.
Bug: webrtc:405341160, b:402019802, b:405299912
Change-Id: I9cff9f2f8e7c9b8933fd0fbb100ce37221eaf084
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382640
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#44228}
diff --git a/modules/video_coding/codecs/av1/BUILD.gn b/modules/video_coding/codecs/av1/BUILD.gn
index 7ca705f..1a4f6c0 100644
--- a/modules/video_coding/codecs/av1/BUILD.gn
+++ b/modules/video_coding/codecs/av1/BUILD.gn
@@ -34,6 +34,7 @@
deps = [
"../..:video_codec_interface",
+ "../../../../api:refcountedbase",
"../../../../api:scoped_refptr",
"../../../../api/environment",
"../../../../api/video:encoded_image",
@@ -97,7 +98,6 @@
"../../../../api/video_codecs:video_codecs_api",
"../../../../test:explicit_key_value_config",
"../../../../test:test_support",
- "//third_party/abseil-cpp/absl/functional:any_invocable",
]
if (enable_libaom) {
diff --git a/modules/video_coding/codecs/av1/dav1d_decoder.cc b/modules/video_coding/codecs/av1/dav1d_decoder.cc
index 097c270..e8a7354 100644
--- a/modules/video_coding/codecs/av1/dav1d_decoder.cc
+++ b/modules/video_coding/codecs/av1/dav1d_decoder.cc
@@ -11,16 +11,24 @@
#include "modules/video_coding/codecs/av1/dav1d_decoder.h"
#include <algorithm>
+#include <cstdint>
+#include <memory>
+#include <optional>
+#include "api/environment/environment.h"
+#include "api/ref_counted_base.h"
#include "api/scoped_refptr.h"
#include "api/video/encoded_image.h"
+#include "api/video/video_frame.h"
#include "api/video/video_frame_buffer.h"
+#include "api/video_codecs/video_decoder.h"
#include "common_video/include/video_frame_buffer.h"
#include "modules/video_coding/include/video_error_codes.h"
#include "rtc_base/logging.h"
+#include "third_party/dav1d/libdav1d/include/dav1d/data.h"
#include "third_party/dav1d/libdav1d/include/dav1d/dav1d.h"
-#include "third_party/libyuv/include/libyuv/convert.h"
-#include "third_party/libyuv/include/libyuv/planar_functions.h"
+#include "third_party/dav1d/libdav1d/include/dav1d/headers.h"
+#include "third_party/dav1d/libdav1d/include/dav1d/picture.h"
namespace webrtc {
namespace {
@@ -47,7 +55,7 @@
Dav1dContext* context_ = nullptr;
DecodedImageCallback* decode_complete_callback_ = nullptr;
- const bool crop_to_render_resolution_ = true;
+ const bool crop_to_render_resolution_ = false;
};
class ScopedDav1dData {
@@ -80,7 +88,7 @@
Dav1dDecoder::Dav1dDecoder() = default;
Dav1dDecoder::Dav1dDecoder(const Environment& env)
- : crop_to_render_resolution_(!env.field_trials().IsDisabled(
+ : crop_to_render_resolution_(env.field_trials().IsEnabled(
"WebRTC-Dav1dDecoder-CropToRenderResolution")) {}
Dav1dDecoder::~Dav1dDecoder() {
diff --git a/modules/video_coding/codecs/av1/dav1d_decoder_unittest.cc b/modules/video_coding/codecs/av1/dav1d_decoder_unittest.cc
index 013536e..5c2d33a 100644
--- a/modules/video_coding/codecs/av1/dav1d_decoder_unittest.cc
+++ b/modules/video_coding/codecs/av1/dav1d_decoder_unittest.cc
@@ -10,12 +10,11 @@
#include "modules/video_coding/codecs/av1/dav1d_decoder.h"
+#include <cstdint>
#include <memory>
#include <optional>
-#include <string>
#include <utility>
-#include "absl/functional/any_invocable.h"
#include "api/array_view.h"
#include "api/environment/environment.h"
#include "api/environment/environment_factory.h"
@@ -88,15 +87,25 @@
std::optional<VideoFrame> decoded_frame_;
};
-TEST(Dav1dDecoderTest, CropsToRenderResolutionByDefault) {
+TEST(Dav1dDecoderTest, KeepsDecodedResolutionByDefault) {
TestAv1Decoder decoder(CreateEnvironment());
decoder.Decode(
CreateEncodedImage(kAv1FrameWith36x20EncodededAnd32x16RenderResolution));
+ EXPECT_EQ(decoder.decoded_frame().width(), 36);
+ EXPECT_EQ(decoder.decoded_frame().height(), 20);
+}
+
+TEST(Dav1dDecoderTest, CropsToRenderResolutionWhenCropIsEnabled) {
+ TestAv1Decoder decoder(
+ CreateEnvironment(std::make_unique<ExplicitKeyValueConfig>(
+ "WebRTC-Dav1dDecoder-CropToRenderResolution/Enabled/")));
+ decoder.Decode(
+ CreateEncodedImage(kAv1FrameWith36x20EncodededAnd32x16RenderResolution));
EXPECT_EQ(decoder.decoded_frame().width(), 32);
EXPECT_EQ(decoder.decoded_frame().height(), 16);
}
-TEST(Dav1dDecoderTest, KeepsDecodedResolutionWhenCropIsDisabled) {
+TEST(Dav1dDecoderTest, DoesNotCropToRenderResolutionWhenCropIsDisabled) {
TestAv1Decoder decoder(
CreateEnvironment(std::make_unique<ExplicitKeyValueConfig>(
"WebRTC-Dav1dDecoder-CropToRenderResolution/Disabled/")));