1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 14 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 15 #include "webrtc/modules/video_processing/main/interface/video_processing.h" 16 #include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h" 17 #include "webrtc/system_wrappers/interface/tick_util.h" 18 #include "webrtc/test/testsupport/fileutils.h" 19 #include "webrtc/test/testsupport/gtest_disable.h" 20 21 namespace webrtc { 22 23 TEST_F(VideoProcessingModuleTest, DISABLED_ON_ANDROID(Denoising)) 24 { 25 enum { NumRuns = 10 }; 26 uint32_t frameNum = 0; 27 28 int64_t min_runtime = 0; 29 int64_t avg_runtime = 0; 30 31 const std::string denoise_filename = 32 webrtc::test::OutputPath() + "denoise_testfile.yuv"; 33 FILE* denoiseFile = fopen(denoise_filename.c_str(), "wb"); 34 ASSERT_TRUE(denoiseFile != NULL) << 35 "Could not open output file: " << denoise_filename << "\n"; 36 37 const std::string noise_filename = 38 webrtc::test::OutputPath() + "noise_testfile.yuv"; 39 FILE* noiseFile = fopen(noise_filename.c_str(), "wb"); 40 ASSERT_TRUE(noiseFile != NULL) << 41 "Could not open noisy file: " << noise_filename << "\n"; 42 43 printf("\nRun time [us / frame]:\n"); 44 for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) 45 { 46 TickTime t0; 47 TickTime t1; 48 TickInterval acc_ticks; 49 int32_t modifiedPixels = 0; 50 51 frameNum = 0; 52 scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); 53 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == 54 frame_length_) 55 { 56 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, 57 width_, height_, 58 0, kRotateNone, &video_frame_)); 59 frameNum++; 60 uint8_t* sourceBuffer = video_frame_.buffer(kYPlane); 61 62 // Add noise to a part in video stream 63 // Random noise 64 // TODO: investigate the effectiveness of this test. 65 66 for (int ir = 0; ir < height_; ir++) 67 { 68 uint32_t ik = ir * width_; 69 for (int ic = 0; ic < width_; ic++) 70 { 71 uint8_t r = rand() % 16; 72 r -= 8; 73 if (ir < height_ / 4) 74 r = 0; 75 if (ir >= 3 * height_ / 4) 76 r = 0; 77 if (ic < width_ / 4) 78 r = 0; 79 if (ic >= 3 * width_ / 4) 80 r = 0; 81 82 /*uint8_t pixelValue = 0; 83 if (ir >= height_ / 2) 84 { // Region 3 or 4 85 pixelValue = 170; 86 } 87 if (ic >= width_ / 2) 88 { // Region 2 or 4 89 pixelValue += 85; 90 } 91 pixelValue += r; 92 sourceBuffer[ik + ic] = pixelValue; 93 */ 94 sourceBuffer[ik + ic] += r; 95 } 96 } 97 98 if (run_idx == 0) 99 { 100 if (PrintI420VideoFrame(video_frame_, noiseFile) < 0) { 101 return; 102 } 103 } 104 105 t0 = TickTime::Now(); 106 ASSERT_GE(modifiedPixels = vpm_->Denoising(&video_frame_), 0); 107 t1 = TickTime::Now(); 108 acc_ticks += (t1 - t0); 109 110 if (run_idx == 0) 111 { 112 if (PrintI420VideoFrame(video_frame_, noiseFile) < 0) { 113 return; 114 } 115 } 116 } 117 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; 118 119 printf("%u\n", static_cast<int>(acc_ticks.Microseconds() / frameNum)); 120 if (acc_ticks.Microseconds() < min_runtime || run_idx == 0) 121 { 122 min_runtime = acc_ticks.Microseconds(); 123 } 124 avg_runtime += acc_ticks.Microseconds(); 125 126 rewind(source_file_); 127 } 128 ASSERT_EQ(0, fclose(denoiseFile)); 129 ASSERT_EQ(0, fclose(noiseFile)); 130 printf("\nAverage run time = %d us / frame\n", 131 static_cast<int>(avg_runtime / frameNum / NumRuns)); 132 printf("Min run time = %d us / frame\n\n", 133 static_cast<int>(min_runtime / frameNum)); 134 } 135 136 } // namespace webrtc 137