• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2014 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_CODING_UTILITY_QUALITY_SCALER_H_
12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
13 
14 #include "webrtc/common_video/libyuv/include/scaler.h"
15 #include "webrtc/modules/video_coding/utility/moving_average.h"
16 
17 namespace webrtc {
18 class QualityScaler {
19  public:
20   static const int kDefaultLowQpDenominator;
21   static const int kDefaultMinDownscaleDimension;
22   struct Resolution {
23     int width;
24     int height;
25   };
26 
27   QualityScaler();
28   void Init(int low_qp_threshold,
29             int high_qp_threshold,
30             bool use_framerate_reduction);
31   void SetMinResolution(int min_width, int min_height);
32   void ReportFramerate(int framerate);
33   void ReportQP(int qp);
34   void ReportDroppedFrame();
35   void Reset(int framerate, int bitrate, int width, int height);
36   void OnEncodeFrame(const VideoFrame& frame);
37   Resolution GetScaledResolution() const;
38   const VideoFrame& GetScaledFrame(const VideoFrame& frame);
39   int GetTargetFramerate() const;
downscale_shift()40   int downscale_shift() const { return downscale_shift_; }
41 
42  private:
43   void AdjustScale(bool up);
44   void ClearSamples();
45 
46   Scaler scaler_;
47   VideoFrame scaled_frame_;
48 
49   size_t num_samples_;
50   int framerate_;
51   int target_framerate_;
52   int low_qp_threshold_;
53   int high_qp_threshold_;
54   MovingAverage<int> framedrop_percent_;
55   MovingAverage<int> average_qp_;
56   Resolution res_;
57 
58   int downscale_shift_;
59   int framerate_down_;
60   bool use_framerate_reduction_;
61   int min_width_;
62   int min_height_;
63 };
64 
65 }  // namespace webrtc
66 
67 #endif  // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
68