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

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

Issue 1952793002: Move the exception logic to the AudioNode creator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address some review comments Created 4 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 size_t bufferSize = 1 << static_cast<unsigned>(log2(4 * hardwareBufferSize) + 0.5); 252 size_t bufferSize = 1 << static_cast<unsigned>(log2(4 * hardwareBufferSize) + 0.5);
253 253
254 if (bufferSize < 256) 254 if (bufferSize < 256)
255 return 256; 255 return 256;
256 if (bufferSize > 16384) 256 if (bufferSize > 16384)
257 return 16384; 257 return 16384;
258 258
259 return bufferSize; 259 return bufferSize;
260 } 260 }
261 261
262 ScriptProcessorNode* ScriptProcessorNode::create(AbstractAudioContext& context, float sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned nu mberOfOutputChannels) 262 ScriptProcessorNode* ScriptProcessorNode::create(
263 AbstractAudioContext& context,
264 ExceptionState& exceptionState)
263 { 265 {
266 DCHECK(isMainThread());
267
hongchan 2016/05/13 21:35:48 Let's add a comment here. In fact, I think we shou
Raymond Toy 2016/05/16 23:11:53 Done.
268 return create(context, 0, 2, 2, exceptionState);
269 }
270
271 ScriptProcessorNode* ScriptProcessorNode::create(
272 AbstractAudioContext& context,
273 size_t bufferSize,
274 ExceptionState& exceptionState)
275 {
276 DCHECK(isMainThread());
277
278 return create(context, bufferSize, 2, 2, exceptionState);
279 }
280
281 ScriptProcessorNode* ScriptProcessorNode::create(
282 AbstractAudioContext& context,
283 size_t bufferSize,
284 unsigned numberOfInputChannels,
285 ExceptionState& exceptionState)
286 {
287 DCHECK(isMainThread());
288
289 return create(context, bufferSize, numberOfInputChannels, 2, exceptionState) ;
290 }
291
292 ScriptProcessorNode* ScriptProcessorNode::create(
293 AbstractAudioContext& context,
294 size_t bufferSize,
295 unsigned numberOfInputChannels,
296 unsigned numberOfOutputChannels,
297 ExceptionState& exceptionState)
298 {
299 DCHECK(isMainThread());
300
301 if (context.isContextClosed()) {
302 context.throwExceptionForClosedState(exceptionState);
303 return nullptr;
304 }
305
306 if (numberOfInputChannels == 0 && numberOfOutputChannels == 0) {
307 exceptionState.throwDOMException(
308 IndexSizeError,
309 "number of input channels and output channels cannot both be zero.") ;
310 return nullptr;
311 }
312
313 if (numberOfInputChannels > AbstractAudioContext::maxNumberOfChannels()) {
314 exceptionState.throwDOMException(
315 IndexSizeError,
316 "number of input channels (" + String::number(numberOfInputChannels)
317 + ") exceeds maximum ("
318 + String::number(AbstractAudioContext::maxNumberOfChannels()) + ")." );
319 return nullptr;
320 }
321
322 if (numberOfOutputChannels > AbstractAudioContext::maxNumberOfChannels()) {
323 exceptionState.throwDOMException(
324 IndexSizeError,
325 "number of output channels (" + String::number(numberOfInputChannels )
326 + ") exceeds maximum ("
327 + String::number(AbstractAudioContext::maxNumberOfChannels()) + ")." );
328 return nullptr;
329 }
330
264 // Check for valid buffer size. 331 // Check for valid buffer size.
265 switch (bufferSize) { 332 switch (bufferSize) {
266 case 0: 333 case 0:
267 bufferSize = chooseBufferSize(); 334 bufferSize = chooseBufferSize();
268 break; 335 break;
269 case 256: 336 case 256:
270 case 512: 337 case 512:
271 case 1024: 338 case 1024:
272 case 2048: 339 case 2048:
273 case 4096: 340 case 4096:
274 case 8192: 341 case 8192:
275 case 16384: 342 case 16384:
276 break; 343 break;
277 default: 344 default:
345 exceptionState.throwDOMException(
346 IndexSizeError,
347 "buffer size (" + String::number(bufferSize)
348 + ") must be 0 or a power of two between 256 and 16384.");
278 return nullptr; 349 return nullptr;
279 } 350 }
280 351
281 if (!numberOfInputChannels && !numberOfOutputChannels) 352 ScriptProcessorNode* node = new ScriptProcessorNode(context, context.sample Rate(), bufferSize, numberOfInputChannels, numberOfOutputChannels);
282 return nullptr;
283 353
284 if (numberOfInputChannels > AbstractAudioContext::maxNumberOfChannels()) 354 if (node) {
285 return nullptr; 355 // context keeps reference until we stop making javascript rendering cal lbacks
356 context.notifySourceNodeStartedProcessing(node);
357 }
286 358
287 if (numberOfOutputChannels > AbstractAudioContext::maxNumberOfChannels()) 359 return node;
288 return nullptr;
289
290 return new ScriptProcessorNode(context, sampleRate, bufferSize, numberOfInpu tChannels, numberOfOutputChannels);
291 } 360 }
292 361
293 size_t ScriptProcessorNode::bufferSize() const 362 size_t ScriptProcessorNode::bufferSize() const
294 { 363 {
295 return static_cast<ScriptProcessorHandler&>(handler()).bufferSize(); 364 return static_cast<ScriptProcessorHandler&>(handler()).bufferSize();
296 } 365 }
297 366
298 bool ScriptProcessorNode::hasPendingActivity() const 367 bool ScriptProcessorNode::hasPendingActivity() const
299 { 368 {
300 // To prevent the node from leaking after the context is closed. 369 // To prevent the node from leaking after the context is closed.
301 if (context()->isContextClosed()) 370 if (context()->isContextClosed())
302 return false; 371 return false;
303 372
304 // If |onaudioprocess| event handler is defined, the node should not be 373 // If |onaudioprocess| event handler is defined, the node should not be
305 // GCed even if it is out of scope. 374 // GCed even if it is out of scope.
306 if (hasEventListeners(EventTypeNames::audioprocess)) 375 if (hasEventListeners(EventTypeNames::audioprocess))
307 return true; 376 return true;
308 377
309 return false; 378 return false;
310 } 379 }
311 380
312 } // namespace blink 381 } // namespace blink
313 382
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698