Index: media/audio/win/wavein_input_win.cc |
=================================================================== |
--- media/audio/win/wavein_input_win.cc (revision 112154) |
+++ media/audio/win/wavein_input_win.cc (working copy) |
@@ -12,11 +12,14 @@ |
#include "media/audio/audio_io.h" |
#include "media/audio/audio_util.h" |
#include "media/audio/win/audio_manager_win.h" |
+#include "media/audio/win/device_enumeration_win.h" |
namespace { |
const int kStopInputStreamCallbackTimeout = 3000; // Three seconds. |
} |
+using media::AudioDeviceNames; |
+ |
// Our sound buffers are allocated once and kept in a linked list using the |
// the WAVEHDR::dwUser variable. The last buffer points to the first buffer. |
static WAVEHDR* GetNextBuffer(WAVEHDR* current) { |
@@ -25,7 +28,7 @@ |
PCMWaveInAudioInputStream::PCMWaveInAudioInputStream( |
AudioManagerWin* manager, const AudioParameters& params, int num_buffers, |
- UINT device_id) |
+ const std::string& device_id) |
: state_(kStateEmpty), |
manager_(manager), |
device_id_(device_id), |
@@ -58,10 +61,20 @@ |
return false; |
if (num_buffers_ < 2 || num_buffers_ > 10) |
return false; |
- MMRESULT result = ::waveInOpen(&wavein_, device_id_, &format_, |
- reinterpret_cast<DWORD_PTR>(WaveCallback), |
- reinterpret_cast<DWORD_PTR>(this), |
- CALLBACK_FUNCTION); |
+ |
+ // Convert the stored device id string into an unsigned integer |
+ // corresponding to the selected device. |
+ UINT device_id = WAVE_MAPPER; |
+ if (!GetDeviceId(&device_id)) { |
+ return false; |
+ } |
+ |
+ // Open the specified input device for recording. |
+ MMRESULT result = MMSYSERR_NOERROR; |
+ result = ::waveInOpen(&wavein_, device_id, &format_, |
+ reinterpret_cast<DWORD_PTR>(WaveCallback), |
+ reinterpret_cast<DWORD_PTR>(this), |
+ CALLBACK_FUNCTION); |
if (result != MMSYSERR_NOERROR) |
return false; |
@@ -185,6 +198,40 @@ |
HandleError(res); |
} |
+bool PCMWaveInAudioInputStream::GetDeviceId(UINT* device_index) { |
+ // Deliver the default input device id (WAVE_MAPPER) if the default |
+ // device has been selected. |
+ if (device_id_ == AudioManagerBase::kDefaultDeviceId) { |
+ *device_index = WAVE_MAPPER; |
+ return true; |
+ } |
+ |
+ // Get list of all available and active devices. |
+ AudioDeviceNames device_names; |
+ if (!GetInputDeviceNamesWinXP(&device_names)) { |
tommi (sloooow) - chröme
2011/12/01 14:11:03
nit: no need for {} (like the the next statement)
henrika (OOO until Aug 14)
2011/12/01 16:02:38
Done.
|
+ return false; |
+ } |
+ |
+ if (device_names.empty()) |
+ return false; |
+ |
+ // Search the full list of devices and compare with the specified |
+ // device id which was specified in the constructor. Stop comparing |
+ // when a match is found and return the corresponding index. |
+ UINT index = 0; |
+ AudioDeviceNames::const_iterator it = device_names.begin(); |
+ while (it != device_names.end()) { |
no longer working on chromium
2011/12/01 15:28:03
what happen if none of the device in the list matc
henrika (OOO until Aug 14)
2011/12/01 16:02:38
Done.
|
+ if (it->unique_id.compare(device_id_) == 0) { |
no longer working on chromium
2011/12/01 15:28:03
we can directly use device_id_ == it->unique_id
henrika (OOO until Aug 14)
2011/12/01 16:02:38
I actually prefer the compare() method for std::st
|
+ *device_index = index; |
+ break; |
+ } |
+ ++index; |
+ ++it; |
+ } |
+ |
+ return true; |
+} |
+ |
// Windows calls us back in this function when some events happen. Most notably |
// when it has an audio buffer with recorded data. |
void PCMWaveInAudioInputStream::WaveCallback(HWAVEIN hwi, UINT msg, |