chromium/media/gpu/h264_rate_controller.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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 {
// Base temporal layer index.
constexpr int kBaseLayerIndex =;

// Delta QP between layers in Fixed Delta QP mode. It is arbitrary chosen value.
constexpr int kFixedLayerDeltaQP =;

// Maximum FPS used in the tradeoff calculation between FPS and maximum QP.
constexpr float kFpsMax =;

// Base layer to enhancement layer data rate ratio. It is used in fixed delta QP
// mode only.
constexpr float kLayerRateRatio =;

// Initial QP size value used in initialization of the estimators. The value is
// chosen arbitrarily bases on common values for QP and P frame size.
constexpr float kInitQPSize =;

// The constant kIntraFrameMAD is the average MAD between the original and
// predicted pixels for intra frames in H.264 video. The average is calculated
// over a set of frames with a common complexity level.
constexpr float kIntraFrameMAD =;

// Arbitrarily chosen value for the minimum QP of the first encoded intra frame.
constexpr uint32_t kMinFirstFrameQP =;

// The constants kRDSlope and kRDYIntercept are the slope and Y-intercept of the
// linear approximation in the expression
// log2(bpp) = a * log2(mad / q_step) + b.
// a - kRDSlope
// b - kRDYIntercept
// The optimal values for kRDSlope and kRDYIntercept are derived from the
// analysis of rate and distortion values over a large set of data.
constexpr float kRDSlope =;
constexpr float kRDYIntercept =;

// The arrays define line segments in the tradeoff function between FPS and
// maximum QP .
constexpr struct {} kFPS2QPTradeoffs[] =;

// Window size in number of frames for the Moving Window. The average framerate
// is based on the last received frames within the window.
constexpr int kWindowFrameCount =;

// Returns a budget in bytes per frame for the given frame rate and average
// bitrate. The budget represents the amount of data equally distributed among
// frames.
size_t GetRateBudget(float frame_rate, uint32_t avg_bitrate) {}

// Returns the FPS value related to the Max QP value. The function is
// represented by line segments defined in the array `kFPS2QPTradeoffs`.
float Fps2MaxQP(float fps) {}

// Returns the FPS value related to the Max QP value. The returned value is
// a constant value obtained from the `kFPS2QPTradeoffs` array.
float MaxQP2Fps(int max_qp) {}
}  // namespace

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 {}

}  // namespace media