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 * | 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 15 matching lines...) Expand all Loading... |
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 "platform/audio/AudioDestination.h" | 29 #include "platform/audio/AudioDestination.h" |
30 | 30 |
31 #include "platform/Histogram.h" | 31 #include "platform/Histogram.h" |
32 #include "platform/audio/AudioFIFO.h" | 32 #include "platform/audio/AudioFIFO.h" |
33 #include "platform/audio/AudioPullFIFO.h" | 33 #include "platform/audio/AudioPullFIFO.h" |
34 #include "public/platform/Platform.h" | 34 #include "public/platform/Platform.h" |
35 #include "public/platform/WebSecurityOrigin.h" | 35 #include "public/platform/WebSecurityOrigin.h" |
36 #include "wtf/PtrUtil.h" | |
37 #include <memory> | |
38 | 36 |
39 namespace blink { | 37 namespace blink { |
40 | 38 |
41 // Buffer size at which the web audio engine will render. | 39 // Buffer size at which the web audio engine will render. |
42 const unsigned renderBufferSize = 128; | 40 const unsigned renderBufferSize = 128; |
43 | 41 |
44 // Size of the FIFO | 42 // Size of the FIFO |
45 const size_t fifoSize = 8192; | 43 const size_t fifoSize = 8192; |
46 | 44 |
47 // Factory method: Chromium-implementation | 45 // Factory method: Chromium-implementation |
48 std::unique_ptr<AudioDestination> AudioDestination::create(AudioIOCallback& call
back, const String& inputDeviceId, unsigned numberOfInputChannels, unsigned numb
erOfOutputChannels, float sampleRate, const PassRefPtr<SecurityOrigin>& security
Origin) | 46 PassOwnPtr<AudioDestination> AudioDestination::create(AudioIOCallback& callback,
const String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfO
utputChannels, float sampleRate, const PassRefPtr<SecurityOrigin>& securityOrigi
n) |
49 { | 47 { |
50 return wrapUnique(new AudioDestination(callback, inputDeviceId, numberOfInpu
tChannels, numberOfOutputChannels, sampleRate, securityOrigin)); | 48 return adoptPtr(new AudioDestination(callback, inputDeviceId, numberOfInputC
hannels, numberOfOutputChannels, sampleRate, securityOrigin)); |
51 } | 49 } |
52 | 50 |
53 AudioDestination::AudioDestination(AudioIOCallback& callback, const String& inpu
tDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutputChannels, floa
t sampleRate, const PassRefPtr<SecurityOrigin>& securityOrigin) | 51 AudioDestination::AudioDestination(AudioIOCallback& callback, const String& inpu
tDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutputChannels, floa
t sampleRate, const PassRefPtr<SecurityOrigin>& securityOrigin) |
54 : m_callback(callback) | 52 : m_callback(callback) |
55 , m_numberOfOutputChannels(numberOfOutputChannels) | 53 , m_numberOfOutputChannels(numberOfOutputChannels) |
56 , m_inputBus(AudioBus::create(numberOfInputChannels, renderBufferSize)) | 54 , m_inputBus(AudioBus::create(numberOfInputChannels, renderBufferSize)) |
57 , m_renderBus(AudioBus::create(numberOfOutputChannels, renderBufferSize, fal
se)) | 55 , m_renderBus(AudioBus::create(numberOfOutputChannels, renderBufferSize, fal
se)) |
58 , m_sampleRate(sampleRate) | 56 , m_sampleRate(sampleRate) |
59 , m_isPlaying(false) | 57 , m_isPlaying(false) |
60 { | 58 { |
(...skipping 23 matching lines...) Expand all Loading... |
84 | 82 |
85 if (m_callbackBufferSize <= kSmallBufferSize) | 83 if (m_callbackBufferSize <= kSmallBufferSize) |
86 m_callbackBufferSize = kDefaultCallbackBufferSize; | 84 m_callbackBufferSize = kDefaultCallbackBufferSize; |
87 #endif | 85 #endif |
88 | 86 |
89 // Quick exit if the requested size is too large. | 87 // Quick exit if the requested size is too large. |
90 ASSERT(m_callbackBufferSize + renderBufferSize <= fifoSize); | 88 ASSERT(m_callbackBufferSize + renderBufferSize <= fifoSize); |
91 if (m_callbackBufferSize + renderBufferSize > fifoSize) | 89 if (m_callbackBufferSize + renderBufferSize > fifoSize) |
92 return; | 90 return; |
93 | 91 |
94 m_audioDevice = wrapUnique(Platform::current()->createAudioDevice(m_callback
BufferSize, numberOfInputChannels, numberOfOutputChannels, sampleRate, this, inp
utDeviceId, securityOrigin)); | 92 m_audioDevice = adoptPtr(Platform::current()->createAudioDevice(m_callbackBu
fferSize, numberOfInputChannels, numberOfOutputChannels, sampleRate, this, input
DeviceId, securityOrigin)); |
95 ASSERT(m_audioDevice); | 93 ASSERT(m_audioDevice); |
96 | 94 |
97 // Record the sizes if we successfully created an output device. | 95 // Record the sizes if we successfully created an output device. |
98 hardwareBufferSizeHistogram.sample(recommendedHardwareBufferSize); | 96 hardwareBufferSizeHistogram.sample(recommendedHardwareBufferSize); |
99 callbackBufferSizeHistogram.sample(m_callbackBufferSize); | 97 callbackBufferSizeHistogram.sample(m_callbackBufferSize); |
100 | 98 |
101 // Create a FIFO to handle the possibility of the callback size | 99 // Create a FIFO to handle the possibility of the callback size |
102 // not being a multiple of the render size. If the FIFO already | 100 // not being a multiple of the render size. If the FIFO already |
103 // contains enough data, the data will be provided directly. | 101 // contains enough data, the data will be provided directly. |
104 // Otherwise, the FIFO will call the provider enough times to | 102 // Otherwise, the FIFO will call the provider enough times to |
105 // satisfy the request for data. | 103 // satisfy the request for data. |
106 m_fifo = wrapUnique(new AudioPullFIFO(*this, numberOfOutputChannels, fifoSiz
e, renderBufferSize)); | 104 m_fifo = adoptPtr(new AudioPullFIFO(*this, numberOfOutputChannels, fifoSize,
renderBufferSize)); |
107 | 105 |
108 // Input buffering. | 106 // Input buffering. |
109 m_inputFifo = wrapUnique(new AudioFIFO(numberOfInputChannels, fifoSize)); | 107 m_inputFifo = adoptPtr(new AudioFIFO(numberOfInputChannels, fifoSize)); |
110 | 108 |
111 // If the callback size does not match the render size, then we need to buff
er some | 109 // If the callback size does not match the render size, then we need to buff
er some |
112 // extra silence for the input. Otherwise, we can over-consume the input FIF
O. | 110 // extra silence for the input. Otherwise, we can over-consume the input FIF
O. |
113 if (m_callbackBufferSize != renderBufferSize) { | 111 if (m_callbackBufferSize != renderBufferSize) { |
114 // FIXME: handle multi-channel input and don't hard-code to stereo. | 112 // FIXME: handle multi-channel input and don't hard-code to stereo. |
115 RefPtr<AudioBus> silence = AudioBus::create(2, renderBufferSize); | 113 RefPtr<AudioBus> silence = AudioBus::create(2, renderBufferSize); |
116 m_inputFifo->push(silence.get()); | 114 m_inputFifo->push(silence.get()); |
117 } | 115 } |
118 } | 116 } |
119 | 117 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if (m_inputFifo->framesInFifo() >= framesToProcess) { | 181 if (m_inputFifo->framesInFifo() >= framesToProcess) { |
184 m_inputFifo->consume(m_inputBus.get(), framesToProcess); | 182 m_inputFifo->consume(m_inputBus.get(), framesToProcess); |
185 sourceBus = m_inputBus.get(); | 183 sourceBus = m_inputBus.get(); |
186 } | 184 } |
187 | 185 |
188 m_callback.render(sourceBus, bus, framesToProcess); | 186 m_callback.render(sourceBus, bus, framesToProcess); |
189 } | 187 } |
190 | 188 |
191 } // namespace blink | 189 } // namespace blink |
192 | 190 |
OLD | NEW |