[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ppapi/proxy/ppb_audio_proxy.h" |
| 6 | |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 7 | #include "base/compiler_specific.h" |
[email protected] | ac9ba8fe | 2010-12-30 18:08:36 | [diff] [blame] | 8 | #include "base/threading/simple_thread.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 9 | #include "ppapi/c/pp_errors.h" |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 10 | #include "ppapi/c/ppb_audio.h" |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 11 | #include "ppapi/c/ppb_audio_config.h" |
| 12 | #include "ppapi/c/ppb_var.h" |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 13 | #include "ppapi/c/trusted/ppb_audio_trusted.h" |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 14 | #include "ppapi/proxy/enter_proxy.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 15 | #include "ppapi/proxy/interface_id.h" |
| 16 | #include "ppapi/proxy/plugin_dispatcher.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 17 | #include "ppapi/proxy/ppapi_messages.h" |
| 18 | #include "ppapi/shared_impl/audio_impl.h" |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame^] | 19 | #include "ppapi/shared_impl/ppapi_globals.h" |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 20 | #include "ppapi/shared_impl/resource.h" |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 21 | #include "ppapi/thunk/ppb_audio_config_api.h" |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 22 | #include "ppapi/thunk/enter.h" |
| 23 | #include "ppapi/thunk/resource_creation_api.h" |
| 24 | #include "ppapi/thunk/thunk.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 25 | |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 26 | using ppapi::thunk::EnterResourceNoLock; |
| 27 | using ppapi::thunk::PPB_Audio_API; |
| 28 | using ppapi::thunk::PPB_AudioConfig_API; |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 29 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 30 | namespace ppapi { |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 31 | namespace proxy { |
| 32 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 33 | class Audio : public Resource, public AudioImpl { |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 34 | public: |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 35 | Audio(const HostResource& audio_id, |
[email protected] | 4614f19 | 2011-01-21 00:26:43 | [diff] [blame] | 36 | PP_Resource config_id, |
| 37 | PPB_Audio_Callback callback, |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 38 | void* user_data); |
| 39 | virtual ~Audio(); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 40 | |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 41 | // Resource overrides. |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 42 | virtual PPB_Audio_API* AsPPB_Audio_API(); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 43 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 44 | // PPB_Audio_API implementation. |
| 45 | virtual PP_Resource GetCurrentConfig() OVERRIDE; |
| 46 | virtual PP_Bool StartPlayback() OVERRIDE; |
| 47 | virtual PP_Bool StopPlayback() OVERRIDE; |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 48 | virtual int32_t OpenTrusted(PP_Resource config_id, |
| 49 | PP_CompletionCallback create_callback) OVERRIDE; |
| 50 | virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; |
| 51 | virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 52 | |
| 53 | private: |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 54 | // Owning reference to the current config object. This isn't actually used, |
| 55 | // we just dish it out as requested by the plugin. |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 56 | PP_Resource config_; |
| 57 | |
| 58 | DISALLOW_COPY_AND_ASSIGN(Audio); |
| 59 | }; |
| 60 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 61 | Audio::Audio(const HostResource& audio_id, |
| 62 | PP_Resource config_id, |
| 63 | PPB_Audio_Callback callback, |
| 64 | void* user_data) |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 65 | : Resource(audio_id), |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 66 | config_(config_id) { |
| 67 | SetCallback(callback, user_data); |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame^] | 68 | PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | Audio::~Audio() { |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame^] | 72 | PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(config_); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 73 | } |
| 74 | |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 75 | PPB_Audio_API* Audio::AsPPB_Audio_API() { |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 76 | return this; |
| 77 | } |
| 78 | |
| 79 | PP_Resource Audio::GetCurrentConfig() { |
| 80 | // AddRef for the caller. |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame^] | 81 | PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 82 | return config_; |
| 83 | } |
| 84 | |
| 85 | PP_Bool Audio::StartPlayback() { |
| 86 | if (playing()) |
| 87 | return PP_TRUE; |
| 88 | SetStartPlaybackState(); |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 89 | PluginDispatcher::GetForResource(this)->Send( |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 90 | new PpapiHostMsg_PPBAudio_StartOrStop( |
| 91 | INTERFACE_ID_PPB_AUDIO, host_resource(), true)); |
| 92 | return PP_TRUE; |
| 93 | } |
| 94 | |
| 95 | PP_Bool Audio::StopPlayback() { |
| 96 | if (!playing()) |
| 97 | return PP_TRUE; |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 98 | PluginDispatcher::GetForResource(this)->Send( |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 99 | new PpapiHostMsg_PPBAudio_StartOrStop( |
| 100 | INTERFACE_ID_PPB_AUDIO, host_resource(), false)); |
| 101 | SetStopPlaybackState(); |
| 102 | return PP_TRUE; |
| 103 | } |
| 104 | |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 105 | int32_t Audio::OpenTrusted(PP_Resource config_id, |
| 106 | PP_CompletionCallback create_callback) { |
| 107 | return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 108 | } |
| 109 | |
| 110 | int32_t Audio::GetSyncSocket(int* sync_socket) { |
| 111 | return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 112 | } |
| 113 | |
| 114 | int32_t Audio::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { |
| 115 | return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 116 | } |
| 117 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 118 | namespace { |
| 119 | |
[email protected] | db0f57f5 | 2011-02-25 03:54:54 | [diff] [blame] | 120 | base::PlatformFile IntToPlatformFile(int32_t handle) { |
| 121 | // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, |
| 122 | // those casts are ugly. |
| 123 | #if defined(OS_WIN) |
| 124 | return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle)); |
| 125 | #elif defined(OS_POSIX) |
| 126 | return handle; |
| 127 | #else |
| 128 | #error Not implemented. |
| 129 | #endif |
| 130 | } |
| 131 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 132 | } // namespace |
| 133 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 134 | PPB_Audio_Proxy::PPB_Audio_Proxy(Dispatcher* dispatcher) |
| 135 | : InterfaceProxy(dispatcher), |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 136 | callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 137 | } |
| 138 | |
| 139 | PPB_Audio_Proxy::~PPB_Audio_Proxy() { |
| 140 | } |
| 141 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 142 | // static |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 143 | PP_Resource PPB_Audio_Proxy::CreateProxyResource( |
| 144 | PP_Instance instance_id, |
| 145 | PP_Resource config_id, |
| 146 | PPB_Audio_Callback audio_callback, |
| 147 | void* user_data) { |
| 148 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 149 | if (!dispatcher) |
| 150 | return 0; |
| 151 | |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 152 | EnterResourceNoLock<PPB_AudioConfig_API> config(config_id, true); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 153 | if (config.failed()) |
| 154 | return 0; |
| 155 | |
| 156 | HostResource result; |
| 157 | dispatcher->Send(new PpapiHostMsg_PPBAudio_Create( |
| 158 | INTERFACE_ID_PPB_AUDIO, instance_id, |
| 159 | config.object()->GetSampleRate(), config.object()->GetSampleFrameCount(), |
| 160 | &result)); |
| 161 | if (result.is_null()) |
| 162 | return 0; |
| 163 | |
[email protected] | bab65ef | 2011-08-20 04:53:22 | [diff] [blame] | 164 | return (new Audio(result, config_id, |
| 165 | audio_callback, user_data))->GetReference(); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 166 | } |
| 167 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 168 | bool PPB_Audio_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 169 | bool handled = true; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 170 | IPC_BEGIN_MESSAGE_MAP(PPB_Audio_Proxy, msg) |
| 171 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_Create, OnMsgCreate) |
| 172 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudio_StartOrStop, |
| 173 | OnMsgStartOrStop) |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 174 | IPC_MESSAGE_HANDLER(PpapiMsg_PPBAudio_NotifyAudioStreamCreated, |
| 175 | OnMsgNotifyAudioStreamCreated) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 176 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 177 | IPC_END_MESSAGE_MAP() |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 178 | return handled; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | void PPB_Audio_Proxy::OnMsgCreate(PP_Instance instance_id, |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 182 | int32_t sample_rate, |
| 183 | uint32_t sample_frame_count, |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 184 | HostResource* result) { |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 185 | thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation( |
| 186 | instance_id, true); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 187 | if (resource_creation.failed()) |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 188 | return; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 189 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 190 | // Make the resource and get the API pointer to its trusted interface. |
| 191 | result->SetHostResource( |
| 192 | instance_id, |
| 193 | resource_creation.functions()->CreateAudioTrusted(instance_id)); |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 194 | if (result->is_null()) |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 195 | return; |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 196 | |
| 197 | // At this point, we've set the result resource, and this is a sync request. |
| 198 | // Anything below this point must issue the AudioChannelConnected callback |
| 199 | // to the browser. Since that's an async message, it will be issued back to |
| 200 | // the plugin after the Create function returns (which is good because it |
| 201 | // would be weird to get a connected message with a failure code for a |
| 202 | // resource you haven't finished creating yet). |
| 203 | // |
| 204 | // The ...ForceCallback class will help ensure the callback is always called. |
| 205 | // All error cases must call SetResult on this class. |
| 206 | EnterHostFromHostResourceForceCallback<PPB_Audio_API> enter( |
| 207 | *result, callback_factory_, |
| 208 | &PPB_Audio_Proxy::AudioChannelConnected, *result); |
| 209 | if (enter.failed()) |
| 210 | return; // When enter fails, it will internally schedule the callback. |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 211 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 212 | // Make an audio config object. |
| 213 | PP_Resource audio_config_res = |
| 214 | resource_creation.functions()->CreateAudioConfig( |
| 215 | instance_id, static_cast<PP_AudioSampleRate>(sample_rate), |
| 216 | sample_frame_count); |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 217 | if (!audio_config_res) { |
| 218 | enter.SetResult(PP_ERROR_FAILED); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 219 | return; |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 220 | } |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 221 | |
| 222 | // Initiate opening the audio object. |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 223 | enter.SetResult(enter.object()->OpenTrusted(audio_config_res, |
| 224 | enter.callback())); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 225 | |
| 226 | // Clean up the temporary audio config resource we made. |
| 227 | const PPB_Core* core = static_cast<const PPB_Core*>( |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 228 | dispatcher()->local_get_interface()(PPB_CORE_INTERFACE)); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 229 | core->ReleaseResource(audio_config_res); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 230 | } |
| 231 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 232 | void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id, |
| 233 | bool play) { |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 234 | EnterHostFromHostResource<PPB_Audio_API> enter(audio_id); |
| 235 | if (enter.failed()) |
| 236 | return; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 237 | if (play) |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 238 | enter.object()->StartPlayback(); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 239 | else |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 240 | enter.object()->StopPlayback(); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 241 | } |
| 242 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 243 | // Processed in the plugin (message from host). |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 244 | void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( |
[email protected] | 2031aeb | 2011-01-28 20:01:16 | [diff] [blame] | 245 | const HostResource& audio_id, |
| 246 | int32_t result_code, |
| 247 | IPC::PlatformFileForTransit socket_handle, |
| 248 | base::SharedMemoryHandle handle, |
| 249 | uint32_t length) { |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 250 | EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 251 | if (enter.failed() || result_code != PP_OK) { |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 252 | // The caller may still have given us these handles in the failure case. |
| 253 | // The easiest way to clean these up is to just put them in the objects |
| 254 | // and then close them. This failure case is not performance critical. |
| 255 | base::SyncSocket temp_socket( |
[email protected] | 2031aeb | 2011-01-28 20:01:16 | [diff] [blame] | 256 | IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
| 257 | base::SharedMemory temp_mem(handle, false); |
[email protected] | cd910b9 | 2011-06-01 07:19:31 | [diff] [blame] | 258 | } else { |
| 259 | static_cast<Audio*>(enter.object())->SetStreamInfo( |
| 260 | handle, length, |
| 261 | IPC::PlatformFileForTransitToPlatformFile(socket_handle)); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 262 | } |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 263 | } |
| 264 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 265 | void PPB_Audio_Proxy::AudioChannelConnected( |
| 266 | int32_t result, |
| 267 | const HostResource& resource) { |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 268 | IPC::PlatformFileForTransit socket_handle = |
| 269 | IPC::InvalidPlatformFileForTransit(); |
[email protected] | db0f57f5 | 2011-02-25 03:54:54 | [diff] [blame] | 270 | base::SharedMemoryHandle shared_memory = IPC::InvalidPlatformFileForTransit(); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 271 | uint32_t shared_memory_length = 0; |
| 272 | |
| 273 | int32_t result_code = result; |
| 274 | if (result_code == PP_OK) { |
| 275 | result_code = GetAudioConnectedHandles(resource, &socket_handle, |
| 276 | &shared_memory, |
| 277 | &shared_memory_length); |
| 278 | } |
| 279 | |
| 280 | // Send all the values, even on error. This simplifies some of our cleanup |
| 281 | // code since the handles will be in the other process and could be |
| 282 | // inconvenient to clean up. Our IPC code will automatically handle this for |
| 283 | // us, as long as the remote side always closes the handles it receives |
| 284 | // (in OnMsgNotifyAudioStreamCreated), even in the failure case. |
| 285 | dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated( |
[email protected] | 2031aeb | 2011-01-28 20:01:16 | [diff] [blame] | 286 | INTERFACE_ID_PPB_AUDIO, resource, result_code, socket_handle, |
| 287 | shared_memory, shared_memory_length)); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 291 | const HostResource& resource, |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 292 | IPC::PlatformFileForTransit* foreign_socket_handle, |
| 293 | base::SharedMemoryHandle* foreign_shared_memory_handle, |
| 294 | uint32_t* shared_memory_length) { |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 295 | // Get the audio interface which will give us the handles. |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 296 | EnterHostFromHostResource<PPB_Audio_API> enter(resource); |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 297 | if (enter.failed()) |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 298 | return PP_ERROR_NOINTERFACE; |
| 299 | |
| 300 | // Get the socket handle for signaling. |
| 301 | int32_t socket_handle; |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 302 | int32_t result = enter.object()->GetSyncSocket(&socket_handle); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 303 | if (result != PP_OK) |
| 304 | return result; |
| 305 | |
[email protected] | db0f57f5 | 2011-02-25 03:54:54 | [diff] [blame] | 306 | // socket_handle doesn't belong to us: don't close it. |
| 307 | *foreign_socket_handle = dispatcher()->ShareHandleWithRemote( |
| 308 | IntToPlatformFile(socket_handle), false); |
| 309 | if (*foreign_socket_handle == IPC::InvalidPlatformFileForTransit()) |
| 310 | return PP_ERROR_FAILED; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 311 | |
| 312 | // Get the shared memory for the buffer. |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 313 | int shared_memory_handle; |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 314 | result = enter.object()->GetSharedMemory(&shared_memory_handle, |
| 315 | shared_memory_length); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 316 | if (result != PP_OK) |
| 317 | return result; |
| 318 | |
[email protected] | db0f57f5 | 2011-02-25 03:54:54 | [diff] [blame] | 319 | // shared_memory_handle doesn't belong to us: don't close it. |
| 320 | *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( |
| 321 | IntToPlatformFile(shared_memory_handle), false); |
| 322 | if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 323 | return PP_ERROR_FAILED; |
| 324 | |
| 325 | return PP_OK; |
| 326 | } |
| 327 | |
| 328 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 329 | } // namespace ppapi |