blob: c0f94409ce30ee0d5b46260857bc42f696f72c01 [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
kthelgason478681e2016-09-28 08:17:43 -070014#include "webrtc/common_types.h"
Niels Möller718a7632016-06-13 13:06:01 +020015#include "webrtc/common_video/include/i420_buffer_pool.h"
kjellander@webrtc.orgb7ce9642015-11-18 23:04:10 +010016#include "webrtc/modules/video_coding/utility/moving_average.h"
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000017
18namespace webrtc {
19class QualityScaler {
20 public:
21 struct Resolution {
22 int width;
23 int height;
24 };
25
26 QualityScaler();
kthelgason478681e2016-09-28 08:17:43 -070027 void Init(VideoCodecType codec_type,
28 int initial_bitrate_kbps,
29 int width,
30 int height,
31 int fps);
Peter Boström17417702015-09-25 17:03:26 +020032 void Init(int low_qp_threshold,
33 int high_qp_threshold,
Alex Glazneva9d08922016-02-19 15:24:06 -080034 int initial_bitrate_kbps,
35 int width,
pboscbac40d2016-04-13 02:51:02 -070036 int height,
37 int fps);
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000038 void ReportFramerate(int framerate);
jackychen98d8cf52015-05-21 11:12:02 -070039 void ReportQP(int qp);
jackychen61b4d512015-04-21 15:30:11 -070040 void ReportDroppedFrame();
Niels Möller718a7632016-06-13 13:06:01 +020041 void OnEncodeFrame(int width, int height);
jackychen6e2ce6e2015-07-13 16:26:33 -070042 Resolution GetScaledResolution() const;
Niels Möller718a7632016-06-13 13:06:01 +020043 rtc::scoped_refptr<VideoFrameBuffer> GetScaledBuffer(
44 const rtc::scoped_refptr<VideoFrameBuffer>& frame);
asapersson4306fc72015-10-19 00:35:21 -070045 int downscale_shift() const { return downscale_shift_; }
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000046
47 private:
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000048 void ClearSamples();
kthelgason194f40a2016-09-14 02:14:58 -070049 void ScaleUp();
50 void ScaleDown();
51 void UpdateTargetResolution(int width, int height);
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000052
Niels Möller718a7632016-06-13 13:06:01 +020053 I420BufferPool pool_;
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_;
kthelgason194f40a2016-09-14 02:14:58 -070057 bool fast_rampup_;
58 MovingAverage average_qp_;
59 MovingAverage framedrop_percent_;
pboscbac40d2016-04-13 02:51:02 -070060
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000061 int low_qp_threshold_;
Peter Boström17417702015-09-25 17:03:26 +020062 int high_qp_threshold_;
kthelgason194f40a2016-09-14 02:14:58 -070063 Resolution target_res_;
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000064
65 int downscale_shift_;
kthelgason194f40a2016-09-14 02:14:58 -070066 int maximum_shift_;
pbos@webrtc.orga0d78272014-09-12 11:51:47 +000067};
68
69} // namespace webrtc
70
71#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_