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 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 height_(288), | 64 height_(288), |
65 size_y_(width_ * height_), | 65 size_y_(width_ * height_), |
66 size_uv_(half_width_ * ((height_ + 1) / 2)), | 66 size_uv_(half_width_ * ((height_ + 1) / 2)), |
67 frame_length_(CalcBufferSize(kI420, width_, height_)) {} | 67 frame_length_(CalcBufferSize(kI420, width_, height_)) {} |
68 | 68 |
69 void VideoProcessingTest::SetUp() { | 69 void VideoProcessingTest::SetUp() { |
70 vp_ = VideoProcessing::Create(); | 70 vp_ = VideoProcessing::Create(); |
71 ASSERT_TRUE(vp_ != NULL); | 71 ASSERT_TRUE(vp_ != NULL); |
72 | 72 |
73 ASSERT_EQ(0, video_frame_.CreateEmptyFrame(width_, height_, width_, | 73 ASSERT_EQ(0, video_frame_.CreateEmptyFrame(width_, height_, width_, |
74 half_width_, half_width_)); | 74 half_width_, half_width_)); |
75 // 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. |
76 memset(video_frame_.buffer(kYPlane), 0, video_frame_.allocated_size(kYPlane)); | 76 memset(video_frame_.buffer(kYPlane), 0, video_frame_.allocated_size(kYPlane)); |
77 memset(video_frame_.buffer(kUPlane), 0, video_frame_.allocated_size(kUPlane)); | 77 memset(video_frame_.buffer(kUPlane), 0, video_frame_.allocated_size(kUPlane)); |
78 memset(video_frame_.buffer(kVPlane), 0, video_frame_.allocated_size(kVPlane)); | 78 memset(video_frame_.buffer(kVPlane), 0, video_frame_.allocated_size(kVPlane)); |
79 const std::string video_file = | 79 const std::string video_file = |
80 webrtc::test::ResourcePath("foreman_cif", "yuv"); | 80 webrtc::test::ResourcePath("foreman_cif", "yuv"); |
81 source_file_ = fopen(video_file.c_str(), "rb"); | 81 source_file_ = fopen(video_file.c_str(), "rb"); |
82 ASSERT_TRUE(source_file_ != NULL) << | 82 ASSERT_TRUE(source_file_ != NULL) |
83 "Cannot read source file: " + video_file + "\n"; | 83 << "Cannot read source file: " + video_file + "\n"; |
84 } | 84 } |
85 | 85 |
86 void VideoProcessingTest::TearDown() { | 86 void VideoProcessingTest::TearDown() { |
87 if (source_file_ != NULL) { | 87 if (source_file_ != NULL) { |
88 ASSERT_EQ(0, fclose(source_file_)); | 88 ASSERT_EQ(0, fclose(source_file_)); |
89 } | 89 } |
90 source_file_ = NULL; | 90 source_file_ = NULL; |
91 delete vp_; | 91 delete vp_; |
92 vp_ = NULL; | 92 vp_ = NULL; |
93 } | 93 } |
94 | 94 |
95 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(HandleNullBuffer)) { | 95 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(HandleNullBuffer)) { |
96 // TODO(mikhal/stefan): Do we need this one? | 96 // TODO(mikhal/stefan): Do we need this one? |
97 VideoProcessing::FrameStats stats; | 97 VideoProcessing::FrameStats stats; |
98 // Video frame with unallocated buffer. | 98 // Video frame with unallocated buffer. |
99 VideoFrame videoFrame; | 99 VideoFrame videoFrame; |
100 | 100 |
101 vp_->GetFrameStats(videoFrame, &stats); | 101 vp_->GetFrameStats(videoFrame, &stats); |
102 EXPECT_EQ(stats.num_pixels, 0u); | 102 EXPECT_EQ(stats.num_pixels, 0u); |
103 | 103 |
104 EXPECT_EQ(-1, vp_->Deflickering(&videoFrame, &stats)); | 104 EXPECT_EQ(-1, vp_->Deflickering(&videoFrame, &stats)); |
105 | 105 |
106 EXPECT_EQ(-3, vp_->BrightnessDetection(videoFrame, stats)); | 106 EXPECT_EQ(-3, vp_->BrightnessDetection(videoFrame, stats)); |
107 } | 107 } |
108 | 108 |
109 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(HandleBadStats)) { | 109 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(HandleBadStats)) { |
110 VideoProcessing::FrameStats stats; | 110 VideoProcessing::FrameStats stats; |
111 vp_->ClearFrameStats(&stats); | 111 vp_->ClearFrameStats(&stats); |
112 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); | 112 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); |
113 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, | 113 ASSERT_EQ(frame_length_, |
114 source_file_)); | 114 fread(video_buffer.get(), 1, frame_length_, source_file_)); |
115 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, | 115 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
116 0, kVideoRotation_0, &video_frame_)); | 116 0, kVideoRotation_0, &video_frame_)); |
117 | 117 |
118 EXPECT_EQ(-1, vp_->Deflickering(&video_frame_, &stats)); | 118 EXPECT_EQ(-1, vp_->Deflickering(&video_frame_, &stats)); |
119 | 119 |
120 EXPECT_EQ(-3, vp_->BrightnessDetection(video_frame_, stats)); | 120 EXPECT_EQ(-3, vp_->BrightnessDetection(video_frame_, stats)); |
121 } | 121 } |
122 | 122 |
123 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(IdenticalResultsAfterReset)) { | 123 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(IdenticalResultsAfterReset)) { |
124 VideoFrame video_frame2; | 124 VideoFrame video_frame2; |
125 VideoProcessing::FrameStats stats; | 125 VideoProcessing::FrameStats stats; |
126 // Only testing non-static functions here. | 126 // Only testing non-static functions here. |
127 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); | 127 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); |
128 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, | 128 ASSERT_EQ(frame_length_, |
129 source_file_)); | 129 fread(video_buffer.get(), 1, frame_length_, source_file_)); |
130 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, | 130 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
131 0, kVideoRotation_0, &video_frame_)); | 131 0, kVideoRotation_0, &video_frame_)); |
132 vp_->GetFrameStats(video_frame_, &stats); | 132 vp_->GetFrameStats(video_frame_, &stats); |
133 EXPECT_GT(stats.num_pixels, 0u); | 133 EXPECT_GT(stats.num_pixels, 0u); |
134 ASSERT_EQ(0, video_frame2.CopyFrame(video_frame_)); | 134 ASSERT_EQ(0, video_frame2.CopyFrame(video_frame_)); |
135 ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats)); | 135 ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats)); |
136 | 136 |
137 // Retrieve frame stats again in case Deflickering() has zeroed them. | 137 // Retrieve frame stats again in case Deflickering() has zeroed them. |
138 vp_->GetFrameStats(video_frame2, &stats); | 138 vp_->GetFrameStats(video_frame2, &stats); |
139 EXPECT_GT(stats.num_pixels, 0u); | 139 EXPECT_GT(stats.num_pixels, 0u); |
140 ASSERT_EQ(0, vp_->Deflickering(&video_frame2, &stats)); | 140 ASSERT_EQ(0, vp_->Deflickering(&video_frame2, &stats)); |
141 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); | 141 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); |
142 | 142 |
143 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, | 143 ASSERT_EQ(frame_length_, |
144 source_file_)); | 144 fread(video_buffer.get(), 1, frame_length_, source_file_)); |
145 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, | 145 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
146 0, kVideoRotation_0, &video_frame_)); | 146 0, kVideoRotation_0, &video_frame_)); |
147 vp_->GetFrameStats(video_frame_, &stats); | 147 vp_->GetFrameStats(video_frame_, &stats); |
148 EXPECT_GT(stats.num_pixels, 0u); | 148 EXPECT_GT(stats.num_pixels, 0u); |
149 video_frame2.CopyFrame(video_frame_); | 149 video_frame2.CopyFrame(video_frame_); |
150 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame_, stats)); | 150 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame_, stats)); |
151 | 151 |
152 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame2, stats)); | 152 ASSERT_EQ(0, vp_->BrightnessDetection(video_frame2, stats)); |
153 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); | 153 EXPECT_TRUE(CompareFrames(video_frame_, video_frame2)); |
154 } | 154 } |
155 | 155 |
156 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(FrameStats)) { | 156 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(FrameStats)) { |
157 VideoProcessing::FrameStats stats; | 157 VideoProcessing::FrameStats stats; |
158 vp_->ClearFrameStats(&stats); | 158 vp_->ClearFrameStats(&stats); |
159 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); | 159 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); |
160 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, | 160 ASSERT_EQ(frame_length_, |
161 source_file_)); | 161 fread(video_buffer.get(), 1, frame_length_, source_file_)); |
162 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, | 162 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
163 0, kVideoRotation_0, &video_frame_)); | 163 0, kVideoRotation_0, &video_frame_)); |
164 | 164 |
165 EXPECT_FALSE(vp_->ValidFrameStats(stats)); | 165 EXPECT_FALSE(vp_->ValidFrameStats(stats)); |
166 vp_->GetFrameStats(video_frame_, &stats); | 166 vp_->GetFrameStats(video_frame_, &stats); |
167 EXPECT_GT(stats.num_pixels, 0u); | 167 EXPECT_GT(stats.num_pixels, 0u); |
168 EXPECT_TRUE(vp_->ValidFrameStats(stats)); | 168 EXPECT_TRUE(vp_->ValidFrameStats(stats)); |
169 | 169 |
170 printf("\nFrameStats\n"); | 170 printf("\nFrameStats\n"); |
171 printf("mean: %u\nnum_pixels: %u\nsubSamplFactor: %u\nsum: %u\n\n", | 171 printf("mean: %u\nnum_pixels: %u\nsubSamplFactor: %u\nsum: %u\n\n", |
(...skipping 25 matching lines...) Expand all Loading... |
197 EXPECT_TRUE(vp_->PreprocessFrame(video_frame_) != nullptr); | 197 EXPECT_TRUE(vp_->PreprocessFrame(video_frame_) != nullptr); |
198 } | 198 } |
199 | 199 |
200 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Resampler)) { | 200 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Resampler)) { |
201 enum { NumRuns = 1 }; | 201 enum { NumRuns = 1 }; |
202 | 202 |
203 int64_t min_runtime = 0; | 203 int64_t min_runtime = 0; |
204 int64_t total_runtime = 0; | 204 int64_t total_runtime = 0; |
205 | 205 |
206 rewind(source_file_); | 206 rewind(source_file_); |
207 ASSERT_TRUE(source_file_ != NULL) << | 207 ASSERT_TRUE(source_file_ != NULL) << "Cannot read input file \n"; |
208 "Cannot read input file \n"; | |
209 | 208 |
210 // CA not needed here | 209 // CA not needed here |
211 vp_->EnableContentAnalysis(false); | 210 vp_->EnableContentAnalysis(false); |
212 // no temporal decimation | 211 // no temporal decimation |
213 vp_->EnableTemporalDecimation(false); | 212 vp_->EnableTemporalDecimation(false); |
214 | 213 |
215 // Reading test frame | 214 // Reading test frame |
216 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); | 215 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); |
217 ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, | 216 ASSERT_EQ(frame_length_, |
218 source_file_)); | 217 fread(video_buffer.get(), 1, frame_length_, source_file_)); |
219 // Using ConvertToI420 to add stride to the image. | 218 // Using ConvertToI420 to add stride to the image. |
220 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, | 219 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
221 0, kVideoRotation_0, &video_frame_)); | 220 0, kVideoRotation_0, &video_frame_)); |
222 // Cropped source frame that will contain the expected visible region. | 221 // Cropped source frame that will contain the expected visible region. |
223 VideoFrame cropped_source_frame; | 222 VideoFrame cropped_source_frame; |
224 cropped_source_frame.CopyFrame(video_frame_); | 223 cropped_source_frame.CopyFrame(video_frame_); |
225 | 224 |
226 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { | 225 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { |
227 // Initiate test timer. | 226 // Initiate test timer. |
228 const TickTime time_start = TickTime::Now(); | 227 const TickTime time_start = TickTime::Now(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // Stop timer. | 273 // Stop timer. |
275 const int64_t runtime = (TickTime::Now() - time_start).Microseconds(); | 274 const int64_t runtime = (TickTime::Now() - time_start).Microseconds(); |
276 if (runtime < min_runtime || run_idx == 0) { | 275 if (runtime < min_runtime || run_idx == 0) { |
277 min_runtime = runtime; | 276 min_runtime = runtime; |
278 } | 277 } |
279 total_runtime += runtime; | 278 total_runtime += runtime; |
280 } | 279 } |
281 | 280 |
282 printf("\nAverage run time = %d us / frame\n", | 281 printf("\nAverage run time = %d us / frame\n", |
283 static_cast<int>(total_runtime)); | 282 static_cast<int>(total_runtime)); |
284 printf("Min run time = %d us / frame\n\n", | 283 printf("Min run time = %d us / frame\n\n", static_cast<int>(min_runtime)); |
285 static_cast<int>(min_runtime)); | |
286 } | 284 } |
287 | 285 |
288 void PreprocessFrameAndVerify(const VideoFrame& source, | 286 void PreprocessFrameAndVerify(const VideoFrame& source, |
289 int target_width, | 287 int target_width, |
290 int target_height, | 288 int target_height, |
291 VideoProcessing* vpm, | 289 VideoProcessing* vpm, |
292 const VideoFrame* out_frame) { | 290 const VideoFrame* out_frame) { |
293 ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); | 291 ASSERT_EQ(VPM_OK, vpm->SetTargetResolution(target_width, target_height, 30)); |
294 out_frame = vpm->PreprocessFrame(source); | 292 out_frame = vpm->PreprocessFrame(source); |
295 EXPECT_TRUE(out_frame != nullptr); | 293 EXPECT_TRUE(out_frame != nullptr); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // Scale |resampled_source_frame| back to the source scale. | 340 // Scale |resampled_source_frame| back to the source scale. |
343 VideoFrame resampled_source_frame; | 341 VideoFrame resampled_source_frame; |
344 resampled_source_frame.CopyFrame(*out_frame); | 342 resampled_source_frame.CopyFrame(*out_frame); |
345 PreprocessFrameAndVerify(resampled_source_frame, cropped_source_frame.width(), | 343 PreprocessFrameAndVerify(resampled_source_frame, cropped_source_frame.width(), |
346 cropped_source_frame.height(), vpm, out_frame); | 344 cropped_source_frame.height(), vpm, out_frame); |
347 WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame); | 345 WriteProcessedFrameForVisualInspection(resampled_source_frame, *out_frame); |
348 | 346 |
349 // Compute PSNR against the cropped source frame and check expectation. | 347 // Compute PSNR against the cropped source frame and check expectation. |
350 double psnr = I420PSNR(&cropped_source_frame, out_frame); | 348 double psnr = I420PSNR(&cropped_source_frame, out_frame); |
351 EXPECT_GT(psnr, expected_psnr); | 349 EXPECT_GT(psnr, expected_psnr); |
352 printf("PSNR: %f. PSNR is between source of size %d %d, and a modified " | 350 printf( |
353 "source which is scaled down/up to: %d %d, and back to source size \n", | 351 "PSNR: %f. PSNR is between source of size %d %d, and a modified " |
354 psnr, source_frame.width(), source_frame.height(), | 352 "source which is scaled down/up to: %d %d, and back to source size \n", |
355 target_width, target_height); | 353 psnr, source_frame.width(), source_frame.height(), target_width, |
| 354 target_height); |
356 } | 355 } |
357 | 356 |
358 bool CompareFrames(const webrtc::VideoFrame& frame1, | 357 bool CompareFrames(const webrtc::VideoFrame& frame1, |
359 const webrtc::VideoFrame& frame2) { | 358 const webrtc::VideoFrame& frame2) { |
360 for (int plane = 0; plane < webrtc::kNumOfPlanes; plane ++) { | 359 for (int plane = 0; plane < webrtc::kNumOfPlanes; plane++) { |
361 webrtc::PlaneType plane_type = static_cast<webrtc::PlaneType>(plane); | 360 webrtc::PlaneType plane_type = static_cast<webrtc::PlaneType>(plane); |
362 int allocated_size1 = frame1.allocated_size(plane_type); | 361 int allocated_size1 = frame1.allocated_size(plane_type); |
363 int allocated_size2 = frame2.allocated_size(plane_type); | 362 int allocated_size2 = frame2.allocated_size(plane_type); |
364 if (allocated_size1 != allocated_size2) | 363 if (allocated_size1 != allocated_size2) |
365 return false; | 364 return false; |
366 const uint8_t* plane_buffer1 = frame1.buffer(plane_type); | 365 const uint8_t* plane_buffer1 = frame1.buffer(plane_type); |
367 const uint8_t* plane_buffer2 = frame2.buffer(plane_type); | 366 const uint8_t* plane_buffer2 = frame2.buffer(plane_type); |
368 if (memcmp(plane_buffer1, plane_buffer2, allocated_size1)) | 367 if (memcmp(plane_buffer1, plane_buffer2, allocated_size1)) |
369 return false; | 368 return false; |
370 } | 369 } |
(...skipping 13 matching lines...) Expand all Loading... |
384 std::cout << "Watch " << filename.str() << " and verify that it is okay." | 383 std::cout << "Watch " << filename.str() << " and verify that it is okay." |
385 << std::endl; | 384 << std::endl; |
386 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); | 385 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); |
387 if (PrintVideoFrame(processed, stand_alone_file) < 0) | 386 if (PrintVideoFrame(processed, stand_alone_file) < 0) |
388 std::cerr << "Failed to write: " << filename.str() << std::endl; | 387 std::cerr << "Failed to write: " << filename.str() << std::endl; |
389 if (stand_alone_file) | 388 if (stand_alone_file) |
390 fclose(stand_alone_file); | 389 fclose(stand_alone_file); |
391 } | 390 } |
392 | 391 |
393 } // namespace webrtc | 392 } // namespace webrtc |
OLD | NEW |