Index: media/audio/win/audio_low_latency_input_win.cc |
diff --git a/media/audio/win/audio_low_latency_input_win.cc b/media/audio/win/audio_low_latency_input_win.cc |
index c6bb0ed06ad94a9e25bdc78dcd63f7a66f79fcbd..c1c1d42c6a2fbb2b3cae2d872b20d0c1d0684a3a 100644 |
--- a/media/audio/win/audio_low_latency_input_win.cc |
+++ b/media/audio/win/audio_low_latency_input_win.cc |
@@ -184,6 +184,31 @@ void WASAPIAudioInputStream::Close() { |
// static |
double WASAPIAudioInputStream::HardwareSampleRate(ERole device_role) { |
+ base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; |
+ HRESULT hr = GetMixFormat(device_role, &audio_engine_mix_format); |
+ if (FAILED(hr)) { |
+ NOTREACHED() << "error code: " << hr; |
+ return 0.0; |
+ } |
+ |
+ return static_cast<double>(audio_engine_mix_format->nSamplesPerSec); |
+} |
+ |
+// static |
+size_t WASAPIAudioInputStream::HardwareChannels(ERole device_role) { |
+ base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; |
+ HRESULT hr = GetMixFormat(device_role, &audio_engine_mix_format); |
+ if (FAILED(hr)) { |
+ NOTREACHED() << "error code: " << hr; |
+ return CHANNEL_LAYOUT_NONE; |
+ } |
+ |
+ return audio_engine_mix_format->nChannels; |
+} |
+ |
+// static |
+HRESULT WASAPIAudioInputStream::GetMixFormat(ERole device_role, |
+ WAVEFORMATEX** device_format) { |
// It is assumed that this static method is called from a COM thread, i.e., |
// CoInitializeEx() is not called here to avoid STA/MTA conflicts. |
ScopedComPtr<IMMDeviceEnumerator> enumerator; |
@@ -193,8 +218,7 @@ double WASAPIAudioInputStream::HardwareSampleRate(ERole device_role) { |
__uuidof(IMMDeviceEnumerator), |
enumerator.ReceiveVoid()); |
if (FAILED(hr)) { |
tommi (sloooow) - chröme
2012/01/17 12:01:08
nit: remove {}
henrika (OOO until Aug 14)
2012/01/17 12:54:59
Done.
|
- NOTREACHED() << "error code: " << hr; |
- return 0.0; |
+ return hr; |
} |
ScopedComPtr<IMMDevice> endpoint_device; |
@@ -206,7 +230,7 @@ double WASAPIAudioInputStream::HardwareSampleRate(ERole device_role) { |
// (e.g. some audio cards that have inputs will still report them as |
// "not found" when no mic is plugged into the input jack). |
LOG(WARNING) << "No audio end point: " << std::hex << hr; |
- return 0.0; |
+ return hr; |
} |
ScopedComPtr<IAudioClient> audio_client; |
@@ -214,19 +238,10 @@ double WASAPIAudioInputStream::HardwareSampleRate(ERole device_role) { |
CLSCTX_INPROC_SERVER, |
NULL, |
audio_client.ReceiveVoid()); |
- if (FAILED(hr)) { |
- NOTREACHED() << "error code: " << hr; |
- return 0.0; |
- } |
+ if (SUCCEEDED(hr)) |
+ hr = audio_client->GetMixFormat(device_format); |
- base::win::ScopedCoMem<WAVEFORMATEX> audio_engine_mix_format; |
- hr = audio_client->GetMixFormat(&audio_engine_mix_format); |
- if (FAILED(hr)) { |
- NOTREACHED() << "error code: " << hr; |
- return 0.0; |
- } |
- |
- return static_cast<double>(audio_engine_mix_format->nSamplesPerSec); |
+ return hr; |
} |
void WASAPIAudioInputStream::Run() { |