aaudio_loopback: Allow specifying input device id
This is useful when there are multiple audio devices in the system.
Test: use aaudio_loopback on a TV device with USB soundcard connected
specify -d<HDMI out device id> -D<USB in device id>
Change-Id: I60e84132f5974db6f4314c58f76705018e22b7db
diff --git a/media/libaaudio/examples/loopback/src/loopback.cpp b/media/libaaudio/examples/loopback/src/loopback.cpp
index 6578156..c7c42eb 100644
--- a/media/libaaudio/examples/loopback/src/loopback.cpp
+++ b/media/libaaudio/examples/loopback/src/loopback.cpp
@@ -295,6 +295,7 @@
AAudioArgsParser::usage();
printf(" -B{frames} input capacity in frames\n");
printf(" -C{channels} number of input channels\n");
+ printf(" -D{deviceId} input device ID\n");
printf(" -F{0,1,2} input format, 1=I16, 2=FLOAT\n");
printf(" -g{gain} recirculating loopback gain\n");
printf(" -h{hangMillis} occasionally hang in the callback\n");
@@ -393,6 +394,7 @@
AAudioStream *outputStream = nullptr;
aaudio_result_t result = AAUDIO_OK;
+ int32_t requestedInputDeviceId = AAUDIO_UNSPECIFIED;
aaudio_sharing_mode_t requestedInputSharingMode = AAUDIO_SHARING_MODE_SHARED;
int requestedInputChannelCount = kNumInputChannels;
aaudio_format_t requestedInputFormat = AAUDIO_FORMAT_UNSPECIFIED;
@@ -431,6 +433,9 @@
case 'C':
requestedInputChannelCount = atoi(&arg[2]);
break;
+ case 'D':
+ requestedInputDeviceId = atoi(&arg[2]);
+ break;
case 'F':
requestedInputFormat = atoi(&arg[2]);
break;
@@ -529,6 +534,7 @@
printf("INPUT stream ----------------------------------------\n");
// Use different parameters for the input.
+ argParser.setDeviceId(requestedInputDeviceId);
argParser.setNumberOfBursts(AAUDIO_UNSPECIFIED);
argParser.setFormat(requestedInputFormat);
argParser.setPerformanceMode(inputPerformanceLevel);