Move HRTFDatabaseLoader to AudioListenerHandler
This CL moves the HRTFDataBaseLoader to the AudioListenerHandler, along with the previously moved AudioParamHandlers. This ensures that all data needed for audio processing is in a single place. This is a mechanical change, so there should be no changes to the logic or behavior of the audio processing. Bug: 1259897 Change-Id: I9f2032a1c5f7e09636d54da4f97dacc6a35669a4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4761789 Commit-Queue: Hongchan Choi <hongchan@chromium.org> Reviewed-by: Michael Wilson <mjwilson@chromium.org> Cr-Commit-Position: refs/heads/main@{#1181731}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
a2ea97ad0d
commit
a9df26b66a
third_party/blink/renderer/modules/webaudio
@ -33,7 +33,6 @@
|
||||
#include "third_party/blink/renderer/modules/webaudio/panner_handler.h"
|
||||
#include "third_party/blink/renderer/platform/audio/audio_bus.h"
|
||||
#include "third_party/blink/renderer/platform/audio/audio_utilities.h"
|
||||
#include "third_party/blink/renderer/platform/audio/hrtf_database_loader.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
@ -125,8 +124,6 @@ AudioListener::~AudioListener() {
|
||||
DeferredTaskHandler::GraphAutoLocker locker(*deferred_task_handler_);
|
||||
handler_ = nullptr;
|
||||
}
|
||||
|
||||
hrtf_database_loader_ = nullptr;
|
||||
}
|
||||
|
||||
void AudioListener::setOrientation(float x, float y, float z,
|
||||
@ -218,18 +215,15 @@ void AudioListener::RemovePannerHandler(PannerHandler& panner_handler) {
|
||||
}
|
||||
|
||||
void AudioListener::CreateAndLoadHRTFDatabaseLoader(float sample_rate) {
|
||||
DCHECK(IsMainThread());
|
||||
|
||||
if (!hrtf_database_loader_) {
|
||||
hrtf_database_loader_ =
|
||||
HRTFDatabaseLoader::CreateAndLoadAsynchronouslyIfNecessary(sample_rate);
|
||||
}
|
||||
Handler().CreateAndLoadHRTFDatabaseLoader(sample_rate);
|
||||
}
|
||||
|
||||
void AudioListener::WaitForHRTFDatabaseLoaderThreadCompletion() {
|
||||
if (hrtf_database_loader_) {
|
||||
hrtf_database_loader_->WaitForLoaderThreadCompletion();
|
||||
}
|
||||
Handler().WaitForHRTFDatabaseLoaderThreadCompletion();
|
||||
}
|
||||
|
||||
HRTFDatabaseLoader* AudioListener::HrtfDatabaseLoader() {
|
||||
return Handler().HrtfDatabaseLoader();
|
||||
}
|
||||
|
||||
void AudioListener::Trace(Visitor* visitor) const {
|
||||
|
@ -107,9 +107,7 @@ class AudioListener final : public ScriptWrappable,
|
||||
|
||||
void CreateAndLoadHRTFDatabaseLoader(float);
|
||||
void WaitForHRTFDatabaseLoaderThreadCompletion();
|
||||
HRTFDatabaseLoader* HrtfDatabaseLoader() {
|
||||
return hrtf_database_loader_.get();
|
||||
}
|
||||
HRTFDatabaseLoader* HrtfDatabaseLoader();
|
||||
|
||||
// InspectorHelperMixin: Note that this object belongs to a BaseAudioContext,
|
||||
// so these methods get called by the parent context.
|
||||
@ -137,9 +135,6 @@ class AudioListener final : public ScriptWrappable,
|
||||
Member<AudioParam> up_x_;
|
||||
Member<AudioParam> up_y_;
|
||||
Member<AudioParam> up_z_;
|
||||
|
||||
// HRTF database loader used by PannderNodes in the same context.
|
||||
scoped_refptr<HRTFDatabaseLoader> hrtf_database_loader_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "third_party/blink/renderer/modules/webaudio/audio_listener_handler.h"
|
||||
|
||||
#include "third_party/blink/renderer/modules/webaudio/panner_handler.h"
|
||||
#include "third_party/blink/renderer/platform/audio/hrtf_database_loader.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
@ -71,6 +72,7 @@ AudioListenerHandler::~AudioListenerHandler() {
|
||||
up_x_handler_ = nullptr;
|
||||
up_y_handler_ = nullptr;
|
||||
up_z_handler_ = nullptr;
|
||||
hrtf_database_loader_ = nullptr;
|
||||
panner_handlers_.clear();
|
||||
}
|
||||
|
||||
@ -196,6 +198,33 @@ void AudioListenerHandler::UpdateState() {
|
||||
}
|
||||
}
|
||||
|
||||
void AudioListenerHandler::CreateAndLoadHRTFDatabaseLoader(float sample_rate) {
|
||||
DCHECK(IsMainThread());
|
||||
|
||||
if (hrtf_database_loader_) {
|
||||
return;
|
||||
}
|
||||
|
||||
hrtf_database_loader_ =
|
||||
HRTFDatabaseLoader::CreateAndLoadAsynchronouslyIfNecessary(sample_rate);
|
||||
}
|
||||
|
||||
void AudioListenerHandler::WaitForHRTFDatabaseLoaderThreadCompletion() {
|
||||
// This can be called from both main and audio threads.
|
||||
|
||||
if (!hrtf_database_loader_) {
|
||||
return;
|
||||
}
|
||||
|
||||
hrtf_database_loader_->WaitForLoaderThreadCompletion();
|
||||
}
|
||||
|
||||
HRTFDatabaseLoader* AudioListenerHandler::HrtfDatabaseLoader() {
|
||||
DCHECK(IsMainThread());
|
||||
|
||||
return hrtf_database_loader_.get();
|
||||
}
|
||||
|
||||
void AudioListenerHandler::UpdateValuesIfNeeded(uint32_t frames_to_process) {
|
||||
double current_time = position_x_handler_->DestinationHandler().CurrentTime();
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace blink {
|
||||
|
||||
class HRTFDatabaseLoader;
|
||||
class PannerHandler;
|
||||
|
||||
class AudioListenerHandler final
|
||||
@ -78,6 +79,13 @@ class AudioListenerHandler final
|
||||
|
||||
base::Lock& Lock() { return listener_lock_; }
|
||||
|
||||
void CreateAndLoadHRTFDatabaseLoader(float sample_rate);
|
||||
HRTFDatabaseLoader* HrtfDatabaseLoader();
|
||||
|
||||
// TODO(crbug.com/1471284): this method can be called from both main and
|
||||
// audio thread.
|
||||
void WaitForHRTFDatabaseLoaderThreadCompletion();
|
||||
|
||||
private:
|
||||
AudioListenerHandler(AudioParamHandler& position_x_handler,
|
||||
AudioParamHandler& position_y_handler,
|
||||
@ -133,6 +141,9 @@ class AudioListenerHandler final
|
||||
// referred in the audio thread. These raw pointers are safe because
|
||||
// `PannerHandler::uninitialize()` unregisters it from this set.
|
||||
HashSet<PannerHandler*> panner_handlers_;
|
||||
|
||||
// HRTF database loader used by PannerHandlers in the same context.
|
||||
scoped_refptr<HRTFDatabaseLoader> hrtf_database_loader_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
Reference in New Issue
Block a user