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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( |
57 PP_Resource* devices, | 57 PP_Resource* devices, |
58 const PP_CompletionCallback& callback) { | 58 scoped_refptr<TrackedCallback> callback) { |
59 if (!callback.func) | |
60 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
61 if (TrackedCallback::IsPending(enumerate_devices_callback_)) | 59 if (TrackedCallback::IsPending(enumerate_devices_callback_)) |
62 return PP_ERROR_INPROGRESS; | 60 return PP_ERROR_INPROGRESS; |
63 | 61 |
64 return InternalEnumerateDevices(devices, callback); | 62 return InternalEnumerateDevices(devices, callback); |
65 } | 63 } |
66 | 64 |
67 int32_t PPB_AudioInput_Shared::Open( | 65 int32_t PPB_AudioInput_Shared::Open( |
68 const std::string& device_id, | 66 const std::string& device_id, |
69 PP_Resource config, | 67 PP_Resource config, |
70 PPB_AudioInput_Callback audio_input_callback, | 68 PPB_AudioInput_Callback audio_input_callback, |
71 void* user_data, | 69 void* user_data, |
72 const PP_CompletionCallback& callback) { | 70 scoped_refptr<TrackedCallback> callback) { |
73 if (!audio_input_callback) | 71 if (!audio_input_callback) |
74 return PP_ERROR_BADARGUMENT; | 72 return PP_ERROR_BADARGUMENT; |
75 | 73 |
76 return CommonOpen(device_id, config, audio_input_callback, user_data, | 74 return CommonOpen(device_id, config, audio_input_callback, user_data, |
77 callback); | 75 callback); |
78 } | 76 } |
79 | 77 |
80 PP_Resource PPB_AudioInput_Shared::GetCurrentConfig() { | 78 PP_Resource PPB_AudioInput_Shared::GetCurrentConfig() { |
81 // AddRef for the caller. | 79 // AddRef for the caller. |
82 if (config_.get()) | 80 if (config_.get()) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 base::SharedMemory temp_mem(shared_memory_handle, false); | 157 base::SharedMemory temp_mem(shared_memory_handle, false); |
160 capturing_ = false; | 158 capturing_ = false; |
161 } | 159 } |
162 | 160 |
163 // The callback may have been aborted by Close(). | 161 // The callback may have been aborted by Close(). |
164 if (TrackedCallback::IsPending(open_callback_)) | 162 if (TrackedCallback::IsPending(open_callback_)) |
165 TrackedCallback::ClearAndRun(&open_callback_, result); | 163 TrackedCallback::ClearAndRun(&open_callback_, result); |
166 } | 164 } |
167 | 165 |
168 // static | 166 // static |
169 PP_CompletionCallback PPB_AudioInput_Shared::MakeIgnoredCompletionCallback() { | 167 scoped_refptr<TrackedCallback> |
170 return PP_MakeCompletionCallback(&IgnoredCompletionCallback, NULL); | 168 PPB_AudioInput_Shared::MakeIgnoredCompletionCallback( |
| 169 Resource* resource) { |
| 170 return new TrackedCallback(resource, |
| 171 PP_MakeCompletionCallback(&IgnoredCompletionCallback, NULL)); |
171 } | 172 } |
172 | 173 |
173 void PPB_AudioInput_Shared::SetStartCaptureState() { | 174 void PPB_AudioInput_Shared::SetStartCaptureState() { |
174 DCHECK(!capturing_); | 175 DCHECK(!capturing_); |
175 DCHECK(!audio_input_thread_.get()); | 176 DCHECK(!audio_input_thread_.get()); |
176 | 177 |
177 capturing_ = true; | 178 capturing_ = true; |
178 StartThread(); | 179 StartThread(); |
179 } | 180 } |
180 | 181 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 if (buffer->params.size > 0) | 248 if (buffer->params.size > 0) |
248 audio_input_callback_(&buffer->audio[0], buffer->params.size, user_data_); | 249 audio_input_callback_(&buffer->audio[0], buffer->params.size, user_data_); |
249 } | 250 } |
250 } | 251 } |
251 | 252 |
252 int32_t PPB_AudioInput_Shared::CommonOpen( | 253 int32_t PPB_AudioInput_Shared::CommonOpen( |
253 const std::string& device_id, | 254 const std::string& device_id, |
254 PP_Resource config, | 255 PP_Resource config, |
255 PPB_AudioInput_Callback audio_input_callback, | 256 PPB_AudioInput_Callback audio_input_callback, |
256 void* user_data, | 257 void* user_data, |
257 PP_CompletionCallback callback) { | 258 scoped_refptr<TrackedCallback> callback) { |
258 if (open_state_ != BEFORE_OPEN) | 259 if (open_state_ != BEFORE_OPEN) |
259 return PP_ERROR_FAILED; | 260 return PP_ERROR_FAILED; |
260 | 261 |
261 thunk::EnterResourceNoLock<thunk::PPB_AudioConfig_API> enter_config(config, | 262 thunk::EnterResourceNoLock<thunk::PPB_AudioConfig_API> enter_config(config, |
262 true); | 263 true); |
263 if (enter_config.failed()) | 264 if (enter_config.failed()) |
264 return PP_ERROR_BADARGUMENT; | 265 return PP_ERROR_BADARGUMENT; |
265 | 266 |
266 if (!callback.func) | |
267 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
268 | |
269 if (TrackedCallback::IsPending(open_callback_)) | 267 if (TrackedCallback::IsPending(open_callback_)) |
270 return PP_ERROR_INPROGRESS; | 268 return PP_ERROR_INPROGRESS; |
271 | 269 |
272 config_ = config; | 270 config_ = config; |
273 audio_input_callback_ = audio_input_callback; | 271 audio_input_callback_ = audio_input_callback; |
274 user_data_ = user_data; | 272 user_data_ = user_data; |
275 | 273 |
276 return InternalOpen(device_id, enter_config.object()->GetSampleRate(), | 274 return InternalOpen(device_id, enter_config.object()->GetSampleRate(), |
277 enter_config.object()->GetSampleFrameCount(), callback); | 275 enter_config.object()->GetSampleFrameCount(), callback); |
278 } | 276 } |
279 | 277 |
280 } // namespace ppapi | 278 } // namespace ppapi |
OLD | NEW |