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

Side by Side Diff: media/audio/audio_device_thread.cc

Issue 10823175: Switch AudioRenderSink::Callback to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup MCR AudioBus usage. Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/audio/audio_device_thread.h" 5 #include "media/audio/audio_device_thread.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/aligned_memory.h" 11 #include "base/memory/aligned_memory.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 #include "base/threading/thread_restrictions.h" 14 #include "base/threading/thread_restrictions.h"
15 #include "media/audio/audio_util.h" 15 #include "media/audio/audio_util.h"
16 #include "media/base/audio_bus.h"
16 17
17 using base::PlatformThread; 18 using base::PlatformThread;
18 19
19 namespace media { 20 namespace media {
20 21
21 // The actual worker thread implementation. It's very bare bones and much 22 // The actual worker thread implementation. It's very bare bones and much
22 // simpler than SimpleThread (no synchronization in Start, etc) and supports 23 // simpler than SimpleThread (no synchronization in Start, etc) and supports
23 // joining the thread handle asynchronously via a provided message loop even 24 // joining the thread handle asynchronously via a provided message loop even
24 // after the Thread object itself has been deleted. 25 // after the Thread object itself has been deleted.
25 class AudioDeviceThread::Thread 26 class AudioDeviceThread::Thread
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 samples_per_ms_(audio_parameters.sample_rate() / 1000), 182 samples_per_ms_(audio_parameters.sample_rate() / 1000),
182 bytes_per_ms_(audio_parameters.channels() * 183 bytes_per_ms_(audio_parameters.channels() *
183 (audio_parameters_.bits_per_sample() / 8) * 184 (audio_parameters_.bits_per_sample() / 8) *
184 samples_per_ms_), 185 samples_per_ms_),
185 shared_memory_(memory, false), 186 shared_memory_(memory, false),
186 memory_length_(memory_length) { 187 memory_length_(memory_length) {
187 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early. 188 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early.
188 CHECK_NE(samples_per_ms_, 0); 189 CHECK_NE(samples_per_ms_, 0);
189 } 190 }
190 191
191 AudioDeviceThread::Callback::~Callback() { 192 AudioDeviceThread::Callback::~Callback() {}
192 for (size_t i = 0; i < audio_data_.size(); ++i)
193 base::AlignedFree(audio_data_[i]);
194 }
195 193
196 void AudioDeviceThread::Callback::InitializeOnAudioThread() { 194 void AudioDeviceThread::Callback::InitializeOnAudioThread() {
197 DCHECK(audio_data_.empty()); 195 DCHECK(!audio_bus_.get());
198 196
199 MapSharedMemory(); 197 MapSharedMemory();
200 DCHECK(shared_memory_.memory() != NULL); 198 DCHECK(shared_memory_.memory() != NULL);
201 199
202 // Allocate buffer with a 16-byte alignment to allow SSE optimizations. 200 // TODO(dalecurtis): Instead of creating a new AudioBus and memcpy'ing into
203 audio_data_.reserve(audio_parameters_.channels()); 201 // the shared memory we should wrap the shared memory.
204 for (int i = 0; i < audio_parameters_.channels(); ++i) { 202 audio_bus_ = AudioBus::Create(audio_parameters_);
205 audio_data_.push_back(static_cast<float*>(base::AlignedAlloc(
206 sizeof(float) * audio_parameters_.frames_per_buffer(), 16)));
207 }
208 } 203 }
209 204
210 } // namespace media. 205 } // namespace media.
OLDNEW
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698