| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pepper/pepper_platform_audio_output.h" | 5 #include "content/renderer/pepper/pepper_platform_audio_output.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // Balanced by Release invoked in | 33 // Balanced by Release invoked in |
| 34 // PepperPlatformAudioOutput::ShutDownOnIOThread(). | 34 // PepperPlatformAudioOutput::ShutDownOnIOThread(). |
| 35 audio_output->AddRef(); | 35 audio_output->AddRef(); |
| 36 return audio_output.get(); | 36 return audio_output.get(); |
| 37 } | 37 } |
| 38 return NULL; | 38 return NULL; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool PepperPlatformAudioOutput::StartPlayback() { | 41 bool PepperPlatformAudioOutput::StartPlayback() { |
| 42 if (ipc_) { | 42 if (ipc_) { |
| 43 io_message_loop_proxy_->PostTask( | 43 io_task_runner_->PostTask( |
| 44 FROM_HERE, | 44 FROM_HERE, |
| 45 base::Bind(&PepperPlatformAudioOutput::StartPlaybackOnIOThread, this)); | 45 base::Bind(&PepperPlatformAudioOutput::StartPlaybackOnIOThread, this)); |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool PepperPlatformAudioOutput::StopPlayback() { | 51 bool PepperPlatformAudioOutput::StopPlayback() { |
| 52 if (ipc_) { | 52 if (ipc_) { |
| 53 io_message_loop_proxy_->PostTask( | 53 io_task_runner_->PostTask( |
| 54 FROM_HERE, | 54 FROM_HERE, |
| 55 base::Bind(&PepperPlatformAudioOutput::StopPlaybackOnIOThread, this)); | 55 base::Bind(&PepperPlatformAudioOutput::StopPlaybackOnIOThread, this)); |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void PepperPlatformAudioOutput::ShutDown() { | 61 void PepperPlatformAudioOutput::ShutDown() { |
| 62 // Called on the main thread to stop all audio callbacks. We must only change | 62 // Called on the main thread to stop all audio callbacks. We must only change |
| 63 // the client on the main thread, and the delegates from the I/O thread. | 63 // the client on the main thread, and the delegates from the I/O thread. |
| 64 client_ = NULL; | 64 client_ = NULL; |
| 65 io_message_loop_proxy_->PostTask( | 65 io_task_runner_->PostTask( |
| 66 FROM_HERE, | 66 FROM_HERE, |
| 67 base::Bind(&PepperPlatformAudioOutput::ShutDownOnIOThread, this)); | 67 base::Bind(&PepperPlatformAudioOutput::ShutDownOnIOThread, this)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void PepperPlatformAudioOutput::OnStateChanged( | 70 void PepperPlatformAudioOutput::OnStateChanged( |
| 71 media::AudioOutputIPCDelegate::State state) {} | 71 media::AudioOutputIPCDelegate::State state) {} |
| 72 | 72 |
| 73 void PepperPlatformAudioOutput::OnStreamCreated( | 73 void PepperPlatformAudioOutput::OnStreamCreated( |
| 74 base::SharedMemoryHandle handle, | 74 base::SharedMemoryHandle handle, |
| 75 base::SyncSocket::Handle socket_handle, | 75 base::SyncSocket::Handle socket_handle, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 105 PepperPlatformAudioOutput::~PepperPlatformAudioOutput() { | 105 PepperPlatformAudioOutput::~PepperPlatformAudioOutput() { |
| 106 // Make sure we have been shut down. Warning: this will usually happen on | 106 // Make sure we have been shut down. Warning: this will usually happen on |
| 107 // the I/O thread! | 107 // the I/O thread! |
| 108 DCHECK(!ipc_); | 108 DCHECK(!ipc_); |
| 109 DCHECK(!client_); | 109 DCHECK(!client_); |
| 110 } | 110 } |
| 111 | 111 |
| 112 PepperPlatformAudioOutput::PepperPlatformAudioOutput() | 112 PepperPlatformAudioOutput::PepperPlatformAudioOutput() |
| 113 : client_(NULL), | 113 : client_(NULL), |
| 114 main_message_loop_proxy_(base::MessageLoopProxy::current()), | 114 main_message_loop_proxy_(base::MessageLoopProxy::current()), |
| 115 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()) { | 115 io_task_runner_(ChildProcess::current()->io_task_runner()) { |
| 116 } | 116 } |
| 117 | 117 |
| 118 bool PepperPlatformAudioOutput::Initialize(int sample_rate, | 118 bool PepperPlatformAudioOutput::Initialize(int sample_rate, |
| 119 int frames_per_buffer, | 119 int frames_per_buffer, |
| 120 int source_render_frame_id, | 120 int source_render_frame_id, |
| 121 AudioHelper* client) { | 121 AudioHelper* client) { |
| 122 DCHECK(client); | 122 DCHECK(client); |
| 123 client_ = client; | 123 client_ = client; |
| 124 | 124 |
| 125 RenderThreadImpl* const render_thread = RenderThreadImpl::current(); | 125 RenderThreadImpl* const render_thread = RenderThreadImpl::current(); |
| 126 ipc_ = render_thread->audio_message_filter()->CreateAudioOutputIPC( | 126 ipc_ = render_thread->audio_message_filter()->CreateAudioOutputIPC( |
| 127 source_render_frame_id); | 127 source_render_frame_id); |
| 128 CHECK(ipc_); | 128 CHECK(ipc_); |
| 129 | 129 |
| 130 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 130 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 131 media::CHANNEL_LAYOUT_STEREO, | 131 media::CHANNEL_LAYOUT_STEREO, |
| 132 sample_rate, | 132 sample_rate, |
| 133 ppapi::kBitsPerAudioOutputSample, | 133 ppapi::kBitsPerAudioOutputSample, |
| 134 frames_per_buffer); | 134 frames_per_buffer); |
| 135 | 135 |
| 136 io_message_loop_proxy_->PostTask( | 136 io_task_runner_->PostTask( |
| 137 FROM_HERE, | 137 FROM_HERE, base::Bind(&PepperPlatformAudioOutput::InitializeOnIOThread, |
| 138 base::Bind( | 138 this, params)); |
| 139 &PepperPlatformAudioOutput::InitializeOnIOThread, this, params)); | |
| 140 return true; | 139 return true; |
| 141 } | 140 } |
| 142 | 141 |
| 143 void PepperPlatformAudioOutput::InitializeOnIOThread( | 142 void PepperPlatformAudioOutput::InitializeOnIOThread( |
| 144 const media::AudioParameters& params) { | 143 const media::AudioParameters& params) { |
| 145 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 144 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 146 const int kSessionId = 0; | 145 const int kSessionId = 0; |
| 147 if (ipc_) | 146 if (ipc_) |
| 148 ipc_->CreateStream(this, params, kSessionId); | 147 ipc_->CreateStream(this, params, kSessionId); |
| 149 } | 148 } |
| 150 | 149 |
| 151 void PepperPlatformAudioOutput::StartPlaybackOnIOThread() { | 150 void PepperPlatformAudioOutput::StartPlaybackOnIOThread() { |
| 152 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 151 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 153 if (ipc_) | 152 if (ipc_) |
| 154 ipc_->PlayStream(); | 153 ipc_->PlayStream(); |
| 155 } | 154 } |
| 156 | 155 |
| 157 void PepperPlatformAudioOutput::StopPlaybackOnIOThread() { | 156 void PepperPlatformAudioOutput::StopPlaybackOnIOThread() { |
| 158 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 157 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 159 if (ipc_) | 158 if (ipc_) |
| 160 ipc_->PauseStream(); | 159 ipc_->PauseStream(); |
| 161 } | 160 } |
| 162 | 161 |
| 163 void PepperPlatformAudioOutput::ShutDownOnIOThread() { | 162 void PepperPlatformAudioOutput::ShutDownOnIOThread() { |
| 164 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 163 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 165 | 164 |
| 166 // Make sure we don't call shutdown more than once. | 165 // Make sure we don't call shutdown more than once. |
| 167 if (!ipc_) | 166 if (!ipc_) |
| 168 return; | 167 return; |
| 169 | 168 |
| 170 ipc_->CloseStream(); | 169 ipc_->CloseStream(); |
| 171 ipc_.reset(); | 170 ipc_.reset(); |
| 172 | 171 |
| 173 Release(); // Release for the delegate, balances out the reference taken in | 172 Release(); // Release for the delegate, balances out the reference taken in |
| 174 // PepperPlatformAudioOutput::Create. | 173 // PepperPlatformAudioOutput::Create. |
| 175 } | 174 } |
| 176 | 175 |
| 177 } // namespace content | 176 } // namespace content |
| OLD | NEW |