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

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: Ready for Review 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 21 matching lines...) Expand all
32 32
33 class ExceptionState; 33 class ExceptionState;
34 34
35 class MODULES_EXPORT OfflineAudioContext final : public AudioContext { 35 class MODULES_EXPORT OfflineAudioContext final : public AudioContext {
36 DEFINE_WRAPPERTYPEINFO(); 36 DEFINE_WRAPPERTYPEINFO();
37 public: 37 public:
38 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&); 38 static OfflineAudioContext* create(ExecutionContext*, unsigned numberOfChann els, size_t numberOfFrames, float sampleRate, ExceptionState&);
39 39
40 virtual ~OfflineAudioContext(); 40 virtual ~OfflineAudioContext();
41 41
42 // Check all the scheduled suspends if the context should suspend at
43 // currentTime(). Then post tasks to resolve promises on the main thread
44 // if necessary.
45 bool shouldSuspendNow();
46
47 // Clear suspensions marked as 'resolved' in the list.
48 void resolvePendingSuspendPromises();
49
50 // Fire completion event when the rendering is finished.
51 void fireCompletionEvent();
52
53 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
54
42 ScriptPromise startOfflineRendering(ScriptState*); 55 ScriptPromise startOfflineRendering(ScriptState*);
56 ScriptPromise suspendOfflineRendering(ScriptState*, double);
57 ScriptPromise resumeOfflineRendering(ScriptState*);
58
43 private: 59 private:
44 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate); 60 OfflineAudioContext(Document*, unsigned numberOfChannels, size_t numberOfFra mes, float sampleRate);
61
62 // A container class for a pair of time information and the suspend promise
63 // resolver.
64 class ScheduledSuspendContainer
65 : public NoBaseWillBeGarbageCollected<ScheduledSuspendContainer> {
66 public:
67 static PassOwnPtr<ScheduledSuspendContainer> create(size_t suspendFrame, PassRefPtrWillBeRawPtr<ScriptPromiseResolver>);
68 ~ScheduledSuspendContainer();
69 PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver() { return m_reso lver; }
70
71 // Query if the rendering should be suspended at |whenFrame|.
72 bool shouldSuspendAt(size_t whenFrame) const;
73
74 // Query if the suspend is pending for the promise resolution.
75 bool isPending() const;
76
77 // Mark the suspend as 'pending'.
Raymond Toy 2015/06/12 21:11:37 Describe better what pending means.
hongchan 2015/06/15 18:40:46 Done.
78 void markAsPending();
79
80 DECLARE_TRACE();
81
82 private:
83 ScheduledSuspendContainer(size_t suspendFrame, PassRefPtrWillBeRawPtr<Sc riptPromiseResolver>);
84
85 // Suspend time in samples.
86 size_t m_suspendFrame;
87
88 // Associated promise resolver.
89 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver;
90
91 // A pending marker for the safe batch removal.
92 bool m_isPending;
93 };
94
95 // Resolve pending suspend promises and removes it from the list.
96 void resolvePendingSuspendPromisesOnMainThread();
97
98 WillBeHeapVector<OwnPtrWillBeMember<ScheduledSuspendContainer>> m_scheduledS uspends;
99 RefPtrWillBeMember<ScriptPromiseResolver> m_completeResolver;
100
101 // This flag is necessary to indicate the rendering has actually started.
102 // Note that initial state of context is 'Suspended', which is the same
103 // state when the context is suspended.
104 bool m_isRenderingStarted;
105
106 // Total render sample length.
107 size_t m_totalRenderFrames;
45 }; 108 };
46 109
47 } // namespace blink 110 } // namespace blink
48 111
49 #endif // OfflineAudioContext_h 112 #endif // OfflineAudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698