| 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/ppb_audio_input_proxy.h" | 5 #include "ppapi/proxy/ppb_audio_input_proxy.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/threading/simple_thread.h" | |
| 9 #include "ppapi/c/dev/ppb_audio_input_dev.h" | 8 #include "ppapi/c/dev/ppb_audio_input_dev.h" |
| 10 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 11 #include "ppapi/c/ppb_audio_config.h" | 10 #include "ppapi/c/ppb_audio_config.h" |
| 12 #include "ppapi/c/ppb_var.h" | |
| 13 #include "ppapi/c/trusted/ppb_audio_trusted.h" | |
| 14 #include "ppapi/proxy/enter_proxy.h" | 11 #include "ppapi/proxy/enter_proxy.h" |
| 15 #include "ppapi/proxy/plugin_dispatcher.h" | 12 #include "ppapi/proxy/plugin_dispatcher.h" |
| 16 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
| 17 #include "ppapi/shared_impl/api_id.h" | 14 #include "ppapi/shared_impl/api_id.h" |
| 18 #include "ppapi/shared_impl/platform_file.h" | 15 #include "ppapi/shared_impl/platform_file.h" |
| 19 #include "ppapi/shared_impl/ppapi_globals.h" | 16 #include "ppapi/shared_impl/ppapi_globals.h" |
| 20 #include "ppapi/shared_impl/ppb_audio_input_shared.h" | 17 #include "ppapi/shared_impl/ppb_audio_input_shared.h" |
| 21 #include "ppapi/shared_impl/resource.h" | 18 #include "ppapi/shared_impl/ppb_device_ref_shared.h" |
| 19 #include "ppapi/shared_impl/tracked_callback.h" |
| 22 #include "ppapi/thunk/enter.h" | 20 #include "ppapi/thunk/enter.h" |
| 23 #include "ppapi/thunk/ppb_audio_config_api.h" | |
| 24 #include "ppapi/thunk/resource_creation_api.h" | 21 #include "ppapi/thunk/resource_creation_api.h" |
| 25 #include "ppapi/thunk/thunk.h" | 22 #include "ppapi/thunk/thunk.h" |
| 26 | 23 |
| 27 using ppapi::IntToPlatformFile; | 24 using ppapi::IntToPlatformFile; |
| 28 using ppapi::thunk::EnterResourceNoLock; | |
| 29 using ppapi::thunk::PPB_AudioInput_API; | 25 using ppapi::thunk::PPB_AudioInput_API; |
| 30 using ppapi::thunk::PPB_AudioConfig_API; | |
| 31 | 26 |
| 32 namespace ppapi { | 27 namespace ppapi { |
| 33 namespace proxy { | 28 namespace proxy { |
| 34 | 29 |
| 35 class AudioInput : public Resource, public PPB_AudioInput_Shared { | 30 class AudioInput : public PPB_AudioInput_Shared { |
| 36 public: | 31 public: |
| 37 AudioInput(const HostResource& audio_input_id, | 32 explicit AudioInput(const HostResource& audio_input); |
| 38 PP_Resource config_id, | |
| 39 PPB_AudioInput_Callback callback, | |
| 40 void* user_data); | |
| 41 virtual ~AudioInput(); | 33 virtual ~AudioInput(); |
| 42 | 34 |
| 43 // Resource overrides. | 35 // Implementation of PPB_AudioInput_API trusted methods. |
| 44 virtual PPB_AudioInput_API* AsPPB_AudioInput_API() OVERRIDE; | 36 virtual int32_t OpenTrusted(const std::string& device_id, |
| 45 | 37 PP_Resource config, |
| 46 // PPB_AudioInput_API implementation. | |
| 47 virtual PP_Resource GetCurrentConfig() OVERRIDE; | |
| 48 virtual PP_Bool StartCapture() OVERRIDE; | |
| 49 virtual PP_Bool StopCapture() OVERRIDE; | |
| 50 | |
| 51 virtual int32_t OpenTrusted(PP_Resource config_id, | |
| 52 PP_CompletionCallback create_callback) OVERRIDE; | 38 PP_CompletionCallback create_callback) OVERRIDE; |
| 53 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; | 39 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; |
| 54 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; | 40 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; |
| 41 virtual const std::vector<DeviceRefData>& GetDeviceRefData() const OVERRIDE; |
| 55 | 42 |
| 56 private: | 43 private: |
| 57 // Owning reference to the current config object. This isn't actually used, | 44 // PPB_AudioInput_Shared implementation. |
| 58 // we just dish it out as requested by the plugin. | 45 virtual int32_t InternalEnumerateDevices( |
| 59 PP_Resource config_; | 46 PP_Resource* devices, |
| 47 PP_CompletionCallback callback) OVERRIDE; |
| 48 virtual int32_t InternalOpen(const std::string& device_id, |
| 49 PP_AudioSampleRate sample_rate, |
| 50 uint32_t sample_frame_count, |
| 51 PP_CompletionCallback callback) OVERRIDE; |
| 52 virtual PP_Bool InternalStartCapture() OVERRIDE; |
| 53 virtual PP_Bool InternalStopCapture() OVERRIDE; |
| 54 virtual void InternalClose() OVERRIDE; |
| 55 |
| 56 PluginDispatcher* GetDispatcher() const { |
| 57 return PluginDispatcher::GetForResource(this); |
| 58 } |
| 60 | 59 |
| 61 DISALLOW_COPY_AND_ASSIGN(AudioInput); | 60 DISALLOW_COPY_AND_ASSIGN(AudioInput); |
| 62 }; | 61 }; |
| 63 | 62 |
| 64 AudioInput::AudioInput(const HostResource& audio_input_id, | 63 AudioInput::AudioInput(const HostResource& audio_input) |
| 65 PP_Resource config_id, | 64 : PPB_AudioInput_Shared(audio_input) { |
| 66 PPB_AudioInput_Callback callback, | |
| 67 void* user_data) | |
| 68 : Resource(OBJECT_IS_PROXY, audio_input_id), | |
| 69 config_(config_id) { | |
| 70 SetCallback(callback, user_data); | |
| 71 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); | |
| 72 } | 65 } |
| 73 | 66 |
| 74 AudioInput::~AudioInput() { | 67 AudioInput::~AudioInput() { |
| 75 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(config_); | 68 Close(); |
| 76 } | 69 } |
| 77 | 70 |
| 78 PPB_AudioInput_API* AudioInput::AsPPB_AudioInput_API() { | 71 int32_t AudioInput::OpenTrusted(const std::string& device_id, |
| 79 return this; | 72 PP_Resource config, |
| 80 } | |
| 81 | |
| 82 PP_Resource AudioInput::GetCurrentConfig() { | |
| 83 // AddRef for the caller. | |
| 84 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); | |
| 85 return config_; | |
| 86 } | |
| 87 | |
| 88 PP_Bool AudioInput::StartCapture() { | |
| 89 if (capturing()) | |
| 90 return PP_TRUE; | |
| 91 SetStartCaptureState(); | |
| 92 PluginDispatcher::GetForResource(this)->Send( | |
| 93 new PpapiHostMsg_PPBAudioInput_StartOrStop( | |
| 94 API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), true)); | |
| 95 return PP_TRUE; | |
| 96 } | |
| 97 | |
| 98 PP_Bool AudioInput::StopCapture() { | |
| 99 if (!capturing()) | |
| 100 return PP_TRUE; | |
| 101 PluginDispatcher::GetForResource(this)->Send( | |
| 102 new PpapiHostMsg_PPBAudioInput_StartOrStop( | |
| 103 API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), false)); | |
| 104 SetStopCaptureState(); | |
| 105 return PP_TRUE; | |
| 106 } | |
| 107 | |
| 108 int32_t AudioInput::OpenTrusted(PP_Resource config_id, | |
| 109 PP_CompletionCallback create_callback) { | 73 PP_CompletionCallback create_callback) { |
| 110 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | 74 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 111 } | 75 } |
| 112 | 76 |
| 113 int32_t AudioInput::GetSyncSocket(int* sync_socket) { | 77 int32_t AudioInput::GetSyncSocket(int* sync_socket) { |
| 114 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | 78 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 115 } | 79 } |
| 116 | 80 |
| 117 int32_t AudioInput::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { | 81 int32_t AudioInput::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { |
| 118 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | 82 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 119 } | 83 } |
| 120 | 84 |
| 85 const std::vector<DeviceRefData>& AudioInput::GetDeviceRefData() const { |
| 86 // Don't proxy the trusted interface. |
| 87 static std::vector<DeviceRefData> result; |
| 88 return result; |
| 89 } |
| 90 |
| 91 int32_t AudioInput::InternalEnumerateDevices(PP_Resource* devices, |
| 92 PP_CompletionCallback callback) { |
| 93 devices_ = devices; |
| 94 enumerate_devices_callback_ = new TrackedCallback(this, callback); |
| 95 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_EnumerateDevices( |
| 96 API_ID_PPB_AUDIO_INPUT_DEV, host_resource())); |
| 97 return PP_OK_COMPLETIONPENDING; |
| 98 } |
| 99 |
| 100 int32_t AudioInput::InternalOpen(const std::string& device_id, |
| 101 PP_AudioSampleRate sample_rate, |
| 102 uint32_t sample_frame_count, |
| 103 PP_CompletionCallback callback) { |
| 104 open_callback_ = new TrackedCallback(this, callback); |
| 105 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_Open( |
| 106 API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), device_id, sample_rate, |
| 107 sample_frame_count)); |
| 108 return PP_OK_COMPLETIONPENDING; |
| 109 } |
| 110 |
| 111 PP_Bool AudioInput::InternalStartCapture() { |
| 112 SetStartCaptureState(); |
| 113 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_StartOrStop( |
| 114 API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), true)); |
| 115 return PP_TRUE; |
| 116 } |
| 117 |
| 118 PP_Bool AudioInput::InternalStopCapture() { |
| 119 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_StartOrStop( |
| 120 API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), false)); |
| 121 SetStopCaptureState(); |
| 122 return PP_TRUE; |
| 123 } |
| 124 |
| 125 void AudioInput::InternalClose() { |
| 126 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_Close( |
| 127 API_ID_PPB_AUDIO_INPUT_DEV, host_resource())); |
| 128 } |
| 129 |
| 121 PPB_AudioInput_Proxy::PPB_AudioInput_Proxy(Dispatcher* dispatcher) | 130 PPB_AudioInput_Proxy::PPB_AudioInput_Proxy(Dispatcher* dispatcher) |
| 122 : InterfaceProxy(dispatcher), | 131 : InterfaceProxy(dispatcher), |
| 123 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 132 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 124 } | 133 } |
| 125 | 134 |
| 126 PPB_AudioInput_Proxy::~PPB_AudioInput_Proxy() { | 135 PPB_AudioInput_Proxy::~PPB_AudioInput_Proxy() { |
| 127 } | 136 } |
| 128 | 137 |
| 129 // static | 138 // static |
| 139 PP_Resource PPB_AudioInput_Proxy::CreateProxyResource0_1( |
| 140 PP_Instance instance, |
| 141 PP_Resource config, |
| 142 PPB_AudioInput_Callback audio_input_callback, |
| 143 void* user_data) { |
| 144 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 145 if (!dispatcher) |
| 146 return 0; |
| 147 |
| 148 HostResource result; |
| 149 dispatcher->Send(new PpapiHostMsg_PPBAudioInput_Create( |
| 150 API_ID_PPB_AUDIO_INPUT_DEV, instance, &result)); |
| 151 if (result.is_null()) |
| 152 return 0; |
| 153 |
| 154 AudioInput* audio_input = new AudioInput(result); |
| 155 int32_t open_result = audio_input->Open("", config, audio_input_callback, |
| 156 user_data, AudioInput::MakeIgnoredCompletionCallback()); |
| 157 if (open_result != PP_OK && open_result != PP_OK_COMPLETIONPENDING) { |
| 158 delete audio_input; |
| 159 return 0; |
| 160 } |
| 161 return audio_input->GetReference(); |
| 162 } |
| 163 |
| 164 // static |
| 130 PP_Resource PPB_AudioInput_Proxy::CreateProxyResource( | 165 PP_Resource PPB_AudioInput_Proxy::CreateProxyResource( |
| 131 PP_Instance instance_id, | 166 PP_Instance instance) { |
| 132 PP_Resource config_id, | 167 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 133 PPB_AudioInput_Callback audio_input_callback, | |
| 134 void* user_data) { | |
| 135 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); | |
| 136 if (!dispatcher) | 168 if (!dispatcher) |
| 137 return 0; | 169 return 0; |
| 138 | 170 |
| 139 EnterResourceNoLock<PPB_AudioConfig_API> config(config_id, true); | |
| 140 if (config.failed()) | |
| 141 return 0; | |
| 142 | |
| 143 if (!audio_input_callback) | |
| 144 return 0; | |
| 145 | |
| 146 HostResource result; | 171 HostResource result; |
| 147 dispatcher->Send(new PpapiHostMsg_PPBAudioInput_Create( | 172 dispatcher->Send(new PpapiHostMsg_PPBAudioInput_Create( |
| 148 API_ID_PPB_AUDIO_INPUT_DEV, instance_id, | 173 API_ID_PPB_AUDIO_INPUT_DEV, instance, &result)); |
| 149 config.object()->GetSampleRate(), config.object()->GetSampleFrameCount(), | |
| 150 &result)); | |
| 151 if (result.is_null()) | 174 if (result.is_null()) |
| 152 return 0; | 175 return 0; |
| 153 | 176 |
| 154 return (new AudioInput(result, config_id, audio_input_callback, | 177 return (new AudioInput(result))->GetReference(); |
| 155 user_data))->GetReference(); | |
| 156 } | 178 } |
| 157 | 179 |
| 158 bool PPB_AudioInput_Proxy::OnMessageReceived(const IPC::Message& msg) { | 180 bool PPB_AudioInput_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 159 bool handled = true; | 181 bool handled = true; |
| 160 IPC_BEGIN_MESSAGE_MAP(PPB_AudioInput_Proxy, msg) | 182 IPC_BEGIN_MESSAGE_MAP(PPB_AudioInput_Proxy, msg) |
| 161 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioInput_Create, OnMsgCreate) | 183 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioInput_Create, OnMsgCreate) |
| 184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioInput_EnumerateDevices, |
| 185 OnMsgEnumerateDevices) |
| 186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioInput_Open, OnMsgOpen) |
| 162 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioInput_StartOrStop, | 187 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioInput_StartOrStop, |
| 163 OnMsgStartOrStop) | 188 OnMsgStartOrStop) |
| 164 IPC_MESSAGE_HANDLER(PpapiMsg_PPBAudioInput_NotifyAudioStreamCreated, | 189 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioInput_Close, OnMsgClose) |
| 165 OnMsgNotifyAudioStreamCreated) | 190 |
| 191 IPC_MESSAGE_HANDLER(PpapiMsg_PPBAudioInput_EnumerateDevicesACK, |
| 192 OnMsgEnumerateDevicesACK) |
| 193 IPC_MESSAGE_HANDLER(PpapiMsg_PPBAudioInput_OpenACK, OnMsgOpenACK) |
| 166 IPC_MESSAGE_UNHANDLED(handled = false) | 194 IPC_MESSAGE_UNHANDLED(handled = false) |
| 167 IPC_END_MESSAGE_MAP() | 195 IPC_END_MESSAGE_MAP() |
| 168 // TODO(brettw) handle bad messages! | 196 // TODO(brettw) handle bad messages! |
| 169 | 197 |
| 170 return handled; | 198 return handled; |
| 171 } | 199 } |
| 172 | 200 |
| 173 void PPB_AudioInput_Proxy::OnMsgCreate(PP_Instance instance_id, | 201 void PPB_AudioInput_Proxy::OnMsgCreate(PP_Instance instance, |
| 174 int32_t sample_rate, | |
| 175 uint32_t sample_frame_count, | |
| 176 HostResource* result) { | 202 HostResource* result) { |
| 177 thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation( | 203 thunk::EnterResourceCreation resource_creation(instance); |
| 178 instance_id, true); | 204 if (resource_creation.succeeded()) { |
| 179 if (resource_creation.failed()) | 205 result->SetHostResource( |
| 180 return; | 206 instance, resource_creation.functions()->CreateAudioInput(instance)); |
| 207 } |
| 208 } |
| 181 | 209 |
| 182 // Make the resource and get the API pointer to its trusted interface. | 210 void PPB_AudioInput_Proxy::OnMsgEnumerateDevices( |
| 183 result->SetHostResource( | 211 const ppapi::HostResource& audio_input) { |
| 184 instance_id, | 212 EnterHostFromHostResourceForceCallback<PPB_AudioInput_API> enter( |
| 185 resource_creation.functions()->CreateAudioInputTrusted(instance_id)); | 213 audio_input, callback_factory_, |
| 186 if (result->is_null()) | 214 &PPB_AudioInput_Proxy::EnumerateDevicesACKInHost, audio_input); |
| 187 return; | |
| 188 | 215 |
| 189 // At this point, we've set the result resource, and this is a sync request. | 216 if (enter.succeeded()) |
| 190 // Anything below this point must issue the AudioInputChannelConnected | 217 enter.SetResult(enter.object()->EnumerateDevices(NULL, enter.callback())); |
| 191 // callback to the browser. Since that's an async message, it will be issued | 218 } |
| 192 // back to the plugin after the Create function returns (which is good | 219 |
| 193 // because it would be weird to get a connected message with a failure code | 220 void PPB_AudioInput_Proxy::OnMsgOpen(const ppapi::HostResource& audio_input, |
| 194 // for a resource you haven't finished creating yet). | 221 const std::string& device_id, |
| 195 // | 222 int32_t sample_rate, |
| 223 uint32_t sample_frame_count) { |
| 196 // The ...ForceCallback class will help ensure the callback is always called. | 224 // The ...ForceCallback class will help ensure the callback is always called. |
| 197 // All error cases must call SetResult on this class. | 225 // All error cases must call SetResult on this class. |
| 198 | |
| 199 EnterHostFromHostResourceForceCallback<PPB_AudioInput_API> enter( | 226 EnterHostFromHostResourceForceCallback<PPB_AudioInput_API> enter( |
| 200 *result, callback_factory_, | 227 audio_input, callback_factory_, &PPB_AudioInput_Proxy::OpenACKInHost, |
| 201 &PPB_AudioInput_Proxy::AudioInputChannelConnected, *result); | 228 audio_input); |
| 202 if (enter.failed()) | 229 if (enter.failed()) |
| 203 return; // When enter fails, it will internally schedule the callback. | 230 return; // When enter fails, it will internally schedule the callback. |
| 204 | 231 |
| 232 thunk::EnterResourceCreation resource_creation(audio_input.instance()); |
| 205 // Make an audio config object. | 233 // Make an audio config object. |
| 206 PP_Resource audio_config_res = | 234 PP_Resource audio_config_res = |
| 207 resource_creation.functions()->CreateAudioConfig( | 235 resource_creation.functions()->CreateAudioConfig( |
| 208 instance_id, static_cast<PP_AudioSampleRate>(sample_rate), | 236 audio_input.instance(), static_cast<PP_AudioSampleRate>(sample_rate), |
| 209 sample_frame_count); | 237 sample_frame_count); |
| 210 if (!audio_config_res) { | 238 if (!audio_config_res) { |
| 211 enter.SetResult(PP_ERROR_FAILED); | 239 enter.SetResult(PP_ERROR_FAILED); |
| 212 return; | 240 return; |
| 213 } | 241 } |
| 214 | 242 |
| 215 // Initiate opening the audio object. | 243 // Initiate opening the audio object. |
| 216 enter.SetResult(enter.object()->OpenTrusted(audio_config_res, | 244 enter.SetResult(enter.object()->OpenTrusted( |
| 217 enter.callback())); | 245 device_id, audio_config_res, enter.callback())); |
| 218 | 246 |
| 219 // Clean up the temporary audio config resource we made. | 247 // Clean up the temporary audio config resource we made. |
| 220 const PPB_Core* core = static_cast<const PPB_Core*>( | 248 const PPB_Core* core = static_cast<const PPB_Core*>( |
| 221 dispatcher()->local_get_interface()(PPB_CORE_INTERFACE)); | 249 dispatcher()->local_get_interface()(PPB_CORE_INTERFACE)); |
| 222 core->ReleaseResource(audio_config_res); | 250 core->ReleaseResource(audio_config_res); |
| 223 } | 251 } |
| 224 | 252 |
| 225 void PPB_AudioInput_Proxy::OnMsgStartOrStop( | 253 void PPB_AudioInput_Proxy::OnMsgStartOrStop(const HostResource& audio_input, |
| 226 const HostResource& resource, | 254 bool capture) { |
| 227 bool capture) { | 255 EnterHostFromHostResource<PPB_AudioInput_API> enter(audio_input); |
| 228 EnterHostFromHostResource<PPB_AudioInput_API> enter(resource); | |
| 229 if (enter.failed()) | 256 if (enter.failed()) |
| 230 return; | 257 return; |
| 231 if (capture) | 258 if (capture) |
| 232 enter.object()->StartCapture(); | 259 enter.object()->StartCapture(); |
| 233 else | 260 else |
| 234 enter.object()->StopCapture(); | 261 enter.object()->StopCapture(); |
| 235 } | 262 } |
| 236 | 263 |
| 264 void PPB_AudioInput_Proxy::OnMsgClose(const ppapi::HostResource& audio_input) { |
| 265 EnterHostFromHostResource<PPB_AudioInput_API> enter(audio_input); |
| 266 if (enter.succeeded()) |
| 267 enter.object()->Close(); |
| 268 } |
| 269 |
| 237 // Processed in the plugin (message from host). | 270 // Processed in the plugin (message from host). |
| 238 void PPB_AudioInput_Proxy::OnMsgNotifyAudioStreamCreated( | 271 void PPB_AudioInput_Proxy::OnMsgEnumerateDevicesACK( |
| 239 const HostResource& audio_id, | 272 const ppapi::HostResource& audio_input, |
| 240 int32_t result_code, | 273 int32_t result, |
| 274 const std::vector<ppapi::DeviceRefData>& devices) { |
| 275 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); |
| 276 if (enter.succeeded()) { |
| 277 static_cast<AudioInput*>(enter.object())->OnEnumerateDevicesComplete( |
| 278 result, devices); |
| 279 } |
| 280 } |
| 281 |
| 282 void PPB_AudioInput_Proxy::OnMsgOpenACK( |
| 283 const HostResource& audio_input, |
| 284 int32_t result, |
| 241 IPC::PlatformFileForTransit socket_handle, | 285 IPC::PlatformFileForTransit socket_handle, |
| 242 base::SharedMemoryHandle handle, | 286 base::SharedMemoryHandle handle, |
| 243 uint32_t length) { | 287 uint32_t length) { |
| 244 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_id); | 288 EnterPluginFromHostResource<PPB_AudioInput_API> enter(audio_input); |
| 245 if (enter.failed() || result_code != PP_OK) { | 289 if (enter.failed()) { |
| 246 // The caller may still have given us these handles in the failure case. | 290 // The caller may still have given us these handles in the failure case. |
| 247 // The easiest way to clean these up is to just put them in the objects | 291 // The easiest way to clean these up is to just put them in the objects |
| 248 // and then close them. This failure case is not performance critical. | 292 // and then close them. This failure case is not performance critical. |
| 249 base::SyncSocket temp_socket( | 293 base::SyncSocket temp_socket( |
| 250 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | 294 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
| 251 base::SharedMemory temp_mem(handle, false); | 295 base::SharedMemory temp_mem(handle, false); |
| 252 } else { | 296 } else { |
| 253 static_cast<AudioInput*>(enter.object())->SetStreamInfo( | 297 static_cast<AudioInput*>(enter.object())->OnOpenComplete( |
| 254 handle, length, | 298 result, handle, length, |
| 255 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); | 299 IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
| 256 } | 300 } |
| 257 } | 301 } |
| 258 | 302 |
| 259 void PPB_AudioInput_Proxy::AudioInputChannelConnected( | 303 void PPB_AudioInput_Proxy::EnumerateDevicesACKInHost( |
| 260 int32_t result, | 304 int32_t result, |
| 261 const HostResource& resource) { | 305 const HostResource& audio_input) { |
| 306 EnterHostFromHostResource<PPB_AudioInput_API> enter(audio_input); |
| 307 dispatcher()->Send(new PpapiMsg_PPBAudioInput_EnumerateDevicesACK( |
| 308 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, |
| 309 enter.succeeded() && result == PP_OK ? |
| 310 enter.object()->GetDeviceRefData() : std::vector<DeviceRefData>())); |
| 311 } |
| 312 |
| 313 void PPB_AudioInput_Proxy::OpenACKInHost(int32_t result, |
| 314 const HostResource& audio_input) { |
| 262 IPC::PlatformFileForTransit socket_handle = | 315 IPC::PlatformFileForTransit socket_handle = |
| 263 IPC::InvalidPlatformFileForTransit(); | 316 IPC::InvalidPlatformFileForTransit(); |
| 264 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); | 317 base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); |
| 265 uint32_t shared_memory_length = 0; | 318 uint32_t shared_memory_length = 0; |
| 266 | 319 |
| 267 int32_t result_code = result; | 320 if (result == PP_OK) { |
| 268 if (result_code == PP_OK) { | 321 result = GetAudioInputConnectedHandles(audio_input, &socket_handle, |
| 269 result_code = GetAudioInputConnectedHandles(resource, &socket_handle, | |
| 270 &shared_memory, | 322 &shared_memory, |
| 271 &shared_memory_length); | 323 &shared_memory_length); |
| 272 } | 324 } |
| 273 | 325 |
| 274 // Send all the values, even on error. This simplifies some of our cleanup | 326 // Send all the values, even on error. This simplifies some of our cleanup |
| 275 // code since the handles will be in the other process and could be | 327 // code since the handles will be in the other process and could be |
| 276 // inconvenient to clean up. Our IPC code will automatically handle this for | 328 // inconvenient to clean up. Our IPC code will automatically handle this for |
| 277 // us, as long as the remote side always closes the handles it receives | 329 // us, as long as the remote side always closes the handles it receives |
| 278 // (in OnMsgNotifyAudioStreamCreated), even in the failure case. | 330 // (in OnMsgOpenACK), even in the failure case. |
| 279 dispatcher()->Send(new PpapiMsg_PPBAudioInput_NotifyAudioStreamCreated( | 331 dispatcher()->Send(new PpapiMsg_PPBAudioInput_OpenACK( |
| 280 API_ID_PPB_AUDIO_INPUT_DEV, resource, result_code, socket_handle, | 332 API_ID_PPB_AUDIO_INPUT_DEV, audio_input, result, socket_handle, |
| 281 shared_memory, shared_memory_length)); | 333 shared_memory, shared_memory_length)); |
| 282 } | 334 } |
| 283 | 335 |
| 284 int32_t PPB_AudioInput_Proxy::GetAudioInputConnectedHandles( | 336 int32_t PPB_AudioInput_Proxy::GetAudioInputConnectedHandles( |
| 285 const HostResource& resource, | 337 const HostResource& resource, |
| 286 IPC::PlatformFileForTransit* foreign_socket_handle, | 338 IPC::PlatformFileForTransit* foreign_socket_handle, |
| 287 base::SharedMemoryHandle* foreign_shared_memory_handle, | 339 base::SharedMemoryHandle* foreign_shared_memory_handle, |
| 288 uint32_t* shared_memory_length) { | 340 uint32_t* shared_memory_length) { |
| 289 // Get the audio interface which will give us the handles. | 341 // Get the audio interface which will give us the handles. |
| 290 EnterHostFromHostResource<PPB_AudioInput_API> enter(resource); | 342 EnterHostFromHostResource<PPB_AudioInput_API> enter(resource); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 314 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( | 366 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( |
| 315 IntToPlatformFile(shared_memory_handle), false); | 367 IntToPlatformFile(shared_memory_handle), false); |
| 316 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) | 368 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
| 317 return PP_ERROR_FAILED; | 369 return PP_ERROR_FAILED; |
| 318 | 370 |
| 319 return PP_OK; | 371 return PP_OK; |
| 320 } | 372 } |
| 321 | 373 |
| 322 } // namespace proxy | 374 } // namespace proxy |
| 323 } // namespace ppapi | 375 } // namespace ppapi |
| OLD | NEW |