Commit f100aadb authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu: Cache HW encoder capabilities

After crrev.com/c/1994849, a renderer process queries GPU process
HW encoder capabilities when the renderer process is created.
To get hw encoder capabilities, it is needed to open driver
nodes and query them. The time is small but may not be small
enough to ignore.

This CL caches hw encoder capabilities so that GPU process
only needs to query one time. The exception is V4L2 HW encoder.
Since V4L2 driver nodes may not be loaded at the early time of a
system boot up, we need to query it until the capabilities are
detected.

Bug: b:147404923
Bug: 948147
Test: HW encoder is used at appr.tc
Test: tast run webrtc.* on krane
Change-Id: Iba256bfda861adb75a5454eb011244cb193618d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1994038
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarAlexandre Courbot <acourbot@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733999}
parent 778ac205
......@@ -9,6 +9,7 @@
#include "build/build_config.h"
#include "media/gpu/buildflags.h"
#include "media/gpu/gpu_video_accelerator_util.h"
#include "media/gpu/macros.h"
#if BUILDFLAG(USE_V4L2_CODEC)
#include "media/gpu/v4l2/v4l2_video_encode_accelerator.h"
......@@ -108,6 +109,22 @@ std::vector<VEAFactoryFunction> GetVEAFactoryFunctions(
return vea_factory_functions;
}
VideoEncodeAccelerator::SupportedProfiles GetSupportedProfilesInternal(
const gpu::GpuPreferences& gpu_preferences) {
if (gpu_preferences.disable_accelerated_video_encode)
return VideoEncodeAccelerator::SupportedProfiles();
VideoEncodeAccelerator::SupportedProfiles profiles;
for (const auto& create_vea : GetVEAFactoryFunctions(gpu_preferences)) {
auto vea = std::move(create_vea).Run();
if (!vea)
continue;
GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(
vea->GetSupportedProfiles(), &profiles);
}
return profiles;
}
} // anonymous namespace
// static
......@@ -117,7 +134,7 @@ GpuVideoEncodeAcceleratorFactory::CreateVEA(
VideoEncodeAccelerator::Client* client,
const gpu::GpuPreferences& gpu_preferences) {
for (const auto& create_vea : GetVEAFactoryFunctions(gpu_preferences)) {
auto vea = create_vea.Run();
std::unique_ptr<VideoEncodeAccelerator> vea = create_vea.Run();
if (!vea)
continue;
if (!vea->Initialize(config, client)) {
......@@ -134,14 +151,23 @@ GpuVideoEncodeAcceleratorFactory::CreateVEA(
MEDIA_GPU_EXPORT VideoEncodeAccelerator::SupportedProfiles
GpuVideoEncodeAcceleratorFactory::GetSupportedProfiles(
const gpu::GpuPreferences& gpu_preferences) {
VideoEncodeAccelerator::SupportedProfiles profiles;
for (const auto& create_vea : GetVEAFactoryFunctions(gpu_preferences)) {
auto vea = std::move(create_vea).Run();
if (!vea)
continue;
GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(
vea->GetSupportedProfiles(), &profiles);
// Cache the supported profiles so that they will not be computed more than
// once per GPU process. It is assumed that |gpu_preferences| do not change
// between calls.
static VideoEncodeAccelerator::SupportedProfiles profiles =
GetSupportedProfilesInternal(gpu_preferences);
#if BUILDFLAG(USE_V4L2_CODEC)
// V4L2-only: the encoder devices may not be visible at the time the GPU
// process is starting. If the capabilities vector is empty, try to query the
// devices again in the hope that they will have appeared in the meantime.
// TODO(crbug.com/948147): trigger query when an device add/remove event
// (e.g. via udev) has happened instead.
if (profiles.empty()) {
VLOGF(1) << "Supported profiles empty, querying again...";
profiles = GetSupportedProfilesInternal(gpu_preferences);
}
#endif
return profiles;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment