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

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: Making Oilpan-compatible changes 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_TRACE();
44
45 // Check all the scheduled suspends if the context should suspend at
46 // currentTime(). Then post tasks to resolve promises on the main thread
47 // if necessary.
48 bool shouldSuspendNow();
yhirano 2015/06/18 13:40:52 +override ditto for below
hongchan 2015/06/18 18:22:31 Done.
49
50 // Clear suspensions marked as 'resolved' in the list.
51 void resolvePendingSuspendPromises();
52
53 // Fire completion event when the rendering is finished.
54 void fireCompletionEvent();
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 // Resolve pending suspend promises and removes them from the list.
66 void resolvePendingSuspendPromisesOnMainThread();
67
68 HeapVector<Member<ScheduledSuspendContainer>> m_scheduledSuspends;
69 RefPtrWillBeMember<ScriptPromiseResolver> m_completeResolver;
70
71 // This flag is necessary to indicate the rendering has actually started.
72 // Note that initial state of context is 'Suspended', which is the same
73 // state when the context is suspended.
74 bool m_isRenderingStarted;
75
76 // Total render sample length.
77 size_t m_totalRenderFrames;
78 };
79
80 // A container class for a pair of time information and the suspend promise
81 // resolver.
82 class ScheduledSuspendContainer : public GarbageCollectedFinalized<ScheduledSusp endContainer> {
83 public:
84 static ScheduledSuspendContainer* create(size_t suspendFrame, PassRefPtrWill BeRawPtr<ScriptPromiseResolver>);
85 ~ScheduledSuspendContainer();
86
87 DECLARE_TRACE();
88
89 PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver() { return m_resolver ; }
90
91 // Query if the rendering should be suspended at |whenFrame|.
92 bool shouldSuspendAt(size_t whenFrame) const;
93
94 // Query if the suspend is pending for the promise resolution.
95 bool isPending() const;
96
97 // Mark the suspend as pending. Containers with 'pending' flag will
98 // be collectively resolved when the actual suspension happens.
99 void markAsPending();
100
101 private:
102 ScheduledSuspendContainer(size_t suspendFrame, PassRefPtrWillBeRawPtr<Script PromiseResolver>);
103
104 // Suspend time in samples.
105 size_t m_suspendFrame;
106
107 // Associated promise resolver.
108 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver;
109
110 // A pending marker for the safe batch removal.
111 bool m_isPending;
45 }; 112 };
46 113
47 } // namespace blink 114 } // namespace blink
48 115
49 #endif // OfflineAudioContext_h 116 #endif // OfflineAudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698