Refactor VideoDenoiser to use a buffer pool, replacing explicit double buffering.

Also improve denoiser to not assume identical stride of all involved
frames, and delete the no longer needed function I420Buffer::CopyKeepStride.

BUG=None

Review-Url: https://codereview.webrtc.org/2469763002
Cr-Commit-Position: refs/heads/master@{#14940}
This commit is contained in:
nisse
2016-11-07 01:34:59 -08:00
committed by Commit bot
parent c97d1150f2
commit 18ee17d1e7
14 changed files with 116 additions and 178 deletions

View File

@ -13,6 +13,7 @@
#include <memory>
#include "webrtc/common_video/include/i420_buffer_pool.h"
#include "webrtc/modules/video_processing/util/denoiser_filter.h"
#include "webrtc/modules/video_processing/util/noise_estimation.h"
#include "webrtc/modules/video_processing/util/skin_detection.h"
@ -23,21 +24,12 @@ class VideoDenoiser {
public:
explicit VideoDenoiser(bool runtime_cpu_detection);
// TODO(nisse): Let the denoised_frame and denoised_frame_prev be
// member variables referencing two I420Buffer, and return a refptr
// to the current one. When we also move the double-buffering logic
// from the caller.
void DenoiseFrame(const rtc::scoped_refptr<VideoFrameBuffer>& frame,
// Buffers are allocated/replaced when dimensions
// change.
rtc::scoped_refptr<I420Buffer>* denoised_frame,
rtc::scoped_refptr<I420Buffer>* denoised_frame_prev,
bool noise_estimation_enabled);
rtc::scoped_refptr<VideoFrameBuffer> DenoiseFrame(
rtc::scoped_refptr<VideoFrameBuffer> frame,
bool noise_estimation_enabled);
private:
void DenoiserReset(const rtc::scoped_refptr<VideoFrameBuffer>& frame,
rtc::scoped_refptr<I420Buffer>* denoised_frame,
rtc::scoped_refptr<I420Buffer>* denoised_frame_prev);
void DenoiserReset(rtc::scoped_refptr<VideoFrameBuffer> frame);
// Check the mb position, return 1: close to the frame center (between 1/8
// and 7/8 of width/height), 3: close to the border (out of 1/16 and 15/16
@ -56,18 +48,21 @@ class VideoDenoiser {
int mb_col);
// Copy input blocks to dst buffer on moving object blocks (MOB).
void CopySrcOnMOB(const uint8_t* y_src, uint8_t* y_dst);
void CopySrcOnMOB(const uint8_t* y_src,
int stride_src,
uint8_t* y_dst,
int stride_dst);
// Copy luma margin blocks when frame width/height not divisible by 16.
void CopyLumaOnMargin(const uint8_t* y_src, uint8_t* y_dst);
void CopyLumaOnMargin(const uint8_t* y_src,
int stride_src,
uint8_t* y_dst,
int stride_dst);
int width_;
int height_;
int mb_rows_;
int mb_cols_;
int stride_y_;
int stride_u_;
int stride_v_;
CpuType cpu_type_;
std::unique_ptr<DenoiserFilter> filter_;
std::unique_ptr<NoiseEstimation> ne_;
@ -80,6 +75,8 @@ class VideoDenoiser {
std::unique_ptr<uint8_t[]> y_density_;
// Save the return values by MbDenoise for each block.
std::unique_ptr<DenoiserDecision[]> mb_filter_decision_;
I420BufferPool buffer_pool_;
rtc::scoped_refptr<VideoFrameBuffer> prev_buffer_;
};
} // namespace webrtc