Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: content/renderer/pepper_plugin_delegate_impl.cc

Issue 7157001: Implements AudioMessageFilter as member in RenderThread (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Added input message filter and audio input device Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.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/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/string_split.h" 15 #include "base/string_split.h"
16 #include "base/sync_socket.h" 16 #include "base/sync_socket.h"
17 #include "base/task.h" 17 #include "base/task.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "content/common/child_process_messages.h" 19 #include "content/common/child_process_messages.h"
20 #include "content/common/child_process.h"
20 #include "content/common/child_thread.h" 21 #include "content/common/child_thread.h"
21 #include "content/common/content_switches.h" 22 #include "content/common/content_switches.h"
22 #include "content/common/file_system/file_system_dispatcher.h" 23 #include "content/common/file_system/file_system_dispatcher.h"
23 #include "content/common/media/audio_messages.h" 24 #include "content/common/media/audio_messages.h"
24 #include "content/common/pepper_file_messages.h" 25 #include "content/common/pepper_file_messages.h"
25 #include "content/common/pepper_plugin_registry.h" 26 #include "content/common/pepper_plugin_registry.h"
26 #include "content/common/pepper_messages.h" 27 #include "content/common/pepper_messages.h"
27 #include "content/common/view_messages.h" 28 #include "content/common/view_messages.h"
28 #include "content/renderer/content_renderer_client.h" 29 #include "content/renderer/content_renderer_client.h"
29 #include "content/renderer/gpu/command_buffer_proxy.h" 30 #include "content/renderer/gpu/command_buffer_proxy.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 153
153 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); 154 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl);
154 }; 155 };
155 156
156 157
157 class PlatformAudioImpl 158 class PlatformAudioImpl
158 : public webkit::ppapi::PluginDelegate::PlatformAudio, 159 : public webkit::ppapi::PluginDelegate::PlatformAudio,
159 public AudioMessageFilter::Delegate, 160 public AudioMessageFilter::Delegate,
160 public base::RefCountedThreadSafe<PlatformAudioImpl> { 161 public base::RefCountedThreadSafe<PlatformAudioImpl> {
161 public: 162 public:
162 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) 163 explicit PlatformAudioImpl()
scherkus (not reviewing) 2011/07/07 21:26:47 drop explicit
henrika_dont_use 2011/07/08 12:47:58 Done.
163 : client_(NULL), filter_(filter), stream_id_(0), 164 : client_(NULL), stream_id_(0),
164 main_message_loop_(MessageLoop::current()) { 165 main_message_loop_(MessageLoop::current()) {
165 DCHECK(filter_); 166 filter_ = RenderThread::current()->audio_message_filter();
166 } 167 }
167 168
168 virtual ~PlatformAudioImpl() { 169 virtual ~PlatformAudioImpl() {
169 // Make sure we have been shut down. Warning: this will usually happen on 170 // Make sure we have been shut down. Warning: this will usually happen on
170 // the I/O thread! 171 // the I/O thread!
171 DCHECK_EQ(0, stream_id_); 172 DCHECK_EQ(0, stream_id_);
172 DCHECK(!client_); 173 DCHECK(!client_);
173 } 174 }
174 175
175 // Initialize this audio context. StreamCreated() will be called when the 176 // Initialize this audio context. StreamCreated() will be called when the
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 233
233 client_ = client; 234 client_ = client;
234 235
235 AudioParameters params; 236 AudioParameters params;
236 params.format = AudioParameters::AUDIO_PCM_LINEAR; 237 params.format = AudioParameters::AUDIO_PCM_LINEAR;
237 params.channels = 2; 238 params.channels = 2;
238 params.sample_rate = sample_rate; 239 params.sample_rate = sample_rate;
239 params.bits_per_sample = 16; 240 params.bits_per_sample = 16;
240 params.samples_per_packet = sample_count; 241 params.samples_per_packet = sample_count;
241 242
242 filter_->message_loop()->PostTask(FROM_HERE, 243 ChildProcess::current()->io_message_loop()->PostTask(
244 FROM_HERE,
243 NewRunnableMethod(this, &PlatformAudioImpl::InitializeOnIOThread, 245 NewRunnableMethod(this, &PlatformAudioImpl::InitializeOnIOThread,
244 params)); 246 params));
245 return true; 247 return true;
246 } 248 }
247 249
248 bool PlatformAudioImpl::StartPlayback() { 250 bool PlatformAudioImpl::StartPlayback() {
249 if (filter_) { 251 if (filter_) {
250 filter_->message_loop()->PostTask(FROM_HERE, 252 ChildProcess::current()->io_message_loop()->PostTask(
253 FROM_HERE,
251 NewRunnableMethod(this, &PlatformAudioImpl::StartPlaybackOnIOThread)); 254 NewRunnableMethod(this, &PlatformAudioImpl::StartPlaybackOnIOThread));
252 return true; 255 return true;
253 } 256 }
254 return false; 257 return false;
255 } 258 }
256 259
257 bool PlatformAudioImpl::StopPlayback() { 260 bool PlatformAudioImpl::StopPlayback() {
258 if (filter_) { 261 if (filter_) {
259 filter_->message_loop()->PostTask(FROM_HERE, 262 ChildProcess::current()->io_message_loop()->PostTask(
263 FROM_HERE,
260 NewRunnableMethod(this, &PlatformAudioImpl::StopPlaybackOnIOThread)); 264 NewRunnableMethod(this, &PlatformAudioImpl::StopPlaybackOnIOThread));
261 return true; 265 return true;
262 } 266 }
263 return false; 267 return false;
264 } 268 }
265 269
266 void PlatformAudioImpl::ShutDown() { 270 void PlatformAudioImpl::ShutDown() {
267 // Called on the main thread to stop all audio callbacks. We must only change 271 // Called on the main thread to stop all audio callbacks. We must only change
268 // the client on the main thread, and the delegates from the I/O thread. 272 // the client on the main thread, and the delegates from the I/O thread.
269 client_ = NULL; 273 client_ = NULL;
270 filter_->message_loop()->PostTask(FROM_HERE, 274 ChildProcess::current()->io_message_loop()->PostTask(
275 FROM_HERE,
271 NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread)); 276 NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread));
272 } 277 }
273 278
274 void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) { 279 void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) {
275 stream_id_ = filter_->AddDelegate(this); 280 stream_id_ = filter_->AddDelegate(this);
276 filter_->Send(new AudioHostMsg_CreateStream(0, stream_id_, params, true)); 281 filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params, true));
277 } 282 }
278 283
279 void PlatformAudioImpl::StartPlaybackOnIOThread() { 284 void PlatformAudioImpl::StartPlaybackOnIOThread() {
280 if (stream_id_) 285 if (stream_id_)
281 filter_->Send(new AudioHostMsg_PlayStream(0, stream_id_)); 286 filter_->Send(new AudioHostMsg_PlayStream(stream_id_));
282 } 287 }
283 288
284 void PlatformAudioImpl::StopPlaybackOnIOThread() { 289 void PlatformAudioImpl::StopPlaybackOnIOThread() {
285 if (stream_id_) 290 if (stream_id_)
286 filter_->Send(new AudioHostMsg_PauseStream(0, stream_id_)); 291 filter_->Send(new AudioHostMsg_PauseStream(stream_id_));
287 } 292 }
288 293
289 void PlatformAudioImpl::ShutDownOnIOThread() { 294 void PlatformAudioImpl::ShutDownOnIOThread() {
290 // Make sure we don't call shutdown more than once. 295 // Make sure we don't call shutdown more than once.
291 if (!stream_id_) 296 if (!stream_id_)
292 return; 297 return;
293 298
294 filter_->Send(new AudioHostMsg_CloseStream(0, stream_id_)); 299 filter_->Send(new AudioHostMsg_CloseStream(stream_id_));
295 filter_->RemoveDelegate(stream_id_); 300 filter_->RemoveDelegate(stream_id_);
296 stream_id_ = 0; 301 stream_id_ = 0;
297 302
298 Release(); // Release for the delegate, balances out the reference taken in 303 Release(); // Release for the delegate, balances out the reference taken in
299 // PepperPluginDelegateImpl::CreateAudio. 304 // PepperPluginDelegateImpl::CreateAudio.
300 } 305 }
301 306
302 void PlatformAudioImpl::OnLowLatencyCreated( 307 void PlatformAudioImpl::OnLowLatencyCreated(
303 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, 308 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle,
304 uint32 length) { 309 uint32 length) {
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, 849 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier,
845 int index) { 850 int index) {
846 render_view_->reportFindInPageSelection( 851 render_view_->reportFindInPageSelection(
847 identifier, index + 1, WebKit::WebRect()); 852 identifier, index + 1, WebKit::WebRect());
848 } 853 }
849 854
850 webkit::ppapi::PluginDelegate::PlatformAudio* 855 webkit::ppapi::PluginDelegate::PlatformAudio*
851 PepperPluginDelegateImpl::CreateAudio( 856 PepperPluginDelegateImpl::CreateAudio(
852 uint32_t sample_rate, uint32_t sample_count, 857 uint32_t sample_rate, uint32_t sample_count,
853 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { 858 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) {
854 scoped_refptr<PlatformAudioImpl> audio( 859 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl());
855 new PlatformAudioImpl(render_view_->audio_message_filter()));
856 if (audio->Initialize(sample_rate, sample_count, client)) { 860 if (audio->Initialize(sample_rate, sample_count, client)) {
857 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). 861 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread().
858 return audio.release(); 862 return audio.release();
859 } else { 863 } else {
860 return NULL; 864 return NULL;
861 } 865 }
862 } 866 }
863 867
864 // If a broker has not already been created for this plugin, creates one. 868 // If a broker has not already been created for this plugin, creates one.
865 webkit::ppapi::PluginDelegate::PpapiBroker* 869 webkit::ppapi::PluginDelegate::PpapiBroker*
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 } 988 }
985 989
986 bool PepperPluginDelegateImpl::ReadDirectory( 990 bool PepperPluginDelegateImpl::ReadDirectory(
987 const GURL& directory_path, 991 const GURL& directory_path,
988 fileapi::FileSystemCallbackDispatcher* dispatcher) { 992 fileapi::FileSystemCallbackDispatcher* dispatcher) {
989 FileSystemDispatcher* file_system_dispatcher = 993 FileSystemDispatcher* file_system_dispatcher =
990 ChildThread::current()->file_system_dispatcher(); 994 ChildThread::current()->file_system_dispatcher();
991 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); 995 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher);
992 } 996 }
993 997
994 class AsyncOpenFileSystemURLCallbackTranslator : 998 class AsyncOpenFileSystemURLCallbackTranslator
995 public fileapi::FileSystemCallbackDispatcher { 999 : public fileapi::FileSystemCallbackDispatcher {
996 public: 1000 public:
997 AsyncOpenFileSystemURLCallbackTranslator( 1001 AsyncOpenFileSystemURLCallbackTranslator(
998 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback) 1002 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback)
999 : callback_(callback) { 1003 : callback_(callback) {
1000 } 1004 }
1001 1005
1002 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} 1006 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {}
1003 1007
1004 virtual void DidSucceed() { 1008 virtual void DidSucceed() {
1005 NOTREACHED(); 1009 NOTREACHED();
1006 } 1010 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 if (!base::SharedMemory::IsHandleValid(handle)) { 1334 if (!base::SharedMemory::IsHandleValid(handle)) {
1331 DLOG(WARNING) << "Browser failed to allocate shared memory"; 1335 DLOG(WARNING) << "Browser failed to allocate shared memory";
1332 return NULL; 1336 return NULL;
1333 } 1337 }
1334 return new base::SharedMemory(handle, false); 1338 return new base::SharedMemory(handle, false);
1335 } 1339 }
1336 1340
1337 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { 1341 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() {
1338 return ppapi::Preferences(render_view_->webkit_preferences()); 1342 return ppapi::Preferences(render_view_->webkit_preferences());
1339 } 1343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698