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/video_processing_impl.h" | 11 #include "webrtc/modules/video_processing/video_processing_impl.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
17 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 17 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
18 | 18 |
19 | |
20 namespace webrtc { | 19 namespace webrtc { |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 int GetSubSamplingFactor(int width, int height) { | 23 int GetSubSamplingFactor(int width, int height) { |
25 if (width * height >= 640 * 480) { | 24 if (width * height >= 640 * 480) { |
26 return 3; | 25 return 3; |
27 } else if (width * height >= 352 * 288) { | 26 } else if (width * height >= 352 * 288) { |
28 return 2; | 27 return 2; |
29 } else if (width * height >= 176 * 144) { | 28 } else if (width * height >= 176 * 144) { |
(...skipping 25 matching lines...) Expand all Loading... |
55 const uint8_t* buffer = frame.buffer(kYPlane); | 54 const uint8_t* buffer = frame.buffer(kYPlane); |
56 // Compute histogram and sum of frame | 55 // Compute histogram and sum of frame |
57 for (int i = 0; i < height; i += (1 << stats->sub_sampling_factor)) { | 56 for (int i = 0; i < height; i += (1 << stats->sub_sampling_factor)) { |
58 int k = i * width; | 57 int k = i * width; |
59 for (int j = 0; j < width; j += (1 << stats->sub_sampling_factor)) { | 58 for (int j = 0; j < width; j += (1 << stats->sub_sampling_factor)) { |
60 stats->hist[buffer[k + j]]++; | 59 stats->hist[buffer[k + j]]++; |
61 stats->sum += buffer[k + j]; | 60 stats->sum += buffer[k + j]; |
62 } | 61 } |
63 } | 62 } |
64 | 63 |
65 stats->num_pixels = (width * height) / | 64 stats->num_pixels = (width * height) / ((1 << stats->sub_sampling_factor) * |
66 ((1 << stats->sub_sampling_factor) * (1 << stats->sub_sampling_factor)); | 65 (1 << stats->sub_sampling_factor)); |
67 assert(stats->num_pixels > 0); | 66 assert(stats->num_pixels > 0); |
68 | 67 |
69 // Compute mean value of frame | 68 // Compute mean value of frame |
70 stats->mean = stats->sum / stats->num_pixels; | 69 stats->mean = stats->sum / stats->num_pixels; |
71 } | 70 } |
72 | 71 |
73 bool VideoProcessing::ValidFrameStats(const FrameStats& stats) { | 72 bool VideoProcessing::ValidFrameStats(const FrameStats& stats) { |
74 if (stats.num_pixels == 0) { | 73 if (stats.num_pixels == 0) { |
75 LOG(LS_WARNING) << "Invalid frame stats."; | 74 LOG(LS_WARNING) << "Invalid frame stats."; |
76 return false; | 75 return false; |
(...skipping 28 matching lines...) Expand all Loading... |
105 temp_ptr++; | 104 temp_ptr++; |
106 } | 105 } |
107 } | 106 } |
108 | 107 |
109 int32_t VideoProcessingImpl::Deflickering(VideoFrame* frame, | 108 int32_t VideoProcessingImpl::Deflickering(VideoFrame* frame, |
110 FrameStats* stats) { | 109 FrameStats* stats) { |
111 rtc::CritScope mutex(&mutex_); | 110 rtc::CritScope mutex(&mutex_); |
112 return deflickering_.ProcessFrame(frame, stats); | 111 return deflickering_.ProcessFrame(frame, stats); |
113 } | 112 } |
114 | 113 |
115 int32_t VideoProcessingImpl::BrightnessDetection( | 114 int32_t VideoProcessingImpl::BrightnessDetection(const VideoFrame& frame, |
116 const VideoFrame& frame, | 115 const FrameStats& stats) { |
117 const FrameStats& stats) { | |
118 rtc::CritScope mutex(&mutex_); | 116 rtc::CritScope mutex(&mutex_); |
119 return brightness_detection_.ProcessFrame(frame, stats); | 117 return brightness_detection_.ProcessFrame(frame, stats); |
120 } | 118 } |
121 | 119 |
122 | |
123 void VideoProcessingImpl::EnableTemporalDecimation(bool enable) { | 120 void VideoProcessingImpl::EnableTemporalDecimation(bool enable) { |
124 rtc::CritScope mutex(&mutex_); | 121 rtc::CritScope mutex(&mutex_); |
125 frame_pre_processor_.EnableTemporalDecimation(enable); | 122 frame_pre_processor_.EnableTemporalDecimation(enable); |
126 } | 123 } |
127 | 124 |
128 | 125 void VideoProcessingImpl::SetInputFrameResampleMode( |
129 void VideoProcessingImpl::SetInputFrameResampleMode(VideoFrameResampling | 126 VideoFrameResampling resampling_mode) { |
130 resampling_mode) { | |
131 rtc::CritScope cs(&mutex_); | 127 rtc::CritScope cs(&mutex_); |
132 frame_pre_processor_.SetInputFrameResampleMode(resampling_mode); | 128 frame_pre_processor_.SetInputFrameResampleMode(resampling_mode); |
133 } | 129 } |
134 | 130 |
135 int32_t VideoProcessingImpl::SetTargetResolution(uint32_t width, | 131 int32_t VideoProcessingImpl::SetTargetResolution(uint32_t width, |
136 uint32_t height, | 132 uint32_t height, |
137 uint32_t frame_rate) { | 133 uint32_t frame_rate) { |
138 rtc::CritScope cs(&mutex_); | 134 rtc::CritScope cs(&mutex_); |
139 return frame_pre_processor_.SetTargetResolution(width, height, frame_rate); | 135 return frame_pre_processor_.SetTargetResolution(width, height, frame_rate); |
140 } | 136 } |
141 | 137 |
142 void VideoProcessingImpl::SetTargetFramerate(int frame_rate) { | 138 void VideoProcessingImpl::SetTargetFramerate(int frame_rate) { |
143 rtc::CritScope cs(&mutex_); | 139 rtc::CritScope cs(&mutex_); |
144 frame_pre_processor_.SetTargetFramerate(frame_rate); | 140 frame_pre_processor_.SetTargetFramerate(frame_rate); |
145 } | 141 } |
146 | 142 |
147 uint32_t VideoProcessingImpl::GetDecimatedFrameRate() { | 143 uint32_t VideoProcessingImpl::GetDecimatedFrameRate() { |
148 rtc::CritScope cs(&mutex_); | 144 rtc::CritScope cs(&mutex_); |
149 return frame_pre_processor_.GetDecimatedFrameRate(); | 145 return frame_pre_processor_.GetDecimatedFrameRate(); |
150 } | 146 } |
151 | 147 |
152 uint32_t VideoProcessingImpl::GetDecimatedWidth() const { | 148 uint32_t VideoProcessingImpl::GetDecimatedWidth() const { |
153 rtc::CritScope cs(&mutex_); | 149 rtc::CritScope cs(&mutex_); |
154 return frame_pre_processor_.GetDecimatedWidth(); | 150 return frame_pre_processor_.GetDecimatedWidth(); |
155 } | 151 } |
156 | 152 |
157 uint32_t VideoProcessingImpl::GetDecimatedHeight() const { | 153 uint32_t VideoProcessingImpl::GetDecimatedHeight() const { |
158 rtc::CritScope cs(&mutex_); | 154 rtc::CritScope cs(&mutex_); |
159 return frame_pre_processor_.GetDecimatedHeight(); | 155 return frame_pre_processor_.GetDecimatedHeight(); |
(...skipping 14 matching lines...) Expand all Loading... |
174 rtc::CritScope mutex(&mutex_); | 170 rtc::CritScope mutex(&mutex_); |
175 return frame_pre_processor_.GetContentMetrics(); | 171 return frame_pre_processor_.GetContentMetrics(); |
176 } | 172 } |
177 | 173 |
178 void VideoProcessingImpl::EnableContentAnalysis(bool enable) { | 174 void VideoProcessingImpl::EnableContentAnalysis(bool enable) { |
179 rtc::CritScope mutex(&mutex_); | 175 rtc::CritScope mutex(&mutex_); |
180 frame_pre_processor_.EnableContentAnalysis(enable); | 176 frame_pre_processor_.EnableContentAnalysis(enable); |
181 } | 177 } |
182 | 178 |
183 } // namespace webrtc | 179 } // namespace webrtc |
OLD | NEW |