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

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: Ready for Review (2) 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..abf9a8d7033956ac4efa98a3e8de05f76e38a7f3 100644
--- a/Source/modules/webaudio/OfflineAudioContext.h
+++ b/Source/modules/webaudio/OfflineAudioContext.h
@@ -27,10 +27,15 @@
#include "modules/ModulesExport.h"
#include "modules/webaudio/AudioContext.h"
+#include "wtf/HashMap.h"
namespace blink {
class ExceptionState;
+class ScheduledSuspendContainer;
+
+// The HashMap with 'zero' key is needed because |currentSampleFrame| can be zero.
+using SuspendContainerMap = HashMap<size_t, RefPtr<ScheduledSuspendContainer>, DefaultHash<size_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<size_t>>;
class MODULES_EXPORT OfflineAudioContext final : public AudioContext {
DEFINE_WRAPPERTYPEINFO();
@@ -39,9 +44,81 @@ public:
virtual ~OfflineAudioContext();
+ DECLARE_VIRTUAL_TRACE();
+
+ // Fire completion event when the rendering is finished.
+ void fireCompletionEvent() override;
+
+ // 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() override;
+
+ // Clear suspensions marked as 'resolved' in the list.
+ void resolvePendingSuspendPromises() override;
+
+ 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);
+
+ // Check if there is any duplicate entry in scheduled suspends and reject
+ // the promise if needed.
+ void checkDuplicateSuspend(PassRefPtr<ScheduledSuspendContainer>);
+
+ // Reject a suspend promise on the main thread when the validation fails.
+ void rejectSuspendPromiseOnMainThread(PassRefPtr<ScheduledSuspendContainer>);
+
+ // Resolve a pending suspend promise and removes it from the map.
+ void resolvePendingSuspendPromisesOnMainThread(PassRefPtr<ScheduledSuspendContainer>);
+
+ SuspendContainerMap 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.
+//
+// TODO: This class is |ThreadSafeRefCounted| because it needs to be accessed by
haraken 2015/06/30 07:41:51 Add your name to TODO.
hongchan 2015/06/30 18:52:10 Done.
+// the offline render thread which is not oilpan-enabled. This is a short-term
+// solution until the offline render thread gets oilpan coverage.
+class ScheduledSuspendContainer : public ThreadSafeRefCounted<ScheduledSuspendContainer> {
+public:
+ static PassRefPtr<ScheduledSuspendContainer> create(double suspendTime, size_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>);
+ ~ScheduledSuspendContainer();
+
+ PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver() { return m_resolver; }
haraken 2015/06/30 07:41:51 I guess this should be ScriptPromiseResolver*, bec
hongchan 2015/06/30 18:52:10 I made this change from the suggestion from yhiran
+
+ double suspendTime() const { return m_suspendTime; }
+
+ size_t suspendFrame() const { return m_suspendFrame; }
+
+ // Query if the rendering should be suspended at |whenFrame|.
+ bool shouldSuspendAtFrame(size_t whenFrame) const;
+
+private:
+ ScheduledSuspendContainer(double suspendTime, size_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>);
+
+ // Actual suspend time before the quantization by render quantum frame.
+ double m_suspendTime;
+
+ // Suspend sample frame. This is quantized by the render quantum size.
+ size_t m_suspendFrame;
+
+ // Associated promise resolver.
+ RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698