blob: d4f8ece81afdbb1ef29d6ac482902f3f1ccb7b21 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/webaudio/realtime_audio_worklet_thread.h"
#include "base/feature_list.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/modules/webaudio/audio_worklet_global_scope.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
namespace blink {
template class WorkletThreadHolder<RealtimeAudioWorkletThread>;
int RealtimeAudioWorkletThread::s_ref_count_ = 0;
RealtimeAudioWorkletThread::RealtimeAudioWorkletThread(
WorkerReportingProxy& worker_reporting_proxy)
: WorkerThread(worker_reporting_proxy) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("audio-worklet"),
"RealtimeAudioWorkletThread()");
DCHECK(IsMainThread());
ThreadCreationParams params =
ThreadCreationParams(ThreadType::kRealtimeAudioWorkletThread);
// Use a higher priority thread only when it is allowed by Finch.
if (base::FeatureList::IsEnabled(
features::kAudioWorkletThreadRealtimePriority)) {
// TODO(crbug.com/1022888): The worklet thread priority is always NORMAL on
// Linux and Chrome OS regardless of this thread priority setting.
params.thread_priority = base::ThreadPriority::REALTIME_AUDIO;
} else {
params.thread_priority = base::ThreadPriority::NORMAL;
}
if (++s_ref_count_ == 1)
EnsureSharedBackingThread(params);
}
RealtimeAudioWorkletThread::~RealtimeAudioWorkletThread() {
DCHECK(IsMainThread());
if (--s_ref_count_ == 0)
ClearSharedBackingThread();
}
WorkerBackingThread& RealtimeAudioWorkletThread::GetWorkerBackingThread() {
return *WorkletThreadHolder<RealtimeAudioWorkletThread>::GetInstance()
->GetThread();
}
void RealtimeAudioWorkletThread::EnsureSharedBackingThread(
const ThreadCreationParams& params) {
DCHECK(IsMainThread());
WorkletThreadHolder<RealtimeAudioWorkletThread>::EnsureInstance(params);
}
void RealtimeAudioWorkletThread::ClearSharedBackingThread() {
DCHECK(IsMainThread());
CHECK_EQ(s_ref_count_, 0);
WorkletThreadHolder<RealtimeAudioWorkletThread>::ClearInstance();
}
WorkerOrWorkletGlobalScope* RealtimeAudioWorkletThread::CreateWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("audio-worklet"),
"RealtimeAudioWorkletThread::CreateWorkerGlobalScope");
return MakeGarbageCollected<AudioWorkletGlobalScope>(
std::move(creation_params), this);
}
} // namespace blink
|