Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: webrtc/modules/video_processing/frame_preprocessor.cc

Issue 1466763002: Standalone denoiser (off by default). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 #include "webrtc/modules/video_processing/frame_preprocessor.h" 11 #include "webrtc/modules/video_processing/frame_preprocessor.h"
12 12
13 namespace webrtc { 13 namespace webrtc {
14 14
15 VPMFramePreprocessor::VPMFramePreprocessor() 15 VPMFramePreprocessor::VPMFramePreprocessor()
16 : content_metrics_(NULL), 16 : content_metrics_(nullptr),
17 resampled_frame_(), 17 resampled_frame_(),
18 enable_ca_(false), 18 enable_ca_(false),
19 enable_denoising_(false),
19 frame_cnt_(0) { 20 frame_cnt_(0) {
20 spatial_resampler_ = new VPMSimpleSpatialResampler(); 21 spatial_resampler_ = new VPMSimpleSpatialResampler();
21 ca_ = new VPMContentAnalysis(true); 22 ca_ = new VPMContentAnalysis(true);
22 vd_ = new VPMVideoDecimator(); 23 vd_ = new VPMVideoDecimator();
24 if (enable_denoising_) {
mflodman 2015/11/26 10:50:00 This can later be changed to only be an input para
25 denoiser_ = new VideoDenoiser();
26 } else {
27 denoiser_ = nullptr;
28 }
23 } 29 }
24 30
25 VPMFramePreprocessor::~VPMFramePreprocessor() { 31 VPMFramePreprocessor::~VPMFramePreprocessor() {
26 Reset(); 32 Reset();
27 delete spatial_resampler_;
28 delete ca_; 33 delete ca_;
29 delete vd_; 34 delete vd_;
35 if (enable_denoising_)
36 delete denoiser_;
37 delete spatial_resampler_;
30 } 38 }
31 39
32 void VPMFramePreprocessor::Reset() { 40 void VPMFramePreprocessor::Reset() {
33 ca_->Release(); 41 ca_->Release();
34 vd_->Reset(); 42 vd_->Reset();
35 content_metrics_ = NULL; 43 content_metrics_ = nullptr;
36 spatial_resampler_->Reset(); 44 spatial_resampler_->Reset();
37 enable_ca_ = false; 45 enable_ca_ = false;
38 frame_cnt_ = 0; 46 frame_cnt_ = 0;
39 } 47 }
40 48
41 void VPMFramePreprocessor::EnableTemporalDecimation(bool enable) { 49 void VPMFramePreprocessor::EnableTemporalDecimation(bool enable) {
42 vd_->EnableTemporalDecimation(enable); 50 vd_->EnableTemporalDecimation(enable);
43 } 51 }
44 52
45 void VPMFramePreprocessor::EnableContentAnalysis(bool enable) { 53 void VPMFramePreprocessor::EnableContentAnalysis(bool enable) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if (frame.IsZeroSize()) { 105 if (frame.IsZeroSize()) {
98 return VPM_PARAMETER_ERROR; 106 return VPM_PARAMETER_ERROR;
99 } 107 }
100 108
101 vd_->UpdateIncomingframe_rate(); 109 vd_->UpdateIncomingframe_rate();
102 110
103 if (vd_->DropFrame()) { 111 if (vd_->DropFrame()) {
104 return 1; // drop 1 frame 112 return 1; // drop 1 frame
105 } 113 }
106 114
107 // Resizing incoming frame if needed. Otherwise, remains NULL. 115 // Resizing incoming frame if needed. Otherwise, remains nullptr.
108 // We are not allowed to resample the input frame (must make a copy of it). 116 // We are not allowed to resample the input frame (must make a copy of it).
109 *processed_frame = NULL; 117 *processed_frame = nullptr;
118 if (denoiser_ != nullptr) {
119 denoiser_->DenoiseFrame(frame, &denoised_frame_);
120 *processed_frame = &denoised_frame_;
121 }
122
110 if (spatial_resampler_->ApplyResample(frame.width(), frame.height())) { 123 if (spatial_resampler_->ApplyResample(frame.width(), frame.height())) {
111 int32_t ret = spatial_resampler_->ResampleFrame(frame, &resampled_frame_); 124 int32_t ret;
125 if (enable_denoising_) {
mflodman 2015/11/26 10:50:00 Change to denoiser != nullptr here too.
126 ret = spatial_resampler_->ResampleFrame(denoised_frame_,
127 &resampled_frame_);
128 } else {
129 ret = spatial_resampler_->ResampleFrame(frame, &resampled_frame_);
130 }
112 if (ret != VPM_OK) return ret; 131 if (ret != VPM_OK) return ret;
113 *processed_frame = &resampled_frame_; 132 *processed_frame = &resampled_frame_;
114 } 133 }
115 134
116 // Perform content analysis on the frame to be encoded. 135 // Perform content analysis on the frame to be encoded.
117 if (enable_ca_) { 136 if (enable_ca_) {
118 // Compute new metrics every |kSkipFramesCA| frames, starting with 137 // Compute new metrics every |kSkipFramesCA| frames, starting with
119 // the first frame. 138 // the first frame.
120 if (frame_cnt_ % kSkipFrameCA == 0) { 139 if (frame_cnt_ % kSkipFrameCA == 0) {
121 if (*processed_frame == NULL) { 140 if (*processed_frame == nullptr) {
122 content_metrics_ = ca_->ComputeContentMetrics(frame); 141 content_metrics_ = ca_->ComputeContentMetrics(frame);
123 } else { 142 } else {
124 content_metrics_ = ca_->ComputeContentMetrics(resampled_frame_); 143 content_metrics_ = ca_->ComputeContentMetrics(**processed_frame);
125 } 144 }
126 } 145 }
127 ++frame_cnt_;
128 } 146 }
147 ++frame_cnt_;
129 return VPM_OK; 148 return VPM_OK;
130 } 149 }
131 150
132 VideoContentMetrics* VPMFramePreprocessor::ContentMetrics() const { 151 VideoContentMetrics* VPMFramePreprocessor::ContentMetrics() const {
133 return content_metrics_; 152 return content_metrics_;
134 } 153 }
135 154
136 } // namespace 155 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698