Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: Source/modules/webaudio/OfflineAudioContext.h

Issue 1140723003: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Revering oilpan-compatible changes + HashMap Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 using SuspendContainerMap = HashMap<size_t, RefPtr<ScheduledSuspendContainer>>;
hongchan 2015/06/24 21:14:12 I changed the vector to HashMap. I didn't use Heap
34 38
35 class MODULES_EXPORT OfflineAudioContext final : public AudioContext { 39 class MODULES_EXPORT OfflineAudioContext final : public AudioContext {
36 DEFINE_WRAPPERTYPEINFO(); 40 DEFINE_WRAPPERTYPEINFO();
37 public: 41 public:
38 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); 42 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&);
39 43
40 virtual ~OfflineAudioContext(); 44 virtual ~OfflineAudioContext();
41 45
46 DECLARE_VIRTUAL_TRACE();
47
48 // Fire completion event when the rendering is finished.
49 void fireCompletionEvent() override;
50
51 // Check all the scheduled suspends if the context should suspend at
52 // currentTime(). Then post tasks to resolve promises on the main thread
53 // if necessary.
54 bool shouldSuspendNow() override;
55
56 // Clear suspensions marked as 'resolved' in the list.
57 void resolvePendingSuspendPromises() override;
58
59 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
60
42 ScriptPromise startOfflineRendering(ScriptState*); 61 ScriptPromise startOfflineRendering(ScriptState*);
62 ScriptPromise suspendOfflineRendering(ScriptState*, double);
63 ScriptPromise resumeOfflineRendering(ScriptState*);
64
43 private: 65 private:
44 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); 66 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate);
67
68 // Validate a suspend with various criteria on the render thread.
69 void checkDuplicateSuspend(ScheduledSuspendContainer*);
70
71 // Reject a suspend on the main thread after the validation fails.
72 void rejectSuspendPromiseOnMainThread(ScheduledSuspendContainer*);
73
74 // Resolve pending suspend promises and removes them from the list.
75 void resolvePendingSuspendPromisesOnMainThread(ScheduledSuspendContainer*);
76
77 // Vector<RefPtr<ScheduledSuspendContainer>> m_scheduledSuspends;
78 SuspendContainerMap m_scheduledSuspends;
hongchan 2015/06/24 21:14:12 This is HashMap of <size_t suspendFrame, RefPtr<Sc
79 RefPtrWillBeMember<ScriptPromiseResolver> m_completeResolver;
80
81 // This flag is necessary to indicate the rendering has actually started.
82 // Note that initial state of context is 'Suspended', which is the same
83 // state when the context is suspended.
84 bool m_isRenderingStarted;
85
86 bool m_isResolvingSuspendPromise;
87
88 // Total render sample length.
89 size_t m_totalRenderFrames;
90 };
91
92 // A container class for a pair of time information and the suspend promise
93 // resolver.
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 ScheduledSuspendContainer* create(double suspendTime, size_t suspendF rame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>);
yhirano 2015/06/25 04:00:53 static PassRefPtr<ScheduledSuspendContainer> creat
hongchan 2015/06/25 23:34:13 Done.
100 ~ScheduledSuspendContainer();
101
102 DECLARE_TRACE();
yhirano 2015/06/25 04:00:53 No TRACE is needed.
hongchan 2015/06/25 23:34:13 Removed.
103
104 PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver() { return m_resolver ; }
105
106 double suspendTime() const { return m_suspendTime; }
107
108 size_t suspendFrame() const { return m_suspendFrame; }
109
110 // Query if the rendering should be suspended at |whenFrame|.
111 bool shouldSuspendAtFrame(size_t whenFrame) const;
112
113 // Query if the suspend is pending for the promise resolution.
114 bool isPending() const;
115
116 // Mark the suspend as pending. Containers with 'pending' flag will
117 // be collectively resolved when the actual suspension happens.
118 void markAsPending();
119
120 private:
121 ScheduledSuspendContainer(double suspendTime, size_t suspendFrame, PassRefPt rWillBeRawPtr<ScriptPromiseResolver>);
122
123 // Actual suspend time before the quantization by render quantum frame.
124 double m_suspendTime;
125
126 // Suspend time in samples.
127 size_t m_suspendFrame;
128
129 // Associated promise resolver.
130 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver;
yhirano 2015/06/25 04:00:53 RefPtrWillBePersistent
hongchan 2015/06/25 23:34:13 Done.
131
132 // A pending marker for the safe batch removal.
133 bool m_isPending;
45 }; 134 };
46 135
47 } // namespace blink 136 } // namespace blink
48 137
49 #endif // OfflineAudioContext_h 138 #endif // OfflineAudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698