#include "media/gpu/test/video_test_environment.h"
#include "base/logging/logging_settings.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "media/gpu/buildflags.h"
#include "mojo/core/embedder/embedder.h"
#if BUILDFLAG(USE_V4L2_CODEC)
#include "media/gpu/v4l2/v4l2_utils.h"
#endif
#if BUILDFLAG(USE_VAAPI)
#include "media/gpu/vaapi/vaapi_wrapper.h"
#endif
namespace media {
namespace test {
VideoTestEnvironment::VideoTestEnvironment() : VideoTestEnvironment({}, {}) {}
VideoTestEnvironment::VideoTestEnvironment(
const std::vector<base::test::FeatureRef>& enabled_features,
const std::vector<base::test::FeatureRef>& disabled_features,
const bool need_task_environment) {
mojo::core::Init();
logging::LoggingSettings settings;
settings.logging_dest =
logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
if (!logging::InitLogging(settings))
ADD_FAILURE();
if (need_task_environment) {
TestTimeouts::Initialize();
task_environment_ = std::make_unique<base::test::TaskEnvironment>(
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
base::test::TaskEnvironment::MainThreadType::UI
#else
base::test::TaskEnvironment::MainThreadType::DEFAULT
#endif
);
at_exit_manager_ = std::make_unique<base::AtExitManager>();
}
scoped_feature_list_.InitWithFeatures(enabled_features, disabled_features);
#if BUILDFLAG(USE_VAAPI)
media::VaapiWrapper::PreSandboxInitialization(
true);
#endif
}
VideoTestEnvironment::~VideoTestEnvironment() = default;
void VideoTestEnvironment::TearDown() {
task_environment_->RunUntilIdle();
}
base::FilePath VideoTestEnvironment::GetTestOutputFilePath() const {
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
base::FilePath::StringType test_name;
base::FilePath::StringType test_suite_name;
#if BUILDFLAG(IS_WIN)
test_name =
base::FilePath::FromASCII(base::StringPrintf("%s", test_info->name()))
.value();
test_suite_name = base::FilePath::FromASCII(
base::StringPrintf("%s", test_info->test_suite_name()))
.value();
#else
test_name = test_info->name();
test_suite_name = test_info->test_suite_name();
#endif
return base::FilePath(test_suite_name).Append(test_name);
}
bool VideoTestEnvironment::IsV4L2VirtualDriver() const {
#if BUILDFLAG(USE_V4L2_CODEC)
return IsVislDriver();
#else
return false;
#endif
}
}
}