1 /* 2 * Copyright (c) 2016 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 #ifndef MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_ 12 #define MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_ 13 14 #include <cstdint> 15 #include <memory> 16 17 #include "modules/video_processing/util/denoiser_filter.h" 18 19 namespace webrtc { 20 21 #define DISPLAY 0 // Rectangle diagnostics 22 #define DISPLAYNEON 0 // Rectangle diagnostics on NEON 23 24 const int kNoiseThreshold = 150; 25 const int kNoiseThresholdNeon = 70; 26 const int kConsecLowVarFrame = 6; 27 const int kAverageLumaMin = 20; 28 const int kAverageLumaMax = 220; 29 const int kBlockSelectionVarMax = kNoiseThreshold << 1; 30 31 // TODO(jackychen): To test different sampling strategy. 32 // Collect noise data every NOISE_SUBSAMPLE_INTERVAL blocks. 33 #define NOISE_SUBSAMPLE_INTERVAL 41 34 35 class NoiseEstimation { 36 public: 37 void Init(int width, int height, CpuType cpu_type); 38 // Collect noise data from one qualified block. 39 void GetNoise(int mb_index, uint32_t var, uint32_t luma); 40 // Reset the counter for consecutive low-var blocks. 41 void ResetConsecLowVar(int mb_index); 42 // Update noise level for current frame. 43 void UpdateNoiseLevel(); 44 // 0: low noise, 1: high noise 45 uint8_t GetNoiseLevel(); 46 47 private: 48 int width_; 49 int height_; 50 int mb_rows_; 51 int mb_cols_; 52 int num_noisy_block_; 53 int num_static_block_; 54 CpuType cpu_type_; 55 uint32_t noise_var_; 56 double noise_var_accum_; 57 double percent_static_block_; 58 std::unique_ptr<uint32_t[]> consec_low_var_; 59 }; 60 61 } // namespace webrtc 62 63 #endif // MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_ 64