Provide a default implementation of NV12BufferInterface::CropAndScale.
This avoids falling back on the VideoFrameBuffer::CropAndScale default
implementation which performs ToI420. This has two major benefits:
1. We save CPU by not converting to I420 for NV12 frames.
2. We make is possible for simulcast encoders to use Scale() and be
able to trust that the scaled simulcast layers have the same pixel
format as the top layer, which is required by libvpx.
In order to invoke NV12Buffer::CropAndScaleFrom() without introducing a
circular dependency, nv12_buffer.[h/cc] is moved to the "video_frame"
build target.
Bug: webrtc:12595, webrtc:12469
Change-Id: I81aac5c6b3e81c49f32a7be6dc2640e6b40f7692
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212643
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@google.com>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33521}
diff --git a/api/video/BUILD.gn b/api/video/BUILD.gn
index b697b86..1a83248 100644
--- a/api/video/BUILD.gn
+++ b/api/video/BUILD.gn
@@ -43,6 +43,8 @@
sources = [
"i420_buffer.cc",
"i420_buffer.h",
+ "nv12_buffer.cc",
+ "nv12_buffer.h",
"video_codec_type.h",
"video_frame.cc",
"video_frame.h",
@@ -90,23 +92,6 @@
]
}
-rtc_library("video_frame_nv12") {
- visibility = [ "*" ]
- sources = [
- "nv12_buffer.cc",
- "nv12_buffer.h",
- ]
- deps = [
- ":video_frame",
- "..:scoped_refptr",
- "../../rtc_base",
- "../../rtc_base:checks",
- "../../rtc_base/memory:aligned_malloc",
- "../../rtc_base/system:rtc_export",
- "//third_party/libyuv",
- ]
-}
-
rtc_source_set("recordable_encoded_frame") {
visibility = [ "*" ]
sources = [ "recordable_encoded_frame.h" ]
diff --git a/api/video/test/BUILD.gn b/api/video/test/BUILD.gn
index 72f5049..1573e78 100644
--- a/api/video/test/BUILD.gn
+++ b/api/video/test/BUILD.gn
@@ -20,7 +20,6 @@
"..:video_adaptation",
"..:video_bitrate_allocation",
"..:video_frame",
- "..:video_frame_nv12",
"..:video_rtp_headers",
"../../../test:frame_utils",
"../../../test:test_support",
diff --git a/api/video/video_frame_buffer.cc b/api/video/video_frame_buffer.cc
index 64f3394..7085010 100644
--- a/api/video/video_frame_buffer.cc
+++ b/api/video/video_frame_buffer.cc
@@ -11,6 +11,7 @@
#include "api/video/video_frame_buffer.h"
#include "api/video/i420_buffer.h"
+#include "api/video/nv12_buffer.h"
#include "rtc_base/checks.h"
namespace webrtc {
@@ -139,4 +140,18 @@
int NV12BufferInterface::ChromaHeight() const {
return (height() + 1) / 2;
}
+
+rtc::scoped_refptr<VideoFrameBuffer> NV12BufferInterface::CropAndScale(
+ int offset_x,
+ int offset_y,
+ int crop_width,
+ int crop_height,
+ int scaled_width,
+ int scaled_height) {
+ rtc::scoped_refptr<NV12Buffer> result =
+ NV12Buffer::Create(scaled_width, scaled_height);
+ result->CropAndScaleFrom(*this, offset_x, offset_y, crop_width, crop_height);
+ return result;
+}
+
} // namespace webrtc
diff --git a/api/video/video_frame_buffer.h b/api/video/video_frame_buffer.h
index 67b8797..62adc20 100644
--- a/api/video/video_frame_buffer.h
+++ b/api/video/video_frame_buffer.h
@@ -242,6 +242,13 @@
int ChromaWidth() const final;
int ChromaHeight() const final;
+ rtc::scoped_refptr<VideoFrameBuffer> CropAndScale(int offset_x,
+ int offset_y,
+ int crop_width,
+ int crop_height,
+ int scaled_width,
+ int scaled_height) override;
+
protected:
~NV12BufferInterface() override {}
};
diff --git a/common_video/BUILD.gn b/common_video/BUILD.gn
index 57c4158..2503f7f 100644
--- a/common_video/BUILD.gn
+++ b/common_video/BUILD.gn
@@ -50,7 +50,6 @@
"../api/video:video_bitrate_allocation",
"../api/video:video_bitrate_allocator",
"../api/video:video_frame",
- "../api/video:video_frame_nv12",
"../api/video:video_rtp_headers",
"../api/video_codecs:bitstream_parser_api",
"../media:rtc_h264_profile_id",
@@ -105,7 +104,6 @@
"../api/units:time_delta",
"../api/video:video_frame",
"../api/video:video_frame_i010",
- "../api/video:video_frame_nv12",
"../api/video:video_rtp_headers",
"../media:rtc_h264_profile_id",
"../rtc_base",
diff --git a/test/BUILD.gn b/test/BUILD.gn
index ed4eebe..db508ca 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -56,7 +56,6 @@
"../api/video:encoded_image",
"../api/video:video_frame",
"../api/video:video_frame_i010",
- "../api/video:video_frame_nv12",
"../api/video:video_rtp_headers",
"../api/video_codecs:video_codecs_api",
"../common_video",
diff --git a/video/BUILD.gn b/video/BUILD.gn
index e0399a1..acf1ba2 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -663,7 +663,6 @@
"../api/video:video_adaptation",
"../api/video:video_bitrate_allocation",
"../api/video:video_frame",
- "../api/video:video_frame_nv12",
"../api/video:video_frame_type",
"../api/video:video_rtp_headers",
"../api/video_codecs:video_codecs_api",