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

Side by Side Diff: webrtc/modules/video_processing/test/video_processing_unittest.cc

Issue 1482913003: Initial VideoProcessing refactoring. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: More lint. Created 5 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/video_processing/test/video_processing_unittest.h" 11 #include "webrtc/modules/video_processing/test/video_processing_unittest.h"
12 12
13 #include <gflags/gflags.h>
14
13 #include <string> 15 #include <string>
14 16
15 #include <gflags/gflags.h>
16 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
17 #include "webrtc/system_wrappers/include/tick_util.h" 18 #include "webrtc/system_wrappers/include/tick_util.h"
18 #include "webrtc/test/testsupport/fileutils.h" 19 #include "webrtc/test/testsupport/fileutils.h"
19 #include "webrtc/test/testsupport/gtest_disable.h" 20 #include "webrtc/test/testsupport/gtest_disable.h"
20 21
21 namespace webrtc { 22 namespace webrtc {
22 23
23 namespace { 24 namespace {
24 25
25 // Define command line flag 'gen_files' (default value: false). 26 // Define command line flag 'gen_files' (default value: false).
26 DEFINE_bool(gen_files, false, "Output files for visual inspection."); 27 DEFINE_bool(gen_files, false, "Output files for visual inspection.");
27 28
28 } // namespace 29 } // namespace
29 30
30 static void PreprocessFrameAndVerify(const VideoFrame& source, 31 static void PreprocessFrameAndVerify(const VideoFrame& source,
31 int target_width, 32 int target_width,
32 int target_height, 33 int target_height,
33 VideoProcessingModule* vpm, 34 VideoProcessing* vpm,
34 VideoFrame** out_frame); 35 const VideoFrame* out_frame);
35 static void CropFrame(const uint8_t* source_data, 36 static void CropFrame(const uint8_t* source_data,
36 int source_width, 37 int source_width,
37 int source_height, 38 int source_height,
38 int offset_x, 39 int offset_x,
39 int offset_y, 40 int offset_y,
40 int cropped_width, 41 int cropped_width,
41 int cropped_height, 42 int cropped_height,
42 VideoFrame* cropped_frame); 43 VideoFrame* cropped_frame);
43 // The |source_data| is cropped and scaled to |target_width| x |target_height|, 44 // The |source_data| is cropped and scaled to |target_width| x |target_height|,
44 // and then scaled back to the expected cropped size. |expected_psnr| is used to 45 // and then scaled back to the expected cropped size. |expected_psnr| is used to
45 // verify basic quality, and is set to be ~0.1/0.05dB lower than actual PSNR 46 // verify basic quality, and is set to be ~0.1/0.05dB lower than actual PSNR
46 // verified under the same conditions. 47 // verified under the same conditions.
47 static void TestSize(const VideoFrame& source_frame, 48 static void TestSize(const VideoFrame& source_frame,
48 const VideoFrame& cropped_source_frame, 49 const VideoFrame& cropped_source_frame,
49 int target_width, 50 int target_width,
50 int target_height, 51 int target_height,
51 double expected_psnr, 52 double expected_psnr,
52 VideoProcessingModule* vpm); 53 VideoProcessing* vpm);
53 static bool CompareFrames(const webrtc::VideoFrame& frame1, 54 static bool CompareFrames(const webrtc::VideoFrame& frame1,
54 const webrtc::VideoFrame& frame2); 55 const webrtc::VideoFrame& frame2);
55 static void WriteProcessedFrameForVisualInspection(const VideoFrame& source, 56 static void WriteProcessedFrameForVisualInspection(const VideoFrame& source,
56 const VideoFrame& processed); 57 const VideoFrame& processed);
57 58
58 VideoProcessingModuleTest::VideoProcessingModuleTest() 59 VideoProcessingTest::VideoProcessingTest()
59 : vpm_(NULL), 60 : vp_(NULL),
60 source_file_(NULL), 61 source_file_(NULL),
61 width_(352), 62 width_(352),
62 half_width_((width_ + 1) / 2), 63 half_width_((width_ + 1) / 2),
63 height_(288), 64 height_(288),
64 size_y_(width_ * height_), 65 size_y_(width_ * height_),
65 size_uv_(half_width_ * ((height_ + 1) / 2)), 66 size_uv_(half_width_ * ((height_ + 1) / 2)),
66 frame_length_(CalcBufferSize(kI420, width_, height_)) {} 67 frame_length_(CalcBufferSize(kI420, width_, height_)) {}
67 68
68 void VideoProcessingModuleTest::SetUp() { 69 void VideoProcessingTest::SetUp() {
69 vpm_ = VideoProcessingModule::Create(); 70 vp_ = VideoProcessing::Create();
70 ASSERT_TRUE(vpm_ != NULL); 71 ASSERT_TRUE(vp_ != NULL);
71 72
72 ASSERT_EQ(0, video_frame_.CreateEmptyFrame(width_, height_, width_, 73 ASSERT_EQ(0, video_frame_.CreateEmptyFrame(width_, height_, width_,
73 half_width_, half_width_)); 74 half_width_, half_width_));
74 // Clear video frame so DrMemory/Valgrind will allow reads of the buffer. 75 // Clear video frame so DrMemory/Valgrind will allow reads of the buffer.
75 memset(video_frame_.buffer(kYPlane), 0, video_frame_.allocated_size(kYPlane)); 76 memset(video_frame_.buffer(kYPlane), 0, video_frame_.allocated_size(kYPlane));
76 memset(video_frame_.buffer(kUPlane), 0, video_frame_.allocated_size(kUPlane)); 77 memset(video_frame_.buffer(kUPlane), 0, video_frame_.allocated_size(kUPlane));
77 memset(video_frame_.buffer(kVPlane), 0, video_frame_.allocated_size(kVPlane)); 78 memset(video_frame_.buffer(kVPlane), 0, video_frame_.allocated_size(kVPlane));
78 const std::string video_file = 79 const std::string video_file =
79 webrtc::test::ResourcePath("foreman_cif", "yuv"); 80 webrtc::test::ResourcePath("foreman_cif", "yuv");
80 source_file_ = fopen(video_file.c_str(),"rb"); 81 source_file_ = fopen(video_file.c_str(), "rb");
pbos-webrtc 2015/11/30 11:51:57 double space, please run git cl format
81 ASSERT_TRUE(source_file_ != NULL) << 82 ASSERT_TRUE(source_file_ != NULL) <<
82 "Cannot read source file: " + video_file + "\n"; 83 "Cannot read source file: " + video_file + "\n";
83 } 84 }
84 85
85 void VideoProcessingModuleTest::TearDown() { 86 void VideoProcessingTest::TearDown() {
86 if (source_file_ != NULL) { 87 if (source_file_ != NULL) {
87 ASSERT_EQ(0, fclose(source_file_)); 88 ASSERT_EQ(0, fclose(source_file_));
88 } 89 }
89 source_file_ = NULL; 90 source_file_ = NULL;
90 91
91 if (vpm_ != NULL) { 92 if (vp_ != NULL) {
pbos-webrtc 2015/11/30 11:51:57 Can you make this a scoped_ptr? Or otherwise alway
mflodman 2015/12/04 15:01:08 Done.
92 VideoProcessingModule::Destroy(vpm_); 93 delete vp_;
93 } 94 }
94 vpm_ = NULL; 95 vp_ = NULL;
95 } 96 }
96 97
97 TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(HandleNullBuffer)) { 98 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(HandleNullBuffer)) {
98 // TODO(mikhal/stefan): Do we need this one? 99 // TODO(mikhal/stefan): Do we need this one?
99 VideoProcessingModule::FrameStats stats; 100 VideoProcessing::FrameStats stats;
100 // Video frame with unallocated buffer. 101 // Video frame with unallocated buffer.
101 VideoFrame videoFrame; 102 VideoFrame videoFrame;
102 103
103 EXPECT_EQ(-3, vpm_->GetFrameStats(&stats, videoFrame)); 104 EXPECT_EQ(-3, vp_->GetFrameStats(videoFrame, &stats));
104 105
105 EXPECT_EQ(-1, vpm_->Deflickering(&videoFrame, &stats)); 106 EXPECT_EQ(-1, vp_->Deflickering(&videoFrame, &stats));
106 107
107 EXPECT_EQ(-3, vpm_->BrightnessDetection(videoFrame, stats)); 108 EXPECT_EQ(-3, vp_->BrightnessDetection(videoFrame, stats));
108 } 109 }
109 110
110 TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(HandleBadStats)) { 111 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(HandleBadStats)) {
111 VideoProcessingModule::FrameStats stats; 112 VideoProcessing::FrameStats stats;
112 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); 113 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
113 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, 114 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
114 source_file_)); 115 source_file_));
115 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, 116 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
116 0, kVideoRotation_0, &video_frame_)); 117 0, kVideoRotation_0, &video_frame_));
117 118
118 EXPECT_EQ(-1, vpm_->Deflickering(&video_frame_, &stats)); 119 EXPECT_EQ(-1, vp_->Deflickering(&video_frame_, &stats));
119 120
120 EXPECT_EQ(-3, vpm_->BrightnessDetection(video_frame_, stats)); 121 EXPECT_EQ(-3, vp_->BrightnessDetection(video_frame_, stats));
121 } 122 }
122 123
123 TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(IdenticalResultsAfterReset)) { 124 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(IdenticalResultsAfterReset)) {
124 VideoFrame video_frame2; 125 VideoFrame video_frame2;
125 VideoProcessingModule::FrameStats stats; 126 VideoProcessing::FrameStats stats;
126 // Only testing non-static functions here. 127 // Only testing non-static functions here.
127 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); 128 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
128 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, 129 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
129 source_file_)); 130 source_file_));
130 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, 131 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
131 0, kVideoRotation_0, &video_frame_)); 132 0, kVideoRotation_0, &video_frame_));
132 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); 133 ASSERT_EQ(0, vp_->GetFrameStats(video_frame_, &stats));
133 ASSERT_EQ(0, video_frame2.CopyFrame(video_frame_)); 134 ASSERT_EQ(0, video_frame2.CopyFrame(video_frame_));
134 ASSERT_EQ(0, vpm_->Deflickering(&video_frame_, &stats)); 135 ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats));
135 vpm_->Reset(); 136
136 // Retrieve frame stats again in case Deflickering() has zeroed them. 137 // Retrieve frame stats again in case Deflickering() has zeroed them.
137 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame2)); 138 ASSERT_EQ(0, vp_->GetFrameStats(video_frame2, &stats));
138 ASSERT_EQ(0, vpm_->Deflickering(&video_frame2, &stats)); 139 ASSERT_EQ(0, vp_->Deflickering(&video_frame2, &stats));
139 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); 140 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2));
140 141
141 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, 142 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
142 source_file_)); 143 source_file_));
143 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, 144 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
144 0, kVideoRotation_0, &video_frame_)); 145 0, kVideoRotation_0, &video_frame_));
145 ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); 146 ASSERT_EQ(0, vp_->GetFrameStats(video_frame_, &stats));
146 video_frame2.CopyFrame(video_frame_); 147 video_frame2.CopyFrame(video_frame_);
147 ASSERT_EQ(0, vpm_->BrightnessDetection(video_frame_, stats)); 148 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame_, stats));
148 vpm_->Reset(); 149
149 ASSERT_EQ(0, vpm_->BrightnessDetection(video_frame2, stats)); 150 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame2, stats));
150 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); 151 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2));
151 } 152 }
152 153
153 TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(FrameStats)) { 154 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(FrameStats)) {
154 VideoProcessingModule::FrameStats stats; 155 VideoProcessing::FrameStats stats;
155 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); 156 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
156 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, 157 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
157 source_file_)); 158 source_file_));
158 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, 159 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
159 0, kVideoRotation_0, &video_frame_)); 160 0, kVideoRotation_0, &video_frame_));
160 161
161 EXPECT_FALSE(vpm_->ValidFrameStats(stats)); 162 EXPECT_FALSE(vp_->ValidFrameStats(stats));
162 EXPECT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_)); 163 EXPECT_EQ(0, vp_->GetFrameStats(video_frame_, &stats));
163 EXPECT_TRUE(vpm_->ValidFrameStats(stats)); 164 EXPECT_TRUE(vp_->ValidFrameStats(stats));
164 165
165 printf("\nFrameStats\n"); 166 printf("\nFrameStats\n");
166 printf("mean: %u\nnum_pixels: %u\nsubSamplWidth: " 167 printf("mean: %u\nnum_pixels: %u\nsubSamplFactor: %u\nsum: %u\n\n",
167 "%u\nsumSamplHeight: %u\nsum: %u\n\n",
168 static_cast<unsigned int>(stats.mean), 168 static_cast<unsigned int>(stats.mean),
169 static_cast<unsigned int>(stats.num_pixels), 169 static_cast<unsigned int>(stats.num_pixels),
170 static_cast<unsigned int>(stats.subSamplHeight), 170 static_cast<unsigned int>(stats.sub_sampling_factor),
171 static_cast<unsigned int>(stats.subSamplWidth),
172 static_cast<unsigned int>(stats.sum)); 171 static_cast<unsigned int>(stats.sum));
173 172
174 vpm_->ClearFrameStats(&stats); 173 vp_->ClearFrameStats(&stats);
175 EXPECT_FALSE(vpm_->ValidFrameStats(stats)); 174 EXPECT_FALSE(vp_->ValidFrameStats(stats));
176 } 175 }
177 176
178 TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(PreprocessorLogic)) { 177 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(PreprocessorLogic)) {
179 // Disable temporal sampling (frame dropping). 178 // Disable temporal sampling (frame dropping).
180 vpm_->EnableTemporalDecimation(false); 179 vp_->EnableTemporalDecimation(false);
181 int resolution = 100; 180 int resolution = 100;
182 EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 15)); 181 EXPECT_EQ(VPM_OK, vp_->SetTargetResolution(resolution, resolution, 15));
183 EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); 182 EXPECT_EQ(VPM_OK, vp_->SetTargetResolution(resolution, resolution, 30));
184 // Disable spatial sampling. 183 // Disable spatial sampling.
185 vpm_->SetInputFrameResampleMode(kNoRescaling); 184 vp_->SetInputFrameResampleMode(kNoRescaling);
186 EXPECT_EQ(VPM_OK, vpm_->SetTargetResolution(resolution, resolution, 30)); 185 EXPECT_EQ(VPM_OK, vp_->SetTargetResolution(resolution, resolution, 30));
187 VideoFrame* out_frame = NULL; 186 VideoFrame* out_frame = NULL;
188 // Set rescaling => output frame != NULL. 187 // Set rescaling => output frame != NULL.
189 vpm_->SetInputFrameResampleMode(kFastRescaling); 188 vp_->SetInputFrameResampleMode(kFastRescaling);
190 PreprocessFrameAndVerify(video_frame_, resolution, resolution, vpm_, 189 PreprocessFrameAndVerify(video_frame_, resolution, resolution, vp_,
191 &out_frame); 190 out_frame);
192 // No rescaling=> output frame = NULL. 191 // No rescaling=> output frame = NULL.
193 vpm_->SetInputFrameResampleMode(kNoRescaling); 192 vp_->SetInputFrameResampleMode(kNoRescaling);
194 EXPECT_EQ(VPM_OK, vpm_->PreprocessFrame(video_frame_, &out_frame)); 193 EXPECT_TRUE(vp_->PreprocessFrame(video_frame_) != nullptr);
195 EXPECT_TRUE(out_frame == NULL);
196 } 194 }
197 195
198 TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(Resampler)) { 196 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Resampler)) {
199 enum { NumRuns = 1 }; 197 enum { NumRuns = 1 };
200 198
201 int64_t min_runtime = 0; 199 int64_t min_runtime = 0;
202 int64_t total_runtime = 0; 200 int64_t total_runtime = 0;
203 201
204 rewind(source_file_); 202 rewind(source_file_);
205 ASSERT_TRUE(source_file_ != NULL) << 203 ASSERT_TRUE(source_file_ != NULL) <<
206 "Cannot read input file \n"; 204 "Cannot read input file \n";
207 205
208 // CA not needed here 206 // CA not needed here
209 vpm_->EnableContentAnalysis(false); 207 vp_->EnableContentAnalysis(false);
210 // no temporal decimation 208 // no temporal decimation
211 vpm_->EnableTemporalDecimation(false); 209 vp_->EnableTemporalDecimation(false);
212 210
213 // Reading test frame 211 // Reading test frame
214 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); 212 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
215 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, 213 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_,
216 source_file_)); 214 source_file_));
217 // Using ConvertToI420 to add stride to the image. 215 // Using ConvertToI420 to add stride to the image.
218 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, 216 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_,
219 0, kVideoRotation_0, &video_frame_)); 217 0, kVideoRotation_0, &video_frame_));
220 // Cropped source frame that will contain the expected visible region. 218 // Cropped source frame that will contain the expected visible region.
221 VideoFrame cropped_source_frame; 219 VideoFrame cropped_source_frame;
222 cropped_source_frame.CopyFrame(video_frame_); 220 cropped_source_frame.CopyFrame(video_frame_);
223 221
224 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { 222 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) {
225 // Initiate test timer. 223 // Initiate test timer.
226 const TickTime time_start = TickTime::Now(); 224 const TickTime time_start = TickTime::Now();
227 225
228 // Init the sourceFrame with a timestamp. 226 // Init the sourceFrame with a timestamp.
229 video_frame_.set_render_time_ms(time_start.MillisecondTimestamp()); 227 video_frame_.set_render_time_ms(time_start.MillisecondTimestamp());
230 video_frame_.set_timestamp(time_start.MillisecondTimestamp() * 90); 228 video_frame_.set_timestamp(time_start.MillisecondTimestamp() * 90);
231 229
232 // Test scaling to different sizes: source is of |width|/|height| = 352/288. 230 // Test scaling to different sizes: source is of |width|/|height| = 352/288.
233 // Pure scaling: 231 // Pure scaling:
234 TestSize(video_frame_, video_frame_, width_ / 4, height_ / 4, 25.2, vpm_); 232 TestSize(video_frame_, video_frame_, width_ / 4, height_ / 4, 25.2, vp_);
235 TestSize(video_frame_, video_frame_, width_ / 2, height_ / 2, 28.1, vpm_); 233 TestSize(video_frame_, video_frame_, width_ / 2, height_ / 2, 28.1, vp_);
236 // No resampling: 234 // No resampling:
237 TestSize(video_frame_, video_frame_, width_, height_, -1, vpm_); 235 TestSize(video_frame_, video_frame_, width_, height_, -1, vp_);
238 TestSize(video_frame_, video_frame_, 2 * width_, 2 * height_, 32.2, vpm_); 236 TestSize(video_frame_, video_frame_, 2 * width_, 2 * height_, 32.2, vp_);
239 237
240 // Scaling and cropping. The cropped source frame is the largest center 238 // Scaling and cropping. The cropped source frame is the largest center
241 // aligned region that can be used from the source while preserving aspect 239 // aligned region that can be used from the source while preserving aspect
242 // ratio. 240 // ratio.
243 CropFrame(video_buffer.get(), width_, height_, 0, 56, 352, 176, 241 CropFrame(video_buffer.get(), width_, height_, 0, 56, 352, 176,
244 &cropped_source_frame); 242 &cropped_source_frame);
245 TestSize(video_frame_, cropped_source_frame, 100, 50, 24.0, vpm_); 243 TestSize(video_frame_, cropped_source_frame, 100, 50, 24.0, vp_);
246 244
247 CropFrame(video_buffer.get(), width_, height_, 0, 30, 352, 225, 245 CropFrame(video_buffer.get(), width_, height_, 0, 30, 352, 225,
248 &cropped_source_frame); 246 &cropped_source_frame);
249 TestSize(video_frame_, cropped_source_frame, 400, 256, 31.3, vpm_); 247 TestSize(video_frame_, cropped_source_frame, 400, 256, 31.3, vp_);
250 248
251 CropFrame(video_buffer.get(), width_, height_, 68, 0, 216, 288, 249 CropFrame(video_buffer.get(), width_, height_, 68, 0, 216, 288,
252 &cropped_source_frame); 250 &cropped_source_frame);
253 TestSize(video_frame_, cropped_source_frame, 480, 640, 32.15, vpm_); 251 TestSize(video_frame_, cropped_source_frame, 480, 640, 32.15, vp_);
254 252
255 CropFrame(video_buffer.get(), width_, height_, 0, 12, 352, 264, 253 CropFrame(video_buffer.get(), width_, height_, 0, 12, 352, 264,
256 &cropped_source_frame); 254 &cropped_source_frame);
257 TestSize(video_frame_, cropped_source_frame, 960, 720, 32.2, vpm_); 255 TestSize(video_frame_, cropped_source_frame, 960, 720, 32.2, vp_);
258 256
259 CropFrame(video_buffer.get(), width_, height_, 0, 44, 352, 198, 257 CropFrame(video_buffer.get(), width_, height_, 0, 44, 352, 198,
260 &cropped_source_frame); 258 &cropped_source_frame);
261 TestSize(video_frame_, cropped_source_frame, 1280, 720, 32.15, vpm_); 259 TestSize(video_frame_, cropped_source_frame, 1280, 720, 32.15, vp_);
262 260
263 // Upsampling to odd size. 261 // Upsampling to odd size.
264 CropFrame(video_buffer.get(), width_, height_, 0, 26, 352, 233, 262 CropFrame(video_buffer.get(), width_, height_, 0, 26, 352, 233,
265 &cropped_source_frame); 263 &cropped_source_frame);
266 TestSize(video_frame_, cropped_source_frame, 501, 333, 32.05, vpm_); 264 TestSize(video_frame_, cropped_source_frame, 501, 333, 32.05, vp_);
267 // Downsample to odd size. 265 // Downsample to odd size.
268 CropFrame(video_buffer.get(), width_, height_, 0, 34, 352, 219, 266 CropFrame(video_buffer.get(), width_, height_, 0, 34, 352, 219,
269 &cropped_source_frame); 267 &cropped_source_frame);
270 TestSize(video_frame_, cropped_source_frame, 281, 175, 29.3, vpm_); 268 TestSize(video_frame_, cropped_source_frame, 281, 175, 29.3, vp_);
271 269
272 // Stop timer. 270 // Stop timer.
273 const int64_t runtime = (TickTime::Now() - time_start).Microseconds(); 271 const int64_t runtime = (TickTime::Now() - time_start).Microseconds();
274 if (runtime < min_runtime || run_idx == 0) { 272 if (runtime < min_runtime || run_idx == 0) {
275 min_runtime = runtime; 273 min_runtime = runtime;
276 } 274 }
277 total_runtime += runtime; 275 total_runtime += runtime;
278 } 276 }
279 277
280 printf("\nAverage run time = %d us / frame\n", 278 printf("\nAverage run time = %d us / frame\n",
281 static_cast<int>(total_runtime)); 279 static_cast<int>(total_runtime));
282 printf("Min run time = %d us / frame\n\n", 280 printf("Min run time = %d us / frame\n\n",
283 static_cast<int>(min_runtime)); 281 static_cast<int>(min_runtime));
284 } 282 }
285 283
286 void PreprocessFrameAndVerify(const VideoFrame& source, 284 void PreprocessFrameAndVerify(const VideoFrame& source,
287 int target_width, 285 int target_width,
288 int target_height, 286 int target_height,
289 VideoProcessingModule* vpm, 287 VideoProcessing* vpm,
290 VideoFrame** out_frame) { 288 const VideoFrame* out_frame) {
291 ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); 289 ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30));
292 ASSERT_EQ(VPM_OK, vpm->PreprocessFrame(source, out_frame)); 290 out_frame = vpm->PreprocessFrame(source);
291 EXPECT_TRUE(out_frame != nullptr);
293 292
294 // If no resizing is needed, expect NULL. 293 // If no resizing is needed, expect the original frame.
295 if (target_width == source.width() && target_height == source.height()) { 294 if (target_width == source.width() && target_height == source.height()) {
296 EXPECT_EQ(NULL, *out_frame); 295 EXPECT_EQ(&source, out_frame);
297 return; 296 return;
298 } 297 }
299 298
300 // Verify the resampled frame. 299 // Verify the resampled frame.
301 EXPECT_TRUE(*out_frame != NULL); 300 EXPECT_TRUE(out_frame != NULL);
302 EXPECT_EQ(source.render_time_ms(), (*out_frame)->render_time_ms()); 301 EXPECT_EQ(source.render_time_ms(), (out_frame)->render_time_ms());
303 EXPECT_EQ(source.timestamp(), (*out_frame)->timestamp()); 302 EXPECT_EQ(source.timestamp(), (out_frame)->timestamp());
304 EXPECT_EQ(target_width, (*out_frame)->width()); 303 EXPECT_EQ(target_width, (out_frame)->width());
305 EXPECT_EQ(target_height, (*out_frame)->height()); 304 EXPECT_EQ(target_height, (out_frame)->height());
306 } 305 }
307 306
308 void CropFrame(const uint8_t* source_data, 307 void CropFrame(const uint8_t* source_data,
309 int source_width, 308 int source_width,
310 int source_height, 309 int source_height,
311 int offset_x, 310 int offset_x,
312 int offset_y, 311 int offset_y,
313 int cropped_width, 312 int cropped_width,
314 int cropped_height, 313 int cropped_height,
315 VideoFrame* cropped_frame) { 314 VideoFrame* cropped_frame) {
316 cropped_frame->CreateEmptyFrame(cropped_width, cropped_height, cropped_width, 315 cropped_frame->CreateEmptyFrame(cropped_width, cropped_height, cropped_width,
317 (cropped_width + 1) / 2, 316 (cropped_width + 1) / 2,
318 (cropped_width + 1) / 2); 317 (cropped_width + 1) / 2);
319 EXPECT_EQ(0, 318 EXPECT_EQ(0,
320 ConvertToI420(kI420, source_data, offset_x, offset_y, source_width, 319 ConvertToI420(kI420, source_data, offset_x, offset_y, source_width,
321 source_height, 0, kVideoRotation_0, cropped_frame)); 320 source_height, 0, kVideoRotation_0, cropped_frame));
322 } 321 }
323 322
324 void TestSize(const VideoFrame& source_frame, 323 void TestSize(const VideoFrame& source_frame,
325 const VideoFrame& cropped_source_frame, 324 const VideoFrame& cropped_source_frame,
326 int target_width, 325 int target_width,
327 int target_height, 326 int target_height,
328 double expected_psnr, 327 double expected_psnr,
329 VideoProcessingModule* vpm) { 328 VideoProcessing* vpm) {
330 // Resample source_frame to out_frame. 329 // Resample source_frame to out_frame.
331 VideoFrame* out_frame = NULL; 330 VideoFrame* out_frame = NULL;
332 vpm->SetInputFrameResampleMode(kBox); 331 vpm->SetInputFrameResampleMode(kBox);
333 PreprocessFrameAndVerify(source_frame, target_width, target_height, vpm, 332 PreprocessFrameAndVerify(source_frame, target_width, target_height, vpm,
334 &out_frame); 333 out_frame);
335 if (out_frame == NULL) 334 if (out_frame == NULL)
336 return; 335 return;
337 WriteProcessedFrameForVisualInspection(source_frame, *out_frame); 336 WriteProcessedFrameForVisualInspection(source_frame, *out_frame);
338 337
339 // Scale |resampled_source_frame| back to the source scale. 338 // Scale |resampled_source_frame| back to the source scale.
340 VideoFrame resampled_source_frame; 339 VideoFrame resampled_source_frame;
341 resampled_source_frame.CopyFrame(*out_frame); 340 resampled_source_frame.CopyFrame(*out_frame);
342 PreprocessFrameAndVerify(resampled_source_frame, cropped_source_frame.width(), 341 PreprocessFrameAndVerify(resampled_source_frame, cropped_source_frame.width(),
343 cropped_source_frame.height(), vpm, &out_frame); 342 cropped_source_frame.height(), vpm, out_frame);
344 WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame); 343 WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame);
345 344
346 // Compute PSNR against the cropped source frame and check expectation. 345 // Compute PSNR against the cropped source frame and check expectation.
347 double psnr = I420PSNR(&cropped_source_frame, out_frame); 346 double psnr = I420PSNR(&cropped_source_frame, out_frame);
348 EXPECT_GT(psnr, expected_psnr); 347 EXPECT_GT(psnr, expected_psnr);
349 printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " 348 printf("PSNR: %f. PSNR is between source of size %d %d, and a modified "
350 "source which is scaled down/up to: %d %d, and back to source size \n", 349 "source which is scaled down/up to: %d %d, and back to source size \n",
351 psnr, source_frame.width(), source_frame.height(), 350 psnr, source_frame.width(), source_frame.height(),
352 target_width, target_height); 351 target_width, target_height);
353 } 352 }
(...skipping 27 matching lines...) Expand all
381 std::cout << "Watch " << filename.str() << " and verify that it is okay." 380 std::cout << "Watch " << filename.str() << " and verify that it is okay."
382 << std::endl; 381 << std::endl;
383 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); 382 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb");
384 if (PrintVideoFrame(processed, stand_alone_file) < 0) 383 if (PrintVideoFrame(processed, stand_alone_file) < 0)
385 std::cerr << "Failed to write: " << filename.str() << std::endl; 384 std::cerr << "Failed to write: " << filename.str() << std::endl;
386 if (stand_alone_file) 385 if (stand_alone_file)
387 fclose(stand_alone_file); 386 fclose(stand_alone_file);
388 } 387 }
389 388
390 } // namespace webrtc 389 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698