Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: webrtc/modules/video_processing/main/source/video_processing_impl.cc

Issue 1410663004: modules/video_processing: refactor interface->include + more. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
12 #include "webrtc/modules/video_processing/main/source/video_processing_impl.h"
13 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
14 #include "webrtc/system_wrappers/include/logging.h"
15
16 #include <assert.h>
17
18 namespace webrtc {
19
20 namespace {
21 void SetSubSampling(VideoProcessingModule::FrameStats* stats,
22 const int32_t width,
23 const int32_t height) {
24 if (width * height >= 640 * 480) {
25 stats->subSamplWidth = 3;
26 stats->subSamplHeight = 3;
27 } else if (width * height >= 352 * 288) {
28 stats->subSamplWidth = 2;
29 stats->subSamplHeight = 2;
30 } else if (width * height >= 176 * 144) {
31 stats->subSamplWidth = 1;
32 stats->subSamplHeight = 1;
33 } else {
34 stats->subSamplWidth = 0;
35 stats->subSamplHeight = 0;
36 }
37 }
38 } // namespace
39
40 VideoProcessingModule* VideoProcessingModule::Create() {
41 return new VideoProcessingModuleImpl();
42 }
43
44 void VideoProcessingModule::Destroy(VideoProcessingModule* module) {
45 if (module)
46 delete static_cast<VideoProcessingModuleImpl*>(module);
47 }
48
49 VideoProcessingModuleImpl::VideoProcessingModuleImpl() {}
50 VideoProcessingModuleImpl::~VideoProcessingModuleImpl() {}
51
52 void VideoProcessingModuleImpl::Reset() {
53 rtc::CritScope mutex(&mutex_);
54 deflickering_.Reset();
55 brightness_detection_.Reset();
56 frame_pre_processor_.Reset();
57 }
58
59 int32_t VideoProcessingModule::GetFrameStats(FrameStats* stats,
60 const VideoFrame& frame) {
61 if (frame.IsZeroSize()) {
62 LOG(LS_ERROR) << "Zero size frame.";
63 return VPM_PARAMETER_ERROR;
64 }
65
66 int width = frame.width();
67 int height = frame.height();
68
69 ClearFrameStats(stats); // The histogram needs to be zeroed out.
70 SetSubSampling(stats, width, height);
71
72 const uint8_t* buffer = frame.buffer(kYPlane);
73 // Compute histogram and sum of frame
74 for (int i = 0; i < height; i += (1 << stats->subSamplHeight)) {
75 int k = i * width;
76 for (int j = 0; j < width; j += (1 << stats->subSamplWidth)) {
77 stats->hist[buffer[k + j]]++;
78 stats->sum += buffer[k + j];
79 }
80 }
81
82 stats->num_pixels = (width * height) / ((1 << stats->subSamplWidth) *
83 (1 << stats->subSamplHeight));
84 assert(stats->num_pixels > 0);
85
86 // Compute mean value of frame
87 stats->mean = stats->sum / stats->num_pixels;
88
89 return VPM_OK;
90 }
91
92 bool VideoProcessingModule::ValidFrameStats(const FrameStats& stats) {
93 if (stats.num_pixels == 0) {
94 LOG(LS_WARNING) << "Invalid frame stats.";
95 return false;
96 }
97 return true;
98 }
99
100 void VideoProcessingModule::ClearFrameStats(FrameStats* stats) {
101 stats->mean = 0;
102 stats->sum = 0;
103 stats->num_pixels = 0;
104 stats->subSamplWidth = 0;
105 stats->subSamplHeight = 0;
106 memset(stats->hist, 0, sizeof(stats->hist));
107 }
108
109 int32_t VideoProcessingModule::Brighten(VideoFrame* frame, int delta) {
110 return VideoProcessing::Brighten(frame, delta);
111 }
112
113 int32_t VideoProcessingModuleImpl::Deflickering(VideoFrame* frame,
114 FrameStats* stats) {
115 rtc::CritScope mutex(&mutex_);
116 return deflickering_.ProcessFrame(frame, stats);
117 }
118
119 int32_t VideoProcessingModuleImpl::BrightnessDetection(
120 const VideoFrame& frame,
121 const FrameStats& stats) {
122 rtc::CritScope mutex(&mutex_);
123 return brightness_detection_.ProcessFrame(frame, stats);
124 }
125
126
127 void VideoProcessingModuleImpl::EnableTemporalDecimation(bool enable) {
128 rtc::CritScope mutex(&mutex_);
129 frame_pre_processor_.EnableTemporalDecimation(enable);
130 }
131
132
133 void VideoProcessingModuleImpl::SetInputFrameResampleMode(VideoFrameResampling
134 resampling_mode) {
135 rtc::CritScope cs(&mutex_);
136 frame_pre_processor_.SetInputFrameResampleMode(resampling_mode);
137 }
138
139 int32_t VideoProcessingModuleImpl::SetTargetResolution(uint32_t width,
140 uint32_t height,
141 uint32_t frame_rate) {
142 rtc::CritScope cs(&mutex_);
143 return frame_pre_processor_.SetTargetResolution(width, height, frame_rate);
144 }
145
146 void VideoProcessingModuleImpl::SetTargetFramerate(int frame_rate) {
147 rtc::CritScope cs(&mutex_);
148 frame_pre_processor_.SetTargetFramerate(frame_rate);
149 }
150
151 uint32_t VideoProcessingModuleImpl::Decimatedframe_rate() {
152 rtc::CritScope cs(&mutex_);
153 return frame_pre_processor_.Decimatedframe_rate();
154 }
155
156 uint32_t VideoProcessingModuleImpl::DecimatedWidth() const {
157 rtc::CritScope cs(&mutex_);
158 return frame_pre_processor_.DecimatedWidth();
159 }
160
161 uint32_t VideoProcessingModuleImpl::DecimatedHeight() const {
162 rtc::CritScope cs(&mutex_);
163 return frame_pre_processor_.DecimatedHeight();
164 }
165
166 int32_t VideoProcessingModuleImpl::PreprocessFrame(
167 const VideoFrame& frame,
168 VideoFrame** processed_frame) {
169 rtc::CritScope mutex(&mutex_);
170 return frame_pre_processor_.PreprocessFrame(frame, processed_frame);
171 }
172
173 VideoContentMetrics* VideoProcessingModuleImpl::ContentMetrics() const {
174 rtc::CritScope mutex(&mutex_);
175 return frame_pre_processor_.ContentMetrics();
176 }
177
178 void VideoProcessingModuleImpl::EnableContentAnalysis(bool enable) {
179 rtc::CritScope mutex(&mutex_);
180 frame_pre_processor_.EnableContentAnalysis(enable);
181 }
182
183 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698