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

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: Moving the suspend list manipulation to the render thread (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 validateSuspend(double when, PassRefPtrWillBeRawPtr<ScriptPromiseResolv er>);
67
68 // TODO: Reject a suspend on the main thread after the validation fails.
69 // void rejectSuspendOnMainThread();
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
86 // A container class for a pair of time information and the suspend promise
87 // resolver.
88 class ScheduledSuspendContainer : public GarbageCollectedFinalized<ScheduledSusp endContainer> {
89 public:
90 static ScheduledSuspendContainer* create(size_t suspendFrame, PassRefPtrWill BeRawPtr<ScriptPromiseResolver>);
91 ~ScheduledSuspendContainer();
92
93 DECLARE_TRACE();
94
95 PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver() { return m_resolver ; }
96
97 // Query if the rendering should be suspended at |whenFrame|.
98 bool shouldSuspendAt(size_t whenFrame) const;
99
100 // Query if the suspend is pending for the promise resolution.
101 bool isPending() const;
102
103 // Mark the suspend as pending. Containers with 'pending' flag will
104 // be collectively resolved when the actual suspension happens.
105 void markAsPending();
106
107 private:
108 ScheduledSuspendContainer(size_t suspendFrame, PassRefPtrWillBeRawPtr<Script PromiseResolver>);
109
110 // Suspend time in samples.
111 size_t m_suspendFrame;
112
113 // Associated promise resolver.
114 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver;
115
116 // A pending marker for the safe batch removal.
117 bool m_isPending;
45 }; 118 };
46 119
47 } // namespace blink 120 } // namespace blink
48 121
49 #endif // OfflineAudioContext_h 122 #endif // OfflineAudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698