#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/gpu/h264_rate_controller.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "media/gpu/h264_rate_control_util.h"
namespace media {
namespace {
constexpr int kBaseLayerIndex = …;
constexpr int kFixedLayerDeltaQP = …;
constexpr float kFpsMax = …;
constexpr float kLayerRateRatio = …;
constexpr float kInitQPSize = …;
constexpr float kIntraFrameMAD = …;
constexpr uint32_t kMinFirstFrameQP = …;
constexpr float kRDSlope = …;
constexpr float kRDYIntercept = …;
constexpr struct { … } kFPS2QPTradeoffs[] = …;
constexpr int kWindowFrameCount = …;
size_t GetRateBudget(float frame_rate, uint32_t avg_bitrate) { … }
float Fps2MaxQP(float fps) { … }
float MaxQP2Fps(int max_qp) { … }
}
H264RateControllerSettings::H264RateControllerSettings() = default;
H264RateControllerSettings::~H264RateControllerSettings() = default;
H264RateControllerSettings::H264RateControllerSettings(
const H264RateControllerSettings&) = default;
H264RateControllerSettings& H264RateControllerSettings::operator=(
const H264RateControllerSettings&) = default;
std::partial_ordering H264RateControllerSettings::operator<=>(
const H264RateControllerSettings& other) const { … }
H264RateController::Layer::Layer(H264RateControllerLayerSettings settings,
float expected_fps,
base::TimeDelta short_term_window_size,
base::TimeDelta long_term_window_size)
: … { … }
H264RateController::Layer::~Layer() = default;
void H264RateController::Layer::ShrinkHRDBuffer(base::TimeDelta timestamp) { … }
void H264RateController::Layer::AddFrameBytes(size_t frame_bytes,
base::TimeDelta frame_timestamp) { … }
void H264RateController::Layer::AddFrameTimestamp(
base::TimeDelta frame_timestamp) { … }
void H264RateController::Layer::SetBufferParameters(size_t buffer_size,
uint32_t avg_bitrate,
uint32_t peak_bitrate,
bool ease_hrd_reduction) { … }
size_t H264RateController::Layer::GetBufferBytesAtTime(
base::TimeDelta timestamp) const { … }
size_t H264RateController::Layer::GetBufferBytesRemainingAtTime(
base::TimeDelta timestamp) const { … }
float H264RateController::Layer::GetFrameRateMean() const { … }
size_t H264RateController::Layer::EstimateShortTermFrameSize(
uint32_t qp,
uint32_t qp_prev) const { … }
size_t H264RateController::Layer::EstimateLongTermFrameSize(
uint32_t qp,
uint32_t qp_prev) const { … }
uint32_t H264RateController::Layer::EstimateShortTermQP(
size_t target_frame_bytes,
uint32_t qp_prev) const { … }
uint32_t H264RateController::Layer::EstimateLongTermQP(
size_t target_frame_bytes,
uint32_t qp_prev) const { … }
size_t H264RateController::Layer::GetFrameSizeEstimatorError() const { … }
void H264RateController::Layer::UpdateFrameSizeEstimator(
size_t frame_bytes,
uint32_t qp,
uint32_t qp_prev,
base::TimeDelta elapsed_time) { … }
float H264RateController::Layer::GetInitialSizeCorrection(
H264RateControllerLayerSettings settings) const { … }
H264RateController::H264RateController(H264RateControllerSettings settings)
: … { … }
H264RateController::~H264RateController() = default;
void H264RateController::EstimateIntraFrameQP(base::TimeDelta frame_timestamp) { … }
void H264RateController::EstimateInterFrameQP(size_t temporal_id,
base::TimeDelta frame_timestamp) { … }
void H264RateController::FinishIntraFrame(size_t access_unit_bytes,
base::TimeDelta frame_timestamp) { … }
void H264RateController::FinishInterFrame(size_t temporal_id,
size_t access_unit_bytes,
base::TimeDelta frame_timestamp) { … }
void H264RateController::UpdateFrameSize(const gfx::Size& frame_size) { … }
void H264RateController::GetHRDBufferFullness(
base::span<int> buffer_fullness,
base::TimeDelta frame_timestamp) const { … }
void H264RateController::FinishLayerData(size_t temporal_id,
FrameType frame_type,
size_t frame_bytes,
base::TimeDelta frame_timestamp) { … }
void H264RateController::FinishLayerPreviousFrameTimestamp(
size_t temporal_id,
base::TimeDelta frame_timestamp) { … }
void H264RateController::SetLastTsOvershootingFrame(
size_t temporal_id,
base::TimeDelta frame_timestamp) { … }
size_t H264RateController::GetTargetBytesForIntraFrame(
base::TimeDelta frame_timestamp) const { … }
size_t H264RateController::GetTargetBytesForInterFrame(
size_t temporal_id,
uint32_t max_rate_bytes_per_sec,
size_t buffer_size,
int buffer_level_current,
base::TimeDelta frame_timestamp) const { … }
uint32_t H264RateController::GetInterFrameShortTermQP(
size_t temporal_id,
size_t frame_size_target) { … }
uint32_t H264RateController::GetInterFrameLongTermQP(size_t temporal_id) { … }
uint32_t H264RateController::ClipInterFrameQP(uint32_t curr_qp,
size_t temporal_id,
base::TimeDelta frame_timestamp) { … }
float H264RateController::GetTargetFps(
H264RateControllerSettings settings) const { … }
}