Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/media/audio_renderer_impl.h" | 5 #include "content/renderer/media/audio_renderer_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 91 |
| 92 bytes_per_second_ = params.GetBytesPerSecond(); | 92 bytes_per_second_ = params.GetBytesPerSecond(); |
| 93 | 93 |
| 94 ChildProcess::current()->io_message_loop()->PostTask( | 94 ChildProcess::current()->io_message_loop()->PostTask( |
| 95 FROM_HERE, | 95 FROM_HERE, |
| 96 NewRunnableMethod(this, &AudioRendererImpl::CreateStreamTask, params)); | 96 NewRunnableMethod(this, &AudioRendererImpl::CreateStreamTask, params)); |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void AudioRendererImpl::OnStop() { | 100 void AudioRendererImpl::OnStop() { |
| 101 base::AutoLock auto_lock(lock_); | 101 // Since joining with the audio thread can acquire lock_, we make sure to |
| 102 if (stopped_) | 102 // Join() with it not under lock. |
| 103 return; | 103 base::DelegateSimpleThread* audio_thread = NULL; |
| 104 stopped_ = true; | 104 base::SyncSocket* socket = NULL; |
| 105 { | |
| 106 base::AutoLock auto_lock(lock_); | |
| 107 if (stopped_) | |
| 108 return; | |
| 109 stopped_ = true; | |
| 110 DCHECK_EQ(!audio_thread_.get(), !socket_.get()); | |
| 111 if (audio_thread_.get()) { | |
| 112 audio_thread = audio_thread_.get(); | |
| 113 socket = socket_.get(); | |
| 114 } | |
| 115 ChildProcess::current()->io_message_loop()->PostTask( | |
| 116 FROM_HERE, | |
| 117 NewRunnableMethod(this, &AudioRendererImpl::DestroyTask)); | |
| 118 } | |
| 105 | 119 |
| 106 ChildProcess::current()->io_message_loop()->PostTask( | 120 if (audio_thread) { |
| 107 FROM_HERE, | 121 CHECK(socket->Close()); |
|
acolwell GONE FROM CHROMIUM
2011/10/07 15:50:47
Does this need to happen outside of the lock?
Ami GONE FROM CHROMIUM
2011/10/07 16:44:47
Done.
| |
| 108 NewRunnableMethod(this, &AudioRendererImpl::DestroyTask)); | 122 audio_thread->Join(); |
| 109 | |
| 110 if (audio_thread_.get()) { | |
| 111 socket_->Close(); | |
| 112 audio_thread_->Join(); | |
| 113 } | 123 } |
| 114 } | 124 } |
| 115 | 125 |
| 116 void AudioRendererImpl::NotifyDataAvailableIfNecessary() { | 126 void AudioRendererImpl::NotifyDataAvailableIfNecessary() { |
| 117 if (latency_type_ == kHighLatency) { | 127 if (latency_type_ == kHighLatency) { |
| 118 // Post a task to render thread to notify a packet reception. | 128 // Post a task to render thread to notify a packet reception. |
| 119 ChildProcess::current()->io_message_loop()->PostTask( | 129 ChildProcess::current()->io_message_loop()->PostTask( |
| 120 FROM_HERE, | 130 FROM_HERE, |
| 121 NewRunnableMethod(this, &AudioRendererImpl::NotifyPacketReadyTask)); | 131 NewRunnableMethod(this, &AudioRendererImpl::NotifyPacketReadyTask)); |
| 122 } | 132 } |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 if (stopped_) | 458 if (stopped_) |
| 449 return; | 459 return; |
| 450 | 460 |
| 451 stopped_ = true; | 461 stopped_ = true; |
| 452 DestroyTask(); | 462 DestroyTask(); |
| 453 } | 463 } |
| 454 | 464 |
| 455 // Our audio thread runs here. We receive requests for more data and send it | 465 // Our audio thread runs here. We receive requests for more data and send it |
| 456 // on this thread. | 466 // on this thread. |
| 457 void AudioRendererImpl::Run() { | 467 void AudioRendererImpl::Run() { |
| 468 DCHECK_EQ(kLowLatency, latency_type_); | |
| 458 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); | 469 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); |
| 459 | 470 |
| 460 int bytes; | 471 int bytes; |
| 461 while (sizeof(bytes) == socket_->Receive(&bytes, sizeof(bytes))) { | 472 while (sizeof(bytes) == socket_->Receive(&bytes, sizeof(bytes))) { |
| 462 if (bytes == media::AudioOutputController::kPauseMark) | 473 if (bytes == media::AudioOutputController::kPauseMark) |
| 463 continue; | 474 continue; |
| 464 else if (bytes < 0) | 475 else if (bytes < 0) |
| 465 break; | 476 break; |
| 466 base::AutoLock auto_lock(lock_); | 477 base::AutoLock auto_lock(lock_); |
| 467 if (stopped_) | 478 if (stopped_) |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 486 media::SetActualDataSizeInBytes(shared_memory_.get(), | 497 media::SetActualDataSizeInBytes(shared_memory_.get(), |
| 487 shared_memory_size_, | 498 shared_memory_size_, |
| 488 size); | 499 size); |
| 489 UpdateEarliestEndTime(size, request_delay, time_now); | 500 UpdateEarliestEndTime(size, request_delay, time_now); |
| 490 } | 501 } |
| 491 } | 502 } |
| 492 | 503 |
| 493 void AudioRendererImpl::Send(IPC::Message* message) { | 504 void AudioRendererImpl::Send(IPC::Message* message) { |
| 494 filter_->Send(message); | 505 filter_->Send(message); |
| 495 } | 506 } |
| OLD | NEW |