OLD | NEW |
---|---|
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 #include "webrtc/modules/video_processing/video_denoiser.h" | |
12 | 13 |
13 namespace webrtc { | 14 namespace webrtc { |
14 | 15 |
15 VPMFramePreprocessor::VPMFramePreprocessor() | 16 VPMFramePreprocessor::VPMFramePreprocessor() |
16 : content_metrics_(NULL), | 17 : content_metrics_(NULL), |
17 resampled_frame_(), | 18 resampled_frame_(), |
18 enable_ca_(false), | 19 enable_ca_(false), |
20 enable_denoise_(false), | |
19 frame_cnt_(0) { | 21 frame_cnt_(0) { |
20 spatial_resampler_ = new VPMSimpleSpatialResampler(); | 22 spatial_resampler_ = new VPMSimpleSpatialResampler(); |
21 ca_ = new VPMContentAnalysis(true); | 23 ca_ = new VPMContentAnalysis(true); |
22 vd_ = new VPMVideoDecimator(); | 24 vd_ = new VPMVideoDecimator(); |
25 vdn_ = new VideoDenoiser(); | |
23 } | 26 } |
24 | 27 |
25 VPMFramePreprocessor::~VPMFramePreprocessor() { | 28 VPMFramePreprocessor::~VPMFramePreprocessor() { |
26 Reset(); | 29 Reset(); |
27 delete spatial_resampler_; | |
28 delete ca_; | 30 delete ca_; |
29 delete vd_; | 31 delete vd_; |
32 delete vdn_; | |
33 delete spatial_resampler_; | |
30 } | 34 } |
31 | 35 |
32 void VPMFramePreprocessor::Reset() { | 36 void VPMFramePreprocessor::Reset() { |
33 ca_->Release(); | 37 ca_->Release(); |
34 vd_->Reset(); | 38 vd_->Reset(); |
35 content_metrics_ = NULL; | 39 content_metrics_ = NULL; |
36 spatial_resampler_->Reset(); | 40 spatial_resampler_->Reset(); |
37 enable_ca_ = false; | 41 enable_ca_ = false; |
38 frame_cnt_ = 0; | 42 frame_cnt_ = 0; |
39 } | 43 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 | 110 |
107 // Resizing incoming frame if needed. Otherwise, remains NULL. | 111 // Resizing incoming frame if needed. Otherwise, remains NULL. |
108 // We are not allowed to resample the input frame (must make a copy of it). | 112 // We are not allowed to resample the input frame (must make a copy of it). |
109 *processed_frame = NULL; | 113 *processed_frame = NULL; |
110 if (spatial_resampler_->ApplyResample(frame.width(), frame.height())) { | 114 if (spatial_resampler_->ApplyResample(frame.width(), frame.height())) { |
111 int32_t ret = spatial_resampler_->ResampleFrame(frame, &resampled_frame_); | 115 int32_t ret = spatial_resampler_->ResampleFrame(frame, &resampled_frame_); |
112 if (ret != VPM_OK) return ret; | 116 if (ret != VPM_OK) return ret; |
113 *processed_frame = &resampled_frame_; | 117 *processed_frame = &resampled_frame_; |
114 } | 118 } |
115 | 119 |
120 if (enable_denoise_) { | |
121 vdn_->DenoiseFrame(frame, &denoised_frame_); | |
stefan-webrtc
2015/11/23 10:12:52
What if we have resampled the frame above? Then I'
jackychen
2015/11/23 19:44:59
I reordered the code, so that resample will be wor
| |
122 *processed_frame = &denoised_frame_; | |
123 } | |
124 | |
116 // Perform content analysis on the frame to be encoded. | 125 // Perform content analysis on the frame to be encoded. |
117 if (enable_ca_) { | 126 if (enable_ca_) { |
118 // Compute new metrics every |kSkipFramesCA| frames, starting with | 127 // Compute new metrics every |kSkipFramesCA| frames, starting with |
119 // the first frame. | 128 // the first frame. |
120 if (frame_cnt_ % kSkipFrameCA == 0) { | 129 if (frame_cnt_ % kSkipFrameCA == 0) { |
121 if (*processed_frame == NULL) { | 130 if (*processed_frame == NULL) { |
122 content_metrics_ = ca_->ComputeContentMetrics(frame); | 131 content_metrics_ = ca_->ComputeContentMetrics(frame); |
123 } else { | 132 } else { |
124 content_metrics_ = ca_->ComputeContentMetrics(resampled_frame_); | 133 content_metrics_ = ca_->ComputeContentMetrics(resampled_frame_); |
stefan-webrtc
2015/11/23 10:12:52
Should this use *processed_frame instead?
jackychen
2015/11/23 19:44:59
Maybe Marco can change it in another cl, but for m
stefan-webrtc
2015/11/24 08:56:18
But if denoising is on, but no resampling is done,
jackychen
2015/11/24 22:33:05
You are right. Done.
| |
125 } | 134 } |
126 } | 135 } |
127 ++frame_cnt_; | |
128 } | 136 } |
137 ++frame_cnt_; | |
129 return VPM_OK; | 138 return VPM_OK; |
130 } | 139 } |
131 | 140 |
132 VideoContentMetrics* VPMFramePreprocessor::ContentMetrics() const { | 141 VideoContentMetrics* VPMFramePreprocessor::ContentMetrics() const { |
133 return content_metrics_; | 142 return content_metrics_; |
134 } | 143 } |
135 | 144 |
136 } // namespace | 145 } // namespace |
OLD | NEW |