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

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

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

Powered by Google App Engine
This is Rietveld 408576698