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