2014-09-12 11:51:47 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 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_CODING_UTILITY_QUALITY_SCALER_H_
|
|
|
|
|
#define WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
|
|
|
|
|
|
|
|
|
|
#include "webrtc/common_video/libyuv/include/scaler.h"
|
2015-11-18 23:04:10 +01:00
|
|
|
#include "webrtc/modules/video_coding/utility/moving_average.h"
|
2014-09-12 11:51:47 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
class QualityScaler {
|
|
|
|
|
public:
|
2015-06-22 08:02:58 +02:00
|
|
|
static const int kDefaultLowQpDenominator;
|
|
|
|
|
static const int kDefaultMinDownscaleDimension;
|
2014-09-12 11:51:47 +00:00
|
|
|
struct Resolution {
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QualityScaler();
|
2015-09-25 17:03:26 +02:00
|
|
|
void Init(int low_qp_threshold,
|
|
|
|
|
int high_qp_threshold,
|
2016-02-19 15:24:06 -08:00
|
|
|
bool use_framerate_reduction,
|
|
|
|
|
int initial_bitrate_kbps,
|
|
|
|
|
int width,
|
2016-04-04 18:11:06 +02:00
|
|
|
int height,
|
|
|
|
|
int fps);
|
2015-04-21 15:30:11 -07:00
|
|
|
void SetMinResolution(int min_width, int min_height);
|
2014-09-12 11:51:47 +00:00
|
|
|
void ReportFramerate(int framerate);
|
2015-05-21 11:12:02 -07:00
|
|
|
void ReportQP(int qp);
|
2015-04-21 15:30:11 -07:00
|
|
|
void ReportDroppedFrame();
|
|
|
|
|
void Reset(int framerate, int bitrate, int width, int height);
|
2015-07-13 16:26:33 -07:00
|
|
|
void OnEncodeFrame(const VideoFrame& frame);
|
|
|
|
|
Resolution GetScaledResolution() const;
|
2015-05-29 17:21:40 -07:00
|
|
|
const VideoFrame& GetScaledFrame(const VideoFrame& frame);
|
2015-07-13 16:26:33 -07:00
|
|
|
int GetTargetFramerate() const;
|
2015-10-19 00:35:21 -07:00
|
|
|
int downscale_shift() const { return downscale_shift_; }
|
2014-09-12 11:51:47 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void AdjustScale(bool up);
|
2016-03-22 21:44:29 +01:00
|
|
|
void UpdateTargetResolution(int frame_width, int frame_height);
|
2014-09-12 11:51:47 +00:00
|
|
|
void ClearSamples();
|
2016-04-04 18:11:06 +02:00
|
|
|
void UpdateSampleCounts();
|
2014-09-12 11:51:47 +00:00
|
|
|
|
|
|
|
|
Scaler scaler_;
|
2015-05-29 17:21:40 -07:00
|
|
|
VideoFrame scaled_frame_;
|
2014-09-12 11:51:47 +00:00
|
|
|
|
2016-04-04 18:11:06 +02:00
|
|
|
size_t num_samples_downscale_;
|
|
|
|
|
size_t num_samples_upscale_;
|
|
|
|
|
int measure_seconds_upscale_;
|
|
|
|
|
MovingAverage<int> average_qp_upscale_;
|
|
|
|
|
MovingAverage<int> average_qp_downscale_;
|
|
|
|
|
|
2015-07-13 16:26:33 -07:00
|
|
|
int framerate_;
|
|
|
|
|
int target_framerate_;
|
2014-09-12 11:51:47 +00:00
|
|
|
int low_qp_threshold_;
|
2015-09-25 17:03:26 +02:00
|
|
|
int high_qp_threshold_;
|
2015-04-21 15:30:11 -07:00
|
|
|
MovingAverage<int> framedrop_percent_;
|
2015-07-13 16:26:33 -07:00
|
|
|
Resolution res_;
|
2014-09-12 11:51:47 +00:00
|
|
|
|
|
|
|
|
int downscale_shift_;
|
2015-07-13 16:26:33 -07:00
|
|
|
int framerate_down_;
|
|
|
|
|
bool use_framerate_reduction_;
|
2015-04-21 15:30:11 -07:00
|
|
|
int min_width_;
|
|
|
|
|
int min_height_;
|
2014-09-12 11:51:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
|