chromium/media/gpu/vaapi/vaapi_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

// This has to be included first.
// See http://code.google.com/p/googletest/issues/detail?id=371
#include <drm_fourcc.h>
#include <gbm.h>
#include <unistd.h>
#include <va/va.h>
#include <va/va_drmcommon.h>
#include <va/va_str.h>
#include <xf86drm.h>

#include <map>
#include <optional>
#include <vector>

#include "base/bits.h"
#include "base/containers/contains.h"
#include "base/cpu.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/process/launch.h"
#include "base/strings/pattern.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_suite.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "media/base/media_switches.h"
#include "media/base/platform_features.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "media/media_buildflags.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/linux/gbm_defines.h"

#ifndef I915_FORMAT_MOD_4_TILED
#define I915_FORMAT_MOD_4_TILED
#endif

namespace media {
namespace {

std::optional<VAProfile> ConvertToVAProfile(VideoCodecProfile profile) {}

// Converts the given string to VAProfile
std::optional<VAProfile> StringToVAProfile(const std::string& va_profile) {}

// Converts the given string to VAEntrypoint
std::optional<VAEntrypoint> StringToVAEntrypoint(
    const std::string& va_entrypoint) {}

unsigned int ToVaRTFormat(uint32_t va_fourcc) {}

uint32_t ToVaFourcc(unsigned int va_rt_format) {}

int ToGBMFormat(unsigned int va_rt_format) {}

const std::string VARTFormatToString(unsigned int va_rt_format) {}

#define TOSTR(enumCase)

const char* VAProfileToString(VAProfile profile) {}

// Returns true if the Display version is 14. CPU model ID's are referenced from
// the following file in the kernel source: arch/x86/include/asm/intel-family.h.
bool IsDisplayVer14() {}

}  // namespace

class VaapiTest : public testing::Test {};

std::map<VAProfile, std::vector<VAEntrypoint>> ParseVainfo(
    const std::string& output) {}

std::string GetVaInfo(std::vector<std::string> argv) {}

std::map<VAProfile, std::vector<VAEntrypoint>> RetrieveVAInfoOutput() {}

TEST_F(VaapiTest, VaapiSandboxInitialization) {}

// Commit [1] deprecated VAProfileH264Baseline from libva in 2017 (release
// 2.0.0). This test verifies that such profile is never seen in the lab.
// [1] https://github.com/intel/libva/commit/6f69256f8ccc9a73c0b196ab77ac69ab1f4f33c2
TEST_F(VaapiTest, VerifyNoVAProfileH264Baseline) {}

// Verifies that every VAProfile from VaapiWrapper::GetSupportedDecodeProfiles()
// is indeed supported by the command line vainfo utility and by
// VaapiWrapper::IsDecodeSupported().
TEST_F(VaapiTest, GetSupportedDecodeProfiles) {}

// Verifies that every VAProfile from VaapiWrapper::GetSupportedEncodeProfiles()
// is indeed supported by the command line vainfo utility.
TEST_F(VaapiTest, GetSupportedEncodeProfiles) {}

// Verifies that the resolutions of profiles for VBR and CBR are the same.
TEST_F(VaapiTest, VbrAndCbrResolutionsMatch) {}

#if BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA)
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Verifies that VAProfileProtected is indeed supported by the command line
// vainfo utility.
TEST_F(VaapiTest, VaapiProfileProtected) {
  VAImplementation impl = VaapiWrapper::GetImplementationType();
  // VAProfileProtected is only used in the Intel iHD implementation. AMD does
  // not need to support that profile (but should be the only other protected
  // content VAAPI implementation).
  if (impl == VAImplementation::kIntelIHD) {
    const auto va_info = RetrieveVAInfoOutput();

    EXPECT_TRUE(base::Contains(va_info.at(VAProfileProtected),
                               VAEntrypointProtectedContent))
        << ", va profile: " << vaProfileStr(VAProfileProtected);
  } else {
    EXPECT_EQ(impl, VAImplementation::kMesaGallium);
  }
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
#endif  // BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA)

// Verifies that if JPEG decoding and encoding are supported by VaapiWrapper,
// they are also supported by by the command line vainfo utility.
TEST_F(VaapiTest, VaapiProfilesJPEG) {}

// Verifies that the default VAEntrypoint as per VaapiWrapper is indeed among
// the supported ones.
TEST_F(VaapiTest, DefaultEntrypointIsSupported) {}

// Verifies that VaapiWrapper::Create...() fails when called with an unsupported
// codec profile.
TEST_F(VaapiTest, UnsupportedVAProfile) {}

// Verifies that VaapiWrapper::Create...() fails after the limit of created
// instances exceeds the threshold.
TEST_F(VaapiTest, TooManyDecoderInstances) {}

// Verifies that VaapiWrapper::Create...() fails when an EncryptionScheme is
// specified for a non-protected CodecMode.
TEST_F(VaapiTest, EncryptionSchemeNeedsCodecMode) {}

// Verifies that VaapiWrapper::CreateContext() will queue up a buffer to set the
// encoder to its lowest quality setting if a given VAProfile and VAEntrypoint
// claims to support configuring it.
TEST_F(VaapiTest, LowQualityEncodingSetting) {}

// This test checks the supported SVC scalability mode.
TEST_F(VaapiTest, CheckSupportedSVCScalabilityModes) {}

class VaapiVppTest
    : public VaapiTest,
      public testing::WithParamInterface<std::tuple<uint32_t, uint32_t>> {};

TEST_P(VaapiVppTest, BlitWithVAAllocatedSurfaces) {}

// TODO(b/187852384): Consider adding more VaapiVppTest cases, e.g. crops.

// Note: vaCreateSurfaces() uses the RT version of the Four CC, so we don't need
// to consider swizzlings, since they'll end up mapped to the same RT format.
constexpr uint32_t kVAFourCCs[] =;

INSTANTIATE_TEST_SUITE_P();

class VaapiMinigbmTest
    : public VaapiTest,
      public testing::WithParamInterface<
          std::tuple<VAProfile, unsigned int /*va_rt_format*/, gfx::Size>> {};

// This test allocates a VASurface (via VaapiWrapper) for the given VAProfile,
// VA RT Format and resolution (as per the test parameters). It then verifies
// that said VASurface's metadata (e.g. width, height, number of planes, pitch)
// are the same as those we would allocate via minigbm.
TEST_P(VaapiMinigbmTest, AllocateAndCompareWithMinigbm) {}

constexpr VAProfile kVACodecProfiles[] =;
constexpr uint32_t kVARTFormatsForGBM[] =;
constexpr gfx::Size kResolutions[] =;
// clang-format on

INSTANTIATE_TEST_SUITE_P();

}  // namespace media

int main(int argc, char** argv) {}