jackychen | 8f9902a | 2015-11-26 02:59:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ |
| 12 | #define MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ |
jackychen | 8f9902a | 2015-11-26 02:59:48 -0800 | [diff] [blame] | 13 | |
kwiberg | e065fcf | 2016-03-02 01:01:11 -0800 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "common_video/include/i420_buffer_pool.h" |
| 17 | #include "modules/video_processing/util/denoiser_filter.h" |
| 18 | #include "modules/video_processing/util/noise_estimation.h" |
| 19 | #include "modules/video_processing/util/skin_detection.h" |
jackychen | 8f9902a | 2015-11-26 02:59:48 -0800 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | class VideoDenoiser { |
| 24 | public: |
jackychen | 67e94fb | 2016-01-11 21:34:07 -0800 | [diff] [blame] | 25 | explicit VideoDenoiser(bool runtime_cpu_detection); |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 26 | |
Magnus Jedvert | 7a721e8 | 2017-06-14 11:28:08 +0200 | [diff] [blame] | 27 | rtc::scoped_refptr<I420BufferInterface> DenoiseFrame( |
| 28 | rtc::scoped_refptr<I420BufferInterface> frame, |
nisse | 18ee17d | 2016-11-07 01:34:59 -0800 | [diff] [blame] | 29 | bool noise_estimation_enabled); |
jackychen | 8f9902a | 2015-11-26 02:59:48 -0800 | [diff] [blame] | 30 | |
| 31 | private: |
Magnus Jedvert | 7a721e8 | 2017-06-14 11:28:08 +0200 | [diff] [blame] | 32 | void DenoiserReset(rtc::scoped_refptr<I420BufferInterface> frame); |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 33 | |
| 34 | // Check the mb position, return 1: close to the frame center (between 1/8 |
| 35 | // and 7/8 of width/height), 3: close to the border (out of 1/16 and 15/16 |
| 36 | // of width/height), 2: in between. |
| 37 | int PositionCheck(int mb_row, int mb_col, int noise_level); |
| 38 | |
| 39 | // To reduce false detection in moving object detection (MOD). |
| 40 | void ReduceFalseDetection(const std::unique_ptr<uint8_t[]>& d_status, |
| 41 | std::unique_ptr<uint8_t[]>* d_status_red, |
| 42 | int noise_level); |
| 43 | |
| 44 | // Return whether a block might cause trailing artifact by checking if one of |
| 45 | // its neighbor blocks is a moving edge block. |
| 46 | bool IsTrailingBlock(const std::unique_ptr<uint8_t[]>& d_status, |
| 47 | int mb_row, |
| 48 | int mb_col); |
| 49 | |
| 50 | // Copy input blocks to dst buffer on moving object blocks (MOB). |
nisse | 18ee17d | 2016-11-07 01:34:59 -0800 | [diff] [blame] | 51 | void CopySrcOnMOB(const uint8_t* y_src, |
| 52 | int stride_src, |
| 53 | uint8_t* y_dst, |
| 54 | int stride_dst); |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 55 | |
jackychen | 6650d6d | 2016-04-25 16:53:59 -0700 | [diff] [blame] | 56 | // Copy luma margin blocks when frame width/height not divisible by 16. |
nisse | 18ee17d | 2016-11-07 01:34:59 -0800 | [diff] [blame] | 57 | void CopyLumaOnMargin(const uint8_t* y_src, |
| 58 | int stride_src, |
| 59 | uint8_t* y_dst, |
| 60 | int stride_dst); |
jackychen | 6650d6d | 2016-04-25 16:53:59 -0700 | [diff] [blame] | 61 | |
jackychen | 8f9902a | 2015-11-26 02:59:48 -0800 | [diff] [blame] | 62 | int width_; |
| 63 | int height_; |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 64 | int mb_rows_; |
| 65 | int mb_cols_; |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 66 | CpuType cpu_type_; |
kwiberg | e065fcf | 2016-03-02 01:01:11 -0800 | [diff] [blame] | 67 | std::unique_ptr<DenoiserFilter> filter_; |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 68 | std::unique_ptr<NoiseEstimation> ne_; |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 69 | // 1 for moving edge block, 0 for static block. |
| 70 | std::unique_ptr<uint8_t[]> moving_edge_; |
| 71 | // 1 for moving object block, 0 for static block. |
| 72 | std::unique_ptr<uint8_t[]> moving_object_; |
| 73 | // x_density_ and y_density_ are used in MOD process. |
jackychen | fa0befe | 2016-04-01 07:46:58 -0700 | [diff] [blame] | 74 | std::unique_ptr<uint8_t[]> x_density_; |
| 75 | std::unique_ptr<uint8_t[]> y_density_; |
jackychen | afaae0d | 2016-04-12 23:02:55 -0700 | [diff] [blame] | 76 | // Save the return values by MbDenoise for each block. |
| 77 | std::unique_ptr<DenoiserDecision[]> mb_filter_decision_; |
nisse | 18ee17d | 2016-11-07 01:34:59 -0800 | [diff] [blame] | 78 | I420BufferPool buffer_pool_; |
Magnus Jedvert | 7a721e8 | 2017-06-14 11:28:08 +0200 | [diff] [blame] | 79 | rtc::scoped_refptr<I420BufferInterface> prev_buffer_; |
jackychen | 8f9902a | 2015-11-26 02:59:48 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } // namespace webrtc |
| 83 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 84 | #endif // MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ |