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/render_thread_impl.h" | 15 #include "content/renderer/render_thread_impl.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 // static | 19 // static |
19 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( | 20 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( |
20 int sample_rate, | 21 int sample_rate, |
21 int frames_per_buffer, | 22 int frames_per_buffer, |
22 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { | 23 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { |
23 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output( | 24 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output( |
24 new PepperPlatformAudioOutputImpl); | 25 new PepperPlatformAudioOutputImpl); |
25 if (audio_output->Initialize(sample_rate, frames_per_buffer, client)) { | 26 if (audio_output->Initialize(sample_rate, frames_per_buffer, client)) { |
26 // Balanced by Release invoked in | 27 // Balanced by Release invoked in |
27 // PepperPlatformAudioOutputImpl::ShutDownOnIOThread(). | 28 // PepperPlatformAudioOutputImpl::ShutDownOnIOThread(). |
28 return audio_output.release(); | 29 return audio_output.release(); |
29 } | 30 } |
30 return NULL; | 31 return NULL; |
31 } | 32 } |
32 | 33 |
33 bool PepperPlatformAudioOutputImpl::StartPlayback() { | 34 bool PepperPlatformAudioOutputImpl::StartPlayback() { |
34 if (filter_) { | 35 if (ipc_) { |
35 ChildProcess::current()->io_message_loop()->PostTask( | 36 ChildProcess::current()->io_message_loop()->PostTask( |
36 FROM_HERE, | 37 FROM_HERE, |
37 base::Bind(&PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread, | 38 base::Bind(&PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread, |
38 this)); | 39 this)); |
39 return true; | 40 return true; |
40 } | 41 } |
41 return false; | 42 return false; |
42 } | 43 } |
43 | 44 |
44 bool PepperPlatformAudioOutputImpl::StopPlayback() { | 45 bool PepperPlatformAudioOutputImpl::StopPlayback() { |
45 if (filter_) { | 46 if (ipc_) { |
46 ChildProcess::current()->io_message_loop()->PostTask( | 47 ChildProcess::current()->io_message_loop()->PostTask( |
47 FROM_HERE, | 48 FROM_HERE, |
48 base::Bind(&PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread, | 49 base::Bind(&PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread, |
49 this)); | 50 this)); |
50 return true; | 51 return true; |
51 } | 52 } |
52 return false; | 53 return false; |
53 } | 54 } |
54 | 55 |
55 void PepperPlatformAudioOutputImpl::ShutDown() { | 56 void PepperPlatformAudioOutputImpl::ShutDown() { |
56 // Called on the main thread to stop all audio callbacks. We must only change | 57 // Called on the main thread to stop all audio callbacks. We must only change |
57 // the client on the main thread, and the delegates from the I/O thread. | 58 // the client on the main thread, and the delegates from the I/O thread. |
58 client_ = NULL; | 59 client_ = NULL; |
59 ChildProcess::current()->io_message_loop()->PostTask( | 60 ChildProcess::current()->io_message_loop()->PostTask( |
60 FROM_HERE, | 61 FROM_HERE, |
61 base::Bind(&PepperPlatformAudioOutputImpl::ShutDownOnIOThread, this)); | 62 base::Bind(&PepperPlatformAudioOutputImpl::ShutDownOnIOThread, this)); |
62 } | 63 } |
63 | 64 |
64 void PepperPlatformAudioOutputImpl::OnStateChanged(AudioStreamState state) {} | 65 void PepperPlatformAudioOutputImpl::OnStateChanged( |
| 66 media::AudioStreamState state) { |
| 67 } |
65 | 68 |
66 void PepperPlatformAudioOutputImpl::OnStreamCreated( | 69 void PepperPlatformAudioOutputImpl::OnStreamCreated( |
67 base::SharedMemoryHandle handle, | 70 base::SharedMemoryHandle handle, |
68 base::SyncSocket::Handle socket_handle, | 71 base::SyncSocket::Handle socket_handle, |
69 uint32 length) { | 72 uint32 length) { |
70 #if defined(OS_WIN) | 73 #if defined(OS_WIN) |
71 DCHECK(handle); | 74 DCHECK(handle); |
72 DCHECK(socket_handle); | 75 DCHECK(socket_handle); |
73 #else | 76 #else |
74 DCHECK_NE(-1, handle.fd); | 77 DCHECK_NE(-1, handle.fd); |
(...skipping 17 matching lines...) Expand all Loading... |
92 // Make sure we have been shut down. Warning: this will usually happen on | 95 // Make sure we have been shut down. Warning: this will usually happen on |
93 // the I/O thread! | 96 // the I/O thread! |
94 DCHECK_EQ(0, stream_id_); | 97 DCHECK_EQ(0, stream_id_); |
95 DCHECK(!client_); | 98 DCHECK(!client_); |
96 } | 99 } |
97 | 100 |
98 PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl() | 101 PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl() |
99 : client_(NULL), | 102 : client_(NULL), |
100 stream_id_(0), | 103 stream_id_(0), |
101 main_message_loop_proxy_(base::MessageLoopProxy::current()) { | 104 main_message_loop_proxy_(base::MessageLoopProxy::current()) { |
102 filter_ = RenderThreadImpl::current()->audio_message_filter(); | 105 ipc_ = RenderThreadImpl::current()->audio_message_filter(); |
103 } | 106 } |
104 | 107 |
105 bool PepperPlatformAudioOutputImpl::Initialize( | 108 bool PepperPlatformAudioOutputImpl::Initialize( |
106 int sample_rate, | 109 int sample_rate, |
107 int frames_per_buffer, | 110 int frames_per_buffer, |
108 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { | 111 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { |
109 DCHECK(client); | 112 DCHECK(client); |
110 // Make sure we don't call init more than once. | 113 // Make sure we don't call init more than once. |
111 DCHECK_EQ(0, stream_id_); | 114 DCHECK_EQ(0, stream_id_); |
112 | 115 |
(...skipping 16 matching lines...) Expand all Loading... |
129 | 132 |
130 ChildProcess::current()->io_message_loop()->PostTask( | 133 ChildProcess::current()->io_message_loop()->PostTask( |
131 FROM_HERE, | 134 FROM_HERE, |
132 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread, | 135 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread, |
133 this, params)); | 136 this, params)); |
134 return true; | 137 return true; |
135 } | 138 } |
136 | 139 |
137 void PepperPlatformAudioOutputImpl::InitializeOnIOThread( | 140 void PepperPlatformAudioOutputImpl::InitializeOnIOThread( |
138 const media::AudioParameters& params) { | 141 const media::AudioParameters& params) { |
139 stream_id_ = filter_->AddDelegate(this); | 142 stream_id_ = ipc_->AddDelegate(this); |
140 filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params)); | 143 ipc_->CreateStream(stream_id_, params); |
141 } | 144 } |
142 | 145 |
143 void PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread() { | 146 void PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread() { |
144 if (stream_id_) | 147 if (stream_id_) |
145 filter_->Send(new AudioHostMsg_PlayStream(stream_id_)); | 148 ipc_->PlayStream(stream_id_); |
146 } | 149 } |
147 | 150 |
148 void PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread() { | 151 void PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread() { |
149 if (stream_id_) | 152 if (stream_id_) |
150 filter_->Send(new AudioHostMsg_PauseStream(stream_id_)); | 153 ipc_->PauseStream(stream_id_); |
151 } | 154 } |
152 | 155 |
153 void PepperPlatformAudioOutputImpl::ShutDownOnIOThread() { | 156 void PepperPlatformAudioOutputImpl::ShutDownOnIOThread() { |
154 // Make sure we don't call shutdown more than once. | 157 // Make sure we don't call shutdown more than once. |
155 if (!stream_id_) | 158 if (!stream_id_) |
156 return; | 159 return; |
157 | 160 |
158 filter_->Send(new AudioHostMsg_CloseStream(stream_id_)); | 161 ipc_->CloseStream(stream_id_); |
159 filter_->RemoveDelegate(stream_id_); | 162 ipc_->RemoveDelegate(stream_id_); |
160 stream_id_ = 0; | 163 stream_id_ = 0; |
161 | 164 |
162 Release(); // Release for the delegate, balances out the reference taken in | 165 Release(); // Release for the delegate, balances out the reference taken in |
163 // PepperPluginDelegateImpl::CreateAudio. | 166 // PepperPluginDelegateImpl::CreateAudio. |
164 } | 167 } |
165 | 168 |
166 } // namespace content | 169 } // namespace content |
OLD | NEW |