| 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_proxy.h" | 5 #include "ppapi/proxy/ppb_audio_proxy.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/threading/simple_thread.h" | 8 #include "base/threading/simple_thread.h" |
| 9 #include "media/audio/shared_memory_util.h" | 9 #include "media/audio/shared_memory_util.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 using ppapi::thunk::PPB_Audio_API; | 30 using ppapi::thunk::PPB_Audio_API; |
| 31 using ppapi::thunk::PPB_AudioConfig_API; | 31 using ppapi::thunk::PPB_AudioConfig_API; |
| 32 | 32 |
| 33 namespace ppapi { | 33 namespace ppapi { |
| 34 namespace proxy { | 34 namespace proxy { |
| 35 | 35 |
| 36 class Audio : public Resource, public PPB_Audio_Shared { | 36 class Audio : public Resource, public PPB_Audio_Shared { |
| 37 public: | 37 public: |
| 38 Audio(const HostResource& audio_id, | 38 Audio(const HostResource& audio_id, |
| 39 PP_Resource config_id, | 39 PP_Resource config_id, |
| 40 PPB_Audio_Callback callback, | 40 const AudioCallback& callback, |
| 41 void* user_data); | 41 void* user_data); |
| 42 virtual ~Audio(); | 42 virtual ~Audio(); |
| 43 | 43 |
| 44 // Resource overrides. | 44 // Resource overrides. |
| 45 virtual PPB_Audio_API* AsPPB_Audio_API(); | 45 virtual PPB_Audio_API* AsPPB_Audio_API(); |
| 46 | 46 |
| 47 // PPB_Audio_API implementation. | 47 // PPB_Audio_API implementation. |
| 48 virtual PP_Resource GetCurrentConfig() OVERRIDE; | 48 virtual PP_Resource GetCurrentConfig() OVERRIDE; |
| 49 virtual PP_Bool StartPlayback() OVERRIDE; | 49 virtual PP_Bool StartPlayback() OVERRIDE; |
| 50 virtual PP_Bool StopPlayback() OVERRIDE; | 50 virtual PP_Bool StopPlayback() OVERRIDE; |
| 51 virtual int32_t Open( | 51 virtual int32_t Open( |
| 52 PP_Resource config_id, | 52 PP_Resource config_id, |
| 53 scoped_refptr<TrackedCallback> create_callback) OVERRIDE; | 53 scoped_refptr<TrackedCallback> create_callback) OVERRIDE; |
| 54 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; | 54 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; |
| 55 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; | 55 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 // Owning reference to the current config object. This isn't actually used, | 58 // Owning reference to the current config object. This isn't actually used, |
| 59 // we just dish it out as requested by the plugin. | 59 // we just dish it out as requested by the plugin. |
| 60 PP_Resource config_; | 60 PP_Resource config_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(Audio); | 62 DISALLOW_COPY_AND_ASSIGN(Audio); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 Audio::Audio(const HostResource& audio_id, | 65 Audio::Audio(const HostResource& audio_id, |
| 66 PP_Resource config_id, | 66 PP_Resource config_id, |
| 67 PPB_Audio_Callback callback, | 67 const AudioCallback& callback, |
| 68 void* user_data) | 68 void* user_data) |
| 69 : Resource(OBJECT_IS_PROXY, audio_id), | 69 : Resource(OBJECT_IS_PROXY, audio_id), |
| 70 config_(config_id) { | 70 config_(config_id) { |
| 71 SetCallback(callback, user_data); | 71 SetCallback(callback, user_data); |
| 72 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); | 72 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 Audio::~Audio() { | 75 Audio::~Audio() { |
| 76 #if defined(OS_NACL) | 76 #if defined(OS_NACL) |
| 77 // Invoke StopPlayback() to ensure audio back-end has a chance to send the | 77 // Invoke StopPlayback() to ensure audio back-end has a chance to send the |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 callback_factory_(this) { | 131 callback_factory_(this) { |
| 132 } | 132 } |
| 133 | 133 |
| 134 PPB_Audio_Proxy::~PPB_Audio_Proxy() { | 134 PPB_Audio_Proxy::~PPB_Audio_Proxy() { |
| 135 } | 135 } |
| 136 | 136 |
| 137 // static | 137 // static |
| 138 PP_Resource PPB_Audio_Proxy::CreateProxyResource( | 138 PP_Resource PPB_Audio_Proxy::CreateProxyResource( |
| 139 PP_Instance instance_id, | 139 PP_Instance instance_id, |
| 140 PP_Resource config_id, | 140 PP_Resource config_id, |
| 141 PPB_Audio_Callback audio_callback, | 141 const AudioCallback& audio_callback, |
| 142 void* user_data) { | 142 void* user_data) { |
| 143 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); | 143 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 144 if (!dispatcher) | 144 if (!dispatcher) |
| 145 return 0; | 145 return 0; |
| 146 | 146 |
| 147 EnterResourceNoLock<PPB_AudioConfig_API> config(config_id, true); | 147 EnterResourceNoLock<PPB_AudioConfig_API> config(config_id, true); |
| 148 if (config.failed()) | 148 if (config.failed()) |
| 149 return 0; | 149 return 0; |
| 150 | 150 |
| 151 if (!audio_callback) | 151 if (!audio_callback.IsValid()) |
| 152 return 0; | 152 return 0; |
| 153 | 153 |
| 154 HostResource result; | 154 HostResource result; |
| 155 dispatcher->Send(new PpapiHostMsg_PPBAudio_Create( | 155 dispatcher->Send(new PpapiHostMsg_PPBAudio_Create( |
| 156 API_ID_PPB_AUDIO, instance_id, | 156 API_ID_PPB_AUDIO, instance_id, |
| 157 config.object()->GetSampleRate(), config.object()->GetSampleFrameCount(), | 157 config.object()->GetSampleRate(), config.object()->GetSampleFrameCount(), |
| 158 &result)); | 158 &result)); |
| 159 if (result.is_null()) | 159 if (result.is_null()) |
| 160 return 0; | 160 return 0; |
| 161 | 161 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 EnterResourceNoLock<PPB_AudioConfig_API> config( | 334 EnterResourceNoLock<PPB_AudioConfig_API> config( |
| 335 static_cast<Audio*>(enter.object())->GetCurrentConfig(), true); | 335 static_cast<Audio*>(enter.object())->GetCurrentConfig(), true); |
| 336 // See the comment above about how we must call | 336 // See the comment above about how we must call |
| 337 // TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here, | 337 // TotalSharedMemorySizeInBytes to get the actual size of the buffer. Here, |
| 338 // we must call PacketSizeInBytes to get back the size of the audio buffer, | 338 // we must call PacketSizeInBytes to get back the size of the audio buffer, |
| 339 // excluding the bytes that audio uses for book-keeping. | 339 // excluding the bytes that audio uses for book-keeping. |
| 340 static_cast<Audio*>(enter.object())->SetStreamInfo( | 340 static_cast<Audio*>(enter.object())->SetStreamInfo( |
| 341 enter.resource()->pp_instance(), handle.shmem(), | 341 enter.resource()->pp_instance(), handle.shmem(), |
| 342 media::PacketSizeInBytes(handle.size()), | 342 media::PacketSizeInBytes(handle.size()), |
| 343 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()), | 343 IPC::PlatformFileForTransitToPlatformFile(socket_handle.descriptor()), |
| 344 config.object()->GetSampleRate(), |
| 344 config.object()->GetSampleFrameCount()); | 345 config.object()->GetSampleFrameCount()); |
| 345 } | 346 } |
| 346 } | 347 } |
| 347 | 348 |
| 348 } // namespace proxy | 349 } // namespace proxy |
| 349 } // namespace ppapi | 350 } // namespace ppapi |
| OLD | NEW |