| Index: Source/modules/webaudio/OfflineAudioContext.h
|
| diff --git a/Source/modules/webaudio/OfflineAudioContext.h b/Source/modules/webaudio/OfflineAudioContext.h
|
| index 99276e7cbb5e19dc7edf2934b67a726f2eed8d2a..276110fe2798128a2aa3b38fc9358e2ad2df53c8 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,91 @@ 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*);
|
| +
|
| + // TODO: Reject a suspend on the main thread after the validation fails.
|
| + void rejectSuspendOnMainThread(ScheduledSuspendContainer*);
|
| +
|
| + // 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;
|
| +
|
| + // MutexLocker for m_scheduledSuspends.
|
| + Mutex m_suspendMutex;
|
| +};
|
| +
|
| +// A container class for a pair of time information and the suspend promise
|
| +// resolver.
|
| +class ScheduledSuspendContainer : public GarbageCollectedFinalized<ScheduledSuspendContainer> {
|
| +public:
|
| + static ScheduledSuspendContainer* create(double suspendTime, size_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>);
|
| + ~ScheduledSuspendContainer();
|
| +
|
| + DECLARE_TRACE();
|
| +
|
| + 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;
|
| +
|
| + // A pending marker for the safe batch removal.
|
| + bool m_isPending;
|
| };
|
|
|
| } // namespace blink
|
|
|