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

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

Issue 385953003: Revert of WebAudio: Remove AudioNode::RefType. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/webaudio/AudioNode.h ('k') | Source/modules/webaudio/AudioNodeInput.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 , m_nodeType(NodeTypeUnknown) 48 , m_nodeType(NodeTypeUnknown)
49 , m_context(context) 49 , m_context(context)
50 , m_sampleRate(sampleRate) 50 , m_sampleRate(sampleRate)
51 #if ENABLE(OILPAN) 51 #if ENABLE(OILPAN)
52 , m_keepAlive(adoptPtr(new Persistent<AudioNode>(this))) 52 , m_keepAlive(adoptPtr(new Persistent<AudioNode>(this)))
53 #endif 53 #endif
54 , m_lastProcessingTime(-1) 54 , m_lastProcessingTime(-1)
55 , m_lastNonSilentTime(-1) 55 , m_lastNonSilentTime(-1)
56 , m_normalRefCount(1) // start out with normal refCount == 1 (like WTF::RefC ounted class) 56 , m_normalRefCount(1) // start out with normal refCount == 1 (like WTF::RefC ounted class)
57 , m_connectionRefCount(0) 57 , m_connectionRefCount(0)
58 , m_wasDisconnected(false)
59 , m_isMarkedForDeletion(false) 58 , m_isMarkedForDeletion(false)
60 , m_isDisabled(false) 59 , m_isDisabled(false)
61 , m_channelCount(2) 60 , m_channelCount(2)
62 , m_channelCountMode(Max) 61 , m_channelCountMode(Max)
63 , m_channelInterpretation(AudioBus::Speakers) 62 , m_channelInterpretation(AudioBus::Speakers)
64 { 63 {
65 ScriptWrappable::init(this); 64 ScriptWrappable::init(this);
66 #if DEBUG_AUDIONODE_REFERENCES 65 #if DEBUG_AUDIONODE_REFERENCES
67 if (!s_isNodeCountInitialized) { 66 if (!s_isNodeCountInitialized) {
68 s_isNodeCountInitialized = true; 67 s_isNodeCountInitialized = true;
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // a tailTime attribute. Then the AudioNode only needs to remain "active " for tailTime seconds after there are no 462 // a tailTime attribute. Then the AudioNode only needs to remain "active " for tailTime seconds after there are no
464 // longer any active connections. 463 // longer any active connections.
465 if (nodeType() != NodeTypeConvolver && nodeType() != NodeTypeDelay) { 464 if (nodeType() != NodeTypeConvolver && nodeType() != NodeTypeDelay) {
466 m_isDisabled = true; 465 m_isDisabled = true;
467 for (unsigned i = 0; i < m_outputs.size(); ++i) 466 for (unsigned i = 0; i < m_outputs.size(); ++i)
468 output(i)->disable(); 467 output(i)->disable();
469 } 468 }
470 } 469 }
471 } 470 }
472 471
473 void AudioNode::ref() 472 void AudioNode::ref(RefType refType)
474 { 473 {
475 #if ENABLE(OILPAN) 474 #if ENABLE(OILPAN)
476 ASSERT(m_keepAlive); 475 ASSERT(m_keepAlive);
477 #endif 476 #endif
478 atomicIncrement(&m_normalRefCount); 477 switch (refType) {
478 case RefTypeNormal:
479 atomicIncrement(&m_normalRefCount);
480 break;
481 case RefTypeConnection:
482 atomicIncrement(&m_connectionRefCount);
483 break;
484 default:
485 ASSERT_NOT_REACHED();
486 }
479 487
480 #if DEBUG_AUDIONODE_REFERENCES 488 #if DEBUG_AUDIONODE_REFERENCES
481 fprintf(stderr, "%p: %d: AudioNode::ref() %d %d\n", this, nodeType(), m_norm alRefCount, m_connectionRefCount); 489 fprintf(stderr, "%p: %d: AudioNode::ref(%d) %d %d\n", this, nodeType(), refT ype, m_normalRefCount, m_connectionRefCount);
482 #endif 490 #endif
491
492 // See the disabling code in finishDeref() below. This handles the case wher e a node
493 // is being re-connected after being used at least once and disconnected.
494 // In this case, we need to re-enable.
495 if (refType == RefTypeConnection)
496 enableOutputsIfNecessary();
483 } 497 }
484 498
485 void AudioNode::makeConnection() 499 void AudioNode::deref(RefType refType)
486 {
487 atomicIncrement(&m_connectionRefCount);
488 // See the disabling code in finishDeref() below. This handles the case
489 // where a node is being re-connected after being used at least once and
490 // disconnected. In this case, we need to re-enable.
491 enableOutputsIfNecessary();
492 }
493
494 void AudioNode::deref()
495 { 500 {
496 // The actually work for deref happens completely within the audio context's graph lock. 501 // The actually work for deref happens completely within the audio context's graph lock.
497 // In the case of the audio thread, we must use a tryLock to avoid glitches. 502 // In the case of the audio thread, we must use a tryLock to avoid glitches.
498 bool hasLock = false; 503 bool hasLock = false;
499 bool mustReleaseLock = false; 504 bool mustReleaseLock = false;
500 505
501 if (context()->isAudioThread()) { 506 if (context()->isAudioThread()) {
502 // Real-time audio thread must not contend lock (to avoid glitches). 507 // Real-time audio thread must not contend lock (to avoid glitches).
503 hasLock = context()->tryLock(mustReleaseLock); 508 hasLock = context()->tryLock(mustReleaseLock);
504 } else { 509 } else {
505 context()->lock(mustReleaseLock); 510 context()->lock(mustReleaseLock);
506 hasLock = true; 511 hasLock = true;
507 } 512 }
508 513
509 if (hasLock) { 514 if (hasLock) {
510 // This is where the real deref work happens. 515 // This is where the real deref work happens.
511 finishDeref(); 516 finishDeref(refType);
512 517
513 if (mustReleaseLock) 518 if (mustReleaseLock)
514 context()->unlock(); 519 context()->unlock();
515 } else { 520 } else {
516 // We were unable to get the lock, so put this in a list to finish up la ter. 521 // We were unable to get the lock, so put this in a list to finish up la ter.
517 ASSERT(context()->isAudioThread()); 522 ASSERT(context()->isAudioThread());
523 ASSERT(refType == RefTypeConnection);
518 context()->addDeferredFinishDeref(this); 524 context()->addDeferredFinishDeref(this);
519 } 525 }
520 526
521 // Once AudioContext::uninitialize() is called there's no more chances for d eleteMarkedNodes() to get called, so we call here. 527 // Once AudioContext::uninitialize() is called there's no more chances for d eleteMarkedNodes() to get called, so we call here.
522 // We can't call in AudioContext::~AudioContext() since it will never be cal led as long as any AudioNode is alive 528 // We can't call in AudioContext::~AudioContext() since it will never be cal led as long as any AudioNode is alive
523 // because AudioNodes keep a reference to the context. 529 // because AudioNodes keep a reference to the context.
524 if (!context()->isInitialized()) 530 if (!context()->isInitialized())
525 context()->deleteMarkedNodes(); 531 context()->deleteMarkedNodes();
526 } 532 }
527 533
528 void AudioNode::breakConnection() 534 void AudioNode::finishDeref(RefType refType)
529 {
530 ASSERT(m_normalRefCount > 0);
531 atomicDecrement(&m_connectionRefCount);
532 m_wasDisconnected = true;
533 }
534
535 void AudioNode::finishDeref()
536 { 535 {
537 ASSERT(context()->isGraphOwner()); 536 ASSERT(context()->isGraphOwner());
538 537
539 ASSERT(m_normalRefCount > 0); 538 switch (refType) {
540 atomicDecrement(&m_normalRefCount); 539 case RefTypeNormal:
540 ASSERT(m_normalRefCount > 0);
541 atomicDecrement(&m_normalRefCount);
542 break;
543 case RefTypeConnection:
544 ASSERT(m_connectionRefCount > 0);
545 atomicDecrement(&m_connectionRefCount);
546 break;
547 default:
548 ASSERT_NOT_REACHED();
549 }
541 550
542 #if DEBUG_AUDIONODE_REFERENCES 551 #if DEBUG_AUDIONODE_REFERENCES
543 fprintf(stderr, "%p: %d: AudioNode::deref() %d %d\n", this, nodeType(), m_no rmalRefCount, m_connectionRefCount); 552 fprintf(stderr, "%p: %d: AudioNode::deref(%d) %d %d\n", this, nodeType(), re fType, m_normalRefCount, m_connectionRefCount);
544 #endif 553 #endif
545 554
546 if (m_wasDisconnected) { 555 if (!m_connectionRefCount) {
547 if (m_connectionRefCount == 0 && m_normalRefCount > 0) 556 if (!m_normalRefCount) {
557 if (!m_isMarkedForDeletion) {
558 // All references are gone - we need to go away.
559 for (unsigned i = 0; i < m_outputs.size(); ++i)
560 output(i)->disconnectAll(); // This will deref() nodes we're connected to.
561
562 // Mark for deletion at end of each render quantum or when conte xt shuts down.
563 context()->markForDeletion(this);
564 m_isMarkedForDeletion = true;
565 }
566 } else if (refType == RefTypeConnection)
548 disableOutputsIfNecessary(); 567 disableOutputsIfNecessary();
549 m_wasDisconnected = false;
550 }
551
552 if (!m_normalRefCount && !m_isMarkedForDeletion) {
553 // All references are gone - we need to go away.
554 for (unsigned i = 0; i < m_outputs.size(); ++i)
555 output(i)->disconnectAll(); // This will deref() nodes we're connect ed to.
556
557 // Mark for deletion at end of each render quantum or when context shuts
558 // down.
559 context()->markForDeletion(this);
560 m_isMarkedForDeletion = true;
561 } 568 }
562 } 569 }
563 570
564 #if DEBUG_AUDIONODE_REFERENCES 571 #if DEBUG_AUDIONODE_REFERENCES
565 572
566 bool AudioNode::s_isNodeCountInitialized = false; 573 bool AudioNode::s_isNodeCountInitialized = false;
567 int AudioNode::s_nodeCount[NodeTypeEnd]; 574 int AudioNode::s_nodeCount[NodeTypeEnd];
568 575
569 void AudioNode::printNodeCounts() 576 void AudioNode::printNodeCounts()
570 { 577 {
(...skipping 25 matching lines...) Expand all
596 // it cannot be reattached. Therefore, the reference count 603 // it cannot be reattached. Therefore, the reference count
597 // will not go above zero again. 604 // will not go above zero again.
598 ASSERT(m_keepAlive); 605 ASSERT(m_keepAlive);
599 m_keepAlive = nullptr; 606 m_keepAlive = nullptr;
600 } 607 }
601 #endif 608 #endif
602 609
603 } // namespace WebCore 610 } // namespace WebCore
604 611
605 #endif // ENABLE(WEB_AUDIO) 612 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AudioNode.h ('k') | Source/modules/webaudio/AudioNodeInput.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698