| 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 <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "webrtc/base/timeutils.h" |
| 16 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 17 #include "webrtc/modules/video_processing/include/video_processing.h" | 18 #include "webrtc/modules/video_processing/include/video_processing.h" |
| 18 #include "webrtc/modules/video_processing/test/video_processing_unittest.h" | 19 #include "webrtc/modules/video_processing/test/video_processing_unittest.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 #if defined(WEBRTC_IOS) | 24 #if defined(WEBRTC_IOS) |
| 25 TEST_F(VideoProcessingTest, DISABLED_Deflickering) { | 25 TEST_F(VideoProcessingTest, DISABLED_Deflickering) { |
| 26 #else | 26 #else |
| 27 TEST_F(VideoProcessingTest, Deflickering) { | 27 TEST_F(VideoProcessingTest, Deflickering) { |
| 28 #endif | 28 #endif |
| 29 enum { NumRuns = 30 }; | 29 enum { NumRuns = 30 }; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 43 | 43 |
| 44 const std::string output_file = | 44 const std::string output_file = |
| 45 webrtc::test::OutputPath() + "deflicker_output_cif_short.yuv"; | 45 webrtc::test::OutputPath() + "deflicker_output_cif_short.yuv"; |
| 46 FILE* deflickerFile = fopen(output_file.c_str(), "wb"); | 46 FILE* deflickerFile = fopen(output_file.c_str(), "wb"); |
| 47 ASSERT_TRUE(deflickerFile != NULL) | 47 ASSERT_TRUE(deflickerFile != NULL) |
| 48 << "Could not open output file: " << output_file << "\n"; | 48 << "Could not open output file: " << output_file << "\n"; |
| 49 | 49 |
| 50 printf("\nRun time [us / frame]:\n"); | 50 printf("\nRun time [us / frame]:\n"); |
| 51 std::unique_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); | 51 std::unique_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); |
| 52 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { | 52 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { |
| 53 TickTime t0; | 53 int64_t t0; |
| 54 TickTime t1; | 54 int64_t t1; |
| 55 TickInterval acc_ticks; | 55 int64_t acc_ticks = 0; |
| 56 uint32_t timeStamp = 1; | 56 uint32_t timeStamp = 1; |
| 57 | 57 |
| 58 frameNum = 0; | 58 frameNum = 0; |
| 59 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == | 59 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == |
| 60 frame_length_) { | 60 frame_length_) { |
| 61 frameNum++; | 61 frameNum++; |
| 62 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, | 62 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, |
| 63 height_, 0, kVideoRotation_0, &video_frame_)); | 63 height_, 0, kVideoRotation_0, &video_frame_)); |
| 64 video_frame_.set_timestamp(timeStamp); | 64 video_frame_.set_timestamp(timeStamp); |
| 65 | 65 |
| 66 t0 = TickTime::Now(); | 66 t0 = rtc::TimeNanos(); |
| 67 VideoProcessing::FrameStats stats; | 67 VideoProcessing::FrameStats stats; |
| 68 vp_->GetFrameStats(video_frame_, &stats); | 68 vp_->GetFrameStats(video_frame_, &stats); |
| 69 EXPECT_GT(stats.num_pixels, 0u); | 69 EXPECT_GT(stats.num_pixels, 0u); |
| 70 ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats)); | 70 ASSERT_EQ(0, vp_->Deflickering(&video_frame_, &stats)); |
| 71 t1 = TickTime::Now(); | 71 t1 = rtc::TimeNanos(); |
| 72 acc_ticks += (t1 - t0); | 72 acc_ticks += (t1 - t0); |
| 73 | 73 |
| 74 if (run_idx == 0) { | 74 if (run_idx == 0) { |
| 75 if (PrintVideoFrame(video_frame_, deflickerFile) < 0) { | 75 if (PrintVideoFrame(video_frame_, deflickerFile) < 0) { |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 timeStamp += (90000 / frame_rate); | 79 timeStamp += (90000 / frame_rate); |
| 80 } | 80 } |
| 81 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; | 81 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; |
| 82 | 82 |
| 83 printf("%u\n", static_cast<int>(acc_ticks.Microseconds() / frameNum)); | 83 int64_t acc_us = acc_ticks / rtc::kNumNanosecsPerMicrosec; |
| 84 if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) { | 84 printf("%u\n", static_cast<int>( |
| 85 min_runtime = acc_ticks.Microseconds(); | 85 acc_us / frameNum)); |
| 86 if (acc_us < min_runtime || run_idx == 0) { |
| 87 min_runtime = acc_us; |
| 86 } | 88 } |
| 87 avg_runtime += acc_ticks.Microseconds(); | 89 avg_runtime += acc_us; |
| 88 | 90 |
| 89 rewind(source_file_); | 91 rewind(source_file_); |
| 90 } | 92 } |
| 91 ASSERT_EQ(0, fclose(deflickerFile)); | 93 ASSERT_EQ(0, fclose(deflickerFile)); |
| 92 // TODO(kjellander): Add verification of deflicker output file. | 94 // TODO(kjellander): Add verification of deflicker output file. |
| 93 | 95 |
| 94 printf("\nAverage run time = %d us / frame\n", | 96 printf("\nAverage run time = %d us / frame\n", |
| 95 static_cast<int>(avg_runtime / frameNum / NumRuns)); | 97 static_cast<int>(avg_runtime / frameNum / NumRuns)); |
| 96 printf("Min run time = %d us / frame\n\n", | 98 printf("Min run time = %d us / frame\n\n", |
| 97 static_cast<int>(min_runtime / frameNum)); | 99 static_cast<int>(min_runtime / frameNum)); |
| 98 } | 100 } |
| 99 | 101 |
| 100 } // namespace webrtc | 102 } // namespace webrtc |
| OLD | NEW |