| 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 "ppapi/c/dev/ppb_audio_input_dev.h" | 8 #include "ppapi/c/dev/ppb_audio_input_dev.h" |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/c/ppb_audio_config.h" | 10 #include "ppapi/c/ppb_audio_config.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 namespace ppapi { | 27 namespace ppapi { |
| 28 namespace proxy { | 28 namespace proxy { |
| 29 | 29 |
| 30 class AudioInput : public PPB_AudioInput_Shared { | 30 class AudioInput : public PPB_AudioInput_Shared { |
| 31 public: | 31 public: |
| 32 explicit AudioInput(const HostResource& audio_input); | 32 explicit AudioInput(const HostResource& audio_input); |
| 33 virtual ~AudioInput(); | 33 virtual ~AudioInput(); |
| 34 | 34 |
| 35 // Implementation of PPB_AudioInput_API trusted methods. | 35 // Implementation of PPB_AudioInput_API trusted methods. |
| 36 virtual int32_t OpenTrusted( | 36 virtual int32_t OpenTrusted(const std::string& device_id, |
| 37 const std::string& device_id, | 37 PP_Resource config, |
| 38 PP_Resource config, | 38 ApiCallbackType create_callback) OVERRIDE; |
| 39 const PP_CompletionCallback& create_callback) OVERRIDE; | |
| 40 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; | 39 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; |
| 41 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; |
| 42 virtual const std::vector<DeviceRefData>& GetDeviceRefData() const OVERRIDE; | 41 virtual const std::vector<DeviceRefData>& GetDeviceRefData() const OVERRIDE; |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 // PPB_AudioInput_Shared implementation. | 44 // PPB_AudioInput_Shared implementation. |
| 46 virtual int32_t InternalEnumerateDevices( | 45 virtual int32_t InternalEnumerateDevices(PP_Resource* devices, |
| 47 PP_Resource* devices, | 46 ApiCallbackType callback) OVERRIDE; |
| 48 PP_CompletionCallback callback) OVERRIDE; | |
| 49 virtual int32_t InternalOpen(const std::string& device_id, | 47 virtual int32_t InternalOpen(const std::string& device_id, |
| 50 PP_AudioSampleRate sample_rate, | 48 PP_AudioSampleRate sample_rate, |
| 51 uint32_t sample_frame_count, | 49 uint32_t sample_frame_count, |
| 52 PP_CompletionCallback callback) OVERRIDE; | 50 ApiCallbackType callback) OVERRIDE; |
| 53 virtual PP_Bool InternalStartCapture() OVERRIDE; | 51 virtual PP_Bool InternalStartCapture() OVERRIDE; |
| 54 virtual PP_Bool InternalStopCapture() OVERRIDE; | 52 virtual PP_Bool InternalStopCapture() OVERRIDE; |
| 55 virtual void InternalClose() OVERRIDE; | 53 virtual void InternalClose() OVERRIDE; |
| 56 | 54 |
| 57 PluginDispatcher* GetDispatcher() const { | 55 PluginDispatcher* GetDispatcher() const { |
| 58 return PluginDispatcher::GetForResource(this); | 56 return PluginDispatcher::GetForResource(this); |
| 59 } | 57 } |
| 60 | 58 |
| 61 DISALLOW_COPY_AND_ASSIGN(AudioInput); | 59 DISALLOW_COPY_AND_ASSIGN(AudioInput); |
| 62 }; | 60 }; |
| 63 | 61 |
| 64 AudioInput::AudioInput(const HostResource& audio_input) | 62 AudioInput::AudioInput(const HostResource& audio_input) |
| 65 : PPB_AudioInput_Shared(audio_input) { | 63 : PPB_AudioInput_Shared(audio_input) { |
| 66 } | 64 } |
| 67 | 65 |
| 68 AudioInput::~AudioInput() { | 66 AudioInput::~AudioInput() { |
| 69 Close(); | 67 Close(); |
| 70 } | 68 } |
| 71 | 69 |
| 72 int32_t AudioInput::OpenTrusted(const std::string& device_id, | 70 int32_t AudioInput::OpenTrusted(const std::string& device_id, |
| 73 PP_Resource config, | 71 PP_Resource config, |
| 74 const PP_CompletionCallback& create_callback) { | 72 ApiCallbackType create_callback) { |
| 75 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | 73 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 76 } | 74 } |
| 77 | 75 |
| 78 int32_t AudioInput::GetSyncSocket(int* sync_socket) { | 76 int32_t AudioInput::GetSyncSocket(int* sync_socket) { |
| 79 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | 77 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 80 } | 78 } |
| 81 | 79 |
| 82 int32_t AudioInput::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { | 80 int32_t AudioInput::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { |
| 83 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. | 81 return PP_ERROR_NOTSUPPORTED; // Don't proxy the trusted interface. |
| 84 } | 82 } |
| 85 | 83 |
| 86 const std::vector<DeviceRefData>& AudioInput::GetDeviceRefData() const { | 84 const std::vector<DeviceRefData>& AudioInput::GetDeviceRefData() const { |
| 87 // Don't proxy the trusted interface. | 85 // Don't proxy the trusted interface. |
| 88 static std::vector<DeviceRefData> result; | 86 static std::vector<DeviceRefData> result; |
| 89 return result; | 87 return result; |
| 90 } | 88 } |
| 91 | 89 |
| 92 int32_t AudioInput::InternalEnumerateDevices(PP_Resource* devices, | 90 int32_t AudioInput::InternalEnumerateDevices(PP_Resource* devices, |
| 93 PP_CompletionCallback callback) { | 91 ApiCallbackType callback) { |
| 94 devices_ = devices; | 92 devices_ = devices; |
| 95 enumerate_devices_callback_ = new TrackedCallback(this, callback); | 93 enumerate_devices_callback_ = callback; |
| 96 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_EnumerateDevices( | 94 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_EnumerateDevices( |
| 97 API_ID_PPB_AUDIO_INPUT_DEV, host_resource())); | 95 API_ID_PPB_AUDIO_INPUT_DEV, host_resource())); |
| 98 return PP_OK_COMPLETIONPENDING; | 96 return PP_OK_COMPLETIONPENDING; |
| 99 } | 97 } |
| 100 | 98 |
| 101 int32_t AudioInput::InternalOpen(const std::string& device_id, | 99 int32_t AudioInput::InternalOpen(const std::string& device_id, |
| 102 PP_AudioSampleRate sample_rate, | 100 PP_AudioSampleRate sample_rate, |
| 103 uint32_t sample_frame_count, | 101 uint32_t sample_frame_count, |
| 104 PP_CompletionCallback callback) { | 102 ApiCallbackType callback) { |
| 105 open_callback_ = new TrackedCallback(this, callback); | 103 open_callback_ = callback; |
| 106 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_Open( | 104 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_Open( |
| 107 API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), device_id, sample_rate, | 105 API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), device_id, sample_rate, |
| 108 sample_frame_count)); | 106 sample_frame_count)); |
| 109 return PP_OK_COMPLETIONPENDING; | 107 return PP_OK_COMPLETIONPENDING; |
| 110 } | 108 } |
| 111 | 109 |
| 112 PP_Bool AudioInput::InternalStartCapture() { | 110 PP_Bool AudioInput::InternalStartCapture() { |
| 113 SetStartCaptureState(); | 111 SetStartCaptureState(); |
| 114 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_StartOrStop( | 112 GetDispatcher()->Send(new PpapiHostMsg_PPBAudioInput_StartOrStop( |
| 115 API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), true)); | 113 API_ID_PPB_AUDIO_INPUT_DEV, host_resource(), true)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 return 0; | 145 return 0; |
| 148 | 146 |
| 149 HostResource result; | 147 HostResource result; |
| 150 dispatcher->Send(new PpapiHostMsg_PPBAudioInput_Create( | 148 dispatcher->Send(new PpapiHostMsg_PPBAudioInput_Create( |
| 151 API_ID_PPB_AUDIO_INPUT_DEV, instance, &result)); | 149 API_ID_PPB_AUDIO_INPUT_DEV, instance, &result)); |
| 152 if (result.is_null()) | 150 if (result.is_null()) |
| 153 return 0; | 151 return 0; |
| 154 | 152 |
| 155 AudioInput* audio_input = new AudioInput(result); | 153 AudioInput* audio_input = new AudioInput(result); |
| 156 int32_t open_result = audio_input->Open("", config, audio_input_callback, | 154 int32_t open_result = audio_input->Open("", config, audio_input_callback, |
| 157 user_data, AudioInput::MakeIgnoredCompletionCallback()); | 155 user_data, AudioInput::MakeIgnoredCompletionCallback(audio_input)); |
| 158 if (open_result != PP_OK && open_result != PP_OK_COMPLETIONPENDING) { | 156 if (open_result != PP_OK && open_result != PP_OK_COMPLETIONPENDING) { |
| 159 delete audio_input; | 157 delete audio_input; |
| 160 return 0; | 158 return 0; |
| 161 } | 159 } |
| 162 return audio_input->GetReference(); | 160 return audio_input->GetReference(); |
| 163 } | 161 } |
| 164 | 162 |
| 165 // static | 163 // static |
| 166 PP_Resource PPB_AudioInput_Proxy::CreateProxyResource( | 164 PP_Resource PPB_AudioInput_Proxy::CreateProxyResource( |
| 167 PP_Instance instance) { | 165 PP_Instance instance) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( | 365 *foreign_shared_memory_handle = dispatcher()->ShareHandleWithRemote( |
| 368 IntToPlatformFile(shared_memory_handle), false); | 366 IntToPlatformFile(shared_memory_handle), false); |
| 369 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) | 367 if (*foreign_shared_memory_handle == IPC::InvalidPlatformFileForTransit()) |
| 370 return PP_ERROR_FAILED; | 368 return PP_ERROR_FAILED; |
| 371 | 369 |
| 372 return PP_OK; | 370 return PP_OK; |
| 373 } | 371 } |
| 374 | 372 |
| 375 } // namespace proxy | 373 } // namespace proxy |
| 376 } // namespace ppapi | 374 } // namespace ppapi |
| OLD | NEW |