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

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

Issue 1140723003: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Initial Design Created 5 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
Index: Source/modules/webaudio/OfflineAudioContext.cpp
diff --git a/Source/modules/webaudio/OfflineAudioContext.cpp b/Source/modules/webaudio/OfflineAudioContext.cpp
index d3488419e947e373d50f13cb105be0fb0604d178..629b853e6205e569b79fe61b281bdc2cf2acd59f 100644
--- a/Source/modules/webaudio/OfflineAudioContext.cpp
+++ b/Source/modules/webaudio/OfflineAudioContext.cpp
@@ -31,7 +31,10 @@
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
+#include "modules/webaudio/OfflineAudioDestinationNode.h"
+#include "platform/ThreadSafeFunctional.h"
#include "platform/audio/AudioUtilities.h"
+#include "public/platform/Platform.h"
namespace blink {
@@ -92,6 +95,8 @@ OfflineAudioContext* OfflineAudioContext::create(ExecutionContext* context, unsi
OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate)
: AudioContext(document, numberOfChannels, numberOfFrames, sampleRate)
+ , m_isSuspendScheduled(false)
+ , m_suspendTime(-0.0)
Raymond Toy 2015/05/13 17:16:08 Why -0.0? This probably won't do what you think i
hongchan 2015/05/13 17:30:53 What would be the proper 'null' value for this cas
{
}
@@ -99,8 +104,24 @@ OfflineAudioContext::~OfflineAudioContext()
{
}
+bool OfflineAudioContext::suspendIfNecessary()
+{
+ ASSERT(!isMainThread());
+
+ if (m_isSuspendScheduled && m_suspendTime <= currentTime()) {
+ m_isSuspendScheduled = false;
+ m_suspendTime = -0.0;
+ return true;
+ }
+
+ return false;
+}
+
ScriptPromise OfflineAudioContext::startOfflineRendering(ScriptState* scriptState)
{
+ ASSERT(isMainThread());
+ AutoLocker locker(this);
+
// Calling close() on an OfflineAudioContext is not supported/allowed,
// but it might well have been stopped by its execution context.
if (isContextClosed()) {
@@ -121,10 +142,60 @@ ScriptPromise OfflineAudioContext::startOfflineRendering(ScriptState* scriptStat
}
m_offlineResolver = ScriptPromiseResolver::create(scriptState);
- startRendering();
+
+ // This calls AudioContext.startRendering(). It seems to be odd to go up the
+ // chain and call the parent's method, but the current OAC is basically a
+ // thin wrapper on AudioContext. (a container-like object.)
+ //
+ // If we decide to fix this structural issue completely, we have to touch
+ // AudioContext and AudioNode.
+ // startRendering();
+
+ destination()->audioDestinationHandler().startRendering();
+ setContextState(Running);
+
return m_offlineResolver->promise();
}
+ScriptPromise OfflineAudioContext::suspendOfflineRendering(ScriptState* scriptState, double suspendTime)
+{
+ ASSERT(isMainThread());
+ AutoLocker locker(this);
+
+ // suspendTime should be greater than currentTime. Otherwise stop the
+ // rendering as soon as possible.
+ //
+ // TODO: add extra time when suspendTime is earlier than currentTime
+ if (currentTime() < suspendTime) {
+ m_isSuspendScheduled = true;
+ m_suspendTime = suspendTime;
+ }
+
+ RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ m_offlineSuspendResolvers.append(resolver);
+
+ // fprintf(stderr, "suspend scheduled = %f\n", m_suspendTime);
+
+ return promise;
+}
+
+ScriptPromise OfflineAudioContext::resumeOfflineRendering(ScriptState* scriptState)
+{
+ ASSERT(isMainThread());
+ AutoLocker locker(this);
+
+ RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ m_offlineResumeResolvers.append(resolver);
+
+ // Calling startRendering() in OfflineAudioDestinationHandler.
+ destination()->audioDestinationHandler().startRendering();
+ setContextState(Running);
+
+ return promise;
+}
+
} // namespace blink
#endif // ENABLE(WEB_AUDIO)

Powered by Google App Engine
This is Rietveld 408576698