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

Side by Side Diff: content/renderer/audio_device.cc

Issue 6949009: Add support for real-time audio threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 | « base/threading/simple_thread.h ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/renderer/audio_device.h" 5 #include "content/renderer/audio_device.h"
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "content/common/audio_messages.h" 9 #include "content/common/audio_messages.h"
10 #include "content/common/child_process.h" 10 #include "content/common/child_process.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 // TODO(crogers) : check that length is big enough for buffer_size_ 201 // TODO(crogers) : check that length is big enough for buffer_size_
202 202
203 shared_memory_.reset(new base::SharedMemory(handle, false)); 203 shared_memory_.reset(new base::SharedMemory(handle, false));
204 shared_memory_->Map(length); 204 shared_memory_->Map(length);
205 205
206 socket_.reset(new base::SyncSocket(socket_handle)); 206 socket_.reset(new base::SyncSocket(socket_handle));
207 // Allow the client to pre-populate the buffer. 207 // Allow the client to pre-populate the buffer.
208 FireRenderCallback(); 208 FireRenderCallback();
209 209
210 // TODO(crogers): we could optionally set the thread to high-priority
211 audio_thread_.reset( 210 audio_thread_.reset(
212 new base::DelegateSimpleThread(this, "renderer_audio_thread")); 211 new base::DelegateSimpleThread(this, "renderer_audio_thread"));
213 audio_thread_->Start(); 212 audio_thread_->Start();
214 213
215 if (filter_) { 214 if (filter_) {
216 filter_->message_loop()->PostTask(FROM_HERE, 215 filter_->message_loop()->PostTask(FROM_HERE,
217 NewRunnableMethod(this, &AudioDevice::StartOnIOThread)); 216 NewRunnableMethod(this, &AudioDevice::StartOnIOThread));
218 } 217 }
219 } 218 }
220 219
221 void AudioDevice::OnVolume(double volume) { 220 void AudioDevice::OnVolume(double volume) {
222 NOTIMPLEMENTED(); 221 NOTIMPLEMENTED();
223 } 222 }
224 223
225 // Our audio thread runs here. 224 // Our audio thread runs here.
226 void AudioDevice::Run() { 225 void AudioDevice::Run() {
226 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio);
227
227 int pending_data; 228 int pending_data;
228 const int samples_per_ms = static_cast<int>(sample_rate_) / 1000; 229 const int samples_per_ms = static_cast<int>(sample_rate_) / 1000;
229 const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms; 230 const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms;
230 231
231 while (sizeof(pending_data) == socket_->Receive(&pending_data, 232 while (sizeof(pending_data) == socket_->Receive(&pending_data,
232 sizeof(pending_data)) && 233 sizeof(pending_data)) &&
233 pending_data >= 0) { 234 pending_data >= 0) {
234 { 235 {
235 // Convert the number of pending bytes in the render buffer 236 // Convert the number of pending bytes in the render buffer
236 // into milliseconds. 237 // into milliseconds.
237 audio_delay_milliseconds_ = pending_data / bytes_per_ms; 238 audio_delay_milliseconds_ = pending_data / bytes_per_ms;
238 } 239 }
239 240
240 FireRenderCallback(); 241 FireRenderCallback();
241 } 242 }
242 } 243 }
243 244
244 void AudioDevice::FireRenderCallback() { 245 void AudioDevice::FireRenderCallback() {
245 if (callback_) { 246 if (callback_) {
246 // Update the audio-delay measurement then ask client to render audio. 247 // Update the audio-delay measurement then ask client to render audio.
247 callback_->Render(audio_data_, buffer_size_, audio_delay_milliseconds_); 248 callback_->Render(audio_data_, buffer_size_, audio_delay_milliseconds_);
248 249
249 // Interleave, scale, and clip to int16. 250 // Interleave, scale, and clip to int16.
250 int16* output_buffer16 = static_cast<int16*>(shared_memory_data()); 251 int16* output_buffer16 = static_cast<int16*>(shared_memory_data());
251 media::InterleaveFloatToInt16(audio_data_, output_buffer16, buffer_size_); 252 media::InterleaveFloatToInt16(audio_data_, output_buffer16, buffer_size_);
252 } 253 }
253 } 254 }
OLDNEW
« no previous file with comments | « base/threading/simple_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698