Index: third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.h |
diff --git a/third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.h b/third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.h |
index 030586f4d409064f9104460129d823414c9ac71f..8e8bd4a1a3fc2c61fd41423934df07b8405fab73 100644 |
--- a/third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.h |
+++ b/third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.h |
@@ -28,9 +28,16 @@ |
#include "modules/ModulesExport.h" |
#include "modules/webaudio/AbstractAudioContext.h" |
+#include "wtf/HashMap.h" |
+ |
namespace blink { |
class ExceptionState; |
+class OfflineAudioDestinationHandler; |
+ |
+// The HashMap with 'zero' key is needed because |currentSampleFrame| can be |
+// zero. |
+using SuspendMap = HeapHashMap<size_t, Member<ScriptPromiseResolver>, DefaultHash<size_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<size_t>>; |
class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext { |
DEFINE_WRAPPERTYPEINFO(); |
@@ -39,16 +46,62 @@ public: |
~OfflineAudioContext() override; |
+ DECLARE_VIRTUAL_TRACE(); |
+ |
ScriptPromise startOfflineRendering(ScriptState*); |
ScriptPromise closeContext(ScriptState*) final; |
- ScriptPromise suspendContext(ScriptState*) final; |
+ ScriptPromise suspendContext(ScriptState*, double) final; |
ScriptPromise resumeContext(ScriptState*) final; |
+ // This is to implement the pure virtual method from AbstractAudioContext. |
+ // CANNOT be called on OfflineAudioContext. |
Raymond Toy
2015/10/16 23:32:36
What does "called on OfflineAudioContext" mean her
hongchan
2015/10/19 20:08:12
Yes, the IDL will raise the exception if the time
Raymond Toy
2015/10/19 20:27:27
Maybe change "called on Offline..." with "called f
hongchan
2015/10/20 22:03:06
Done.
|
+ ScriptPromise suspendContext(ScriptState*) final; |
+ |
bool hasRealtimeConstraint() final { return false; } |
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); |
+ |
+ // Fire completion event when the rendering is suspended. |
+ void fireSuspendedEvent(); |
+ |
+ // Fire completion event when the rendering is finished. |
+ void fireCompletionEvent(); |
+ |
+ bool handlePreOfflineRenderTasks(); |
+ void handlePostOfflineRenderTasks(); |
+ |
+ // Resolve a suspend scheduled at the specified frame. With this specified |
+ // frame as a unique key, the associated promise resolver can be retrieved |
+ // from the map (m_scheduledSuspends) and resolved. |
+ void resolveSuspendOnMainThread(size_t); |
+ |
private: |
OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate); |
+ |
+ // Fetch directly the destination handler. |
+ OfflineAudioDestinationHandler& destinationHandler(); |
+ |
+ AudioBuffer* renderTarget() const { return m_renderTarget.get(); } |
+ |
+ // Check if the rendering needs to be suspended. |
+ bool shouldSuspend(); |
+ |
+ Member<AudioBuffer> m_renderTarget; |
+ |
+ // This map is to store the timing of scheduled suspends (frame) and the |
+ // associated promise resolver. |
+ SuspendMap m_scheduledSuspends; |
Raymond Toy
2015/10/16 23:32:36
Say something that this can only be read or writte
hongchan
2015/10/19 20:08:12
Done.
|
+ |
+ Member<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. |
Raymond Toy
2015/10/16 23:32:36
Not for this CL, but maybe it would be good in the
hongchan
2015/10/19 20:08:12
I agree with the idea, but I suggest a different n
|
+ bool m_isRenderingStarted; |
+ |
+ // Total render sample length. |
+ size_t m_totalRenderFrames; |
}; |
} // namespace blink |