#ifdef UNSAFE_BUFFERS_BUILD
#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 {
constexpr size_t kKFPeriod = …;
constexpr uint8_t kMinQP = …;
constexpr uint8_t kMaxQP = …;
constexpr uint8_t kScreenMinQP = …;
constexpr uint8_t kScreenMaxQP = …;
uint8_t QindexToQuantizer(uint8_t q_index) { … }
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() { … }
}
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) { … }
}