Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_util.h" | 14 #include "media/audio/audio_util.h" |
| 15 #include "media/audio/win/audio_manager_win.h" | 15 #include "media/audio/win/audio_manager_win.h" |
| 16 | 16 |
| 17 namespace { | |
| 18 const int kCallbackTimeout = 1000; // One second. | |
|
Satish
2011/06/14 14:28:04
rename to kStopInputStreamCallbackTimeout to be mo
allanwoj
2011/06/14 15:03:12
Done.
| |
| 19 } | |
| 20 | |
| 17 // Our sound buffers are allocated once and kept in a linked list using the | 21 // 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. | 22 // the WAVEHDR::dwUser variable. The last buffer points to the first buffer. |
| 19 static WAVEHDR* GetNextBuffer(WAVEHDR* current) { | 23 static WAVEHDR* GetNextBuffer(WAVEHDR* current) { |
| 20 return reinterpret_cast<WAVEHDR*>(current->dwUser); | 24 return reinterpret_cast<WAVEHDR*>(current->dwUser); |
| 21 } | 25 } |
| 22 | 26 |
| 23 PCMWaveInAudioInputStream::PCMWaveInAudioInputStream( | 27 PCMWaveInAudioInputStream::PCMWaveInAudioInputStream( |
| 24 AudioManagerWin* manager, AudioParameters params, int num_buffers, | 28 AudioManagerWin* manager, AudioParameters params, int num_buffers, |
| 25 UINT device_id) | 29 UINT device_id) |
| 26 : state_(kStateEmpty), | 30 : state_(kStateEmpty), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 127 |
| 124 // Stopping is tricky. First, no buffer should be locked by the audio driver | 128 // 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 | 129 // or else the waveInReset() will deadlock and secondly, the callback should |
| 126 // not be inside the AudioInputCallback's OnData because waveInReset() | 130 // not be inside the AudioInputCallback's OnData because waveInReset() |
| 127 // forcefully kills the callback thread. | 131 // forcefully kills the callback thread. |
| 128 void PCMWaveInAudioInputStream::Stop() { | 132 void PCMWaveInAudioInputStream::Stop() { |
| 129 if (state_ != kStateRecording) | 133 if (state_ != kStateRecording) |
| 130 return; | 134 return; |
| 131 state_ = kStateStopping; | 135 state_ = kStateStopping; |
| 132 // Wait for the callback to finish, it will signal us when ready to be reset. | 136 // Wait for the callback to finish, it will signal us when ready to be reset. |
| 133 if (WAIT_OBJECT_0 != ::WaitForSingleObject(stopped_event_, INFINITE)) { | 137 if (WAIT_OBJECT_0 != |
| 138 ::WaitForSingleObject(stopped_event_, kCallbackTimeout)) { | |
| 134 HandleError(::GetLastError()); | 139 HandleError(::GetLastError()); |
| 135 return; | 140 return; |
| 136 } | 141 } |
| 137 state_ = kStateStopped; | 142 state_ = kStateStopped; |
| 138 MMRESULT res = ::waveInReset(wavein_); | 143 MMRESULT res = ::waveInReset(wavein_); |
| 139 if (res != MMSYSERR_NOERROR) { | 144 if (res != MMSYSERR_NOERROR) { |
| 140 state_ = kStateRecording; | 145 state_ = kStateRecording; |
| 141 HandleError(res); | 146 HandleError(res); |
| 142 return; | 147 return; |
| 143 } | 148 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 // waveInPrepareHeader. | 208 // waveInPrepareHeader. |
| 204 obj->QueueNextPacket(buffer); | 209 obj->QueueNextPacket(buffer); |
| 205 } | 210 } |
| 206 } else if (msg == WIM_CLOSE) { | 211 } else if (msg == WIM_CLOSE) { |
| 207 // We can be closed before calling Start, so it is possible to have a | 212 // We can be closed before calling Start, so it is possible to have a |
| 208 // null callback at this point. | 213 // null callback at this point. |
| 209 if (obj->callback_) | 214 if (obj->callback_) |
| 210 obj->callback_->OnClose(obj); | 215 obj->callback_->OnClose(obj); |
| 211 } | 216 } |
| 212 } | 217 } |
| OLD | NEW |