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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 vd_ = new VPMVideoDecimator(); | 24 vd_ = new VPMVideoDecimator(); |
25 } | 25 } |
26 | 26 |
27 VPMFramePreprocessor::~VPMFramePreprocessor() { | 27 VPMFramePreprocessor::~VPMFramePreprocessor() { |
28 Reset(); | 28 Reset(); |
29 delete ca_; | 29 delete ca_; |
30 delete vd_; | 30 delete vd_; |
31 delete spatial_resampler_; | 31 delete spatial_resampler_; |
32 } | 32 } |
33 | 33 |
34 void VPMFramePreprocessor::Reset() { | 34 void VPMFramePreprocessor::Reset() { |
35 ca_->Release(); | 35 ca_->Release(); |
36 vd_->Reset(); | 36 vd_->Reset(); |
37 content_metrics_ = nullptr; | 37 content_metrics_ = nullptr; |
38 spatial_resampler_->Reset(); | 38 spatial_resampler_->Reset(); |
39 enable_ca_ = false; | 39 enable_ca_ = false; |
40 frame_cnt_ = 0; | 40 frame_cnt_ = 0; |
41 } | 41 } |
42 | 42 |
43 void VPMFramePreprocessor::EnableTemporalDecimation(bool enable) { | 43 void VPMFramePreprocessor::EnableTemporalDecimation(bool enable) { |
44 vd_->EnableTemporalDecimation(enable); | 44 vd_->EnableTemporalDecimation(enable); |
45 } | 45 } |
46 | 46 |
47 void VPMFramePreprocessor::EnableContentAnalysis(bool enable) { | 47 void VPMFramePreprocessor::EnableContentAnalysis(bool enable) { |
48 enable_ca_ = enable; | 48 enable_ca_ = enable; |
49 } | 49 } |
50 | 50 |
51 void VPMFramePreprocessor::SetInputFrameResampleMode( | 51 void VPMFramePreprocessor::SetInputFrameResampleMode( |
52 VideoFrameResampling resampling_mode) { | 52 VideoFrameResampling resampling_mode) { |
53 spatial_resampler_->SetInputFrameResampleMode(resampling_mode); | 53 spatial_resampler_->SetInputFrameResampleMode(resampling_mode); |
54 } | 54 } |
55 | 55 |
56 int32_t VPMFramePreprocessor::SetTargetResolution( | 56 int32_t VPMFramePreprocessor::SetTargetResolution(uint32_t width, |
57 uint32_t width, uint32_t height, uint32_t frame_rate) { | 57 uint32_t height, |
| 58 uint32_t frame_rate) { |
58 if ((width == 0) || (height == 0) || (frame_rate == 0)) { | 59 if ((width == 0) || (height == 0) || (frame_rate == 0)) { |
59 return VPM_PARAMETER_ERROR; | 60 return VPM_PARAMETER_ERROR; |
60 } | 61 } |
61 int32_t ret_val = 0; | 62 int32_t ret_val = 0; |
62 ret_val = spatial_resampler_->SetTargetFrameSize(width, height); | 63 ret_val = spatial_resampler_->SetTargetFrameSize(width, height); |
63 | 64 |
64 if (ret_val < 0) return ret_val; | 65 if (ret_val < 0) |
| 66 return ret_val; |
65 | 67 |
66 vd_->SetTargetFramerate(frame_rate); | 68 vd_->SetTargetFramerate(frame_rate); |
67 return VPM_OK; | 69 return VPM_OK; |
68 } | 70 } |
69 | 71 |
70 void VPMFramePreprocessor::SetTargetFramerate(int frame_rate) { | 72 void VPMFramePreprocessor::SetTargetFramerate(int frame_rate) { |
71 if (frame_rate == -1) { | 73 if (frame_rate == -1) { |
72 vd_->EnableTemporalDecimation(false); | 74 vd_->EnableTemporalDecimation(false); |
73 } else { | 75 } else { |
74 vd_->EnableTemporalDecimation(true); | 76 vd_->EnableTemporalDecimation(true); |
75 vd_->SetTargetFramerate(frame_rate); | 77 vd_->SetTargetFramerate(frame_rate); |
76 } | 78 } |
77 } | 79 } |
78 | 80 |
79 void VPMFramePreprocessor::UpdateIncomingframe_rate() { | 81 void VPMFramePreprocessor::UpdateIncomingframe_rate() { |
80 vd_->UpdateIncomingframe_rate(); | 82 vd_->UpdateIncomingframe_rate(); |
81 } | 83 } |
82 | 84 |
83 uint32_t VPMFramePreprocessor::GetDecimatedFrameRate() { | 85 uint32_t VPMFramePreprocessor::GetDecimatedFrameRate() { |
84 return vd_->GetDecimatedFrameRate(); | 86 return vd_->GetDecimatedFrameRate(); |
85 } | 87 } |
86 | 88 |
87 | |
88 uint32_t VPMFramePreprocessor::GetDecimatedWidth() const { | 89 uint32_t VPMFramePreprocessor::GetDecimatedWidth() const { |
89 return spatial_resampler_->TargetWidth(); | 90 return spatial_resampler_->TargetWidth(); |
90 } | 91 } |
91 | 92 |
92 | |
93 uint32_t VPMFramePreprocessor::GetDecimatedHeight() const { | 93 uint32_t VPMFramePreprocessor::GetDecimatedHeight() const { |
94 return spatial_resampler_->TargetHeight(); | 94 return spatial_resampler_->TargetHeight(); |
95 } | 95 } |
96 | 96 |
97 void VPMFramePreprocessor::EnableDenosing(bool enable) { | 97 void VPMFramePreprocessor::EnableDenosing(bool enable) { |
98 denoiser_.reset(new VideoDenoiser()); | 98 denoiser_.reset(new VideoDenoiser()); |
99 } | 99 } |
100 | 100 |
101 const VideoFrame* VPMFramePreprocessor::PreprocessFrame( | 101 const VideoFrame* VPMFramePreprocessor::PreprocessFrame( |
102 const VideoFrame& frame) { | 102 const VideoFrame& frame) { |
103 if (frame.IsZeroSize()) { | 103 if (frame.IsZeroSize()) { |
104 return nullptr; | 104 return nullptr; |
105 } | 105 } |
106 | 106 |
107 vd_->UpdateIncomingframe_rate(); | 107 vd_->UpdateIncomingframe_rate(); |
108 if (vd_->DropFrame()) { | 108 if (vd_->DropFrame()) { |
109 return nullptr; | 109 return nullptr; |
110 } | 110 } |
111 | 111 |
112 const VideoFrame* current_frame = &frame; | 112 const VideoFrame* current_frame = &frame; |
113 if (denoiser_) { | 113 if (denoiser_) { |
114 denoiser_->DenoiseFrame(*current_frame, &denoised_frame_); | 114 denoiser_->DenoiseFrame(*current_frame, &denoised_frame_); |
115 current_frame = &denoised_frame_; | 115 current_frame = &denoised_frame_; |
116 } | 116 } |
117 | 117 |
118 if (spatial_resampler_->ApplyResample(current_frame->width(), | 118 if (spatial_resampler_->ApplyResample(current_frame->width(), |
119 current_frame->height())) { | 119 current_frame->height())) { |
120 if (spatial_resampler_->ResampleFrame(*current_frame, &resampled_frame_) != | 120 if (spatial_resampler_->ResampleFrame(*current_frame, &resampled_frame_) != |
121 VPM_OK) { | 121 VPM_OK) { |
122 return nullptr; | 122 return nullptr; |
123 } | 123 } |
124 current_frame = &resampled_frame_; | 124 current_frame = &resampled_frame_; |
125 } | 125 } |
126 | 126 |
127 // Perform content analysis on the frame to be encoded. | 127 // Perform content analysis on the frame to be encoded. |
128 if (enable_ca_ && frame_cnt_ % kSkipFrameCA == 0) { | 128 if (enable_ca_ && frame_cnt_ % kSkipFrameCA == 0) { |
129 // Compute new metrics every |kSkipFramesCA| frames, starting with | 129 // Compute new metrics every |kSkipFramesCA| frames, starting with |
130 // the first frame. | 130 // the first frame. |
131 content_metrics_ = ca_->ComputeContentMetrics(*current_frame); | 131 content_metrics_ = ca_->ComputeContentMetrics(*current_frame); |
132 } | 132 } |
133 ++frame_cnt_; | 133 ++frame_cnt_; |
134 return current_frame; | 134 return current_frame; |
135 } | 135 } |
136 | 136 |
137 VideoContentMetrics* VPMFramePreprocessor::GetContentMetrics() const { | 137 VideoContentMetrics* VPMFramePreprocessor::GetContentMetrics() const { |
138 return content_metrics_; | 138 return content_metrics_; |
139 } | 139 } |
140 | 140 |
141 } // namespace webrtc | 141 } // namespace webrtc |
OLD | NEW |