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 "ppapi/proxy/audio_input_resource.h" | 5 #include "ppapi/proxy/audio_input_resource.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 "ipc/ipc_platform_file.h" | 9 #include "ipc/ipc_platform_file.h" |
10 #include "media/audio/audio_parameters.h" | 10 #include "media/audio/audio_parameters.h" |
11 #include "media/audio/shared_memory_util.h" | 11 #include "media/audio/shared_memory_util.h" |
12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
14 #include "ppapi/proxy/resource_message_params.h" | 14 #include "ppapi/proxy/resource_message_params.h" |
15 #include "ppapi/proxy/serialized_structs.h" | 15 #include "ppapi/proxy/serialized_structs.h" |
16 #include "ppapi/shared_impl/ppapi_globals.h" | 16 #include "ppapi/shared_impl/ppapi_globals.h" |
17 #include "ppapi/shared_impl/ppb_device_ref_shared.h" | |
18 #include "ppapi/shared_impl/resource_tracker.h" | 17 #include "ppapi/shared_impl/resource_tracker.h" |
19 #include "ppapi/shared_impl/tracked_callback.h" | 18 #include "ppapi/shared_impl/tracked_callback.h" |
20 #include "ppapi/thunk/enter.h" | 19 #include "ppapi/thunk/enter.h" |
21 #include "ppapi/thunk/ppb_audio_config_api.h" | 20 #include "ppapi/thunk/ppb_audio_config_api.h" |
22 | 21 |
23 namespace ppapi { | 22 namespace ppapi { |
24 namespace proxy { | 23 namespace proxy { |
25 | 24 |
26 AudioInputResource::AudioInputResource( | 25 AudioInputResource::AudioInputResource( |
27 Connection connection, | 26 Connection connection, |
28 PP_Instance instance) | 27 PP_Instance instance) |
29 : PluginResource(connection, instance), | 28 : PluginResource(connection, instance), |
30 open_state_(BEFORE_OPEN), | 29 open_state_(BEFORE_OPEN), |
31 capturing_(false), | 30 capturing_(false), |
32 shared_memory_size_(0), | 31 shared_memory_size_(0), |
33 audio_input_callback_(NULL), | 32 audio_input_callback_(NULL), |
34 user_data_(NULL), | 33 user_data_(NULL), |
35 pending_enumerate_devices_(false) { | 34 ALLOW_THIS_IN_INITIALIZER_LIST(enumeration_helper_(this)) { |
36 SendCreate(RENDERER, PpapiHostMsg_AudioInput_Create()); | 35 SendCreate(RENDERER, PpapiHostMsg_AudioInput_Create()); |
37 } | 36 } |
38 | 37 |
39 AudioInputResource::~AudioInputResource() { | 38 AudioInputResource::~AudioInputResource() { |
40 Close(); | 39 Close(); |
41 } | 40 } |
42 | 41 |
43 thunk::PPB_AudioInput_API* AudioInputResource::AsPPB_AudioInput_API() { | 42 thunk::PPB_AudioInput_API* AudioInputResource::AsPPB_AudioInput_API() { |
44 return this; | 43 return this; |
45 } | 44 } |
46 | 45 |
47 int32_t AudioInputResource::EnumerateDevices( | 46 void AudioInputResource::OnReplyReceived( |
| 47 const ResourceMessageReplyParams& params, |
| 48 const IPC::Message& msg) { |
| 49 if (!enumeration_helper_.HandleReply(params, msg)) |
| 50 PluginResource::OnReplyReceived(params, msg); |
| 51 } |
| 52 |
| 53 int32_t AudioInputResource::EnumerateDevices0_2( |
48 PP_Resource* devices, | 54 PP_Resource* devices, |
49 scoped_refptr<TrackedCallback> callback) { | 55 scoped_refptr<TrackedCallback> callback) { |
50 if (pending_enumerate_devices_) | 56 return enumeration_helper_.EnumerateDevices0_2(devices, callback); |
51 return PP_ERROR_INPROGRESS; | 57 } |
52 if (!devices) | |
53 return PP_ERROR_BADARGUMENT; | |
54 | 58 |
55 pending_enumerate_devices_ = true; | 59 int32_t AudioInputResource::EnumerateDevices( |
56 PpapiHostMsg_AudioInput_EnumerateDevices msg; | 60 const PP_ArrayOutput& output, |
57 Call<PpapiPluginMsg_AudioInput_EnumerateDevicesReply>( | 61 scoped_refptr<TrackedCallback> callback) { |
58 RENDERER, msg, | 62 return enumeration_helper_.EnumerateDevices(output, callback); |
59 base::Bind(&AudioInputResource::OnPluginMsgEnumerateDevicesReply, | 63 } |
60 base::Unretained(this), devices, callback)); | 64 |
61 return PP_OK_COMPLETIONPENDING; | 65 int32_t AudioInputResource::MonitorDeviceChange( |
| 66 PP_MonitorDeviceChangeCallback callback, |
| 67 void* user_data) { |
| 68 return enumeration_helper_.MonitorDeviceChange(callback, user_data); |
62 } | 69 } |
63 | 70 |
64 int32_t AudioInputResource::Open(const std::string& device_id, | 71 int32_t AudioInputResource::Open(const std::string& device_id, |
65 PP_Resource config, | 72 PP_Resource config, |
66 PPB_AudioInput_Callback audio_input_callback, | 73 PPB_AudioInput_Callback audio_input_callback, |
67 void* user_data, | 74 void* user_data, |
68 scoped_refptr<TrackedCallback> callback) { | 75 scoped_refptr<TrackedCallback> callback) { |
69 if (TrackedCallback::IsPending(open_callback_)) | 76 if (TrackedCallback::IsPending(open_callback_)) |
70 return PP_ERROR_INPROGRESS; | 77 return PP_ERROR_INPROGRESS; |
71 if (open_state_ != BEFORE_OPEN) | 78 if (open_state_ != BEFORE_OPEN) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 return; | 153 return; |
147 | 154 |
148 open_state_ = CLOSED; | 155 open_state_ = CLOSED; |
149 Post(RENDERER, PpapiHostMsg_AudioInput_Close()); | 156 Post(RENDERER, PpapiHostMsg_AudioInput_Close()); |
150 StopThread(); | 157 StopThread(); |
151 | 158 |
152 if (TrackedCallback::IsPending(open_callback_)) | 159 if (TrackedCallback::IsPending(open_callback_)) |
153 open_callback_->PostAbort(); | 160 open_callback_->PostAbort(); |
154 } | 161 } |
155 | 162 |
156 void AudioInputResource::OnPluginMsgEnumerateDevicesReply( | 163 void AudioInputResource::LastPluginRefWasDeleted() { |
157 PP_Resource* devices_resource, | 164 enumeration_helper_.LastPluginRefWasDeleted(); |
158 scoped_refptr<TrackedCallback> callback, | |
159 const ResourceMessageReplyParams& params, | |
160 const std::vector<DeviceRefData>& devices) { | |
161 pending_enumerate_devices_ = false; | |
162 | |
163 // We shouldn't access |devices_resource| if the callback has been called, | |
164 // which is possible if the last plugin reference to this resource has gone | |
165 // away, and the callback has been aborted. | |
166 if (!TrackedCallback::IsPending(callback)) | |
167 return; | |
168 | |
169 if (params.result() == PP_OK) { | |
170 *devices_resource = PPB_DeviceRef_Shared::CreateResourceArray( | |
171 OBJECT_IS_PROXY, pp_instance(), devices); | |
172 } | |
173 | |
174 callback->Run(params.result()); | |
175 } | 165 } |
176 | 166 |
177 void AudioInputResource::OnPluginMsgOpenReply( | 167 void AudioInputResource::OnPluginMsgOpenReply( |
178 const ResourceMessageReplyParams& params) { | 168 const ResourceMessageReplyParams& params) { |
179 if (open_state_ == BEFORE_OPEN && params.result() == PP_OK) { | 169 if (open_state_ == BEFORE_OPEN && params.result() == PP_OK) { |
180 IPC::PlatformFileForTransit socket_handle_for_transit = | 170 IPC::PlatformFileForTransit socket_handle_for_transit = |
181 IPC::InvalidPlatformFileForTransit(); | 171 IPC::InvalidPlatformFileForTransit(); |
182 params.TakeSocketHandleAtIndex(0, &socket_handle_for_transit); | 172 params.TakeSocketHandleAtIndex(0, &socket_handle_for_transit); |
183 base::SyncSocket::Handle socket_handle = | 173 base::SyncSocket::Handle socket_handle = |
184 IPC::PlatformFileForTransitToPlatformFile(socket_handle_for_transit); | 174 IPC::PlatformFileForTransitToPlatformFile(socket_handle_for_transit); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // While closing the stream, we may receive buffers whose size is different | 256 // While closing the stream, we may receive buffers whose size is different |
267 // from |data_buffer_size|. | 257 // from |data_buffer_size|. |
268 CHECK_LE(buffer->params.size, data_buffer_size); | 258 CHECK_LE(buffer->params.size, data_buffer_size); |
269 if (buffer->params.size > 0) | 259 if (buffer->params.size > 0) |
270 audio_input_callback_(&buffer->audio[0], buffer->params.size, user_data_); | 260 audio_input_callback_(&buffer->audio[0], buffer->params.size, user_data_); |
271 } | 261 } |
272 } | 262 } |
273 | 263 |
274 } // namespace proxy | 264 } // namespace proxy |
275 } // namespace ppapi | 265 } // namespace ppapi |
OLD | NEW |