OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // TODO(hclam): Several changes need to be made to this code: | 5 // TODO(hclam): Several changes need to be made to this code: |
6 // 1. We should host AudioRendererHost on a dedicated audio thread. Doing | 6 // 1. We should host AudioRendererHost on a dedicated audio thread. Doing |
7 // so we don't have to worry about blocking method calls such as | 7 // so we don't have to worry about blocking method calls such as |
8 // play / stop an audio stream. | 8 // play / stop an audio stream. |
9 // 2. Move locked data structures into a separate structure that sanity | 9 // 2. Move locked data structures into a separate structure that sanity |
10 // checks access by different threads that use it. | 10 // checks access by different threads that use it. |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 stream_->Stop(); | 205 stream_->Stop(); |
206 stream_->Close(); | 206 stream_->Close(); |
207 // After stream is closed it is destroyed, so don't keep a reference to it. | 207 // After stream is closed it is destroyed, so don't keep a reference to it. |
208 stream_ = NULL; | 208 stream_ = NULL; |
209 | 209 |
210 // Update the current state. | 210 // Update the current state. |
211 state_ = kClosed; | 211 state_ = kClosed; |
212 } | 212 } |
213 | 213 |
214 void AudioRendererHost::IPCAudioSource::SetVolume(double left, double right) { | 214 void AudioRendererHost::IPCAudioSource::SetVolume(double volume) { |
215 // TODO(hclam): maybe send an error message back to renderer if this object | 215 // TODO(hclam): maybe send an error message back to renderer if this object |
216 // is in a wrong state. | 216 // is in a wrong state. |
217 if (!stream_) | 217 if (!stream_) |
218 return; | 218 return; |
219 stream_->SetVolume(left, right); | 219 stream_->SetVolume(volume); |
220 } | 220 } |
221 | 221 |
222 void AudioRendererHost::IPCAudioSource::GetVolume() { | 222 void AudioRendererHost::IPCAudioSource::GetVolume() { |
223 // TODO(hclam): maybe send an error message back to renderer if this object | 223 // TODO(hclam): maybe send an error message back to renderer if this object |
224 // is in a wrong state. | 224 // is in a wrong state. |
225 if (!stream_) | 225 if (!stream_) |
226 return; | 226 return; |
227 double left_channel, right_channel; | 227 double volume; |
228 stream_->GetVolume(&left_channel, &right_channel); | 228 stream_->GetVolume(&volume); |
229 host_->Send(new ViewMsg_NotifyAudioStreamVolume(route_id_, stream_id_, | 229 host_->Send(new ViewMsg_NotifyAudioStreamVolume(route_id_, stream_id_, |
230 left_channel, right_channel)); | 230 volume)); |
231 } | 231 } |
232 | 232 |
233 size_t AudioRendererHost::IPCAudioSource::OnMoreData(AudioOutputStream* stream, | 233 size_t AudioRendererHost::IPCAudioSource::OnMoreData(AudioOutputStream* stream, |
234 void* dest, | 234 void* dest, |
235 size_t max_size, | 235 size_t max_size, |
236 int pending_bytes) { | 236 int pending_bytes) { |
237 AutoLock auto_lock(lock_); | 237 AutoLock auto_lock(lock_); |
238 | 238 |
239 // Record the callback time. | 239 // Record the callback time. |
240 last_callback_time_ = base::Time::Now(); | 240 last_callback_time_ = base::Time::Now(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 host_->Send( | 308 host_->Send( |
309 new ViewMsg_RequestAudioPacket( | 309 new ViewMsg_RequestAudioPacket( |
310 route_id_, | 310 route_id_, |
311 stream_id_, | 311 stream_id_, |
312 buffered_bytes, | 312 buffered_bytes, |
313 last_callback_time_.ToInternalValue())); | 313 last_callback_time_.ToInternalValue())); |
314 } | 314 } |
315 } | 315 } |
316 | 316 |
317 void AudioRendererHost::IPCAudioSource::SubmitPacketRequest(AutoLock* alock) { | 317 void AudioRendererHost::IPCAudioSource::SubmitPacketRequest(AutoLock* alock) { |
318 if (alock) { | 318 if (alock) { |
319 SubmitPacketRequest_Locked(); | 319 SubmitPacketRequest_Locked(); |
320 } else { | 320 } else { |
321 AutoLock auto_lock(lock_); | 321 AutoLock auto_lock(lock_); |
322 SubmitPacketRequest_Locked(); | 322 SubmitPacketRequest_Locked(); |
323 } | 323 } |
324 } | 324 } |
325 | 325 |
326 void AudioRendererHost::IPCAudioSource::StartBuffering() { | 326 void AudioRendererHost::IPCAudioSource::StartBuffering() { |
327 SubmitPacketRequest(NULL); | 327 SubmitPacketRequest(NULL); |
328 } | 328 } |
329 | 329 |
330 //----------------------------------------------------------------------------- | 330 //----------------------------------------------------------------------------- |
331 // AudioRendererHost implementations. | 331 // AudioRendererHost implementations. |
332 | 332 |
333 AudioRendererHost::AudioRendererHost() | 333 AudioRendererHost::AudioRendererHost() |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 | 458 |
459 void AudioRendererHost::OnCloseStream(const IPC::Message& msg, int stream_id) { | 459 void AudioRendererHost::OnCloseStream(const IPC::Message& msg, int stream_id) { |
460 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 460 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
461 IPCAudioSource* source = Lookup(msg.routing_id(), stream_id); | 461 IPCAudioSource* source = Lookup(msg.routing_id(), stream_id); |
462 if (source) { | 462 if (source) { |
463 DestroySource(source); | 463 DestroySource(source); |
464 } | 464 } |
465 } | 465 } |
466 | 466 |
467 void AudioRendererHost::OnSetVolume(const IPC::Message& msg, int stream_id, | 467 void AudioRendererHost::OnSetVolume(const IPC::Message& msg, int stream_id, |
468 double left_channel, double right_channel) { | 468 double volume) { |
469 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 469 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
470 IPCAudioSource* source = Lookup(msg.routing_id(), stream_id); | 470 IPCAudioSource* source = Lookup(msg.routing_id(), stream_id); |
471 if (source) { | 471 if (source) { |
472 source->SetVolume(left_channel, right_channel); | 472 source->SetVolume(volume); |
473 } else { | 473 } else { |
474 SendErrorMessage(msg.routing_id(), stream_id); | 474 SendErrorMessage(msg.routing_id(), stream_id); |
475 } | 475 } |
476 } | 476 } |
477 | 477 |
478 void AudioRendererHost::OnGetVolume(const IPC::Message& msg, int stream_id) { | 478 void AudioRendererHost::OnGetVolume(const IPC::Message& msg, int stream_id) { |
479 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 479 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
480 IPCAudioSource* source = Lookup(msg.routing_id(), stream_id); | 480 IPCAudioSource* source = Lookup(msg.routing_id(), stream_id); |
481 if (source) { | 481 if (source) { |
482 source->GetVolume(); | 482 source->GetVolume(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 563 |
564 void AudioRendererHost::DestroySource(IPCAudioSource* source) { | 564 void AudioRendererHost::DestroySource(IPCAudioSource* source) { |
565 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 565 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
566 OnDestroySource(source); | 566 OnDestroySource(source); |
567 } else { | 567 } else { |
568 ChromeThread::PostTask( | 568 ChromeThread::PostTask( |
569 ChromeThread::IO, FROM_HERE, | 569 ChromeThread::IO, FROM_HERE, |
570 NewRunnableMethod(this, &AudioRendererHost::OnDestroySource, source)); | 570 NewRunnableMethod(this, &AudioRendererHost::OnDestroySource, source)); |
571 } | 571 } |
572 } | 572 } |
OLD | NEW |