1470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* 2470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * 4470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * Use of this source code is governed by a BSD-style license 5470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * that can be found in the LICENSE file in the root of the source 6470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * tree. An additional intellectual property rights grant can be found 7470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * in the file PATENTS. All contributing project authors may 8470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * be found in the AUTHORS file in the root of the source tree. 9470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com */ 10470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 110f59a88b32d95430bf12bd8c4d9b2963e018ead2Henrik Kjellander#ifndef WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ 120f59a88b32d95430bf12bd8c4d9b2963e018ead2Henrik Kjellander#define WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ 13470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 14ff761fba8274d93bd73e76c8b8a1f2d0776dd840Henrik Kjellander#include "webrtc/modules/include/module_common_types.h" 150f59a88b32d95430bf12bd8c4d9b2963e018ead2Henrik Kjellander#include "webrtc/modules/video_processing/include/video_processing_defines.h" 169bfe3daf7349b62647997ced9389baa8ab043afeThiago Farina#include "webrtc/video_frame.h" 17470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 18a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman// The module is largely intended to process video streams, except functionality 19a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman// provided by static functions which operate independent of previous frames. It 20a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman// is recommended, but not required that a unique instance be used for each 21a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman// concurrently processed stream. Similarly, it is recommended to call Reset() 22a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman// before switching to a new stream, but this is not absolutely required. 23a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman// 24a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman// The module provides basic thread safety by permitting only a single function 25a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman// to execute concurrently. 26470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 27470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comnamespace webrtc { 28470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 29a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodmanclass VideoProcessing { 30b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org public: 31b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org struct FrameStats { 32a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman uint32_t hist[256]; // Frame histogram. 33a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman uint32_t mean; 34a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman uint32_t sum; 35a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman uint32_t num_pixels; 36a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman uint32_t sub_sampling_factor; // Sub-sampling factor, in powers of 2. 37a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman }; 38b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 3999ab9447d1b48043adf6bfdf72cf820bbda3ee3fmflodman enum BrightnessWarning { kNoWarning, kDarkWarning, kBrightWarning }; 40b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 41a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman static VideoProcessing* Create(); 42a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman virtual ~VideoProcessing() {} 43b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 44a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // Retrieves statistics for the input frame. This function must be used to 45a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // prepare a FrameStats struct for use in certain VPM functions. 46a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman static void GetFrameStats(const VideoFrame& frame, FrameStats* stats); 47b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 48a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // Checks the validity of a FrameStats struct. Currently, valid implies only 49a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // that is had changed from its initialized state. 50b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org static bool ValidFrameStats(const FrameStats& stats); 51b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 52b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org static void ClearFrameStats(FrameStats* stats); 53b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 54a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // Increases/decreases the luminance value. 'delta' can be in the range {} 55a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman static void Brighten(int delta, VideoFrame* frame); 56b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 57a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // Detects and removes camera flicker from a video stream. Every frame from 58a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // the stream must be passed in. A frame will only be altered if flicker has 59a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // been detected. Has a fixed-point implementation. 60a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // Frame statistics provided by GetFrameStats(). On return the stats will 61a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // be reset to zero if the frame was altered. Call GetFrameStats() again 62a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // if the statistics for the altered frame are required. 634765070b8d6f024509c717c04d9b708750666927Miguel Casas-Sanchez virtual int32_t Deflickering(VideoFrame* frame, FrameStats* stats) = 0; 64b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 65a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // Detects if a video frame is excessively bright or dark. Returns a 66a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // warning if this is the case. Multiple frames should be passed in before 67a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // expecting a warning. Has a floating-point implementation. 684765070b8d6f024509c717c04d9b708750666927Miguel Casas-Sanchez virtual int32_t BrightnessDetection(const VideoFrame& frame, 69b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org const FrameStats& stats) = 0; 70b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 71a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // The following functions refer to the pre-processor unit within VPM. The 72a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // pre-processor perfoms spatial/temporal decimation and content analysis on 73a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // the frames prior to encoding. 74b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 75a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // Enable/disable temporal decimation 76b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org virtual void EnableTemporalDecimation(bool enable) = 0; 77b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 78b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org virtual int32_t SetTargetResolution(uint32_t width, 79b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org uint32_t height, 80b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org uint32_t frame_rate) = 0; 81b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 82a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman virtual void SetTargetFramerate(int frame_rate) = 0; 83b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 84a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman virtual uint32_t GetDecimatedFrameRate() = 0; 85a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman virtual uint32_t GetDecimatedWidth() const = 0; 86a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman virtual uint32_t GetDecimatedHeight() const = 0; 87470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 88a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // Set the spatial resampling settings of the VPM according to 89a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman // VideoFrameResampling. 90a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman virtual void SetInputFrameResampleMode( 91a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman VideoFrameResampling resampling_mode) = 0; 92b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 93a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman virtual void EnableDenosing(bool enable) = 0; 94a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman virtual const VideoFrame* PreprocessFrame(const VideoFrame& frame) = 0; 95b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org 96a8565425bc6b1d3d7b5a0b0e0a49bc4e57c64f21mflodman virtual VideoContentMetrics* GetContentMetrics() const = 0; 97b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org virtual void EnableContentAnalysis(bool enable) = 0; 98470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com}; 99470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 100b43d8078a152d91037b25175712a57a9a377220amikhal@webrtc.org} // namespace webrtc 101470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 1020f59a88b32d95430bf12bd8c4d9b2963e018ead2Henrik Kjellander#endif // WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_ 103