Index: Source/modules/webaudio/OfflineAudioContext.h |
diff --git a/Source/modules/webaudio/OfflineAudioContext.h b/Source/modules/webaudio/OfflineAudioContext.h |
index 99276e7cbb5e19dc7edf2934b67a726f2eed8d2a..b1db612069c09d532d456f8a76d471eb587305c7 100644 |
--- a/Source/modules/webaudio/OfflineAudioContext.h |
+++ b/Source/modules/webaudio/OfflineAudioContext.h |
@@ -27,10 +27,14 @@ |
#include "modules/ModulesExport.h" |
#include "modules/webaudio/AudioContext.h" |
+#include "wtf/HashMap.h" |
namespace blink { |
class ExceptionState; |
+class ScheduledSuspendContainer; |
+ |
+using SuspendContainerMap = HashMap<size_t, RefPtr<ScheduledSuspendContainer>>; |
hongchan
2015/06/24 21:14:12
I changed the vector to HashMap. I didn't use Heap
|
class MODULES_EXPORT OfflineAudioContext final : public AudioContext { |
DEFINE_WRAPPERTYPEINFO(); |
@@ -39,9 +43,94 @@ 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); |
+ |
+ // Validate a suspend with various criteria on the render thread. |
+ void checkDuplicateSuspend(ScheduledSuspendContainer*); |
+ |
+ // Reject a suspend on the main thread after the validation fails. |
+ void rejectSuspendPromiseOnMainThread(ScheduledSuspendContainer*); |
+ |
+ // Resolve pending suspend promises and removes them from the list. |
+ void resolvePendingSuspendPromisesOnMainThread(ScheduledSuspendContainer*); |
+ |
+ // Vector<RefPtr<ScheduledSuspendContainer>> m_scheduledSuspends; |
+ SuspendContainerMap m_scheduledSuspends; |
hongchan
2015/06/24 21:14:12
This is HashMap of <size_t suspendFrame, RefPtr<Sc
|
+ 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; |
+ |
+ bool m_isResolvingSuspendPromise; |
+ |
+ // 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 |
+// 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 ScheduledSuspendContainer* create(double suspendTime, size_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>); |
yhirano
2015/06/25 04:00:53
static PassRefPtr<ScheduledSuspendContainer> creat
hongchan
2015/06/25 23:34:13
Done.
|
+ ~ScheduledSuspendContainer(); |
+ |
+ DECLARE_TRACE(); |
yhirano
2015/06/25 04:00:53
No TRACE is needed.
hongchan
2015/06/25 23:34:13
Removed.
|
+ |
+ PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver() { return m_resolver; } |
+ |
+ 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; |
+ |
+ // 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(double suspendTime, size_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>); |
+ |
+ // Actual suspend time before the quantization by render quantum frame. |
+ double m_suspendTime; |
+ |
+ // Suspend time in samples. |
+ size_t m_suspendFrame; |
+ |
+ // Associated promise resolver. |
+ RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; |
yhirano
2015/06/25 04:00:53
RefPtrWillBePersistent
hongchan
2015/06/25 23:34:13
Done.
|
+ |
+ // A pending marker for the safe batch removal. |
+ bool m_isPending; |
}; |
} // namespace blink |