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