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/AudioContext.h" | 29 #include "modules/webaudio/AudioContext.h" |
| 30 #include "wtf/HashMap.h" |
30 | 31 |
31 namespace blink { | 32 namespace blink { |
32 | 33 |
33 class ExceptionState; | 34 class ExceptionState; |
| 35 class ScheduledSuspendContainer; |
| 36 |
| 37 // The HashMap with 'zero' key is needed because |currentSampleFrame| can be zer
o. |
| 38 using SuspendContainerMap = HashMap<size_t, RefPtr<ScheduledSuspendContainer>, D
efaultHash<size_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<size_t>>; |
34 | 39 |
35 class MODULES_EXPORT OfflineAudioContext final : public AudioContext { | 40 class MODULES_EXPORT OfflineAudioContext final : public AudioContext { |
36 DEFINE_WRAPPERTYPEINFO(); | 41 DEFINE_WRAPPERTYPEINFO(); |
37 public: | 42 public: |
38 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann
els, size_t numberOfFrames, float sampleRate, ExceptionState&); | 43 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann
els, size_t numberOfFrames, float sampleRate, ExceptionState&); |
39 | 44 |
40 virtual ~OfflineAudioContext(); | 45 virtual ~OfflineAudioContext(); |
41 | 46 |
| 47 DECLARE_VIRTUAL_TRACE(); |
| 48 |
| 49 // Fire completion event when the rendering is finished. |
| 50 void fireCompletionEvent() override; |
| 51 |
| 52 // Check all the scheduled suspends if the context should suspend at |
| 53 // currentTime(). Then post tasks to resolve promises on the main thread |
| 54 // if necessary. |
| 55 bool shouldSuspendNow() override; |
| 56 |
| 57 // Clear suspensions marked as 'resolved' in the list. |
| 58 void resolvePendingSuspendPromises() override; |
| 59 |
| 60 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete); |
| 61 |
42 ScriptPromise startOfflineRendering(ScriptState*); | 62 ScriptPromise startOfflineRendering(ScriptState*); |
| 63 ScriptPromise suspendOfflineRendering(ScriptState*, double); |
| 64 ScriptPromise resumeOfflineRendering(ScriptState*); |
| 65 |
43 private: | 66 private: |
44 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra
mes, float sampleRate); | 67 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra
mes, float sampleRate); |
| 68 |
| 69 // Check if there is any duplicate entry in scheduled suspends and reject |
| 70 // the promise if needed. |
| 71 void checkDuplicateSuspend(PassRefPtr<ScheduledSuspendContainer>); |
| 72 |
| 73 // Reject a suspend promise on the main thread when the validation fails. |
| 74 void rejectSuspendPromiseOnMainThread(PassRefPtr<ScheduledSuspendContainer>)
; |
| 75 |
| 76 // Resolve a pending suspend promise and removes it from the map. |
| 77 void resolvePendingSuspendPromisesOnMainThread(PassRefPtr<ScheduledSuspendCo
ntainer>); |
| 78 |
| 79 SuspendContainerMap m_scheduledSuspends; |
| 80 RefPtrWillBeMember<ScriptPromiseResolver> m_completeResolver; |
| 81 |
| 82 // This flag is necessary to indicate the rendering has actually started. |
| 83 // Note that initial state of context is 'Suspended', which is the same |
| 84 // state when the context is suspended. |
| 85 bool m_isRenderingStarted; |
| 86 |
| 87 // Total render sample length. |
| 88 size_t m_totalRenderFrames; |
| 89 }; |
| 90 |
| 91 // A container class for a pair of time information and the suspend promise |
| 92 // resolver. |
| 93 // |
| 94 // TODO: This class is |ThreadSafeRefCounted| because it needs to be accessed by |
| 95 // the offline render thread which is not oilpan-enabled. This is a short-term |
| 96 // solution until the offline render thread gets oilpan coverage. |
| 97 class ScheduledSuspendContainer : public ThreadSafeRefCounted<ScheduledSuspendCo
ntainer> { |
| 98 public: |
| 99 static PassRefPtr<ScheduledSuspendContainer> create(double suspendTime, size
_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>); |
| 100 ~ScheduledSuspendContainer(); |
| 101 |
| 102 PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver() { return m_resolver
; } |
| 103 |
| 104 double suspendTime() const { return m_suspendTime; } |
| 105 |
| 106 size_t suspendFrame() const { return m_suspendFrame; } |
| 107 |
| 108 // Query if the rendering should be suspended at |whenFrame|. |
| 109 bool shouldSuspendAtFrame(size_t whenFrame) const; |
| 110 |
| 111 private: |
| 112 ScheduledSuspendContainer(double suspendTime, size_t suspendFrame, PassRefPt
rWillBeRawPtr<ScriptPromiseResolver>); |
| 113 |
| 114 // Actual suspend time before the quantization by render quantum frame. |
| 115 double m_suspendTime; |
| 116 |
| 117 // Suspend sample frame. This is quantized by the render quantum size. |
| 118 size_t m_suspendFrame; |
| 119 |
| 120 // Associated promise resolver. |
| 121 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; |
45 }; | 122 }; |
46 | 123 |
47 } // namespace blink | 124 } // namespace blink |
48 | 125 |
49 #endif // OfflineAudioContext_h | 126 #endif // OfflineAudioContext_h |
OLD | NEW |