2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
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.
13 * This header file contains the API required for the video
14 * processing module class.
18 #ifndef WEBRTC_MODULES_INTERFACE_VIDEO_PROCESSING_H
19 #define WEBRTC_MODULES_INTERFACE_VIDEO_PROCESSING_H
21 #include "webrtc/common_video/interface/i420_video_frame.h"
22 #include "webrtc/modules/interface/module.h"
23 #include "webrtc/modules/interface/module_common_types.h"
24 #include "webrtc/modules/video_processing/main/interface/video_processing_defines.h"
27 The module is largely intended to process video streams, except functionality
28 provided by static functions which operate independent of previous frames. It
29 is recommended, but not required that a unique instance be used for each
30 concurrently processed stream. Similarly, it is recommended to call Reset()
31 before switching to a new stream, but this is not absolutely required.
33 The module provides basic thread safety by permitting only a single function
34 to execute concurrently.
39 class VideoProcessingModule : public Module {
42 Structure to hold frame statistics. Populate it with GetFrameStats().
51 memset(hist, 0, sizeof(hist));
54 uint32_t hist[256]; // FRame histogram.
55 uint32_t mean; // Frame Mean value.
56 uint32_t sum; // Sum of frame.
57 uint32_t num_pixels; // Number of pixels.
58 uint8_t subSamplWidth; // Subsampling rate of width in powers of 2.
59 uint8_t subSamplHeight; // Subsampling rate of height in powers of 2.
63 Specifies the warning types returned by BrightnessDetection().
65 enum BrightnessWarning {
66 kNoWarning, // Frame has acceptable brightness.
67 kDarkWarning, // Frame is too dark.
68 kBrightWarning // Frame is too bright.
75 Unique identifier of this object.
77 \return Pointer to a VPM object.
79 static VideoProcessingModule* Create(int32_t id);
82 Destroys a VPM object.
85 Pointer to the VPM object to destroy.
87 static void Destroy(VideoProcessingModule* module);
92 virtual int32_t TimeUntilNextProcess() { return -1; }
97 virtual int32_t Process() { return -1; }
100 Resets all processing components to their initial states. This should be
101 called whenever a new video stream is started.
103 virtual void Reset() = 0;
106 Retrieves statistics for the input frame. This function must be used to
107 prepare a FrameStats struct for use in certain VPM functions.
110 The frame statistics will be stored here on return.
113 Reference to the video frame.
115 \return 0 on success, -1 on failure.
117 static int32_t GetFrameStats(FrameStats* stats,
118 const I420VideoFrame& frame);
121 Checks the validity of a FrameStats struct. Currently, valid implies only
122 that is had changed from its initialized state.
127 \return True on valid stats, false on invalid stats.
129 static bool ValidFrameStats(const FrameStats& stats);
132 Returns a FrameStats struct to its intialized state.
137 static void ClearFrameStats(FrameStats* stats);
140 Enhances the color of an image through a constant mapping. Only the
141 chrominance is altered. Has a fixed-point implementation.
144 Pointer to the video frame.
146 static int32_t ColorEnhancement(I420VideoFrame* frame);
149 Increases/decreases the luminance value.
152 Pointer to the video frame.
155 The amount to change the chrominance value of every single pixel.
158 \return 0 on success, -1 on failure.
160 static int32_t Brighten(I420VideoFrame* frame, int delta);
163 Detects and removes camera flicker from a video stream. Every frame from
164 the stream must be passed in. A frame will only be altered if flicker has
165 been detected. Has a fixed-point implementation.
168 Pointer to the video frame.
171 Frame statistics provided by GetFrameStats(). On return the stats will
172 be reset to zero if the frame was altered. Call GetFrameStats() again
173 if the statistics for the altered frame are required.
175 \return 0 on success, -1 on failure.
177 virtual int32_t Deflickering(I420VideoFrame* frame, FrameStats* stats) = 0;
180 Detects if a video frame is excessively bright or dark. Returns a
181 warning if this is the case. Multiple frames should be passed in before
182 expecting a warning. Has a floating-point implementation.
185 Pointer to the video frame.
188 Frame statistics provided by GetFrameStats().
190 \return A member of BrightnessWarning on success, -1 on error
192 virtual int32_t BrightnessDetection(const I420VideoFrame& frame,
193 const FrameStats& stats) = 0;
196 The following functions refer to the pre-processor unit within VPM. The
197 pre-processor perfoms spatial/temporal decimation and content analysis on
198 the frames prior to encoding.
202 Enable/disable temporal decimation
204 \param[in] enable when true, temporal decimation is enabled
206 virtual void EnableTemporalDecimation(bool enable) = 0;
209 Set target resolution
217 \param[in] frame_rate
220 \return VPM_OK on success, a negative value on error (see error codes)
223 virtual int32_t SetTargetResolution(uint32_t width,
225 uint32_t frame_rate) = 0;
228 Get decimated(target) frame rate
230 virtual uint32_t Decimatedframe_rate() = 0;
233 Get decimated(target) frame width
235 virtual uint32_t DecimatedWidth() const = 0;
238 Get decimated(target) frame height
240 virtual uint32_t DecimatedHeight() const = 0 ;
243 Set the spatial resampling settings of the VPM: The resampler may either be
244 disabled or one of the following:
245 scaling to a close to target dimension followed by crop/pad
247 \param[in] resampling_mode
248 Set resampling mode (a member of VideoFrameResampling)
250 virtual void SetInputFrameResampleMode(VideoFrameResampling
251 resampling_mode) = 0;
254 Get Processed (decimated) frame
256 \param[in] frame pointer to the video frame.
257 \param[in] processed_frame pointer (double) to the processed frame. If no
258 processing is required, processed_frame will be NULL.
260 \return VPM_OK on success, a negative value on error (see error codes)
262 virtual int32_t PreprocessFrame(const I420VideoFrame& frame,
263 I420VideoFrame** processed_frame) = 0;
266 Return content metrics for the last processed frame
268 virtual VideoContentMetrics* ContentMetrics() const = 0 ;
271 Enable content analysis
273 virtual void EnableContentAnalysis(bool enable) = 0;
276 } // namespace webrtc
278 #endif // WEBRTC_MODULES_INTERFACE_VIDEO_PROCESSING_H