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/base/timeutils.h" |
18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
19 #include "webrtc/system_wrappers/include/tick_util.h" | |
20 #include "webrtc/test/testsupport/fileutils.h" | 20 #include "webrtc/test/testsupport/fileutils.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Define command line flag 'gen_files' (default value: false). | 26 // Define command line flag 'gen_files' (default value: false). |
27 DEFINE_bool(gen_files, false, "Output files for visual inspection."); | 27 DEFINE_bool(gen_files, false, "Output files for visual inspection."); |
28 | 28 |
29 } // namespace | 29 } // namespace |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 fread(video_buffer.get(), 1, frame_length_, source_file_)); | 137 fread(video_buffer.get(), 1, frame_length_, source_file_)); |
138 // Using ConvertToI420 to add stride to the image. | 138 // Using ConvertToI420 to add stride to the image. |
139 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, | 139 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
140 0, kVideoRotation_0, &video_frame_)); | 140 0, kVideoRotation_0, &video_frame_)); |
141 // Cropped source frame that will contain the expected visible region. | 141 // Cropped source frame that will contain the expected visible region. |
142 VideoFrame cropped_source_frame; | 142 VideoFrame cropped_source_frame; |
143 cropped_source_frame.CopyFrame(video_frame_); | 143 cropped_source_frame.CopyFrame(video_frame_); |
144 | 144 |
145 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { | 145 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { |
146 // Initiate test timer. | 146 // Initiate test timer. |
147 const TickTime time_start = TickTime::Now(); | 147 const int64_t time_start = rtc::TimeNanos(); |
148 | 148 |
149 // Init the sourceFrame with a timestamp. | 149 // Init the sourceFrame with a timestamp. |
150 video_frame_.set_render_time_ms(time_start.MillisecondTimestamp()); | 150 int64_t time_start_ms = time_start / rtc::kNumNanosecsPerMillisec; |
151 video_frame_.set_timestamp(time_start.MillisecondTimestamp() * 90); | 151 video_frame_.set_render_time_ms(time_start_ms); |
| 152 video_frame_.set_timestamp(time_start_ms * 90); |
152 | 153 |
153 // Test scaling to different sizes: source is of |width|/|height| = 352/288. | 154 // Test scaling to different sizes: source is of |width|/|height| = 352/288. |
154 // Pure scaling: | 155 // Pure scaling: |
155 TestSize(video_frame_, video_frame_, width_ / 4, height_ / 4, 25.2, vp_); | 156 TestSize(video_frame_, video_frame_, width_ / 4, height_ / 4, 25.2, vp_); |
156 TestSize(video_frame_, video_frame_, width_ / 2, height_ / 2, 28.1, vp_); | 157 TestSize(video_frame_, video_frame_, width_ / 2, height_ / 2, 28.1, vp_); |
157 // No resampling: | 158 // No resampling: |
158 TestSize(video_frame_, video_frame_, width_, height_, -1, vp_); | 159 TestSize(video_frame_, video_frame_, width_, height_, -1, vp_); |
159 TestSize(video_frame_, video_frame_, 2 * width_, 2 * height_, 32.2, vp_); | 160 TestSize(video_frame_, video_frame_, 2 * width_, 2 * height_, 32.2, vp_); |
160 | 161 |
161 // Scaling and cropping. The cropped source frame is the largest center | 162 // Scaling and cropping. The cropped source frame is the largest center |
(...skipping 22 matching lines...) Expand all Loading... |
184 // Upsampling to odd size. | 185 // Upsampling to odd size. |
185 CropFrame(video_buffer.get(), width_, height_, 0, 26, 352, 233, | 186 CropFrame(video_buffer.get(), width_, height_, 0, 26, 352, 233, |
186 &cropped_source_frame); | 187 &cropped_source_frame); |
187 TestSize(video_frame_, cropped_source_frame, 501, 333, 32.05, vp_); | 188 TestSize(video_frame_, cropped_source_frame, 501, 333, 32.05, vp_); |
188 // Downsample to odd size. | 189 // Downsample to odd size. |
189 CropFrame(video_buffer.get(), width_, height_, 0, 34, 352, 219, | 190 CropFrame(video_buffer.get(), width_, height_, 0, 34, 352, 219, |
190 &cropped_source_frame); | 191 &cropped_source_frame); |
191 TestSize(video_frame_, cropped_source_frame, 281, 175, 29.3, vp_); | 192 TestSize(video_frame_, cropped_source_frame, 281, 175, 29.3, vp_); |
192 | 193 |
193 // Stop timer. | 194 // Stop timer. |
194 const int64_t runtime = (TickTime::Now() - time_start).Microseconds(); | 195 const int64_t runtime = |
| 196 (rtc::TimeNanos() - time_start) / rtc::kNumNanosecsPerMicrosec; |
195 if (runtime < min_runtime || run_idx == 0) { | 197 if (runtime < min_runtime || run_idx == 0) { |
196 min_runtime = runtime; | 198 min_runtime = runtime; |
197 } | 199 } |
198 total_runtime += runtime; | 200 total_runtime += runtime; |
199 } | 201 } |
200 | 202 |
201 printf("\nAverage run time = %d us / frame\n", | 203 printf("\nAverage run time = %d us / frame\n", |
202 static_cast<int>(total_runtime)); | 204 static_cast<int>(total_runtime)); |
203 printf("Min run time = %d us / frame\n\n", static_cast<int>(min_runtime)); | 205 printf("Min run time = %d us / frame\n\n", static_cast<int>(min_runtime)); |
204 } | 206 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 std::cout << "Watch " << filename.str() << " and verify that it is okay." | 289 std::cout << "Watch " << filename.str() << " and verify that it is okay." |
288 << std::endl; | 290 << std::endl; |
289 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); | 291 FILE* stand_alone_file = fopen(filename.str().c_str(), "wb"); |
290 if (PrintVideoFrame(processed, stand_alone_file) < 0) | 292 if (PrintVideoFrame(processed, stand_alone_file) < 0) |
291 std::cerr << "Failed to write: " << filename.str() << std::endl; | 293 std::cerr << "Failed to write: " << filename.str() << std::endl; |
292 if (stand_alone_file) | 294 if (stand_alone_file) |
293 fclose(stand_alone_file); | 295 fclose(stand_alone_file); |
294 } | 296 } |
295 | 297 |
296 } // namespace webrtc | 298 } // namespace webrtc |
OLD | NEW |