Chromium Code Reviews| 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 | |
| 11 #include "webrtc/modules/video_processing/video_processing_impl.h" | |
| 12 | |
| 13 #include <assert.h> | |
| 14 | |
| 15 #include "webrtc/base/checks.h" | |
| 10 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 11 #include "webrtc/modules/video_processing/video_processing_impl.h" | |
| 12 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 17 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 13 | 18 |
| 14 #include <assert.h> | |
| 15 | 19 |
| 16 namespace webrtc { | 20 namespace webrtc { |
| 17 | 21 |
| 18 namespace { | 22 namespace { |
| 19 void SetSubSampling(VideoProcessingModule::FrameStats* stats, | 23 |
| 20 const int32_t width, | 24 int GetSubSamplingFactor(int width, int height) { |
| 21 const int32_t height) { | |
| 22 if (width * height >= 640 * 480) { | 25 if (width * height >= 640 * 480) { |
| 23 stats->subSamplWidth = 3; | 26 return 3; |
| 24 stats->subSamplHeight = 3; | |
| 25 } else if (width * height >= 352 * 288) { | 27 } else if (width * height >= 352 * 288) { |
| 26 stats->subSamplWidth = 2; | 28 return 2; |
| 27 stats->subSamplHeight = 2; | |
| 28 } else if (width * height >= 176 * 144) { | 29 } else if (width * height >= 176 * 144) { |
| 29 stats->subSamplWidth = 1; | 30 return 1; |
| 30 stats->subSamplHeight = 1; | |
| 31 } else { | 31 } else { |
| 32 stats->subSamplWidth = 0; | 32 return 0; |
| 33 stats->subSamplHeight = 0; | |
| 34 } | 33 } |
| 35 } | 34 } |
| 36 } // namespace | 35 } // namespace |
| 37 | 36 |
| 38 VideoProcessingModule* VideoProcessingModule::Create() { | 37 VideoProcessing* VideoProcessing::Create() { |
| 39 return new VideoProcessingModuleImpl(); | 38 return new VideoProcessingImpl(); |
| 40 } | 39 } |
| 41 | 40 |
| 42 void VideoProcessingModule::Destroy(VideoProcessingModule* module) { | 41 VideoProcessingImpl::VideoProcessingImpl() {} |
| 43 if (module) | 42 VideoProcessingImpl::~VideoProcessingImpl() {} |
| 44 delete static_cast<VideoProcessingModuleImpl*>(module); | |
| 45 } | |
| 46 | 43 |
| 47 VideoProcessingModuleImpl::VideoProcessingModuleImpl() {} | 44 int32_t VideoProcessing::GetFrameStats(const VideoFrame& frame, |
|
pbos-webrtc
2015/11/30 11:51:58
Make void.
mflodman
2015/12/04 15:01:08
Done.
| |
| 48 VideoProcessingModuleImpl::~VideoProcessingModuleImpl() {} | 45 FrameStats* stats) { |
| 49 | |
| 50 void VideoProcessingModuleImpl::Reset() { | |
| 51 rtc::CritScope mutex(&mutex_); | |
| 52 deflickering_.Reset(); | |
| 53 brightness_detection_.Reset(); | |
| 54 frame_pre_processor_.Reset(); | |
| 55 } | |
| 56 | |
| 57 int32_t VideoProcessingModule::GetFrameStats(FrameStats* stats, | |
| 58 const VideoFrame& frame) { | |
| 59 if (frame.IsZeroSize()) { | 46 if (frame.IsZeroSize()) { |
|
pbos-webrtc
2015/11/30 11:51:57
DCHECK here?
mflodman
2015/12/04 15:01:08
I don't know if that is ok, I'll follow up.
| |
| 60 LOG(LS_ERROR) << "Zero size frame."; | 47 LOG(LS_ERROR) << "Zero size frame."; |
| 61 return VPM_PARAMETER_ERROR; | 48 return VPM_PARAMETER_ERROR; |
| 62 } | 49 } |
| 63 | 50 |
| 64 int width = frame.width(); | 51 int width = frame.width(); |
| 65 int height = frame.height(); | 52 int height = frame.height(); |
| 66 | 53 |
| 67 ClearFrameStats(stats); // The histogram needs to be zeroed out. | 54 ClearFrameStats(stats); // The histogram needs to be zeroed out. |
| 68 SetSubSampling(stats, width, height); | 55 stats->sub_sampling_factor = GetSubSamplingFactor(width, height); |
| 69 | 56 |
| 70 const uint8_t* buffer = frame.buffer(kYPlane); | 57 const uint8_t* buffer = frame.buffer(kYPlane); |
| 71 // Compute histogram and sum of frame | 58 // Compute histogram and sum of frame |
| 72 for (int i = 0; i < height; i += (1 << stats->subSamplHeight)) { | 59 for (int i = 0; i < height; i += (1 << stats->sub_sampling_factor)) { |
| 73 int k = i * width; | 60 int k = i * width; |
| 74 for (int j = 0; j < width; j += (1 << stats->subSamplWidth)) { | 61 for (int j = 0; j < width; j += (1 << stats->sub_sampling_factor)) { |
| 75 stats->hist[buffer[k + j]]++; | 62 stats->hist[buffer[k + j]]++; |
| 76 stats->sum += buffer[k + j]; | 63 stats->sum += buffer[k + j]; |
| 77 } | 64 } |
| 78 } | 65 } |
| 79 | 66 |
| 80 stats->num_pixels = (width * height) / ((1 << stats->subSamplWidth) * | 67 stats->num_pixels = (width * height) / |
| 81 (1 << stats->subSamplHeight)); | 68 ((1 << stats->sub_sampling_factor) * (1 << stats->sub_sampling_factor)); |
| 82 assert(stats->num_pixels > 0); | 69 assert(stats->num_pixels > 0); |
| 83 | 70 |
| 84 // Compute mean value of frame | 71 // Compute mean value of frame |
| 85 stats->mean = stats->sum / stats->num_pixels; | 72 stats->mean = stats->sum / stats->num_pixels; |
| 86 | 73 |
| 87 return VPM_OK; | 74 return VPM_OK; |
| 88 } | 75 } |
| 89 | 76 |
| 90 bool VideoProcessingModule::ValidFrameStats(const FrameStats& stats) { | 77 bool VideoProcessing::ValidFrameStats(const FrameStats& stats) { |
| 91 if (stats.num_pixels == 0) { | 78 if (stats.num_pixels == 0) { |
| 92 LOG(LS_WARNING) << "Invalid frame stats."; | 79 LOG(LS_WARNING) << "Invalid frame stats."; |
| 93 return false; | 80 return false; |
| 94 } | 81 } |
| 95 return true; | 82 return true; |
| 96 } | 83 } |
| 97 | 84 |
| 98 void VideoProcessingModule::ClearFrameStats(FrameStats* stats) { | 85 void VideoProcessing::ClearFrameStats(FrameStats* stats) { |
| 99 stats->mean = 0; | 86 stats->mean = 0; |
| 100 stats->sum = 0; | 87 stats->sum = 0; |
| 101 stats->num_pixels = 0; | 88 stats->num_pixels = 0; |
| 102 stats->subSamplWidth = 0; | 89 stats->sub_sampling_factor = 0; |
| 103 stats->subSamplHeight = 0; | |
| 104 memset(stats->hist, 0, sizeof(stats->hist)); | 90 memset(stats->hist, 0, sizeof(stats->hist)); |
| 105 } | 91 } |
| 106 | 92 |
| 107 int32_t VideoProcessingModule::Brighten(VideoFrame* frame, int delta) { | 93 void VideoProcessing::Brighten(int delta, VideoFrame* frame) { |
| 108 return VideoProcessing::Brighten(frame, delta); | 94 RTC_DCHECK(!frame->IsZeroSize()); |
| 95 RTC_DCHECK(frame->width() > 0); | |
| 96 RTC_DCHECK(frame->height() > 0); | |
| 97 | |
| 98 int num_pixels = frame->width() * frame->height(); | |
| 99 | |
| 100 int look_up[256]; | |
| 101 for (int i = 0; i < 256; i++) { | |
| 102 int val = i + delta; | |
| 103 look_up[i] = ((((val < 0) ? 0 : val) > 255) ? 255 : val); | |
| 104 } | |
| 105 | |
| 106 uint8_t* temp_ptr = frame->buffer(kYPlane); | |
| 107 for (int i = 0; i < num_pixels; i++) { | |
| 108 *temp_ptr = static_cast<uint8_t>(look_up[*temp_ptr]); | |
| 109 temp_ptr++; | |
| 110 } | |
| 109 } | 111 } |
| 110 | 112 |
| 111 int32_t VideoProcessingModuleImpl::Deflickering(VideoFrame* frame, | 113 int32_t VideoProcessingImpl::Deflickering(VideoFrame* frame, |
| 112 FrameStats* stats) { | 114 FrameStats* stats) { |
| 113 rtc::CritScope mutex(&mutex_); | 115 rtc::CritScope mutex(&mutex_); |
| 114 return deflickering_.ProcessFrame(frame, stats); | 116 return deflickering_.ProcessFrame(frame, stats); |
| 115 } | 117 } |
| 116 | 118 |
| 117 int32_t VideoProcessingModuleImpl::BrightnessDetection( | 119 int32_t VideoProcessingImpl::BrightnessDetection( |
| 118 const VideoFrame& frame, | 120 const VideoFrame& frame, |
| 119 const FrameStats& stats) { | 121 const FrameStats& stats) { |
| 120 rtc::CritScope mutex(&mutex_); | 122 rtc::CritScope mutex(&mutex_); |
| 121 return brightness_detection_.ProcessFrame(frame, stats); | 123 return brightness_detection_.ProcessFrame(frame, stats); |
| 122 } | 124 } |
| 123 | 125 |
| 124 | 126 |
| 125 void VideoProcessingModuleImpl::EnableTemporalDecimation(bool enable) { | 127 void VideoProcessingImpl::EnableTemporalDecimation(bool enable) { |
| 126 rtc::CritScope mutex(&mutex_); | 128 rtc::CritScope mutex(&mutex_); |
| 127 frame_pre_processor_.EnableTemporalDecimation(enable); | 129 frame_pre_processor_.EnableTemporalDecimation(enable); |
| 128 } | 130 } |
| 129 | 131 |
| 130 | 132 |
| 131 void VideoProcessingModuleImpl::SetInputFrameResampleMode(VideoFrameResampling | 133 void VideoProcessingImpl::SetInputFrameResampleMode(VideoFrameResampling |
| 132 resampling_mode) { | 134 resampling_mode) { |
| 133 rtc::CritScope cs(&mutex_); | 135 rtc::CritScope cs(&mutex_); |
| 134 frame_pre_processor_.SetInputFrameResampleMode(resampling_mode); | 136 frame_pre_processor_.SetInputFrameResampleMode(resampling_mode); |
| 135 } | 137 } |
| 136 | 138 |
| 137 int32_t VideoProcessingModuleImpl::SetTargetResolution(uint32_t width, | 139 int32_t VideoProcessingImpl::SetTargetResolution(uint32_t width, |
| 138 uint32_t height, | 140 uint32_t height, |
| 139 uint32_t frame_rate) { | 141 uint32_t frame_rate) { |
| 140 rtc::CritScope cs(&mutex_); | 142 rtc::CritScope cs(&mutex_); |
| 141 return frame_pre_processor_.SetTargetResolution(width, height, frame_rate); | 143 return frame_pre_processor_.SetTargetResolution(width, height, frame_rate); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void VideoProcessingModuleImpl::SetTargetFramerate(int frame_rate) { | 146 void VideoProcessingImpl::SetTargetFramerate(int frame_rate) { |
| 145 rtc::CritScope cs(&mutex_); | 147 rtc::CritScope cs(&mutex_); |
| 146 frame_pre_processor_.SetTargetFramerate(frame_rate); | 148 frame_pre_processor_.SetTargetFramerate(frame_rate); |
| 147 } | 149 } |
| 148 | 150 |
| 149 uint32_t VideoProcessingModuleImpl::Decimatedframe_rate() { | 151 uint32_t VideoProcessingImpl::GetDecimatedFrameRate() { |
| 150 rtc::CritScope cs(&mutex_); | 152 rtc::CritScope cs(&mutex_); |
| 151 return frame_pre_processor_.Decimatedframe_rate(); | 153 return frame_pre_processor_.GetDecimatedFrameRate(); |
| 152 } | 154 } |
| 153 | 155 |
| 154 uint32_t VideoProcessingModuleImpl::DecimatedWidth() const { | 156 uint32_t VideoProcessingImpl::GetDecimatedWidth() const { |
| 155 rtc::CritScope cs(&mutex_); | 157 rtc::CritScope cs(&mutex_); |
| 156 return frame_pre_processor_.DecimatedWidth(); | 158 return frame_pre_processor_.GetDecimatedWidth(); |
| 157 } | 159 } |
| 158 | 160 |
| 159 uint32_t VideoProcessingModuleImpl::DecimatedHeight() const { | 161 uint32_t VideoProcessingImpl::GetDecimatedHeight() const { |
| 160 rtc::CritScope cs(&mutex_); | 162 rtc::CritScope cs(&mutex_); |
| 161 return frame_pre_processor_.DecimatedHeight(); | 163 return frame_pre_processor_.GetDecimatedHeight(); |
| 162 } | 164 } |
| 163 | 165 |
| 164 int32_t VideoProcessingModuleImpl::PreprocessFrame( | 166 void VideoProcessingImpl::EnableDenosing(bool enable) { |
| 165 const VideoFrame& frame, | 167 rtc::CritScope cs(&mutex_); |
| 166 VideoFrame** processed_frame) { | 168 frame_pre_processor_.EnableDenosing(enable); |
| 167 rtc::CritScope mutex(&mutex_); | |
| 168 return frame_pre_processor_.PreprocessFrame(frame, processed_frame); | |
| 169 } | 169 } |
| 170 | 170 |
| 171 VideoContentMetrics* VideoProcessingModuleImpl::ContentMetrics() const { | 171 const VideoFrame* VideoProcessingImpl::PreprocessFrame( |
| 172 const VideoFrame& frame) { | |
| 172 rtc::CritScope mutex(&mutex_); | 173 rtc::CritScope mutex(&mutex_); |
| 173 return frame_pre_processor_.ContentMetrics(); | 174 return frame_pre_processor_.PreprocessFrame(frame); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void VideoProcessingModuleImpl::EnableContentAnalysis(bool enable) { | 177 VideoContentMetrics* VideoProcessingImpl::GetContentMetrics() const { |
| 178 rtc::CritScope mutex(&mutex_); | |
| 179 return frame_pre_processor_.GetContentMetrics(); | |
| 180 } | |
| 181 | |
| 182 void VideoProcessingImpl::EnableContentAnalysis(bool enable) { | |
| 177 rtc::CritScope mutex(&mutex_); | 183 rtc::CritScope mutex(&mutex_); |
| 178 frame_pre_processor_.EnableContentAnalysis(enable); | 184 frame_pre_processor_.EnableContentAnalysis(enable); |
| 179 } | 185 } |
| 180 | 186 |
| 181 } // namespace webrtc | 187 } // namespace webrtc |
| OLD | NEW |