| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ |
| 12 #define WEBRTC_MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ | 12 #define WEBRTC_MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "webrtc/common_video/include/i420_buffer_pool.h" |
| 16 #include "webrtc/modules/video_processing/util/denoiser_filter.h" | 17 #include "webrtc/modules/video_processing/util/denoiser_filter.h" |
| 17 #include "webrtc/modules/video_processing/util/noise_estimation.h" | 18 #include "webrtc/modules/video_processing/util/noise_estimation.h" |
| 18 #include "webrtc/modules/video_processing/util/skin_detection.h" | 19 #include "webrtc/modules/video_processing/util/skin_detection.h" |
| 19 | 20 |
| 20 namespace webrtc { | 21 namespace webrtc { |
| 21 | 22 |
| 22 class VideoDenoiser { | 23 class VideoDenoiser { |
| 23 public: | 24 public: |
| 24 explicit VideoDenoiser(bool runtime_cpu_detection); | 25 explicit VideoDenoiser(bool runtime_cpu_detection); |
| 25 | 26 |
| 26 // TODO(nisse): Let the denoised_frame and denoised_frame_prev be | 27 rtc::scoped_refptr<VideoFrameBuffer> DenoiseFrame( |
| 27 // member variables referencing two I420Buffer, and return a refptr | 28 rtc::scoped_refptr<VideoFrameBuffer> frame, |
| 28 // to the current one. When we also move the double-buffering logic | 29 bool noise_estimation_enabled); |
| 29 // from the caller. | |
| 30 void DenoiseFrame(const rtc::scoped_refptr<VideoFrameBuffer>& frame, | |
| 31 // Buffers are allocated/replaced when dimensions | |
| 32 // change. | |
| 33 rtc::scoped_refptr<I420Buffer>* denoised_frame, | |
| 34 rtc::scoped_refptr<I420Buffer>* denoised_frame_prev, | |
| 35 bool noise_estimation_enabled); | |
| 36 | 30 |
| 37 private: | 31 private: |
| 38 void DenoiserReset(const rtc::scoped_refptr<VideoFrameBuffer>& frame, | 32 void DenoiserReset(rtc::scoped_refptr<VideoFrameBuffer> frame); |
| 39 rtc::scoped_refptr<I420Buffer>* denoised_frame, | |
| 40 rtc::scoped_refptr<I420Buffer>* denoised_frame_prev); | |
| 41 | 33 |
| 42 // Check the mb position, return 1: close to the frame center (between 1/8 | 34 // Check the mb position, return 1: close to the frame center (between 1/8 |
| 43 // and 7/8 of width/height), 3: close to the border (out of 1/16 and 15/16 | 35 // and 7/8 of width/height), 3: close to the border (out of 1/16 and 15/16 |
| 44 // of width/height), 2: in between. | 36 // of width/height), 2: in between. |
| 45 int PositionCheck(int mb_row, int mb_col, int noise_level); | 37 int PositionCheck(int mb_row, int mb_col, int noise_level); |
| 46 | 38 |
| 47 // To reduce false detection in moving object detection (MOD). | 39 // To reduce false detection in moving object detection (MOD). |
| 48 void ReduceFalseDetection(const std::unique_ptr<uint8_t[]>& d_status, | 40 void ReduceFalseDetection(const std::unique_ptr<uint8_t[]>& d_status, |
| 49 std::unique_ptr<uint8_t[]>* d_status_red, | 41 std::unique_ptr<uint8_t[]>* d_status_red, |
| 50 int noise_level); | 42 int noise_level); |
| 51 | 43 |
| 52 // Return whether a block might cause trailing artifact by checking if one of | 44 // Return whether a block might cause trailing artifact by checking if one of |
| 53 // its neighbor blocks is a moving edge block. | 45 // its neighbor blocks is a moving edge block. |
| 54 bool IsTrailingBlock(const std::unique_ptr<uint8_t[]>& d_status, | 46 bool IsTrailingBlock(const std::unique_ptr<uint8_t[]>& d_status, |
| 55 int mb_row, | 47 int mb_row, |
| 56 int mb_col); | 48 int mb_col); |
| 57 | 49 |
| 58 // Copy input blocks to dst buffer on moving object blocks (MOB). | 50 // Copy input blocks to dst buffer on moving object blocks (MOB). |
| 59 void CopySrcOnMOB(const uint8_t* y_src, uint8_t* y_dst); | 51 void CopySrcOnMOB(const uint8_t* y_src, |
| 52 int stride_src, |
| 53 uint8_t* y_dst, |
| 54 int stride_dst); |
| 60 | 55 |
| 61 // Copy luma margin blocks when frame width/height not divisible by 16. | 56 // Copy luma margin blocks when frame width/height not divisible by 16. |
| 62 void CopyLumaOnMargin(const uint8_t* y_src, uint8_t* y_dst); | 57 void CopyLumaOnMargin(const uint8_t* y_src, |
| 58 int stride_src, |
| 59 uint8_t* y_dst, |
| 60 int stride_dst); |
| 63 | 61 |
| 64 int width_; | 62 int width_; |
| 65 int height_; | 63 int height_; |
| 66 int mb_rows_; | 64 int mb_rows_; |
| 67 int mb_cols_; | 65 int mb_cols_; |
| 68 int stride_y_; | |
| 69 int stride_u_; | |
| 70 int stride_v_; | |
| 71 CpuType cpu_type_; | 66 CpuType cpu_type_; |
| 72 std::unique_ptr<DenoiserFilter> filter_; | 67 std::unique_ptr<DenoiserFilter> filter_; |
| 73 std::unique_ptr<NoiseEstimation> ne_; | 68 std::unique_ptr<NoiseEstimation> ne_; |
| 74 // 1 for moving edge block, 0 for static block. | 69 // 1 for moving edge block, 0 for static block. |
| 75 std::unique_ptr<uint8_t[]> moving_edge_; | 70 std::unique_ptr<uint8_t[]> moving_edge_; |
| 76 // 1 for moving object block, 0 for static block. | 71 // 1 for moving object block, 0 for static block. |
| 77 std::unique_ptr<uint8_t[]> moving_object_; | 72 std::unique_ptr<uint8_t[]> moving_object_; |
| 78 // x_density_ and y_density_ are used in MOD process. | 73 // x_density_ and y_density_ are used in MOD process. |
| 79 std::unique_ptr<uint8_t[]> x_density_; | 74 std::unique_ptr<uint8_t[]> x_density_; |
| 80 std::unique_ptr<uint8_t[]> y_density_; | 75 std::unique_ptr<uint8_t[]> y_density_; |
| 81 // Save the return values by MbDenoise for each block. | 76 // Save the return values by MbDenoise for each block. |
| 82 std::unique_ptr<DenoiserDecision[]> mb_filter_decision_; | 77 std::unique_ptr<DenoiserDecision[]> mb_filter_decision_; |
| 78 I420BufferPool buffer_pool_; |
| 79 rtc::scoped_refptr<VideoFrameBuffer> prev_buffer_; |
| 83 }; | 80 }; |
| 84 | 81 |
| 85 } // namespace webrtc | 82 } // namespace webrtc |
| 86 | 83 |
| 87 #endif // WEBRTC_MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ | 84 #endif // WEBRTC_MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_ |
| OLD | NEW |