blob: b590756bfa069db3ed069cfa16fc0c6e50ca99eb [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 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
Henrik Kjellander0f59a882015-11-18 22:31:24 +010011#ifndef WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_
12#define WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010014#include "webrtc/modules/include/module_common_types.h"
Henrik Kjellander0f59a882015-11-18 22:31:24 +010015#include "webrtc/modules/video_processing/include/video_processing_defines.h"
Thiago Farina9bfe3da2015-04-10 12:52:13 +020016#include "webrtc/video_frame.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
mflodmana8565422015-12-07 01:09:52 -080018// The module is largely intended to process video streams, except functionality
19// provided by static functions which operate independent of previous frames. It
20// is recommended, but not required that a unique instance be used for each
21// concurrently processed stream. Similarly, it is recommended to call Reset()
22// before switching to a new stream, but this is not absolutely required.
23//
24// The module provides basic thread safety by permitting only a single function
25// to execute concurrently.
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27namespace webrtc {
28
mflodmana8565422015-12-07 01:09:52 -080029class VideoProcessing {
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000030 public:
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000031 struct FrameStats {
mflodmana8565422015-12-07 01:09:52 -080032 uint32_t hist[256]; // Frame histogram.
33 uint32_t mean;
34 uint32_t sum;
35 uint32_t num_pixels;
36 uint32_t sub_sampling_factor; // Sub-sampling factor, in powers of 2.
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000037 };
niklase@google.com470e71d2011-07-07 08:21:25 +000038
mflodman99ab9442015-12-07 22:54:50 -080039 enum BrightnessWarning { kNoWarning, kDarkWarning, kBrightWarning };
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000040
mflodmana8565422015-12-07 01:09:52 -080041 static VideoProcessing* Create();
42 virtual ~VideoProcessing() {}
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000043
mflodmana8565422015-12-07 01:09:52 -080044 // Retrieves statistics for the input frame. This function must be used to
45 // prepare a FrameStats struct for use in certain VPM functions.
46 static void GetFrameStats(const VideoFrame& frame, FrameStats* stats);
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000047
mflodmana8565422015-12-07 01:09:52 -080048 // Checks the validity of a FrameStats struct. Currently, valid implies only
49 // that is had changed from its initialized state.
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000050 static bool ValidFrameStats(const FrameStats& stats);
51
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000052 static void ClearFrameStats(FrameStats* stats);
53
mflodmana8565422015-12-07 01:09:52 -080054 // Increases/decreases the luminance value. 'delta' can be in the range {}
55 static void Brighten(int delta, VideoFrame* frame);
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000056
mflodmana8565422015-12-07 01:09:52 -080057 // Detects and removes camera flicker from a video stream. Every frame from
58 // the stream must be passed in. A frame will only be altered if flicker has
59 // been detected. Has a fixed-point implementation.
60 // Frame statistics provided by GetFrameStats(). On return the stats will
61 // be reset to zero if the frame was altered. Call GetFrameStats() again
62 // if the statistics for the altered frame are required.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070063 virtual int32_t Deflickering(VideoFrame* frame, FrameStats* stats) = 0;
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000064
mflodmana8565422015-12-07 01:09:52 -080065 // Detects if a video frame is excessively bright or dark. Returns a
66 // warning if this is the case. Multiple frames should be passed in before
67 // expecting a warning. Has a floating-point implementation.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070068 virtual int32_t BrightnessDetection(const VideoFrame& frame,
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000069 const FrameStats& stats) = 0;
70
mflodmana8565422015-12-07 01:09:52 -080071 // The following functions refer to the pre-processor unit within VPM. The
72 // pre-processor perfoms spatial/temporal decimation and content analysis on
73 // the frames prior to encoding.
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000074
mflodmana8565422015-12-07 01:09:52 -080075 // Enable/disable temporal decimation
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000076 virtual void EnableTemporalDecimation(bool enable) = 0;
77
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000078 virtual int32_t SetTargetResolution(uint32_t width,
79 uint32_t height,
80 uint32_t frame_rate) = 0;
81
mflodmana8565422015-12-07 01:09:52 -080082 virtual uint32_t GetDecimatedFrameRate() = 0;
83 virtual uint32_t GetDecimatedWidth() const = 0;
84 virtual uint32_t GetDecimatedHeight() const = 0;
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000085
mflodmana8565422015-12-07 01:09:52 -080086 // Set the spatial resampling settings of the VPM according to
87 // VideoFrameResampling.
88 virtual void SetInputFrameResampleMode(
89 VideoFrameResampling resampling_mode) = 0;
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000090
mflodmana8565422015-12-07 01:09:52 -080091 virtual void EnableDenosing(bool enable) = 0;
92 virtual const VideoFrame* PreprocessFrame(const VideoFrame& frame) = 0;
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000093
mflodmana8565422015-12-07 01:09:52 -080094 virtual VideoContentMetrics* GetContentMetrics() const = 0;
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000095 virtual void EnableContentAnalysis(bool enable) = 0;
96};
97
98} // namespace webrtc
99
Henrik Kjellander0f59a882015-11-18 22:31:24 +0100100#endif // WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_