Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: ppapi/shared_impl/ppb_audio_input_shared.cc

Issue 9705056: PepperPlatformAudioInputImpl: support audio input device selection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes in response to Shijing's suggestions. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/shared_impl/ppapi_globals.h" 9 #include "ppapi/shared_impl/ppapi_globals.h"
10 #include "ppapi/shared_impl/ppb_device_ref_shared.h" 10 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 85
86 PP_Bool PPB_AudioInput_Shared::StartCapture() { 86 PP_Bool PPB_AudioInput_Shared::StartCapture() {
87 if (open_state_ == CLOSED || (open_state_ == BEFORE_OPEN && 87 if (open_state_ == CLOSED || (open_state_ == BEFORE_OPEN &&
88 !TrackedCallback::IsPending(open_callback_))) { 88 !TrackedCallback::IsPending(open_callback_))) {
89 return PP_FALSE; 89 return PP_FALSE;
90 } 90 }
91 if (capturing_) 91 if (capturing_)
92 return PP_TRUE; 92 return PP_TRUE;
93 93
94 // If the audio input device hasn't been opened, set |capturing_| to true and
95 // return directly. Capturing will be started once the open operation is
96 // completed.
97 if (open_state_ == BEFORE_OPEN) {
98 capturing_ = true;
99 return PP_TRUE;
100 }
101
94 return InternalStartCapture(); 102 return InternalStartCapture();
95 } 103 }
96 104
97 PP_Bool PPB_AudioInput_Shared::StopCapture() { 105 PP_Bool PPB_AudioInput_Shared::StopCapture() {
98 if (open_state_ == CLOSED || (open_state_ == BEFORE_OPEN && 106 if (open_state_ == CLOSED)
99 !TrackedCallback::IsPending(open_callback_))) {
100 return PP_FALSE; 107 return PP_FALSE;
101 }
102 if (!capturing_) 108 if (!capturing_)
103 return PP_TRUE; 109 return PP_TRUE;
104 110
111 // If the audio input device hasn't been opened, set |capturing_| to false and
112 // return directly.
113 if (open_state_ == BEFORE_OPEN) {
114 capturing_ = false;
115 return PP_TRUE;
116 }
117
105 return InternalStopCapture(); 118 return InternalStopCapture();
106 } 119 }
107 120
108 void PPB_AudioInput_Shared::Close() { 121 void PPB_AudioInput_Shared::Close() {
109 if (open_state_ == CLOSED) 122 if (open_state_ == CLOSED)
110 return; 123 return;
111 124
112 open_state_ = CLOSED; 125 open_state_ = CLOSED;
113 InternalClose(); 126 InternalClose();
114 127
(...skipping 28 matching lines...) Expand all
143 base::SharedMemoryHandle shared_memory_handle, 156 base::SharedMemoryHandle shared_memory_handle,
144 size_t shared_memory_size, 157 size_t shared_memory_size,
145 base::SyncSocket::Handle socket_handle) { 158 base::SyncSocket::Handle socket_handle) {
146 if (open_state_ == BEFORE_OPEN && result == PP_OK) { 159 if (open_state_ == BEFORE_OPEN && result == PP_OK) {
147 open_state_ = OPENED; 160 open_state_ = OPENED;
148 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); 161 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle);
149 } else { 162 } else {
150 // Clean up the handles. 163 // Clean up the handles.
151 base::SyncSocket temp_socket(socket_handle); 164 base::SyncSocket temp_socket(socket_handle);
152 base::SharedMemory temp_mem(shared_memory_handle, false); 165 base::SharedMemory temp_mem(shared_memory_handle, false);
166 capturing_ = false;
153 } 167 }
154 168
155 // The callback may have been aborted by Close(). 169 // The callback may have been aborted by Close().
156 if (TrackedCallback::IsPending(open_callback_)) 170 if (TrackedCallback::IsPending(open_callback_))
157 TrackedCallback::ClearAndRun(&open_callback_, result); 171 TrackedCallback::ClearAndRun(&open_callback_, result);
158 } 172 }
159 173
160 // static 174 // static
161 PP_CompletionCallback PPB_AudioInput_Shared::MakeIgnoredCompletionCallback() { 175 PP_CompletionCallback PPB_AudioInput_Shared::MakeIgnoredCompletionCallback() {
162 return PP_MakeCompletionCallback(&IgnoredCompletionCallback, NULL); 176 return PP_MakeCompletionCallback(&IgnoredCompletionCallback, NULL);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 258
245 config_ = config; 259 config_ = config;
246 audio_input_callback_ = audio_input_callback; 260 audio_input_callback_ = audio_input_callback;
247 user_data_ = user_data; 261 user_data_ = user_data;
248 262
249 return InternalOpen(device_id, enter_config.object()->GetSampleRate(), 263 return InternalOpen(device_id, enter_config.object()->GetSampleRate(),
250 enter_config.object()->GetSampleFrameCount(), callback); 264 enter_config.object()->GetSampleFrameCount(), callback);
251 } 265 }
252 266
253 } // namespace ppapi 267 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698