summaryrefslogtreecommitdiff
path: root/chromium/content/renderer/media/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/renderer/media/gpu')
-rw-r--r--chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.cc76
-rw-r--r--chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.h35
2 files changed, 105 insertions, 6 deletions
diff --git a/chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.cc b/chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.cc
index 77baecdaad4..a411ffbaafb 100644
--- a/chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.cc
+++ b/chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.cc
@@ -25,6 +25,7 @@
#include "gpu/ipc/client/command_buffer_proxy_impl.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "gpu/ipc/common/gpu_memory_buffer_support.h"
+#include "media/base/bind_to_current_loop.h"
#include "media/gpu/gpu_video_accelerator_util.h"
#include "media/gpu/ipc/common/media_messages.h"
#include "media/mojo/buildflags.h"
@@ -52,6 +53,26 @@ void RecordContextProviderPhaseUmaEnum(const ContextProviderPhase phase) {
} // namespace
+GpuVideoAcceleratorFactoriesImpl::Notifier::Notifier() = default;
+GpuVideoAcceleratorFactoriesImpl::Notifier::~Notifier() = default;
+
+void GpuVideoAcceleratorFactoriesImpl::Notifier::Register(
+ base::OnceClosure callback) {
+ if (is_notified_) {
+ std::move(callback).Run();
+ return;
+ }
+ callbacks_.push_back(std::move(callback));
+}
+
+void GpuVideoAcceleratorFactoriesImpl::Notifier::Notify() {
+ DCHECK(!is_notified_);
+ is_notified_ = true;
+ for (auto& callback : callbacks_)
+ std::move(callback).Run();
+ callbacks_.clear();
+}
+
// static
std::unique_ptr<GpuVideoAcceleratorFactoriesImpl>
GpuVideoAcceleratorFactoriesImpl::Create(
@@ -124,6 +145,8 @@ void GpuVideoAcceleratorFactoriesImpl::BindOnTaskRunner(
if (context_provider_->BindToCurrentThread() !=
gpu::ContextResult::kSuccess) {
+ OnDecoderSupportFailed();
+ OnEncoderSupportFailed();
OnContextLost();
return;
}
@@ -140,10 +163,15 @@ void GpuVideoAcceleratorFactoriesImpl::BindOnTaskRunner(
.video_encode_accelerator_supported_profiles);
}
+ vea_provider_.set_disconnect_handler(base::BindOnce(
+ &GpuVideoAcceleratorFactoriesImpl::OnEncoderSupportFailed,
+ base::Unretained(this)));
vea_provider_->GetVideoEncodeAcceleratorSupportedProfiles(
base::BindOnce(&GpuVideoAcceleratorFactoriesImpl::
OnGetVideoEncodeAcceleratorSupportedProfiles,
base::Unretained(this)));
+ } else {
+ OnEncoderSupportFailed();
}
#if BUILDFLAG(ENABLE_MOJO_VIDEO_DECODER)
@@ -154,17 +182,56 @@ void GpuVideoAcceleratorFactoriesImpl::BindOnTaskRunner(
// kAlternate, for example.
interface_factory_->CreateVideoDecoder(
video_decoder_.BindNewPipeAndPassReceiver());
+ video_decoder_.set_disconnect_handler(
+ base::BindOnce(&GpuVideoAcceleratorFactoriesImpl::OnDecoderSupportFailed,
+ base::Unretained(this)));
video_decoder_->GetSupportedConfigs(base::BindOnce(
&GpuVideoAcceleratorFactoriesImpl::OnSupportedDecoderConfigs,
base::Unretained(this)));
+#else
+ OnDecoderSupportFailed();
#endif // BUILDFLAG(ENABLE_MOJO_VIDEO_DECODER)
}
+bool GpuVideoAcceleratorFactoriesImpl::IsDecoderSupportKnown() {
+ base::AutoLock lock(supported_profiles_lock_);
+ return decoder_support_notifier_.is_notified();
+}
+
+void GpuVideoAcceleratorFactoriesImpl::NotifyDecoderSupportKnown(
+ base::OnceClosure callback) {
+ base::AutoLock lock(supported_profiles_lock_);
+ decoder_support_notifier_.Register(
+ media::BindToCurrentLoop(std::move(callback)));
+}
+
void GpuVideoAcceleratorFactoriesImpl::OnSupportedDecoderConfigs(
const media::SupportedVideoDecoderConfigMap& supported_configs) {
base::AutoLock lock(supported_profiles_lock_);
+ video_decoder_.reset();
supported_decoder_configs_ = supported_configs;
+ decoder_support_notifier_.Notify();
+}
+
+void GpuVideoAcceleratorFactoriesImpl::OnDecoderSupportFailed() {
+ base::AutoLock lock(supported_profiles_lock_);
video_decoder_.reset();
+ if (decoder_support_notifier_.is_notified())
+ return;
+ supported_decoder_configs_ = media::SupportedVideoDecoderConfigMap();
+ decoder_support_notifier_.Notify();
+}
+
+bool GpuVideoAcceleratorFactoriesImpl::IsEncoderSupportKnown() {
+ base::AutoLock lock(supported_profiles_lock_);
+ return encoder_support_notifier_.is_notified();
+}
+
+void GpuVideoAcceleratorFactoriesImpl::NotifyEncoderSupportKnown(
+ base::OnceClosure callback) {
+ base::AutoLock lock(supported_profiles_lock_);
+ encoder_support_notifier_.Register(
+ media::BindToCurrentLoop(std::move(callback)));
}
void GpuVideoAcceleratorFactoriesImpl::
@@ -173,6 +240,15 @@ void GpuVideoAcceleratorFactoriesImpl::
supported_profiles) {
base::AutoLock lock(supported_profiles_lock_);
supported_vea_profiles_ = supported_profiles;
+ encoder_support_notifier_.Notify();
+}
+
+void GpuVideoAcceleratorFactoriesImpl::OnEncoderSupportFailed() {
+ base::AutoLock lock(supported_profiles_lock_);
+ if (encoder_support_notifier_.is_notified())
+ return;
+ supported_vea_profiles_ = media::VideoEncodeAccelerator::SupportedProfiles();
+ encoder_support_notifier_.Notify();
}
bool GpuVideoAcceleratorFactoriesImpl::CheckContextLost() {
diff --git a/chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.h b/chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.h
index c15269de003..4bc4f75cc36 100644
--- a/chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.h
+++ b/chromium/content/renderer/media/gpu/gpu_video_accelerator_factories_impl.h
@@ -76,13 +76,19 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
bool IsGpuVideoAcceleratorEnabled() override;
base::UnguessableToken GetChannelToken() override;
int32_t GetCommandBufferRouteId() override;
+ Supported IsDecoderConfigSupported(
+ media::VideoDecoderImplementation implementation,
+ const media::VideoDecoderConfig& config) override;
+ bool IsDecoderSupportKnown() override;
+ void NotifyDecoderSupportKnown(base::OnceClosure callback) override;
std::unique_ptr<media::VideoDecoder> CreateVideoDecoder(
media::MediaLog* media_log,
media::VideoDecoderImplementation implementation,
media::RequestOverlayInfoCB request_overlay_info_cb) override;
- Supported IsDecoderConfigSupported(
- media::VideoDecoderImplementation implementation,
- const media::VideoDecoderConfig& config) override;
+ base::Optional<media::VideoEncodeAccelerator::SupportedProfiles>
+ GetVideoEncodeAcceleratorSupportedProfiles() override;
+ bool IsEncoderSupportKnown() override;
+ void NotifyEncoderSupportKnown(base::OnceClosure callback) override;
std::unique_ptr<media::VideoEncodeAccelerator> CreateVideoEncodeAccelerator()
override;
@@ -113,9 +119,6 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
base::UnsafeSharedMemoryRegion CreateSharedMemoryRegion(size_t size) override;
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override;
- base::Optional<media::VideoEncodeAccelerator::SupportedProfiles>
- GetVideoEncodeAcceleratorSupportedProfiles() override;
-
viz::RasterContextProvider* GetMediaContextProvider() override;
void SetRenderingColorSpace(const gfx::ColorSpace& color_space) override;
@@ -128,6 +131,21 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
~GpuVideoAcceleratorFactoriesImpl() override;
private:
+ class Notifier {
+ public:
+ Notifier();
+ ~Notifier();
+
+ void Register(base::OnceClosure callback);
+ void Notify();
+
+ bool is_notified() { return is_notified_; }
+
+ private:
+ bool is_notified_ = false;
+ std::vector<base::OnceClosure> callbacks_;
+ };
+
GpuVideoAcceleratorFactoriesImpl(
scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
const scoped_refptr<base::SingleThreadTaskRunner>&
@@ -154,9 +172,12 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
void OnSupportedDecoderConfigs(
const media::SupportedVideoDecoderConfigMap& supported_configs);
+ void OnDecoderSupportFailed();
+
void OnGetVideoEncodeAcceleratorSupportedProfiles(
const media::VideoEncodeAccelerator::SupportedProfiles&
supported_profiles);
+ void OnEncoderSupportFailed();
const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
@@ -197,9 +218,11 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
// are no supported configs.
base::Optional<media::SupportedVideoDecoderConfigMap>
supported_decoder_configs_ GUARDED_BY(supported_profiles_lock_);
+ Notifier decoder_support_notifier_ GUARDED_BY(supported_profiles_lock_);
base::Optional<media::VideoEncodeAccelerator::SupportedProfiles>
supported_vea_profiles_ GUARDED_BY(supported_profiles_lock_);
+ Notifier encoder_support_notifier_ GUARDED_BY(supported_profiles_lock_);
// For sending requests to allocate shared memory in the Browser process.
scoped_refptr<ThreadSafeSender> thread_safe_sender_;