AudioBasicInspectorNode.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2012, Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  17. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #include "config.h"
  25. #if ENABLE(WEB_AUDIO)
  26. #include "AudioBasicInspectorNode.h"
  27. #include "AudioContext.h"
  28. #include "AudioNodeInput.h"
  29. #include "AudioNodeOutput.h"
  30. namespace WebCore {
  31. AudioBasicInspectorNode::AudioBasicInspectorNode(AudioContext* context, float sampleRate, unsigned outputChannelCount)
  32. : AudioNode(context, sampleRate)
  33. , m_needAutomaticPull(false)
  34. {
  35. addInput(adoptPtr(new AudioNodeInput(this)));
  36. addOutput(adoptPtr(new AudioNodeOutput(this, outputChannelCount)));
  37. }
  38. // We override pullInputs() as an optimization allowing this node to take advantage of in-place processing,
  39. // where the input is simply passed through unprocessed to the output.
  40. // Note: this only applies if the input and output channel counts match.
  41. void AudioBasicInspectorNode::pullInputs(size_t framesToProcess)
  42. {
  43. // Render input stream - try to render directly into output bus for pass-through processing where process() doesn't need to do anything...
  44. input(0)->pull(output(0)->bus(), framesToProcess);
  45. }
  46. void AudioBasicInspectorNode::connect(AudioNode* destination, unsigned outputIndex, unsigned inputIndex, ExceptionCode& ec)
  47. {
  48. ASSERT(isMainThread());
  49. AudioContext::AutoLocker locker(context());
  50. AudioNode::connect(destination, outputIndex, inputIndex, ec);
  51. updatePullStatus();
  52. }
  53. void AudioBasicInspectorNode::disconnect(unsigned outputIndex, ExceptionCode& ec)
  54. {
  55. ASSERT(isMainThread());
  56. AudioContext::AutoLocker locker(context());
  57. AudioNode::disconnect(outputIndex, ec);
  58. updatePullStatus();
  59. }
  60. void AudioBasicInspectorNode::checkNumberOfChannelsForInput(AudioNodeInput* input)
  61. {
  62. ASSERT(context()->isAudioThread() && context()->isGraphOwner());
  63. ASSERT(input == this->input(0));
  64. if (input != this->input(0))
  65. return;
  66. unsigned numberOfChannels = input->numberOfChannels();
  67. if (numberOfChannels != output(0)->numberOfChannels()) {
  68. // This will propagate the channel count to any nodes connected further downstream in the graph.
  69. output(0)->setNumberOfChannels(numberOfChannels);
  70. }
  71. AudioNode::checkNumberOfChannelsForInput(input);
  72. updatePullStatus();
  73. }
  74. void AudioBasicInspectorNode::updatePullStatus()
  75. {
  76. ASSERT(context()->isGraphOwner());
  77. if (output(0)->isConnected()) {
  78. // When an AudioBasicInspectorNode is connected to a downstream node, it will get pulled by the
  79. // downstream node, thus remove it from the context's automatic pull list.
  80. if (m_needAutomaticPull) {
  81. context()->removeAutomaticPullNode(this);
  82. m_needAutomaticPull = false;
  83. }
  84. } else {
  85. unsigned numberOfInputConnections = input(0)->numberOfRenderingConnections();
  86. if (numberOfInputConnections && !m_needAutomaticPull) {
  87. // When an AudioBasicInspectorNode is not connected to any downstream node while still connected from
  88. // upstream node(s), add it to the context's automatic pull list.
  89. context()->addAutomaticPullNode(this);
  90. m_needAutomaticPull = true;
  91. } else if (!numberOfInputConnections && m_needAutomaticPull) {
  92. // The AudioBasicInspectorNode is connected to nothing, remove it from the context's automatic pull list.
  93. context()->removeAutomaticPullNode(this);
  94. m_needAutomaticPull = false;
  95. }
  96. }
  97. }
  98. } // namespace WebCore
  99. #endif // ENABLE(WEB_AUDIO)