From a276e731683c673388cf3aeaa1888a5bcc3e1dc0 Mon Sep 17 00:00:00 2001 From: jackychen Date: Wed, 13 Jan 2016 05:36:31 -0800 Subject: Clean the code for external denoiser. BUG=webrtc:5255 Review URL: https://codereview.webrtc.org/1578373003 Cr-Commit-Position: refs/heads/master@{#11235} --- webrtc/common_video/video_frame.cc | 39 ++++++++++------------ .../video_processing/util/denoiser_filter.cc | 19 ++++++----- .../video_processing/util/denoiser_filter.h | 3 +- 3 files changed, 31 insertions(+), 30 deletions(-) (limited to 'webrtc') diff --git a/webrtc/common_video/video_frame.cc b/webrtc/common_video/video_frame.cc index 710a06d3dc..8ccd821d09 100644 --- a/webrtc/common_video/video_frame.cc +++ b/webrtc/common_video/video_frame.cc @@ -34,12 +34,9 @@ bool EqualPlane(const uint8_t* data1, } int ExpectedSize(int plane_stride, int image_height, PlaneType type) { - if (type == kYPlane) { - return (plane_stride * image_height); - } else { - int half_height = (image_height + 1) / 2; - return (plane_stride * half_height); - } + if (type == kYPlane) + return plane_stride * image_height; + return plane_stride * ((image_height + 1) / 2); } VideoFrame::VideoFrame() { @@ -226,23 +223,23 @@ VideoFrame VideoFrame::ConvertNativeToI420Frame() const { } bool VideoFrame::EqualsFrame(const VideoFrame& frame) const { - if ((this->width() != frame.width()) || (this->height() != frame.height()) || - (this->stride(kYPlane) != frame.stride(kYPlane)) || - (this->stride(kUPlane) != frame.stride(kUPlane)) || - (this->stride(kVPlane) != frame.stride(kVPlane)) || - (this->timestamp() != frame.timestamp()) || - (this->ntp_time_ms() != frame.ntp_time_ms()) || - (this->render_time_ms() != frame.render_time_ms())) { + if (width() != frame.width() || height() != frame.height() || + stride(kYPlane) != frame.stride(kYPlane) || + stride(kUPlane) != frame.stride(kUPlane) || + stride(kVPlane) != frame.stride(kVPlane) || + timestamp() != frame.timestamp() || + ntp_time_ms() != frame.ntp_time_ms() || + render_time_ms() != frame.render_time_ms()) { return false; } - const int half_width = (this->width() + 1) / 2; - const int half_height = (this->height() + 1) / 2; - return EqualPlane(this->buffer(kYPlane), frame.buffer(kYPlane), - this->stride(kYPlane), this->width(), this->height()) && - EqualPlane(this->buffer(kUPlane), frame.buffer(kUPlane), - this->stride(kUPlane), half_width, half_height) && - EqualPlane(this->buffer(kVPlane), frame.buffer(kVPlane), - this->stride(kVPlane), half_width, half_height); + const int half_width = (width() + 1) / 2; + const int half_height = (height() + 1) / 2; + return EqualPlane(buffer(kYPlane), frame.buffer(kYPlane), + stride(kYPlane), width(), height()) && + EqualPlane(buffer(kUPlane), frame.buffer(kUPlane), + stride(kUPlane), half_width, half_height) && + EqualPlane(buffer(kVPlane), frame.buffer(kVPlane), + stride(kVPlane), half_width, half_height); } } // namespace webrtc diff --git a/webrtc/modules/video_processing/util/denoiser_filter.cc b/webrtc/modules/video_processing/util/denoiser_filter.cc index 8fead6dd31..fbc2435cb5 100644 --- a/webrtc/modules/video_processing/util/denoiser_filter.cc +++ b/webrtc/modules/video_processing/util/denoiser_filter.cc @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "webrtc/base/checks.h" #include "webrtc/modules/video_processing/util/denoiser_filter.h" #include "webrtc/modules/video_processing/util/denoiser_filter_c.h" #include "webrtc/modules/video_processing/util/denoiser_filter_neon.h" @@ -20,31 +21,33 @@ const int kMotionMagnitudeThreshold = 8 * 3; const int kSumDiffThreshold = 16 * 16 * 2; const int kSumDiffThresholdHigh = 600; -DenoiserFilter* DenoiserFilter::Create(bool runtime_cpu_detection) { - DenoiserFilter* filter = NULL; +rtc::scoped_ptr DenoiserFilter::Create( + bool runtime_cpu_detection) { + rtc::scoped_ptr filter; if (runtime_cpu_detection) { // If we know the minimum architecture at compile time, avoid CPU detection. #if defined(WEBRTC_ARCH_X86_FAMILY) // x86 CPU detection required. if (WebRtc_GetCPUInfo(kSSE2)) { - filter = new DenoiserFilterSSE2(); + filter.reset(new DenoiserFilterSSE2()); } else { - filter = new DenoiserFilterC(); + filter.reset(new DenoiserFilterC()); } #elif defined(WEBRTC_DETECT_NEON) if (WebRtc_GetCPUFeaturesARM() & kCPUFeatureNEON) { - filter = new DenoiserFilterNEON(); + filter.reset(new DenoiserFilterNEON()); } else { - filter = new DenoiserFilterC(); + filter.reset(new DenoiserFilterC()); } #else - filter = new DenoiserFilterC(); + filter.reset(new DenoiserFilterC()); #endif } else { - filter = new DenoiserFilterC(); + filter.reset(new DenoiserFilterC()); } + RTC_DCHECK(filter.get() != nullptr); return filter; } diff --git a/webrtc/modules/video_processing/util/denoiser_filter.h b/webrtc/modules/video_processing/util/denoiser_filter.h index e9bd375a22..5d5a61c59c 100644 --- a/webrtc/modules/video_processing/util/denoiser_filter.h +++ b/webrtc/modules/video_processing/util/denoiser_filter.h @@ -11,6 +11,7 @@ #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_UTIL_DENOISER_FILTER_H_ #define WEBRTC_MODULES_VIDEO_PROCESSING_UTIL_DENOISER_FILTER_H_ +#include "webrtc/base/scoped_ptr.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/video_processing/include/video_processing_defines.h" @@ -30,7 +31,7 @@ struct DenoiseMetrics { class DenoiserFilter { public: - static DenoiserFilter* Create(bool runtime_cpu_detection); + static rtc::scoped_ptr Create(bool runtime_cpu_detection); virtual ~DenoiserFilter() {} -- cgit v1.2.3