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

Side by Side Diff: content/renderer/media/audio_input_device.cc

Issue 9534002: Stop the AudioDeviceThread when the IO loop goes away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle another edge case 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 "content/renderer/media/audio_input_device.h" 5 #include "content/renderer/media/audio_input_device.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // NOTE: |completion| may be NULL. 139 // NOTE: |completion| may be NULL.
140 // Make sure we don't call shutdown more than once. 140 // Make sure we don't call shutdown more than once.
141 if (stream_id_) { 141 if (stream_id_) {
142 filter_->RemoveDelegate(stream_id_); 142 filter_->RemoveDelegate(stream_id_);
143 Send(new AudioInputHostMsg_CloseStream(stream_id_)); 143 Send(new AudioInputHostMsg_CloseStream(stream_id_));
144 144
145 stream_id_ = 0; 145 stream_id_ = 0;
146 session_id_ = 0; 146 session_id_ = 0;
147 pending_device_ready_ = false; 147 pending_device_ready_ = false;
148 } 148 }
149
150 // We can run into an issue where ShutDownOnIOThread is called right after
151 // OnStreamCreated is called in cases where Start/Stop are called before we
152 // get the OnStreamCreated callback. To handle that corner case, we call
153 // Stop(). In most cases, the thread will already be stopped.
154 audio_thread_.Stop(MessageLoop::current());
149 audio_callback_.reset(); 155 audio_callback_.reset();
150 } 156 }
151 157
152 void AudioInputDevice::SetVolumeOnIOThread(double volume) { 158 void AudioInputDevice::SetVolumeOnIOThread(double volume) {
153 DCHECK(message_loop()->BelongsToCurrentThread()); 159 DCHECK(message_loop()->BelongsToCurrentThread());
154 if (stream_id_) 160 if (stream_id_)
155 Send(new AudioInputHostMsg_SetVolume(stream_id_, volume)); 161 Send(new AudioInputHostMsg_SetVolume(stream_id_, volume));
156 } 162 }
157 163
158 void AudioInputDevice::OnStreamCreated( 164 void AudioInputDevice::OnStreamCreated(
(...skipping 12 matching lines...) Expand all
171 DVLOG(1) << "OnStreamCreated (stream_id=" << stream_id_ << ")"; 177 DVLOG(1) << "OnStreamCreated (stream_id=" << stream_id_ << ")";
172 178
173 // Takes care of the case when Stop() is called before OnStreamCreated(). 179 // Takes care of the case when Stop() is called before OnStreamCreated().
174 if (!stream_id_) { 180 if (!stream_id_) {
175 base::SharedMemory::CloseHandle(handle); 181 base::SharedMemory::CloseHandle(handle);
176 // Close the socket handler. 182 // Close the socket handler.
177 base::SyncSocket socket(socket_handle); 183 base::SyncSocket socket(socket_handle);
178 return; 184 return;
179 } 185 }
180 186
187 DCHECK(audio_thread_.IsStopped());
181 audio_callback_.reset( 188 audio_callback_.reset(
182 new AudioInputDevice::AudioThreadCallback(audio_parameters_, handle, 189 new AudioInputDevice::AudioThreadCallback(audio_parameters_, handle,
183 length, callback_)); 190 length, callback_));
184 audio_thread_.Start(audio_callback_.get(), socket_handle, 191 audio_thread_.Start(audio_callback_.get(), socket_handle, "AudioInputDevice");
185 "AudioInputDevice");
186 192
187 MessageLoop::current()->PostTask(FROM_HERE, 193 MessageLoop::current()->PostTask(FROM_HERE,
188 base::Bind(&AudioInputDevice::StartOnIOThread, this)); 194 base::Bind(&AudioInputDevice::StartOnIOThread, this));
189 } 195 }
190 196
191 void AudioInputDevice::OnVolume(double volume) { 197 void AudioInputDevice::OnVolume(double volume) {
192 NOTIMPLEMENTED(); 198 NOTIMPLEMENTED();
193 } 199 }
194 200
195 void AudioInputDevice::OnStateChanged(AudioStreamState state) { 201 void AudioInputDevice::OnStateChanged(AudioStreamState state) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 pending_device_ready_ = false; 256 pending_device_ready_ = false;
251 // Notify the client that the device has been started. 257 // Notify the client that the device has been started.
252 if (event_handler_) 258 if (event_handler_)
253 event_handler_->OnDeviceStarted(device_id); 259 event_handler_->OnDeviceStarted(device_id);
254 } 260 }
255 261
256 void AudioInputDevice::Send(IPC::Message* message) { 262 void AudioInputDevice::Send(IPC::Message* message) {
257 filter_->Send(message); 263 filter_->Send(message);
258 } 264 }
259 265
260 void AudioInputDevice::WillDestroyCurrentMessageLoop() { 266 void AudioInputDevice::WillDestroyCurrentMessageLoop() {
scherkus (not reviewing) 2012/02/29 21:10:15 ditto
267 LOG(ERROR) << "IO loop going away before the input device has been stopped";
268 audio_thread_.Stop(NULL);
261 ShutDownOnIOThread(); 269 ShutDownOnIOThread();
262 } 270 }
263 271
264 // AudioInputDevice::AudioThreadCallback 272 // AudioInputDevice::AudioThreadCallback
265 AudioInputDevice::AudioThreadCallback::AudioThreadCallback( 273 AudioInputDevice::AudioThreadCallback::AudioThreadCallback(
266 const AudioParameters& audio_parameters, 274 const AudioParameters& audio_parameters,
267 base::SharedMemoryHandle memory, 275 base::SharedMemoryHandle memory,
268 int memory_length, 276 int memory_length,
269 CaptureCallback* capture_callback) 277 CaptureCallback* capture_callback)
270 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length), 278 : AudioDeviceThread::Callback(audio_parameters, memory, memory_length),
(...skipping 23 matching lines...) Expand all
294 channel_index, 302 channel_index,
295 bytes_per_sample, 303 bytes_per_sample,
296 number_of_frames); 304 number_of_frames);
297 } 305 }
298 306
299 // Deliver captured data to the client in floating point format 307 // Deliver captured data to the client in floating point format
300 // and update the audio-delay measurement. 308 // and update the audio-delay measurement.
301 capture_callback_->Capture(audio_data_, number_of_frames, 309 capture_callback_->Capture(audio_data_, number_of_frames,
302 audio_delay_milliseconds); 310 audio_delay_milliseconds);
303 } 311 }
OLDNEW
« content/renderer/media/audio_device_thread.h ('K') | « content/renderer/media/audio_device_thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698