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

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: sync&resolve again 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
« no previous file with comments | « ppapi/examples/audio_input/audio_input.html ('k') | webkit/plugins/ppapi/audio_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
163 } 177 }
164 178
165 void PPB_AudioInput_Shared::SetStartCaptureState() { 179 void PPB_AudioInput_Shared::SetStartCaptureState() {
166 DCHECK(!capturing_); 180 DCHECK(!capturing_);
167 DCHECK(!audio_input_thread_.get()); 181 DCHECK(!audio_input_thread_.get());
168 182
169 // If the socket doesn't exist, that means that the plugin has started before
170 // the browser has had a chance to create all the shared memory info and
171 // notify us. This is a common case. In this case, we just set the capturing_
172 // flag and the capture will automatically start when that data is available
173 // in SetStreamInfo.
174 if (audio_input_callback_ && socket_.get()) 183 if (audio_input_callback_ && socket_.get())
175 StartThread(); 184 StartThread();
176 capturing_ = true; 185 capturing_ = true;
177 } 186 }
178 187
179 void PPB_AudioInput_Shared::SetStopCaptureState() { 188 void PPB_AudioInput_Shared::SetStopCaptureState() {
180 DCHECK(capturing_); 189 DCHECK(capturing_);
181 190
182 if (audio_input_thread_.get()) { 191 if (audio_input_thread_.get()) {
183 audio_input_thread_->Join(); 192 audio_input_thread_->Join();
184 audio_input_thread_.reset(); 193 audio_input_thread_.reset();
185 } 194 }
186 capturing_ = false; 195 capturing_ = false;
187 } 196 }
188 197
189 void PPB_AudioInput_Shared::SetStreamInfo( 198 void PPB_AudioInput_Shared::SetStreamInfo(
190 base::SharedMemoryHandle shared_memory_handle, 199 base::SharedMemoryHandle shared_memory_handle,
191 size_t shared_memory_size, 200 size_t shared_memory_size,
192 base::SyncSocket::Handle socket_handle) { 201 base::SyncSocket::Handle socket_handle) {
193 socket_.reset(new base::SyncSocket(socket_handle)); 202 socket_.reset(new base::SyncSocket(socket_handle));
194 shared_memory_.reset(new base::SharedMemory(shared_memory_handle, false)); 203 shared_memory_.reset(new base::SharedMemory(shared_memory_handle, false));
195 shared_memory_size_ = shared_memory_size; 204 shared_memory_size_ = shared_memory_size;
196 205
197 if (audio_input_callback_) { 206 if (audio_input_callback_)
198 shared_memory_->Map(shared_memory_size_); 207 shared_memory_->Map(shared_memory_size_);
199 208
200 // StartCapture() may be called before SetSreamInfo(). 209 // There is a pending capture request before SetStreamInfo().
201 if (capturing_) 210 if (capturing_) {
202 StartThread(); 211 // Set |capturing_| to false so that the state looks consistent to
212 // InternalStartCapture(). It will be reset to true by
213 // SetStartCaptureState().
214 capturing_ = false;
215 InternalStartCapture();
203 } 216 }
204 } 217 }
205 218
206 void PPB_AudioInput_Shared::StartThread() { 219 void PPB_AudioInput_Shared::StartThread() {
207 DCHECK(audio_input_callback_); 220 DCHECK(audio_input_callback_);
208 DCHECK(!audio_input_thread_.get()); 221 DCHECK(!audio_input_thread_.get());
209 audio_input_thread_.reset(new base::DelegateSimpleThread( 222 audio_input_thread_.reset(new base::DelegateSimpleThread(
210 this, "plugin_audio_input_thread")); 223 this, "plugin_audio_input_thread"));
211 audio_input_thread_->Start(); 224 audio_input_thread_->Start();
212 } 225 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 257
245 config_ = config; 258 config_ = config;
246 audio_input_callback_ = audio_input_callback; 259 audio_input_callback_ = audio_input_callback;
247 user_data_ = user_data; 260 user_data_ = user_data;
248 261
249 return InternalOpen(device_id, enter_config.object()->GetSampleRate(), 262 return InternalOpen(device_id, enter_config.object()->GetSampleRate(),
250 enter_config.object()->GetSampleFrameCount(), callback); 263 enter_config.object()->GetSampleFrameCount(), callback);
251 } 264 }
252 265
253 } // namespace ppapi 266 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/examples/audio_input/audio_input.html ('k') | webkit/plugins/ppapi/audio_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698