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