OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "chrome/renderer/pepper_plugin_delegate_impl.h" | 7 #include "chrome/renderer/pepper_plugin_delegate_impl.h" |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/surface/transport_dib.h" | 10 #include "app/surface/transport_dib.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 | 116 |
117 private: | 117 private: |
118 WebKit::WebView* web_view_; | 118 WebKit::WebView* web_view_; |
119 ggl::Context* context_; | 119 ggl::Context* context_; |
120 }; | 120 }; |
121 | 121 |
122 #endif // ENABLE_GPU | 122 #endif // ENABLE_GPU |
123 | 123 |
124 class PlatformAudioImpl | 124 class PlatformAudioImpl |
125 : public pepper::PluginDelegate::PlatformAudio, | 125 : public pepper::PluginDelegate::PlatformAudio, |
126 public AudioMessageFilter::Delegate { | 126 public AudioMessageFilter::Delegate, |
127 public base::RefCountedThreadSafe<PlatformAudioImpl> { | |
127 public: | 128 public: |
128 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) | 129 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) |
129 : client_(NULL), filter_(filter), stream_id_(0) { | 130 : client_(NULL), filter_(filter), stream_id_(0), |
131 main_message_loop_(MessageLoop::current()) { | |
130 DCHECK(filter_); | 132 DCHECK(filter_); |
131 } | 133 } |
132 | 134 |
133 virtual ~PlatformAudioImpl() { | 135 virtual ~PlatformAudioImpl() { |
134 // Make sure we have been shut down. | 136 // Make sure we have been shut down. |
135 DCHECK_EQ(0, stream_id_); | 137 DCHECK_EQ(0, stream_id_); |
136 DCHECK(!client_); | 138 DCHECK(!client_); |
137 } | 139 } |
138 | 140 |
139 // Initialize this audio context. StreamCreated() will be called when the | 141 // Initialize this audio context. StreamCreated() will be called when the |
(...skipping 30 matching lines...) Expand all Loading... | |
170 | 172 |
171 virtual void OnVolume(double volume) { } | 173 virtual void OnVolume(double volume) { } |
172 | 174 |
173 // The client to notify when the stream is created. | 175 // The client to notify when the stream is created. |
174 pepper::PluginDelegate::PlatformAudio::Client* client_; | 176 pepper::PluginDelegate::PlatformAudio::Client* client_; |
175 // MessageFilter used to send/receive IPC. | 177 // MessageFilter used to send/receive IPC. |
176 scoped_refptr<AudioMessageFilter> filter_; | 178 scoped_refptr<AudioMessageFilter> filter_; |
177 // Our ID on the MessageFilter. | 179 // Our ID on the MessageFilter. |
178 int32 stream_id_; | 180 int32 stream_id_; |
179 | 181 |
182 MessageLoop* main_message_loop_; | |
183 | |
180 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); | 184 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); |
181 }; | 185 }; |
182 | 186 |
183 #ifdef ENABLE_GPU | 187 #ifdef ENABLE_GPU |
184 | 188 |
185 bool PlatformContext3DImpl::Init() { | 189 bool PlatformContext3DImpl::Init() { |
186 // Ignore initializing more than once. | 190 // Ignore initializing more than once. |
187 if (context_) | 191 if (context_) |
188 return true; | 192 return true; |
189 | 193 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 client_ = client; | 278 client_ = client; |
275 | 279 |
276 ViewHostMsg_Audio_CreateStream_Params params; | 280 ViewHostMsg_Audio_CreateStream_Params params; |
277 params.params.format = AudioParameters::AUDIO_PCM_LINEAR; | 281 params.params.format = AudioParameters::AUDIO_PCM_LINEAR; |
278 params.params.channels = 2; | 282 params.params.channels = 2; |
279 params.params.sample_rate = sample_rate; | 283 params.params.sample_rate = sample_rate; |
280 params.params.bits_per_sample = 16; | 284 params.params.bits_per_sample = 16; |
281 params.params.samples_per_packet = sample_count; | 285 params.params.samples_per_packet = sample_count; |
282 | 286 |
283 stream_id_ = filter_->AddDelegate(this); | 287 stream_id_ = filter_->AddDelegate(this); |
288 AddRef(); // Take a reference for the filter. | |
289 | |
284 return filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, | 290 return filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, |
285 true)); | 291 true)); |
286 } | 292 } |
287 | 293 |
288 void PlatformAudioImpl::OnLowLatencyCreated( | 294 void PlatformAudioImpl::OnLowLatencyCreated( |
289 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, | 295 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, |
290 uint32 length) { | 296 uint32 length) { |
291 #if defined(OS_WIN) | 297 #if defined(OS_WIN) |
292 DCHECK(handle); | 298 DCHECK(handle); |
293 DCHECK(socket_handle); | 299 DCHECK(socket_handle); |
294 #else | 300 #else |
295 DCHECK_NE(-1, handle.fd); | 301 DCHECK_NE(-1, handle.fd); |
296 DCHECK_NE(-1, socket_handle); | 302 DCHECK_NE(-1, socket_handle); |
297 #endif | 303 #endif |
298 DCHECK(length); | 304 DCHECK(length); |
299 | 305 |
300 client_->StreamCreated(handle, length, socket_handle); | 306 if (MessageLoop::current() == main_message_loop_) { |
307 if (client_) { | |
308 client_->StreamCreated(handle, length, socket_handle); | |
309 } | |
310 } else { | |
311 main_message_loop_->PostTask(FROM_HERE, | |
312 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, | |
313 handle, socket_handle, length)); | |
314 } | |
301 } | 315 } |
302 | 316 |
303 void PlatformAudioImpl::ShutDown() { | 317 void PlatformAudioImpl::ShutDown() { |
304 // Make sure we don't call shutdown more than once. | 318 // Make sure we don't call shutdown more than once. |
305 if (!stream_id_) { | 319 if (!stream_id_) { |
306 return; | 320 return; |
307 } | 321 } |
308 filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); | 322 filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); |
309 filter_->RemoveDelegate(stream_id_); | 323 filter_->RemoveDelegate(stream_id_); |
324 // Release reference taken for the filter on the IO thread so that | |
325 // we avoid race problems with OnLowLatencyCreated. | |
326 filter_->message_loop()->ReleaseSoon(FROM_HERE, this); | |
brettw
2010/11/23 07:10:19
I'm confused about this since it looks like you're
nfullagar
2010/11/23 21:51:17
After talking with Darin, we removed one AddRef an
| |
327 | |
310 stream_id_ = 0; | 328 stream_id_ = 0; |
311 client_ = NULL; | 329 client_ = NULL; |
330 | |
331 Release(); // May end up deleting ourselves. | |
312 } | 332 } |
313 | 333 |
314 // Implements the VideoDecoder. | 334 // Implements the VideoDecoder. |
315 class PlatformVideoDecoderImpl | 335 class PlatformVideoDecoderImpl |
316 : public pepper::PluginDelegate::PlatformVideoDecoder { | 336 : public pepper::PluginDelegate::PlatformVideoDecoder { |
317 public: | 337 public: |
318 PlatformVideoDecoderImpl() | 338 PlatformVideoDecoderImpl() |
319 : input_buffer_size_(0), | 339 : input_buffer_size_(0), |
320 next_dib_id_(0), | 340 next_dib_id_(0), |
321 dib_(NULL) { | 341 dib_(NULL) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 | 573 |
554 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, | 574 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, |
555 int index) { | 575 int index) { |
556 render_view_->reportFindInPageSelection( | 576 render_view_->reportFindInPageSelection( |
557 identifier, index + 1, WebKit::WebRect()); | 577 identifier, index + 1, WebKit::WebRect()); |
558 } | 578 } |
559 | 579 |
560 pepper::PluginDelegate::PlatformAudio* PepperPluginDelegateImpl::CreateAudio( | 580 pepper::PluginDelegate::PlatformAudio* PepperPluginDelegateImpl::CreateAudio( |
561 uint32_t sample_rate, uint32_t sample_count, | 581 uint32_t sample_rate, uint32_t sample_count, |
562 pepper::PluginDelegate::PlatformAudio::Client* client) { | 582 pepper::PluginDelegate::PlatformAudio::Client* client) { |
563 scoped_ptr<PlatformAudioImpl> audio( | 583 scoped_refptr<PlatformAudioImpl> audio( |
564 new PlatformAudioImpl(render_view_->audio_message_filter())); | 584 new PlatformAudioImpl(render_view_->audio_message_filter())); |
565 if (audio->Initialize(sample_rate, sample_count, client)) { | 585 if (audio->Initialize(sample_rate, sample_count, client)) { |
566 return audio.release(); | 586 return audio.release(); |
567 } else { | 587 } else { |
568 return NULL; | 588 return NULL; |
569 } | 589 } |
570 } | 590 } |
571 | 591 |
572 bool PepperPluginDelegateImpl::RunFileChooser( | 592 bool PepperPluginDelegateImpl::RunFileChooser( |
573 const WebKit::WebFileChooserParams& params, | 593 const WebKit::WebFileChooserParams& params, |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 } | 844 } |
825 | 845 |
826 void PepperPluginDelegateImpl::DidStopLoading() { | 846 void PepperPluginDelegateImpl::DidStopLoading() { |
827 render_view_->DidStopLoadingForPlugin(); | 847 render_view_->DidStopLoadingForPlugin(); |
828 } | 848 } |
829 | 849 |
830 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { | 850 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { |
831 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( | 851 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( |
832 render_view_->routing_id(), restrictions)); | 852 render_view_->routing_id(), restrictions)); |
833 } | 853 } |
OLD | NEW |