Refactor scaling.
Introduce a new method I420Buffer::CropAndScale, and a static
convenience helper I420Buffer::CenterCropAndScale. Use them for almost
all scaling needs.
Delete the Scaler class and the cricket::VideoFrame::Stretch* methods.
BUG=webrtc:5682
R=pbos@webrtc.org, perkj@webrtc.org, stefan@webrtc.org
Review URL: https://codereview.webrtc.org/2020593002 .
Cr-Commit-Position: refs/heads/master@{#13110}
diff --git a/webrtc/api/java/jni/androidmediaencoder_jni.cc b/webrtc/api/java/jni/androidmediaencoder_jni.cc
index a240b25..b76cfe7 100644
--- a/webrtc/api/java/jni/androidmediaencoder_jni.cc
+++ b/webrtc/api/java/jni/androidmediaencoder_jni.cc
@@ -670,7 +670,7 @@
VideoFrame input_frame = frame;
if (scale_) {
// Check framerate before spatial resolution change.
- quality_scaler_.OnEncodeFrame(frame);
+ quality_scaler_.OnEncodeFrame(frame.width(), frame.height());
const webrtc::QualityScaler::Resolution scaled_resolution =
quality_scaler_.GetScaledResolution();
if (scaled_resolution.width != frame.width() ||
@@ -684,7 +684,8 @@
webrtc::kVideoRotation_0));
input_frame.set_video_frame_buffer(scaled_buffer);
} else {
- input_frame = quality_scaler_.GetScaledFrame(frame);
+ input_frame.set_video_frame_buffer(
+ quality_scaler_.GetScaledBuffer(frame.video_frame_buffer()));
}
}
}
diff --git a/webrtc/api/java/jni/androidvideocapturer_jni.cc b/webrtc/api/java/jni/androidvideocapturer_jni.cc
index 82d8c8e..4f3d64b 100644
--- a/webrtc/api/java/jni/androidvideocapturer_jni.cc
+++ b/webrtc/api/java/jni/androidvideocapturer_jni.cc
@@ -13,7 +13,6 @@
#include "webrtc/api/java/jni/native_handle_impl.h"
#include "webrtc/api/java/jni/surfacetexturehelper_jni.h"
#include "third_party/libyuv/include/libyuv/convert.h"
-#include "third_party/libyuv/include/libyuv/scale.h"
#include "webrtc/base/bind.h"
namespace webrtc_jni {
@@ -223,25 +222,11 @@
crop_width, crop_height, static_cast<libyuv::RotationMode>(
capturer_->apply_rotation() ? rotation : 0));
- if (adapted_width != rotated_width || adapted_height != rotated_height) {
- rtc::scoped_refptr<webrtc::VideoFrameBuffer> scaled =
- post_scale_pool_.CreateBuffer(adapted_width, adapted_height);
- // TODO(nisse): This should be done by some Scale method in
- // I420Buffer, but we can't do that right now, since
- // I420BufferPool uses a wrapper object.
- if (libyuv::I420Scale(buffer->DataY(), buffer->StrideY(),
- buffer->DataU(), buffer->StrideU(),
- buffer->DataV(), buffer->StrideV(),
- rotated_width, rotated_height,
- scaled->MutableDataY(), scaled->StrideY(),
- scaled->MutableDataU(), scaled->StrideU(),
- scaled->MutableDataV(), scaled->StrideV(),
- adapted_width, adapted_height,
- libyuv::kFilterBox) < 0) {
- LOG(LS_WARNING) << "I420Scale failed";
- return;
- }
- buffer = scaled;
+ if (adapted_width != buffer->width() || adapted_height != buffer->height()) {
+ rtc::scoped_refptr<webrtc::I420Buffer> scaled_buffer(
+ post_scale_pool_.CreateBuffer(adapted_width, adapted_height));
+ scaled_buffer->ScaleFrom(buffer);
+ buffer = scaled_buffer;
}
// TODO(nisse): Use microsecond time instead.
capturer_->OnFrame(cricket::WebRtcVideoFrame(