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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
haraken
2015/11/17 08:28:10
Nit: Remove the empty line.
hongchan
2015/11/17 18:11:44
Done.
| |
31 #include "wtf/HashMap.h" | |
32 | |
31 namespace blink { | 33 namespace blink { |
32 | 34 |
33 class ExceptionState; | 35 class ExceptionState; |
36 class OfflineAudioDestinationHandler; | |
34 | 37 |
35 class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext { | 38 class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext { |
36 DEFINE_WRAPPERTYPEINFO(); | 39 DEFINE_WRAPPERTYPEINFO(); |
37 public: | 40 public: |
38 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); | 41 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); |
39 | 42 |
40 ~OfflineAudioContext() override; | 43 ~OfflineAudioContext() override; |
41 | 44 |
45 DECLARE_VIRTUAL_TRACE(); | |
46 | |
42 ScriptPromise startOfflineRendering(ScriptState*); | 47 ScriptPromise startOfflineRendering(ScriptState*); |
43 | 48 |
44 ScriptPromise closeContext(ScriptState*) final; | 49 ScriptPromise closeContext(ScriptState*) final; |
50 ScriptPromise suspendContext(ScriptState*, double); | |
51 ScriptPromise resumeContext(ScriptState*) final; | |
52 | |
53 // This is to implement the pure virtual method from AbstractAudioContext. | |
54 // CANNOT be called from an OfflineAudioContext. | |
45 ScriptPromise suspendContext(ScriptState*) final; | 55 ScriptPromise suspendContext(ScriptState*) final; |
46 ScriptPromise resumeContext(ScriptState*) final; | |
47 | 56 |
48 bool hasRealtimeConstraint() final { return false; } | 57 bool hasRealtimeConstraint() final { return false; } |
49 | 58 |
59 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); | |
60 | |
61 // Fire completion event when the rendering is finished. | |
62 void fireCompletionEvent(); | |
63 | |
64 // This is same with the online version in AbstractAudioContext class except | |
65 // for returning a boolean value after checking the scheduled suspends. | |
66 bool handlePreOfflineRenderTasks(); | |
67 | |
68 void handlePostOfflineRenderTasks(); | |
69 | |
70 // Resolve a suspend scheduled at the specified frame. With this specified | |
71 // frame as a unique key, the associated promise resolver can be retrieved | |
72 // from the map (m_scheduledSuspends) and resolved. | |
73 void resolveSuspendOnMainThread(size_t); | |
74 | |
75 // The HashMap with 'zero' key is needed because |currentSampleFrame| can be | |
76 // zero. | |
77 using SuspendMap = HeapHashMap<size_t, Member<ScriptPromiseResolver>, Defaul tHash<size_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<size_t>>; | |
78 | |
79 using OfflineGraphAutoLocker = DeferredTaskHandler::OfflineGraphAutoLocker; | |
80 | |
50 private: | 81 private: |
51 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); | 82 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate, ExceptionState&); |
83 | |
84 // Fetch directly the destination handler. | |
85 OfflineAudioDestinationHandler& destinationHandler(); | |
86 | |
87 AudioBuffer* renderTarget() const { return m_renderTarget.get(); } | |
88 | |
89 // Check if the rendering needs to be suspended. | |
90 bool shouldSuspend(); | |
91 | |
92 Member<AudioBuffer> m_renderTarget; | |
93 | |
94 // This map is to store the timing of scheduled suspends (frame) and the | |
95 // associated promise resolver. This storage can only be modified by the | |
96 // main thread and accessed by the audio thread with the graph lock. | |
97 // | |
98 // 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.
| |
99 // { size_t quantizedFrame: ScriptPromiseResolver resolver } | |
100 // | |
101 // Note that |quantizedFrame| is a unique key, since you can have only one | |
102 // suspend scheduled for a certain frame. | |
103 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.
| |
104 | |
105 Member<ScriptPromiseResolver> m_completeResolver; | |
106 | |
107 // This flag is necessary to indicate the rendering has actually started. | |
108 // Note that initial state of context is 'Suspended', which is the same | |
109 // state when the context is suspended. | |
110 bool m_isRenderingStarted; | |
111 | |
112 // Total render sample length. | |
113 size_t m_totalRenderFrames; | |
52 }; | 114 }; |
53 | 115 |
54 } // namespace blink | 116 } // namespace blink |
55 | 117 |
56 #endif // OfflineAudioContext_h | 118 #endif // OfflineAudioContext_h |
OLD | NEW |