| 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 : resampled_frame_(), frame_cnt_(0) { | 18 : resampled_frame_(), frame_cnt_(0) { |
| 19 spatial_resampler_ = new VPMSimpleSpatialResampler(); | 19 spatial_resampler_ = new VPMSimpleSpatialResampler(); |
| 20 vd_ = new VPMVideoDecimator(); | 20 vd_ = new VPMVideoDecimator(); |
| 21 EnableDenoising(false); | 21 EnableDenoising(false); |
| 22 denoised_frame_toggle_ = 0; | |
| 23 } | 22 } |
| 24 | 23 |
| 25 VPMFramePreprocessor::~VPMFramePreprocessor() { | 24 VPMFramePreprocessor::~VPMFramePreprocessor() { |
| 26 Reset(); | 25 Reset(); |
| 27 delete vd_; | 26 delete vd_; |
| 28 delete spatial_resampler_; | 27 delete spatial_resampler_; |
| 29 } | 28 } |
| 30 | 29 |
| 31 void VPMFramePreprocessor::Reset() { | 30 void VPMFramePreprocessor::Reset() { |
| 32 vd_->Reset(); | 31 vd_->Reset(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 return nullptr; | 88 return nullptr; |
| 90 } | 89 } |
| 91 | 90 |
| 92 vd_->UpdateIncomingframe_rate(); | 91 vd_->UpdateIncomingframe_rate(); |
| 93 if (vd_->DropFrame()) { | 92 if (vd_->DropFrame()) { |
| 94 return nullptr; | 93 return nullptr; |
| 95 } | 94 } |
| 96 | 95 |
| 97 const VideoFrame* current_frame = &frame; | 96 const VideoFrame* current_frame = &frame; |
| 98 if (denoiser_) { | 97 if (denoiser_) { |
| 99 rtc::scoped_refptr<I420Buffer>* denoised_buffer = &denoised_buffer_[0]; | 98 denoised_frame_ = VideoFrame( |
| 100 rtc::scoped_refptr<I420Buffer>* denoised_buffer_prev = &denoised_buffer_[1]; | 99 denoiser_->DenoiseFrame(current_frame->video_frame_buffer(), true), |
| 101 // Swap the buffer to save one memcpy in DenoiseFrame. | 100 current_frame->timestamp(), current_frame->render_time_ms(), |
| 102 if (denoised_frame_toggle_) { | 101 current_frame->rotation()); |
| 103 denoised_buffer = &denoised_buffer_[1]; | |
| 104 denoised_buffer_prev = &denoised_buffer_[0]; | |
| 105 } | |
| 106 // Invert the flag. | |
| 107 denoised_frame_toggle_ ^= 1; | |
| 108 denoiser_->DenoiseFrame(current_frame->video_frame_buffer(), | |
| 109 denoised_buffer, | |
| 110 denoised_buffer_prev, true); | |
| 111 denoised_frame_ = VideoFrame(*denoised_buffer, | |
| 112 current_frame->timestamp(), | |
| 113 current_frame->render_time_ms(), | |
| 114 current_frame->rotation()); | |
| 115 current_frame = &denoised_frame_; | 102 current_frame = &denoised_frame_; |
| 116 } | 103 } |
| 117 | 104 |
| 118 if (spatial_resampler_->ApplyResample(current_frame->width(), | 105 if (spatial_resampler_->ApplyResample(current_frame->width(), |
| 119 current_frame->height())) { | 106 current_frame->height())) { |
| 120 if (spatial_resampler_->ResampleFrame(*current_frame, &resampled_frame_) != | 107 if (spatial_resampler_->ResampleFrame(*current_frame, &resampled_frame_) != |
| 121 VPM_OK) { | 108 VPM_OK) { |
| 122 return nullptr; | 109 return nullptr; |
| 123 } | 110 } |
| 124 current_frame = &resampled_frame_; | 111 current_frame = &resampled_frame_; |
| 125 } | 112 } |
| 126 | 113 |
| 127 ++frame_cnt_; | 114 ++frame_cnt_; |
| 128 return current_frame; | 115 return current_frame; |
| 129 } | 116 } |
| 130 | 117 |
| 131 } // namespace webrtc | 118 } // namespace webrtc |
| OLD | NEW |