Commit 2fa2ada0 authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Append USB VID/PID to audio-device enumeration results on Windows

This CL appends a suffix containing the device model (i.e., vid:pid)
for USB audio devices in device enumeration results on Windows.
The (vid:pid) suffix is already available on video device enumerations.

Bug: 780492
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Id8a7cbd75dd8a0fb9f70827015d2920ac088adfa
Reviewed-on: https://chromium-review.googlesource.com/995537
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549202}
parent fe8a5e81
......@@ -461,6 +461,7 @@ source_set("unit_tests") {
"win/audio_low_latency_output_win_unittest.cc",
"win/audio_output_win_unittest.cc",
"win/core_audio_util_win_unittest.cc",
"win/device_enumeration_win_unittest.cc",
]
}
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/win/device_enumeration_win.h"
#include <MMDeviceAPI.h>
#include <mmsystem.h>
#include <objbase.h>
......@@ -10,10 +12,12 @@
#include <wrl/client.h>
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_co_mem.h"
#include "base/win/scoped_propvariant.h"
#include "media/audio/win/audio_manager_win.h"
#include "media/audio/win/core_audio_util_win.h"
using base::win::ScopedCoMem;
......@@ -84,6 +88,13 @@ static bool GetDeviceNamesWinImpl(EDataFlow data_flow,
friendly_name.get().pwszVal) {
device.device_name = base::WideToUTF8(friendly_name.get().pwszVal);
}
// Append VID/PID to USB 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;
}
// Add combination of user-friendly and unique name to the output list.
......@@ -154,4 +165,14 @@ bool GetOutputDeviceNamesWinXP(AudioDeviceNames* device_names) {
waveOutGetDevCapsW>(device_names);
}
std::string GetUsbVidPidSuffixWin(const std::string& controller_id) {
std::string vid_pid;
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)) + ")";
}
return vid_pid;
}
} // namespace media
......@@ -8,6 +8,7 @@
#include <string>
#include "media/audio/audio_device_name.h"
#include "media/base/media_export.h"
namespace media {
......@@ -29,6 +30,16 @@ 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);
} // namespace media
#endif // MEDIA_AUDIO_WIN_DEVICE_ENUMERATION_WIN_H_
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/win/device_enumeration_win.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
TEST(DeviceEnumerationWin, GetUsbVidPidSuffix) {
// Some real-world USB devices
EXPECT_EQ(
GetUsbVidPidSuffixWin("USB\\VID_046D&PID_09A6&MI_02\\6&318d810e&1&0002"),
" (046d:09a6)");
EXPECT_EQ(GetUsbVidPidSuffixWin("USB\\VID_8087&PID_07DC&REV_0001"),
" (8087:07dc)");
EXPECT_EQ(GetUsbVidPidSuffixWin("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")
.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")
.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());
}
} // 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