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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 bytes_per_second_ = params.GetBytesPerSecond(); | 93 bytes_per_second_ = params.GetBytesPerSecond(); |
94 | 94 |
95 ChildProcess::current()->io_message_loop()->PostTask( | 95 ChildProcess::current()->io_message_loop()->PostTask( |
96 FROM_HERE, | 96 FROM_HERE, |
97 base::Bind(&AudioRendererImpl::CreateStreamTask, this, params)); | 97 base::Bind(&AudioRendererImpl::CreateStreamTask, this, params)); |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 void AudioRendererImpl::OnStop() { | 101 void AudioRendererImpl::OnStop() { |
102 base::AutoLock auto_lock(lock_); | 102 // Since joining with the audio thread can acquire lock_, we make sure to |
103 if (stopped_) | 103 // Join() with it not under lock. |
104 return; | 104 base::DelegateSimpleThread* audio_thread = NULL; |
105 stopped_ = true; | 105 { |
| 106 base::AutoLock auto_lock(lock_); |
| 107 if (stopped_) |
| 108 return; |
| 109 stopped_ = true; |
106 | 110 |
107 ChildProcess::current()->io_message_loop()->PostTask( | 111 DCHECK_EQ(!audio_thread_.get(), !socket_.get()); |
108 FROM_HERE, | 112 if (socket_.get()) |
109 base::Bind(&AudioRendererImpl::DestroyTask, this)); | 113 socket_->Close(); |
| 114 if (audio_thread_.get()) |
| 115 audio_thread = audio_thread_.get(); |
110 | 116 |
111 if (audio_thread_.get()) { | 117 ChildProcess::current()->io_message_loop()->PostTask( |
112 socket_->Close(); | 118 FROM_HERE, |
113 audio_thread_->Join(); | 119 base::Bind(&AudioRendererImpl::DestroyTask, this)); |
114 } | 120 } |
| 121 |
| 122 if (audio_thread) |
| 123 audio_thread->Join(); |
115 } | 124 } |
116 | 125 |
117 void AudioRendererImpl::NotifyDataAvailableIfNecessary() { | 126 void AudioRendererImpl::NotifyDataAvailableIfNecessary() { |
118 if (latency_type_ == kHighLatency) { | 127 if (latency_type_ == kHighLatency) { |
119 // Post a task to render thread to notify a packet reception. | 128 // Post a task to render thread to notify a packet reception. |
120 ChildProcess::current()->io_message_loop()->PostTask( | 129 ChildProcess::current()->io_message_loop()->PostTask( |
121 FROM_HERE, | 130 FROM_HERE, |
122 base::Bind(&AudioRendererImpl::NotifyPacketReadyTask, this)); | 131 base::Bind(&AudioRendererImpl::NotifyPacketReadyTask, this)); |
123 } | 132 } |
124 } | 133 } |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 if (stopped_) | 458 if (stopped_) |
450 return; | 459 return; |
451 | 460 |
452 stopped_ = true; | 461 stopped_ = true; |
453 DestroyTask(); | 462 DestroyTask(); |
454 } | 463 } |
455 | 464 |
456 // 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 |
457 // on this thread. | 466 // on this thread. |
458 void AudioRendererImpl::Run() { | 467 void AudioRendererImpl::Run() { |
| 468 DCHECK_EQ(kLowLatency, latency_type_); |
459 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); | 469 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); |
460 | 470 |
461 int bytes; | 471 int bytes; |
462 while (sizeof(bytes) == socket_->Receive(&bytes, sizeof(bytes))) { | 472 while (sizeof(bytes) == socket_->Receive(&bytes, sizeof(bytes))) { |
463 if (bytes == media::AudioOutputController::kPauseMark) { | 473 if (bytes == media::AudioOutputController::kPauseMark) { |
464 // When restarting playback, host should get new data, | 474 // When restarting playback, host should get new data, |
465 // not what is currently in the buffer. | 475 // not what is currently in the buffer. |
466 media::SetActualDataSizeInBytes(shared_memory_.get(), | 476 media::SetActualDataSizeInBytes(shared_memory_.get(), |
467 shared_memory_size_, | 477 shared_memory_size_, |
468 0); | 478 0); |
(...skipping 24 matching lines...) Expand all Loading... |
493 media::SetActualDataSizeInBytes(shared_memory_.get(), | 503 media::SetActualDataSizeInBytes(shared_memory_.get(), |
494 shared_memory_size_, | 504 shared_memory_size_, |
495 size); | 505 size); |
496 UpdateEarliestEndTime(size, request_delay, time_now); | 506 UpdateEarliestEndTime(size, request_delay, time_now); |
497 } | 507 } |
498 } | 508 } |
499 | 509 |
500 void AudioRendererImpl::Send(IPC::Message* message) { | 510 void AudioRendererImpl::Send(IPC::Message* message) { |
501 filter_->Send(message); | 511 filter_->Send(message); |
502 } | 512 } |
OLD | NEW |