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