Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (C) 2012, Google Inc. All rights reserved. | 2 * Copyright (C) 2012, Google Inc. All rights reserved. | 
| 3 * | 3 * | 
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without | 
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions | 
| 6 * are met: | 6 * are met: | 
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright | 
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. | 
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright | 
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 23 */ | 23 */ | 
| 24 | 24 | 
| 25 #ifndef OfflineAudioContext_h | 25 #ifndef OfflineAudioContext_h | 
| 26 #define OfflineAudioContext_h | 26 #define OfflineAudioContext_h | 
| 27 | 27 | 
| 28 #include "modules/ModulesExport.h" | 28 #include "modules/ModulesExport.h" | 
| 29 #include "modules/webaudio/AbstractAudioContext.h" | 29 #include "modules/webaudio/AbstractAudioContext.h" | 
| 30 | 30 | 
| 31 #include "wtf/HashMap.h" | |
| 32 | |
| 31 namespace blink { | 33 namespace blink { | 
| 32 | 34 | 
| 33 class ExceptionState; | 35 class ExceptionState; | 
| 36 class OfflineAudioDestinationHandler; | |
| 37 | |
| 38 // The HashMap with 'zero' key is needed because |currentSampleFrame| can be | |
| 39 // zero. | |
| 40 using SuspendMap = HeapHashMap<size_t, Member<ScriptPromiseResolver>, DefaultHas h<size_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<size_t>>; | |
| 34 | 41 | 
| 35 class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext { | 42 class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext { | 
| 36 DEFINE_WRAPPERTYPEINFO(); | 43 DEFINE_WRAPPERTYPEINFO(); | 
| 37 public: | 44 public: | 
| 38 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); | 45 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); | 
| 39 | 46 | 
| 40 ~OfflineAudioContext() override; | 47 ~OfflineAudioContext() override; | 
| 41 | 48 | 
| 49 DECLARE_VIRTUAL_TRACE(); | |
| 50 | |
| 42 ScriptPromise startOfflineRendering(ScriptState*); | 51 ScriptPromise startOfflineRendering(ScriptState*); | 
| 43 | 52 | 
| 44 ScriptPromise closeContext(ScriptState*) final; | 53 ScriptPromise closeContext(ScriptState*) final; | 
| 54 ScriptPromise suspendContext(ScriptState*, double) final; | |
| 55 ScriptPromise resumeContext(ScriptState*) final; | |
| 56 | |
| 57 // This is to implement the pure virtual method from AbstractAudioContext. | |
| 58 // CANNOT be called from an OfflineAudioContext. | |
| 45 ScriptPromise suspendContext(ScriptState*) final; | 59 ScriptPromise suspendContext(ScriptState*) final; | 
| 46 ScriptPromise resumeContext(ScriptState*) final; | |
| 47 | 60 | 
| 48 bool hasRealtimeConstraint() final { return false; } | 61 bool hasRealtimeConstraint() final { return false; } | 
| 49 | 62 | 
| 63 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); | |
| 64 | |
| 65 // Fire completion event when the rendering is suspended. | |
| 66 void fireSuspendedEvent(); | |
| 67 | |
| 68 // Fire completion event when the rendering is finished. | |
| 69 void fireCompletionEvent(); | |
| 70 | |
| 71 // This is same with the online version in AbstractAudioContext class except | |
| 72 // for returning a boolean value after checking the scheduled suspends. | |
| 73 bool handlePreOfflineRenderTasks(); | |
| 74 | |
| 75 void handlePostOfflineRenderTasks(); | |
| 76 | |
| 77 // Resolve a suspend scheduled at the specified frame. With this specified | |
| 78 // frame as a unique key, the associated promise resolver can be retrieved | |
| 79 // from the map (m_scheduledSuspends) and resolved. | |
| 80 void resolveSuspendOnMainThread(size_t); | |
| 81 | |
| 50 private: | 82 private: | 
| 51 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); | 83 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); | 
| 84 | |
| 85 // Fetch directly the destination handler. | |
| 86 OfflineAudioDestinationHandler& destinationHandler(); | |
| 87 | |
| 88 AudioBuffer* renderTarget() const { return m_renderTarget.get(); } | |
| 89 | |
| 90 // Check if the rendering needs to be suspended. | |
| 91 bool shouldSuspend(); | |
| 92 | |
| 93 Member<AudioBuffer> m_renderTarget; | |
| 94 | |
| 95 // This map is to store the timing of scheduled suspends (frame) and the | |
| 96 // associated promise resolver. This storage can only be modified by the | |
| 97 // main thread and accessed by the audio thread with the graph lock. | |
| 
 
Raymond Toy
2015/10/21 18:22:45
Add comment on what the key is and the value in th
 
hongchan
2015/10/22 18:23:49
Done.
 
 | |
| 98 SuspendMap m_scheduledSuspends; | |
| 99 | |
| 100 Member<ScriptPromiseResolver> m_completeResolver; | |
| 101 | |
| 102 // This flag is necessary to indicate the rendering has actually started. | |
| 103 // Note that initial state of context is 'Suspended', which is the same | |
| 104 // state when the context is suspended. | |
| 105 bool m_isRenderingStarted; | |
| 106 | |
| 107 // Total render sample length. | |
| 108 size_t m_totalRenderFrames; | |
| 52 }; | 109 }; | 
| 53 | 110 | 
| 54 } // namespace blink | 111 } // namespace blink | 
| 55 | 112 | 
| 56 #endif // OfflineAudioContext_h | 113 #endif // OfflineAudioContext_h | 
| OLD | NEW |