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

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: Resolving the render thread issue (WIP) 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
(...skipping 13 matching lines...) Expand all
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 30
31 namespace blink { 31 namespace blink {
32 32
33 class ExceptionState; 33 class ExceptionState;
34 class ScheduledSuspendContainer;
34 35
35 class MODULES_EXPORT OfflineAudioContext final : public AudioContext { 36 class MODULES_EXPORT OfflineAudioContext final : public AudioContext {
36 DEFINE_WRAPPERTYPEINFO(); 37 DEFINE_WRAPPERTYPEINFO();
37 public: 38 public:
38 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); 39 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&);
39 40
40 virtual ~OfflineAudioContext(); 41 virtual ~OfflineAudioContext();
41 42
43 DECLARE_VIRTUAL_TRACE();
44
45 // Fire completion event when the rendering is finished.
46 void fireCompletionEvent() override;
47
48 // Check all the scheduled suspends if the context should suspend at
49 // currentTime(). Then post tasks to resolve promises on the main thread
50 // if necessary.
51 bool shouldSuspendNow() override;
52
53 // Clear suspensions marked as 'resolved' in the list.
54 void resolvePendingSuspendPromises() override;
55
56 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
57
42 ScriptPromise startOfflineRendering(ScriptState*); 58 ScriptPromise startOfflineRendering(ScriptState*);
59 ScriptPromise suspendOfflineRendering(ScriptState*, double);
60 ScriptPromise resumeOfflineRendering(ScriptState*);
61
43 private: 62 private:
44 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); 63 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate);
64
65 // Validate a suspend with various criteria on the render thread.
66 void checkDuplicateSuspend(ScheduledSuspendContainer*);
67
68 // TODO: Reject a suspend on the main thread after the validation fails.
69 void rejectSuspendOnMainThread(ScheduledSuspendContainer*);
70
71 // Resolve pending suspend promises and removes them from the list.
72 void resolvePendingSuspendPromisesOnMainThread();
73
74 HeapVector<Member<ScheduledSuspendContainer>> m_scheduledSuspends;
75 RefPtrWillBeMember<ScriptPromiseResolver> m_completeResolver;
76
77 // This flag is necessary to indicate the rendering has actually started.
78 // Note that initial state of context is 'Suspended', which is the same
79 // state when the context is suspended.
80 bool m_isRenderingStarted;
81
82 // Total render sample length.
83 size_t m_totalRenderFrames;
84
85 // MutexLocker for m_scheduledSuspends.
86 Mutex m_suspendMutex;
87 };
88
89 // A container class for a pair of time information and the suspend promise
90 // resolver.
91 class ScheduledSuspendContainer : public GarbageCollectedFinalized<ScheduledSusp endContainer> {
92 public:
93 static ScheduledSuspendContainer* create(double suspendTime, size_t suspendF rame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>);
94 ~ScheduledSuspendContainer();
95
96 DECLARE_TRACE();
97
98 PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver() { return m_resolver ; }
99
100 double suspendTime() const { return m_suspendTime; }
101
102 size_t suspendFrame() const { return m_suspendFrame; }
103
104 // Query if the rendering should be suspended at |whenFrame|.
105 bool shouldSuspendAtFrame(size_t whenFrame) const;
106
107 // Query if the suspend is pending for the promise resolution.
108 bool isPending() const;
109
110 // Mark the suspend as pending. Containers with 'pending' flag will
111 // be collectively resolved when the actual suspension happens.
112 void markAsPending();
113
114 private:
115 ScheduledSuspendContainer(double suspendTime, size_t suspendFrame, PassRefPt rWillBeRawPtr<ScriptPromiseResolver>);
116
117 // Actual suspend time before the quantization by render quantum frame.
118 double m_suspendTime;
119
120 // Suspend time in samples.
121 size_t m_suspendFrame;
122
123 // Associated promise resolver.
124 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver;
125
126 // A pending marker for the safe batch removal.
127 bool m_isPending;
45 }; 128 };
46 129
47 } // namespace blink 130 } // namespace blink
48 131
49 #endif // OfflineAudioContext_h 132 #endif // OfflineAudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698