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

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

Issue 1140723003: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Making Oilpan-compatible changes Created 5 years, 6 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.h
diff --git a/Source/modules/webaudio/OfflineAudioContext.h b/Source/modules/webaudio/OfflineAudioContext.h
index 99276e7cbb5e19dc7edf2934b67a726f2eed8d2a..bb903fe1662995139f0fbcabee8c3088902a58cc 100644
--- a/Source/modules/webaudio/OfflineAudioContext.h
+++ b/Source/modules/webaudio/OfflineAudioContext.h
@@ -31,6 +31,7 @@
namespace blink {
class ExceptionState;
+class ScheduledSuspendContainer;
class MODULES_EXPORT OfflineAudioContext final : public AudioContext {
DEFINE_WRAPPERTYPEINFO();
@@ -39,9 +40,75 @@ public:
virtual ~OfflineAudioContext();
+ DECLARE_TRACE();
+
+ // Check all the scheduled suspends if the context should suspend at
+ // currentTime(). Then post tasks to resolve promises on the main thread
+ // if necessary.
+ bool shouldSuspendNow();
yhirano 2015/06/18 13:40:52 +override ditto for below
hongchan 2015/06/18 18:22:31 Done.
+
+ // Clear suspensions marked as 'resolved' in the list.
+ void resolvePendingSuspendPromises();
+
+ // Fire completion event when the rendering is finished.
+ void fireCompletionEvent();
+
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
+
ScriptPromise startOfflineRendering(ScriptState*);
+ ScriptPromise suspendOfflineRendering(ScriptState*, double);
+ ScriptPromise resumeOfflineRendering(ScriptState*);
+
private:
OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate);
+
+ // Resolve pending suspend promises and removes them from the list.
+ void resolvePendingSuspendPromisesOnMainThread();
+
+ HeapVector<Member<ScheduledSuspendContainer>> m_scheduledSuspends;
+ RefPtrWillBeMember<ScriptPromiseResolver> m_completeResolver;
+
+ // This flag is necessary to indicate the rendering has actually started.
+ // Note that initial state of context is 'Suspended', which is the same
+ // state when the context is suspended.
+ bool m_isRenderingStarted;
+
+ // Total render sample length.
+ size_t m_totalRenderFrames;
+};
+
+// A container class for a pair of time information and the suspend promise
+// resolver.
+class ScheduledSuspendContainer : public GarbageCollectedFinalized<ScheduledSuspendContainer> {
+public:
+ static ScheduledSuspendContainer* create(size_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>);
+ ~ScheduledSuspendContainer();
+
+ DECLARE_TRACE();
+
+ PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver() { return m_resolver; }
+
+ // Query if the rendering should be suspended at |whenFrame|.
+ bool shouldSuspendAt(size_t whenFrame) const;
+
+ // Query if the suspend is pending for the promise resolution.
+ bool isPending() const;
+
+ // Mark the suspend as pending. Containers with 'pending' flag will
+ // be collectively resolved when the actual suspension happens.
+ void markAsPending();
+
+private:
+ ScheduledSuspendContainer(size_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>);
+
+ // Suspend time in samples.
+ size_t m_suspendFrame;
+
+ // Associated promise resolver.
+ RefPtrWillBeMember<ScriptPromiseResolver> m_resolver;
+
+ // A pending marker for the safe batch removal.
+ bool m_isPending;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698