OLD | NEW |
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 Loading... |
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. Containers with 'pending' flag will |
| 78 // be collectively resolved when the actual suspension happens. |
| 79 void markAsPending(); |
| 80 |
| 81 DECLARE_TRACE(); |
| 82 |
| 83 private: |
| 84 ScheduledSuspendContainer(size_t suspendFrame, PassRefPtrWillBeRawPtr<Sc
riptPromiseResolver>); |
| 85 |
| 86 // Suspend time in samples. |
| 87 size_t m_suspendFrame; |
| 88 |
| 89 // Associated promise resolver. |
| 90 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; |
| 91 |
| 92 // A pending marker for the safe batch removal. |
| 93 bool m_isPending; |
| 94 }; |
| 95 |
| 96 // Resolve pending suspend promises and removes it from the list. |
| 97 void resolvePendingSuspendPromisesOnMainThread(); |
| 98 |
| 99 WillBeHeapVector<OwnPtrWillBeMember<ScheduledSuspendContainer>> m_scheduledS
uspends; |
| 100 RefPtrWillBeMember<ScriptPromiseResolver> m_completeResolver; |
| 101 |
| 102 // This flag is necessary to indicate the rendering has actually started. |
| 103 // Note that initial state of context is 'Suspended', which is the same |
| 104 // state when the context is suspended. |
| 105 bool m_isRenderingStarted; |
| 106 |
| 107 // Total render sample length. |
| 108 size_t m_totalRenderFrames; |
45 }; | 109 }; |
46 | 110 |
47 } // namespace blink | 111 } // namespace blink |
48 | 112 |
49 #endif // OfflineAudioContext_h | 113 #endif // OfflineAudioContext_h |
OLD | NEW |