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

Side by Side Diff: Source/platform/audio/AudioDestination.cpp

Issue 100993004: Move chrome specific code from platform/audio/chromium to platform/audio (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed atreat review commets Created 7 years 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
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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 12 matching lines...) Expand all
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 30
31 #if ENABLE(WEB_AUDIO) 31 #if ENABLE(WEB_AUDIO)
32 32
33 #include "platform/audio/chromium/AudioDestinationChromium.h" 33 #include "platform/audio/AudioDestination.h"
34 34
35 #include "platform/audio/AudioFIFO.h" 35 #include "platform/audio/AudioFIFO.h"
36 #include "platform/audio/AudioPullFIFO.h" 36 #include "platform/audio/AudioPullFIFO.h"
37 #include "public/platform/Platform.h" 37 #include "public/platform/Platform.h"
38 38
39 namespace WebCore { 39 namespace WebCore {
40 40
41 // Buffer size at which the web audio engine will render. 41 // Buffer size at which the web audio engine will render.
42 const unsigned renderBufferSize = 128; 42 const unsigned renderBufferSize = 128;
43 43
44 // Size of the FIFO 44 // Size of the FIFO
45 const size_t fifoSize = 8192; 45 const size_t fifoSize = 8192;
46 46
47 // Factory method: Chromium-implementation 47 // Factory method: Chromium-implementation
48 PassOwnPtr<AudioDestination> AudioDestination::create(AudioIOCallback& callback, const String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfO utputChannels, float sampleRate) 48 PassOwnPtr<AudioDestination> AudioDestination::create(AudioIOCallback& callback, const String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfO utputChannels, float sampleRate)
49 { 49 {
50 return adoptPtr(new AudioDestinationChromium(callback, inputDeviceId, number OfInputChannels, numberOfOutputChannels, sampleRate)); 50 return adoptPtr(new AudioDestination(callback, inputDeviceId, numberOfInputC hannels, numberOfOutputChannels, sampleRate));
51 } 51 }
52 52
53 AudioDestinationChromium::AudioDestinationChromium(AudioIOCallback& callback, co nst String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutp utChannels, float sampleRate) 53 AudioDestination::AudioDestination(AudioIOCallback& callback, const String& inpu tDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutputChannels, floa t sampleRate)
54 : m_callback(callback) 54 : m_callback(callback)
55 , m_numberOfOutputChannels(numberOfOutputChannels) 55 , m_numberOfOutputChannels(numberOfOutputChannels)
56 , m_inputBus(AudioBus::create(numberOfInputChannels, renderBufferSize)) 56 , m_inputBus(AudioBus::create(numberOfInputChannels, renderBufferSize))
57 , m_renderBus(AudioBus::create(numberOfOutputChannels, renderBufferSize, fal se)) 57 , m_renderBus(AudioBus::create(numberOfOutputChannels, renderBufferSize, fal se))
58 , m_sampleRate(sampleRate) 58 , m_sampleRate(sampleRate)
59 , m_isPlaying(false) 59 , m_isPlaying(false)
60 { 60 {
61 // Use the optimal buffer size recommended by the audio backend. 61 // Use the optimal buffer size recommended by the audio backend.
62 m_callbackBufferSize = blink::Platform::current()->audioHardwareBufferSize() ; 62 m_callbackBufferSize = blink::Platform::current()->audioHardwareBufferSize() ;
63 63
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 // If the callback size does not match the render size, then we need to buff er some 98 // If the callback size does not match the render size, then we need to buff er some
99 // extra silence for the input. Otherwise, we can over-consume the input FIF O. 99 // extra silence for the input. Otherwise, we can over-consume the input FIF O.
100 if (m_callbackBufferSize != renderBufferSize) { 100 if (m_callbackBufferSize != renderBufferSize) {
101 // FIXME: handle multi-channel input and don't hard-code to stereo. 101 // FIXME: handle multi-channel input and don't hard-code to stereo.
102 RefPtr<AudioBus> silence = AudioBus::create(2, renderBufferSize); 102 RefPtr<AudioBus> silence = AudioBus::create(2, renderBufferSize);
103 m_inputFifo->push(silence.get()); 103 m_inputFifo->push(silence.get());
104 } 104 }
105 } 105 }
106 106
107 AudioDestinationChromium::~AudioDestinationChromium() 107 AudioDestination::~AudioDestination()
108 { 108 {
109 stop(); 109 stop();
110 } 110 }
111 111
112 void AudioDestinationChromium::start() 112 void AudioDestination::start()
113 { 113 {
114 if (!m_isPlaying && m_audioDevice) { 114 if (!m_isPlaying && m_audioDevice) {
115 m_audioDevice->start(); 115 m_audioDevice->start();
116 m_isPlaying = true; 116 m_isPlaying = true;
117 } 117 }
118 } 118 }
119 119
120 void AudioDestinationChromium::stop() 120 void AudioDestination::stop()
121 { 121 {
122 if (m_isPlaying && m_audioDevice) { 122 if (m_isPlaying && m_audioDevice) {
123 m_audioDevice->stop(); 123 m_audioDevice->stop();
124 m_isPlaying = false; 124 m_isPlaying = false;
125 } 125 }
126 } 126 }
127 127
128 float AudioDestination::hardwareSampleRate() 128 float AudioDestination::hardwareSampleRate()
129 { 129 {
130 return static_cast<float>(blink::Platform::current()->audioHardwareSampleRat e()); 130 return static_cast<float>(blink::Platform::current()->audioHardwareSampleRat e());
131 } 131 }
132 132
133 unsigned long AudioDestination::maxChannelCount() 133 unsigned long AudioDestination::maxChannelCount()
134 { 134 {
135 return static_cast<float>(blink::Platform::current()->audioHardwareOutputCha nnels()); 135 return static_cast<float>(blink::Platform::current()->audioHardwareOutputCha nnels());
136 } 136 }
137 137
138 void AudioDestinationChromium::render(const blink::WebVector<float*>& sourceData , const blink::WebVector<float*>& audioData, size_t numberOfFrames) 138 void AudioDestination::render(const blink::WebVector<float*>& sourceData, const blink::WebVector<float*>& audioData, size_t numberOfFrames)
139 { 139 {
140 bool isNumberOfChannelsGood = audioData.size() == m_numberOfOutputChannels; 140 bool isNumberOfChannelsGood = audioData.size() == m_numberOfOutputChannels;
141 if (!isNumberOfChannelsGood) { 141 if (!isNumberOfChannelsGood) {
142 ASSERT_NOT_REACHED(); 142 ASSERT_NOT_REACHED();
143 return; 143 return;
144 } 144 }
145 145
146 bool isBufferSizeGood = numberOfFrames == m_callbackBufferSize; 146 bool isBufferSizeGood = numberOfFrames == m_callbackBufferSize;
147 if (!isBufferSizeGood) { 147 if (!isBufferSizeGood) {
148 ASSERT_NOT_REACHED(); 148 ASSERT_NOT_REACHED();
149 return; 149 return;
150 } 150 }
151 151
152 // Buffer optional live input. 152 // Buffer optional live input.
153 if (sourceData.size() >= 2) { 153 if (sourceData.size() >= 2) {
154 // FIXME: handle multi-channel input and don't hard-code to stereo. 154 // FIXME: handle multi-channel input and don't hard-code to stereo.
155 RefPtr<AudioBus> wrapperBus = AudioBus::create(2, numberOfFrames, false) ; 155 RefPtr<AudioBus> wrapperBus = AudioBus::create(2, numberOfFrames, false) ;
156 wrapperBus->setChannelMemory(0, sourceData[0], numberOfFrames); 156 wrapperBus->setChannelMemory(0, sourceData[0], numberOfFrames);
157 wrapperBus->setChannelMemory(1, sourceData[1], numberOfFrames); 157 wrapperBus->setChannelMemory(1, sourceData[1], numberOfFrames);
158 m_inputFifo->push(wrapperBus.get()); 158 m_inputFifo->push(wrapperBus.get());
159 } 159 }
160 160
161 for (unsigned i = 0; i < m_numberOfOutputChannels; ++i) 161 for (unsigned i = 0; i < m_numberOfOutputChannels; ++i)
162 m_renderBus->setChannelMemory(i, audioData[i], numberOfFrames); 162 m_renderBus->setChannelMemory(i, audioData[i], numberOfFrames);
163 163
164 m_fifo->consume(m_renderBus.get(), numberOfFrames); 164 m_fifo->consume(m_renderBus.get(), numberOfFrames);
165 } 165 }
166 166
167 void AudioDestinationChromium::provideInput(AudioBus* bus, size_t framesToProces s) 167 void AudioDestination::provideInput(AudioBus* bus, size_t framesToProcess)
168 { 168 {
169 AudioBus* sourceBus = 0; 169 AudioBus* sourceBus = 0;
170 if (m_inputFifo->framesInFifo() >= framesToProcess) { 170 if (m_inputFifo->framesInFifo() >= framesToProcess) {
171 m_inputFifo->consume(m_inputBus.get(), framesToProcess); 171 m_inputFifo->consume(m_inputBus.get(), framesToProcess);
172 sourceBus = m_inputBus.get(); 172 sourceBus = m_inputBus.get();
173 } 173 }
174 174
175 m_callback.render(sourceBus, bus, framesToProcess); 175 m_callback.render(sourceBus, bus, framesToProcess);
176 } 176 }
177 177
178 } // namespace WebCore 178 } // namespace WebCore
179 179
180 #endif // ENABLE(WEB_AUDIO) 180 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/platform/audio/AudioDestination.h ('k') | Source/platform/audio/android/FFTFrameOpenMAXDLAndroid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698