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

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

Issue 2448053003: Fix out_frame argument of PreprocessFrameAndVerify. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 16 matching lines...) Expand all
27 27
28 // Define command line flag 'gen_files' (default value: false). 28 // Define command line flag 'gen_files' (default value: false).
29 DEFINE_bool(gen_files, false, "Output files for visual inspection."); 29 DEFINE_bool(gen_files, false, "Output files for visual inspection.");
30 30
31 } // namespace 31 } // namespace
32 32
33 static void PreprocessFrameAndVerify(const VideoFrame& source, 33 static void PreprocessFrameAndVerify(const VideoFrame& source,
34 int target_width, 34 int target_width,
35 int target_height, 35 int target_height,
36 VideoProcessing* vpm, 36 VideoProcessing* vpm,
37 const VideoFrame* out_frame); 37 const VideoFrame** out_frame);
38 static rtc::scoped_refptr<VideoFrameBuffer> CropBuffer( 38 static rtc::scoped_refptr<VideoFrameBuffer> CropBuffer(
39 rtc::scoped_refptr<VideoFrameBuffer> source_buffer, 39 rtc::scoped_refptr<VideoFrameBuffer> source_buffer,
40 int offset_x, 40 int offset_x,
41 int offset_y, 41 int offset_y,
42 int cropped_width, 42 int cropped_width,
43 int cropped_height); 43 int cropped_height);
44 // 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|,
45 // 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
46 // 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
47 // verified under the same conditions. 47 // verified under the same conditions.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 TEST_F(VideoProcessingTest, PreprocessorLogic) { 91 TEST_F(VideoProcessingTest, PreprocessorLogic) {
92 #endif 92 #endif
93 // Disable temporal sampling (frame dropping). 93 // Disable temporal sampling (frame dropping).
94 vp_->EnableTemporalDecimation(false); 94 vp_->EnableTemporalDecimation(false);
95 int resolution = 100; 95 int resolution = 100;
96 EXPECT_EQ(VPM_OK, vp_->SetTargetResolution(resolution, resolution, 15)); 96 EXPECT_EQ(VPM_OK, vp_->SetTargetResolution(resolution, resolution, 15));
97 EXPECT_EQ(VPM_OK, vp_->SetTargetResolution(resolution, resolution, 30)); 97 EXPECT_EQ(VPM_OK, vp_->SetTargetResolution(resolution, resolution, 30));
98 // Disable spatial sampling. 98 // Disable spatial sampling.
99 vp_->SetInputFrameResampleMode(kNoRescaling); 99 vp_->SetInputFrameResampleMode(kNoRescaling);
100 EXPECT_EQ(VPM_OK, vp_->SetTargetResolution(resolution, resolution, 30)); 100 EXPECT_EQ(VPM_OK, vp_->SetTargetResolution(resolution, resolution, 30));
101 VideoFrame* out_frame = NULL; 101 const VideoFrame* out_frame = NULL;
102 // Set rescaling => output frame != NULL. 102 // Set rescaling => output frame != NULL.
103 vp_->SetInputFrameResampleMode(kFastRescaling); 103 vp_->SetInputFrameResampleMode(kFastRescaling);
104 104
105 rtc::scoped_refptr<webrtc::I420Buffer> buffer = 105 rtc::scoped_refptr<webrtc::I420Buffer> buffer =
106 I420Buffer::Create(width_, height_, width_, half_width_, half_width_); 106 I420Buffer::Create(width_, height_, width_, half_width_, half_width_);
107 107
108 // Clear video frame so DrMemory/Valgrind will allow reads of the buffer. 108 // Clear video frame so DrMemory/Valgrind will allow reads of the buffer.
109 buffer->InitializeData(); 109 buffer->InitializeData();
110 VideoFrame video_frame(buffer, 0, 0, webrtc::kVideoRotation_0); 110 VideoFrame video_frame(buffer, 0, 0, webrtc::kVideoRotation_0);
111 111
112 PreprocessFrameAndVerify(video_frame, resolution, resolution, vp_, out_frame); 112 PreprocessFrameAndVerify(video_frame, resolution, resolution, vp_,
113 &out_frame);
113 // No rescaling=> output frame = NULL. 114 // No rescaling=> output frame = NULL.
114 vp_->SetInputFrameResampleMode(kNoRescaling); 115 vp_->SetInputFrameResampleMode(kNoRescaling);
115 EXPECT_TRUE(vp_->PreprocessFrame(video_frame) != nullptr); 116 EXPECT_TRUE(vp_->PreprocessFrame(video_frame) != nullptr);
116 } 117 }
117 118
118 #if defined(WEBRTC_IOS) 119 #if defined(WEBRTC_IOS)
119 TEST_F(VideoProcessingTest, DISABLED_Resampler) { 120 TEST_F(VideoProcessingTest, DISABLED_Resampler) {
120 #else 121 #else
121 TEST_F(VideoProcessingTest, Resampler) { 122 TEST_F(VideoProcessingTest, Resampler) {
122 #endif 123 #endif
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 186
186 printf("\nAverage run time = %d us / frame\n", 187 printf("\nAverage run time = %d us / frame\n",
187 static_cast<int>(total_runtime)); 188 static_cast<int>(total_runtime));
188 printf("Min run time = %d us / frame\n\n", static_cast<int>(min_runtime)); 189 printf("Min run time = %d us / frame\n\n", static_cast<int>(min_runtime));
189 } 190 }
190 191
191 void PreprocessFrameAndVerify(const VideoFrame& source, 192 void PreprocessFrameAndVerify(const VideoFrame& source,
192 int target_width, 193 int target_width,
193 int target_height, 194 int target_height,
194 VideoProcessing* vpm, 195 VideoProcessing* vpm,
195 const VideoFrame* out_frame) { 196 const VideoFrame** out_frame) {
196 ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); 197 ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30));
197 out_frame = vpm->PreprocessFrame(source); 198 *out_frame = vpm->PreprocessFrame(source);
198 EXPECT_TRUE(out_frame != nullptr); 199 EXPECT_TRUE(*out_frame != nullptr);
199 200
200 // If no resizing is needed, expect the original frame. 201 // If no resizing is needed, expect the original frame.
201 if (target_width == source.width() && target_height == source.height()) { 202 if (target_width == source.width() && target_height == source.height()) {
202 EXPECT_EQ(&source, out_frame); 203 EXPECT_EQ(&source, *out_frame);
203 return; 204 return;
204 } 205 }
205 206
206 // Verify the resampled frame. 207 // Verify the resampled frame.
207 EXPECT_TRUE(out_frame != NULL); 208 EXPECT_EQ(source.render_time_ms(), (*out_frame)->render_time_ms());
208 EXPECT_EQ(source.render_time_ms(), (out_frame)->render_time_ms()); 209 EXPECT_EQ(source.timestamp(), (*out_frame)->timestamp());
209 EXPECT_EQ(source.timestamp(), (out_frame)->timestamp()); 210 EXPECT_EQ(target_width, (*out_frame)->width());
210 EXPECT_EQ(target_width, (out_frame)->width()); 211 EXPECT_EQ(target_height, (*out_frame)->height());
211 EXPECT_EQ(target_height, (out_frame)->height());
212 } 212 }
213 213
214 rtc::scoped_refptr<VideoFrameBuffer> CropBuffer( 214 rtc::scoped_refptr<VideoFrameBuffer> CropBuffer(
215 rtc::scoped_refptr<VideoFrameBuffer> source_buffer, 215 rtc::scoped_refptr<VideoFrameBuffer> source_buffer,
216 int offset_x, 216 int offset_x,
217 int offset_y, 217 int offset_y,
218 int cropped_width, 218 int cropped_width,
219 int cropped_height) { 219 int cropped_height) {
220 // Force even. 220 // Force even.
221 offset_x &= ~1; 221 offset_x &= ~1;
(...skipping 11 matching lines...) Expand all
233 source_buffer->StrideV(), rtc::KeepRefUntilDone(source_buffer))); 233 source_buffer->StrideV(), rtc::KeepRefUntilDone(source_buffer)));
234 } 234 }
235 235
236 void TestSize(const VideoFrame& source_frame, 236 void TestSize(const VideoFrame& source_frame,
237 const VideoFrameBuffer& cropped_source, 237 const VideoFrameBuffer& cropped_source,
238 int target_width, 238 int target_width,
239 int target_height, 239 int target_height,
240 double expected_psnr, 240 double expected_psnr,
241 VideoProcessing* vpm) { 241 VideoProcessing* vpm) {
242 // Resample source_frame to out_frame. 242 // Resample source_frame to out_frame.
243 VideoFrame* out_frame = NULL; 243 const VideoFrame* out_frame = NULL;
244 vpm->SetInputFrameResampleMode(kBox); 244 vpm->SetInputFrameResampleMode(kBox);
245 PreprocessFrameAndVerify(source_frame, target_width, target_height, vpm, 245 PreprocessFrameAndVerify(source_frame, target_width, target_height, vpm,
246 out_frame); 246 &out_frame);
247 if (out_frame == NULL) 247 if (out_frame == NULL)
248 return; 248 return;
249 WriteProcessedFrameForVisualInspection(source_frame, *out_frame); 249 WriteProcessedFrameForVisualInspection(source_frame, *out_frame);
250 250
251 // Scale |resampled_source_frame| back to the source scale. 251 // Scale |resampled_source_frame| back to the source scale.
252 VideoFrame resampled_source_frame; 252 VideoFrame resampled_source_frame;
253 resampled_source_frame.ShallowCopy(*out_frame); 253 resampled_source_frame.ShallowCopy(*out_frame);
254 // Compute PSNR against the cropped source frame and check expectation. 254 // Compute PSNR against the cropped source frame and check expectation.
255 PreprocessFrameAndVerify(resampled_source_frame, 255 PreprocessFrameAndVerify(resampled_source_frame,
256 cropped_source.width(), 256 cropped_source.width(),
257 cropped_source.height(), vpm, out_frame); 257 cropped_source.height(), vpm, &out_frame);
258 WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame); 258 WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame);
259 259
260 // Compute PSNR against the cropped source frame and check expectation. 260 // Compute PSNR against the cropped source frame and check expectation.
261 double psnr = 261 double psnr =
262 I420PSNR(cropped_source, *out_frame->video_frame_buffer()); 262 I420PSNR(cropped_source, *out_frame->video_frame_buffer());
263 EXPECT_GT(psnr, expected_psnr); 263 EXPECT_GT(psnr, expected_psnr);
264 printf( 264 printf(
265 "PSNR: %f. PSNR is between source of size %d %d, and a modified " 265 "PSNR: %f. PSNR is between source of size %d %d, and a modified "
266 "source which is scaled down/up to: %d %d, and back to source size \n", 266 "source which is scaled down/up to: %d %d, and back to source size \n",
267 psnr, source_frame.width(), source_frame.height(), target_width, 267 psnr, source_frame.width(), source_frame.height(), target_width,
(...skipping 13 matching lines...) Expand all
281 std::cout << "Watch " << filename.str() << " and verify that it is okay." 281 std::cout << "Watch " << filename.str() << " and verify that it is okay."
282 << std::endl; 282 << std::endl;
283 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); 283 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb");
284 if (PrintVideoFrame(processed, stand_alone_file) < 0) 284 if (PrintVideoFrame(processed, stand_alone_file) < 0)
285 std::cerr << "Failed to write: " << filename.str() << std::endl; 285 std::cerr << "Failed to write: " << filename.str() << std::endl;
286 if (stand_alone_file) 286 if (stand_alone_file)
287 fclose(stand_alone_file); 287 fclose(stand_alone_file);
288 } 288 }
289 289
290 } // namespace webrtc 290 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698