Add AudioDeviceVector to MMAP path
This CL adds AudioDeviceVector in the MMAP interface between
AudioFlinger and AAudioService.
Bug: 367816690
Test: OboeTester Test Output
Flag: android.media.audio.routed_device_ids
Change-Id: Ib658a36e91ee9f0336a59855d33cb326497a1bdc
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index db01cff..7ed53f2 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -10393,13 +10393,13 @@
audio_stream_type_t streamType __unused,
audio_session_t sessionId,
const sp<MmapStreamCallback>& callback,
- audio_port_handle_t deviceId,
+ const DeviceIdVector& deviceIds,
audio_port_handle_t portId)
{
mAttr = *attr;
mSessionId = sessionId;
mCallback = callback;
- mDeviceId = deviceId;
+ mDeviceIds = deviceIds;
mPortId = portId;
}
@@ -10492,12 +10492,7 @@
audio_stream_type_t stream = streamType_l();
audio_output_flags_t flags =
(audio_output_flags_t)(AUDIO_OUTPUT_FLAG_MMAP_NOIRQ | AUDIO_OUTPUT_FLAG_DIRECT);
- DeviceIdVector deviceIds;
- if (mDeviceId != AUDIO_PORT_HANDLE_NONE) {
- deviceIds.push_back(mDeviceId);
- } else {
- ALOGW("%s no device id set", __func__);
- }
+ DeviceIdVector deviceIds = mDeviceIds;
std::vector<audio_io_handle_t> secondaryOutputs;
bool isSpatialized;
bool isBitPerfect;
@@ -10524,7 +10519,7 @@
config.sample_rate = mSampleRate;
config.channel_mask = mChannelMask;
config.format = mFormat;
- audio_port_handle_t deviceId = mDeviceId;
+ audio_port_handle_t deviceId = getFirstDeviceId(mDeviceIds);
mutex().unlock();
ret = AudioSystem::getInputForAttr(&localAttr, &io,
RECORD_RIID_INVALID,
@@ -10877,7 +10872,7 @@
// store new device and send to effects
audio_devices_t type = AUDIO_DEVICE_NONE;
- audio_port_handle_t deviceId;
+ DeviceIdVector deviceIds;
AudioDeviceTypeAddrVector sinkDeviceTypeAddrs;
AudioDeviceTypeAddr sourceDeviceTypeAddr;
uint32_t numDevices = 0;
@@ -10891,12 +10886,12 @@
type = static_cast<audio_devices_t>(type | patch->sinks[i].ext.device.type);
sinkDeviceTypeAddrs.emplace_back(patch->sinks[i].ext.device.type,
patch->sinks[i].ext.device.address);
+ deviceIds.push_back(patch->sinks[i].id);
}
- deviceId = patch->sinks[0].id;
numDevices = mPatch.num_sinks;
} else {
type = patch->sources[0].ext.device.type;
- deviceId = patch->sources[0].id;
+ deviceIds.push_back(patch->sources[0].id);
numDevices = mPatch.num_sources;
sourceDeviceTypeAddr.mType = patch->sources[0].ext.device.type;
sourceDeviceTypeAddr.setAddress(patch->sources[0].ext.device.address);
@@ -10922,11 +10917,11 @@
// For mmap streams, once the routing has changed, they will be disconnected. It should be
// okay to notify the client earlier before the new patch creation.
- if (mDeviceId != deviceId) {
+ if (mDeviceIds != deviceIds) {
if (const sp<MmapStreamCallback> callback = mCallback.promote()) {
// The aaudioservice handle the routing changed event asynchronously. In that case,
// it is safe to hold the lock here.
- callback->onRoutingChanged(deviceId);
+ callback->onRoutingChanged(deviceIds);
}
}
@@ -10946,7 +10941,7 @@
*handle = AUDIO_PATCH_HANDLE_NONE;
}
- if (numDevices == 0 || mDeviceId != deviceId) {
+ if (numDevices == 0 || mDeviceIds != deviceIds) {
if (isOutput()) {
sendIoConfigEvent_l(AUDIO_OUTPUT_CONFIG_CHANGED);
mOutDeviceTypeAddrs = sinkDeviceTypeAddrs;
@@ -10956,7 +10951,7 @@
mInDeviceTypeAddr = sourceDeviceTypeAddr;
}
mPatch = *patch;
- mDeviceId = deviceId;
+ mDeviceIds = deviceIds;
}
// Force meteadata update after a route change
mActiveTracks.setHasChanged();
@@ -11111,7 +11106,8 @@
if (const sp<MmapStreamCallback> callback = mCallback.promote()) {
// The aaudioservice handle the routing changed event asynchronously. In that case,
// it is safe to hold the lock here.
- callback->onRoutingChanged(AUDIO_PORT_HANDLE_NONE);
+ DeviceIdVector emptyDeviceIdVector;
+ callback->onRoutingChanged(emptyDeviceIdVector);
} else if (mNoCallbackWarningCount < kMaxNoCallbackWarnings) {
ALOGW("Could not notify MMAP stream tear down: no onRoutingChanged callback!");
mNoCallbackWarningCount++;
@@ -11203,11 +11199,11 @@
audio_stream_type_t streamType,
audio_session_t sessionId,
const sp<MmapStreamCallback>& callback,
- audio_port_handle_t deviceId,
+ const DeviceIdVector& deviceIds,
audio_port_handle_t portId)
{
audio_utils::lock_guard l(mutex());
- MmapThread::configure_l(attr, streamType, sessionId, callback, deviceId, portId);
+ MmapThread::configure_l(attr, streamType, sessionId, callback, deviceIds, portId);
mStreamType = streamType;
}