Commit cf25f421 authored by Chris Cunningham's avatar Chris Cunningham Committed by Commit Bot

WebCodecs: never use main thread for audio|video decoding

Prior to this CL, video decoding used the main thread whenever gpu
acceleration is unavailable/disabled, and audio decoding always used the
main thread. Now both cases use a SequencedTaskRunner from the worker
(no relation to web workers) pool.

Also

Bug: 1095786
Change-Id: I1c6265cdb63bcd4dadf48fdbe9bd27622218b948
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500526
Auto-Submit: Chrome Cunningham <chcunningham@chromium.org>
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823520}
parent 1a6de624
......@@ -26,6 +26,7 @@
#include "third_party/blink/renderer/modules/webcodecs/decoder_selector.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
......@@ -259,10 +260,9 @@ class MediaAudioTaskWrapper {
constexpr char AudioDecoderBroker::kDefaultDisplayName[];
AudioDecoderBroker::AudioDecoderBroker(ExecutionContext& execution_context)
: media_task_runner_(
// TODO(chcunningham): This should use a separate thread from the
// pool. http://crbug.com/1095786
execution_context.GetTaskRunner(TaskType::kInternalMedia)) {
// Use a worker task runner to avoid scheduling decoder
// work on the main thread.
: media_task_runner_(worker_pool::CreateSequencedTaskRunner({})) {
DVLOG(2) << __func__;
media_tasks_ = std::make_unique<MediaAudioTaskWrapper>(
weak_factory_.GetWeakPtr(), execution_context, media_task_runner_,
......
......@@ -30,6 +30,7 @@
#include "third_party/blink/renderer/modules/webcodecs/decoder_selector.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "ui/gfx/color_space.h"
......@@ -299,14 +300,11 @@ VideoDecoderBroker::VideoDecoderBroker(
media::GpuVideoAcceleratorFactories* gpu_factories)
: media_task_runner_(
gpu_factories
// GpuFactories requires we use its task runner when available.
? gpu_factories->GetTaskRunner()
// TODO(chcunningham): Consider adding a new single thread task
// runner just for WebCodecs. This is still using the main thread,
// albeit at a lower priority than things like user gestures.
// http://crbug.com/1095786
// TODO(chcunningham): Should this be kInternalMediaRealTime? Why
// does WebAudio use that task type?
: execution_context.GetTaskRunner(TaskType::kInternalMedia)) {
// Otherwise, use a worker task runner to avoid scheduling decoder
// work on the main thread.
: worker_pool::CreateSequencedTaskRunner({})) {
DVLOG(2) << __func__;
media_tasks_ = std::make_unique<MediaVideoTaskWrapper>(
weak_factory_.GetWeakPtr(), execution_context, gpu_factories,
......
......@@ -23,6 +23,11 @@ void PostTask(const base::Location& location,
ConvertToBaseOnceCallback(std::move(closure)));
}
scoped_refptr<base::SequencedTaskRunner> CreateSequencedTaskRunner(
const base::TaskTraits& traits) {
return base::ThreadPool::CreateSequencedTaskRunner(traits);
}
} // namespace worker_pool
} // namespace blink
......@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_PUBLIC_WORKER_POOL_H_
#include "base/location.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "third_party/blink/renderer/platform/platform_export.h"
......@@ -31,8 +32,8 @@ PLATFORM_EXPORT void PostTask(const base::Location&,
const base::TaskTraits&,
CrossThreadOnceClosure);
// TODO(altimin): Expose CreateSequencedTaskRunner when the
// need arises.
PLATFORM_EXPORT scoped_refptr<base::SequencedTaskRunner>
CreateSequencedTaskRunner(const base::TaskTraits& traits);
} // namespace worker_pool
......
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