chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate.cc

// Copyright 2018 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/vaapi/h264_vaapi_video_encoder_delegate.h"

#include <va/va.h>
#include <va/va_enc_h264.h>

#include <climits>
#include <utility>

#include "base/bits.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/numerics/checked_math.h"
#include "build/build_config.h"
#include "media/base/media_switches.h"
#include "media/base/video_bitrate_allocation.h"
#include "media/gpu/gpu_video_encode_accelerator_helpers.h"
#include "media/gpu/h264_builder.h"
#include "media/gpu/macros.h"
#include "media/gpu/vaapi/vaapi_common.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "media/parsers/h264_level_limits.h"
#include "media/video/video_encode_accelerator.h"

namespace media {
namespace {
// An IDR every 2048 frames (must be >= 16 per spec), no I frames and no B
// frames. We choose IDR period to equal MaxFrameNum so it must be a power of 2.
// Produce an IDR at least once per this many frames. Must be >= 16 (per spec).
constexpr uint32_t kIDRPeriod =;
static_assert;
// Produce an I frame at least once per this many frames.
constexpr uint32_t kIPeriod =;
// How often do we need to have either an I or a P frame in the stream.
// A period of 1 implies no B frames.
constexpr uint32_t kIPPeriod =;

// The qp range is 0-51 in H264. Select 26 because of the center value.
// WebRTC H264 encoder uses 1-51. We set the minimum QP to 1 for camera
// and 10 for screen sharing to mitigate the bitrate overshoot due
// to a scene, and maximum qp to 42 to pass the CTS test (b/354557852).
constexpr uint8_t kDefaultQP =;
constexpr uint8_t kMinQP =;
constexpr uint8_t kScreenMinQP =;
constexpr uint8_t kMaxQP =;

// Subjectively chosen bitrate window size for rate control, in ms.
constexpr uint32_t kCPBWindowSizeMs =;

// Subjectively chosen.
// Generally use up to 2 reference frames.
constexpr size_t kMaxRefIdxL0Size =;

// HRD parameters (ch. E.2.2 in H264 spec).
constexpr int kBitRateScale =;  // bit_rate_scale for SPS HRD parameters.
constexpr int kCPBSizeScale =;  // cpb_size_scale for SPS HRD parameters.

// 4:2:0
constexpr int kChromaFormatIDC =;

constexpr uint8_t kMinSupportedH264TemporalLayers =;
constexpr uint8_t kMaxSupportedH264TemporalLayers =;

template <typename VAEncMiscParam>
VAEncMiscParam& AllocateMiscParameterBuffer(
    std::vector<uint8_t>& misc_buffer,
    VAEncMiscParameterType misc_param_type) {}

void CreateVAEncRateControlParams(uint32_t bps,
                                  uint32_t target_percentage,
                                  uint32_t window_size,
                                  uint32_t initial_qp,
                                  uint32_t min_qp,
                                  uint32_t max_qp,
                                  uint32_t framerate,
                                  uint32_t buffer_size,
                                  std::vector<uint8_t> misc_buffers[3]) {}

static void InitVAPictureH264(VAPictureH264* va_pic) {}

// Updates |frame_num| as spec section 7.4.3 and sets it to |pic.frame_num|.
void UpdateAndSetFrameNum(H264Picture& pic, unsigned int& frame_num) {}

// Updates and fills variables in |pic|, |frame_num| and |ref_frame_idx| for
// temporal layer encoding. |frame_num| is the frame_num in H.264 spec for
// |pic|. |ref_frame_idx| is the index in |ref_pic_list0| of the frame
// referenced by |pic|.
void UpdatePictureForTemporalLayerEncoding(
    const size_t num_layers,
    H264Picture& pic,
    unsigned int& frame_num,
    std::optional<size_t>& ref_frame_idx,
    const unsigned int num_encoded_frames,
    const base::circular_deque<scoped_refptr<H264Picture>>& ref_pic_list0) {}

scoped_refptr<H264Picture> GetH264Picture(
    const VaapiVideoEncoderDelegate::EncodeJob& job) {}

std::optional<H264RateControlConfigRTC> CreateRateControlConfig(
    const gfx::Size encode_size,
    const H264VaapiVideoEncoderDelegate::EncodeParams& encode_params,
    const VideoBitrateAllocation& bitrate_allocation,
    const size_t& num_temporal_layers) {}
}  // namespace

std::unique_ptr<H264RateControlWrapper> H264RateControlWrapper::Create(
    const H264RateControlConfigRTC& config) {}

H264RateControlWrapper::H264RateControlWrapper() = default;

H264RateControlWrapper::H264RateControlWrapper(
    std::unique_ptr<H264RateCtrlRTC> impl)
    :{}

H264RateControlWrapper::~H264RateControlWrapper() = default;

void H264RateControlWrapper::UpdateRateControl(
    const H264RateControlConfigRTC& config) {}

H264RateCtrlRTC::FrameDropDecision H264RateControlWrapper::ComputeQP(
    const H264FrameParamsRTC& frame_params) {}

int H264RateControlWrapper::GetQP() const {}

void H264RateControlWrapper::PostEncodeUpdate(
    uint64_t encoded_frame_size,
    const H264FrameParamsRTC& frame_params) {}

H264VaapiVideoEncoderDelegate::EncodeParams::EncodeParams()
    :{}

H264VaapiVideoEncoderDelegate::H264VaapiVideoEncoderDelegate(
    scoped_refptr<VaapiWrapper> vaapi_wrapper,
    base::RepeatingClosure error_cb)
    :{}

H264VaapiVideoEncoderDelegate::~H264VaapiVideoEncoderDelegate() = default;

void H264VaapiVideoEncoderDelegate::set_rate_ctrl_for_testing(
    std::unique_ptr<H264RateControlWrapper> rate_ctrl) {}

bool H264VaapiVideoEncoderDelegate::Initialize(
    const VideoEncodeAccelerator::Config& config,
    const VaapiVideoEncoderDelegate::Config& ave_config) {}

gfx::Size H264VaapiVideoEncoderDelegate::GetCodedSize() const {}

size_t H264VaapiVideoEncoderDelegate::GetMaxNumOfRefFrames() const {}

std::vector<gfx::Size> H264VaapiVideoEncoderDelegate::GetSVCLayerResolutions() {}

bool H264VaapiVideoEncoderDelegate::UseSoftwareRateController(
    const VideoEncodeAccelerator::Config& config) {}

BitstreamBufferMetadata H264VaapiVideoEncoderDelegate::GetMetadata(
    const EncodeJob& encode_job,
    size_t payload_size) {}

VaapiVideoEncoderDelegate::PrepareEncodeJobResult
H264VaapiVideoEncoderDelegate::PrepareEncodeJob(EncodeJob& encode_job) {}

bool H264VaapiVideoEncoderDelegate::UpdateRates(
    const VideoBitrateAllocation& bitrate_allocation,
    uint32_t framerate) {}

void H264VaapiVideoEncoderDelegate::UpdateSPS() {}

void H264VaapiVideoEncoderDelegate::UpdatePPS() {}

void H264VaapiVideoEncoderDelegate::GeneratePackedSliceHeader(
    H26xAnnexBBitstreamBuilder& packed_slice_header,
    const VAEncPictureParameterBufferH264& pic_param,
    const VAEncSliceParameterBufferH264& slice_param,
    const H264Picture& pic) {}

bool H264VaapiVideoEncoderDelegate::SubmitFrameParameters(
    EncodeJob& job,
    const H264VaapiVideoEncoderDelegate::EncodeParams& encode_params,
    const H264SPS& sps,
    const H264PPS& pps,
    scoped_refptr<H264Picture> pic,
    const base::circular_deque<scoped_refptr<H264Picture>>& ref_pic_list0,
    const std::optional<size_t>& ref_frame_index,
    const std::optional<int>& qp) {}

bool H264VaapiVideoEncoderDelegate::SubmitPackedHeaders(
    const H26xAnnexBBitstreamBuilder& packed_sps,
    const H26xAnnexBBitstreamBuilder& packed_pps) {}

void H264VaapiVideoEncoderDelegate::BitrateControlUpdate(
    const BitstreamBufferMetadata& metadata) {}

}  // namespace media