Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: Source/modules/webaudio/AudioContext.cpp

Issue 304103002: Remove unnecessary members for tricky lazy initialization in AudioContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/webaudio/AudioContext.h ('k') | Source/modules/webaudio/AudioNode.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webaudio/AudioContext.cpp
diff --git a/Source/modules/webaudio/AudioContext.cpp b/Source/modules/webaudio/AudioContext.cpp
index 10cd39b14aba6137ffde7f75484dbeada815b602..6e4ddf65add102016812c4947f32b902ee144636 100644
--- a/Source/modules/webaudio/AudioContext.cpp
+++ b/Source/modules/webaudio/AudioContext.cpp
@@ -110,7 +110,6 @@ AudioContext::AudioContext(Document* document)
, m_isStopScheduled(false)
, m_isCleared(false)
, m_isInitialized(false)
- , m_isAudioThreadFinished(false)
, m_destinationNode(nullptr)
, m_isDeletionScheduled(false)
, m_automaticPullNodesNeedUpdating(false)
@@ -119,9 +118,11 @@ AudioContext::AudioContext(Document* document)
, m_graphOwnerThread(UndefinedThreadIdentifier)
, m_isOfflineContext(false)
{
+ ScriptWrappable::init(this);
+
m_destinationNode = DefaultAudioDestinationNode::create(this);
- constructCommon();
+ initialize();
}
// Constructor for offline (non-realtime) rendering.
@@ -130,7 +131,6 @@ AudioContext::AudioContext(Document* document, unsigned numberOfChannels, size_t
, m_isStopScheduled(false)
, m_isCleared(false)
, m_isInitialized(false)
- , m_isAudioThreadFinished(false)
, m_destinationNode(nullptr)
, m_automaticPullNodesNeedUpdating(false)
, m_connectionCount(0)
@@ -138,22 +138,13 @@ AudioContext::AudioContext(Document* document, unsigned numberOfChannels, size_t
, m_graphOwnerThread(UndefinedThreadIdentifier)
, m_isOfflineContext(true)
{
+ ScriptWrappable::init(this);
+
// Create a new destination for offline rendering.
m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampleRate);
if (m_renderTarget.get())
m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTarget.get());
- constructCommon();
-}
-
-void AudioContext::constructCommon()
-{
- ScriptWrappable::init(this);
-
- FFTFrame::initialize();
-
- m_listener = AudioListener::create();
-
initialize();
}
@@ -175,27 +166,25 @@ AudioContext::~AudioContext()
void AudioContext::initialize()
{
- if (!m_isInitialized) {
- // Don't allow the context to initialize a second time after it's already been explicitly uninitialized.
- ASSERT(!m_isAudioThreadFinished);
- if (!m_isAudioThreadFinished) {
- // Creation of a destination node should not start the audio HW. The
- // creation of any other AudioNode will initialize the audio HW and start processing
- if (m_destinationNode.get()) {
- m_destinationNode->initialize();
-
- if (!isOfflineContext()) {
- // 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.
- // We may want to consider requiring it for symmetry with OfflineAudioContext.
- m_destinationNode->startRendering();
- ++s_hardwareContextCount;
- }
-
- m_isInitialized = true;
- }
+ if (isInitialized())
+ return;
+
+ FFTFrame::initialize();
+ m_listener = AudioListener::create();
+
+ if (m_destinationNode.get()) {
+ m_destinationNode->initialize();
+
+ if (!isOfflineContext()) {
+ // 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.
+ // We may want to consider requiring it for symmetry with OfflineAudioContext.
+ m_destinationNode->startRendering();
+ ++s_hardwareContextCount;
}
+
+ m_isInitialized = true;
}
}
@@ -219,15 +208,12 @@ void AudioContext::uninitialize()
{
ASSERT(isMainThread());
- if (!m_isInitialized)
+ if (!isInitialized())
return;
// This stops the audio thread and all audio rendering.
m_destinationNode->uninitialize();
- // Don't allow the context to initialize a second time after it's already been explicitly uninitialized.
- m_isAudioThreadFinished = true;
-
if (!isOfflineContext()) {
ASSERT(s_hardwareContextCount);
--s_hardwareContextCount;
@@ -239,11 +225,6 @@ void AudioContext::uninitialize()
m_isInitialized = false;
}
-bool AudioContext::isInitialized() const
-{
- return m_isInitialized;
-}
-
void AudioContext::stopDispatch(void* userData)
{
AudioContext* context = reinterpret_cast<AudioContext*>(userData);
@@ -593,7 +574,7 @@ void AudioContext::notifyNodeFinishedProcessing(AudioNode* node)
void AudioContext::derefFinishedSourceNodes()
{
ASSERT(isGraphOwner());
- ASSERT(isAudioThread() || isAudioThreadFinished());
+ ASSERT(isAudioThread());
for (unsigned i = 0; i < m_finishedNodes.size(); i++)
derefNode(m_finishedNodes[i]);
@@ -625,7 +606,7 @@ void AudioContext::derefNode(AudioNode* node)
void AudioContext::derefUnfinishedSourceNodes()
{
- ASSERT(isMainThread() && isAudioThreadFinished());
+ ASSERT(isMainThread());
for (unsigned i = 0; i < m_referencedNodes.size(); ++i)
m_referencedNodes[i]->deref(AudioNode::RefTypeConnection);
@@ -656,7 +637,7 @@ bool AudioContext::tryLock(bool& mustReleaseLock)
bool isAudioThread = thisThread == audioThread();
// Try to catch cases of using try lock on main thread - it should use regular lock.
- ASSERT(isAudioThread || isAudioThreadFinished());
+ ASSERT(isAudioThread);
if (!isAudioThread) {
// In release build treat tryLock() as lock() (since above ASSERT(isAudioThread) never fires) - this is the best we can do.
@@ -771,7 +752,7 @@ void AudioContext::markForDeletion(AudioNode* node)
{
ASSERT(isGraphOwner());
- if (isAudioThreadFinished())
+ if (!isInitialized())
m_nodesToDelete.append(node);
else
m_nodesMarkedForDeletion.append(node);
@@ -785,7 +766,7 @@ void AudioContext::markForDeletion(AudioNode* node)
void AudioContext::scheduleNodeDeletion()
{
- bool isGood = m_isInitialized && isGraphOwner();
+ bool isGood = isInitialized() && isGraphOwner();
ASSERT(isGood);
if (!isGood)
return;
« no previous file with comments | « Source/modules/webaudio/AudioContext.h ('k') | Source/modules/webaudio/AudioNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698