blob: fa5b5225482bca40e7f4529845209152a4bc5998 [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
kwiberg84be5112016-04-27 01:19:58 -070014#include <memory>
15
terelius52d4e6b2016-04-26 09:31:59 -070016#include "webrtc/base/scoped_ptr.h"
jackychenfa0befe2016-04-01 07:46:58 -070017#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
21namespace webrtc {
22
jackychen8556c482016-04-20 16:04:31 -070023#define DISPLAY 0 // Rectangle diagnostics
24#define DISPLAYNEON 0 // Rectangle diagnostics on NEON
jackychenfa0befe2016-04-01 07:46:58 -070025
26const int kNoiseThreshold = 200;
27const int kNoiseThresholdNeon = 70;
28const int kConsecLowVarFrame = 6;
29const int kAverageLumaMin = 20;
30const int kAverageLumaMax = 220;
31const int kBlockSelectionVarMax = kNoiseThreshold << 1;
32
jackychenafaae0d2016-04-12 23:02:55 -070033// TODO(jackychen): To test different sampling strategy.
34// Collect noise data every NOISE_SUBSAMPLE_INTERVAL blocks.
35#define NOISE_SUBSAMPLE_INTERVAL 41
36
jackychenfa0befe2016-04-01 07:46:58 -070037class NoiseEstimation {
38 public:
39 void Init(int width, int height, CpuType cpu_type);
jackychenafaae0d2016-04-12 23:02:55 -070040 // Collect noise data from one qualified block.
jackychenfa0befe2016-04-01 07:46:58 -070041 void GetNoise(int mb_index, uint32_t var, uint32_t luma);
jackychenafaae0d2016-04-12 23:02:55 -070042 // Reset the counter for consecutive low-var blocks.
jackychenfa0befe2016-04-01 07:46:58 -070043 void ResetConsecLowVar(int mb_index);
jackychenafaae0d2016-04-12 23:02:55 -070044 // Update noise level for current frame.
jackychenfa0befe2016-04-01 07:46:58 -070045 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_;
jackychenafaae0d2016-04-12 23:02:55 -070054 int num_noisy_block_;
55 int num_static_block_;
jackychenfa0befe2016-04-01 07:46:58 -070056 CpuType cpu_type_;
57 uint32_t noise_var_;
58 double noise_var_accum_;
jackychenfa0befe2016-04-01 07:46:58 -070059 double percent_static_block_;
jackychenafaae0d2016-04-12 23:02:55 -070060 std::unique_ptr<uint32_t[]> consec_low_var_;
jackychenfa0befe2016-04-01 07:46:58 -070061};
62
63} // namespace webrtc
64
65#endif // WEBRTC_MODULES_VIDEO_PROCESSING_UTIL_NOISE_ESTIMATION_H_