// Copyright 2020 The Chromium Authors // 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 "base/metrics/histogram_functions.h" #include "third_party/blink/public/common/features.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.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 { namespace { // The realtime AudioWorklet thread is managed by a pool system. The system // can contain up to 4 concurrent real-time threads and it is based on “first // come first served” policy. // - The 1st ~ 3rd threads are a “dedicated” thread. The first 3 AudioWorklets // will have their own dedicated backing thread. // - The 4th thread is a “shared” thread: Starting from the 4th AudioWorklet, // all subsequent contexts will share the same thread for the AudioWorklet // operation. static constexpr int kMaxDedicatedBackingThreadCount = …; // Used for counting dedicated backing threads. Incremented by the constructor // and decremented by destructor. int dedicated_backing_thread_count = …; // Used for ref-counting of all backing thread in the current renderer process. // Incremented by the constructor and decremented by destructor. int shared_backing_thread_ref_count = …; // For UMA logging: Represents the maximum number of dedicated backing worklet // threads throughout the lifetime of the document/frame. Can't exceed // `kMaxDedicatedBackingThreadCount`. int peak_dedicated_backing_thread_count = …; // For UMA logging: Represents the maximum number of ref counts using the // shared backing thread throughout the lifetime of the document/frame. int peak_shared_backing_thread_ref_count = …; } // namespace template class WorkletThreadHolder<RealtimeAudioWorkletThread>; RealtimeAudioWorkletThread::RealtimeAudioWorkletThread( WorkerReportingProxy& worker_reporting_proxy, base::TimeDelta realtime_buffer_duration) : … { … } RealtimeAudioWorkletThread::~RealtimeAudioWorkletThread() { … } WorkerBackingThread& RealtimeAudioWorkletThread::GetWorkerBackingThread() { … } WorkerOrWorkletGlobalScope* RealtimeAudioWorkletThread::CreateWorkerGlobalScope( std::unique_ptr<GlobalScopeCreationParams> creation_params) { … } } // namespace blink