Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(713)

Unified Diff: webrtc/common_video/libyuv/libyuv_unittest.cc

Issue 2278883002: Move MutableDataY{,U,V} methods to I420Buffer only. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update android capture and decoder code. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/common_video/libyuv/libyuv_unittest.cc
diff --git a/webrtc/common_video/libyuv/libyuv_unittest.cc b/webrtc/common_video/libyuv/libyuv_unittest.cc
index ab36559ba557d54912ea5f5544acf0e264bd7b32..5c6398b0eb9aca74fdb39a7ab3f8b670606e1ebe 100644
--- a/webrtc/common_video/libyuv/libyuv_unittest.cc
+++ b/webrtc/common_video/libyuv/libyuv_unittest.cc
@@ -95,108 +95,122 @@ TEST_F(TestLibYuv, ConvertTest) {
double psnr = 0.0;
- VideoFrame res_i420_frame;
- res_i420_frame.CreateEmptyFrame(width_, height_, width_,
- (width_ + 1) / 2,
- (width_ + 1) / 2);
- printf("\nConvert #%d I420 <-> I420 \n", j);
- std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]);
- EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0,
- out_i420_buffer.get()));
- EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_,
- height_, 0, kVideoRotation_0, &res_i420_frame));
-
- if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
- return;
+ rtc::scoped_refptr<I420Buffer> res_i420_buffer = I420Buffer::Create(
+ width_, height_, width_, (width_ + 1) / 2, (width_ + 1) / 2);
+ {
+ printf("\nConvert #%d I420 <-> I420 \n", j);
+ std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]);
+ EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, out_i420_buffer.get()));
+ EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_,
+ height_, 0, kVideoRotation_0, res_i420_buffer));
+
+ VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
+ if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
+ return;
+ }
+ psnr = I420PSNR(&orig_frame_, &res_i420_frame);
magjed_webrtc 2016/08/25 11:12:56 Can you use VideoFrameBuffers as input here instea
nisse-webrtc 2016/08/25 11:31:35 I think the problem is the PrintVideoFrame method.
+ EXPECT_EQ(48.0, psnr);
+ j++;
}
- psnr = I420PSNR(&orig_frame_, &res_i420_frame);
- EXPECT_EQ(48.0, psnr);
- j++;
-
- printf("\nConvert #%d I420 <-> RGB24\n", j);
- std::unique_ptr<uint8_t[]> res_rgb_buffer2(new uint8_t[width_ * height_ * 3]);
- // Align the stride values for the output frame.
- int stride_y = 0;
- int stride_uv = 0;
- Calc16ByteAlignedStride(width_, &stride_y, &stride_uv);
- res_i420_frame.CreateEmptyFrame(width_, height_, stride_y,
- stride_uv, stride_uv);
- EXPECT_EQ(0, ConvertFromI420(orig_frame_, kRGB24, 0, res_rgb_buffer2.get()));
-
- EXPECT_EQ(0, ConvertToI420(kRGB24, res_rgb_buffer2.get(), 0, 0, width_,
- height_, 0, kVideoRotation_0, &res_i420_frame));
-
- if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
- return;
+ {
magjed_webrtc 2016/08/25 11:12:56 The diff is kind of broken and becomes unnecessari
+ printf("\nConvert #%d I420 <-> RGB24\n", j);
+ std::unique_ptr<uint8_t[]> res_rgb_buffer2(
+ new uint8_t[width_ * height_ * 3]);
+ // Align the stride values for the output frame.
+ int stride_y = 0;
+ int stride_uv = 0;
+ Calc16ByteAlignedStride(width_, &stride_y, &stride_uv);
+ res_i420_buffer =
+ I420Buffer::Create(width_, height_, stride_y, stride_uv, stride_uv);
+ EXPECT_EQ(0,
+ ConvertFromI420(orig_frame_, kRGB24, 0, res_rgb_buffer2.get()));
+
+ EXPECT_EQ(0, ConvertToI420(kRGB24, res_rgb_buffer2.get(), 0, 0, width_,
+ height_, 0, kVideoRotation_0, res_i420_buffer));
+
+ VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
+ if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
+ return;
+ }
+ psnr = I420PSNR(&orig_frame_, &res_i420_frame);
+
+ // Optimization Speed- quality trade-off => 45 dB only (platform dependant).
+ EXPECT_GT(ceil(psnr), 44);
+ j++;
}
- psnr = I420PSNR(&orig_frame_, &res_i420_frame);
-
- // Optimization Speed- quality trade-off => 45 dB only (platform dependant).
- EXPECT_GT(ceil(psnr), 44);
- j++;
-
- printf("\nConvert #%d I420 <-> UYVY\n", j);
- std::unique_ptr<uint8_t[]> out_uyvy_buffer(new uint8_t[width_ * height_ * 2]);
- EXPECT_EQ(0, ConvertFromI420(orig_frame_, kUYVY, 0, out_uyvy_buffer.get()));
- EXPECT_EQ(0, ConvertToI420(kUYVY, out_uyvy_buffer.get(), 0, 0, width_,
- height_, 0, kVideoRotation_0, &res_i420_frame));
- psnr = I420PSNR(&orig_frame_, &res_i420_frame);
- EXPECT_EQ(48.0, psnr);
- if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
- return;
+ {
+ printf("\nConvert #%d I420 <-> UYVY\n", j);
+ std::unique_ptr<uint8_t[]> out_uyvy_buffer(
+ new uint8_t[width_ * height_ * 2]);
+ EXPECT_EQ(0, ConvertFromI420(orig_frame_, kUYVY, 0, out_uyvy_buffer.get()));
+ EXPECT_EQ(0, ConvertToI420(kUYVY, out_uyvy_buffer.get(), 0, 0, width_,
+ height_, 0, kVideoRotation_0, res_i420_buffer));
+ VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
+ psnr = I420PSNR(&orig_frame_, &res_i420_frame);
+ EXPECT_EQ(48.0, psnr);
+ if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
+ return;
+ }
+ j++;
}
- j++;
-
- printf("\nConvert #%d I420 <-> YUY2\n", j);
- std::unique_ptr<uint8_t[]> out_yuy2_buffer(new uint8_t[width_ * height_ * 2]);
- EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYUY2, 0, out_yuy2_buffer.get()));
-
- EXPECT_EQ(0, ConvertToI420(kYUY2, out_yuy2_buffer.get(), 0, 0, width_,
- height_, 0, kVideoRotation_0, &res_i420_frame));
-
- if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
- return;
+ {
+ printf("\nConvert #%d I420 <-> YUY2\n", j);
+ std::unique_ptr<uint8_t[]> out_yuy2_buffer(
+ new uint8_t[width_ * height_ * 2]);
+ EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYUY2, 0, out_yuy2_buffer.get()));
+
+ EXPECT_EQ(0, ConvertToI420(kYUY2, out_yuy2_buffer.get(), 0, 0, width_,
+ height_, 0, kVideoRotation_0, res_i420_buffer));
+
+ VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
+ if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
+ return;
+ }
+
+ psnr = I420PSNR(&orig_frame_, &res_i420_frame);
+ EXPECT_EQ(48.0, psnr);
}
-
- psnr = I420PSNR(&orig_frame_, &res_i420_frame);
- EXPECT_EQ(48.0, psnr);
- printf("\nConvert #%d I420 <-> RGB565\n", j);
- std::unique_ptr<uint8_t[]> out_rgb565_buffer(
- new uint8_t[width_ * height_ * 2]);
- EXPECT_EQ(0, ConvertFromI420(orig_frame_, kRGB565, 0,
- out_rgb565_buffer.get()));
-
- EXPECT_EQ(0, ConvertToI420(kRGB565, out_rgb565_buffer.get(), 0, 0, width_,
- height_, 0, kVideoRotation_0, &res_i420_frame));
-
- if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
- return;
+ {
+ printf("\nConvert #%d I420 <-> RGB565\n", j);
+ std::unique_ptr<uint8_t[]> out_rgb565_buffer(
+ new uint8_t[width_ * height_ * 2]);
+ EXPECT_EQ(
+ 0, ConvertFromI420(orig_frame_, kRGB565, 0, out_rgb565_buffer.get()));
+
+ EXPECT_EQ(0, ConvertToI420(kRGB565, out_rgb565_buffer.get(), 0, 0, width_,
+ height_, 0, kVideoRotation_0, res_i420_buffer));
+ VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
+ if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
+ return;
+ }
+ j++;
+
+ psnr = I420PSNR(&orig_frame_, &res_i420_frame);
+ // TODO(leozwang) Investigate the right psnr should be set for I420ToRGB565,
+ // Another example is I420ToRGB24, the psnr is 44
+ // TODO(mikhal): Add psnr for RGB565, 1555, 4444, convert to ARGB.
+ EXPECT_GT(ceil(psnr), 40);
}
- j++;
-
- psnr = I420PSNR(&orig_frame_, &res_i420_frame);
- // TODO(leozwang) Investigate the right psnr should be set for I420ToRGB565,
- // Another example is I420ToRGB24, the psnr is 44
- // TODO(mikhal): Add psnr for RGB565, 1555, 4444, convert to ARGB.
- EXPECT_GT(ceil(psnr), 40);
-
- printf("\nConvert #%d I420 <-> ARGB8888\n", j);
- std::unique_ptr<uint8_t[]> out_argb8888_buffer(
- new uint8_t[width_ * height_ * 4]);
- EXPECT_EQ(0, ConvertFromI420(orig_frame_, kARGB, 0,
- out_argb8888_buffer.get()));
-
- EXPECT_EQ(0, ConvertToI420(kARGB, out_argb8888_buffer.get(), 0, 0, width_,
- height_, 0, kVideoRotation_0, &res_i420_frame));
-
- if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
- return;
+ {
+ printf("\nConvert #%d I420 <-> ARGB8888\n", j);
+ std::unique_ptr<uint8_t[]> out_argb8888_buffer(
+ new uint8_t[width_ * height_ * 4]);
+ EXPECT_EQ(
+ 0, ConvertFromI420(orig_frame_, kARGB, 0, out_argb8888_buffer.get()));
+
+ EXPECT_EQ(0, ConvertToI420(kARGB, out_argb8888_buffer.get(), 0, 0, width_,
+ height_, 0, kVideoRotation_0, res_i420_buffer));
+
+ VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
+ if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
+ return;
+ }
+
+ psnr = I420PSNR(&orig_frame_, &res_i420_frame);
+ // TODO(leozwang) Investigate the right psnr should be set for
+ // I420ToARGB8888,
+ EXPECT_GT(ceil(psnr), 42);
}
-
- psnr = I420PSNR(&orig_frame_, &res_i420_frame);
- // TODO(leozwang) Investigate the right psnr should be set for I420ToARGB8888,
- EXPECT_GT(ceil(psnr), 42);
-
ASSERT_EQ(0, fclose(output_file));
}
@@ -209,18 +223,19 @@ TEST_F(TestLibYuv, ConvertAlignedFrame) {
double psnr = 0.0;
- VideoFrame res_i420_frame;
int stride_y = 0;
int stride_uv = 0;
Calc16ByteAlignedStride(width_, &stride_y, &stride_uv);
- res_i420_frame.CreateEmptyFrame(width_, height_,
- stride_y, stride_uv, stride_uv);
+
+ rtc::scoped_refptr<I420Buffer> res_i420_buffer =
+ I420Buffer::Create(width_, height_, stride_y, stride_uv, stride_uv);
std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]);
EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0,
out_i420_buffer.get()));
EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_,
- height_, 0, kVideoRotation_0, &res_i420_frame));
+ height_, 0, kVideoRotation_0, res_i420_buffer));
+ VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
magjed_webrtc 2016/08/25 11:12:56 It would be nice if you can make functions like Pr
return;
}
@@ -230,28 +245,23 @@ TEST_F(TestLibYuv, ConvertAlignedFrame) {
TEST_F(TestLibYuv, RotateTest) {
- // Use ConvertToI420 for multiple roatations - see that nothing breaks, all
+ // Use ConvertToI420 for multiple rotations - see that nothing breaks, all
// memory is properly allocated and end result is equal to the starting point.
- VideoFrame rotated_res_i420_frame;
int rotated_width = height_;
int rotated_height = width_;
int stride_y;
int stride_uv;
Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv);
- rotated_res_i420_frame.CreateEmptyFrame(rotated_width,
- rotated_height,
- stride_y,
- stride_uv,
- stride_uv);
+ rtc::scoped_refptr<I420Buffer> rotated_res_i420_buffer = I420Buffer::Create(
+ rotated_width, rotated_height, stride_y, stride_uv, stride_uv);
EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
- 0, kVideoRotation_90, &rotated_res_i420_frame));
+ 0, kVideoRotation_90, rotated_res_i420_buffer));
EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
- 0, kVideoRotation_270, &rotated_res_i420_frame));
- rotated_res_i420_frame.CreateEmptyFrame(width_, height_,
- width_, (width_ + 1) / 2,
- (width_ + 1) / 2);
+ 0, kVideoRotation_270, rotated_res_i420_buffer));
+ rotated_res_i420_buffer = I420Buffer::Create(
+ width_, height_, width_, (width_ + 1) / 2, (width_ + 1) / 2);
EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
- 0, kVideoRotation_180, &rotated_res_i420_frame));
+ 0, kVideoRotation_180, rotated_res_i420_buffer));
}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698