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

Unified Diff: webrtc/modules/video_processing/test/video_processing_unittest.cc

Issue 2362683002: New helper function test::ReadI420Buffer, refactor FrameReader to use it. (Closed)
Patch Set: Created 4 years, 3 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/modules/video_processing/test/video_processing_unittest.cc
diff --git a/webrtc/modules/video_processing/test/video_processing_unittest.cc b/webrtc/modules/video_processing/test/video_processing_unittest.cc
index 9e61b51884f75a41532eaf242319314ee2481b38..0153a67f964aa58a3a0c3e39f42b069e05dc7970 100644
--- a/webrtc/modules/video_processing/test/video_processing_unittest.cc
+++ b/webrtc/modules/video_processing/test/video_processing_unittest.cc
@@ -15,8 +15,10 @@
#include <memory>
#include <string>
+#include "webrtc/base/keep_ref_until_done.h"
#include "webrtc/base/timeutils.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
+#include "webrtc/test/frame_utils.h"
#include "webrtc/test/testsupport/fileutils.h"
namespace webrtc {
@@ -33,20 +35,18 @@ static void PreprocessFrameAndVerify(const VideoFrame& source,
int target_height,
VideoProcessing* vpm,
const VideoFrame* out_frame);
-static void CropFrame(const uint8_t* source_data,
- int source_width,
- int source_height,
- int offset_x,
- int offset_y,
- int cropped_width,
- int cropped_height,
- VideoFrame* cropped_frame);
+static rtc::scoped_refptr<VideoFrameBuffer> CropFrame(
+ rtc::scoped_refptr<VideoFrameBuffer> source,
+ int offset_x,
+ int offset_y,
+ int cropped_width,
+ int cropped_height);
// The |source_data| is cropped and scaled to |target_width| x |target_height|,
// and then scaled back to the expected cropped size. |expected_psnr| is used to
// verify basic quality, and is set to be ~0.1/0.05dB lower than actual PSNR
// verified under the same conditions.
static void TestSize(const VideoFrame& source_frame,
- const VideoFrame& cropped_source_frame,
+ const VideoFrameBuffer& cropped_source,
int target_width,
int target_height,
double expected_psnr,
@@ -133,15 +133,11 @@ TEST_F(VideoProcessingTest, Resampler) {
vp_->EnableTemporalDecimation(false);
// Reading test frame
- std::unique_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
- ASSERT_EQ(frame_length_,
- fread(video_buffer.get(), 1, frame_length_, source_file_));
- // Using ConvertToI420 to add stride to the image.
- EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
- 0, kVideoRotation_0, &video_frame_));
- // Cropped source frame that will contain the expected visible region.
- VideoFrame cropped_source_frame;
- cropped_source_frame.CopyFrame(video_frame_);
+ rtc::scoped_refptr<VideoFrameBuffer> video_buffer(
+ test::ReadI420Buffer(width_, height_, source_file_));
+ ASSERT_TRUE(video_buffer);
+
+ VideoFrame video_frame(video_buffer, kVideoRotation_0, 0);
for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) {
// Initiate test timer.
@@ -154,43 +150,36 @@ TEST_F(VideoProcessingTest, Resampler) {
// Test scaling to different sizes: source is of |width|/|height| = 352/288.
// Pure scaling:
- TestSize(video_frame_, video_frame_, width_ / 4, height_ / 4, 25.2, vp_);
- TestSize(video_frame_, video_frame_, width_ / 2, height_ / 2, 28.1, vp_);
+ TestSize(video_frame, *video_buffer, width_ / 4, height_ / 4, 25.2, vp_);
+ TestSize(video_frame, *video_buffer, width_ / 2, height_ / 2, 28.1, vp_);
// No resampling:
- TestSize(video_frame_, video_frame_, width_, height_, -1, vp_);
- TestSize(video_frame_, video_frame_, 2 * width_, 2 * height_, 32.2, vp_);
+ TestSize(video_frame, *video_buffer, width_, height_, -1, vp_);
+ TestSize(video_frame, *video_buffer, 2 * width_, 2 * height_, 32.2, vp_);
// Scaling and cropping. The cropped source frame is the largest center
// aligned region that can be used from the source while preserving aspect
// ratio.
- CropFrame(video_buffer.get(), width_, height_, 0, 56, 352, 176,
- &cropped_source_frame);
- TestSize(video_frame_, cropped_source_frame, 100, 50, 24.0, vp_);
+ TestSize(video_frame_, *CropFrame(video_buffer, 0, 56, 352, 176),
+ 100, 50, 24.0, vp_);
- CropFrame(video_buffer.get(), width_, height_, 0, 30, 352, 225,
- &cropped_source_frame);
- TestSize(video_frame_, cropped_source_frame, 400, 256, 31.3, vp_);
+ TestSize(video_frame_, *CropFrame(video_buffer, 0, 30, 352, 225),
+ 400, 256, 31.3, vp_);
- CropFrame(video_buffer.get(), width_, height_, 68, 0, 216, 288,
- &cropped_source_frame);
- TestSize(video_frame_, cropped_source_frame, 480, 640, 32.15, vp_);
+ TestSize(video_frame_, *CropFrame(video_buffer, 68, 0, 216, 288),
+ 480, 640, 32.15, vp_);
- CropFrame(video_buffer.get(), width_, height_, 0, 12, 352, 264,
- &cropped_source_frame);
- TestSize(video_frame_, cropped_source_frame, 960, 720, 32.2, vp_);
+ TestSize(video_frame_, *CropFrame(video_buffer, 0, 12, 352, 264),
+ 960, 720, 32.2, vp_);
- CropFrame(video_buffer.get(), width_, height_, 0, 44, 352, 198,
- &cropped_source_frame);
- TestSize(video_frame_, cropped_source_frame, 1280, 720, 32.15, vp_);
+ TestSize(video_frame_, *CropFrame(video_buffer, 0, 44, 352, 198),
+ 1280, 720, 32.15, vp_);
// Upsampling to odd size.
- CropFrame(video_buffer.get(), width_, height_, 0, 26, 352, 233,
- &cropped_source_frame);
- TestSize(video_frame_, cropped_source_frame, 501, 333, 32.05, vp_);
+ TestSize(video_frame_, *CropFrame(video_buffer, 0, 26, 352, 233),
+ 501, 333, 32.05, vp_);
// Downsample to odd size.
- CropFrame(video_buffer.get(), width_, height_, 0, 34, 352, 219,
- &cropped_source_frame);
- TestSize(video_frame_, cropped_source_frame, 281, 175, 29.3, vp_);
+ TestSize(video_frame_, *CropFrame(video_buffer, 0, 34, 352, 219),
+ 281, 175, 29.3, vp_);
// Stop timer.
const int64_t runtime =
@@ -229,24 +218,30 @@ void PreprocessFrameAndVerify(const VideoFrame& source,
EXPECT_EQ(target_height, (out_frame)->height());
}
-void CropFrame(const uint8_t* source_data,
- int source_width,
- int source_height,
- int offset_x,
- int offset_y,
- int cropped_width,
- int cropped_height,
- VideoFrame* cropped_frame) {
- cropped_frame->CreateEmptyFrame(cropped_width, cropped_height, cropped_width,
- (cropped_width + 1) / 2,
- (cropped_width + 1) / 2);
- EXPECT_EQ(0,
- ConvertToI420(kI420, source_data, offset_x, offset_y, source_width,
- source_height, 0, kVideoRotation_0, cropped_frame));
+rtc::scoped_refptr<VideoFrameBuffer> CropFrame(
+ rtc::scoped_refptr<VideoFrameBuffer> source,
+ int offset_x,
+ int offset_y,
+ int cropped_width,
+ int cropped_height) {
+ offset_x &= ~1;
+ offset_y &= ~1;
+
+ size_t start_y = offset_x + offset_y * source->StrideY();
+ size_t start_u = offset_x / 2 + (offset_y / 2) * source->StrideU();
+ size_t start_v = offset_x / 2 + (offset_y / 2) * source->StrideV();
+
+ return rtc::scoped_refptr<VideoFrameBuffer>(
+ new rtc::RefCountedObject<WrappedI420Buffer>(
+ cropped_width, cropped_height,
+ source->DataY() + start_y, source->StrideY(),
+ source->DataU() + start_u, source->StrideU(),
+ source->DataV() + start_v, source->StrideV(),
+ rtc::KeepRefUntilDone(source)));
}
void TestSize(const VideoFrame& source_frame,
- const VideoFrame& cropped_source_frame,
+ const VideoFrameBuffer& cropped_source,
int target_width,
int target_height,
double expected_psnr,
@@ -263,12 +258,13 @@ void TestSize(const VideoFrame& source_frame,
// Scale |resampled_source_frame| back to the source scale.
VideoFrame resampled_source_frame;
resampled_source_frame.CopyFrame(*out_frame);
- PreprocessFrameAndVerify(resampled_source_frame, cropped_source_frame.width(),
- cropped_source_frame.height(), vpm, out_frame);
+ PreprocessFrameAndVerify(resampled_source_frame, cropped_source.width(),
+ cropped_source.height(), vpm, out_frame);
WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame);
// Compute PSNR against the cropped source frame and check expectation.
- double psnr = I420PSNR(&cropped_source_frame, out_frame);
+ double psnr = I420PSNR(cropped_source,
+ *out_frame->video_frame_buffer().get());
EXPECT_GT(psnr, expected_psnr);
printf(
"PSNR: %f. PSNR is between source of size %d %d, and a modified "

Powered by Google App Engine
This is Rietveld 408576698