#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.h"
#include <va/va.h>
#include <algorithm>
#include <memory>
#include <numeric>
#include <optional>
#include <tuple>
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "media/gpu/gpu_video_encode_accelerator_helpers.h"
#include "media/gpu/vaapi/vaapi_common.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "media/gpu/vp9_svc_layers.h"
#include "media/parsers/vp9_parser.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libvpx/source/libvpx/vp9/common/vp9_blockd.h"
#include "third_party/libvpx/source/libvpx/vp9/ratectrl_rtc.h"
_;
InSequence;
Invoke;
Return;
namespace media {
namespace {
constexpr size_t kDefaultMaxNumRefFrames = …;
constexpr int kSpatialLayersResolutionScaleDenom[][3] = …;
constexpr uint8_t kTemporalLayerPattern[][4] = …;
VaapiVideoEncoderDelegate::Config kDefaultVaapiVideoEncoderDelegateConfig{ … };
VideoEncodeAccelerator::Config DefaultVideoEncodeAcceleratorConfig() { … }
constexpr std::array<bool, kVp9NumRefsPerFrame> kRefFramesUsedForKeyFrame = …;
constexpr std::array<bool, kVp9NumRefsPerFrame> kRefFramesUsedForInterFrame = …;
constexpr std::array<bool, kVp9NumRefsPerFrame>
kRefFramesUsedForInterFrameInTemporalLayer = …;
void GetTemporalLayer(bool keyframe,
int frame_num,
size_t num_spatial_layers,
size_t num_temporal_layers,
std::array<bool, kVp9NumRefsPerFrame>* ref_frames_used,
uint8_t* temporal_layer_id) { … }
VideoBitrateAllocation CreateBitrateAllocationWithActiveLayers(
const VideoBitrateAllocation& bitrate_allocation,
const std::vector<size_t>& active_layers,
size_t num_temporal_layers) { … }
VideoBitrateAllocation AdaptBitrateAllocation(
const VideoBitrateAllocation& bitrate_allocation) { … }
std::vector<gfx::Size> GetDefaultSpatialLayerResolutions(
size_t num_spatial_layers) { … }
MATCHER_P4(MatchRtcConfigWithRates,
bitrate_allocation,
framerate,
num_temporal_layers,
spatial_layer_resolutions,
"") { … }
MATCHER_P3(MatchFrameParam,
frame_type,
temporal_layer_id,
spatial_layer_id,
"") { … }
MATCHER_P2(MatchVABufferDescriptor, va_buffer_type, va_buffer_size, "") { … }
class MockVaapiWrapper : public VaapiWrapper { … };
class MockVP9RateControl : public VP9RateControlWrapper { … };
}
struct VP9VaapiVideoEncoderDelegateTestParam;
class VP9VaapiVideoEncoderDelegateTest
: public ::testing::TestWithParam<VP9VaapiVideoEncoderDelegateTestParam> { … };
void VP9VaapiVideoEncoderDelegateTest::ResetEncoder() { … }
void VP9VaapiVideoEncoderDelegateTest::SetUp() { … }
std::unique_ptr<VaapiVideoEncoderDelegate::EncodeJob>
VP9VaapiVideoEncoderDelegateTest::CreateEncodeJob(
bool keyframe,
uint8_t spatial_index,
bool end_of_picture,
base::TimeDelta timestamp,
const VASurfaceID va_surface_id,
const scoped_refptr<VP9Picture>& picture) { … }
void VP9VaapiVideoEncoderDelegateTest::InitializeVP9VaapiVideoEncoderDelegate(
SVCInterLayerPredMode inter_layer_pred,
size_t num_spatial_layers,
size_t num_temporal_layers,
bool enable_drop_frame) { … }
void VP9VaapiVideoEncoderDelegateTest::
EncodeConstantQuantizationParameterSequence(
bool force_key,
bool end_of_picture,
base::TimeDelta timestamp,
const gfx::Size& layer_size,
std::optional<std::array<bool, kVp9NumRefsPerFrame>>
expected_ref_frames_used,
uint8_t expected_temporal_layer_id,
uint8_t expected_spatial_layer_id,
bool s_mode_keyframe,
bool drop_frame) { … }
void VP9VaapiVideoEncoderDelegateTest::UpdateRatesAndEncode(
SVCInterLayerPredMode inter_layer_pred,
const VideoBitrateAllocation& bitrate_allocation,
uint32_t framerate,
bool valid_rates_request,
bool is_key_pic,
const std::vector<gfx::Size>& expected_spatial_layer_resolutions,
size_t expected_temporal_layers,
size_t expected_temporal_layer_id) { … }
void VP9VaapiVideoEncoderDelegateTest::UpdateRatesTest(
SVCInterLayerPredMode inter_layer_pred,
size_t num_spatial_layers,
size_t num_temporal_layers) { … }
struct VP9VaapiVideoEncoderDelegateTestParam { … } kTestCasesForVP9VaapiVideoEncoderDelegateTest[] = …;
TEST_P(VP9VaapiVideoEncoderDelegateTest, Initialize) { … }
TEST_P(VP9VaapiVideoEncoderDelegateTest, EncodeWithSoftwareBitrateControl) { … }
TEST_P(VP9VaapiVideoEncoderDelegateTest,
ForceKeyFrameWithSoftwareBitrateControl) { … }
TEST_P(VP9VaapiVideoEncoderDelegateTest,
EncodeWithSoftwareBitrateControlEnablingFrameDrop) { … }
TEST_P(VP9VaapiVideoEncoderDelegateTest, UpdateRates) { … }
TEST_P(VP9VaapiVideoEncoderDelegateTest, DeactivateActivateSpatialLayers) { … }
TEST_P(VP9VaapiVideoEncoderDelegateTest, FailsWithInvalidSpatialLayers) { … }
INSTANTIATE_TEST_SUITE_P(…);
}