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 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.
| |
| 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 bool handlePreOfflineRenderTasks(); | |
| 72 void handlePostOfflineRenderTasks(); | |
| 73 | |
| 74 // Resolve a suspend scheduled at the specified frame. With this specified | |
| 75 // frame as a unique key, the associated promise resolver can be retrieved | |
| 76 // from the map (m_scheduledSuspends) and resolved. | |
| 77 void resolveSuspendOnMainThread(size_t); | |
| 78 | |
| 50 private: | 79 private: |
| 51 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); | 80 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); |
| 81 | |
| 82 // Fetch directly the destination handler. | |
| 83 OfflineAudioDestinationHandler& destinationHandler(); | |
| 84 | |
| 85 AudioBuffer* renderTarget() const { return m_renderTarget.get(); } | |
| 86 | |
| 87 // Check if the rendering needs to be suspended. | |
| 88 bool shouldSuspend(); | |
| 89 | |
| 90 Member<AudioBuffer> m_renderTarget; | |
| 91 | |
| 92 // This map is to store the timing of scheduled suspends (frame) and the | |
| 93 // associated promise resolver. | |
| 94 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.
| |
| 95 | |
| 96 Member<ScriptPromiseResolver> m_completeResolver; | |
| 97 | |
| 98 // This flag is necessary to indicate the rendering has actually started. | |
| 99 // Note that initial state of context is 'Suspended', which is the same | |
| 100 // 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
| |
| 101 bool m_isRenderingStarted; | |
| 102 | |
| 103 // Total render sample length. | |
| 104 size_t m_totalRenderFrames; | |
| 52 }; | 105 }; |
| 53 | 106 |
| 54 } // namespace blink | 107 } // namespace blink |
| 55 | 108 |
| 56 #endif // OfflineAudioContext_h | 109 #endif // OfflineAudioContext_h |
| OLD | NEW |