Rewrite CreateBlackFrame in webrtcvideoengine.

Don't use VideoFrameBuffer::MutableDataY and friends, instead, use
I420Buffer::SetToBlack.

Also introduce static method I420Buffer::Create, to create an object and
return a scoped_refptr.

TBR=marpan@webrtc.org # Trivial change to video_denoiser.cc
BUG=webrtc:5921

Review-Url: https://codereview.webrtc.org/2078943002
Cr-Commit-Position: refs/heads/master@{#13212}
This commit is contained in:
nisse
2016-06-20 03:38:52 -07:00
committed by Commit bot
parent 44bf02fba2
commit ac62bd4a3b
9 changed files with 48 additions and 49 deletions

View File

@ -29,7 +29,7 @@ int ExpectedSize(int plane_stride, int image_height, PlaneType type) {
rtc::scoped_refptr<I420Buffer> CreateGradient(int width, int height) {
rtc::scoped_refptr<I420Buffer> buffer(
new rtc::RefCountedObject<I420Buffer>(width, height));
I420Buffer::Create(width, height));
// Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
@ -296,7 +296,7 @@ TEST(TestVideoFrame, TextureInitialValues) {
TEST(TestI420FrameBuffer, Copy) {
rtc::scoped_refptr<I420Buffer> buf1(
new rtc::RefCountedObject<I420Buffer>(20, 10));
I420Buffer::Create(20, 10));
memset(buf1->MutableDataY(), 1, 200);
memset(buf1->MutableDataU(), 2, 50);
memset(buf1->MutableDataV(), 3, 50);
@ -309,7 +309,7 @@ TEST(TestI420FrameBuffer, Scale) {
// Pure scaling, no cropping.
rtc::scoped_refptr<I420Buffer> scaled_buffer(
new rtc::RefCountedObject<I420Buffer>(150, 75));
I420Buffer::Create(150, 75));
scaled_buffer->ScaleFrom(buf);
CheckCrop(scaled_buffer, 0.0, 0.0, 1.0, 1.0);
@ -320,7 +320,7 @@ TEST(TestI420FrameBuffer, CropXCenter) {
// Pure center cropping, no scaling.
rtc::scoped_refptr<I420Buffer> scaled_buffer(
new rtc::RefCountedObject<I420Buffer>(100, 100));
I420Buffer::Create(100, 100));
scaled_buffer->CropAndScaleFrom(buf, 50, 0, 100, 100);
CheckCrop(scaled_buffer, 0.25, 0.0, 0.5, 1.0);
@ -331,7 +331,7 @@ TEST(TestI420FrameBuffer, CropXNotCenter) {
// Non-center cropping, no scaling.
rtc::scoped_refptr<I420Buffer> scaled_buffer(
new rtc::RefCountedObject<I420Buffer>(100, 100));
I420Buffer::Create(100, 100));
scaled_buffer->CropAndScaleFrom(buf, 25, 0, 100, 100);
CheckCrop(scaled_buffer, 0.125, 0.0, 0.5, 1.0);
@ -342,7 +342,7 @@ TEST(TestI420FrameBuffer, CropYCenter) {
// Pure center cropping, no scaling.
rtc::scoped_refptr<I420Buffer> scaled_buffer(
new rtc::RefCountedObject<I420Buffer>(100, 100));
I420Buffer::Create(100, 100));
scaled_buffer->CropAndScaleFrom(buf, 0, 50, 100, 100);
CheckCrop(scaled_buffer, 0.0, 0.25, 1.0, 0.5);
@ -353,7 +353,7 @@ TEST(TestI420FrameBuffer, CropYNotCenter) {
// Non-center cropping, no scaling.
rtc::scoped_refptr<I420Buffer> scaled_buffer(
new rtc::RefCountedObject<I420Buffer>(100, 100));
I420Buffer::Create(100, 100));
scaled_buffer->CropAndScaleFrom(buf, 0, 25, 100, 100);
CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.5);
@ -364,7 +364,7 @@ TEST(TestI420FrameBuffer, CropAndScale16x9) {
// Center crop to 640 x 360 (16/9 aspect), then scale down by 2.
rtc::scoped_refptr<I420Buffer> scaled_buffer(
new rtc::RefCountedObject<I420Buffer>(320, 180));
I420Buffer::Create(320, 180));
scaled_buffer->CropAndScaleFrom(buf);
CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.75);

View File

@ -88,6 +88,13 @@ class I420Buffer : public VideoFrameBuffer {
I420Buffer(int width, int height);
I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v);
static rtc::scoped_refptr<I420Buffer> Create(int width, int height);
static rtc::scoped_refptr<I420Buffer> Create(int width,
int height,
int stride_y,
int stride_u,
int stride_v);
// Sets all three planes to all zeros. Used to work around for
// quirks in memory checkers
// (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and

View File

@ -61,7 +61,7 @@ void VideoFrame::CreateEmptyFrame(int width,
rotation_ = kVideoRotation_0;
// Allocate a new buffer.
video_frame_buffer_ = new rtc::RefCountedObject<I420Buffer>(
video_frame_buffer_ = I420Buffer::Create(
width, height, stride_y, stride_u, stride_v);
}

View File

@ -134,6 +134,19 @@ I420Buffer::I420Buffer(int width,
I420Buffer::~I420Buffer() {
}
rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, int height) {
return new rtc::RefCountedObject<I420Buffer>(width, height);
}
rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width,
int height,
int stride_y,
int stride_u,
int stride_v) {
return new rtc::RefCountedObject<I420Buffer>(
width, height, stride_y, stride_u, stride_v);
}
void I420Buffer::InitializeData() {
memset(data_.get(), 0,
I420DataSize(height_, stride_y_, stride_u_, stride_v_));
@ -190,8 +203,7 @@ rtc::scoped_refptr<I420Buffer> I420Buffer::Copy(
const rtc::scoped_refptr<VideoFrameBuffer>& source) {
int width = source->width();
int height = source->height();
rtc::scoped_refptr<I420Buffer> target =
new rtc::RefCountedObject<I420Buffer>(width, height);
rtc::scoped_refptr<I420Buffer> target = I420Buffer::Create(width, height);
RTC_CHECK(libyuv::I420Copy(source->DataY(), source->StrideY(),
source->DataU(), source->StrideU(),
source->DataV(), source->StrideV(),
@ -273,8 +285,7 @@ rtc::scoped_refptr<I420Buffer> I420Buffer::CopyKeepStride(
int stride_u = source->StrideU();
int stride_v = source->StrideV();
rtc::scoped_refptr<I420Buffer> target =
new rtc::RefCountedObject<I420Buffer>(
width, height, stride_y, stride_u, stride_v);
I420Buffer::Create(width, height, stride_y, stride_u, stride_v);
RTC_CHECK(libyuv::I420Copy(source->DataY(), stride_y,
source->DataU(), stride_u,
source->DataV(), stride_v,

View File

@ -1577,24 +1577,6 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() {
DestroyVideoEncoder(&allocated_encoder_);
}
static webrtc::VideoFrame CreateBlackFrame(int width,
int height,
int64_t render_time_ms_,
webrtc::VideoRotation rotation) {
webrtc::VideoFrame frame;
frame.CreateEmptyFrame(width, height, width, (width + 1) / 2,
(width + 1) / 2);
memset(frame.video_frame_buffer()->MutableDataY(), 16,
frame.allocated_size(webrtc::kYPlane));
memset(frame.video_frame_buffer()->MutableDataU(), 128,
frame.allocated_size(webrtc::kUPlane));
memset(frame.video_frame_buffer()->MutableDataV(), 128,
frame.allocated_size(webrtc::kVPlane));
frame.set_rotation(rotation);
frame.set_render_time_ms(render_time_ms_);
return frame;
}
void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame(
const VideoFrame& frame) {
TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::OnFrame");
@ -1691,8 +1673,13 @@ bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend(
// necessary to give this black frame a larger timestamp than the
// previous one.
last_frame_timestamp_ms_ += 1;
stream_->Input()->IncomingCapturedFrame(CreateBlackFrame(
last_frame_info_.width, last_frame_info_.height,
rtc::scoped_refptr<webrtc::I420Buffer> black_buffer(
webrtc::I420Buffer::Create(last_frame_info_.width,
last_frame_info_.height));
black_buffer->SetToBlack();
stream_->Input()->IncomingCapturedFrame(webrtc::VideoFrame(
black_buffer, 0 /* timestamp (90 kHz) */,
last_frame_timestamp_ms_, last_frame_info_.rotation));
}
source_ = source;

View File

@ -335,7 +335,7 @@ void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) {
if (image.width() != config_.codec_settings->width ||
image.height() != config_.codec_settings->height) {
rtc::scoped_refptr<I420Buffer> up_image(
new rtc::RefCountedObject<I420Buffer>(config_.codec_settings->width,
I420Buffer::Create(config_.codec_settings->width,
config_.codec_settings->height));
// Should be the same aspect ratio, no cropping needed.

View File

@ -42,8 +42,7 @@ class QualityScalerTest : public ::testing::Test {
};
QualityScalerTest() {
input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>(
new rtc::RefCountedObject<I420Buffer>(kWidth, kHeight));
input_frame_ = I420Buffer::Create(kWidth, kHeight);
qs_.Init(kLowQpThreshold, kHighQp, 0, 0, 0, kFramerate);
qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height());
}
@ -219,14 +218,12 @@ TEST_F(QualityScalerTest,
ContinuouslyDownscalesOddResolutionsByHalfDimensionsAndBackUp) {
const int kOddWidth = 517;
const int kOddHeight = 1239;
input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>(
new rtc::RefCountedObject<I420Buffer>(kOddWidth, kOddHeight));
input_frame_ = I420Buffer::Create(kOddWidth, kOddHeight);
ContinuouslyDownscalesByHalfDimensionsAndBackUp();
}
void QualityScalerTest::DoesNotDownscaleFrameDimensions(int width, int height) {
input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>(
new rtc::RefCountedObject<I420Buffer>(width, height));
input_frame_ = I420Buffer::Create(width, height);
for (int i = 0; i < kFramerate * kNumSeconds; ++i) {
qs_.ReportDroppedFrame();
@ -262,8 +259,7 @@ TEST_F(QualityScalerTest, DownscaleToVgaOnLowInitialBitrate) {
static const int kWidth720p = 1280;
static const int kHeight720p = 720;
static const int kInitialBitrateKbps = 300;
input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>(
new rtc::RefCountedObject<I420Buffer>(kWidth720p, kHeight720p));
input_frame_ = I420Buffer::Create(kWidth720p, kHeight720p);
qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, kInitialBitrateKbps,
kWidth720p, kHeight720p, kFramerate);
qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height());
@ -277,8 +273,7 @@ TEST_F(QualityScalerTest, DownscaleToQvgaOnLowerInitialBitrate) {
static const int kWidth720p = 1280;
static const int kHeight720p = 720;
static const int kInitialBitrateKbps = 200;
input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>(
new rtc::RefCountedObject<I420Buffer>(kWidth720p, kHeight720p));
input_frame_ = I420Buffer::Create(kWidth720p, kHeight720p);
qs_.Init(kLowQpThreshold, kDisabledBadQpThreshold, kInitialBitrateKbps,
kWidth720p, kHeight720p, kFramerate);
qs_.OnEncodeFrame(input_frame_->width(), input_frame_->height());
@ -353,8 +348,7 @@ void QualityScalerTest::DownscaleEndsAt(int input_width,
int end_height) {
// Create a frame with 2x expected end width/height to verify that we can
// scale down to expected end width/height.
input_frame_ = rtc::scoped_refptr<VideoFrameBuffer>(
new rtc::RefCountedObject<I420Buffer>(input_width, input_height));
input_frame_ = I420Buffer::Create(input_width, input_height);
int last_width = input_width;
int last_height = input_height;

View File

@ -86,7 +86,7 @@ void VideoDenoiser::DenoiserReset(
stride_v_ = frame->StrideV();
// Allocate an empty buffer for denoised_frame_prev.
*denoised_frame_prev = new rtc::RefCountedObject<I420Buffer>(
*denoised_frame_prev = I420Buffer::Create(
width_, height_, stride_y_, stride_u_, stride_v_);
// Allocate and initialize denoised_frame with key frame.
*denoised_frame = I420Buffer::CopyKeepStride(frame);

View File

@ -39,7 +39,7 @@ class FakeNativeHandleBuffer : public NativeHandleBuffer {
private:
rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override {
rtc::scoped_refptr<VideoFrameBuffer> buffer(
new rtc::RefCountedObject<I420Buffer>(width_, height_));
I420Buffer::Create(width_, height_));
int half_height = (height_ + 1) / 2;
int half_width = (width_ + 1) / 2;
memset(buffer->MutableDataY(), 0, height_ * width_);