Use 'audio_port_config' in DeviceHalInterface::add/removeDeviceEffect
Previously, `audio_port_handle_t` was used to specify the device
port. However, these port handles are allocated by the framework
and are not known to the HAL a priori. The current scenario
assumes that the framework first creates an audio patch, thus
passes a complete `audio_port_config` to the HAL prior to adding
an effect. However, this assumption isn't stated anywhere in
the legacy interface definition.
To make things more flexible, make the framework to pass
`audio_port_config` when it adds/removes a device effect.
This also makes unnecessary to pass the hw module ID as it is
contained within the port config. The legacy HAL interface
is left intact.
Bug: 205884982
Test: m
Change-Id: Ie9410637ad092bff22b2c0fe1c92e516a1f24ee0
diff --git a/media/libaudiohal/impl/DeviceHalAidl.cpp b/media/libaudiohal/impl/DeviceHalAidl.cpp
index e6e7c6a..22bdc23 100644
--- a/media/libaudiohal/impl/DeviceHalAidl.cpp
+++ b/media/libaudiohal/impl/DeviceHalAidl.cpp
@@ -882,7 +882,7 @@
return OK;
}
-status_t DeviceHalAidl::addDeviceEffect(audio_port_handle_t device __unused,
+status_t DeviceHalAidl::addDeviceEffect(const struct audio_port_config *device __unused,
sp<EffectHalInterface> effect) {
if (!effect) {
return BAD_VALUE;
@@ -892,7 +892,7 @@
ALOGE("%s not implemented yet", __func__);
return OK;
}
-status_t DeviceHalAidl::removeDeviceEffect(audio_port_handle_t device __unused,
+status_t DeviceHalAidl::removeDeviceEffect(const struct audio_port_config *device __unused,
sp<EffectHalInterface> effect) {
if (!effect) {
return BAD_VALUE;
diff --git a/media/libaudiohal/impl/DeviceHalAidl.h b/media/libaudiohal/impl/DeviceHalAidl.h
index 45768a3..e0b0981 100644
--- a/media/libaudiohal/impl/DeviceHalAidl.h
+++ b/media/libaudiohal/impl/DeviceHalAidl.h
@@ -148,9 +148,11 @@
// List microphones
status_t getMicrophones(std::vector<audio_microphone_characteristic_t>* microphones) override;
- status_t addDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override;
+ status_t addDeviceEffect(
+ const struct audio_port_config *device, sp<EffectHalInterface> effect) override;
- status_t removeDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override;
+ status_t removeDeviceEffect(
+ const struct audio_port_config *device, sp<EffectHalInterface> effect) override;
status_t getMmapPolicyInfos(media::audio::common::AudioMMapPolicyType policyType __unused,
std::vector<media::audio::common::AudioMMapPolicyInfo>* policyInfos
diff --git a/media/libaudiohal/impl/DeviceHalHidl.cpp b/media/libaudiohal/impl/DeviceHalHidl.cpp
index 4066f3c..6755f3d 100644
--- a/media/libaudiohal/impl/DeviceHalHidl.cpp
+++ b/media/libaudiohal/impl/DeviceHalHidl.cpp
@@ -499,32 +499,32 @@
#if MAJOR_VERSION >= 6
status_t DeviceHalHidl::addDeviceEffect(
- audio_port_handle_t device, sp<EffectHalInterface> effect) {
+ const struct audio_port_config *device, sp<EffectHalInterface> effect) {
TIME_CHECK();
if (mDevice == 0) return NO_INIT;
auto hidlEffect = sp<effect::EffectHalHidl>::cast(effect);
return processReturn("addDeviceEffect", mDevice->addDeviceEffect(
- static_cast<AudioPortHandle>(device), hidlEffect->effectId()));
+ static_cast<AudioPortHandle>(device->id), hidlEffect->effectId()));
}
#else
status_t DeviceHalHidl::addDeviceEffect(
- audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
+ const struct audio_port_config *device __unused, sp<EffectHalInterface> effect __unused) {
return INVALID_OPERATION;
}
#endif
#if MAJOR_VERSION >= 6
status_t DeviceHalHidl::removeDeviceEffect(
- audio_port_handle_t device, sp<EffectHalInterface> effect) {
+ const struct audio_port_config *device, sp<EffectHalInterface> effect) {
TIME_CHECK();
if (mDevice == 0) return NO_INIT;
auto hidlEffect = sp<effect::EffectHalHidl>::cast(effect);
return processReturn("removeDeviceEffect", mDevice->removeDeviceEffect(
- static_cast<AudioPortHandle>(device), hidlEffect->effectId()));
+ static_cast<AudioPortHandle>(device->id), hidlEffect->effectId()));
}
#else
status_t DeviceHalHidl::removeDeviceEffect(
- audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
+ const struct audio_port_config *device __unused, sp<EffectHalInterface> effect __unused) {
return INVALID_OPERATION;
}
#endif
diff --git a/media/libaudiohal/impl/DeviceHalHidl.h b/media/libaudiohal/impl/DeviceHalHidl.h
index 17acd2f..e82f20a 100644
--- a/media/libaudiohal/impl/DeviceHalHidl.h
+++ b/media/libaudiohal/impl/DeviceHalHidl.h
@@ -105,8 +105,10 @@
// List microphones
status_t getMicrophones(std::vector<audio_microphone_characteristic_t>* microphones) override;
- status_t addDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override;
- status_t removeDeviceEffect(audio_port_handle_t device, sp<EffectHalInterface> effect) override;
+ status_t addDeviceEffect(
+ const struct audio_port_config *device, sp<EffectHalInterface> effect) override;
+ status_t removeDeviceEffect(
+ const struct audio_port_config *device, sp<EffectHalInterface> effect) override;
status_t getMmapPolicyInfos(
media::audio::common::AudioMMapPolicyType policyType __unused,
diff --git a/media/libaudiohal/include/media/audiohal/DeviceHalInterface.h b/media/libaudiohal/include/media/audiohal/DeviceHalInterface.h
index 0103680..51590e0 100644
--- a/media/libaudiohal/include/media/audiohal/DeviceHalInterface.h
+++ b/media/libaudiohal/include/media/audiohal/DeviceHalInterface.h
@@ -128,9 +128,9 @@
std::vector<audio_microphone_characteristic_t>* microphones) = 0;
virtual status_t addDeviceEffect(
- audio_port_handle_t device, sp<EffectHalInterface> effect) = 0;
+ const struct audio_port_config *device, sp<EffectHalInterface> effect) = 0;
virtual status_t removeDeviceEffect(
- audio_port_handle_t device, sp<EffectHalInterface> effect) = 0;
+ const struct audio_port_config *device, sp<EffectHalInterface> effect) = 0;
virtual status_t getMmapPolicyInfos(
media::audio::common::AudioMMapPolicyType policyType,
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 4f1d554..926110882 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -716,24 +716,24 @@
}
}
-status_t AudioFlinger::addEffectToHal(audio_port_handle_t deviceId,
- audio_module_handle_t hwModuleId, const sp<EffectHalInterface>& effect) {
+status_t AudioFlinger::addEffectToHal(
+ const struct audio_port_config *device, const sp<EffectHalInterface>& effect) {
AutoMutex lock(mHardwareLock);
- AudioHwDevice *audioHwDevice = mAudioHwDevs.valueFor(hwModuleId);
+ AudioHwDevice *audioHwDevice = mAudioHwDevs.valueFor(device->ext.device.hw_module);
if (audioHwDevice == nullptr) {
return NO_INIT;
}
- return audioHwDevice->hwDevice()->addDeviceEffect(deviceId, effect);
+ return audioHwDevice->hwDevice()->addDeviceEffect(device, effect);
}
-status_t AudioFlinger::removeEffectFromHal(audio_port_handle_t deviceId,
- audio_module_handle_t hwModuleId, const sp<EffectHalInterface>& effect) {
+status_t AudioFlinger::removeEffectFromHal(
+ const struct audio_port_config *device, const sp<EffectHalInterface>& effect) {
AutoMutex lock(mHardwareLock);
- AudioHwDevice *audioHwDevice = mAudioHwDevs.valueFor(hwModuleId);
+ AudioHwDevice *audioHwDevice = mAudioHwDevs.valueFor(device->ext.device.hw_module);
if (audioHwDevice == nullptr) {
return NO_INIT;
}
- return audioHwDevice->hwDevice()->removeDeviceEffect(deviceId, effect);
+ return audioHwDevice->hwDevice()->removeDeviceEffect(device, effect);
}
static const char * const audio_interfaces[] = {
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 6d422b6..e4e39c6 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -338,10 +338,10 @@
static int onExternalVibrationStart(const sp<os::ExternalVibration>& externalVibration);
static void onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration);
- status_t addEffectToHal(audio_port_handle_t deviceId,
- audio_module_handle_t hwModuleId, const sp<EffectHalInterface>& effect);
- status_t removeEffectFromHal(audio_port_handle_t deviceId,
- audio_module_handle_t hwModuleId, const sp<EffectHalInterface>& effect);
+ status_t addEffectToHal(
+ const struct audio_port_config *device, const sp<EffectHalInterface>& effect);
+ status_t removeEffectFromHal(
+ const struct audio_port_config *device, const sp<EffectHalInterface>& effect);
void updateDownStreamPatches_l(const struct audio_patch *patch,
const std::set<audio_io_handle_t>& streams);
diff --git a/services/audioflinger/DeviceEffectManager.h b/services/audioflinger/DeviceEffectManager.h
index 493800e..dc1e2ec 100644
--- a/services/audioflinger/DeviceEffectManager.h
+++ b/services/audioflinger/DeviceEffectManager.h
@@ -46,13 +46,13 @@
status_t createEffectHal(const effect_uuid_t *pEffectUuid,
int32_t sessionId, int32_t deviceId,
sp<EffectHalInterface> *effect);
- status_t addEffectToHal(audio_port_handle_t deviceId, audio_module_handle_t hwModuleId,
+ status_t addEffectToHal(const struct audio_port_config *device,
const sp<EffectHalInterface>& effect) {
- return mAudioFlinger.addEffectToHal(deviceId, hwModuleId, effect);
+ return mAudioFlinger.addEffectToHal(device, effect);
};
- status_t removeEffectFromHal(audio_port_handle_t deviceId, audio_module_handle_t hwModuleId,
+ status_t removeEffectFromHal(const struct audio_port_config *device,
const sp<EffectHalInterface>& effect) {
- return mAudioFlinger.removeEffectFromHal(deviceId, hwModuleId, effect);
+ return mAudioFlinger.removeEffectFromHal(device, effect);
};
AudioFlinger& audioFlinger() const { return mAudioFlinger; }
@@ -203,13 +203,13 @@
int newEffectId() { return mManager.audioFlinger().nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT); }
- status_t addEffectToHal(audio_port_handle_t deviceId,
- audio_module_handle_t hwModuleId, const sp<EffectHalInterface>& effect) {
- return mManager.addEffectToHal(deviceId, hwModuleId, effect);
+ status_t addEffectToHal(const struct audio_port_config *device,
+ const sp<EffectHalInterface>& effect) {
+ return mManager.addEffectToHal(device, effect);
}
- status_t removeEffectFromHal(audio_port_handle_t deviceId,
- audio_module_handle_t hwModuleId, const sp<EffectHalInterface>& effect) {
- return mManager.removeEffectFromHal(deviceId, hwModuleId, effect);
+ status_t removeEffectFromHal(const struct audio_port_config *device,
+ const sp<EffectHalInterface>& effect) {
+ return mManager.removeEffectFromHal(device, effect);
}
private:
DeviceEffectManager& mManager;
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index 6963bb9..c3735be 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -3382,8 +3382,7 @@
if (mHalEffect == nullptr) {
return NO_INIT;
}
- return mManagerCallback->addEffectToHal(
- mDevicePort.id, mDevicePort.ext.device.hw_module, effect);
+ return mManagerCallback->addEffectToHal(&mDevicePort, effect);
}
status_t AudioFlinger::DeviceEffectProxy::removeEffectFromHal(
@@ -3391,8 +3390,7 @@
if (mHalEffect == nullptr) {
return NO_INIT;
}
- return mManagerCallback->removeEffectFromHal(
- mDevicePort.id, mDevicePort.ext.device.hw_module, effect);
+ return mManagerCallback->removeEffectFromHal(&mDevicePort, effect);
}
bool AudioFlinger::DeviceEffectProxy::isOutput() const {