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