Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 441dbf9

Browse files
Ilya NikolaevskiyCommit Bot
authored andcommitted
Revert "Add scaling interface to VideoFrameBuffer"
This reverts commit c79f1d8. Reason for revert: Breaks downstream project. Original change's description: > Add scaling interface to VideoFrameBuffer > > This can be overriden for kNative frame types to perform scaling efficiently. > > Default implementations for existing buffer types require actual > buffer implementation, thus this CL also merges "video_frame" > with "video_frame_I420" build targets. > > Bug: webrtc:11976, chromium:1132299 > Change-Id: I3bf5f6bf179db5e7ab165b1c2301980043a08765 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186303 > Commit-Queue: Ilya Nikolaevskiy <[email protected]> > Reviewed-by: Mirko Bonadei <[email protected]> > Reviewed-by: Stefan Holmer <[email protected]> > Reviewed-by: Sami Kalliomäki <[email protected]> > Reviewed-by: Niels Moller <[email protected]> > Reviewed-by: Evan Shrubsole <[email protected]> > Cr-Commit-Position: refs/heads/master@{#32352} [email protected],[email protected],[email protected],[email protected],[email protected],[email protected] Change-Id: I86ac697bf963ef7e2c4f2ed34c3a7bf04f4f1ce1 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:11976 Bug: chromium:1132299 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/187344 Reviewed-by: Ilya Nikolaevskiy <[email protected]> Commit-Queue: Ilya Nikolaevskiy <[email protected]> Cr-Commit-Position: refs/heads/master@{#32354}
1 parent b556b08 commit 441dbf9

File tree

26 files changed

+116
-162
lines changed

26 files changed

+116
-162
lines changed

