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