blob: 34dda0e9f37a44fb8f6cfdf03b0837ee13c90386 [file] [log] [blame]
pbos@webrtc.orga0d78272014-09-12 11:51:47 +00001/*
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
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000014#include "webrtc/common_video/libyuv/include/scaler.h"
kjellander@webrtc.orgb7ce9642015-11-18 23:04:10 +010015#include "webrtc/modules/video_coding/utility/moving_average.h"
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000016
17namespace webrtc {
18class QualityScaler {
19 public:
Peter Boström6a688f52015-06-22 08:02:58 +020020 static const int kDefaultLowQpDenominator;
21 static const int kDefaultMinDownscaleDimension;
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000022 struct Resolution {
23 int width;
24 int height;
25 };
26
27 QualityScaler();
Peter Boström17417702015-09-25 17:03:26 +020028 void Init(int low_qp_threshold,
29 int high_qp_threshold,
Alex Glazneva9d08922016-02-19 15:24:06 -080030 bool use_framerate_reduction,
31 int initial_bitrate_kbps,
32 int width,
pboscbac40d2016-04-13 02:51:02 -070033 int height,
34 int fps);
jackychen61b4d512015-04-21 15:30:11 -070035 void SetMinResolution(int min_width, int min_height);
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000036 void ReportFramerate(int framerate);
jackychen98d8cf52015-05-21 11:12:02 -070037 void ReportQP(int qp);
jackychen61b4d512015-04-21 15:30:11 -070038 void ReportDroppedFrame();
39 void Reset(int framerate, int bitrate, int width, int height);
jackychen6e2ce6e2015-07-13 16:26:33 -070040 void OnEncodeFrame(const VideoFrame& frame);
41 Resolution GetScaledResolution() const;
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070042 const VideoFrame& GetScaledFrame(const VideoFrame& frame);
jackychen6e2ce6e2015-07-13 16:26:33 -070043 int GetTargetFramerate() const;
asapersson4306fc72015-10-19 00:35:21 -070044 int downscale_shift() const { return downscale_shift_; }
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000045
46 private:
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000047 void AdjustScale(bool up);
Peter Boström01bcbd02016-03-22 21:44:29 +010048 void UpdateTargetResolution(int frame_width, int frame_height);
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000049 void ClearSamples();
pboscbac40d2016-04-13 02:51:02 -070050 void UpdateSampleCounts();
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000051
52 Scaler scaler_;
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070053 VideoFrame scaled_frame_;
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000054
pboscbac40d2016-04-13 02:51:02 -070055 size_t num_samples_downscale_;
56 size_t num_samples_upscale_;
57 int measure_seconds_upscale_;
58 MovingAverage<int> average_qp_upscale_;
59 MovingAverage<int> average_qp_downscale_;
60
jackychen6e2ce6e2015-07-13 16:26:33 -070061 int framerate_;
62 int target_framerate_;
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000063 int low_qp_threshold_;
Peter Boström17417702015-09-25 17:03:26 +020064 int high_qp_threshold_;
jackychen61b4d512015-04-21 15:30:11 -070065 MovingAverage<int> framedrop_percent_;
jackychen6e2ce6e2015-07-13 16:26:33 -070066 Resolution res_;
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000067
68 int downscale_shift_;
jackychen6e2ce6e2015-07-13 16:26:33 -070069 int framerate_down_;
70 bool use_framerate_reduction_;
jackychen61b4d512015-04-21 15:30:11 -070071 int min_width_;
72 int min_height_;
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000073};
74
75} // namespace webrtc
76
77#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_