Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 ASSERT(isMainThread()); | |
|
hongchan
2016/05/13 01:20:13
DCHECK.
Raymond Toy
2016/05/20 23:12:01
Done.
| |
| 267 | |
| 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 ASSERT(isMainThread()); | |
|
hongchan
2016/05/13 01:20:13
Ditto.
Raymond Toy
2016/05/20 23:12:01
Done.
| |
| 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 ASSERT(isMainThread()); | |
|
hongchan
2016/05/13 01:20:13
Ditto.
Raymond Toy
2016/05/20 23:12:01
Done.
| |
| 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 ASSERT(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.") ; | |
|
hongchan
2016/05/13 01:20:13
input channels and output channels => input and ou
Raymond Toy
2016/05/13 16:36:01
I chose this originally to kind of match the text
| |
| 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 | |
|
hongchan
2016/05/13 01:20:13
In the change above, we have few "80-col" issues.
| |
| 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); |
|
hongchan
2016/05/13 01:20:13
Let's wrap arguments.
| |
| 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 |
|
hongchan
2016/05/13 01:20:13
If we move this comment above |if (node)| Then we
hongchan
2016/05/20 21:28:32
Perhaps it needs one more look here?
Raymond Toy
2016/05/20 21:46:09
I like the braces; moving the comment out just so
hongchan
2016/05/20 22:57:48
It goes both ways. Without braces, we can easily t
| |
| 356 context.notifySourceNodeStartedProcessing(node); | |
| 357 } | |
| 286 | 358 |
| 287 if (numberOfOutputChannels > AbstractAudioContext::maxNumberOfChannels()) | 359 return node; |
|
hongchan
2016/05/13 01:20:13
The same issue before - we should return node when
hongchan
2016/05/20 21:28:32
Is this addressed somewhere?
Raymond Toy
2016/05/20 21:46:09
If line 352 fails to create a ScriptProcessor, nod
hongchan
2016/05/20 22:57:48
But can we be explicit about that? We can easily r
| |
| 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 |
| OLD | NEW |