video_denoiser.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_
  11. #define MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_
  12. #include <memory>
  13. #include "api/scoped_refptr.h"
  14. #include "api/video/video_frame_buffer.h"
  15. #include "common_video/include/video_frame_buffer_pool.h"
  16. #include "modules/video_processing/util/denoiser_filter.h"
  17. #include "modules/video_processing/util/noise_estimation.h"
  18. #include "modules/video_processing/util/skin_detection.h"
  19. namespace webrtc {
  20. class VideoDenoiser {
  21. public:
  22. explicit VideoDenoiser(bool runtime_cpu_detection);
  23. rtc::scoped_refptr<I420BufferInterface> DenoiseFrame(
  24. rtc::scoped_refptr<I420BufferInterface> frame,
  25. bool noise_estimation_enabled);
  26. private:
  27. void DenoiserReset(rtc::scoped_refptr<I420BufferInterface> frame);
  28. // Check the mb position, return 1: close to the frame center (between 1/8
  29. // and 7/8 of width/height), 3: close to the border (out of 1/16 and 15/16
  30. // of width/height), 2: in between.
  31. int PositionCheck(int mb_row, int mb_col, int noise_level);
  32. // To reduce false detection in moving object detection (MOD).
  33. void ReduceFalseDetection(const std::unique_ptr<uint8_t[]>& d_status,
  34. std::unique_ptr<uint8_t[]>* d_status_red,
  35. int noise_level);
  36. // Return whether a block might cause trailing artifact by checking if one of
  37. // its neighbor blocks is a moving edge block.
  38. bool IsTrailingBlock(const std::unique_ptr<uint8_t[]>& d_status,
  39. int mb_row,
  40. int mb_col);
  41. // Copy input blocks to dst buffer on moving object blocks (MOB).
  42. void CopySrcOnMOB(const uint8_t* y_src,
  43. int stride_src,
  44. uint8_t* y_dst,
  45. int stride_dst);
  46. // Copy luma margin blocks when frame width/height not divisible by 16.
  47. void CopyLumaOnMargin(const uint8_t* y_src,
  48. int stride_src,
  49. uint8_t* y_dst,
  50. int stride_dst);
  51. int width_;
  52. int height_;
  53. int mb_rows_;
  54. int mb_cols_;
  55. CpuType cpu_type_;
  56. std::unique_ptr<DenoiserFilter> filter_;
  57. std::unique_ptr<NoiseEstimation> ne_;
  58. // 1 for moving edge block, 0 for static block.
  59. std::unique_ptr<uint8_t[]> moving_edge_;
  60. // 1 for moving object block, 0 for static block.
  61. std::unique_ptr<uint8_t[]> moving_object_;
  62. // x_density_ and y_density_ are used in MOD process.
  63. std::unique_ptr<uint8_t[]> x_density_;
  64. std::unique_ptr<uint8_t[]> y_density_;
  65. // Save the return values by MbDenoise for each block.
  66. std::unique_ptr<DenoiserDecision[]> mb_filter_decision_;
  67. VideoFrameBufferPool buffer_pool_;
  68. rtc::scoped_refptr<I420BufferInterface> prev_buffer_;
  69. };
  70. } // namespace webrtc
  71. #endif // MODULES_VIDEO_PROCESSING_VIDEO_DENOISER_H_