| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/core_audio_util_win.h" | 5 #include "media/audio/win/core_audio_util_win.h" |
| 6 | 6 |
| 7 #include <devicetopology.h> | 7 #include <devicetopology.h> |
| 8 #include <dxdiag.h> | 8 #include <dxdiag.h> |
| 9 #include <functiondiscoverykeys_devpkey.h> | 9 #include <functiondiscoverykeys_devpkey.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/win/scoped_co_mem.h" | 17 #include "base/win/scoped_co_mem.h" |
| 18 #include "base/win/scoped_handle.h" | 18 #include "base/win/scoped_handle.h" |
| 19 #include "base/win/scoped_propvariant.h" | 19 #include "base/win/scoped_propvariant.h" |
| 20 #include "base/win/scoped_variant.h" | 20 #include "base/win/scoped_variant.h" |
| 21 #include "base/win/windows_version.h" | 21 #include "base/win/windows_version.h" |
| 22 #include "media/audio/audio_manager_base.h" | 22 #include "media/audio/audio_device_description.h" |
| 23 #include "media/base/media_switches.h" | 23 #include "media/base/media_switches.h" |
| 24 | 24 |
| 25 using base::win::ScopedCoMem; | 25 using base::win::ScopedCoMem; |
| 26 using base::win::ScopedHandle; | 26 using base::win::ScopedHandle; |
| 27 | 27 |
| 28 namespace media { | 28 namespace media { |
| 29 | 29 |
| 30 // See header file for documentation. | 30 // See header file for documentation. |
| 31 // {BE39AF4F-087C-423F-9303-234EC1E5B8EE} | 31 // {BE39AF4F-087C-423F-9303-234EC1E5B8EE} |
| 32 const GUID kCommunicationsSessionId = { | 32 const GUID kCommunicationsSessionId = { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 static std::string GetDeviceID(IMMDevice* device) { | 143 static std::string GetDeviceID(IMMDevice* device) { |
| 144 ScopedCoMem<WCHAR> device_id_com; | 144 ScopedCoMem<WCHAR> device_id_com; |
| 145 std::string device_id; | 145 std::string device_id; |
| 146 if (SUCCEEDED(device->GetId(&device_id_com))) | 146 if (SUCCEEDED(device->GetId(&device_id_com))) |
| 147 base::WideToUTF8(device_id_com, wcslen(device_id_com), &device_id); | 147 base::WideToUTF8(device_id_com, wcslen(device_id_com), &device_id); |
| 148 return device_id; | 148 return device_id; |
| 149 } | 149 } |
| 150 | 150 |
| 151 static bool IsDefaultDeviceId(const std::string& device_id) { | 151 static bool IsDefaultDeviceId(const std::string& device_id) { |
| 152 return device_id.empty() || device_id == AudioManagerBase::kDefaultDeviceId; | 152 return device_id.empty() || |
| 153 device_id == AudioDeviceDescription::kDefaultDeviceId; |
| 153 } | 154 } |
| 154 | 155 |
| 155 static bool IsDeviceActive(IMMDevice* device) { | 156 static bool IsDeviceActive(IMMDevice* device) { |
| 156 DWORD state = DEVICE_STATE_DISABLED; | 157 DWORD state = DEVICE_STATE_DISABLED; |
| 157 return SUCCEEDED(device->GetState(&state)) && (state & DEVICE_STATE_ACTIVE); | 158 return SUCCEEDED(device->GetState(&state)) && (state & DEVICE_STATE_ACTIVE); |
| 158 } | 159 } |
| 159 | 160 |
| 160 static HRESULT GetDeviceFriendlyNameInternal(IMMDevice* device, | 161 static HRESULT GetDeviceFriendlyNameInternal(IMMDevice* device, |
| 161 std::string* friendly_name) { | 162 std::string* friendly_name) { |
| 162 // Retrieve user-friendly name of endpoint device. | 163 // Retrieve user-friendly name of endpoint device. |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 const std::string& input_device_id) { | 434 const std::string& input_device_id) { |
| 434 // Special handling for the default communications device. | 435 // Special handling for the default communications device. |
| 435 // We always treat the configured communications devices, as a pair. | 436 // We always treat the configured communications devices, as a pair. |
| 436 // If we didn't do that and the user has e.g. configured a mic of a headset | 437 // If we didn't do that and the user has e.g. configured a mic of a headset |
| 437 // as the default comms input device and a different device (not the speakers | 438 // as the default comms input device and a different device (not the speakers |
| 438 // of the headset) as the default comms output device, then we would otherwise | 439 // of the headset) as the default comms output device, then we would otherwise |
| 439 // here pick the headset as the matched output device. That's technically | 440 // here pick the headset as the matched output device. That's technically |
| 440 // correct, but the user experience would be that any audio played out to | 441 // correct, but the user experience would be that any audio played out to |
| 441 // the matched device, would get ducked since it's not the default comms | 442 // the matched device, would get ducked since it's not the default comms |
| 442 // device. So here, we go with the user's configuration. | 443 // device. So here, we go with the user's configuration. |
| 443 if (input_device_id == AudioManagerBase::kCommunicationsDeviceId) | 444 if (input_device_id == AudioDeviceDescription::kCommunicationsDeviceId) |
| 444 return AudioManagerBase::kCommunicationsDeviceId; | 445 return AudioDeviceDescription::kCommunicationsDeviceId; |
| 445 | 446 |
| 446 ScopedComPtr<IMMDevice> input_device; | 447 ScopedComPtr<IMMDevice> input_device; |
| 447 if (IsDefaultDeviceId(input_device_id)) { | 448 if (IsDefaultDeviceId(input_device_id)) { |
| 448 input_device = CreateDefaultDevice(eCapture, eConsole); | 449 input_device = CreateDefaultDevice(eCapture, eConsole); |
| 449 } else { | 450 } else { |
| 450 input_device = CreateDevice(input_device_id); | 451 input_device = CreateDevice(input_device_id); |
| 451 } | 452 } |
| 452 | 453 |
| 453 if (!input_device.get()) | 454 if (!input_device.get()) |
| 454 return std::string(); | 455 return std::string(); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 *params = audio_params; | 737 *params = audio_params; |
| 737 return hr; | 738 return hr; |
| 738 } | 739 } |
| 739 | 740 |
| 740 HRESULT CoreAudioUtil::GetPreferredAudioParameters(const std::string& device_id, | 741 HRESULT CoreAudioUtil::GetPreferredAudioParameters(const std::string& device_id, |
| 741 bool is_output_device, | 742 bool is_output_device, |
| 742 AudioParameters* params) { | 743 AudioParameters* params) { |
| 743 DCHECK(IsSupported()); | 744 DCHECK(IsSupported()); |
| 744 | 745 |
| 745 ScopedComPtr<IMMDevice> device; | 746 ScopedComPtr<IMMDevice> device; |
| 746 if (device_id == AudioManagerBase::kDefaultDeviceId) { | 747 if (device_id == AudioDeviceDescription::kDefaultDeviceId) { |
| 747 device = CoreAudioUtil::CreateDefaultDevice( | 748 device = CoreAudioUtil::CreateDefaultDevice( |
| 748 is_output_device ? eRender : eCapture, eConsole); | 749 is_output_device ? eRender : eCapture, eConsole); |
| 749 } else if (device_id == AudioManagerBase::kLoopbackInputDeviceId) { | 750 } else if (device_id == AudioDeviceDescription::kLoopbackInputDeviceId) { |
| 750 DCHECK(!is_output_device); | 751 DCHECK(!is_output_device); |
| 751 device = CoreAudioUtil::CreateDefaultDevice(eRender, eConsole); | 752 device = CoreAudioUtil::CreateDefaultDevice(eRender, eConsole); |
| 752 } else if (device_id == AudioManagerBase::kCommunicationsDeviceId) { | 753 } else if (device_id == AudioDeviceDescription::kCommunicationsDeviceId) { |
| 753 device = CoreAudioUtil::CreateDefaultDevice( | 754 device = CoreAudioUtil::CreateDefaultDevice( |
| 754 is_output_device ? eRender : eCapture, eCommunications); | 755 is_output_device ? eRender : eCapture, eCommunications); |
| 755 } else { | 756 } else { |
| 756 device = CreateDevice(device_id); | 757 device = CreateDevice(device_id); |
| 757 } | 758 } |
| 758 | 759 |
| 759 if (!device.get()) { | 760 if (!device.get()) { |
| 760 // Map NULL-pointer to new error code which can be different from the | 761 // Map NULL-pointer to new error code which can be different from the |
| 761 // actual error code. The exact value is not important here. | 762 // actual error code. The exact value is not important here. |
| 762 return AUDCLNT_E_DEVICE_INVALIDATED; | 763 return AUDCLNT_E_DEVICE_INVALIDATED; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 | 964 |
| 964 if (variant.type() == VT_BSTR && variant.ptr()->bstrVal) { | 965 if (variant.type() == VT_BSTR && variant.ptr()->bstrVal) { |
| 965 base::WideToUTF8(variant.ptr()->bstrVal, wcslen(variant.ptr()->bstrVal), | 966 base::WideToUTF8(variant.ptr()->bstrVal, wcslen(variant.ptr()->bstrVal), |
| 966 driver_version); | 967 driver_version); |
| 967 } | 968 } |
| 968 | 969 |
| 969 return true; | 970 return true; |
| 970 } | 971 } |
| 971 | 972 |
| 972 } // namespace media | 973 } // namespace media |
| OLD | NEW |