OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 /* | 11 /* |
12 * video_processing.h | 12 * video_processing.h |
13 * This header file contains the API required for the video | 13 * This header file contains the API required for the video |
14 * processing module class. | 14 * processing module class. |
15 */ | 15 */ |
16 | 16 |
17 | 17 |
18 #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ | 18 #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ |
19 #define WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ | 19 #define WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ |
20 | 20 |
21 #include "webrtc/modules/include/module.h" | |
22 #include "webrtc/modules/include/module_common_types.h" | 21 #include "webrtc/modules/include/module_common_types.h" |
23 #include "webrtc/modules/video_processing/include/video_processing_defines.h" | 22 #include "webrtc/modules/video_processing/include/video_processing_defines.h" |
24 #include "webrtc/video_frame.h" | 23 #include "webrtc/video_frame.h" |
25 | 24 |
26 /** | 25 // The module is largely intended to process video streams, except functionality |
27 The module is largely intended to process video streams, except functionality | 26 // provided by static functions which operate independent of previous frames. It |
28 provided by static functions which operate independent of previous frames. It | 27 // is recommended, but not required that a unique instance be used for each |
29 is recommended, but not required that a unique instance be used for each | 28 // concurrently processed stream. Similarly, it is recommended to call Reset() |
30 concurrently processed stream. Similarly, it is recommended to call Reset() | 29 // before switching to a new stream, but this is not absolutely required. |
31 before switching to a new stream, but this is not absolutely required. | 30 // |
32 | 31 // The module provides basic thread safety by permitting only a single function |
33 The module provides basic thread safety by permitting only a single function | 32 // to execute concurrently. |
34 to execute concurrently. | |
35 */ | |
36 | 33 |
37 namespace webrtc { | 34 namespace webrtc { |
38 | 35 |
39 class VideoProcessingModule : public Module { | 36 class VideoProcessing { |
40 public: | 37 public: |
41 /** | |
42 Structure to hold frame statistics. Populate it with GetFrameStats(). | |
43 */ | |
44 struct FrameStats { | 38 struct FrameStats { |
pbos-webrtc
2015/11/30 11:51:57
Q: Should these members even be initialized? Isn't
mflodman
2015/12/04 15:01:08
Init removed.
| |
45 FrameStats() : | 39 FrameStats() { |
46 mean(0), | 40 memset(hist, 0, sizeof(hist)); |
47 sum(0), | 41 } |
48 num_pixels(0), | |
49 subSamplWidth(0), | |
50 subSamplHeight(0) { | |
51 memset(hist, 0, sizeof(hist)); | |
52 } | |
53 | 42 |
54 uint32_t hist[256]; // FRame histogram. | 43 uint32_t hist[256]; // Frame histogram. |
pbos-webrtc
2015/11/30 11:51:57
I think you can do = {}; ?
| |
55 uint32_t mean; // Frame Mean value. | 44 uint32_t mean = 0; |
56 uint32_t sum; // Sum of frame. | 45 uint32_t sum = 0; |
57 uint32_t num_pixels; // Number of pixels. | 46 uint32_t num_pixels = 0; |
58 uint8_t subSamplWidth; // Subsampling rate of width in powers of 2. | 47 uint32_t sub_sampling_factor = 0; // Sub-sampling factor, in powers of 2. |
59 uint8_t subSamplHeight; // Subsampling rate of height in powers of 2. | |
60 }; | |
61 | |
62 /** | |
63 Specifies the warning types returned by BrightnessDetection(). | |
64 */ | |
65 enum BrightnessWarning { | |
66 kNoWarning, // Frame has acceptable brightness. | |
67 kDarkWarning, // Frame is too dark. | |
68 kBrightWarning // Frame is too bright. | |
69 }; | 48 }; |
70 | 49 |
71 /* | 50 enum BrightnessWarning { |
72 Creates a VPM object. | 51 kNoWarning, |
52 kDarkWarning, | |
53 kBrightWarning | |
54 }; | |
73 | 55 |
74 \param[in] id | 56 static VideoProcessing* Create(); |
75 Unique identifier of this object. | 57 virtual ~VideoProcessing() {} |
76 | 58 |
77 \return Pointer to a VPM object. | 59 // Retrieves statistics for the input frame. This function must be used to |
78 */ | 60 // prepare a FrameStats struct for use in certain VPM functions. |
79 static VideoProcessingModule* Create(); | 61 static int32_t GetFrameStats(const VideoFrame& frame, FrameStats* stats); |
80 | 62 |
81 /** | 63 // Checks the validity of a FrameStats struct. Currently, valid implies only |
82 Destroys a VPM object. | 64 // that is had changed from its initialized state. |
83 | |
84 \param[in] module | |
85 Pointer to the VPM object to destroy. | |
86 */ | |
87 static void Destroy(VideoProcessingModule* module); | |
88 | |
89 /** | |
90 Not supported. | |
91 */ | |
92 int64_t TimeUntilNextProcess() override { return -1; } | |
93 | |
94 /** | |
95 Not supported. | |
96 */ | |
97 int32_t Process() override { return -1; } | |
98 | |
99 /** | |
100 Resets all processing components to their initial states. This should be | |
101 called whenever a new video stream is started. | |
102 */ | |
103 virtual void Reset() = 0; | |
104 | |
105 /** | |
106 Retrieves statistics for the input frame. This function must be used to | |
107 prepare a FrameStats struct for use in certain VPM functions. | |
108 | |
109 \param[out] stats | |
110 The frame statistics will be stored here on return. | |
111 | |
112 \param[in] frame | |
113 Reference to the video frame. | |
114 | |
115 \return 0 on success, -1 on failure. | |
116 */ | |
117 static int32_t GetFrameStats(FrameStats* stats, const VideoFrame& frame); | |
118 | |
119 /** | |
120 Checks the validity of a FrameStats struct. Currently, valid implies only | |
121 that is had changed from its initialized state. | |
122 | |
123 \param[in] stats | |
124 Frame statistics. | |
125 | |
126 \return True on valid stats, false on invalid stats. | |
127 */ | |
128 static bool ValidFrameStats(const FrameStats& stats); | 65 static bool ValidFrameStats(const FrameStats& stats); |
pbos-webrtc
2015/11/30 11:51:57
Do we really need this? :\
mflodman
2015/12/04 15:01:08
Maybe not, but I'd prefer to go at this depth in a
| |
129 | 66 |
130 /** | |
131 Returns a FrameStats struct to its intialized state. | |
132 | |
133 \param[in,out] stats | |
134 Frame statistics. | |
135 */ | |
136 static void ClearFrameStats(FrameStats* stats); | 67 static void ClearFrameStats(FrameStats* stats); |
pbos-webrtc
2015/11/30 11:51:57
Same here? If we need it (I don't see why), we sho
mflodman
2015/12/04 15:01:08
On 2015/11/30 11:51:57, pbos-webrtc wrote:
> Same
| |
137 | 68 |
138 /** | 69 // Increases/decreases the luminance value. 'delta' can be in the range {} |
139 Increases/decreases the luminance value. | 70 static void Brighten(int delta, VideoFrame* frame); |
140 | 71 |
141 \param[in,out] frame | 72 // Detects and removes camera flicker from a video stream. Every frame from |
142 Pointer to the video frame. | 73 // the stream must be passed in. A frame will only be altered if flicker has |
143 | 74 // been detected. Has a fixed-point implementation. |
144 \param[in] delta | 75 // Frame statistics provided by GetFrameStats(). On return the stats will |
145 The amount to change the chrominance value of every single pixel. | 76 // be reset to zero if the frame was altered. Call GetFrameStats() again |
146 Can be < 0 also. | 77 // if the statistics for the altered frame are required. |
147 | |
148 \return 0 on success, -1 on failure. | |
149 */ | |
150 static int32_t Brighten(VideoFrame* frame, int delta); | |
151 | |
152 /** | |
153 Detects and removes camera flicker from a video stream. Every frame from | |
154 the stream must be passed in. A frame will only be altered if flicker has | |
155 been detected. Has a fixed-point implementation. | |
156 | |
157 \param[in,out] frame | |
158 Pointer to the video frame. | |
159 | |
160 \param[in,out] stats | |
161 Frame statistics provided by GetFrameStats(). On return the stats will | |
162 be reset to zero if the frame was altered. Call GetFrameStats() again | |
163 if the statistics for the altered frame are required. | |
164 | |
165 \return 0 on success, -1 on failure. | |
166 */ | |
167 virtual int32_t Deflickering(VideoFrame* frame, FrameStats* stats) = 0; | 78 virtual int32_t Deflickering(VideoFrame* frame, FrameStats* stats) = 0; |
168 | 79 |
169 /** | 80 // Detects if a video frame is excessively bright or dark. Returns a |
170 Detects if a video frame is excessively bright or dark. Returns a | 81 // warning if this is the case. Multiple frames should be passed in before |
171 warning if this is the case. Multiple frames should be passed in before | 82 // expecting a warning. Has a floating-point implementation. |
172 expecting a warning. Has a floating-point implementation. | |
173 | |
174 \param[in] frame | |
175 Pointer to the video frame. | |
176 | |
177 \param[in] stats | |
178 Frame statistics provided by GetFrameStats(). | |
179 | |
180 \return A member of BrightnessWarning on success, -1 on error | |
181 */ | |
182 virtual int32_t BrightnessDetection(const VideoFrame& frame, | 83 virtual int32_t BrightnessDetection(const VideoFrame& frame, |
183 const FrameStats& stats) = 0; | 84 const FrameStats& stats) = 0; |
184 | 85 |
185 /** | 86 // The following functions refer to the pre-processor unit within VPM. The |
186 The following functions refer to the pre-processor unit within VPM. The | 87 // pre-processor perfoms spatial/temporal decimation and content analysis on |
187 pre-processor perfoms spatial/temporal decimation and content analysis on | 88 // the frames prior to encoding. |
188 the frames prior to encoding. | |
189 */ | |
190 | 89 |
191 /** | 90 // Enable/disable temporal decimation |
192 Enable/disable temporal decimation | |
193 | |
194 \param[in] enable when true, temporal decimation is enabled | |
195 */ | |
196 virtual void EnableTemporalDecimation(bool enable) = 0; | 91 virtual void EnableTemporalDecimation(bool enable) = 0; |
197 | 92 |
198 /** | |
199 Set target resolution | |
200 | |
201 \param[in] width | |
202 Target width | |
203 | |
204 \param[in] height | |
205 Target height | |
206 | |
207 \param[in] frame_rate | |
208 Target frame_rate | |
209 | |
210 \return VPM_OK on success, a negative value on error (see error codes) | |
211 | |
212 */ | |
213 virtual int32_t SetTargetResolution(uint32_t width, | 93 virtual int32_t SetTargetResolution(uint32_t width, |
214 uint32_t height, | 94 uint32_t height, |
215 uint32_t frame_rate) = 0; | 95 uint32_t frame_rate) = 0; |
216 | 96 |
217 virtual void SetTargetFramerate(int frame_rate) {} | 97 virtual void SetTargetFramerate(int frame_rate) = 0; |
218 | 98 |
219 /** | 99 virtual uint32_t GetDecimatedFrameRate() = 0; |
220 Get decimated(target) frame rate | 100 virtual uint32_t GetDecimatedWidth() const = 0; |
221 */ | 101 virtual uint32_t GetDecimatedHeight() const = 0; |
222 virtual uint32_t Decimatedframe_rate() = 0; | |
223 | 102 |
224 /** | 103 // Set the spatial resampling settings of the VPM according to |
225 Get decimated(target) frame width | 104 // VideoFrameResampling. |
226 */ | 105 virtual void SetInputFrameResampleMode( |
227 virtual uint32_t DecimatedWidth() const = 0; | 106 VideoFrameResampling resampling_mode) = 0; |
228 | 107 |
229 /** | 108 virtual void EnableDenosing(bool enable) = 0; |
230 Get decimated(target) frame height | 109 virtual const VideoFrame* PreprocessFrame(const VideoFrame& frame) = 0; |
231 */ | |
232 virtual uint32_t DecimatedHeight() const = 0 ; | |
233 | 110 |
234 /** | 111 virtual VideoContentMetrics* GetContentMetrics() const = 0; |
235 Set the spatial resampling settings of the VPM: The resampler may either be | |
236 disabled or one of the following: | |
237 scaling to a close to target dimension followed by crop/pad | |
238 | |
239 \param[in] resampling_mode | |
240 Set resampling mode (a member of VideoFrameResampling) | |
241 */ | |
242 virtual void SetInputFrameResampleMode(VideoFrameResampling | |
243 resampling_mode) = 0; | |
244 | |
245 /** | |
246 Get Processed (decimated) frame | |
247 | |
248 \param[in] frame pointer to the video frame. | |
249 \param[in] processed_frame pointer (double) to the processed frame. If no | |
250 processing is required, processed_frame will be NULL. | |
251 | |
252 \return VPM_OK on success, a negative value on error (see error codes) | |
253 */ | |
254 virtual int32_t PreprocessFrame(const VideoFrame& frame, | |
255 VideoFrame** processed_frame) = 0; | |
256 | |
257 /** | |
258 Return content metrics for the last processed frame | |
259 */ | |
260 virtual VideoContentMetrics* ContentMetrics() const = 0 ; | |
261 | |
262 /** | |
263 Enable content analysis | |
264 */ | |
265 virtual void EnableContentAnalysis(bool enable) = 0; | 112 virtual void EnableContentAnalysis(bool enable) = 0; |
266 }; | 113 }; |
267 | 114 |
268 } // namespace webrtc | 115 } // namespace webrtc |
269 | 116 |
270 #endif // WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ | 117 #endif // WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ |
OLD | NEW |