| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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/util/noise_estimation.h" | 11 #include "webrtc/modules/video_processing/util/noise_estimation.h" |
| 12 #if DISPLAY | 12 #if DISPLAYNEON |
| 13 #include <android/log.h> | 13 #include <android/log.h> |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 namespace webrtc { | 16 namespace webrtc { |
| 17 | 17 |
| 18 void NoiseEstimation::Init(int width, int height, CpuType cpu_type) { | 18 void NoiseEstimation::Init(int width, int height, CpuType cpu_type) { |
| 19 int mb_cols = width >> 4; | 19 int mb_cols = width >> 4; |
| 20 int mb_rows = height >> 4; | 20 int mb_rows = height >> 4; |
| 21 consec_low_var_.reset(new uint32_t[mb_cols * mb_rows]()); | 21 consec_low_var_.reset(new uint32_t[mb_cols * mb_rows]()); |
| 22 width_ = width; | 22 width_ = width; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 | 46 |
| 47 void NoiseEstimation::UpdateNoiseLevel() { | 47 void NoiseEstimation::UpdateNoiseLevel() { |
| 48 // TODO(jackychen): Tune a threshold for numb_noisy_block > T to make the | 48 // TODO(jackychen): Tune a threshold for numb_noisy_block > T to make the |
| 49 // condition more reasonable. | 49 // condition more reasonable. |
| 50 // No enough samples implies the motion of the camera or too many moving | 50 // No enough samples implies the motion of the camera or too many moving |
| 51 // objects in the frame. | 51 // objects in the frame. |
| 52 if (num_static_block_ < | 52 if (num_static_block_ < |
| 53 (0.65 * mb_cols_ * mb_rows_ / NOISE_SUBSAMPLE_INTERVAL) || | 53 (0.65 * mb_cols_ * mb_rows_ / NOISE_SUBSAMPLE_INTERVAL) || |
| 54 !num_noisy_block_) { | 54 !num_noisy_block_) { |
| 55 #if DISPLAY | 55 #if DISPLAY |
| 56 if (cpu_type_) { | 56 printf("Not enough samples. %d \n", num_static_block_); |
| 57 printf("Not enough samples. %d \n", num_static_block_); | 57 #elif DISPLAYNEON |
| 58 } else { | 58 __android_log_print(ANDROID_LOG_DEBUG, "DISPLAY", |
| 59 __android_log_print(ANDROID_LOG_DEBUG, "DISPLAY", | 59 "Not enough samples. %d \n", num_static_block_); |
| 60 "Not enough samples. %d \n", num_static_block_); | |
| 61 } | |
| 62 #endif | 60 #endif |
| 63 noise_var_ = 0; | 61 noise_var_ = 0; |
| 64 noise_var_accum_ = 0; | 62 noise_var_accum_ = 0; |
| 65 num_noisy_block_ = 0; | 63 num_noisy_block_ = 0; |
| 66 num_static_block_ = 0; | 64 num_static_block_ = 0; |
| 67 return; | 65 return; |
| 68 } else { | 66 } else { |
| 69 #if DISPLAY | 67 #if DISPLAY |
| 70 if (cpu_type_) { | 68 printf("%d %d fraction = %.3f\n", num_static_block_, |
| 71 printf("%d %d fraction = %.3f\n", num_static_block_, | 69 mb_cols_ * mb_rows_ / NOISE_SUBSAMPLE_INTERVAL, |
| 72 mb_cols_ * mb_rows_ / NOISE_SUBSAMPLE_INTERVAL, | 70 percent_static_block_); |
| 73 percent_static_block_); | 71 #elif DISPLAYNEON |
| 74 } else { | 72 __android_log_print(ANDROID_LOG_DEBUG, "DISPLAY", "%d %d fraction = %.3f\n", |
| 75 __android_log_print(ANDROID_LOG_DEBUG, "DISPLAY", | 73 num_static_block_, |
| 76 "%d %d fraction = %.3f\n", num_static_block_, | 74 mb_cols_ * mb_rows_ / NOISE_SUBSAMPLE_INTERVAL, |
| 77 mb_cols_ * mb_rows_ / NOISE_SUBSAMPLE_INTERVAL, | 75 percent_static_block_); |
| 78 percent_static_block_); | |
| 79 } | |
| 80 #endif | 76 #endif |
| 81 // Normalized by the number of noisy blocks. | 77 // Normalized by the number of noisy blocks. |
| 82 noise_var_ /= num_noisy_block_; | 78 noise_var_ /= num_noisy_block_; |
| 83 // Get the percentage of static blocks. | 79 // Get the percentage of static blocks. |
| 84 percent_static_block_ = static_cast<double>(num_static_block_) / | 80 percent_static_block_ = static_cast<double>(num_static_block_) / |
| 85 (mb_cols_ * mb_rows_ / NOISE_SUBSAMPLE_INTERVAL); | 81 (mb_cols_ * mb_rows_ / NOISE_SUBSAMPLE_INTERVAL); |
| 86 num_noisy_block_ = 0; | 82 num_noisy_block_ = 0; |
| 87 num_static_block_ = 0; | 83 num_static_block_ = 0; |
| 88 } | 84 } |
| 89 // For the first frame just update the value with current noise_var_, | 85 // For the first frame just update the value with current noise_var_, |
| 90 // otherwise, use the averaging window. | 86 // otherwise, use the averaging window. |
| 91 if (noise_var_accum_ == 0) { | 87 if (noise_var_accum_ == 0) { |
| 92 noise_var_accum_ = noise_var_; | 88 noise_var_accum_ = noise_var_; |
| 93 } else { | 89 } else { |
| 94 noise_var_accum_ = (noise_var_accum_ * 15 + noise_var_) / 16; | 90 noise_var_accum_ = (noise_var_accum_ * 15 + noise_var_) / 16; |
| 95 } | 91 } |
| 96 #if DISPLAY | 92 #if DISPLAY |
| 97 if (cpu_type_) { | 93 printf("noise_var_accum_ = %.1f, noise_var_ = %d.\n", noise_var_accum_, |
| 98 printf("noise_var_accum_ = %.1f, noise_var_ = %d.\n", noise_var_accum_, | 94 noise_var_); |
| 99 noise_var_); | 95 #elif DISPLAYNEON |
| 100 } else { | 96 __android_log_print(ANDROID_LOG_DEBUG, "DISPLAY", |
| 101 __android_log_print(ANDROID_LOG_DEBUG, "DISPLAY", | 97 "noise_var_accum_ = %.1f, noise_var_ = %d.\n", |
| 102 "noise_var_accum_ = %.1f, noise_var_ = %d.\n", | 98 noise_var_accum_, noise_var_); |
| 103 noise_var_accum_, noise_var_); | |
| 104 } | |
| 105 #endif | 99 #endif |
| 106 // Reset noise_var_ for the next frame. | 100 // Reset noise_var_ for the next frame. |
| 107 noise_var_ = 0; | 101 noise_var_ = 0; |
| 108 } | 102 } |
| 109 | 103 |
| 110 uint8_t NoiseEstimation::GetNoiseLevel() { | 104 uint8_t NoiseEstimation::GetNoiseLevel() { |
| 111 int noise_thr = cpu_type_ ? kNoiseThreshold : kNoiseThresholdNeon; | 105 int noise_thr = cpu_type_ ? kNoiseThreshold : kNoiseThresholdNeon; |
| 112 UpdateNoiseLevel(); | 106 UpdateNoiseLevel(); |
| 113 if (noise_var_accum_ > noise_thr) { | 107 if (noise_var_accum_ > noise_thr) { |
| 114 return 1; | 108 return 1; |
| 115 } | 109 } |
| 116 return 0; | 110 return 0; |
| 117 } | 111 } |
| 118 | 112 |
| 119 } // namespace webrtc | 113 } // namespace webrtc |
| OLD | NEW |