Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OboeTester Data Paths handle mix of USB #2083

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ protected boolean isDeviceTypeMixedForLoopback(int type) {
}
}

/**
* @param type
* @return list of compatible device types in preferred order
*/
protected ArrayList<Integer> getCompatibleDeviceTypes(int type) {
ArrayList<Integer> compatibleTypes = new ArrayList<Integer>();
switch(type) {
Expand All @@ -466,10 +470,15 @@ protected ArrayList<Integer> getCompatibleDeviceTypes(int type) {
compatibleTypes.add(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);
break;
case AudioDeviceInfo.TYPE_USB_DEVICE:
// Give priority to an exact match of DEVICE.
compatibleTypes.add(AudioDeviceInfo.TYPE_USB_DEVICE);
// A USB Device is often mistaken for a headset.
compatibleTypes.add(AudioDeviceInfo.TYPE_USB_HEADSET);
break;
case AudioDeviceInfo.TYPE_USB_HEADSET:
// Give priority to an exact match of HEADSET.
compatibleTypes.add(AudioDeviceInfo.TYPE_USB_HEADSET);
compatibleTypes.add(AudioDeviceInfo.TYPE_USB_DEVICE);
break;
default:
compatibleTypes.add(type);
break;
Expand All @@ -485,9 +494,12 @@ protected ArrayList<Integer> getCompatibleDeviceTypes(int type) {
protected AudioDeviceInfo findCompatibleInputDevice(int outputDeviceType) {
ArrayList<Integer> compatibleDeviceTypes = getCompatibleDeviceTypes(outputDeviceType);
AudioDeviceInfo[] devices = mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
for (AudioDeviceInfo candidate : devices) {
if (compatibleDeviceTypes.contains(candidate.getType())) {
return candidate;
// Scan the compatible types in order of preference.
for (int compatibleType : compatibleDeviceTypes) {
for (AudioDeviceInfo candidate : devices) {
if (candidate.getType() == compatibleType) {
return candidate;
}
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ private void showDeviceInfo(AudioDeviceInfo outputDeviceInfo, AudioDeviceInfo in
setInstructionsText(deviceText);

if (inputDeviceInfo == null) {
deviceText += "ERROR - cannot find compatible device type for input!";
deviceText += "\nERROR - no compatible input device!";
} else {
deviceText = "IN: type = "
+ AudioDeviceInfoConverter.typeToString(inputDeviceInfo.getType())
Expand Down