chromium/media/gpu/frame_size_estimator.h

// 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.

#ifndef MEDIA_GPU_FRAME_SIZE_ESTIMATOR_H_
#define MEDIA_GPU_FRAME_SIZE_ESTIMATOR_H_

#include "base/time/time.h"
#include "media/gpu/exponential_moving_average.h"
#include "media/gpu/media_gpu_export.h"

namespace media {

// An encoded frame size estimator.
// The estimator maintains the history of intermediate values (qp_size_value)
// that are proportional to encoded frame size and QP, and inversely
// proportional to the QP ratio of the previous and the current frame
// (delta_q_step_factor). The QP is converted to Q step value that has linear
// dependency to the encoded frame size.
//
// q_step = 5 / 8 * 2^(qp / 6)
//
// delta_q_step_factor = q_step_prev / q_step
//
// qp_size_value = q_step * frame_bytes / delta_q_step_factor
//
// The prediction of the encoded frame size is based on average values of
// qp_size_value and qp_size_correction. The qp_size_correction is the
// difference between actual encoded bytes and the predicted value.
//
// qp_size_correction = frame_bytes -
//                      qp_size_value * delta_q_step_factor / q_step
//
// pred_frame_bytes =
//     qp_size_value * delta_q_step_factor / q_step + qp_size_correction
//
// In the inverse estimation process, the QP value is estimated for the given
// encoded frame size and the QP of the previous frame.
//
// q_step =
//     sqrt(qp_size_value * q_step_prev / (frame_bytes + qp_size_correction))
//
// qp = 6 * log2(q_step / (5 / 8))
class MEDIA_GPU_EXPORT FrameSizeEstimator {};

}  // namespace media

#endif  // MEDIA_GPU_FRAME_SIZE_ESTIMATOR_H_