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/pepper_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper_plugin_delegate_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "app/surface/transport_dib.h" | 10 #include "app/surface/transport_dib.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/string_split.h" | 15 #include "base/string_split.h" |
16 #include "base/task.h" | 16 #include "base/task.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "chrome/common/pepper_plugin_registry.h" | 18 #include "chrome/common/pepper_plugin_registry.h" |
19 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
20 #include "chrome/common/render_messages_params.h" | 20 #include "chrome/common/render_messages_params.h" |
21 #include "chrome/renderer/render_thread.h" | 21 #include "chrome/renderer/render_thread.h" |
| 22 #include "content/common/audio_messages.h" |
22 #include "content/common/child_process_messages.h" | 23 #include "content/common/child_process_messages.h" |
23 #include "content/common/child_thread.h" | 24 #include "content/common/child_thread.h" |
24 #include "content/common/file_system/file_system_dispatcher.h" | 25 #include "content/common/file_system/file_system_dispatcher.h" |
25 #include "content/common/pepper_file_messages.h" | 26 #include "content/common/pepper_file_messages.h" |
26 #include "content/common/pepper_messages.h" | 27 #include "content/common/pepper_messages.h" |
27 #include "content/renderer/audio_message_filter.h" | 28 #include "content/renderer/audio_message_filter.h" |
28 #include "content/renderer/command_buffer_proxy.h" | 29 #include "content/renderer/command_buffer_proxy.h" |
29 #include "content/renderer/content_renderer_client.h" | 30 #include "content/renderer/content_renderer_client.h" |
30 #include "content/renderer/ggl.h" | 31 #include "content/renderer/ggl.h" |
31 #include "content/renderer/gpu_channel_host.h" | 32 #include "content/renderer/gpu_channel_host.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 bool Initialize(uint32_t sample_rate, uint32_t sample_count, | 136 bool Initialize(uint32_t sample_rate, uint32_t sample_count, |
136 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client); | 137 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client); |
137 | 138 |
138 // PlatformAudio implementation (called on main thread). | 139 // PlatformAudio implementation (called on main thread). |
139 virtual bool StartPlayback(); | 140 virtual bool StartPlayback(); |
140 virtual bool StopPlayback(); | 141 virtual bool StopPlayback(); |
141 virtual void ShutDown(); | 142 virtual void ShutDown(); |
142 | 143 |
143 private: | 144 private: |
144 // I/O thread backends to above functions. | 145 // I/O thread backends to above functions. |
145 void InitializeOnIOThread( | 146 void InitializeOnIOThread(const AudioParameters& params); |
146 const ViewHostMsg_Audio_CreateStream_Params& params); | |
147 void StartPlaybackOnIOThread(); | 147 void StartPlaybackOnIOThread(); |
148 void StopPlaybackOnIOThread(); | 148 void StopPlaybackOnIOThread(); |
149 void ShutDownOnIOThread(); | 149 void ShutDownOnIOThread(); |
150 | 150 |
151 virtual void OnRequestPacket(AudioBuffersState buffers_state) { | 151 virtual void OnRequestPacket(AudioBuffersState buffers_state) { |
152 LOG(FATAL) << "Should never get OnRequestPacket in PlatformAudioImpl"; | 152 LOG(FATAL) << "Should never get OnRequestPacket in PlatformAudioImpl"; |
153 } | 153 } |
154 | 154 |
155 virtual void OnStateChanged(const ViewMsg_AudioStreamState_Params& state) {} | 155 virtual void OnStateChanged(AudioStreamState state) {} |
156 | 156 |
157 virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length) { | 157 virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length) { |
158 LOG(FATAL) << "Should never get OnCreated in PlatformAudioImpl"; | 158 LOG(FATAL) << "Should never get OnCreated in PlatformAudioImpl"; |
159 } | 159 } |
160 | 160 |
161 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, | 161 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, |
162 base::SyncSocket::Handle socket_handle, | 162 base::SyncSocket::Handle socket_handle, |
163 uint32 length); | 163 uint32 length); |
164 | 164 |
165 virtual void OnVolume(double volume) {} | 165 virtual void OnVolume(double volume) {} |
(...skipping 18 matching lines...) Expand all Loading... |
184 bool PlatformAudioImpl::Initialize( | 184 bool PlatformAudioImpl::Initialize( |
185 uint32_t sample_rate, uint32_t sample_count, | 185 uint32_t sample_rate, uint32_t sample_count, |
186 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { | 186 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { |
187 | 187 |
188 DCHECK(client); | 188 DCHECK(client); |
189 // Make sure we don't call init more than once. | 189 // Make sure we don't call init more than once. |
190 DCHECK_EQ(0, stream_id_); | 190 DCHECK_EQ(0, stream_id_); |
191 | 191 |
192 client_ = client; | 192 client_ = client; |
193 | 193 |
194 ViewHostMsg_Audio_CreateStream_Params params; | 194 AudioParameters params; |
195 params.params.format = AudioParameters::AUDIO_PCM_LINEAR; | 195 params.format = AudioParameters::AUDIO_PCM_LINEAR; |
196 params.params.channels = 2; | 196 params.channels = 2; |
197 params.params.sample_rate = sample_rate; | 197 params.sample_rate = sample_rate; |
198 params.params.bits_per_sample = 16; | 198 params.bits_per_sample = 16; |
199 params.params.samples_per_packet = sample_count; | 199 params.samples_per_packet = sample_count; |
200 | 200 |
201 filter_->message_loop()->PostTask(FROM_HERE, | 201 filter_->message_loop()->PostTask(FROM_HERE, |
202 NewRunnableMethod(this, &PlatformAudioImpl::InitializeOnIOThread, | 202 NewRunnableMethod(this, &PlatformAudioImpl::InitializeOnIOThread, |
203 params)); | 203 params)); |
204 return true; | 204 return true; |
205 } | 205 } |
206 | 206 |
207 bool PlatformAudioImpl::StartPlayback() { | 207 bool PlatformAudioImpl::StartPlayback() { |
208 if (filter_) { | 208 if (filter_) { |
209 filter_->message_loop()->PostTask(FROM_HERE, | 209 filter_->message_loop()->PostTask(FROM_HERE, |
(...skipping 13 matching lines...) Expand all Loading... |
223 } | 223 } |
224 | 224 |
225 void PlatformAudioImpl::ShutDown() { | 225 void PlatformAudioImpl::ShutDown() { |
226 // Called on the main thread to stop all audio callbacks. We must only change | 226 // Called on the main thread to stop all audio callbacks. We must only change |
227 // the client on the main thread, and the delegates from the I/O thread. | 227 // the client on the main thread, and the delegates from the I/O thread. |
228 client_ = NULL; | 228 client_ = NULL; |
229 filter_->message_loop()->PostTask(FROM_HERE, | 229 filter_->message_loop()->PostTask(FROM_HERE, |
230 NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread)); | 230 NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread)); |
231 } | 231 } |
232 | 232 |
233 void PlatformAudioImpl::InitializeOnIOThread( | 233 void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) { |
234 const ViewHostMsg_Audio_CreateStream_Params& params) { | |
235 stream_id_ = filter_->AddDelegate(this); | 234 stream_id_ = filter_->AddDelegate(this); |
236 filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, true)); | 235 filter_->Send(new AudioHostMsg_CreateStream(0, stream_id_, params, true)); |
237 } | 236 } |
238 | 237 |
239 void PlatformAudioImpl::StartPlaybackOnIOThread() { | 238 void PlatformAudioImpl::StartPlaybackOnIOThread() { |
240 if (stream_id_) | 239 if (stream_id_) |
241 filter_->Send(new ViewHostMsg_PlayAudioStream(0, stream_id_)); | 240 filter_->Send(new AudioHostMsg_PlayStream(0, stream_id_)); |
242 } | 241 } |
243 | 242 |
244 void PlatformAudioImpl::StopPlaybackOnIOThread() { | 243 void PlatformAudioImpl::StopPlaybackOnIOThread() { |
245 if (stream_id_) | 244 if (stream_id_) |
246 filter_->Send(new ViewHostMsg_PauseAudioStream(0, stream_id_)); | 245 filter_->Send(new AudioHostMsg_PauseStream(0, stream_id_)); |
247 } | 246 } |
248 | 247 |
249 void PlatformAudioImpl::ShutDownOnIOThread() { | 248 void PlatformAudioImpl::ShutDownOnIOThread() { |
250 // Make sure we don't call shutdown more than once. | 249 // Make sure we don't call shutdown more than once. |
251 if (!stream_id_) | 250 if (!stream_id_) |
252 return; | 251 return; |
253 | 252 |
254 filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); | 253 filter_->Send(new AudioHostMsg_CloseStream(0, stream_id_)); |
255 filter_->RemoveDelegate(stream_id_); | 254 filter_->RemoveDelegate(stream_id_); |
256 stream_id_ = 0; | 255 stream_id_ = 0; |
257 | 256 |
258 Release(); // Release for the delegate, balances out the reference taken in | 257 Release(); // Release for the delegate, balances out the reference taken in |
259 // PepperPluginDelegateImpl::CreateAudio. | 258 // PepperPluginDelegateImpl::CreateAudio. |
260 } | 259 } |
261 | 260 |
262 void PlatformAudioImpl::OnLowLatencyCreated( | 261 void PlatformAudioImpl::OnLowLatencyCreated( |
263 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, | 262 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, |
264 uint32 length) { | 263 uint32 length) { |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 } | 957 } |
959 | 958 |
960 void PepperPluginDelegateImpl::HasUnsupportedFeature() { | 959 void PepperPluginDelegateImpl::HasUnsupportedFeature() { |
961 render_view_->Send(new ViewHostMsg_PDFHasUnsupportedFeature( | 960 render_view_->Send(new ViewHostMsg_PDFHasUnsupportedFeature( |
962 render_view_->routing_id())); | 961 render_view_->routing_id())); |
963 } | 962 } |
964 | 963 |
965 P2PSocketDispatcher* PepperPluginDelegateImpl::GetP2PSocketDispatcher() { | 964 P2PSocketDispatcher* PepperPluginDelegateImpl::GetP2PSocketDispatcher() { |
966 return render_view_->p2p_socket_dispatcher(); | 965 return render_view_->p2p_socket_dispatcher(); |
967 } | 966 } |
OLD | NEW |