Commit 3929eee9 authored by Frank Liberato's avatar Frank Liberato Committed by Commit Bot

Move GpuMediaService to gpu main thread on Windows.

Since the CDM runs on the main thread, and we can't decode on a
separate thread anyway, just start the whole GpuMediaService on
the GPU main thread.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I69e41919f96348c86289844231fe2506822a0ebd
Reviewed-on: https://chromium-review.googlesource.com/1112593
Commit-Queue: Frank Liberato <liberato@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570242}
parent 5c07c41e
......@@ -8,6 +8,7 @@
#include "base/task_scheduler/post_task.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "services/shape_detection/public/mojom/constants.mojom.h"
#include "services/shape_detection/shape_detection_service.h"
......@@ -54,9 +55,14 @@ void GpuServiceFactory::RegisterServices(ServiceMap* services) {
// This service will host audio/video decoders, and if these decoding
// operations are blocked, user may hear audio glitch or see video freezing,
// hence "user blocking".
#if defined(OS_WIN)
// Run everything on the gpu main thread, since that's where the CDM runs.
info.task_runner = task_runner_;
#else
// TODO(crbug.com/786169): Check whether this needs to be single threaded.
info.task_runner = base::CreateSingleThreadTaskRunnerWithTraits(
{base::TaskPriority::USER_BLOCKING});
#endif // defined(OS_WIN)
services->insert(std::make_pair("media", info));
#endif // BUILDFLAG(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
......
......@@ -80,7 +80,10 @@ D3D11VideoDecoder::~D3D11VideoDecoder() {
// Post destruction to the main thread. When this executes, it will also
// cancel pending callbacks into |impl_| via |impl_weak_|. Callbacks out
// from |impl_| will be cancelled by |weak_factory_| when we return.
impl_task_runner_->DeleteSoon(FROM_HERE, std::move(impl_));
if (impl_task_runner_->RunsTasksInCurrentSequence())
impl_.reset();
else
impl_task_runner_->DeleteSoon(FROM_HERE, std::move(impl_));
}
std::string D3D11VideoDecoder::GetDisplayName() const {
......@@ -100,8 +103,14 @@ void D3D11VideoDecoder::Initialize(
return;
}
// Bind our own init / output cb that hop to this thread, so we don't call the
// originals on some other thread.
if (impl_task_runner_->RunsTasksInCurrentSequence()) {
impl_->Initialize(config, low_delay, cdm_context, init_cb, output_cb,
waiting_for_decryption_key_cb);
return;
}
// Bind our own init / output cb that hop to this thread, so we don't call
// the originals on some other thread.
// Important but subtle note: base::Bind will copy |config_| since it's a
// const ref.
// TODO(liberato): what's the lifetime of |cdm_context|?
......@@ -117,6 +126,11 @@ void D3D11VideoDecoder::Initialize(
void D3D11VideoDecoder::Decode(scoped_refptr<DecoderBuffer> buffer,
const DecodeCB& decode_cb) {
if (impl_task_runner_->RunsTasksInCurrentSequence()) {
impl_->Decode(std::move(buffer), decode_cb);
return;
}
impl_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
......@@ -125,6 +139,11 @@ void D3D11VideoDecoder::Decode(scoped_refptr<DecoderBuffer> buffer,
}
void D3D11VideoDecoder::Reset(const base::Closure& closure) {
if (impl_task_runner_->RunsTasksInCurrentSequence()) {
impl_->Reset(closure);
return;
}
impl_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&VideoDecoder::Reset, impl_weak_,
BindToCurrentThreadIfWeakPtr(
......
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