Commit 139567ba authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

content/renderer/media: Query GPU process HW encoder capabilities

Originally GpuVideoAcceleratorFactoriesImpl get HW encoder
capabilities by referencing values stored GpuInfo instance.
However, the values are not updated after GPU process boots up.
Even if a new hw encoder is available after GPU process is
initialized, the hw encoder is not detected.

This fixes the problem by querying GPU process the hw encoder
capabilities when a render process is created. e.g. open the
page.

Bug: b:147404923
Test: HW encoder is used at appr.tc
Test: tast run webrtc.* on krane
Change-Id: Ibca82b6e54e9b5d585037c8e63f4c663d085db0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1994849Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735339}
parent d3becd63
...@@ -97,12 +97,6 @@ GpuVideoAcceleratorFactoriesImpl::GpuVideoAcceleratorFactoriesImpl( ...@@ -97,12 +97,6 @@ GpuVideoAcceleratorFactoriesImpl::GpuVideoAcceleratorFactoriesImpl(
video_accelerator_enabled_(enable_video_accelerator), video_accelerator_enabled_(enable_video_accelerator),
gpu_memory_buffer_manager_( gpu_memory_buffer_manager_(
RenderThreadImpl::current()->GetGpuMemoryBufferManager()), RenderThreadImpl::current()->GetGpuMemoryBufferManager()),
supported_vea_profiles_(
enable_video_accelerator
? media::GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles(
gpu_channel_host_->gpu_info()
.video_encode_accelerator_supported_profiles)
: media::VideoEncodeAccelerator::SupportedProfiles()),
thread_safe_sender_(ChildThreadImpl::current()->thread_safe_sender()) { thread_safe_sender_(ChildThreadImpl::current()->thread_safe_sender()) {
DCHECK(main_thread_task_runner_); DCHECK(main_thread_task_runner_);
DCHECK(gpu_channel_host_); DCHECK(gpu_channel_host_);
...@@ -136,6 +130,11 @@ void GpuVideoAcceleratorFactoriesImpl::BindOnTaskRunner( ...@@ -136,6 +130,11 @@ void GpuVideoAcceleratorFactoriesImpl::BindOnTaskRunner(
context_provider_->AddObserver(this); context_provider_->AddObserver(this);
vea_provider_->GetVideoEncodeAcceleratorSupportedProfiles(
base::BindOnce(&GpuVideoAcceleratorFactoriesImpl::
OnGetVideoEncodeAcceleratorSupportedProfiles,
base::Unretained(this)));
#if BUILDFLAG(ENABLE_MOJO_VIDEO_DECODER) #if BUILDFLAG(ENABLE_MOJO_VIDEO_DECODER)
// Note: This is a bit of a hack, since we don't specify the implementation // Note: This is a bit of a hack, since we don't specify the implementation
// before asking for the map of supported configs. We do this because it // before asking for the map of supported configs. We do this because it
...@@ -152,11 +151,19 @@ void GpuVideoAcceleratorFactoriesImpl::BindOnTaskRunner( ...@@ -152,11 +151,19 @@ void GpuVideoAcceleratorFactoriesImpl::BindOnTaskRunner(
void GpuVideoAcceleratorFactoriesImpl::OnSupportedDecoderConfigs( void GpuVideoAcceleratorFactoriesImpl::OnSupportedDecoderConfigs(
const media::SupportedVideoDecoderConfigMap& supported_configs) { const media::SupportedVideoDecoderConfigMap& supported_configs) {
base::AutoLock lock(supported_decoder_configs_lock_); base::AutoLock lock(supported_profiles_lock_);
supported_decoder_configs_ = supported_configs; supported_decoder_configs_ = supported_configs;
video_decoder_.reset(); video_decoder_.reset();
} }
void GpuVideoAcceleratorFactoriesImpl::
OnGetVideoEncodeAcceleratorSupportedProfiles(
const media::VideoEncodeAccelerator::SupportedProfiles&
supported_profiles) {
base::AutoLock lock(supported_profiles_lock_);
supported_vea_profiles_ = supported_profiles;
}
bool GpuVideoAcceleratorFactoriesImpl::CheckContextLost() { bool GpuVideoAcceleratorFactoriesImpl::CheckContextLost() {
DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(task_runner_->BelongsToCurrentThread());
if (context_provider_lost_on_media_thread_) if (context_provider_lost_on_media_thread_)
...@@ -216,7 +223,7 @@ GpuVideoAcceleratorFactoriesImpl::IsDecoderConfigSupported( ...@@ -216,7 +223,7 @@ GpuVideoAcceleratorFactoriesImpl::IsDecoderConfigSupported(
return Supported::kFalse; return Supported::kFalse;
} }
base::AutoLock lock(supported_decoder_configs_lock_); base::AutoLock lock(supported_profiles_lock_);
// If GetSupportedConfigs() has not completed (or was never started), report // If GetSupportedConfigs() has not completed (or was never started), report
// that all configs are supported. Clients will find out that configs are not // that all configs are supported. Clients will find out that configs are not
...@@ -270,6 +277,16 @@ GpuVideoAcceleratorFactoriesImpl::CreateVideoEncodeAccelerator() { ...@@ -270,6 +277,16 @@ GpuVideoAcceleratorFactoriesImpl::CreateVideoEncodeAccelerator() {
if (CheckContextLost()) if (CheckContextLost())
return nullptr; return nullptr;
base::AutoLock lock(supported_profiles_lock_);
// When |supported_vea_profiles_| is empty, no hw encoder is available or
// we have not yet gotten the supported profiles.
if (!supported_vea_profiles_) {
DVLOG(2) << "VEA's profiles have not yet been gotten";
} else if (supported_vea_profiles_->empty()) {
// There is no profile supported by VEA.
return nullptr;
}
mojo::PendingRemote<media::mojom::VideoEncodeAccelerator> vea; mojo::PendingRemote<media::mojom::VideoEncodeAccelerator> vea;
vea_provider_->CreateVideoEncodeAccelerator( vea_provider_->CreateVideoEncodeAccelerator(
vea.InitWithNewPipeAndPassReceiver()); vea.InitWithNewPipeAndPassReceiver());
...@@ -278,8 +295,10 @@ GpuVideoAcceleratorFactoriesImpl::CreateVideoEncodeAccelerator() { ...@@ -278,8 +295,10 @@ GpuVideoAcceleratorFactoriesImpl::CreateVideoEncodeAccelerator() {
return nullptr; return nullptr;
return std::unique_ptr<media::VideoEncodeAccelerator>( return std::unique_ptr<media::VideoEncodeAccelerator>(
new media::MojoVideoEncodeAccelerator(std::move(vea), new media::MojoVideoEncodeAccelerator(
supported_vea_profiles_)); std::move(vea),
supported_vea_profiles_.value_or(
media::VideoEncodeAccelerator::SupportedProfiles())));
} }
std::unique_ptr<gfx::GpuMemoryBuffer> std::unique_ptr<gfx::GpuMemoryBuffer>
...@@ -389,7 +408,9 @@ GpuVideoAcceleratorFactoriesImpl::GetTaskRunner() { ...@@ -389,7 +408,9 @@ GpuVideoAcceleratorFactoriesImpl::GetTaskRunner() {
media::VideoEncodeAccelerator::SupportedProfiles media::VideoEncodeAccelerator::SupportedProfiles
GpuVideoAcceleratorFactoriesImpl::GetVideoEncodeAcceleratorSupportedProfiles() { GpuVideoAcceleratorFactoriesImpl::GetVideoEncodeAcceleratorSupportedProfiles() {
return supported_vea_profiles_; base::AutoLock lock(supported_profiles_lock_);
return supported_vea_profiles_.value_or(
media::VideoEncodeAccelerator::SupportedProfiles());
} }
scoped_refptr<viz::ContextProvider> scoped_refptr<viz::ContextProvider>
......
...@@ -154,6 +154,9 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl ...@@ -154,6 +154,9 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
void OnSupportedDecoderConfigs( void OnSupportedDecoderConfigs(
const media::SupportedVideoDecoderConfigMap& supported_configs); const media::SupportedVideoDecoderConfigMap& supported_configs);
void OnGetVideoEncodeAcceleratorSupportedProfiles(
const media::VideoEncodeAccelerator::SupportedProfiles&
supported_profiles);
const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
...@@ -186,16 +189,17 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl ...@@ -186,16 +189,17 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
// SupportedDecoderConfigs state. // SupportedDecoderConfigs state.
mojo::Remote<media::mojom::VideoDecoder> video_decoder_; mojo::Remote<media::mojom::VideoDecoder> video_decoder_;
base::Lock supported_decoder_configs_lock_;
base::Lock supported_profiles_lock_;
// If the Optional is empty, then we have not yet gotten the configs. If the // If the Optional is empty, then we have not yet gotten the configs. If the
// Optional contains an empty vector, then we have gotten the result and there // Optional contains an empty vector, then we have gotten the result and there
// are no supported configs. // are no supported configs.
base::Optional<media::SupportedVideoDecoderConfigMap> base::Optional<media::SupportedVideoDecoderConfigMap>
supported_decoder_configs_ GUARDED_BY(supported_decoder_configs_lock_); supported_decoder_configs_ GUARDED_BY(supported_profiles_lock_);
const media::VideoEncodeAccelerator::SupportedProfiles
supported_vea_profiles_;
base::Optional<media::VideoEncodeAccelerator::SupportedProfiles>
supported_vea_profiles_ GUARDED_BY(supported_profiles_lock_);
// For sending requests to allocate shared memory in the Browser process. // For sending requests to allocate shared memory in the Browser process.
scoped_refptr<ThreadSafeSender> thread_safe_sender_; scoped_refptr<ThreadSafeSender> thread_safe_sender_;
......
...@@ -33,10 +33,25 @@ import "media/mojo/mojom/video_encoder_info.mojom"; ...@@ -33,10 +33,25 @@ import "media/mojo/mojom/video_encoder_info.mojom";
// time the Client can send a RequestEncodingParametersChange() to the VEA. None // time the Client can send a RequestEncodingParametersChange() to the VEA. None
// of these messages are acknowledged. // of these messages are acknowledged.
struct VideoEncodeAcceleratorSupportedProfile {
VideoCodecProfile profile;
gfx.mojom.Size min_resolution;
gfx.mojom.Size max_resolution;
uint32 max_framerate_numerator;
uint32 max_framerate_denominator;
};
// A renderer process calls this interface's functions. GPU process implements
// this interface.
interface VideoEncodeAcceleratorProvider { interface VideoEncodeAcceleratorProvider {
// Creates a VideoEncodeAccelerator bound to |receiver|. // Creates a VideoEncodeAccelerator bound to |receiver|.
CreateVideoEncodeAccelerator( CreateVideoEncodeAccelerator(
pending_receiver<VideoEncodeAccelerator> receiver); pending_receiver<VideoEncodeAccelerator> receiver);
// Get a VideoEncodeAccelerator supported profiles.
GetVideoEncodeAcceleratorSupportedProfiles()
=> (array<VideoEncodeAcceleratorSupportedProfile> profiles);
}; };
// Class that describes how video bitrate, in bps, is allocated across temporal // Class that describes how video bitrate, in bps, is allocated across temporal
......
...@@ -31,5 +31,6 @@ type_mappings = [ ...@@ -31,5 +31,6 @@ type_mappings = [
"media.mojom.VideoBitrateAllocation=::media::VideoBitrateAllocation", "media.mojom.VideoBitrateAllocation=::media::VideoBitrateAllocation",
"media.mojom.VideoEncodeAccelerator.Error=::media::VideoEncodeAccelerator::Error", "media.mojom.VideoEncodeAccelerator.Error=::media::VideoEncodeAccelerator::Error",
"media.mojom.VideoEncodeAcceleratorConfig=::media::VideoEncodeAccelerator::Config", "media.mojom.VideoEncodeAcceleratorConfig=::media::VideoEncodeAccelerator::Config",
"media.mojom.VideoEncodeAcceleratorSupportedProfile=::media::VideoEncodeAccelerator::SupportedProfile",
"media.mojom.Vp8Metadata=::media::Vp8Metadata", "media.mojom.Vp8Metadata=::media::Vp8Metadata",
] ]
...@@ -11,6 +11,22 @@ ...@@ -11,6 +11,22 @@
namespace mojo { namespace mojo {
// static
bool StructTraits<media::mojom::VideoEncodeAcceleratorSupportedProfileDataView,
media::VideoEncodeAccelerator::SupportedProfile>::
Read(media::mojom::VideoEncodeAcceleratorSupportedProfileDataView data,
media::VideoEncodeAccelerator::SupportedProfile* out) {
if (!data.ReadMinResolution(&out->min_resolution) ||
!data.ReadMaxResolution(&out->max_resolution) ||
!data.ReadProfile(&out->profile)) {
return false;
}
out->max_framerate_numerator = data.max_framerate_numerator();
out->max_framerate_denominator = data.max_framerate_denominator();
return true;
}
// static // static
media::mojom::VideoEncodeAccelerator::Error media::mojom::VideoEncodeAccelerator::Error
EnumTraits<media::mojom::VideoEncodeAccelerator::Error, EnumTraits<media::mojom::VideoEncodeAccelerator::Error,
......
...@@ -13,6 +13,40 @@ ...@@ -13,6 +13,40 @@
namespace mojo { namespace mojo {
template <>
struct StructTraits<
media::mojom::VideoEncodeAcceleratorSupportedProfileDataView,
media::VideoEncodeAccelerator::SupportedProfile> {
static media::VideoCodecProfile profile(
const media::VideoEncodeAccelerator::SupportedProfile& profile) {
return profile.profile;
}
static const gfx::Size& min_resolution(
const media::VideoEncodeAccelerator::SupportedProfile& profile) {
return profile.min_resolution;
}
static const gfx::Size& max_resolution(
const media::VideoEncodeAccelerator::SupportedProfile& profile) {
return profile.max_resolution;
}
static uint32_t max_framerate_numerator(
const media::VideoEncodeAccelerator::SupportedProfile& profile) {
return profile.max_framerate_numerator;
}
static uint32_t max_framerate_denominator(
const media::VideoEncodeAccelerator::SupportedProfile& profile) {
return profile.max_framerate_denominator;
}
static bool Read(
media::mojom::VideoEncodeAcceleratorSupportedProfileDataView data,
media::VideoEncodeAccelerator::SupportedProfile* out);
};
template <> template <>
struct EnumTraits<media::mojom::VideoEncodeAccelerator::Error, struct EnumTraits<media::mojom::VideoEncodeAccelerator::Error,
media::VideoEncodeAccelerator::Error> { media::VideoEncodeAccelerator::Error> {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "media/base/bind_to_current_loop.h" #include "media/base/bind_to_current_loop.h"
#include "media/base/limits.h" #include "media/base/limits.h"
#include "media/gpu/gpu_video_encode_accelerator_factory.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/system/platform_handle.h" #include "mojo/public/cpp/system/platform_handle.h"
...@@ -43,4 +44,11 @@ void MojoVideoEncodeAcceleratorProvider::CreateVideoEncodeAccelerator( ...@@ -43,4 +44,11 @@ void MojoVideoEncodeAcceleratorProvider::CreateVideoEncodeAccelerator(
std::move(receiver), create_vea_callback_, gpu_preferences_); std::move(receiver), create_vea_callback_, gpu_preferences_);
} }
void MojoVideoEncodeAcceleratorProvider::
GetVideoEncodeAcceleratorSupportedProfiles(
GetVideoEncodeAcceleratorSupportedProfilesCallback callback) {
std::move(callback).Run(
GpuVideoEncodeAcceleratorFactory::GetSupportedProfiles(gpu_preferences_));
}
} // namespace media } // namespace media
...@@ -42,6 +42,8 @@ class MEDIA_MOJO_EXPORT MojoVideoEncodeAcceleratorProvider ...@@ -42,6 +42,8 @@ class MEDIA_MOJO_EXPORT MojoVideoEncodeAcceleratorProvider
// mojom::VideoEncodeAcceleratorProvider impl. // mojom::VideoEncodeAcceleratorProvider impl.
void CreateVideoEncodeAccelerator( void CreateVideoEncodeAccelerator(
mojo::PendingReceiver<mojom::VideoEncodeAccelerator> receiver) override; mojo::PendingReceiver<mojom::VideoEncodeAccelerator> receiver) override;
void GetVideoEncodeAcceleratorSupportedProfiles(
GetVideoEncodeAcceleratorSupportedProfilesCallback callback) override;
private: private:
const CreateAndInitializeVideoEncodeAcceleratorCallback create_vea_callback_; const CreateAndInitializeVideoEncodeAcceleratorCallback create_vea_callback_;
......
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