chromium/media/gpu/vaapi/vaapi_video_encode_accelerator_unittest.cc

// Copyright 2020 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/vaapi_video_encode_accelerator.h"

#include <memory>
#include <numeric>
#include <vector>

#include "base/bits.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/task_environment.h"
#include "build/chromeos_buildflags.h"
#include "media/base/media_util.h"
#include "media/base/mock_media_log.h"
#include "media/base/video_frame.h"
#include "media/gpu/gpu_video_encode_accelerator_helpers.h"
#include "media/gpu/vaapi/vaapi_utils.h"
#include "media/gpu/vaapi/vaapi_video_encoder_delegate.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.h"
#include "media/gpu/vp9_picture.h"
#include "media/video/fake_gpu_memory_buffer.h"
#include "media/video/video_encode_accelerator.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/native_pixmap.h"

RunClosure;
_;
Eq;
HasSubstr;
Return;
WithArgs;

namespace media {
namespace {

constexpr gfx::Size kDefaultEncodeSize(1280, 720);
constexpr uint32_t kDefaultBitrateBps =;
constexpr Bitrate kDefaultBitrate =;
constexpr uint32_t kDefaultFramerate =;
constexpr size_t kMaxNumOfRefFrames =;

constexpr int kSpatialLayersResolutionDenom[][3] =;

VideoEncodeAccelerator::Config DefaultVideoEncodeAcceleratorConfig() {}

std::vector<VideoEncodeAccelerator::Config::SpatialLayer> GetDefaultSVCLayers(
    size_t num_spatial_layers,
    size_t num_temporal_layers) {}

std::vector<gfx::Size> GetDefaultSVCResolutions(size_t num_spatial_layers) {}

bool IsSVCSupported(const VideoEncodeAccelerator::Config& config) {}

MATCHER_P(CheckEncodeData, payload_size_bytes, "") {}

MATCHER_P3(MatchesBitstreamBufferMetadata,
           payload_size_bytes,
           key_frame,
           has_vp9_metadata,
           "") {}

MATCHER_P2(MatchesEncoderInfo,
           num_of_spatial_layers,
           num_of_temporal_layers,
           "") {}

MATCHER(ContainsTooManyEncoderInstances, "") {}

class MockVideoEncodeAcceleratorClient : public VideoEncodeAccelerator::Client {};

class MockVaapiWrapper : public VaapiWrapper {};

class MockVaapiVideoEncoderDelegate : public VaapiVideoEncoderDelegate {};

class MockVP9VaapiVideoEncoderDelegate : public VP9VaapiVideoEncoderDelegate {};
}  // namespace

struct VaapiVideoEncodeAcceleratorTestParam;

class VaapiVideoEncodeAcceleratorTest
    : public ::testing::TestWithParam<VaapiVideoEncodeAcceleratorTestParam> {};

struct VaapiVideoEncodeAcceleratorTestParam {} kTestCases[]{};

TEST_P(VaapiVideoEncodeAcceleratorTest, Initialize) {}

// This test verifies VP9 single stream and temporal layer encoding in non
// native input mode.
TEST_P(VaapiVideoEncodeAcceleratorTest, EncodeVP9WithSingleSpatialLayer) {}

// This test verifies VP9 multiple spaital layers encoding in native input mode.
TEST_P(VaapiVideoEncodeAcceleratorTest, EncodeVP9WithMultipleSpatialLayers) {}

// This test verifies Initialize() fails with correct corresponding error
// logging when the max number of encoder instances is reached. Once it happens,
// the encoder fails the rest of the Initialize() sequence, which requires
// setting up new |encoder_| and |vaapi_wrapper_|s to succeed. So this test
// creates and stores encoder instances within the threshold number without
// initializing them.
TEST_F(VaapiVideoEncodeAcceleratorTest, TooManyEncoderInstances) {}

// This test verifies Initialize() fails when the encoder is already
// Initialize()d.
TEST_F(VaapiVideoEncodeAcceleratorTest, AttemptedInitialization) {}

TEST_F(VaapiVideoEncodeAcceleratorTest, InitializeWithUnsupportedConfig) {}

// This test verifies RequestEncodingParametersChange() succeeds.
TEST_F(VaapiVideoEncodeAcceleratorTest, EncodingParametersChange) {}

// This test verifies RequestEncodingParametersChange() succeeds with
// multi-dimensional bitrate allocation.
TEST_F(VaapiVideoEncodeAcceleratorTest,
       EncodingParametersChangeWithBitrateAllocation) {}

INSTANTIATE_TEST_SUITE_P();
}  // namespace media