OLD | NEW |
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> | 13 #include <gflags/gflags.h> |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
19 #include "webrtc/system_wrappers/include/tick_util.h" | 19 #include "webrtc/system_wrappers/include/tick_util.h" |
| 20 #include "webrtc/test/frame_utils.h" |
20 #include "webrtc/test/testsupport/fileutils.h" | 21 #include "webrtc/test/testsupport/fileutils.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // Define command line flag 'gen_files' (default value: false). | 27 // Define command line flag 'gen_files' (default value: false). |
27 DEFINE_bool(gen_files, false, "Output files for visual inspection."); | 28 DEFINE_bool(gen_files, false, "Output files for visual inspection."); |
28 | 29 |
29 } // namespace | 30 } // namespace |
(...skipping 14 matching lines...) Expand all Loading... |
44 // The |source_data| is cropped and scaled to |target_width| x |target_height|, | 45 // 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 | 46 // 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 | 47 // verify basic quality, and is set to be ~0.1/0.05dB lower than actual PSNR |
47 // verified under the same conditions. | 48 // verified under the same conditions. |
48 static void TestSize(const VideoFrame& source_frame, | 49 static void TestSize(const VideoFrame& source_frame, |
49 const VideoFrame& cropped_source_frame, | 50 const VideoFrame& cropped_source_frame, |
50 int target_width, | 51 int target_width, |
51 int target_height, | 52 int target_height, |
52 double expected_psnr, | 53 double expected_psnr, |
53 VideoProcessing* vpm); | 54 VideoProcessing* vpm); |
54 static bool CompareFrames(const webrtc::VideoFrame& frame1, | |
55 const webrtc::VideoFrame& frame2); | |
56 static void WriteProcessedFrameForVisualInspection(const VideoFrame& source, | 55 static void WriteProcessedFrameForVisualInspection(const VideoFrame& source, |
57 const VideoFrame& processed); | 56 const VideoFrame& processed); |
58 | 57 |
59 VideoProcessingTest::VideoProcessingTest() | 58 VideoProcessingTest::VideoProcessingTest() |
60 : vp_(NULL), | 59 : vp_(NULL), |
61 source_file_(NULL), | 60 source_file_(NULL), |
62 width_(352), | 61 width_(352), |
63 half_width_((width_ + 1) / 2), | 62 half_width_((width_ + 1) / 2), |
64 height_(288), | 63 height_(288), |
65 size_y_(width_ * height_), | 64 size_y_(width_ * height_), |
66 size_uv_(half_width_ * ((height_ + 1) / 2)), | 65 size_uv_(half_width_ * ((height_ + 1) / 2)), |
67 frame_length_(CalcBufferSize(kI420, width_, height_)) {} | 66 frame_length_(CalcBufferSize(kI420, width_, height_)) {} |
68 | 67 |
69 void VideoProcessingTest::SetUp() { | 68 void VideoProcessingTest::SetUp() { |
70 vp_ = VideoProcessing::Create(); | 69 vp_ = VideoProcessing::Create(); |
71 ASSERT_TRUE(vp_ != NULL); | 70 ASSERT_TRUE(vp_ != NULL); |
72 | 71 |
73 video_frame_.CreateEmptyFrame(width_, height_, width_, | 72 video_frame_.CreateEmptyFrame(width_, height_, width_, |
74 half_width_, half_width_); | 73 half_width_, half_width_); |
75 // Clear video frame so DrMemory/Valgrind will allow reads of the buffer. | 74 // Clear video frame so DrMemory/Valgrind will allow reads of the buffer. |
76 memset(video_frame_.buffer(kYPlane), 0, video_frame_.allocated_size(kYPlane)); | 75 memset(video_frame_.video_frame_buffer()->MutableDataY(), 0, |
77 memset(video_frame_.buffer(kUPlane), 0, video_frame_.allocated_size(kUPlane)); | 76 video_frame_.allocated_size(kYPlane)); |
78 memset(video_frame_.buffer(kVPlane), 0, video_frame_.allocated_size(kVPlane)); | 77 memset(video_frame_.video_frame_buffer()->MutableDataU(), 0, |
| 78 video_frame_.allocated_size(kUPlane)); |
| 79 memset(video_frame_.video_frame_buffer()->MutableDataV(), 0, |
| 80 video_frame_.allocated_size(kVPlane)); |
79 const std::string video_file = | 81 const std::string video_file = |
80 webrtc::test::ResourcePath("foreman_cif", "yuv"); | 82 webrtc::test::ResourcePath("foreman_cif", "yuv"); |
81 source_file_ = fopen(video_file.c_str(), "rb"); | 83 source_file_ = fopen(video_file.c_str(), "rb"); |
82 ASSERT_TRUE(source_file_ != NULL) | 84 ASSERT_TRUE(source_file_ != NULL) |
83 << "Cannot read source file: " + video_file + "\n"; | 85 << "Cannot read source file: " + video_file + "\n"; |
84 } | 86 } |
85 | 87 |
86 void VideoProcessingTest::TearDown() { | 88 void VideoProcessingTest::TearDown() { |
87 if (source_file_ != NULL) { | 89 if (source_file_ != NULL) { |
88 ASSERT_EQ(0, fclose(source_file_)); | 90 ASSERT_EQ(0, fclose(source_file_)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 0, kVideoRotation_0, &video_frame_)); | 145 0, kVideoRotation_0, &video_frame_)); |
144 vp_->GetFrameStats(video_frame_, &stats); | 146 vp_->GetFrameStats(video_frame_, &stats); |
145 EXPECT_GT(stats.num_pixels, 0u); | 147 EXPECT_GT(stats.num_pixels, 0u); |
146 video_frame2.CopyFrame(video_frame_); | 148 video_frame2.CopyFrame(video_frame_); |
147 ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats)); | 149 ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats)); |
148 | 150 |
149 // Retrieve frame stats again in case Deflickering() has zeroed them. | 151 // Retrieve frame stats again in case Deflickering() has zeroed them. |
150 vp_->GetFrameStats(video_frame2, &stats); | 152 vp_->GetFrameStats(video_frame2, &stats); |
151 EXPECT_GT(stats.num_pixels, 0u); | 153 EXPECT_GT(stats.num_pixels, 0u); |
152 ASSERT_EQ(0, vp_->Deflickering(&video_frame2, &stats)); | 154 ASSERT_EQ(0, vp_->Deflickering(&video_frame2, &stats)); |
153 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); | 155 EXPECT_TRUE(webrtc::test::FramesEqual(video_frame_, video_frame2)); |
154 | 156 |
155 ASSERT_EQ(frame_length_, | 157 ASSERT_EQ(frame_length_, |
156 fread(video_buffer.get(), 1, frame_length_, source_file_)); | 158 fread(video_buffer.get(), 1, frame_length_, source_file_)); |
157 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_, |
158 0, kVideoRotation_0, &video_frame_)); | 160 0, kVideoRotation_0, &video_frame_)); |
159 vp_->GetFrameStats(video_frame_, &stats); | 161 vp_->GetFrameStats(video_frame_, &stats); |
160 EXPECT_GT(stats.num_pixels, 0u); | 162 EXPECT_GT(stats.num_pixels, 0u); |
161 video_frame2.CopyFrame(video_frame_); | 163 video_frame2.CopyFrame(video_frame_); |
162 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame_, stats)); | 164 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame_, stats)); |
163 | 165 |
164 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame2, stats)); | 166 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame2, stats)); |
165 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); | 167 EXPECT_TRUE(webrtc::test::FramesEqual(video_frame_, video_frame2)); |
166 } | 168 } |
167 | 169 |
168 #if defined(WEBRTC_IOS) | 170 #if defined(WEBRTC_IOS) |
169 TEST_F(VideoProcessingTest, DISABLED_FrameStats) { | 171 TEST_F(VideoProcessingTest, DISABLED_FrameStats) { |
170 #else | 172 #else |
171 TEST_F(VideoProcessingTest, FrameStats) { | 173 TEST_F(VideoProcessingTest, FrameStats) { |
172 #endif | 174 #endif |
173 VideoProcessing::FrameStats stats; | 175 VideoProcessing::FrameStats stats; |
174 vp_->ClearFrameStats(&stats); | 176 vp_->ClearFrameStats(&stats); |
175 std::unique_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); | 177 std::unique_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 // Compute PSNR against the cropped source frame and check expectation. | 373 // Compute PSNR against the cropped source frame and check expectation. |
372 double psnr = I420PSNR(&cropped_source_frame, out_frame); | 374 double psnr = I420PSNR(&cropped_source_frame, out_frame); |
373 EXPECT_GT(psnr, expected_psnr); | 375 EXPECT_GT(psnr, expected_psnr); |
374 printf( | 376 printf( |
375 "PSNR: %f. PSNR is between source of size %d %d, and a modified " | 377 "PSNR: %f. PSNR is between source of size %d %d, and a modified " |
376 "source which is scaled down/up to: %d %d, and back to source size \n", | 378 "source which is scaled down/up to: %d %d, and back to source size \n", |
377 psnr, source_frame.width(), source_frame.height(), target_width, | 379 psnr, source_frame.width(), source_frame.height(), target_width, |
378 target_height); | 380 target_height); |
379 } | 381 } |
380 | 382 |
381 bool CompareFrames(const webrtc::VideoFrame& frame1, | |
382 const webrtc::VideoFrame& frame2) { | |
383 for (int plane = 0; plane < webrtc::kNumOfPlanes; plane++) { | |
384 webrtc::PlaneType plane_type = static_cast<webrtc::PlaneType>(plane); | |
385 int allocated_size1 = frame1.allocated_size(plane_type); | |
386 int allocated_size2 = frame2.allocated_size(plane_type); | |
387 if (allocated_size1 != allocated_size2) | |
388 return false; | |
389 const uint8_t* plane_buffer1 = frame1.buffer(plane_type); | |
390 const uint8_t* plane_buffer2 = frame2.buffer(plane_type); | |
391 if (memcmp(plane_buffer1, plane_buffer2, allocated_size1)) | |
392 return false; | |
393 } | |
394 return true; | |
395 } | |
396 | |
397 void WriteProcessedFrameForVisualInspection(const VideoFrame& source, | 383 void WriteProcessedFrameForVisualInspection(const VideoFrame& source, |
398 const VideoFrame& processed) { | 384 const VideoFrame& processed) { |
399 // Skip if writing to files is not enabled. | 385 // Skip if writing to files is not enabled. |
400 if (!FLAGS_gen_files) | 386 if (!FLAGS_gen_files) |
401 return; | 387 return; |
402 // Write the processed frame to file for visual inspection. | 388 // Write the processed frame to file for visual inspection. |
403 std::ostringstream filename; | 389 std::ostringstream filename; |
404 filename << webrtc::test::OutputPath() << "Resampler_from_" << source.width() | 390 filename << webrtc::test::OutputPath() << "Resampler_from_" << source.width() |
405 << "x" << source.height() << "_to_" << processed.width() << "x" | 391 << "x" << source.height() << "_to_" << processed.width() << "x" |
406 << processed.height() << "_30Hz_P420.yuv"; | 392 << processed.height() << "_30Hz_P420.yuv"; |
407 std::cout << "Watch " << filename.str() << " and verify that it is okay." | 393 std::cout << "Watch " << filename.str() << " and verify that it is okay." |
408 << std::endl; | 394 << std::endl; |
409 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); | 395 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); |
410 if (PrintVideoFrame(processed, stand_alone_file) < 0) | 396 if (PrintVideoFrame(processed, stand_alone_file) < 0) |
411 std::cerr << "Failed to write: " << filename.str() << std::endl; | 397 std::cerr << "Failed to write: " << filename.str() << std::endl; |
412 if (stand_alone_file) | 398 if (stand_alone_file) |
413 fclose(stand_alone_file); | 399 fclose(stand_alone_file); |
414 } | 400 } |
415 | 401 |
416 } // namespace webrtc | 402 } // namespace webrtc |
OLD | NEW |