| 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 | 12 |
| 13 #include "webrtc/modules/video_processing/video_denoiser.h" | 13 #include "webrtc/modules/video_processing/video_denoiser.h" |
| 14 | 14 |
| 15 namespace webrtc { | 15 namespace webrtc { |
| 16 | 16 |
| 17 VPMFramePreprocessor::VPMFramePreprocessor() | 17 VPMFramePreprocessor::VPMFramePreprocessor() |
| 18 : content_metrics_(nullptr), | 18 : content_metrics_(nullptr), |
| 19 resampled_frame_(), | 19 resampled_frame_(), |
| 20 enable_ca_(false), | 20 enable_ca_(false), |
| 21 frame_cnt_(0) { | 21 frame_cnt_(0) { |
| 22 spatial_resampler_ = new VPMSimpleSpatialResampler(); | 22 spatial_resampler_ = new VPMSimpleSpatialResampler(); |
| 23 ca_ = new VPMContentAnalysis(true); | 23 ca_ = new VPMContentAnalysis(true); |
| 24 vd_ = new VPMVideoDecimator(); | 24 vd_ = new VPMVideoDecimator(); |
| 25 EnableDenosing(false); | 25 EnableDenosing(false); |
| 26 denoised_frame_toggle_ = 0; |
| 26 } | 27 } |
| 27 | 28 |
| 28 VPMFramePreprocessor::~VPMFramePreprocessor() { | 29 VPMFramePreprocessor::~VPMFramePreprocessor() { |
| 29 Reset(); | 30 Reset(); |
| 30 delete ca_; | 31 delete ca_; |
| 31 delete vd_; | 32 delete vd_; |
| 32 delete spatial_resampler_; | 33 delete spatial_resampler_; |
| 33 } | 34 } |
| 34 | 35 |
| 35 void VPMFramePreprocessor::Reset() { | 36 void VPMFramePreprocessor::Reset() { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return nullptr; | 110 return nullptr; |
| 110 } | 111 } |
| 111 | 112 |
| 112 vd_->UpdateIncomingframe_rate(); | 113 vd_->UpdateIncomingframe_rate(); |
| 113 if (vd_->DropFrame()) { | 114 if (vd_->DropFrame()) { |
| 114 return nullptr; | 115 return nullptr; |
| 115 } | 116 } |
| 116 | 117 |
| 117 const VideoFrame* current_frame = &frame; | 118 const VideoFrame* current_frame = &frame; |
| 118 if (denoiser_) { | 119 if (denoiser_) { |
| 119 denoiser_->DenoiseFrame(*current_frame, &denoised_frame_, | 120 VideoFrame* denoised_frame = &denoised_frame_[0]; |
| 120 &denoised_frame_prev_, 0); | 121 VideoFrame* denoised_frame_prev = &denoised_frame_[1]; |
| 121 current_frame = &denoised_frame_; | 122 // Swap the buffer to save one memcpy in DenoiseFrame. |
| 123 if (denoised_frame_toggle_) { |
| 124 denoised_frame = &denoised_frame_[1]; |
| 125 denoised_frame_prev = &denoised_frame_[0]; |
| 126 } |
| 127 // Invert the flag. |
| 128 denoised_frame_toggle_ ^= 1; |
| 129 denoiser_->DenoiseFrame(*current_frame, denoised_frame, denoised_frame_prev, |
| 130 true); |
| 131 current_frame = denoised_frame; |
| 122 } | 132 } |
| 123 | 133 |
| 124 if (spatial_resampler_->ApplyResample(current_frame->width(), | 134 if (spatial_resampler_->ApplyResample(current_frame->width(), |
| 125 current_frame->height())) { | 135 current_frame->height())) { |
| 126 if (spatial_resampler_->ResampleFrame(*current_frame, &resampled_frame_) != | 136 if (spatial_resampler_->ResampleFrame(*current_frame, &resampled_frame_) != |
| 127 VPM_OK) { | 137 VPM_OK) { |
| 128 return nullptr; | 138 return nullptr; |
| 129 } | 139 } |
| 130 current_frame = &resampled_frame_; | 140 current_frame = &resampled_frame_; |
| 131 } | 141 } |
| 132 | 142 |
| 133 // Perform content analysis on the frame to be encoded. | 143 // Perform content analysis on the frame to be encoded. |
| 134 if (enable_ca_ && frame_cnt_ % kSkipFrameCA == 0) { | 144 if (enable_ca_ && frame_cnt_ % kSkipFrameCA == 0) { |
| 135 // Compute new metrics every |kSkipFramesCA| frames, starting with | 145 // Compute new metrics every |kSkipFramesCA| frames, starting with |
| 136 // the first frame. | 146 // the first frame. |
| 137 content_metrics_ = ca_->ComputeContentMetrics(*current_frame); | 147 content_metrics_ = ca_->ComputeContentMetrics(*current_frame); |
| 138 } | 148 } |
| 139 ++frame_cnt_; | 149 ++frame_cnt_; |
| 140 return current_frame; | 150 return current_frame; |
| 141 } | 151 } |
| 142 | 152 |
| 143 VideoContentMetrics* VPMFramePreprocessor::GetContentMetrics() const { | 153 VideoContentMetrics* VPMFramePreprocessor::GetContentMetrics() const { |
| 144 return content_metrics_; | 154 return content_metrics_; |
| 145 } | 155 } |
| 146 | 156 |
| 147 } // namespace webrtc | 157 } // namespace webrtc |
| OLD | NEW |