Chromium Code Reviews| Index: Source/modules/webaudio/OfflineAudioContext.h |
| diff --git a/Source/modules/webaudio/OfflineAudioContext.h b/Source/modules/webaudio/OfflineAudioContext.h |
| index 99276e7cbb5e19dc7edf2934b67a726f2eed8d2a..86d9e69975242d6462db73d8ea3290d2b5381f76 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>>; |
|
haraken
2015/07/08 04:05:41
Actually this ScheduledSuspendContainer doesn't ne
hongchan
2015/07/08 17:47:32
Done. However, I am having a cross-thread issue in
|
| class MODULES_EXPORT OfflineAudioContext final : public AudioContext { |
| DEFINE_WRAPPERTYPEINFO(); |
| @@ -39,9 +44,90 @@ 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 a suspend container if it has a duplicate scheduled frame or |
| + // is behind the current frame. If the validation fails, post a task to the |
| + // main thread to reject the promise. |
| + void validateSuspendContainerOnRenderThread(PassRefPtr<ScheduledSuspendContainer>); |
| + |
| + // Reject a suspend container on the main thread when the validation fails. |
| + void rejectSuspendContainerOnMainThread(PassRefPtr<ScheduledSuspendContainer>); |
| + |
| + // Resolve a pending suspend container and removes it from the map. |
| + void resolveSuspendContainerOnMainThread(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; |
|
haraken
2015/07/08 04:05:41
I'm not sure but would it be better to introduce a
hongchan
2015/07/08 17:47:32
rtoy@ and I thought about having a 'created' state
|
| + |
| + // Total render sample length. |
| + size_t m_totalRenderFrames; |
| +}; |
| + |
| +// A container class for a pair of time information and the suspend promise |
| +// resolver. |
| +// |
| +// TODO(hongchan): 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> { |
|
haraken
2015/07/08 04:05:42
As commented above, the render thread can keep Sch
hongchan
2015/07/08 17:47:32
Unfortunately, |resolvePendingSuspendPromises()| c
|
| +public: |
| + static PassRefPtr<ScheduledSuspendContainer> create(double suspendTime, size_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>); |
| + ~ScheduledSuspendContainer(); |
| + |
| + 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; |
| + |
| + // Set the error message for the reason of rejection on the render thread |
| + // before sending it to the main thread. |
| + void setErrorMessageForRejection(ExceptionCode, const String&); |
| + |
| + // {Resolve, Reject} the promise resolver on the main thread. |
| + void resolvePromise(); |
| + void rejectPromise(); |
| + |
| +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; |
| + |
| + ExceptionCode m_errorCode; |
| + String m_errorMessage; |
| }; |
| } // namespace blink |