niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 11 | /* |
| 12 | * video_processing.h |
| 13 | * This header file contains the API required for the video |
| 14 | * processing module class. |
| 15 | */ |
| 16 | |
| 17 | |
Henrik Kjellander | 0f59a88 | 2015-11-18 22:31:24 +0100 | [diff] [blame] | 18 | #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ |
| 19 | #define WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 21 | #include "webrtc/modules/include/module_common_types.h" |
Henrik Kjellander | 0f59a88 | 2015-11-18 22:31:24 +0100 | [diff] [blame] | 22 | #include "webrtc/modules/video_processing/include/video_processing_defines.h" |
Thiago Farina | 9bfe3da | 2015-04-10 12:52:13 +0200 | [diff] [blame] | 23 | #include "webrtc/video_frame.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 25 | // The module is largely intended to process video streams, except functionality |
| 26 | // 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 |
| 28 | // concurrently processed stream. Similarly, it is recommended to call Reset() |
| 29 | // before switching to a new stream, but this is not absolutely required. |
| 30 | // |
| 31 | // The module provides basic thread safety by permitting only a single function |
| 32 | // to execute concurrently. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
| 34 | namespace webrtc { |
| 35 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 36 | class VideoProcessing { |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 37 | public: |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 38 | struct FrameStats { |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 39 | uint32_t hist[256]; // Frame histogram. |
| 40 | uint32_t mean; |
| 41 | uint32_t sum; |
| 42 | uint32_t num_pixels; |
| 43 | uint32_t sub_sampling_factor; // Sub-sampling factor, in powers of 2. |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 44 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 46 | enum BrightnessWarning { |
| 47 | kNoWarning, |
| 48 | kDarkWarning, |
| 49 | kBrightWarning |
| 50 | }; |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 51 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 52 | static VideoProcessing* Create(); |
| 53 | virtual ~VideoProcessing() {} |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 54 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 55 | // Retrieves statistics for the input frame. This function must be used to |
| 56 | // prepare a FrameStats struct for use in certain VPM functions. |
| 57 | static void GetFrameStats(const VideoFrame& frame, FrameStats* stats); |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 58 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 59 | // Checks the validity of a FrameStats struct. Currently, valid implies only |
| 60 | // that is had changed from its initialized state. |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 61 | static bool ValidFrameStats(const FrameStats& stats); |
| 62 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 63 | static void ClearFrameStats(FrameStats* stats); |
| 64 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 65 | // Increases/decreases the luminance value. 'delta' can be in the range {} |
| 66 | static void Brighten(int delta, VideoFrame* frame); |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 67 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 68 | // Detects and removes camera flicker from a video stream. Every frame from |
| 69 | // the stream must be passed in. A frame will only be altered if flicker has |
| 70 | // been detected. Has a fixed-point implementation. |
| 71 | // Frame statistics provided by GetFrameStats(). On return the stats will |
| 72 | // be reset to zero if the frame was altered. Call GetFrameStats() again |
| 73 | // if the statistics for the altered frame are required. |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 74 | virtual int32_t Deflickering(VideoFrame* frame, FrameStats* stats) = 0; |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 75 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 76 | // Detects if a video frame is excessively bright or dark. Returns a |
| 77 | // warning if this is the case. Multiple frames should be passed in before |
| 78 | // expecting a warning. Has a floating-point implementation. |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 79 | virtual int32_t BrightnessDetection(const VideoFrame& frame, |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 80 | const FrameStats& stats) = 0; |
| 81 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 82 | // The following functions refer to the pre-processor unit within VPM. The |
| 83 | // pre-processor perfoms spatial/temporal decimation and content analysis on |
| 84 | // the frames prior to encoding. |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 85 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 86 | // Enable/disable temporal decimation |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 87 | virtual void EnableTemporalDecimation(bool enable) = 0; |
| 88 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 89 | virtual int32_t SetTargetResolution(uint32_t width, |
| 90 | uint32_t height, |
| 91 | uint32_t frame_rate) = 0; |
| 92 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 93 | virtual void SetTargetFramerate(int frame_rate) = 0; |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 94 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 95 | virtual uint32_t GetDecimatedFrameRate() = 0; |
| 96 | virtual uint32_t GetDecimatedWidth() const = 0; |
| 97 | virtual uint32_t GetDecimatedHeight() const = 0; |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 98 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 99 | // Set the spatial resampling settings of the VPM according to |
| 100 | // VideoFrameResampling. |
| 101 | virtual void SetInputFrameResampleMode( |
| 102 | VideoFrameResampling resampling_mode) = 0; |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 103 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 104 | virtual void EnableDenosing(bool enable) = 0; |
| 105 | virtual const VideoFrame* PreprocessFrame(const VideoFrame& frame) = 0; |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 106 | |
mflodman | a856542 | 2015-12-07 01:09:52 -0800 | [diff] [blame] | 107 | virtual VideoContentMetrics* GetContentMetrics() const = 0; |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame] | 108 | virtual void EnableContentAnalysis(bool enable) = 0; |
| 109 | }; |
| 110 | |
| 111 | } // namespace webrtc |
| 112 | |
Henrik Kjellander | 0f59a88 | 2015-11-18 22:31:24 +0100 | [diff] [blame] | 113 | #endif // WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ |