1 /*
2  *  Copyright (c) 2012 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 #ifndef WEBRTC_MODULES_VIDEO_PROCESSING_FRAME_PREPROCESSOR_H_
12 #define WEBRTC_MODULES_VIDEO_PROCESSING_FRAME_PREPROCESSOR_H_
13 
14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/modules/video_processing/include/video_processing.h"
16 #include "webrtc/modules/video_processing/content_analysis.h"
17 #include "webrtc/modules/video_processing/spatial_resampler.h"
18 #include "webrtc/modules/video_processing/video_decimator.h"
19 #include "webrtc/typedefs.h"
20 #include "webrtc/video_frame.h"
21 
22 namespace webrtc {
23 
24 class VideoDenoiser;
25 
26 // All pointers/members in this class are assumed to be protected by the class
27 // owner.
28 class VPMFramePreprocessor {
29  public:
30   VPMFramePreprocessor();
31   ~VPMFramePreprocessor();
32 
33   void Reset();
34 
35   // Enable temporal decimation.
36   void EnableTemporalDecimation(bool enable);
37 
38   void SetInputFrameResampleMode(VideoFrameResampling resampling_mode);
39 
40   // Enable content analysis.
41   void EnableContentAnalysis(bool enable);
42 
43   // Set target resolution: frame rate and dimension.
44   int32_t SetTargetResolution(uint32_t width,
45                               uint32_t height,
46                               uint32_t frame_rate);
47 
48   // Set target frame rate.
49   void SetTargetFramerate(int frame_rate);
50 
51   // Update incoming frame rate/dimension.
52   void UpdateIncomingframe_rate();
53 
54   int32_t updateIncomingFrameSize(uint32_t width, uint32_t height);
55 
56   // Set decimated values: frame rate/dimension.
57   uint32_t GetDecimatedFrameRate();
58   uint32_t GetDecimatedWidth() const;
59   uint32_t GetDecimatedHeight() const;
60 
61   // Preprocess output:
62   void EnableDenosing(bool enable);
63   const VideoFrame* PreprocessFrame(const VideoFrame& frame);
64   VideoContentMetrics* GetContentMetrics() const;
65 
66  private:
67   // The content does not change so much every frame, so to reduce complexity
68   // we can compute new content metrics every |kSkipFrameCA| frames.
69   enum { kSkipFrameCA = 2 };
70 
71   VideoContentMetrics* content_metrics_;
72   VideoFrame denoised_frame_;
73   VideoFrame resampled_frame_;
74   VPMSpatialResampler* spatial_resampler_;
75   VPMContentAnalysis* ca_;
76   VPMVideoDecimator* vd_;
77   rtc::scoped_ptr<VideoDenoiser> denoiser_;
78   bool enable_ca_;
79   uint32_t frame_cnt_;
80 };
81 
82 }  // namespace webrtc
83 
84 #endif  // WEBRTC_MODULES_VIDEO_PROCESSING_FRAME_PREPROCESSOR_H_
85