| 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 26 matching lines...) Expand all Loading... |
| 37 , m_currentSampleFrame(0) | 37 , m_currentSampleFrame(0) |
| 38 { | 38 { |
| 39 addInput(); | 39 addInput(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 AudioDestinationHandler::~AudioDestinationHandler() | 42 AudioDestinationHandler::~AudioDestinationHandler() |
| 43 { | 43 { |
| 44 ASSERT(!isInitialized()); | 44 ASSERT(!isInitialized()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void AudioDestinationHandler::render(AudioBus* sourceBus, AudioBus* destinationB
us, size_t numberOfFrames) | 47 void AudioDestinationHandler::render(AudioBus* sourceBus, AudioBus* destinationB
us, size_t framesToProcess) |
| 48 { | 48 { |
| 49 // We don't want denormals slowing down any of the audio processing | 49 // We don't want denormals slowing down any of the audio processing since |
| 50 // since they can very seriously hurt performance. | 50 // they can very seriously hurt performance. This will take care of all |
| 51 // This will take care of all AudioNodes because they all process within thi
s scope. | 51 // AudioNodes because they all process within this scope. |
| 52 DenormalDisabler denormalDisabler; | 52 DenormalDisabler denormalDisabler; |
| 53 | 53 |
| 54 // Need to check if the context actually alive. Otherwise the subsequent | 54 // Need to check if the context actually alive. Otherwise the subsequent |
| 55 // steps will fail. If the context is not alive somehow, return immediately | 55 // steps will fail. If the context is not alive somehow, return immediately |
| 56 // and do nothing. | 56 // and do nothing. |
| 57 // | 57 // |
| 58 // TODO(hongchan): because the context can go away while rendering, so this | 58 // TODO(hongchan): because the context can go away while rendering, so this |
| 59 // check cannot guarantee the safe execution of the following steps. | 59 // check cannot guarantee the safe execution of the following steps. |
| 60 ASSERT(context()); | 60 ASSERT(context()); |
| 61 if (!context()) | 61 if (!context()) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 context()->deferredTaskHandler().setAudioThreadToCurrentThread(); | 64 context()->deferredTaskHandler().setAudioThreadToCurrentThread(); |
| 65 | 65 |
| 66 // If the destination node is not initialized, pass the silence to the final | 66 // If the destination node is not initialized, pass the silence to the final |
| 67 // audio destination (one step before the FIFO). This check is for the case | 67 // audio destination (one step before the FIFO). This check is for the case |
| 68 // where the destination is in the middle of tearing down process. | 68 // where the destination is in the middle of tearing down process. |
| 69 if (!isInitialized()) { | 69 if (!isInitialized()) { |
| 70 destinationBus->zero(); | 70 destinationBus->zero(); |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Let the context take care of any business at the start of each render qua
ntum. | 74 // Let the context take care of any business at the start of each render |
| 75 // quantum. |
| 75 context()->handlePreRenderTasks(); | 76 context()->handlePreRenderTasks(); |
| 76 | 77 |
| 77 // Prepare the local audio input provider for this render quantum. | 78 // Prepare the local audio input provider for this render quantum. |
| 78 if (sourceBus) | 79 if (sourceBus) |
| 79 m_localAudioInputProvider.set(sourceBus); | 80 m_localAudioInputProvider.setSourceBus(sourceBus); |
| 80 | 81 |
| 81 ASSERT(numberOfInputs() >= 1); | 82 ASSERT(numberOfInputs() >= 1); |
| 82 if (numberOfInputs() < 1) { | 83 if (numberOfInputs() < 1) { |
| 83 destinationBus->zero(); | 84 destinationBus->zero(); |
| 84 return; | 85 return; |
| 85 } | 86 } |
| 86 // This will cause the node(s) connected to us to process, which in turn wil
l pull on their input(s), | |
| 87 // all the way backwards through the rendering graph. | |
| 88 AudioBus* renderedBus = input(0).pull(destinationBus, numberOfFrames); | |
| 89 | 87 |
| 88 // This will cause the node(s) connected to us to process, which in turn |
| 89 // will pull on their input(s), all the way backwards through the rendering |
| 90 // graph. |
| 91 AudioBus* renderedBus = input(0).pull(destinationBus, framesToProcess); |
| 92 |
| 93 // TODO(hongchan): this logic should be a part of AudioNodeInput::pull(). |
| 90 if (!renderedBus) { | 94 if (!renderedBus) { |
| 91 destinationBus->zero(); | 95 destinationBus->zero(); |
| 92 } else if (renderedBus != destinationBus) { | 96 } else if (renderedBus != destinationBus) { |
| 93 // in-place processing was not possible - so copy | 97 // If the destination node has multiple inputs, in-place processing is |
| 98 // not possible. Thus the explicit copy is necessary. |
| 94 destinationBus->copyFrom(*renderedBus); | 99 destinationBus->copyFrom(*renderedBus); |
| 95 } | 100 } |
| 96 | 101 |
| 97 // Process nodes which need a little extra help because they are not connect
ed to anything, but still need to process. | 102 // Process nodes which need a little extra help because they are not |
| 98 context()->deferredTaskHandler().processAutomaticPullNodes(numberOfFrames); | 103 // connected to anything, but still need to process. |
| 104 context()->deferredTaskHandler().processAutomaticPullNodes(framesToProcess); |
| 99 | 105 |
| 100 // Let the context take care of any business at the end of each render quant
um. | 106 // Let the context take care of any business at the end of each render |
| 107 // quantum. |
| 101 context()->handlePostRenderTasks(); | 108 context()->handlePostRenderTasks(); |
| 102 | 109 |
| 103 // Advance current sample-frame. | 110 // Advance current sample-frame. |
| 104 size_t newSampleFrame = m_currentSampleFrame + numberOfFrames; | 111 size_t newSampleFrame = m_currentSampleFrame + framesToProcess; |
| 105 releaseStore(&m_currentSampleFrame, newSampleFrame); | 112 releaseStore(&m_currentSampleFrame, newSampleFrame); |
| 106 } | 113 } |
| 107 | 114 |
| 108 // ---------------------------------------------------------------- | 115 // ---------------------------------------------------------------- |
| 109 | 116 |
| 110 AudioDestinationNode::AudioDestinationNode(AbstractAudioContext& context) | 117 AudioDestinationNode::AudioDestinationNode(AbstractAudioContext& context) |
| 111 : AudioNode(context) | 118 : AudioNode(context) |
| 112 { | 119 { |
| 113 } | 120 } |
| 114 | 121 |
| 115 AudioDestinationHandler& AudioDestinationNode::audioDestinationHandler() const | 122 AudioDestinationHandler& AudioDestinationNode::audioDestinationHandler() const |
| 116 { | 123 { |
| 117 return static_cast<AudioDestinationHandler&>(handler()); | 124 return static_cast<AudioDestinationHandler&>(handler()); |
| 118 } | 125 } |
| 119 | 126 |
| 120 unsigned long AudioDestinationNode::maxChannelCount() const | 127 unsigned long AudioDestinationNode::maxChannelCount() const |
| 121 { | 128 { |
| 122 return audioDestinationHandler().maxChannelCount(); | 129 return audioDestinationHandler().maxChannelCount(); |
| 123 } | 130 } |
| 124 | 131 |
| 125 } // namespace blink | 132 } // namespace blink |
| 126 | 133 |
| OLD | NEW |