webrtc_m130/video/encoder_overshoot_detector.h
Erik Språng 7ca375c8ca Implement encoder overshoot detector and rate adjuster.
The overshoot detector uses a simple pacer model to determine an
estimate of how much the encoder is overusing the target bitrate.
This utilization factor can then be adjuster for when configuring the
actual target bitrate.

Spatial layers (simulcast streams) are adjusted separately.
Temporal layers are measured separately, but are combined into a single
utilization factor per spatial layer.

Bug: webrtc:10155
Change-Id: I8ea58dc6c4871e880553d7c22202f11cb2feb216
Reviewed-on: https://webrtc-review.googlesource.com/c/114886
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26573}
2019-02-06 15:54:11 +00:00

56 lines
1.6 KiB
C++

/*
* Copyright (c) 2019 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 VIDEO_ENCODER_OVERSHOOT_DETECTOR_H_
#define VIDEO_ENCODER_OVERSHOOT_DETECTOR_H_
#include <deque>
#include "absl/types/optional.h"
#include "api/units/data_rate.h"
namespace webrtc {
class EncoderOvershootDetector {
public:
explicit EncoderOvershootDetector(int64_t window_size_ms);
~EncoderOvershootDetector();
void SetTargetRate(DataRate target_bitrate,
double target_framerate_fps,
int64_t time_ms);
void OnEncodedFrame(size_t bytes, int64_t time_ms);
absl::optional<double> GetUtilizationFactor(int64_t time_ms);
void Reset();
private:
int64_t IdealFrameSizeBits() const;
void LeakBits(int64_t time_ms);
const int64_t window_size_ms_;
int64_t time_last_update_ms_;
struct BitrateUpdate {
BitrateUpdate(double utilization_factor, int64_t update_time_ms)
: utilization_factor(utilization_factor),
update_time_ms(update_time_ms) {}
double utilization_factor;
int64_t update_time_ms;
};
std::deque<BitrateUpdate> utilization_factors_;
double sum_utilization_factors_;
DataRate target_bitrate_;
double target_framerate_fps_;
int64_t buffer_level_bits_;
};
} // namespace webrtc
#endif // VIDEO_ENCODER_OVERSHOOT_DETECTOR_H_