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

Side by Side Diff: media/audio/win/wavein_input_win.cc

Issue 7129057: Fix bug when unplugging an audio input device whilst using speech input. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Removed unnecessary includes Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "media/audio/win/wavein_input_win.h" 5 #include "media/audio/win/wavein_input_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <mmsystem.h> 8 #include <mmsystem.h>
9 #pragma comment(lib, "winmm.lib") 9 #pragma comment(lib, "winmm.lib")
10 10
11 #include "base/basictypes.h"
12 #include "base/logging.h" 11 #include "base/logging.h"
13 #include "media/audio/audio_io.h" 12 #include "media/audio/audio_io.h"
14 #include "media/audio/audio_util.h" 13 #include "media/audio/audio_util.h"
15 #include "media/audio/win/audio_manager_win.h" 14 #include "media/audio/win/audio_manager_win.h"
16 15
16 namespace {
17 const int kStopInputStreamCallbackTimeout = 3000; // Three seconds.
18 }
19
17 // Our sound buffers are allocated once and kept in a linked list using the 20 // Our sound buffers are allocated once and kept in a linked list using the
18 // the WAVEHDR::dwUser variable. The last buffer points to the first buffer. 21 // the WAVEHDR::dwUser variable. The last buffer points to the first buffer.
19 static WAVEHDR* GetNextBuffer(WAVEHDR* current) { 22 static WAVEHDR* GetNextBuffer(WAVEHDR* current) {
20 return reinterpret_cast<WAVEHDR*>(current->dwUser); 23 return reinterpret_cast<WAVEHDR*>(current->dwUser);
21 } 24 }
22 25
23 PCMWaveInAudioInputStream::PCMWaveInAudioInputStream( 26 PCMWaveInAudioInputStream::PCMWaveInAudioInputStream(
24 AudioManagerWin* manager, AudioParameters params, int num_buffers, 27 AudioManagerWin* manager, AudioParameters params, int num_buffers,
25 UINT device_id) 28 UINT device_id)
26 : state_(kStateEmpty), 29 : state_(kStateEmpty),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 126
124 // Stopping is tricky. First, no buffer should be locked by the audio driver 127 // Stopping is tricky. First, no buffer should be locked by the audio driver
125 // or else the waveInReset() will deadlock and secondly, the callback should 128 // or else the waveInReset() will deadlock and secondly, the callback should
126 // not be inside the AudioInputCallback's OnData because waveInReset() 129 // not be inside the AudioInputCallback's OnData because waveInReset()
127 // forcefully kills the callback thread. 130 // forcefully kills the callback thread.
128 void PCMWaveInAudioInputStream::Stop() { 131 void PCMWaveInAudioInputStream::Stop() {
129 if (state_ != kStateRecording) 132 if (state_ != kStateRecording)
130 return; 133 return;
131 state_ = kStateStopping; 134 state_ = kStateStopping;
132 // Wait for the callback to finish, it will signal us when ready to be reset. 135 // Wait for the callback to finish, it will signal us when ready to be reset.
133 if (WAIT_OBJECT_0 != ::WaitForSingleObject(stopped_event_, INFINITE)) { 136 if (WAIT_OBJECT_0 !=
137 ::WaitForSingleObject(stopped_event_, kStopInputStreamCallbackTimeout)) {
134 HandleError(::GetLastError()); 138 HandleError(::GetLastError());
135 return; 139 return;
136 } 140 }
137 state_ = kStateStopped; 141 state_ = kStateStopped;
138 MMRESULT res = ::waveInReset(wavein_); 142 MMRESULT res = ::waveInReset(wavein_);
139 if (res != MMSYSERR_NOERROR) { 143 if (res != MMSYSERR_NOERROR) {
140 state_ = kStateRecording; 144 state_ = kStateRecording;
141 HandleError(res); 145 HandleError(res);
142 return; 146 return;
143 } 147 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // waveInPrepareHeader. 207 // waveInPrepareHeader.
204 obj->QueueNextPacket(buffer); 208 obj->QueueNextPacket(buffer);
205 } 209 }
206 } else if (msg == WIM_CLOSE) { 210 } else if (msg == WIM_CLOSE) {
207 // We can be closed before calling Start, so it is possible to have a 211 // We can be closed before calling Start, so it is possible to have a
208 // null callback at this point. 212 // null callback at this point.
209 if (obj->callback_) 213 if (obj->callback_)
210 obj->callback_->OnClose(obj); 214 obj->callback_->OnClose(obj);
211 } 215 }
212 } 216 }
OLDNEW
« media/audio/audio_input_controller.cc ('K') | « media/audio/audio_input_controller_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698