api/video/BUILD.gn

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ rtc_library("video_rtp_headers") {
4242
rtc_library("video_frame") {
4343
visibility = [ "*" ]
4444
sources = [
45-
"i420_buffer.cc",
46-
"i420_buffer.h",
4745
"video_codec_type.h",
4846
"video_frame.cc",
4947
"video_frame.h",
@@ -61,9 +59,7 @@ rtc_library("video_frame") {
6159
"..:scoped_refptr",
6260
"../../rtc_base:checks",
6361
"../../rtc_base:rtc_base_approved",
64-
"../../rtc_base/memory:aligned_malloc",
6562
"../../rtc_base/system:rtc_export",
66-
"//third_party/libyuv",
6763
]
6864
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
6965
}
@@ -74,18 +70,31 @@ if (is_android) {
7470
}
7571
}
7672

77-
# Deprecated empty target. Use "video_frame" instead.
78-
rtc_source_set("video_frame_i420") {
73+
rtc_source_set("recordable_encoded_frame") {
7974
visibility = [ "*" ]
80-
sources = []
81-
deps = [ ":video_frame" ]
75+
sources = [ "recordable_encoded_frame.h" ]
76+
77+
deps = [
78+
":encoded_image",
79+
":video_frame",
80+
":video_rtp_headers",
81+
"..:array_view",
82+
"..:scoped_refptr",
83+
"../../rtc_base:refcount",
84+
"../units:timestamp",
85+
]
8286
}
8387

84-
rtc_library("video_frame_i010") {
88+
rtc_source_set("video_frame_type") {
89+
visibility = [ "*" ]
90+
sources = [ "video_frame_type.h" ]
91+
}
92+
93+
rtc_library("video_frame_i420") {
8594
visibility = [ "*" ]
8695
sources = [
87-
"i010_buffer.cc",
88-
"i010_buffer.h",
96+
"i420_buffer.cc",
97+
"i420_buffer.h",
8998
]
9099
deps = [
91100
":video_frame",
@@ -94,47 +103,47 @@ rtc_library("video_frame_i010") {
94103
"../../rtc_base",
95104
"../../rtc_base:checks",
96105
"../../rtc_base/memory:aligned_malloc",
106+
"../../rtc_base/system:rtc_export",
97107
"//third_party/libyuv",
98108
]
99109
}
100110

101-
rtc_library("video_frame_nv12") {
111+
rtc_library("video_frame_i010") {
102112
visibility = [ "*" ]
103113
sources = [
104-
"nv12_buffer.cc",
105-
"nv12_buffer.h",
114+
"i010_buffer.cc",
115+
"i010_buffer.h",
106116
]
107117
deps = [
108118
":video_frame",
119+
":video_frame_i420",
120+
":video_rtp_headers",
109121
"..:scoped_refptr",
110122
"../../rtc_base",
111123
"../../rtc_base:checks",
112124
"../../rtc_base/memory:aligned_malloc",
113-
"../../rtc_base/system:rtc_export",
114125
"//third_party/libyuv",
115126
]
116127
}
117128

118-
rtc_source_set("recordable_encoded_frame") {
129+
rtc_library("video_frame_nv12") {
119130
visibility = [ "*" ]
120-
sources = [ "recordable_encoded_frame.h" ]
121-
131+
sources = [
132+
"nv12_buffer.cc",
133+
"nv12_buffer.h",
134+
]
122135
deps = [
123-
":encoded_image",
124136
":video_frame",
125-
":video_rtp_headers",
126-
"..:array_view",
137+
":video_frame_i420",
127138
"..:scoped_refptr",
128-
"../../rtc_base:refcount",
129-
"../units:timestamp",
139+
"../../rtc_base",
140+
"../../rtc_base:checks",
141+
"../../rtc_base/memory:aligned_malloc",
142+
"../../rtc_base/system:rtc_export",
143+
"//third_party/libyuv",
130144
]
131145
}
132146

133-
rtc_source_set("video_frame_type") {
134-
visibility = [ "*" ]
135-
sources = [ "video_frame_type.h" ]
136-
}
137-
138147
rtc_library("encoded_image") {
139148
visibility = [ "*" ]
140149
sources = [

api/video/nv12_buffer.cc

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "rtc_base/checks.h"
1515
#include "rtc_base/ref_counted_object.h"
1616
#include "third_party/libyuv/include/libyuv/convert.h"
17-
#include "third_party/libyuv/include/libyuv/scale.h"
1817

1918
namespace webrtc {
2019

@@ -123,35 +122,4 @@ void NV12Buffer::InitializeData() {
123122
memset(data_.get(), 0, NV12DataSize(height_, stride_y_, stride_uv_));
124123
}
125124

126-
void NV12Buffer::CropAndScaleFrom(const NV12BufferInterface& src,
127-
int offset_x,
128-
int offset_y,
129-
int crop_width,
130-
int crop_height) {
131-
RTC_CHECK_LE(crop_width, src.width());
132-
RTC_CHECK_LE(crop_height, src.height());
133-
RTC_CHECK_LE(crop_width + offset_x, src.width());
134-
RTC_CHECK_LE(crop_height + offset_y, src.height());
135-
RTC_CHECK_GE(offset_x, 0);
136-
RTC_CHECK_GE(offset_y, 0);
137-
138-
// Make sure offset is even so that u/v plane becomes aligned.
139-
const int uv_offset_x = offset_x / 2;
140-
const int uv_offset_y = offset_y / 2;
141-
offset_x = uv_offset_x * 2;
142-
offset_y = uv_offset_y * 2;
143-
144-
const uint8_t* y_plane = src.DataY() + src.StrideY() * offset_y + offset_x;
145-
const uint8_t* uv_plane =
146-
src.DataUV() + src.StrideUV() * uv_offset_y + uv_offset_x * 2;
147-
148-
// kFilterBox is unsupported in libyuv, so using kFilterBilinear instead.
149-
int res = libyuv::NV12Scale(y_plane, src.StrideY(), uv_plane, src.StrideUV(),
150-
crop_width, crop_height, MutableDataY(),
151-
StrideY(), MutableDataUV(), StrideUV(), width(),
152-
height(), libyuv::kFilterBilinear);
153-
154-
RTC_DCHECK_EQ(res, 0);
155-
}
156-
157125
} // namespace webrtc

api/video/nv12_buffer.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ class RTC_EXPORT NV12Buffer : public NV12BufferInterface {
5656
// are resolved in a better way. Or in the mean time, use SetBlack.
5757
void InitializeData();
5858

59-
// Scale the cropped area of |src| to the size of |this| buffer, and
60-
// write the result into |this|.
61-
void CropAndScaleFrom(const NV12BufferInterface& src,
62-
int offset_x,
63-
int offset_y,
64-
int crop_width,
65-
int crop_height);
66-
6759
protected:
6860
NV12Buffer(int width, int height);
6961
NV12Buffer(int width, int height, int stride_y, int stride_uv);

api/video/test/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ rtc_library("rtc_api_video_unittests") {
2020
"..:video_adaptation",
2121
"..:video_bitrate_allocation",
2222
"..:video_frame",
23+
"..:video_frame_i420",
2324
"..:video_frame_nv12",
2425
"..:video_rtp_headers",
2526
"../../../test:frame_utils",

api/video/video_frame_buffer.cc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,10 @@
1010

1111
#include "api/video/video_frame_buffer.h"
1212

13-
#include "api/video/i420_buffer.h"
1413
#include "rtc_base/checks.h"
1514

1615
namespace webrtc {
1716

18-
rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::CropAndScale(
19-
int offset_x,
20-
int offset_y,
21-
int crop_width,
22-
int crop_height,
23-
int scaled_width,
24-
int scaled_height) {
25-
rtc::scoped_refptr<I420Buffer> result =
26-
I420Buffer::Create(scaled_width, scaled_height);
27-
result->CropAndScaleFrom(*this->ToI420(), offset_x, offset_y, crop_width,
28-
crop_height);
29-
return result;
30-
}
31-
3217
const I420BufferInterface* VideoFrameBuffer::GetI420() const {
3318
// Overridden by subclasses that can return an I420 buffer without any
3419
// conversion, in particular, I420BufferInterface.
@@ -139,4 +124,5 @@ int NV12BufferInterface::ChromaWidth() const {
139124
int NV12BufferInterface::ChromaHeight() const {
140125
return (height() + 1) / 2;
141126
}
127+
142128
} // namespace webrtc

api/video/video_frame_buffer.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,6 @@ class RTC_EXPORT VideoFrameBuffer : public rtc::RefCountInterface {
7979
// behave as the other GetXXX methods below.
8080
virtual const I420BufferInterface* GetI420() const;
8181

82-
// A format specific scale function. Default implementation works by
83-
// converting to I420. But more efficient implementations may override it,
84-
// especially for kNative.
85-
// First, the image is cropped to |crop_width| and |crop_height| and then
86-
// scaled to |scaled_width| and |scaled_height|.
87-
virtual rtc::scoped_refptr<VideoFrameBuffer> CropAndScale(int offset_x,
88-
int offset_y,
89-
int crop_width,
90-
int crop_height,
91-
int scaled_width,
92-
int scaled_height);
93-
94-
// Alias for common use case.
95-
rtc::scoped_refptr<VideoFrameBuffer> Scale(int scaled_width,
96-
int scaled_height) {
97-
return CropAndScale(0, 0, width(), height(), scaled_width, scaled_height);
98-
}
99-
10082
// These functions should only be called if type() is of the correct type.
10183
// Calling with a different type will result in a crash.
10284
const I420ABufferInterface* GetI420A() const;

api/video_codecs/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ rtc_library("rtc_software_fallback_wrappers") {
137137
deps = [
138138
":video_codecs_api",
139139
"..:fec_controller_api",
140-
"../../api/video:video_frame",
140+
"../../api/video:video_frame_i420",
141141
"../../media:rtc_h264_profile_id",
142142
"../../media:rtc_media_base",
143143
"../../modules/video_coding:video_codec_interface",

api/video_codecs/test/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ if (rtc_include_tests) {
3636
"../../video:encoded_image",
3737
"../../video:video_bitrate_allocation",
3838
"../../video:video_frame",
39+
"../../video:video_frame_i420",
3940
"../../video:video_rtp_headers",
4041
"//testing/gtest",
4142
]

common_video/BUILD.gn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ rtc_library("common_video") {
4949
"../api/video:video_bitrate_allocation",
5050
"../api/video:video_bitrate_allocator",
5151
"../api/video:video_frame",
52+
"../api/video:video_frame_i420",
5253
"../api/video:video_frame_nv12",
5354
"../api/video:video_rtp_headers",
5455
"../api/video_codecs:bitstream_parser_api",
@@ -104,7 +105,7 @@ if (rtc_include_tests) {
104105
"../api/units:time_delta",
105106
"../api/video:video_frame",
106107
"../api/video:video_frame_i010",
107-
"../api/video:video_frame_nv12",
108+
"../api/video:video_frame_i420",
108109
"../api/video:video_rtp_headers",
109110
"../media:rtc_h264_profile_id",
110111
"../rtc_base",

common_video/video_frame_unittest.cc

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "api/video/i010_buffer.h"
1717
#include "api/video/i420_buffer.h"
18-
#include "api/video/nv12_buffer.h"
1918
#include "rtc_base/bind.h"
2019
#include "rtc_base/time_utils.h"
2120
#include "test/fake_texture_frame.h"
@@ -158,29 +157,6 @@ rtc::scoped_refptr<PlanarYuvBuffer> CreateGradient(VideoFrameBuffer::Type type,
158157
return I010Buffer::Copy(*buffer);
159158
}
160159

161-
rtc::scoped_refptr<NV12BufferInterface> CreateNV12Gradient(int width,
162-
int height) {
163-
rtc::scoped_refptr<NV12Buffer> buffer(NV12Buffer::Create(width, height));
164-
// Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h
165-
for (int x = 0; x < width; x++) {
166-
for (int y = 0; y < height; y++) {
167-
buffer->MutableDataY()[x + y * width] =
168-
128 * (x * height + y * width) / (width * height);
169-
}
170-
}
171-
int chroma_width = buffer->ChromaWidth();
172-
int chroma_height = buffer->ChromaHeight();
173-
for (int x = 0; x < chroma_width; x++) {
174-
for (int y = 0; y < chroma_height; y++) {
175-
buffer->MutableDataUV()[x * 2 + y * buffer->StrideUV()] =
176-
255 * x / (chroma_width - 1);
177-
buffer->MutableDataUV()[x * 2 + 1 + y * buffer->StrideUV()] =
178-
255 * y / (chroma_height - 1);
179-
}
180-
}
181-
return buffer;
182-
}
183-
184160
// The offsets and sizes describe the rectangle extracted from the
185161
// original (gradient) frame, in relative coordinates where the
186162
// original frame correspond to the unit square, 0.0 <= x, y < 1.0.
@@ -519,35 +495,6 @@ INSTANTIATE_TEST_SUITE_P(All,
519495
::testing::Values(VideoFrameBuffer::Type::kI420,
520496
VideoFrameBuffer::Type::kI010));
521497

522-
TEST(TestNV12Buffer, CropAndScale) {
523-
const int kSourceWidth = 640;
524-
const int kSourceHeight = 480;
525-
const int kScaledWidth = 320;
526-
const int kScaledHeight = 240;
527-
const int kCropLeft = 40;
528-
const int kCropTop = 30;
529-
const int kCropRight = 0;
530-
const int kCropBottom = 30;
531-
532-
rtc::scoped_refptr<VideoFrameBuffer> buf =
533-
CreateNV12Gradient(kSourceWidth, kSourceHeight);
534-
535-
rtc::scoped_refptr<VideoFrameBuffer> scaled_buffer = buf->CropAndScale(
536-
kCropLeft, kCropTop, kSourceWidth - kCropLeft - kCropRight,
537-
kSourceHeight - kCropTop - kCropBottom, kScaledWidth, kScaledHeight);
538-
539-
// Parameters to CheckCrop indicate what part of the source frame is in the
540-
// scaled frame.
541-
const float kOffsetX = (kCropLeft + 0.0) / kSourceWidth;
542-
const float kOffsetY = (kCropTop + 0.0) / kSourceHeight;
543-
const float kRelativeWidth =
544-
(kSourceWidth - kCropLeft - kCropRight + 0.0) / kSourceWidth;
545-
const float kRelativeHeight =
546-
(kSourceHeight - kCropTop - kCropBottom + 0.0) / kSourceHeight;
547-
CheckCrop(*scaled_buffer->ToI420(), kOffsetX, kOffsetY, kRelativeWidth,
548-
kRelativeHeight);
549-
}
550-
551498
class TestPlanarYuvBufferRotate
552499
: public ::testing::TestWithParam<
553500
std::tuple<webrtc::VideoRotation, VideoFrameBuffer::Type>> {};

0 commit comments

Comments
 (0)