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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.cpp

Issue 1865583002: Implement BaseAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 return nullptr; 47 return nullptr;
48 } 48 }
49 49
50 Document* document = toDocument(context); 50 Document* document = toDocument(context);
51 51
52 if (!numberOfFrames) { 52 if (!numberOfFrames) {
53 exceptionState.throwDOMException(SyntaxError, "number of frames cannot b e zero."); 53 exceptionState.throwDOMException(SyntaxError, "number of frames cannot b e zero.");
54 return nullptr; 54 return nullptr;
55 } 55 }
56 56
57 if (numberOfChannels > AbstractAudioContext::maxNumberOfChannels()) { 57 if (numberOfChannels > BaseAudioContext::maxNumberOfChannels()) {
58 exceptionState.throwDOMException( 58 exceptionState.throwDOMException(
59 IndexSizeError, 59 IndexSizeError,
60 ExceptionMessages::indexOutsideRange<unsigned>( 60 ExceptionMessages::indexOutsideRange<unsigned>(
61 "number of channels", 61 "number of channels",
62 numberOfChannels, 62 numberOfChannels,
63 0, 63 0,
64 ExceptionMessages::InclusiveBound, 64 ExceptionMessages::InclusiveBound,
65 AbstractAudioContext::maxNumberOfChannels(), 65 BaseAudioContext::maxNumberOfChannels(),
66 ExceptionMessages::InclusiveBound)); 66 ExceptionMessages::InclusiveBound));
67 return nullptr; 67 return nullptr;
68 } 68 }
69 69
70 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate)) { 70 if (!AudioUtilities::isValidAudioBufferSampleRate(sampleRate)) {
71 exceptionState.throwDOMException( 71 exceptionState.throwDOMException(
72 IndexSizeError, 72 IndexSizeError,
73 ExceptionMessages::indexOutsideRange( 73 ExceptionMessages::indexOutsideRange(
74 "sampleRate", sampleRate, 74 "sampleRate", sampleRate,
75 AudioUtilities::minAudioBufferSampleRate(), ExceptionMessages::I nclusiveBound, 75 AudioUtilities::minAudioBufferSampleRate(), ExceptionMessages::I nclusiveBound,
(...skipping 10 matching lines...) Expand all
86 + ", " + String::number(numberOfFrames) 86 + ", " + String::number(numberOfFrames)
87 + ", " + String::number(sampleRate) 87 + ", " + String::number(sampleRate)
88 + ")"); 88 + ")");
89 } 89 }
90 90
91 audioContext->suspendIfNeeded(); 91 audioContext->suspendIfNeeded();
92 return audioContext; 92 return audioContext;
93 } 93 }
94 94
95 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh annels, size_t numberOfFrames, float sampleRate, ExceptionState& exceptionState) 95 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh annels, size_t numberOfFrames, float sampleRate, ExceptionState& exceptionState)
96 : AbstractAudioContext(document, numberOfChannels, numberOfFrames, sampleRat e) 96 : BaseAudioContext(document, numberOfChannels, numberOfFrames, sampleRate)
97 , m_isRenderingStarted(false) 97 , m_isRenderingStarted(false)
98 , m_totalRenderFrames(numberOfFrames) 98 , m_totalRenderFrames(numberOfFrames)
99 { 99 {
100 // Create a new destination for offline rendering. 100 // Create a new destination for offline rendering.
101 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate); 101 m_renderTarget = AudioBuffer::create(numberOfChannels, numberOfFrames, sampl eRate);
102 102
103 // Throw an exception if the render target is not ready. 103 // Throw an exception if the render target is not ready.
104 if (m_renderTarget) { 104 if (m_renderTarget) {
105 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get()); 105 m_destinationNode = OfflineAudioDestinationNode::create(this, m_renderTa rget.get());
106 } else { 106 } else {
(...skipping 10 matching lines...) Expand all
117 117
118 OfflineAudioContext::~OfflineAudioContext() 118 OfflineAudioContext::~OfflineAudioContext()
119 { 119 {
120 } 120 }
121 121
122 DEFINE_TRACE(OfflineAudioContext) 122 DEFINE_TRACE(OfflineAudioContext)
123 { 123 {
124 visitor->trace(m_renderTarget); 124 visitor->trace(m_renderTarget);
125 visitor->trace(m_completeResolver); 125 visitor->trace(m_completeResolver);
126 visitor->trace(m_scheduledSuspends); 126 visitor->trace(m_scheduledSuspends);
127 AbstractAudioContext::trace(visitor); 127 BaseAudioContext::trace(visitor);
128 } 128 }
129 129
130 ScriptPromise OfflineAudioContext::startOfflineRendering(ScriptState* scriptStat e) 130 ScriptPromise OfflineAudioContext::startOfflineRendering(ScriptState* scriptStat e)
131 { 131 {
132 ASSERT(isMainThread()); 132 ASSERT(isMainThread());
133 133
134 // Calling close() on an OfflineAudioContext is not supported/allowed, 134 // Calling close() on an OfflineAudioContext is not supported/allowed,
135 // but it might well have been stopped by its execution context. 135 // but it might well have been stopped by its execution context.
136 // 136 //
137 // See: crbug.com/435867 137 // See: crbug.com/435867
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return ScriptPromise::rejectWithDOMException( 178 return ScriptPromise::rejectWithDOMException(
179 scriptState, 179 scriptState,
180 DOMException::create( 180 DOMException::create(
181 InvalidAccessError, 181 InvalidAccessError,
182 "cannot close an OfflineAudioContext.")); 182 "cannot close an OfflineAudioContext."));
183 } 183 }
184 184
185 ScriptPromise OfflineAudioContext::suspendContext(ScriptState* scriptState) 185 ScriptPromise OfflineAudioContext::suspendContext(ScriptState* scriptState)
186 { 186 {
187 // This CANNOT be called on OfflineAudioContext; this is only to implement 187 // This CANNOT be called on OfflineAudioContext; this is only to implement
188 // the pure virtual interface from AbstractAudioContext. 188 // the pure virtual interface from BaseAudioContext.
189 RELEASE_NOTREACHED(); 189 RELEASE_NOTREACHED();
190 190
191 return ScriptPromise(); 191 return ScriptPromise();
192 } 192 }
193 193
194 ScriptPromise OfflineAudioContext::suspendContext(ScriptState* scriptState, doub le when) 194 ScriptPromise OfflineAudioContext::suspendContext(ScriptState* scriptState, doub le when)
195 { 195 {
196 ASSERT(isMainThread()); 196 ASSERT(isMainThread());
197 197
198 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 198 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Note that the GraphLock is required before this check. Since this needs 389 // Note that the GraphLock is required before this check. Since this needs
390 // to run on the audio thread, OfflineGraphAutoLocker must be used. 390 // to run on the audio thread, OfflineGraphAutoLocker must be used.
391 if (m_scheduledSuspends.contains(currentSampleFrame())) 391 if (m_scheduledSuspends.contains(currentSampleFrame()))
392 return true; 392 return true;
393 393
394 return false; 394 return false;
395 } 395 }
396 396
397 } // namespace blink 397 } // namespace blink
398 398
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698