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

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

Issue 1482913003: Initial VideoProcessing refactoring. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Based on pbos review Created 5 years 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
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 void VideoProcessing::GetFrameStats(const VideoFrame& frame,
48 VideoProcessingModuleImpl::~VideoProcessingModuleImpl() {} 45 FrameStats* stats) {
49 46 ClearFrameStats(stats); // The histogram needs to be zeroed out.
pbos-webrtc 2015/12/04 15:04:59 If this is only true when frame.IsZeroSize() move
mflodman 2015/12/04 15:06:22 We should zero out the histogram anyway.
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()) { 47 if (frame.IsZeroSize()) {
60 LOG(LS_ERROR) << "Zero size frame."; 48 return;
61 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 stats->sub_sampling_factor = GetSubSamplingFactor(width, height);
67 ClearFrameStats(stats); // The histogram needs to be zeroed out.
68 SetSubSampling(stats, width, height);
69 54
70 const uint8_t* buffer = frame.buffer(kYPlane); 55 const uint8_t* buffer = frame.buffer(kYPlane);
71 // Compute histogram and sum of frame 56 // Compute histogram and sum of frame
72 for (int i = 0; i < height; i += (1 << stats->subSamplHeight)) { 57 for (int i = 0; i < height; i += (1 << stats->sub_sampling_factor)) {
73 int k = i * width; 58 int k = i * width;
74 for (int j = 0; j < width; j += (1 << stats->subSamplWidth)) { 59 for (int j = 0; j < width; j += (1 << stats->sub_sampling_factor)) {
75 stats->hist[buffer[k + j]]++; 60 stats->hist[buffer[k + j]]++;
76 stats->sum += buffer[k + j]; 61 stats->sum += buffer[k + j];
77 } 62 }
78 } 63 }
79 64
80 stats->num_pixels = (width * height) / ((1 << stats->subSamplWidth) * 65 stats->num_pixels = (width * height) /
81 (1 << stats->subSamplHeight)); 66 ((1 << stats->sub_sampling_factor) * (1 << stats->sub_sampling_factor));
82 assert(stats->num_pixels > 0); 67 assert(stats->num_pixels > 0);
83 68
84 // Compute mean value of frame 69 // Compute mean value of frame
85 stats->mean = stats->sum / stats->num_pixels; 70 stats->mean = stats->sum / stats->num_pixels;
86
87 return VPM_OK;
88 } 71 }
89 72
90 bool VideoProcessingModule::ValidFrameStats(const FrameStats& stats) { 73 bool VideoProcessing::ValidFrameStats(const FrameStats& stats) {
91 if (stats.num_pixels == 0) { 74 if (stats.num_pixels == 0) {
92 LOG(LS_WARNING) << "Invalid frame stats."; 75 LOG(LS_WARNING) << "Invalid frame stats.";
93 return false; 76 return false;
94 } 77 }
95 return true; 78 return true;
96 } 79 }
97 80
98 void VideoProcessingModule::ClearFrameStats(FrameStats* stats) { 81 void VideoProcessing::ClearFrameStats(FrameStats* stats) {
99 stats->mean = 0; 82 stats->mean = 0;
100 stats->sum = 0; 83 stats->sum = 0;
101 stats->num_pixels = 0; 84 stats->num_pixels = 0;
102 stats->subSamplWidth = 0; 85 stats->sub_sampling_factor = 0;
103 stats->subSamplHeight = 0;
104 memset(stats->hist, 0, sizeof(stats->hist)); 86 memset(stats->hist, 0, sizeof(stats->hist));
105 } 87 }
106 88
107 int32_t VideoProcessingModule::Brighten(VideoFrame* frame, int delta) { 89 void VideoProcessing::Brighten(int delta, VideoFrame* frame) {
108 return VideoProcessing::Brighten(frame, delta); 90 RTC_DCHECK(!frame->IsZeroSize());
91 RTC_DCHECK(frame->width() > 0);
92 RTC_DCHECK(frame->height() > 0);
93
94 int num_pixels = frame->width() * frame->height();
95
96 int look_up[256];
97 for (int i = 0; i < 256; i++) {
98 int val = i + delta;
99 look_up[i] = ((((val < 0) ? 0 : val) > 255) ? 255 : val);
100 }
101
102 uint8_t* temp_ptr = frame->buffer(kYPlane);
103 for (int i = 0; i < num_pixels; i++) {
104 *temp_ptr = static_cast<uint8_t>(look_up[*temp_ptr]);
105 temp_ptr++;
106 }
109 } 107 }
110 108
111 int32_t VideoProcessingModuleImpl::Deflickering(VideoFrame* frame, 109 int32_t VideoProcessingImpl::Deflickering(VideoFrame* frame,
112 FrameStats* stats) { 110 FrameStats* stats) {
113 rtc::CritScope mutex(&mutex_); 111 rtc::CritScope mutex(&mutex_);
114 return deflickering_.ProcessFrame(frame, stats); 112 return deflickering_.ProcessFrame(frame, stats);
115 } 113 }
116 114
117 int32_t VideoProcessingModuleImpl::BrightnessDetection( 115 int32_t VideoProcessingImpl::BrightnessDetection(
118 const VideoFrame& frame, 116 const VideoFrame& frame,
119 const FrameStats& stats) { 117 const FrameStats& stats) {
120 rtc::CritScope mutex(&mutex_); 118 rtc::CritScope mutex(&mutex_);
121 return brightness_detection_.ProcessFrame(frame, stats); 119 return brightness_detection_.ProcessFrame(frame, stats);
122 } 120 }
123 121
124 122
125 void VideoProcessingModuleImpl::EnableTemporalDecimation(bool enable) { 123 void VideoProcessingImpl::EnableTemporalDecimation(bool enable) {
126 rtc::CritScope mutex(&mutex_); 124 rtc::CritScope mutex(&mutex_);
127 frame_pre_processor_.EnableTemporalDecimation(enable); 125 frame_pre_processor_.EnableTemporalDecimation(enable);
128 } 126 }
129 127
130 128
131 void VideoProcessingModuleImpl::SetInputFrameResampleMode(VideoFrameResampling 129 void VideoProcessingImpl::SetInputFrameResampleMode(VideoFrameResampling
132 resampling_mode) { 130 resampling_mode) {
133 rtc::CritScope cs(&mutex_); 131 rtc::CritScope cs(&mutex_);
134 frame_pre_processor_.SetInputFrameResampleMode(resampling_mode); 132 frame_pre_processor_.SetInputFrameResampleMode(resampling_mode);
135 } 133 }
136 134
137 int32_t VideoProcessingModuleImpl::SetTargetResolution(uint32_t width, 135 int32_t VideoProcessingImpl::SetTargetResolution(uint32_t width,
138 uint32_t height, 136 uint32_t height,
139 uint32_t frame_rate) { 137 uint32_t frame_rate) {
140 rtc::CritScope cs(&mutex_); 138 rtc::CritScope cs(&mutex_);
141 return frame_pre_processor_.SetTargetResolution(width, height, frame_rate); 139 return frame_pre_processor_.SetTargetResolution(width, height, frame_rate);
142 } 140 }
143 141
144 void VideoProcessingModuleImpl::SetTargetFramerate(int frame_rate) { 142 void VideoProcessingImpl::SetTargetFramerate(int frame_rate) {
145 rtc::CritScope cs(&mutex_); 143 rtc::CritScope cs(&mutex_);
146 frame_pre_processor_.SetTargetFramerate(frame_rate); 144 frame_pre_processor_.SetTargetFramerate(frame_rate);
147 } 145 }
148 146
149 uint32_t VideoProcessingModuleImpl::Decimatedframe_rate() { 147 uint32_t VideoProcessingImpl::GetDecimatedFrameRate() {
150 rtc::CritScope cs(&mutex_); 148 rtc::CritScope cs(&mutex_);
151 return frame_pre_processor_.Decimatedframe_rate(); 149 return frame_pre_processor_.GetDecimatedFrameRate();
152 } 150 }
153 151
154 uint32_t VideoProcessingModuleImpl::DecimatedWidth() const { 152 uint32_t VideoProcessingImpl::GetDecimatedWidth() const {
155 rtc::CritScope cs(&mutex_); 153 rtc::CritScope cs(&mutex_);
156 return frame_pre_processor_.DecimatedWidth(); 154 return frame_pre_processor_.GetDecimatedWidth();
157 } 155 }
158 156
159 uint32_t VideoProcessingModuleImpl::DecimatedHeight() const { 157 uint32_t VideoProcessingImpl::GetDecimatedHeight() const {
160 rtc::CritScope cs(&mutex_); 158 rtc::CritScope cs(&mutex_);
161 return frame_pre_processor_.DecimatedHeight(); 159 return frame_pre_processor_.GetDecimatedHeight();
162 } 160 }
163 161
164 int32_t VideoProcessingModuleImpl::PreprocessFrame( 162 void VideoProcessingImpl::EnableDenosing(bool enable) {
165 const VideoFrame& frame, 163 rtc::CritScope cs(&mutex_);
166 VideoFrame** processed_frame) { 164 frame_pre_processor_.EnableDenosing(enable);
167 rtc::CritScope mutex(&mutex_);
168 return frame_pre_processor_.PreprocessFrame(frame, processed_frame);
169 } 165 }
170 166
171 VideoContentMetrics* VideoProcessingModuleImpl::ContentMetrics() const { 167 const VideoFrame* VideoProcessingImpl::PreprocessFrame(
168 const VideoFrame& frame) {
172 rtc::CritScope mutex(&mutex_); 169 rtc::CritScope mutex(&mutex_);
173 return frame_pre_processor_.ContentMetrics(); 170 return frame_pre_processor_.PreprocessFrame(frame);
174 } 171 }
175 172
176 void VideoProcessingModuleImpl::EnableContentAnalysis(bool enable) { 173 VideoContentMetrics* VideoProcessingImpl::GetContentMetrics() const {
174 rtc::CritScope mutex(&mutex_);
175 return frame_pre_processor_.GetContentMetrics();
176 }
177
178 void VideoProcessingImpl::EnableContentAnalysis(bool enable) {
177 rtc::CritScope mutex(&mutex_); 179 rtc::CritScope mutex(&mutex_);
178 frame_pre_processor_.EnableContentAnalysis(enable); 180 frame_pre_processor_.EnableContentAnalysis(enable);
179 } 181 }
180 182
181 } // namespace webrtc 183 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_processing/video_processing_impl.h ('k') | webrtc/video_engine/vie_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698