aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/video_processing/include/video_processing.h
blob: a8d6358887662a35858f8fad5f0ee288af9d0266 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_
#define WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_

#include "webrtc/modules/include/module_common_types.h"
#include "webrtc/modules/video_processing/include/video_processing_defines.h"
#include "webrtc/video_frame.h"

// The module is largely intended to process video streams, except functionality
// provided by static functions which operate independent of previous frames. It
// is recommended, but not required that a unique instance be used for each
// concurrently processed stream. Similarly, it is recommended to call Reset()
// before switching to a new stream, but this is not absolutely required.
//
// The module provides basic thread safety by permitting only a single function
// to execute concurrently.

namespace webrtc {

class VideoProcessing {
 public:
  struct FrameStats {
    uint32_t hist[256];  // Frame histogram.
    uint32_t mean;
    uint32_t sum;
    uint32_t num_pixels;
    uint32_t sub_sampling_factor;  // Sub-sampling factor, in powers of 2.
  };

  enum BrightnessWarning { kNoWarning, kDarkWarning, kBrightWarning };

  static VideoProcessing* Create();
  virtual ~VideoProcessing() {}

  // Retrieves statistics for the input frame. This function must be used to
  // prepare a FrameStats struct for use in certain VPM functions.
  static void GetFrameStats(const VideoFrame& frame, FrameStats* stats);

  // Checks the validity of a FrameStats struct. Currently, valid implies only
  // that is had changed from its initialized state.
  static bool ValidFrameStats(const FrameStats& stats);

  static void ClearFrameStats(FrameStats* stats);

  // Increases/decreases the luminance value. 'delta' can be in the range {}
  static void Brighten(int delta, VideoFrame* frame);

  // Detects and removes camera flicker from a video stream. Every frame from
  // the stream must be passed in. A frame will only be altered if flicker has
  // been detected. Has a fixed-point implementation.
  // Frame statistics provided by GetFrameStats(). On return the stats will
  // be reset to zero if the frame was altered. Call GetFrameStats() again
  // if the statistics for the altered frame are required.
  virtual int32_t Deflickering(VideoFrame* frame, FrameStats* stats) = 0;

  // Detects if a video frame is excessively bright or dark. Returns a
  // warning if this is the case. Multiple frames should be passed in before
  // expecting a warning. Has a floating-point implementation.
  virtual int32_t BrightnessDetection(const VideoFrame& frame,
                                      const FrameStats& stats) = 0;

  // The following functions refer to the pre-processor unit within VPM. The
  // pre-processor perfoms spatial/temporal decimation and content analysis on
  // the frames prior to encoding.

  // Enable/disable temporal decimation
  virtual void EnableTemporalDecimation(bool enable) = 0;

  virtual int32_t SetTargetResolution(uint32_t width,
                                      uint32_t height,
                                      uint32_t frame_rate) = 0;

  virtual void SetTargetFramerate(int frame_rate) = 0;

  virtual uint32_t GetDecimatedFrameRate() = 0;
  virtual uint32_t GetDecimatedWidth() const = 0;
  virtual uint32_t GetDecimatedHeight() const = 0;

  // Set the spatial resampling settings of the VPM according to
  // VideoFrameResampling.
  virtual void SetInputFrameResampleMode(
      VideoFrameResampling resampling_mode) = 0;

  virtual void EnableDenosing(bool enable) = 0;
  virtual const VideoFrame* PreprocessFrame(const VideoFrame& frame) = 0;

  virtual VideoContentMetrics* GetContentMetrics() const = 0;
  virtual void EnableContentAnalysis(bool enable) = 0;
};

}  // namespace webrtc

#endif  // WEBRTC_MODULES_VIDEO_PROCESSING_INCLUDE_VIDEO_PROCESSING_H_