Skip to content

Commit

Permalink
Provide a default implementation of NV12BufferInterface::CropAndScale.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Evan Shrubsole <[email protected]>
Commit-Queue: Henrik Boström <[email protected]>
Cr-Commit-Position: refs/heads/master@{#33521}
  • Loading branch information
henbos authored and Commit Bot committed Mar 22, 2021
1 parent 50d79ba commit f412976
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
19 changes: 2 additions & 17 deletions api/video/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ rtc_library("video_frame") {
sources = [
"i420_buffer.cc",
"i420_buffer.h",
"nv12_buffer.cc",
"nv12_buffer.h",
"video_codec_type.h",
"video_frame.cc",
"video_frame.h",
Expand Down Expand Up @@ -90,23 +92,6 @@ rtc_library("video_frame_i010") {
]
}

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" ]
Expand Down
1 change: 0 additions & 1 deletion api/video/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ rtc_library("rtc_api_video_unittests") {
"..:video_adaptation",
"..:video_bitrate_allocation",
"..:video_frame",
"..:video_frame_nv12",
"..:video_rtp_headers",
"../../../test:frame_utils",
"../../../test:test_support",
Expand Down
15 changes: 15 additions & 0 deletions api/video/video_frame_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -139,4 +140,18 @@ int NV12BufferInterface::ChromaWidth() const {
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
7 changes: 7 additions & 0 deletions api/video/video_frame_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ class RTC_EXPORT NV12BufferInterface : public BiplanarYuv8Buffer {
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 {}
};
Expand Down
2 changes: 0 additions & 2 deletions common_video/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ rtc_library("common_video") {
"../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",
Expand Down Expand Up @@ -105,7 +104,6 @@ if (rtc_include_tests && !build_with_chromium) {
"../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",
Expand Down
1 change: 0 additions & 1 deletion test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ rtc_library("frame_generator_impl") {
"../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",
Expand Down
1 change: 0 additions & 1 deletion video/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ if (rtc_include_tests) {
"../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",
Expand Down

0 comments on commit f412976

Please sign in to comment.