| 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 MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ |
| 12 | #define MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ |
| 13 |
| 14 | #include <memory> |
| 15 |
| 16 | #include "api/scoped_refptr.h" |
| 17 | #include "api/video/video_frame_buffer.h" |
| 18 | #include "common_video/include/i420_buffer_pool.h" |
| 19 | #include "modules/video_processing/util/denoiser_filter.h" |
| 20 | #include "modules/video_processing/util/noise_estimation.h" |
| 21 | #include "modules/video_processing/util/skin_detection.h" |
| 22 |
| 23 | namespace webrtc { |
| 24 |
| 25 | class VideoDenoiser { |
| 26 | public: |
| 27 | explicit VideoDenoiser(bool runtime_cpu_detection); |
| 28 |
| 29 | rtc::scoped_refptr<I420BufferInterface> DenoiseFrame( |
| 30 | rtc::scoped_refptr<I420BufferInterface> frame, |
| 31 | bool noise_estimation_enabled); |
| 32 |
| 33 | private: |
| 34 | void DenoiserReset(rtc::scoped_refptr<I420BufferInterface> frame); |
| 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, |
| 54 | int stride_src, |
| 55 | uint8_t* y_dst, |
| 56 | int stride_dst); |
| 57 |
| 58 | // Copy luma margin blocks when frame width/height not divisible by 16. |
| 59 | void CopyLumaOnMargin(const uint8_t* y_src, |
| 60 | int stride_src, |
| 61 | uint8_t* y_dst, |
| 62 | int stride_dst); |
| 63 |
| 64 | int width_; |
| 65 | int height_; |
| 66 | int mb_rows_; |
| 67 | int mb_cols_; |
| 68 | CpuType cpu_type_; |
| 69 | std::unique_ptr<DenoiserFilter> filter_; |
| 70 | std::unique_ptr<NoiseEstimation> ne_; |
| 71 | // 1 for moving edge block, 0 for static block. |
| 72 | std::unique_ptr<uint8_t[]> moving_edge_; |
| 73 | // 1 for moving object block, 0 for static block. |
| 74 | std::unique_ptr<uint8_t[]> moving_object_; |
| 75 | // x_density_ and y_density_ are used in MOD process. |
| 76 | std::unique_ptr<uint8_t[]> x_density_; |
| 77 | std::unique_ptr<uint8_t[]> y_density_; |
| 78 | // Save the return values by MbDenoise for each block. |
| 79 | std::unique_ptr<DenoiserDecision[]> mb_filter_decision_; |
| 80 | I420BufferPool buffer_pool_; |
| 81 | rtc::scoped_refptr<I420BufferInterface> prev_buffer_; |
| 82 | }; |
| 83 |
| 84 | } // namespace webrtc |
| 85 |
| 86 | #endif // MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ |
| 87 |