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_audio_input_host.h" | 5 #include "content/renderer/pepper/pepper_audio_input_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "content/renderer/pepper/pepper_media_device_manager.h" | 9 #include "content/renderer/pepper/pepper_media_device_manager.h" |
10 #include "content/renderer/pepper/pepper_platform_audio_input.h" | 10 #include "content/renderer/pepper/pepper_platform_audio_input.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 void PepperAudioInputHost::StreamCreationFailed() { | 85 void PepperAudioInputHost::StreamCreationFailed() { |
86 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0, | 86 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0, |
87 base::SyncSocket::kInvalidHandle); | 87 base::SyncSocket::kInvalidHandle); |
88 } | 88 } |
89 | 89 |
90 int32_t PepperAudioInputHost::OnOpen( | 90 int32_t PepperAudioInputHost::OnOpen( |
91 ppapi::host::HostMessageContext* context, | 91 ppapi::host::HostMessageContext* context, |
92 const std::string& device_id, | 92 const std::string& device_id, |
93 PP_AudioSampleRate sample_rate, | 93 PP_AudioSampleRate sample_rate, |
94 uint32_t sample_frame_count) { | 94 uint32_t sample_frame_count) { |
95 if (open_context_) | 95 if (open_context_.is_valid()) |
96 return PP_ERROR_INPROGRESS; | 96 return PP_ERROR_INPROGRESS; |
97 if (audio_input_) | 97 if (audio_input_) |
98 return PP_ERROR_FAILED; | 98 return PP_ERROR_FAILED; |
99 | 99 |
100 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); | 100 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); |
101 if (!document_url.is_valid()) | 101 if (!document_url.is_valid()) |
102 return PP_ERROR_FAILED; | 102 return PP_ERROR_FAILED; |
103 | 103 |
104 // When it is done, we'll get called back on StreamCreated() or | 104 // When it is done, we'll get called back on StreamCreated() or |
105 // StreamCreationFailed(). | 105 // StreamCreationFailed(). |
106 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( | 106 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( |
107 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance())); | 107 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance())); |
108 | 108 |
109 audio_input_ = PepperPlatformAudioInput::Create( | 109 audio_input_ = PepperPlatformAudioInput::Create( |
110 render_view->AsWeakPtr(), device_id, | 110 render_view->AsWeakPtr(), device_id, |
111 document_url, | 111 document_url, |
112 static_cast<int>(sample_rate), | 112 static_cast<int>(sample_rate), |
113 static_cast<int>(sample_frame_count), this); | 113 static_cast<int>(sample_frame_count), this); |
114 if (audio_input_) { | 114 if (audio_input_) { |
115 open_context_.reset(new ppapi::host::ReplyMessageContext( | 115 open_context_ = context->MakeReplyMessageContext(); |
116 context->MakeReplyMessageContext())); | |
117 return PP_OK_COMPLETIONPENDING; | 116 return PP_OK_COMPLETIONPENDING; |
118 } else { | 117 } else { |
119 return PP_ERROR_FAILED; | 118 return PP_ERROR_FAILED; |
120 } | 119 } |
121 } | 120 } |
122 | 121 |
123 int32_t PepperAudioInputHost::OnStartOrStop( | 122 int32_t PepperAudioInputHost::OnStartOrStop( |
124 ppapi::host::HostMessageContext* /* context */, | 123 ppapi::host::HostMessageContext* /* context */, |
125 bool capture) { | 124 bool capture) { |
126 if (!audio_input_) | 125 if (!audio_input_) |
(...skipping 13 matching lines...) Expand all Loading... |
140 | 139 |
141 void PepperAudioInputHost::OnOpenComplete( | 140 void PepperAudioInputHost::OnOpenComplete( |
142 int32_t result, | 141 int32_t result, |
143 base::SharedMemoryHandle shared_memory_handle, | 142 base::SharedMemoryHandle shared_memory_handle, |
144 size_t shared_memory_size, | 143 size_t shared_memory_size, |
145 base::SyncSocket::Handle socket_handle) { | 144 base::SyncSocket::Handle socket_handle) { |
146 // Make sure the handles are cleaned up. | 145 // Make sure the handles are cleaned up. |
147 base::SyncSocket scoped_socket(socket_handle); | 146 base::SyncSocket scoped_socket(socket_handle); |
148 base::SharedMemory scoped_shared_memory(shared_memory_handle, false); | 147 base::SharedMemory scoped_shared_memory(shared_memory_handle, false); |
149 | 148 |
150 if (!open_context_) { | 149 if (!open_context_.is_valid()) { |
151 NOTREACHED(); | 150 NOTREACHED(); |
152 return; | 151 return; |
153 } | 152 } |
154 | 153 |
155 ppapi::proxy::SerializedHandle serialized_socket_handle( | 154 ppapi::proxy::SerializedHandle serialized_socket_handle( |
156 ppapi::proxy::SerializedHandle::SOCKET); | 155 ppapi::proxy::SerializedHandle::SOCKET); |
157 ppapi::proxy::SerializedHandle serialized_shared_memory_handle( | 156 ppapi::proxy::SerializedHandle serialized_shared_memory_handle( |
158 ppapi::proxy::SerializedHandle::SHARED_MEMORY); | 157 ppapi::proxy::SerializedHandle::SHARED_MEMORY); |
159 | 158 |
160 if (result == PP_OK) { | 159 if (result == PP_OK) { |
161 IPC::PlatformFileForTransit temp_socket = | 160 IPC::PlatformFileForTransit temp_socket = |
162 IPC::InvalidPlatformFileForTransit(); | 161 IPC::InvalidPlatformFileForTransit(); |
163 base::SharedMemoryHandle temp_shmem = base::SharedMemory::NULLHandle(); | 162 base::SharedMemoryHandle temp_shmem = base::SharedMemory::NULLHandle(); |
164 result = GetRemoteHandles( | 163 result = GetRemoteHandles( |
165 scoped_socket, scoped_shared_memory, &temp_socket, &temp_shmem); | 164 scoped_socket, scoped_shared_memory, &temp_socket, &temp_shmem); |
166 | 165 |
167 serialized_socket_handle.set_socket(temp_socket); | 166 serialized_socket_handle.set_socket(temp_socket); |
168 serialized_shared_memory_handle.set_shmem(temp_shmem, shared_memory_size); | 167 serialized_shared_memory_handle.set_shmem(temp_shmem, shared_memory_size); |
169 } | 168 } |
170 | 169 |
171 // Send all the values, even on error. This simplifies some of our cleanup | 170 // Send all the values, even on error. This simplifies some of our cleanup |
172 // code since the handles will be in the other process and could be | 171 // code since the handles will be in the other process and could be |
173 // inconvenient to clean up. Our IPC code will automatically handle this for | 172 // inconvenient to clean up. Our IPC code will automatically handle this for |
174 // us, as long as the remote side always closes the handles it receives, even | 173 // us, as long as the remote side always closes the handles it receives, even |
175 // in the failure case. | 174 // in the failure case. |
176 open_context_->params.set_result(result); | 175 open_context_.params.AppendHandle(serialized_socket_handle); |
177 open_context_->params.AppendHandle(serialized_socket_handle); | 176 open_context_.params.AppendHandle(serialized_shared_memory_handle); |
178 open_context_->params.AppendHandle(serialized_shared_memory_handle); | 177 SendOpenReply(result); |
179 | |
180 host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply()); | |
181 open_context_.reset(); | |
182 } | 178 } |
183 | 179 |
184 int32_t PepperAudioInputHost::GetRemoteHandles( | 180 int32_t PepperAudioInputHost::GetRemoteHandles( |
185 const base::SyncSocket& socket, | 181 const base::SyncSocket& socket, |
186 const base::SharedMemory& shared_memory, | 182 const base::SharedMemory& shared_memory, |
187 IPC::PlatformFileForTransit* remote_socket_handle, | 183 IPC::PlatformFileForTransit* remote_socket_handle, |
188 base::SharedMemoryHandle* remote_shared_memory_handle) { | 184 base::SharedMemoryHandle* remote_shared_memory_handle) { |
189 *remote_socket_handle = renderer_ppapi_host_->ShareHandleWithRemote( | 185 *remote_socket_handle = renderer_ppapi_host_->ShareHandleWithRemote( |
190 ConvertSyncSocketHandle(socket), false); | 186 ConvertSyncSocketHandle(socket), false); |
191 if (*remote_socket_handle == IPC::InvalidPlatformFileForTransit()) | 187 if (*remote_socket_handle == IPC::InvalidPlatformFileForTransit()) |
192 return PP_ERROR_FAILED; | 188 return PP_ERROR_FAILED; |
193 | 189 |
194 *remote_shared_memory_handle = renderer_ppapi_host_->ShareHandleWithRemote( | 190 *remote_shared_memory_handle = renderer_ppapi_host_->ShareHandleWithRemote( |
195 ConvertSharedMemoryHandle(shared_memory), false); | 191 ConvertSharedMemoryHandle(shared_memory), false); |
196 if (*remote_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) | 192 if (*remote_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
197 return PP_ERROR_FAILED; | 193 return PP_ERROR_FAILED; |
198 | 194 |
199 return PP_OK; | 195 return PP_OK; |
200 } | 196 } |
201 | 197 |
202 void PepperAudioInputHost::Close() { | 198 void PepperAudioInputHost::Close() { |
203 if (!audio_input_) | 199 if (!audio_input_) |
204 return; | 200 return; |
205 | 201 |
206 audio_input_->ShutDown(); | 202 audio_input_->ShutDown(); |
207 audio_input_ = NULL; | 203 audio_input_ = NULL; |
208 | 204 |
209 if (open_context_) { | 205 if (open_context_.is_valid()) |
210 open_context_->params.set_result(PP_ERROR_ABORTED); | 206 SendOpenReply(PP_ERROR_ABORTED); |
211 host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply()); | 207 } |
212 open_context_.reset(); | 208 |
213 } | 209 void PepperAudioInputHost::SendOpenReply(int32_t result) { |
| 210 open_context_.params.set_result(result); |
| 211 host()->SendReply(open_context_, PpapiPluginMsg_AudioInput_OpenReply()); |
| 212 open_context_ = ppapi::host::ReplyMessageContext(); |
214 } | 213 } |
215 | 214 |
216 } // namespace content | 215 } // namespace content |
217 | 216 |
OLD | NEW |