Skip to content
Permalink
Browse files
Refactor AudioContext to register/unregister itself at construction/d…
…estruction time

https://bugs.webkit.org/show_bug.cgi?id=197383

Reviewed by Eric Carlson.

Registering/Unregistering is cheap.
Instead of registering/unregistering in initialize/uninitialize,
move this code to constructor/destructor.
No observable change of behavior.

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::AudioContext):
(WebCore::AudioContext::~AudioContext):
(WebCore::AudioContext::lazyInitialize):
(WebCore::AudioContext::uninitialize):
(WebCore::AudioContext::visibilityStateChanged):


Canonical link: https://commits.webkit.org/211596@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244771 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youennf committed Apr 30, 2019
1 parent 534c1db commit 31d4e7b14197e376ea9da30ae141848e298a1248
Showing 2 changed files with 30 additions and 7 deletions.
@@ -1,3 +1,22 @@
2019-04-30 Youenn Fablet <youenn@apple.com>

Refactor AudioContext to register/unregister itself at construction/destruction time
https://bugs.webkit.org/show_bug.cgi?id=197383

Reviewed by Eric Carlson.

Registering/Unregistering is cheap.
Instead of registering/unregistering in initialize/uninitialize,
move this code to constructor/destructor.
No observable change of behavior.

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::AudioContext):
(WebCore::AudioContext::~AudioContext):
(WebCore::AudioContext::lazyInitialize):
(WebCore::AudioContext::uninitialize):
(WebCore::AudioContext::visibilityStateChanged):

2019-04-30 Michael Catanzaro <mcatanzaro@igalia.com>

WebCore::StyleColorScheme should not have explicitly-declared copy constructor
@@ -147,6 +147,11 @@ AudioContext::AudioContext(Document& document)

// Initialize the destination node's muted state to match the page's current muted state.
pageMutedStateDidChange();

if (!isOfflineContext()) {
document.addAudioProducer(*this);
document.registerForVisibilityStateChangedCallbacks(*this);
}
}

// Constructor for offline (non-realtime) rendering.
@@ -202,6 +207,11 @@ AudioContext::~AudioContext()
m_renderingAutomaticPullNodes.resize(m_automaticPullNodes.size());
ASSERT(m_renderingAutomaticPullNodes.isEmpty());
// FIXME: Can we assert that m_deferredFinishDerefList is empty?

if (!isOfflineContext() && scriptExecutionContext()) {
document()->removeAudioProducer(*this);
document()->unregisterForVisibilityStateChangedCallbacks(*this);
}
}

void AudioContext::lazyInitialize()
@@ -218,9 +228,6 @@ void AudioContext::lazyInitialize()
m_destinationNode->initialize();

if (!isOfflineContext()) {
document()->addAudioProducer(*this);
document()->registerForVisibilityStateChangedCallbacks(*this);

// This starts the audio thread. The destination node's provideInput() method will now be called repeatedly to render audio.
// Each time provideInput() is called, a portion of the audio stream is rendered. Let's call this time period a "render quantum".
// NOTE: for now default AudioContext does not need an explicit startRendering() call from JavaScript.
@@ -265,9 +272,6 @@ void AudioContext::uninitialize()
m_isAudioThreadFinished = true;

if (!isOfflineContext()) {
document()->removeAudioProducer(*this);
document()->unregisterForVisibilityStateChangedCallbacks(*this);

ASSERT(s_hardwareContextCount);
--s_hardwareContextCount;

@@ -378,7 +382,7 @@ bool AudioContext::isSuspended() const
void AudioContext::visibilityStateChanged()
{
// Do not suspend if audio is audible.
if (mediaState() == MediaProducer::IsPlayingAudio)
if (mediaState() == MediaProducer::IsPlayingAudio || m_isStopScheduled)
return;

if (document()->hidden()) {

0 comments on commit 31d4e7b

Please sign in to comment.