| Index: ppapi/proxy/ppb_audio_proxy.cc
|
| ===================================================================
|
| --- ppapi/proxy/ppb_audio_proxy.cc (revision 72840)
|
| +++ ppapi/proxy/ppb_audio_proxy.cc (working copy)
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -19,11 +19,11 @@
|
|
|
| class Audio : public PluginResource, public pp::shared_impl::AudioImpl {
|
| public:
|
| - Audio(PP_Instance instance,
|
| + Audio(const HostResource& audio_id,
|
| PP_Resource config_id,
|
| PPB_Audio_Callback callback,
|
| void* user_data)
|
| - : PluginResource(instance),
|
| + : PluginResource(audio_id),
|
| config_(config_id) {
|
| SetCallback(callback, user_data);
|
| PluginResourceTracker::GetInstance()->AddRefResource(config_);
|
| @@ -43,7 +43,7 @@
|
| SetStartPlaybackState();
|
| PluginDispatcher::GetForInstance(instance())->Send(
|
| new PpapiHostMsg_PPBAudio_StartOrStop(
|
| - INTERFACE_ID_PPB_AUDIO, resource, true));
|
| + INTERFACE_ID_PPB_AUDIO, host_resource(), true));
|
| }
|
|
|
| void StopPlayback(PP_Resource resource) {
|
| @@ -51,7 +51,7 @@
|
| return;
|
| PluginDispatcher::GetForInstance(instance())->Send(
|
| new PpapiHostMsg_PPBAudio_StartOrStop(
|
| - INTERFACE_ID_PPB_AUDIO, resource, false));
|
| + INTERFACE_ID_PPB_AUDIO, host_resource(), false));
|
| SetStopPlaybackState();
|
| }
|
|
|
| @@ -61,22 +61,31 @@
|
| DISALLOW_COPY_AND_ASSIGN(Audio);
|
| };
|
|
|
| +// Closure data for the AudioChannelConnected callback.
|
| +struct AudioChannelConnectedTracking {
|
| + PP_Instance instance;
|
| + HostResource resource;
|
| +};
|
| +
|
| namespace {
|
|
|
| PP_Resource Create(PP_Instance instance_id,
|
| PP_Resource config_id,
|
| PPB_Audio_Callback callback,
|
| void* user_data) {
|
| - PP_Resource result;
|
| + PluginResource* config = PluginResourceTracker::GetInstance()->
|
| + GetResourceObject(config_id);
|
| + if (!config)
|
| + return 0;
|
| +
|
| + HostResource result;
|
| PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBAudio_Create(
|
| - INTERFACE_ID_PPB_AUDIO, instance_id, config_id, &result));
|
| - if (!result)
|
| + INTERFACE_ID_PPB_AUDIO, instance_id, config->host_resource(), &result));
|
| + if (result.is_null())
|
| return 0;
|
|
|
| - linked_ptr<Audio> object(new Audio(instance_id, config_id,
|
| - callback, user_data));
|
| - PluginResourceTracker::GetInstance()->AddResource(result, object);
|
| - return result;
|
| + linked_ptr<Audio> object(new Audio(result, config_id, callback, user_data));
|
| + return PluginResourceTracker::GetInstance()->AddResource(object);
|
| }
|
|
|
| PP_Bool IsAudio(PP_Resource resource) {
|
| @@ -150,57 +159,68 @@
|
| }
|
|
|
| void PPB_Audio_Proxy::OnMsgCreate(PP_Instance instance_id,
|
| - PP_Resource config_id,
|
| - PP_Resource* result) {
|
| + const HostResource& config_id,
|
| + HostResource* result) {
|
| const PPB_AudioTrusted* audio_trusted =
|
| reinterpret_cast<const PPB_AudioTrusted*>(
|
| dispatcher()->GetLocalInterface(PPB_AUDIO_TRUSTED_INTERFACE));
|
| - if (!audio_trusted) {
|
| - *result = 0;
|
| + if (!audio_trusted)
|
| return;
|
| - }
|
|
|
| - *result = audio_trusted->CreateTrusted(instance_id);
|
| - if (!result)
|
| + result->SetHostResource(instance_id,
|
| + audio_trusted->CreateTrusted(instance_id));
|
| + if (result->is_null())
|
| return;
|
|
|
| + // The callback will be in charge of deleting this pointer.
|
| + AudioChannelConnectedTracking* tracking = new AudioChannelConnectedTracking;
|
| + tracking->instance = instance_id;
|
| + tracking->resource = *result;
|
| CompletionCallback callback = callback_factory_.NewCallback(
|
| - &PPB_Audio_Proxy::AudioChannelConnected, *result);
|
| - int32_t open_error = audio_trusted->Open(*result, config_id,
|
| + &PPB_Audio_Proxy::AudioChannelConnected, tracking);
|
| + int32_t open_error = audio_trusted->Open(result->host_resource(),
|
| + config_id.host_resource(),
|
| callback.pp_completion_callback());
|
| if (open_error != PP_ERROR_WOULDBLOCK)
|
| callback.Run(open_error);
|
| }
|
|
|
| -void PPB_Audio_Proxy::OnMsgStartOrStop(PP_Resource audio_id, bool play) {
|
| +void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id,
|
| + bool play) {
|
| if (play)
|
| - ppb_audio_target()->StartPlayback(audio_id);
|
| + ppb_audio_target()->StartPlayback(audio_id.host_resource());
|
| else
|
| - ppb_audio_target()->StopPlayback(audio_id);
|
| + ppb_audio_target()->StopPlayback(audio_id.host_resource());
|
| }
|
|
|
| +// Processed in the plugin (message from host).
|
| void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated(
|
| - PP_Resource audio_id,
|
| - int32_t result_code,
|
| - IPC::PlatformFileForTransit socket_handle,
|
| - base::SharedMemoryHandle handle,
|
| - uint32_t length) {
|
| - Audio* object = PluginResource::GetAs<Audio>(audio_id);
|
| - if (!object || result_code != PP_OK) {
|
| + const PPBAudio_NotifyAudioStreamCreated_Params& params) {
|
| + PP_Resource plugin_resource =
|
| + PluginResourceTracker::GetInstance()->PluginResourceForHostResource(
|
| + params.audio_id);
|
| + Audio* object = plugin_resource ?
|
| + PluginResource::GetAs<Audio>(plugin_resource) : NULL;
|
| + if (!object || params.result_code != PP_OK) {
|
| // The caller may still have given us these handles in the failure case.
|
| // The easiest way to clean these up is to just put them in the objects
|
| // and then close them. This failure case is not performance critical.
|
| base::SyncSocket temp_socket(
|
| - IPC::PlatformFileForTransitToPlatformFile(socket_handle));
|
| - base::SharedMemory temp_mem(handle, false);
|
| + IPC::PlatformFileForTransitToPlatformFile(params.socket_handle));
|
| + base::SharedMemory temp_mem(params.handle, false);
|
| return;
|
| }
|
| object->SetStreamInfo(
|
| - handle, length, IPC::PlatformFileForTransitToPlatformFile(socket_handle));
|
| + params.handle, params.length,
|
| + IPC::PlatformFileForTransitToPlatformFile(params.socket_handle));
|
| }
|
|
|
| -void PPB_Audio_Proxy::AudioChannelConnected(int32_t result,
|
| - PP_Resource resource) {
|
| +void PPB_Audio_Proxy::AudioChannelConnected(
|
| + int32_t result,
|
| + AudioChannelConnectedTracking* tracking) {
|
| + // Ownership of the pointer was transferred to us.
|
| + scoped_ptr<AudioChannelConnectedTracking> tracking_deleter(tracking);
|
| +
|
| IPC::PlatformFileForTransit socket_handle =
|
| IPC::InvalidPlatformFileForTransit();
|
| #if defined(OS_WIN)
|
| @@ -214,7 +234,7 @@
|
|
|
| int32_t result_code = result;
|
| if (result_code == PP_OK) {
|
| - result_code = GetAudioConnectedHandles(resource, &socket_handle,
|
| + result_code = GetAudioConnectedHandles(tracking->resource, &socket_handle,
|
| &shared_memory,
|
| &shared_memory_length);
|
| }
|
| @@ -224,13 +244,19 @@
|
| // inconvenient to clean up. Our IPC code will automatically handle this for
|
| // us, as long as the remote side always closes the handles it receives
|
| // (in OnMsgNotifyAudioStreamCreated), even in the failure case.
|
| + PPBAudio_NotifyAudioStreamCreated_Params params;
|
| + params.instance = tracking->instance;
|
| + params.audio_id = tracking->resource;
|
| + params.result_code = result;
|
| + params.socket_handle = socket_handle;
|
| + params.handle = shared_memory;
|
| + params.length = shared_memory_length;
|
| dispatcher()->Send(new PpapiMsg_PPBAudio_NotifyAudioStreamCreated(
|
| - INTERFACE_ID_PPB_AUDIO, resource, result_code, socket_handle,
|
| - shared_memory, shared_memory_length));
|
| + INTERFACE_ID_PPB_AUDIO, params));
|
| }
|
|
|
| int32_t PPB_Audio_Proxy::GetAudioConnectedHandles(
|
| - PP_Resource resource,
|
| + const HostResource& resource,
|
| IPC::PlatformFileForTransit* foreign_socket_handle,
|
| base::SharedMemoryHandle* foreign_shared_memory_handle,
|
| uint32_t* shared_memory_length) {
|
| @@ -243,7 +269,8 @@
|
|
|
| // Get the socket handle for signaling.
|
| int32_t socket_handle;
|
| - int32_t result = audio_trusted->GetSyncSocket(resource, &socket_handle);
|
| + int32_t result = audio_trusted->GetSyncSocket(resource.host_resource(),
|
| + &socket_handle);
|
| if (result != PP_OK)
|
| return result;
|
|
|
| @@ -265,8 +292,9 @@
|
| // Get the shared memory for the buffer.
|
| // TODO(brettw) remove the reinterpret cast when the interface is updated.
|
| int shared_memory_handle;
|
| - result = audio_trusted->GetSharedMemory(resource, &shared_memory_handle,
|
| - shared_memory_length);
|
| + result = audio_trusted->GetSharedMemory(resource.host_resource(),
|
| + &shared_memory_handle,
|
| + shared_memory_length);
|
| if (result != PP_OK)
|
| return result;
|
|
|
|
|