| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 bytes_per_second_ = params.GetBytesPerSecond(); | 90 bytes_per_second_ = params.GetBytesPerSecond(); |
| 91 | 91 |
| 92 ChildProcess::current()->io_message_loop()->PostTask( | 92 ChildProcess::current()->io_message_loop()->PostTask( |
| 93 FROM_HERE, | 93 FROM_HERE, |
| 94 NewRunnableMethod(this, &AudioRendererImpl::CreateStreamTask, params)); | 94 NewRunnableMethod(this, &AudioRendererImpl::CreateStreamTask, params)); |
| 95 return true; | 95 return true; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void AudioRendererImpl::OnStop() { | 98 void AudioRendererImpl::OnStop() { |
| 99 base::AutoLock auto_lock(lock_); | 99 // Since joining with the audio thread can acquire lock_, we make sure to |
| 100 if (stopped_) | 100 // Join() with it not under lock. |
| 101 return; | 101 base::DelegateSimpleThread* audio_thread = NULL; |
| 102 stopped_ = true; | 102 { |
| 103 base::AutoLock auto_lock(lock_); |
| 104 if (stopped_) |
| 105 return; |
| 106 stopped_ = true; |
| 103 | 107 |
| 104 ChildProcess::current()->io_message_loop()->PostTask( | 108 DCHECK_EQ(!audio_thread_.get(), !socket_.get()); |
| 105 FROM_HERE, | 109 if (socket_.get()) |
| 106 NewRunnableMethod(this, &AudioRendererImpl::DestroyTask)); | 110 socket_->Close(); |
| 111 if (audio_thread_.get()) |
| 112 audio_thread = audio_thread_.get(); |
| 107 | 113 |
| 108 if (audio_thread_.get()) { | 114 ChildProcess::current()->io_message_loop()->PostTask( |
| 109 socket_->Close(); | 115 FROM_HERE, |
| 110 audio_thread_->Join(); | 116 NewRunnableMethod(this, &AudioRendererImpl::DestroyTask)); |
| 111 } | 117 } |
| 118 |
| 119 if (audio_thread) |
| 120 audio_thread->Join(); |
| 112 } | 121 } |
| 113 | 122 |
| 114 void AudioRendererImpl::NotifyDataAvailableIfNecessary() { | 123 void AudioRendererImpl::NotifyDataAvailableIfNecessary() { |
| 115 if (latency_type_ == kHighLatency) { | 124 if (latency_type_ == kHighLatency) { |
| 116 // Post a task to render thread to notify a packet reception. | 125 // Post a task to render thread to notify a packet reception. |
| 117 ChildProcess::current()->io_message_loop()->PostTask( | 126 ChildProcess::current()->io_message_loop()->PostTask( |
| 118 FROM_HERE, | 127 FROM_HERE, |
| 119 NewRunnableMethod(this, &AudioRendererImpl::NotifyPacketReadyTask)); | 128 NewRunnableMethod(this, &AudioRendererImpl::NotifyPacketReadyTask)); |
| 120 } | 129 } |
| 121 } | 130 } |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 media::SetActualDataSizeInBytes(shared_memory_.get(), | 493 media::SetActualDataSizeInBytes(shared_memory_.get(), |
| 485 shared_memory_size_, | 494 shared_memory_size_, |
| 486 size); | 495 size); |
| 487 UpdateEarliestEndTime(size, request_delay, time_now); | 496 UpdateEarliestEndTime(size, request_delay, time_now); |
| 488 } | 497 } |
| 489 } | 498 } |
| 490 | 499 |
| 491 void AudioRendererImpl::Send(IPC::Message* message) { | 500 void AudioRendererImpl::Send(IPC::Message* message) { |
| 492 filter_->Send(message); | 501 filter_->Send(message); |
| 493 } | 502 } |
| OLD | NEW |