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

Side by Side Diff: Source/modules/webaudio/AudioContext.cpp

Issue 1140723003: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Promise Resolution Created 5 years, 7 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) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 93
94 AudioContext* audioContext = new AudioContext(&document); 94 AudioContext* audioContext = new AudioContext(&document);
95 audioContext->suspendIfNeeded(); 95 audioContext->suspendIfNeeded();
96 return audioContext; 96 return audioContext;
97 } 97 }
98 98
99 // Constructor for rendering to the audio hardware. 99 // Constructor for rendering to the audio hardware.
100 AudioContext::AudioContext(Document* document) 100 AudioContext::AudioContext(Document* document)
101 : ActiveDOMObject(document) 101 : ActiveDOMObject(document)
102 , m_destinationNode(nullptr)
103 , m_didInitializeContextGraphMutex(false)
104 , m_contextState(Suspended)
102 , m_isStopScheduled(false) 105 , m_isStopScheduled(false)
103 , m_isCleared(false) 106 , m_isCleared(false)
104 , m_isInitialized(false) 107 , m_isInitialized(false)
105 , m_destinationNode(nullptr)
106 , m_isResolvingResumePromises(false) 108 , m_isResolvingResumePromises(false)
107 , m_connectionCount(0) 109 , m_connectionCount(0)
108 , m_didInitializeContextGraphMutex(false)
109 , m_deferredTaskHandler(DeferredTaskHandler::create()) 110 , m_deferredTaskHandler(DeferredTaskHandler::create())
110 , m_isOfflineContext(false) 111 , m_isOfflineContext(false)
111 , m_contextState(Suspended)
112 , m_cachedSampleFrame(0) 112 , m_cachedSampleFrame(0)
113 { 113 {
114 m_didInitializeContextGraphMutex = true; 114 m_didInitializeContextGraphMutex = true;
115 m_destinationNode = DefaultAudioDestinationNode::create(this); 115 m_destinationNode = DefaultAudioDestinationNode::create(this);
116 116
117 initialize(); 117 initialize();
118 } 118 }
119 119
120 // Constructor for offline (non-realtime) rendering. 120 // Constructor for offline (non-realtime) rendering.
121 AudioContext::AudioContext(Document* document, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate) 121 AudioContext::AudioContext(Document* document, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate)
122 : ActiveDOMObject(document) 122 : ActiveDOMObject(document)
123 , m_destinationNode(nullptr)
124 , m_didInitializeContextGraphMutex(false)
125 , m_contextState(Suspended)
123 , m_isStopScheduled(false) 126 , m_isStopScheduled(false)
124 , m_isCleared(false) 127 , m_isCleared(false)
125 , m_isInitialized(false) 128 , m_isInitialized(false)
126 , m_destinationNode(nullptr)
127 , m_isResolvingResumePromises(false) 129 , m_isResolvingResumePromises(false)
128 , m_connectionCount(0) 130 , m_connectionCount(0)
129 , m_didInitializeContextGraphMutex(false)
130 , m_deferredTaskHandler(DeferredTaskHandler::create()) 131 , m_deferredTaskHandler(DeferredTaskHandler::create())
131 , m_isOfflineContext(true) 132 , m_isOfflineContext(true)
132 , m_contextState(Suspended)
133 , m_cachedSampleFrame(0) 133 , m_cachedSampleFrame(0)
134 { 134 {
135 m_didInitializeContextGraphMutex = true; 135 m_didInitializeContextGraphMutex = true;
136
136 // Create a new destination for offline rendering. 137 // Create a new destination for offline rendering.
137 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate); 138 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate);
138 if (m_renderTarget.get()) 139 if (m_renderTarget.get())
139 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get()); 140 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get());
140 141
141 initialize(); 142 initialize();
142 } 143 }
143 144
144 AudioContext::~AudioContext() 145 AudioContext::~AudioContext()
145 { 146 {
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 } 730 }
730 731
731 if (newState == m_contextState) { 732 if (newState == m_contextState) {
732 // ASSERTs above failed; just return. 733 // ASSERTs above failed; just return.
733 return; 734 return;
734 } 735 }
735 736
736 m_contextState = newState; 737 m_contextState = newState;
737 738
738 // Notify context that state changed 739 // Notify context that state changed
739 if (executionContext()) 740 if (executionContext()) {
740 executionContext()->postTask(FROM_HERE, createSameThreadTask(&AudioConte xt::notifyStateChange, this)); 741 executionContext()->postTask(FROM_HERE,
742 createSameThreadTask(&AudioContext::notifyStateChange, this));
743 }
741 } 744 }
742 745
743 void AudioContext::notifyStateChange() 746 void AudioContext::notifyStateChange()
744 { 747 {
745 dispatchEvent(Event::create(EventTypeNames::statechange)); 748 dispatchEvent(Event::create(EventTypeNames::statechange));
746 } 749 }
747 750
748 ScriptPromise AudioContext::suspendContext(ScriptState* scriptState) 751 ScriptPromise AudioContext::suspendContext(ScriptState* scriptState)
749 { 752 {
750 ASSERT(isMainThread()); 753 ASSERT(isMainThread());
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 ASSERT(m_destinationNode); 985 ASSERT(m_destinationNode);
983 ASSERT(!isOfflineContext()); 986 ASSERT(!isOfflineContext());
984 987
985 if (m_contextState == Running) { 988 if (m_contextState == Running) {
986 destination()->audioDestinationHandler().stopRendering(); 989 destination()->audioDestinationHandler().stopRendering();
987 setContextState(Suspended); 990 setContextState(Suspended);
988 deferredTaskHandler().clearHandlersToBeDeleted(); 991 deferredTaskHandler().clearHandlersToBeDeleted();
989 } 992 }
990 } 993 }
991 994
995 void AudioContext::fireSuspendEvent()
996 {
997 ASSERT(isMainThread());
998 if (!isMainThread())
999 return;
1000
1001 // AudioBuffer* renderedBuffer = m_renderTarget.get();
1002
1003 // setContextState(Suspended);
1004
1005 // ASSERT(renderedBuffer);
1006 // if (!renderedBuffer)
1007 // return;
1008
1009 // Avoid firing the event if the document has already gone away.
1010 // if (executionContext()) {
1011 // dispatchEvent(Event::create(EventTypeNames::statechange));
1012 // // m_offlineResolver->resolve(renderedBuffer);
1013 // }
1014 }
1015
992 void AudioContext::fireCompletionEvent() 1016 void AudioContext::fireCompletionEvent()
993 { 1017 {
994 ASSERT(isMainThread()); 1018 ASSERT(isMainThread());
995 if (!isMainThread()) 1019 if (!isMainThread())
996 return; 1020 return;
997 1021
998 AudioBuffer* renderedBuffer = m_renderTarget.get(); 1022 AudioBuffer* renderedBuffer = m_renderTarget.get();
999 1023
1000 // For an offline context, we set the state to closed here so that the oncom plete handler sees 1024 // For an offline context, we set the state to closed here so that the oncom plete handler sees
1001 // that the context has been closed. 1025 // that the context has been closed.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1087
1064 // Stop the audio context. This will stop the destination node from pulling audio anymore. And 1088 // Stop the audio context. This will stop the destination node from pulling audio anymore. And
1065 // since we have disconnected the destination from the audio graph, and thus has no references, 1089 // since we have disconnected the destination from the audio graph, and thus has no references,
1066 // the destination node can GCed if JS has no references. stop() will also r esolve the Promise 1090 // the destination node can GCed if JS has no references. stop() will also r esolve the Promise
1067 // created here. 1091 // created here.
1068 stop(); 1092 stop();
1069 1093
1070 return promise; 1094 return promise;
1071 } 1095 }
1072 1096
1097 bool AudioContext::suspendIfNecessary()
1098 {
1099 ASSERT_WITH_MESSAGE(1, "suspendIfNecessary() only valid for offline audio co ntext");
1100 return false;
1101 }
1102
1073 } // namespace blink 1103 } // namespace blink
1074 1104
1075 #endif // ENABLE(WEB_AUDIO) 1105 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698