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/shared_impl/ppb_audio_input_shared.h" | 5 #include "ppapi/shared_impl/ppb_audio_input_shared.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/audio/audio_parameters.h" | 8 #include "media/audio/audio_parameters.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/shared_impl/ppapi_globals.h" | 10 #include "ppapi/shared_impl/ppapi_globals.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 | 47 |
48 PPB_AudioInput_Shared::~PPB_AudioInput_Shared() { | 48 PPB_AudioInput_Shared::~PPB_AudioInput_Shared() { |
49 DCHECK(open_state_ == CLOSED); | 49 DCHECK(open_state_ == CLOSED); |
50 } | 50 } |
51 | 51 |
52 thunk::PPB_AudioInput_API* PPB_AudioInput_Shared::AsPPB_AudioInput_API() { | 52 thunk::PPB_AudioInput_API* PPB_AudioInput_Shared::AsPPB_AudioInput_API() { |
53 return this; | 53 return this; |
54 } | 54 } |
55 | 55 |
56 int32_t PPB_AudioInput_Shared::EnumerateDevices( | 56 int32_t PPB_AudioInput_Shared::EnumerateDevices(PP_Resource* devices, |
57 PP_Resource* devices, | 57 ApiCallbackType callback) { |
58 const PP_CompletionCallback& callback) { | |
59 if (!callback.func) | |
60 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
61 if (TrackedCallback::IsPending(enumerate_devices_callback_)) | 58 if (TrackedCallback::IsPending(enumerate_devices_callback_)) |
62 return PP_ERROR_INPROGRESS; | 59 return PP_ERROR_INPROGRESS; |
63 | 60 |
64 return InternalEnumerateDevices(devices, callback); | 61 return InternalEnumerateDevices(devices, callback); |
65 } | 62 } |
66 | 63 |
67 int32_t PPB_AudioInput_Shared::Open( | 64 int32_t PPB_AudioInput_Shared::Open( |
68 const std::string& device_id, | 65 const std::string& device_id, |
69 PP_Resource config, | 66 PP_Resource config, |
70 PPB_AudioInput_Callback audio_input_callback, | 67 PPB_AudioInput_Callback audio_input_callback, |
71 void* user_data, | 68 void* user_data, |
72 const PP_CompletionCallback& callback) { | 69 ApiCallbackType callback) { |
73 if (!audio_input_callback) | 70 if (!audio_input_callback) |
74 return PP_ERROR_BADARGUMENT; | 71 return PP_ERROR_BADARGUMENT; |
75 | 72 |
76 return CommonOpen(device_id, config, audio_input_callback, user_data, | 73 return CommonOpen(device_id, config, audio_input_callback, user_data, |
77 callback); | 74 callback); |
78 } | 75 } |
79 | 76 |
80 PP_Resource PPB_AudioInput_Shared::GetCurrentConfig() { | 77 PP_Resource PPB_AudioInput_Shared::GetCurrentConfig() { |
81 // AddRef for the caller. | 78 // AddRef for the caller. |
82 if (config_.get()) | 79 if (config_.get()) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 base::SharedMemory temp_mem(shared_memory_handle, false); | 163 base::SharedMemory temp_mem(shared_memory_handle, false); |
167 capturing_ = false; | 164 capturing_ = false; |
168 } | 165 } |
169 | 166 |
170 // The callback may have been aborted by Close(). | 167 // The callback may have been aborted by Close(). |
171 if (TrackedCallback::IsPending(open_callback_)) | 168 if (TrackedCallback::IsPending(open_callback_)) |
172 TrackedCallback::ClearAndRun(&open_callback_, result); | 169 TrackedCallback::ClearAndRun(&open_callback_, result); |
173 } | 170 } |
174 | 171 |
175 // static | 172 // static |
176 PP_CompletionCallback PPB_AudioInput_Shared::MakeIgnoredCompletionCallback() { | 173 ApiCallbackType PPB_AudioInput_Shared::MakeIgnoredCompletionCallback( |
177 return PP_MakeCompletionCallback(&IgnoredCompletionCallback, NULL); | 174 Resource* resource) { |
| 175 return new TrackedCallback(resource, |
| 176 PP_MakeCompletionCallback(&IgnoredCompletionCallback, NULL)); |
178 } | 177 } |
179 | 178 |
180 void PPB_AudioInput_Shared::SetStartCaptureState() { | 179 void PPB_AudioInput_Shared::SetStartCaptureState() { |
181 DCHECK(!capturing_); | 180 DCHECK(!capturing_); |
182 DCHECK(!audio_input_thread_.get()); | 181 DCHECK(!audio_input_thread_.get()); |
183 | 182 |
184 if (audio_input_callback_ && socket_.get()) | 183 if (audio_input_callback_ && socket_.get()) |
185 StartThread(); | 184 StartThread(); |
186 capturing_ = true; | 185 capturing_ = true; |
187 } | 186 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (buffer->params.size > 0) | 242 if (buffer->params.size > 0) |
244 audio_input_callback_(&buffer->audio[0], buffer->params.size, user_data_); | 243 audio_input_callback_(&buffer->audio[0], buffer->params.size, user_data_); |
245 } | 244 } |
246 } | 245 } |
247 | 246 |
248 int32_t PPB_AudioInput_Shared::CommonOpen( | 247 int32_t PPB_AudioInput_Shared::CommonOpen( |
249 const std::string& device_id, | 248 const std::string& device_id, |
250 PP_Resource config, | 249 PP_Resource config, |
251 PPB_AudioInput_Callback audio_input_callback, | 250 PPB_AudioInput_Callback audio_input_callback, |
252 void* user_data, | 251 void* user_data, |
253 PP_CompletionCallback callback) { | 252 ApiCallbackType callback) { |
254 if (open_state_ != BEFORE_OPEN) | 253 if (open_state_ != BEFORE_OPEN) |
255 return PP_ERROR_FAILED; | 254 return PP_ERROR_FAILED; |
256 | 255 |
257 thunk::EnterResourceNoLock<thunk::PPB_AudioConfig_API> enter_config(config, | 256 thunk::EnterResourceNoLock<thunk::PPB_AudioConfig_API> enter_config(config, |
258 true); | 257 true); |
259 if (enter_config.failed()) | 258 if (enter_config.failed()) |
260 return PP_ERROR_BADARGUMENT; | 259 return PP_ERROR_BADARGUMENT; |
261 | 260 |
262 if (!callback.func) | |
263 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
264 | |
265 if (TrackedCallback::IsPending(open_callback_)) | 261 if (TrackedCallback::IsPending(open_callback_)) |
266 return PP_ERROR_INPROGRESS; | 262 return PP_ERROR_INPROGRESS; |
267 | 263 |
268 config_ = config; | 264 config_ = config; |
269 audio_input_callback_ = audio_input_callback; | 265 audio_input_callback_ = audio_input_callback; |
270 user_data_ = user_data; | 266 user_data_ = user_data; |
271 | 267 |
272 return InternalOpen(device_id, enter_config.object()->GetSampleRate(), | 268 return InternalOpen(device_id, enter_config.object()->GetSampleRate(), |
273 enter_config.object()->GetSampleFrameCount(), callback); | 269 enter_config.object()->GetSampleFrameCount(), callback); |
274 } | 270 } |
275 | 271 |
276 } // namespace ppapi | 272 } // namespace ppapi |
OLD | NEW |