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

Unified Diff: third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.h

Issue 1405413004: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed feedback from yhirano Created 5 years, 1 month 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: 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..2ff661537e1b0826701da5073da8cda5c8a834d4 100644
--- a/third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.h
+++ b/third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.h
@@ -28,9 +28,12 @@
#include "modules/ModulesExport.h"
#include "modules/webaudio/AbstractAudioContext.h"
haraken 2015/11/17 08:28:10 Nit: Remove the empty line.
hongchan 2015/11/17 18:11:44 Done.
+#include "wtf/HashMap.h"
+
namespace blink {
class ExceptionState;
+class OfflineAudioDestinationHandler;
class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext {
DEFINE_WRAPPERTYPEINFO();
@@ -39,16 +42,75 @@ public:
~OfflineAudioContext() override;
+ DECLARE_VIRTUAL_TRACE();
+
ScriptPromise startOfflineRendering(ScriptState*);
ScriptPromise closeContext(ScriptState*) final;
- ScriptPromise suspendContext(ScriptState*) final;
+ ScriptPromise suspendContext(ScriptState*, double);
ScriptPromise resumeContext(ScriptState*) final;
+ // This is to implement the pure virtual method from AbstractAudioContext.
+ // CANNOT be called from an OfflineAudioContext.
+ ScriptPromise suspendContext(ScriptState*) final;
+
bool hasRealtimeConstraint() final { return false; }
+ DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
+
+ // Fire completion event when the rendering is finished.
+ void fireCompletionEvent();
+
+ // This is same with the online version in AbstractAudioContext class except
+ // for returning a boolean value after checking the scheduled suspends.
+ 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);
+
+ // 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>>;
+
+ using OfflineGraphAutoLocker = DeferredTaskHandler::OfflineGraphAutoLocker;
+
private:
- OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate);
+ OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionState&);
+
+ // 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. This storage can only be modified by the
+ // main thread and accessed by the audio thread with the graph lock.
+ //
+ // The map is consist of key-value pairs of:
haraken 2015/11/17 08:28:10 The map consists of
hongchan 2015/11/17 18:11:44 Oops. Done.
+ // { size_t quantizedFrame: ScriptPromiseResolver resolver }
+ //
+ // Note that |quantizedFrame| is a unique key, since you can have only one
+ // suspend scheduled for a certain frame.
+ SuspendMap m_scheduledSuspends;
Raymond Toy 2015/11/18 21:40:41 Since this needs to be locked (as haraken pointed
hongchan 2015/11/19 23:48:26 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.
+ bool m_isRenderingStarted;
+
+ // Total render sample length.
+ size_t m_totalRenderFrames;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698