chromium/media/gpu/vaapi/h264_vaapi_video_encoder_delegate_unittest.cc

// Copyright 2019 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 <memory>

#include "base/logging.h"
#include "base/test/scoped_feature_list.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/vaapi/vaapi_common.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
Invoke;
Return;

namespace media {
namespace {

constexpr gfx::Size kDefaultVisibleSize =;
constexpr VideoEncodeAccelerator::Config::ContentType kDefaultContentType =;
// Limit max delay for intra frame with HRD buffer size (500ms-1s for camera
// video, 1s-10s for desktop sharing).
constexpr base::TimeDelta kHRDBufferDelayCamera =;
constexpr base::TimeDelta kHRDBufferDelayDisplay =;
constexpr uint8_t kMinQP =;
constexpr uint8_t kScreenMinQP =;
constexpr uint8_t kMaxQP =;
constexpr size_t kSupportedNumTemporalLayersByController =;

VaapiVideoEncoderDelegate::Config kDefaultVEADelegateConfig{};

VideoEncodeAccelerator::Config DefaultVEAConfig() {}

MATCHER_P2(MatchVABufferDescriptor, va_buffer_type, va_buffer_size, "") {}

MATCHER_P2(MatchVABufferDescriptorForMiscParam,
           va_misc_param_type,
           va_misc_param_size,
           "") {}

MATCHER_P(MatchVABufferDescriptorForPackedHeader, va_packed_header_type, "") {}

MATCHER(MatchVABufferDescriptorForPackedHeaderData, "") {}

MATCHER_P5(MatchRtcConfigWithRates,
           bitrate_allocation,
           framerate,
           visible_size,
           num_temporal_layers,
           content_type,
           "") {}

MATCHER_P3(MatchFrameParam, keyframe, temporal_layer_id, timestamp, "") {}

void ValidateTemporalLayerStructure(uint8_t num_temporal_layers,
                                    size_t num_frames,
                                    int frame_num,
                                    uint8_t temporal_idx,
                                    bool ref,
                                    int& previous_frame_num) {}

class MockVaapiWrapper : public VaapiWrapper {};

class MockH264RateControl : public H264RateControlWrapper {};

}  // namespace

class H264VaapiVideoEncoderDelegateTest
    : public ::testing::TestWithParam<uint8_t> {};

std::unique_ptr<VaapiVideoEncoderDelegate::EncodeJob>
H264VaapiVideoEncoderDelegateTest::CreateEncodeJob(bool keyframe) {}

void H264VaapiVideoEncoderDelegateTest::SetUp() {}

bool H264VaapiVideoEncoderDelegateTest::InitializeEncoder(
    uint8_t num_temporal_layers) {}

void H264VaapiVideoEncoderDelegateTest::InitializeSWBitrateController() {}

void H264VaapiVideoEncoderDelegateTest::EncodeFrame(
    bool force_keyframe,
    uint8_t num_temporal_layers) {}

TEST_F(H264VaapiVideoEncoderDelegateTest, Initialize) {}

TEST_F(H264VaapiVideoEncoderDelegateTest, ChangeBitrateModeFails) {}

TEST_F(H264VaapiVideoEncoderDelegateTest, VariableBitrate_Initialize) {}

#if BUILDFLAG(IS_CHROMEOS)
TEST_F(H264VaapiVideoEncoderDelegateTest, InitializeWithSWBitrateController) {
  base::test::ScopedFeatureList scoped_feature_list(
      media::kVaapiH264SWBitrateController);
  InitializeSWBitrateController();
  auto vea_config = DefaultVEAConfig();
  auto initial_bitrate_allocation =
      AllocateBitrateForDefaultEncoding(vea_config);

  EXPECT_CALL(
      *mock_rate_ctrl_,
      UpdateRateControl(MatchRtcConfigWithRates(
          initial_bitrate_allocation, vea_config.framerate, kDefaultVisibleSize,
          kSupportedNumTemporalLayersByController, kDefaultContentType)));
  EXPECT_TRUE(InitializeEncoder(kSupportedNumTemporalLayersByController));
}

TEST_F(H264VaapiVideoEncoderDelegateTest, EncodeWithSWBitrateController) {
  base::test::ScopedFeatureList scoped_feature_list(
      media::kVaapiH264SWBitrateController);
  InitializeSWBitrateController();
  auto vea_config = DefaultVEAConfig();
  auto initial_bitrate_allocation =
      AllocateBitrateForDefaultEncoding(vea_config);

  EXPECT_CALL(
      *mock_rate_ctrl_,
      UpdateRateControl(MatchRtcConfigWithRates(
          initial_bitrate_allocation, vea_config.framerate, kDefaultVisibleSize,
          kSupportedNumTemporalLayersByController, kDefaultContentType)));
  EXPECT_TRUE(InitializeEncoder(kSupportedNumTemporalLayersByController));

  size_t kKeyFrameInterval = 10;
  for (size_t frame_num = 0; frame_num < 30; ++frame_num) {
    const bool force_keyframe = frame_num % kKeyFrameInterval == 0;
    EncodeFrame(force_keyframe, kSupportedNumTemporalLayersByController);
  }
}
#endif // BUILDFLAG(IS_CHROMEOS)

TEST_P(H264VaapiVideoEncoderDelegateTest, EncodeTemporalLayerRequest) {}

// We expect 4 to fail to initialize.
INSTANTIATE_TEST_SUITE_P();
}  // namespace media