OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/video_processing/frame_preprocessor.h" | |
12 | |
13 #include "webrtc/modules/video_processing/video_denoiser.h" | |
14 | |
15 namespace webrtc { | |
16 | |
17 VPMFramePreprocessor::VPMFramePreprocessor() | |
18 : resampled_frame_(), frame_cnt_(0) { | |
19 spatial_resampler_ = new VPMSimpleSpatialResampler(); | |
20 vd_ = new VPMVideoDecimator(); | |
21 EnableDenoising(false); | |
22 } | |
23 | |
24 VPMFramePreprocessor::~VPMFramePreprocessor() { | |
25 Reset(); | |
26 delete vd_; | |
27 delete spatial_resampler_; | |
28 } | |
29 | |
30 void VPMFramePreprocessor::Reset() { | |
31 vd_->Reset(); | |
32 spatial_resampler_->Reset(); | |
33 frame_cnt_ = 0; | |
34 } | |
35 | |
36 void VPMFramePreprocessor::EnableTemporalDecimation(bool enable) { | |
37 vd_->EnableTemporalDecimation(enable); | |
38 } | |
39 | |
40 void VPMFramePreprocessor::SetInputFrameResampleMode( | |
41 VideoFrameResampling resampling_mode) { | |
42 spatial_resampler_->SetInputFrameResampleMode(resampling_mode); | |
43 } | |
44 | |
45 int32_t VPMFramePreprocessor::SetTargetResolution(uint32_t width, | |
46 uint32_t height, | |
47 uint32_t frame_rate) { | |
48 if ((width == 0) || (height == 0) || (frame_rate == 0)) { | |
49 return VPM_PARAMETER_ERROR; | |
50 } | |
51 int32_t ret_val = 0; | |
52 ret_val = spatial_resampler_->SetTargetFrameSize(width, height); | |
53 | |
54 if (ret_val < 0) | |
55 return ret_val; | |
56 | |
57 vd_->SetTargetFramerate(frame_rate); | |
58 return VPM_OK; | |
59 } | |
60 | |
61 void VPMFramePreprocessor::UpdateIncomingframe_rate() { | |
62 vd_->UpdateIncomingframe_rate(); | |
63 } | |
64 | |
65 uint32_t VPMFramePreprocessor::GetDecimatedFrameRate() { | |
66 return vd_->GetDecimatedFrameRate(); | |
67 } | |
68 | |
69 uint32_t VPMFramePreprocessor::GetDecimatedWidth() const { | |
70 return spatial_resampler_->TargetWidth(); | |
71 } | |
72 | |
73 uint32_t VPMFramePreprocessor::GetDecimatedHeight() const { | |
74 return spatial_resampler_->TargetHeight(); | |
75 } | |
76 | |
77 void VPMFramePreprocessor::EnableDenoising(bool enable) { | |
78 if (enable) { | |
79 denoiser_.reset(new VideoDenoiser(true)); | |
80 } else { | |
81 denoiser_.reset(); | |
82 } | |
83 } | |
84 | |
85 const VideoFrame* VPMFramePreprocessor::PreprocessFrame( | |
86 const VideoFrame& frame) { | |
87 if (frame.IsZeroSize()) { | |
88 return nullptr; | |
89 } | |
90 | |
91 vd_->UpdateIncomingframe_rate(); | |
92 if (vd_->DropFrame()) { | |
93 return nullptr; | |
94 } | |
95 | |
96 const VideoFrame* current_frame = &frame; | |
97 if (denoiser_) { | |
98 denoised_frame_ = VideoFrame( | |
99 denoiser_->DenoiseFrame(current_frame->video_frame_buffer(), true), | |
100 current_frame->timestamp(), current_frame->render_time_ms(), | |
101 current_frame->rotation()); | |
102 current_frame = &denoised_frame_; | |
103 } | |
104 | |
105 if (spatial_resampler_->ApplyResample(current_frame->width(), | |
106 current_frame->height())) { | |
107 if (spatial_resampler_->ResampleFrame(*current_frame, &resampled_frame_) != | |
108 VPM_OK) { | |
109 return nullptr; | |
110 } | |
111 current_frame = &resampled_frame_; | |
112 } | |
113 | |
114 ++frame_cnt_; | |
115 return current_frame; | |
116 } | |
117 | |
118 } // namespace webrtc | |
OLD | NEW |