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

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

Powered by Google App Engine
This is Rietveld 408576698