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