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 <stdio.h> | 11 #include <stdio.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 | 13 |
14 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 14 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
15 #include "webrtc/modules/video_processing/include/video_processing.h" | 15 #include "webrtc/modules/video_processing/include/video_processing.h" |
16 #include "webrtc/modules/video_processing/test/video_processing_unittest.h" | 16 #include "webrtc/modules/video_processing/test/video_processing_unittest.h" |
17 #include "webrtc/system_wrappers/include/tick_util.h" | 17 #include "webrtc/system_wrappers/include/tick_util.h" |
18 #include "webrtc/test/testsupport/fileutils.h" | 18 #include "webrtc/test/testsupport/fileutils.h" |
19 #include "webrtc/test/testsupport/gtest_disable.h" | 19 #include "webrtc/test/testsupport/gtest_disable.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 | 22 |
23 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Deflickering)) { | 23 TEST_F(VideoProcessingTest, DISABLED_ON_IOS(Deflickering)) { |
24 enum { NumRuns = 30 }; | 24 enum { NumRuns = 30 }; |
25 uint32_t frameNum = 0; | 25 uint32_t frameNum = 0; |
26 const uint32_t frame_rate = 15; | 26 const uint32_t frame_rate = 15; |
27 | 27 |
28 int64_t min_runtime = 0; | 28 int64_t min_runtime = 0; |
29 int64_t avg_runtime = 0; | 29 int64_t avg_runtime = 0; |
30 | 30 |
31 // Close automatically opened Foreman. | 31 // Close automatically opened Foreman. |
32 fclose(source_file_); | 32 fclose(source_file_); |
33 const std::string input_file = | 33 const std::string input_file = |
34 webrtc::test::ResourcePath("deflicker_before_cif_short", "yuv"); | 34 webrtc::test::ResourcePath("deflicker_before_cif_short", "yuv"); |
35 source_file_ = fopen(input_file.c_str(), "rb"); | 35 source_file_ = fopen(input_file.c_str(), "rb"); |
36 ASSERT_TRUE(source_file_ != NULL) << | 36 ASSERT_TRUE(source_file_ != NULL) << "Cannot read input file: " << input_file |
37 "Cannot read input file: " << input_file << "\n"; | 37 << "\n"; |
38 | 38 |
39 const std::string output_file = | 39 const std::string output_file = |
40 webrtc::test::OutputPath() + "deflicker_output_cif_short.yuv"; | 40 webrtc::test::OutputPath() + "deflicker_output_cif_short.yuv"; |
41 FILE* deflickerFile = fopen(output_file.c_str(), "wb"); | 41 FILE* deflickerFile = fopen(output_file.c_str(), "wb"); |
42 ASSERT_TRUE(deflickerFile != NULL) << | 42 ASSERT_TRUE(deflickerFile != NULL) |
43 "Could not open output file: " << output_file << "\n"; | 43 << "Could not open output file: " << output_file << "\n"; |
44 | 44 |
45 printf("\nRun time [us / frame]:\n"); | 45 printf("\nRun time [us / frame]:\n"); |
46 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); | 46 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); |
47 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { | 47 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { |
48 TickTime t0; | 48 TickTime t0; |
49 TickTime t1; | 49 TickTime t1; |
50 TickInterval acc_ticks; | 50 TickInterval acc_ticks; |
51 uint32_t timeStamp = 1; | 51 uint32_t timeStamp = 1; |
52 | 52 |
53 frameNum = 0; | 53 frameNum = 0; |
54 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == | 54 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == |
55 frame_length_) { | 55 frame_length_) { |
56 frameNum++; | 56 frameNum++; |
57 EXPECT_EQ( | 57 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, |
58 0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, | |
59 height_, 0, kVideoRotation_0, &video_frame_)); | 58 height_, 0, kVideoRotation_0, &video_frame_)); |
60 video_frame_.set_timestamp(timeStamp); | 59 video_frame_.set_timestamp(timeStamp); |
61 | 60 |
62 t0 = TickTime::Now(); | 61 t0 = TickTime::Now(); |
63 VideoProcessing::FrameStats stats; | 62 VideoProcessing::FrameStats stats; |
64 vp_->GetFrameStats(video_frame_, &stats); | 63 vp_->GetFrameStats(video_frame_, &stats); |
65 EXPECT_GT(stats.num_pixels, 0u); | 64 EXPECT_GT(stats.num_pixels, 0u); |
66 ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats)); | 65 ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats)); |
67 t1 = TickTime::Now(); | 66 t1 = TickTime::Now(); |
68 acc_ticks += (t1 - t0); | 67 acc_ticks += (t1 - t0); |
69 | 68 |
70 if (run_idx == 0) { | 69 if (run_idx == 0) { |
71 if (PrintVideoFrame(video_frame_, deflickerFile) < 0) { | 70 if (PrintVideoFrame(video_frame_, deflickerFile) < 0) { |
72 return; | 71 return; |
73 } | |
74 } | |
75 timeStamp += (90000 / frame_rate); | |
76 } | 72 } |
77 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; | 73 } |
| 74 timeStamp += (90000 / frame_rate); |
| 75 } |
| 76 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; |
78 | 77 |
79 printf("%u\n", static_cast<int>(acc_ticks.Microseconds() / frameNum)); | 78 printf("%u\n", static_cast<int>(acc_ticks.Microseconds() / frameNum)); |
80 if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) { | 79 if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) { |
81 min_runtime = acc_ticks.Microseconds(); | 80 min_runtime = acc_ticks.Microseconds(); |
82 } | 81 } |
83 avg_runtime += acc_ticks.Microseconds(); | 82 avg_runtime += acc_ticks.Microseconds(); |
84 | 83 |
85 rewind(source_file_); | 84 rewind(source_file_); |
86 } | 85 } |
87 ASSERT_EQ(0, fclose(deflickerFile)); | 86 ASSERT_EQ(0, fclose(deflickerFile)); |
88 // TODO(kjellander): Add verification of deflicker output file. | 87 // TODO(kjellander): Add verification of deflicker output file. |
89 | 88 |
90 printf("\nAverage run time = %d us / frame\n", | 89 printf("\nAverage run time = %d us / frame\n", |
91 static_cast<int>(avg_runtime / frameNum / NumRuns)); | 90 static_cast<int>(avg_runtime / frameNum / NumRuns)); |
92 printf("Min run time = %d us / frame\n\n", | 91 printf("Min run time = %d us / frame\n\n", |
93 static_cast<int>(min_runtime / frameNum)); | 92 static_cast<int>(min_runtime / frameNum)); |
94 } | 93 } |
95 | 94 |
96 } // namespace webrtc | 95 } // namespace webrtc |
OLD | NEW |