blob: 24d44ca4ad15902660c769da54ed3df30468520b [file] [log] [blame]
jackychenfa0befe2016-04-01 07:46:58 -07001/*
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
19namespace webrtc {
20
jackychenfa0befe2016-04-01 07:46:58 -070021#define DISPLAY 0
22
23const int kNoiseThreshold = 200;
24const int kNoiseThresholdNeon = 70;
25const int kConsecLowVarFrame = 6;
26const int kAverageLumaMin = 20;
27const int kAverageLumaMax = 220;
28const int kBlockSelectionVarMax = kNoiseThreshold << 1;
29
jackychenafaae0d2016-04-12 23:02:55 -070030// TODO(jackychen): To test different sampling strategy.
31// Collect noise data every NOISE_SUBSAMPLE_INTERVAL blocks.
32#define NOISE_SUBSAMPLE_INTERVAL 41
33
jackychenfa0befe2016-04-01 07:46:58 -070034class NoiseEstimation {
35 public:
36 void Init(int width, int height, CpuType cpu_type);
jackychenafaae0d2016-04-12 23:02:55 -070037 // Collect noise data from one qualified block.
jackychenfa0befe2016-04-01 07:46:58 -070038 void GetNoise(int mb_index, uint32_t var, uint32_t luma);
jackychenafaae0d2016-04-12 23:02:55 -070039 // Reset the counter for consecutive low-var blocks.
jackychenfa0befe2016-04-01 07:46:58 -070040 void ResetConsecLowVar(int mb_index);
jackychenafaae0d2016-04-12 23:02:55 -070041 // Update noise level for current frame.
jackychenfa0befe2016-04-01 07:46:58 -070042 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_;
jackychenafaae0d2016-04-12 23:02:55 -070051 int num_noisy_block_;
52 int num_static_block_;
jackychenfa0befe2016-04-01 07:46:58 -070053 CpuType cpu_type_;
54 uint32_t noise_var_;
55 double noise_var_accum_;
jackychenfa0befe2016-04-01 07:46:58 -070056 double percent_static_block_;
jackychenafaae0d2016-04-12 23:02:55 -070057 std::unique_ptr<uint32_t[]> consec_low_var_;
jackychenfa0befe2016-04-01 07:46:58 -070058};
59
60} // namespace webrtc
61
62#endif // WEBRTC_MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_