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 #include "wtf/HashSet.h" | |
33 | |
31 namespace blink { | 34 namespace blink { |
32 | 35 |
33 class ExceptionState; | 36 class ExceptionState; |
37 class ScheduledSuspendContainer; | |
38 class OfflineAudioDestinationHandler; | |
39 | |
40 // The HashMap with 'zero' key is needed because |currentSampleFrame| can be | |
41 // zero. Also ScheduledSuspendContainer is a raw pointer (rather than RefPtr) | |
42 // because it must be guaranteed that the main thread keeps it alive while the | |
43 // render thread uses it. | |
44 using SuspendContainerMap = HashMap<size_t, ScheduledSuspendContainer*, DefaultH ash<size_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<size_t>>; | |
34 | 45 |
35 class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext { | 46 class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext { |
36 DEFINE_WRAPPERTYPEINFO(); | 47 DEFINE_WRAPPERTYPEINFO(); |
37 public: | 48 public: |
38 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); | 49 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); |
39 | 50 |
40 ~OfflineAudioContext() override; | 51 ~OfflineAudioContext() override; |
41 | 52 |
53 DECLARE_VIRTUAL_TRACE(); | |
54 | |
55 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); | |
56 | |
57 // Check all the scheduled suspends if the context should suspend at | |
58 // currentTime(). Then post tasks to resolve promises on the main thread | |
59 // if necessary. | |
60 bool shouldSuspendNow(); | |
61 | |
62 // Clear suspensions marked as 'resolved' in the list. | |
63 void resolvePendingSuspendPromises(); | |
64 | |
65 // Fire completion event when the rendering is finished. | |
66 void fireCompletionEvent(); | |
67 | |
42 ScriptPromise startOfflineRendering(ScriptState*); | 68 ScriptPromise startOfflineRendering(ScriptState*); |
43 | 69 |
44 ScriptPromise closeContext(ScriptState*) final; | 70 ScriptPromise closeContext(ScriptState*) final; |
71 ScriptPromise suspendContext(ScriptState*, double) final; | |
72 ScriptPromise resumeContext(ScriptState*) final; | |
73 | |
74 // This is to implement the pure virtual method from AbstractAudioContext. | |
75 // CANNOT be called on OfflineAudioContext. | |
45 ScriptPromise suspendContext(ScriptState*) final; | 76 ScriptPromise suspendContext(ScriptState*) final; |
46 ScriptPromise resumeContext(ScriptState*) final; | |
47 | 77 |
48 bool hasRealtimeConstraint() final { return false; } | 78 bool hasRealtimeConstraint() final { return false; } |
49 | 79 |
50 private: | 80 private: |
51 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); | 81 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); |
82 | |
83 // Fetch directly the destination handler. | |
84 OfflineAudioDestinationHandler& destinationHandler(); | |
85 | |
86 // Check a suspend container if it has a duplicate scheduled frame or | |
87 // is behind the current frame. If the validation fails, post a task to the | |
88 // main thread to reject the promise. | |
89 void validateSuspendContainerOnRenderThread(ScheduledSuspendContainer*, doub le, size_t); | |
90 | |
91 // Reject a suspend container on the main thread when the validation fails. | |
92 void rejectSuspendContainerOnMainThread(ScheduledSuspendContainer*, const St ring&); | |
93 | |
94 // Resolve a pending suspend container. | |
95 void resolveSuspendContainerOnMainThread(ScheduledSuspendContainer*); | |
96 | |
97 // This set is for maintaining the ownership of SchduledSuspendContainer | |
98 // raw pointers. | |
hiroshige
2015/07/22 17:32:12
Please add a comment that this field is accessed o
hongchan
2015/07/22 20:36:35
Done.
| |
99 HashSet<ScheduledSuspendContainer*> m_suspendContainers; | |
hiroshige
2015/07/22 17:32:12
nit optional: the names of |m_suspendedContainers|
hongchan
2015/07/22 20:36:35
Acknowledged.
| |
100 | |
101 // This map is to check the timing of scheduled suspends. | |
hiroshige
2015/07/22 17:32:12
Please add a comment that this field is accessed o
hongchan
2015/07/22 20:36:35
Done.
| |
102 SuspendContainerMap m_scheduledSuspends; | |
103 | |
104 RefPtrWillBeMember<ScriptPromiseResolver> m_completeResolver; | |
105 | |
106 // This flag is necessary to indicate the rendering has actually started. | |
107 // Note that initial state of context is 'Suspended', which is the same | |
108 // state when the context is suspended. | |
109 bool m_isRenderingStarted; | |
110 | |
111 // Total render sample length. | |
112 size_t m_totalRenderFrames; | |
113 }; | |
114 | |
115 // A container class for a pair of time information and the suspend promise | |
116 // resolver. This class does not need to be |ThreadSafeRefCounted| because it | |
117 // needs to be created and destructed in the main thread. | |
118 class ScheduledSuspendContainer { | |
119 public: | |
120 static ScheduledSuspendContainer* create(PassRefPtrWillBeRawPtr<ScriptPromis eResolver>); | |
121 ~ScheduledSuspendContainer(); | |
122 | |
123 // {Resolve, Reject} the promise resolver on the main thread. | |
124 void resolvePromise(); | |
125 void rejectPromise(ExceptionCode, const String&); | |
126 | |
127 private: | |
128 ScheduledSuspendContainer(PassRefPtrWillBeRawPtr<ScriptPromiseResolver>); | |
129 | |
130 // Associated promise resolver. | |
131 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | |
52 }; | 132 }; |
53 | 133 |
54 } // namespace blink | 134 } // namespace blink |
55 | 135 |
56 #endif // OfflineAudioContext_h | 136 #endif // OfflineAudioContext_h |
OLD | NEW |