blob: 8e516045ff2b620d12e8bb5b2c450c20a2e64288 [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
kwiberg2c27a062016-04-26 08:37:53 -070014#include <memory>
15
jackychenfa0befe2016-04-01 07:46:58 -070016#include "webrtc/modules/include/module_common_types.h"
17#include "webrtc/modules/video_processing/include/video_processing_defines.h"
18#include "webrtc/modules/video_processing/util/denoiser_filter.h"
19
20namespace webrtc {
21
jackychen8556c482016-04-20 16:04:31 -070022#define DISPLAY 0 // Rectangle diagnostics
23#define DISPLAYNEON 0 // Rectangle diagnostics on NEON
jackychenfa0befe2016-04-01 07:46:58 -070024
25const int kNoiseThreshold = 200;
26const int kNoiseThresholdNeon = 70;
27const int kConsecLowVarFrame = 6;
28const int kAverageLumaMin = 20;
29const int kAverageLumaMax = 220;
30const int kBlockSelectionVarMax = kNoiseThreshold << 1;
31
jackychenafaae0d2016-04-12 23:02:55 -070032// TODO(jackychen): To test different sampling strategy.
33// Collect noise data every NOISE_SUBSAMPLE_INTERVAL blocks.
34#define NOISE_SUBSAMPLE_INTERVAL 41
35
jackychenfa0befe2016-04-01 07:46:58 -070036class NoiseEstimation {
37 public:
38 void Init(int width, int height, CpuType cpu_type);
jackychenafaae0d2016-04-12 23:02:55 -070039 // Collect noise data from one qualified block.
jackychenfa0befe2016-04-01 07:46:58 -070040 void GetNoise(int mb_index, uint32_t var, uint32_t luma);
jackychenafaae0d2016-04-12 23:02:55 -070041 // Reset the counter for consecutive low-var blocks.
jackychenfa0befe2016-04-01 07:46:58 -070042 void ResetConsecLowVar(int mb_index);
jackychenafaae0d2016-04-12 23:02:55 -070043 // Update noise level for current frame.
jackychenfa0befe2016-04-01 07:46:58 -070044 void UpdateNoiseLevel();
45 // 0: low noise, 1: high noise
46 uint8_t GetNoiseLevel();
47
48 private:
49 int width_;
50 int height_;
51 int mb_rows_;
52 int mb_cols_;
jackychenafaae0d2016-04-12 23:02:55 -070053 int num_noisy_block_;
54 int num_static_block_;
jackychenfa0befe2016-04-01 07:46:58 -070055 CpuType cpu_type_;
56 uint32_t noise_var_;
57 double noise_var_accum_;
jackychenfa0befe2016-04-01 07:46:58 -070058 double percent_static_block_;
jackychenafaae0d2016-04-12 23:02:55 -070059 std::unique_ptr<uint32_t[]> consec_low_var_;
jackychenfa0befe2016-04-01 07:46:58 -070060};
61
62} // namespace webrtc
63
64#endif // WEBRTC_MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_