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_impl.h" | 5 #include "content/renderer/pepper/pepper_platform_audio_output_impl.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_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "content/common/child_process.h" | 11 #include "content/common/child_process.h" |
12 #include "content/common/media/audio_messages.h" | 12 #include "content/common/media/audio_messages.h" |
13 #include "content/renderer/media/audio_hardware.h" | 13 #include "content/renderer/media/audio_hardware.h" |
14 #include "content/renderer/media/audio_message_filter.h" | 14 #include "content/renderer/media/audio_message_filter.h" |
| 15 #include "content/renderer/media/audio_output_ipc_impl.h" |
15 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 // static | 20 // static |
20 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( | 21 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( |
| 22 int render_view_id, |
21 int sample_rate, | 23 int sample_rate, |
22 int frames_per_buffer, | 24 int frames_per_buffer, |
23 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { | 25 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { |
24 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output( | 26 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output( |
25 new PepperPlatformAudioOutputImpl()); | 27 new PepperPlatformAudioOutputImpl(render_view_id)); |
26 if (audio_output->Initialize(sample_rate, frames_per_buffer, client)) { | 28 if (audio_output->Initialize(sample_rate, frames_per_buffer, client)) { |
27 // Balanced by Release invoked in | 29 // Balanced by Release invoked in |
28 // PepperPlatformAudioOutputImpl::ShutDownOnIOThread(). | 30 // PepperPlatformAudioOutputImpl::ShutDownOnIOThread(). |
29 return audio_output.release(); | 31 return audio_output.release(); |
30 } | 32 } |
31 return NULL; | 33 return NULL; |
32 } | 34 } |
33 | 35 |
34 bool PepperPlatformAudioOutputImpl::StartPlayback() { | 36 bool PepperPlatformAudioOutputImpl::StartPlayback() { |
35 if (ipc_) { | 37 if (ipc_.get()) { |
36 ChildProcess::current()->io_message_loop()->PostTask( | 38 ChildProcess::current()->io_message_loop()->PostTask( |
37 FROM_HERE, | 39 FROM_HERE, |
38 base::Bind(&PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread, | 40 base::Bind(&PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread, |
39 this)); | 41 this)); |
40 return true; | 42 return true; |
41 } | 43 } |
42 return false; | 44 return false; |
43 } | 45 } |
44 | 46 |
45 bool PepperPlatformAudioOutputImpl::StopPlayback() { | 47 bool PepperPlatformAudioOutputImpl::StopPlayback() { |
46 if (ipc_) { | 48 if (ipc_.get()) { |
47 ChildProcess::current()->io_message_loop()->PostTask( | 49 ChildProcess::current()->io_message_loop()->PostTask( |
48 FROM_HERE, | 50 FROM_HERE, |
49 base::Bind(&PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread, | 51 base::Bind(&PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread, |
50 this)); | 52 this)); |
51 return true; | 53 return true; |
52 } | 54 } |
53 return false; | 55 return false; |
54 } | 56 } |
55 | 57 |
56 void PepperPlatformAudioOutputImpl::ShutDown() { | 58 void PepperPlatformAudioOutputImpl::ShutDown() { |
(...skipping 28 matching lines...) Expand all Loading... |
85 if (client_) | 87 if (client_) |
86 client_->StreamCreated(handle, length, socket_handle); | 88 client_->StreamCreated(handle, length, socket_handle); |
87 } else { | 89 } else { |
88 main_message_loop_proxy_->PostTask(FROM_HERE, | 90 main_message_loop_proxy_->PostTask(FROM_HERE, |
89 base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this, | 91 base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this, |
90 handle, socket_handle, length)); | 92 handle, socket_handle, length)); |
91 } | 93 } |
92 } | 94 } |
93 | 95 |
94 void PepperPlatformAudioOutputImpl::OnIPCClosed() { | 96 void PepperPlatformAudioOutputImpl::OnIPCClosed() { |
95 ipc_ = NULL; | 97 ipc_.reset(); |
96 } | 98 } |
97 | 99 |
98 PepperPlatformAudioOutputImpl::~PepperPlatformAudioOutputImpl() { | 100 PepperPlatformAudioOutputImpl::~PepperPlatformAudioOutputImpl() { |
99 // Make sure we have been shut down. Warning: this will usually happen on | 101 // Make sure we have been shut down. Warning: this will usually happen on |
100 // the I/O thread! | 102 // the I/O thread! |
101 DCHECK_EQ(0, stream_id_); | 103 DCHECK_EQ(0, stream_id_); |
102 DCHECK(!client_); | 104 DCHECK(!client_); |
103 } | 105 } |
104 | 106 |
105 PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl() | 107 PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl( |
| 108 int render_view_id) |
106 : client_(NULL), | 109 : client_(NULL), |
107 stream_id_(0), | 110 stream_id_(0), |
108 main_message_loop_proxy_(base::MessageLoopProxy::current()) { | 111 main_message_loop_proxy_(base::MessageLoopProxy::current()) { |
109 ipc_ = RenderThreadImpl::current()->audio_message_filter(); | 112 ipc_.reset(new AudioOutputIPCImpl(render_view_id)); |
110 } | 113 } |
111 | 114 |
112 bool PepperPlatformAudioOutputImpl::Initialize( | 115 bool PepperPlatformAudioOutputImpl::Initialize( |
113 int sample_rate, | 116 int sample_rate, |
114 int frames_per_buffer, | 117 int frames_per_buffer, |
115 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { | 118 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { |
116 DCHECK(client); | 119 DCHECK(client); |
117 // Make sure we don't call init more than once. | 120 // Make sure we don't call init more than once. |
118 DCHECK_EQ(0, stream_id_); | 121 DCHECK_EQ(0, stream_id_); |
119 | 122 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 167 |
165 ipc_->CloseStream(stream_id_); | 168 ipc_->CloseStream(stream_id_); |
166 ipc_->RemoveDelegate(stream_id_); | 169 ipc_->RemoveDelegate(stream_id_); |
167 stream_id_ = 0; | 170 stream_id_ = 0; |
168 | 171 |
169 Release(); // Release for the delegate, balances out the reference taken in | 172 Release(); // Release for the delegate, balances out the reference taken in |
170 // PepperPluginDelegateImpl::CreateAudio. | 173 // PepperPluginDelegateImpl::CreateAudio. |
171 } | 174 } |
172 | 175 |
173 } // namespace content | 176 } // namespace content |
OLD | NEW |