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

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

Issue 1405413004: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating UseCounter.h after L-G-T-M Created 5 years 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/AbstractAudioContext.h" 29 #include "modules/webaudio/AbstractAudioContext.h"
30 #include "wtf/HashMap.h"
30 31
31 namespace blink { 32 namespace blink {
32 33
33 class ExceptionState; 34 class ExceptionState;
35 class OfflineAudioDestinationHandler;
34 36
35 class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext { 37 class MODULES_EXPORT OfflineAudioContext final : public AbstractAudioContext {
36 DEFINE_WRAPPERTYPEINFO(); 38 DEFINE_WRAPPERTYPEINFO();
37 public: 39 public:
38 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); 40 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&);
39 41
40 ~OfflineAudioContext() override; 42 ~OfflineAudioContext() override;
41 43
44 DECLARE_VIRTUAL_TRACE();
45
42 ScriptPromise startOfflineRendering(ScriptState*); 46 ScriptPromise startOfflineRendering(ScriptState*);
43 47
44 ScriptPromise closeContext(ScriptState*) final; 48 ScriptPromise closeContext(ScriptState*) final;
49 ScriptPromise suspendContext(ScriptState*, double);
50 ScriptPromise resumeContext(ScriptState*) final;
51
52 // This is to implement the pure virtual method from AbstractAudioContext.
53 // CANNOT be called from an OfflineAudioContext.
45 ScriptPromise suspendContext(ScriptState*) final; 54 ScriptPromise suspendContext(ScriptState*) final;
46 ScriptPromise resumeContext(ScriptState*) final;
47 55
48 bool hasRealtimeConstraint() final { return false; } 56 bool hasRealtimeConstraint() final { return false; }
49 57
58 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
59
60 // Fire completion event when the rendering is finished.
61 void fireCompletionEvent();
62
63 // This is same with the online version in AbstractAudioContext class except
64 // for returning a boolean value after checking the scheduled suspends.
65 bool handlePreOfflineRenderTasks();
66
67 void handlePostOfflineRenderTasks();
68
69 // Resolve a suspend scheduled at the specified frame. With this specified
70 // frame as a unique key, the associated promise resolver can be retrieved
71 // from the map (m_scheduledSuspends) and resolved.
72 void resolveSuspendOnMainThread(size_t);
73
74 // The HashMap with 'zero' key is needed because |currentSampleFrame| can be
75 // zero.
76 using SuspendMap = HeapHashMap<size_t, Member<ScriptPromiseResolver>, Defaul tHash<size_t>::Hash, WTF::UnsignedWithZeroKeyHashTraits<size_t>>;
77
78 using OfflineGraphAutoLocker = DeferredTaskHandler::OfflineGraphAutoLocker;
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, ExceptionState&);
82
83 // Fetch directly the destination handler.
84 OfflineAudioDestinationHandler& destinationHandler();
85
86 AudioBuffer* renderTarget() const { return m_renderTarget.get(); }
87
88 // Check if the rendering needs to be suspended.
89 bool shouldSuspend();
90
91 Member<AudioBuffer> m_renderTarget;
92
93 // This map is to store the timing of scheduled suspends (frame) and the
94 // associated promise resolver. This storage can only be modified by the
95 // main thread and accessed by the audio thread with the graph lock.
96 //
97 // The map consists of key-value pairs of:
98 // { size_t quantizedFrame: ScriptPromiseResolver resolver }
99 //
100 // Note that |quantizedFrame| is a unique key, since you can have only one
101 // suspend scheduled for a certain frame. Accessing to this must be
102 // protected by the offline context lock.
103 SuspendMap m_scheduledSuspends;
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698