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