Chromium Code Reviews| Index: media/audio/win/core_audio_util_win.cc |
| diff --git a/media/audio/win/core_audio_util_win.cc b/media/audio/win/core_audio_util_win.cc |
| index efd757ee7498bcb28221a33ca473d286823aee61..4adfdda090a1e474a01e3424b51a7e71dc1d06d4 100644 |
| --- a/media/audio/win/core_audio_util_win.cc |
| +++ b/media/audio/win/core_audio_util_win.cc |
| @@ -123,7 +123,7 @@ static std::ostream& operator<<(std::ostream& os, |
| return os; |
| } |
| -bool LoadAudiosesDll() { |
| +static bool LoadAudiosesDll() { |
| static const wchar_t* const kAudiosesDLL = |
| L"%WINDIR%\\system32\\audioses.dll"; |
| @@ -132,7 +132,7 @@ bool LoadAudiosesDll() { |
| return (LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) != NULL); |
| } |
| -bool CanCreateDeviceEnumerator() { |
| +static bool CanCreateDeviceEnumerator() { |
| ScopedComPtr<IMMDeviceEnumerator> device_enumerator; |
| HRESULT hr = device_enumerator.CreateInstance(__uuidof(MMDeviceEnumerator), |
| NULL, CLSCTX_INPROC_SERVER); |
| @@ -144,6 +144,14 @@ bool CanCreateDeviceEnumerator() { |
| return SUCCEEDED(hr); |
| } |
| +static std::string GetDeviceID(IMMDevice* device) { |
| + ScopedCoMem<WCHAR> device_id_com; |
| + std::string device_id; |
| + if (SUCCEEDED(device->GetId(&device_id_com))) |
| + WideToUTF8(device_id_com, wcslen(device_id_com), &device_id); |
| + return device_id; |
| +} |
| + |
| bool CoreAudioUtil::IsSupported() { |
| // It is possible to force usage of WaveXxx APIs by using a command line flag. |
| const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| @@ -263,6 +271,12 @@ ScopedComPtr<IMMDevice> CoreAudioUtil::CreateDefaultDevice(EDataFlow data_flow, |
| return endpoint_device; |
| } |
| +std::string CoreAudioUtil::GetDefaultOutputDeviceID() { |
| + DCHECK(IsSupported()); |
| + ScopedComPtr<IMMDevice> device(CreateDefaultDevice(eRender, eConsole)); |
| + return device ? GetDeviceID(device) : std::string(); |
| +} |
| + |
| ScopedComPtr<IMMDevice> CoreAudioUtil::CreateDevice( |
| const std::string& device_id) { |
| DCHECK(IsSupported()); |
| @@ -289,17 +303,14 @@ HRESULT CoreAudioUtil::GetDeviceName(IMMDevice* device, AudioDeviceName* name) { |
| // Retrieve unique name of endpoint device. |
| // Example: "{0.0.1.00000000}.{8db6020f-18e3-4f25-b6f5-7726c9122574}". |
| AudioDeviceName device_name; |
| - ScopedCoMem<WCHAR> endpoint_device_id; |
| - HRESULT hr = device->GetId(&endpoint_device_id); |
| - if (FAILED(hr)) |
| - return hr; |
| - WideToUTF8(endpoint_device_id, wcslen(endpoint_device_id), |
| - &device_name.unique_id); |
| + device_name.unique_id = GetDeviceID(device); |
|
henrika (OOO until Aug 14)
2013/09/04 11:11:40
nice
|
| + if (device_name.unique_id.empty()) |
| + return E_FAIL; |
| // Retrieve user-friendly name of endpoint device. |
| // Example: "Microphone (Realtek High Definition Audio)". |
| ScopedComPtr<IPropertyStore> properties; |
| - hr = device->OpenPropertyStore(STGM_READ, properties.Receive()); |
| + HRESULT hr = device->OpenPropertyStore(STGM_READ, properties.Receive()); |
| if (FAILED(hr)) |
| return hr; |
| base::win::ScopedPropVariant friendly_name; |
| @@ -397,14 +408,7 @@ std::string CoreAudioUtil::GetMatchingOutputDeviceID( |
| output_device = NULL; |
| } |
| - std::string id; |
| - if (output_device) { |
| - ScopedCoMem<WCHAR> wide_id; |
| - output_device->GetId(&wide_id); |
| - WideToUTF8(wide_id, wcslen(wide_id), &id); |
| - } |
| - |
| - return id; |
| + return output_device ? GetDeviceID(output_device) : std::string(); |
| } |
| std::string CoreAudioUtil::GetFriendlyName(const std::string& device_id) { |
| @@ -429,16 +433,8 @@ bool CoreAudioUtil::DeviceIsDefault(EDataFlow flow, |
| if (!device) |
| return false; |
| - ScopedCoMem<WCHAR> default_device_id; |
| - HRESULT hr = device->GetId(&default_device_id); |
| - if (FAILED(hr)) |
| - return false; |
| - |
| - std::string str_default; |
| - WideToUTF8(default_device_id, wcslen(default_device_id), &str_default); |
| - if (device_id.compare(str_default) != 0) |
| - return false; |
| - return true; |
| + std::string str_default(GetDeviceID(device)); |
| + return device_id.compare(str_default) == 0; |
| } |
| EDataFlow CoreAudioUtil::GetDataFlow(IMMDevice* device) { |