Commit 8fca5bbd authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Add suffix to bluetooth audio device names.

This change is consistent with how device names are reported on Mac.

Bug: 780492
Change-Id: I835115156a51681744f005d495459a5aa5859cba
Reviewed-on: https://chromium-review.googlesource.com/1251454
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarMax Morin <maxmorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595295}
parent ddf2f59b
......@@ -89,12 +89,12 @@ static bool GetDeviceNamesWinImpl(EDataFlow data_flow,
device.device_name = base::WideToUTF8(friendly_name.get().pwszVal);
}
// Append VID/PID to USB devices.
// Append suffix to USB and Bluetooth devices.
std::string controller_id = CoreAudioUtil::GetAudioControllerID(
audio_device.Get(), enumerator.Get());
std::string vid_pid_suffix = GetUsbVidPidSuffixWin(controller_id);
if (!vid_pid_suffix.empty())
device.device_name += vid_pid_suffix;
std::string suffix = GetDeviceSuffixWin(controller_id);
if (!suffix.empty())
device.device_name += suffix;
}
// Add combination of user-friendly and unique name to the output list.
......@@ -165,14 +165,19 @@ bool GetOutputDeviceNamesWinXP(AudioDeviceNames* device_names) {
waveOutGetDevCapsW>(device_names);
}
std::string GetUsbVidPidSuffixWin(const std::string& controller_id) {
std::string vid_pid;
std::string GetDeviceSuffixWin(const std::string& controller_id) {
std::string suffix;
if (controller_id.size() >= 21 && controller_id.substr(0, 8) == "USB\\VID_" &&
controller_id.substr(12, 5) == "&PID_") {
vid_pid = " (" + base::ToLowerASCII(controller_id.substr(8, 4)) + ":" +
base::ToLowerASCII(controller_id.substr(17, 4)) + ")";
suffix = " (" + base::ToLowerASCII(controller_id.substr(8, 4)) + ":" +
base::ToLowerASCII(controller_id.substr(17, 4)) + ")";
} else if ((controller_id.size() >= 22 &&
controller_id.substr(0, 22) == "BTHHFENUM\\BthHFPAudio\\") ||
(controller_id.size() >= 8 &&
controller_id.substr(0, 8) == "BTHENUM\\")) {
suffix = " (Bluetooth)";
}
return vid_pid;
return suffix;
}
} // namespace media
......@@ -30,15 +30,17 @@ bool GetOutputDeviceNamesWin(media::AudioDeviceNames* device_names);
// - unique_id: "Microphone (Realtek High Defini" (same as friendly name).
bool GetOutputDeviceNamesWinXP(media::AudioDeviceNames* device_names);
// Given a string |controller_id| with the controller ID of a USB device,
// returns a string containing the device's VID and PID.
// The format of the string is " (vid:pid)", with vid and pid being 4-character
// lowercase hexadecimal numbers. This string is intended to be appended to a
// device-name string without any further formatting.
// If |controller_id| does not refer to a USB device, this function returns an
// empty string.
MEDIA_EXPORT std::string GetUsbVidPidSuffixWin(
const std::string& controller_id);
// Given a string |controller_id| with the controller ID of an audio device,
// returns a string containing extra information about the device.
// If the device is a USB device, the format of the returned string is
// " (vid:pid)", with vid and pid being 4-character lowercase hexadecimal
// numbers.
// If the device is a Bluetooth device, the returned string is " (Bluetooth)".
// This string is intended to be appended to a device-name string without any
// further formatting.
// If |controller_id| does not refer to a USB or Bluetooth device, this
// function returns an empty string.
MEDIA_EXPORT std::string GetDeviceSuffixWin(const std::string& controller_id);
} // namespace media
......
......@@ -8,38 +8,38 @@
namespace media {
TEST(DeviceEnumerationWin, GetUsbVidPidSuffix) {
TEST(DeviceEnumerationWin, GetDeviceSuffix) {
// Some real-world USB devices
EXPECT_EQ(
GetUsbVidPidSuffixWin("USB\\VID_046D&PID_09A6&MI_02\\6&318d810e&1&0002"),
GetDeviceSuffixWin("USB\\VID_046D&PID_09A6&MI_02\\6&318d810e&1&0002"),
" (046d:09a6)");
EXPECT_EQ(GetUsbVidPidSuffixWin("USB\\VID_8087&PID_07DC&REV_0001"),
EXPECT_EQ(GetDeviceSuffixWin("USB\\VID_8087&PID_07DC&REV_0001"),
" (8087:07dc)");
EXPECT_EQ(GetUsbVidPidSuffixWin("USB\\VID_0403&PID_6010"), " (0403:6010)");
EXPECT_EQ(GetDeviceSuffixWin("USB\\VID_0403&PID_6010"), " (0403:6010)");
// Some real-world non-USB devices
EXPECT_TRUE(
GetUsbVidPidSuffixWin("BTHHFENUM\\BthHFPAudio\\8&39e29755&0&97").empty());
EXPECT_TRUE(GetUsbVidPidSuffixWin("BTHENUM\\{0000110b-0000-1000-8000-"
"00805f9b34fb}_LOCALMFG&0002\\7&25f92e87&0&"
"70886B900BB0_C00000000")
// Some real-world Bluetooth devices
EXPECT_EQ(GetDeviceSuffixWin("BTHHFENUM\\BthHFPAudio\\8&39e29755&0&97"),
" (Bluetooth)");
EXPECT_EQ(GetDeviceSuffixWin("BTHENUM\\{0000110b-0000-1000-8000-"
"00805f9b34fb}_LOCALMFG&0002\\7&25f92e87&0&"
"70886B900BB0_C00000000"),
" (Bluetooth)");
// Other real-world devices
EXPECT_TRUE(GetDeviceSuffixWin("INTELAUDIO\\FUNC_01&VEN_8086&DEV_280B&SUBSYS_"
"80860101&REV_1000\\4&c083774&0&0201")
.empty());
EXPECT_TRUE(GetDeviceSuffixWin("INTELAUDIO\\FUNC_01&VEN_10EC&DEV_0298&SUBSYS_"
"102807BF&REV_1001\\4&c083774&0&0001")
.empty());
EXPECT_TRUE(
GetUsbVidPidSuffixWin("INTELAUDIO\\FUNC_01&VEN_8086&DEV_280B&SUBSYS_"
"80860101&REV_1000\\4&c083774&0&0201")
.empty());
EXPECT_TRUE(
GetUsbVidPidSuffixWin("INTELAUDIO\\FUNC_01&VEN_10EC&DEV_0298&SUBSYS_"
"102807BF&REV_1001\\4&c083774&0&0001")
GetDeviceSuffixWin("PCI\\VEN_1000&DEV_0001&SUBSYS_00000000&REV_02\\1&08")
.empty());
EXPECT_TRUE(GetUsbVidPidSuffixWin(
"PCI\\VEN_1000&DEV_0001&SUBSYS_00000000&REV_02\\1&08")
.empty());
// Other input strings.
EXPECT_TRUE(GetUsbVidPidSuffixWin(std::string()).empty());
EXPECT_TRUE(GetUsbVidPidSuffixWin(" ").empty());
EXPECT_TRUE(GetUsbVidPidSuffixWin("USBVID_1234&PID1234").empty());
EXPECT_TRUE(GetDeviceSuffixWin(std::string()).empty());
EXPECT_TRUE(GetDeviceSuffixWin(" ").empty());
EXPECT_TRUE(GetDeviceSuffixWin("USBVID_1234&PID1234").empty());
}
} // namespace media
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment