chromium/media/gpu/vaapi/vp8_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/vp8_vaapi_video_encoder_delegate.h"

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

#include <bit>

#include "base/bits.h"
#include "base/containers/contains.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "media/base/media_switches.h"
#include "media/gpu/gpu_video_encode_accelerator_helpers.h"
#include "media/gpu/macros.h"
#include "media/gpu/vaapi/vaapi_common.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "media/video/video_encode_accelerator.h"
#include "third_party/libvpx/source/libvpx/vp8/vp8_ratectrl_rtc.h"

namespace media {

namespace {
// Keyframe period.
constexpr size_t kKFPeriod =;

// Quantization parameter. They are vp8 ac/dc indices and their ranges are
// 0-127. Based on WebRTC's defaults.
constexpr uint8_t kMinQP =;
// b/110059922, crbug.com/1001900: Tuned 112->117 for bitrate issue in a lower
// resolution (180p).
constexpr uint8_t kMaxQP =;

// WebRTC's default quantizer values are 12 and 56 for screen sharing,
// respectively; the corresponding quantization parameters are 15 and 106 for
// screen sharing. Set smaller min qp value, 12, for zero hertz tab sharing,
// which is triggered when qp values are consecutively less than or equal to 15.
constexpr uint8_t kScreenMinQP =;
constexpr uint8_t kScreenMaxQP =;

// Convert Qindex, whose range is 0-127, to the quantizer parameter used in
// libvpx vp8 rate control, whose range is 0-63.
// Cited from //third_party/libvpx/source/libvpx/vp8/vp8_ratectrl_rtc.cc
uint8_t QindexToQuantizer(uint8_t q_index) {}

// The return value is expressed as a percentage of the average. For example,
// to allocate no more than 4.5 frames worth of bitrate to a keyframe, the
// return value is 450.
uint32_t MaxSizeOfKeyframeAsPercentage(uint32_t optimal_buffer_size,
                                       uint32_t max_framerate) {}

libvpx::VP8RateControlRtcConfig CreateRateControlConfig(
    const gfx::Size encode_size,
    const VP8VaapiVideoEncoderDelegate::EncodeParams& encode_params,
    const VideoBitrateAllocation& bitrate_allocation,
    size_t num_temporal_layers) {}

scoped_refptr<VP8Picture> GetVP8Picture(
    const VaapiVideoEncoderDelegate::EncodeJob& job) {}

Vp8FrameHeader GetDefaultVp8FrameHeader(bool keyframe,
                                        const gfx::Size& visible_size) {}

constexpr uint8_t kMinSupportedVP8TemporalLayers =;
constexpr uint8_t kMaxSupportedVP8TemporalLayers =;
constexpr size_t kTemporalLayerCycle =;

bool UpdateFrameHeaderForTemporalLayerEncoding(
    const size_t num_layers,
    const size_t frame_num,
    Vp8FrameHeader& frame_hdr,
    Vp8Metadata& metadata,
    std::array<bool, kNumVp8ReferenceBuffers>& ref_frames_used) {}

size_t GetActiveTemporalLayers(
    const VideoBitrateAllocation& bitrate_allocation) {}

bool VP8TLEncodingIsEnabled() {}

}  // namespace

VP8VaapiVideoEncoderDelegate::EncodeParams::EncodeParams()
    :{}

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

VP8VaapiVideoEncoderDelegate::~VP8VaapiVideoEncoderDelegate() = default;

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

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

size_t VP8VaapiVideoEncoderDelegate::GetMaxNumOfRefFrames() const {}

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

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

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

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

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

VaapiVideoEncoderDelegate::PrepareEncodeJobResult
VP8VaapiVideoEncoderDelegate::SetFrameHeader(
    size_t frame_num,
    VP8Picture& picture,
    std::array<bool, kNumVp8ReferenceBuffers>& ref_frames_used) {}

void VP8VaapiVideoEncoderDelegate::UpdateReferenceFrames(
    scoped_refptr<VP8Picture> picture) {}

bool VP8VaapiVideoEncoderDelegate::SubmitFrameParameters(
    EncodeJob& job,
    const EncodeParams& encode_params,
    scoped_refptr<VP8Picture> pic,
    const Vp8ReferenceFrameVector& ref_frames,
    const std::array<bool, kNumVp8ReferenceBuffers>& ref_frames_used) {}
}  // namespace media