Skip to content

Commit

Permalink
OboeTester Data Paths handle mix of USB types (#2083)
Browse files Browse the repository at this point in the history
Handle any combination of USB Headset or Device.

Find compatible device type in preferred order.
  • Loading branch information
philburk authored Aug 7, 2024
1 parent 8ebc252 commit 9fa656d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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

0 comments on commit 9fa656d

Please sign in to comment.