Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ceaeee1d authored by Eric Laurent's avatar Eric Laurent
Browse files

Audio effect HAL: Add device ID to createEffect API

Add the possibility to specify a target audio device when
creating an audio effect by passing its audio port handle
to createEffect API.

To attach an effect to a device, the framework will use
session ID AudioSessionConsts.DEVICE and provide a valid
AudioPortHandle as device ID.

Bug: 136294538
Test: make
Change-Id: Ic697eeafbd5df6800ad4c7fd9e0698e3d8e3beae
parent b524bbb9
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -48,11 +48,15 @@ interface IEffectsFactory {
     *                stream.
     * @param ioHandle identifies the output or input stream this effect is
     *                 directed to in audio HAL.
     * @param device identifies the sink or source device this effect is directed to in the
     *               audio HAL. Must be specified if session is AudioSessionConsts.DEVICE.
     *               "device" is the AudioPortHandle used for the device when the audio
     *               patch is created at the audio HAL.
     * @return retval operation completion status.
     * @return result the interface for the created effect.
     * @return effectId the unique ID of the effect to be used with
     *                  IStream::addEffect and IStream::removeEffect methods.
     */
    createEffect(Uuid uid, AudioSession session, AudioIoHandle ioHandle)
    createEffect(Uuid uid, AudioSession session, AudioIoHandle ioHandle, AudioPortHandle device)
        generates (Result retval, IEffect result, uint64_t effectId);
};
+24 −6
Original line number Diff line number Diff line
@@ -133,9 +133,9 @@ exit:
    return Void();
}

Return<void> EffectsFactory::getDescriptor(const Uuid& uid, getDescriptor_cb _hidl_cb) {
Return<void> EffectsFactory::getDescriptor(const Uuid& uuid, getDescriptor_cb _hidl_cb) {
    effect_uuid_t halUuid;
    HidlUtils::uuidToHal(uid, &halUuid);
    HidlUtils::uuidToHal(uuid, &halUuid);
    effect_descriptor_t halDescriptor;
    status_t status = EffectGetDescriptor(&halUuid, &halDescriptor);
    EffectDescriptor descriptor;
@@ -154,13 +154,31 @@ Return<void> EffectsFactory::getDescriptor(const Uuid& uid, getDescriptor_cb _hi
    return Void();
}

Return<void> EffectsFactory::createEffect(const Uuid& uid, int32_t session, int32_t ioHandle,
                                          createEffect_cb _hidl_cb) {
#if MAJOR_VERSION <= 5
Return<void> EffectsFactory::createEffect(const Uuid& uuid, int32_t session, int32_t ioHandle,
                                          EffectsFactory::createEffect_cb _hidl_cb) {
    return createEffectImpl(uuid, session, ioHandle, AUDIO_PORT_HANDLE_NONE, _hidl_cb);
}
#else
Return<void> EffectsFactory::createEffect(const Uuid& uuid, int32_t session, int32_t ioHandle,
                                          int32_t device,
                                          EffectsFactory::createEffect_cb _hidl_cb) {
    return createEffectImpl(uuid, session, ioHandle, device, _hidl_cb);
}
#endif

Return<void> EffectsFactory::createEffectImpl(const Uuid& uuid, int32_t session, int32_t ioHandle,
                                              int32_t device, createEffect_cb _hidl_cb) {
    effect_uuid_t halUuid;
    HidlUtils::uuidToHal(uid, &halUuid);
    HidlUtils::uuidToHal(uuid, &halUuid);
    effect_handle_t handle;
    Result retval(Result::OK);
    status_t status = EffectCreate(&halUuid, session, ioHandle, &handle);
    status_t status;
    if (session == AUDIO_SESSION_DEVICE) {
        status = EffectCreateOnDevice(&halUuid, device, ioHandle, &handle);
    } else {
        status = EffectCreate(&halUuid, session, ioHandle, &handle);
    }
    sp<IEffect> effect;
    uint64_t effectId = EffectMap::INVALID_ID;
    if (status == OK) {
+10 −2
Original line number Diff line number Diff line
@@ -47,9 +47,15 @@ using namespace ::android::hardware::audio::effect::CPP_VERSION;
struct EffectsFactory : public IEffectsFactory {
    // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffectsFactory follow.
    Return<void> getAllDescriptors(getAllDescriptors_cb _hidl_cb) override;
    Return<void> getDescriptor(const Uuid& uid, getDescriptor_cb _hidl_cb) override;
    Return<void> createEffect(const Uuid& uid, int32_t session, int32_t ioHandle,
    Return<void> getDescriptor(const Uuid& uuid, getDescriptor_cb _hidl_cb) override;
#if MAJOR_VERSION <= 5
    Return<void> createEffect(const Uuid& uuid, int32_t session, int32_t ioHandle,
                              createEffect_cb _hidl_cb) override;
#else
    Return<void> createEffect(const Uuid& uuid, int32_t session, int32_t ioHandle, int32_t device,
                              createEffect_cb _hidl_cb) override;
#endif

    Return<void> debugDump(
        const hidl_handle& fd);  //< in CPP_VERSION::IEffectsFactory only, alias of debug
    Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
@@ -57,6 +63,8 @@ struct EffectsFactory : public IEffectsFactory {
   private:
    static sp<IEffect> dispatchEffectInstanceCreation(const effect_descriptor_t& halDescriptor,
                                                      effect_handle_t handle);
    Return<void> createEffectImpl(const Uuid& uuid, int32_t session, int32_t ioHandle,
                                  int32_t device, createEffect_cb _hidl_cb);
};

extern "C" IEffectsFactory* HIDL_FETCH_IEffectsFactory(const char* name);
+19 −13
Original line number Diff line number Diff line
@@ -135,6 +135,9 @@ EFFECT_TEST(AudioEffectsFactoryHidlTest, CreateEffect) {
    sp<IEffect> effect;
    ret = effectsFactory->createEffect(
            effectUuid, 1 /*session*/, 1 /*ioHandle*/,
#if MAJOR_VERSION >= 6
            0 /*device*/,
#endif
            [&](Result r, const sp<IEffect>& result, uint64_t /*effectId*/) {
                retval = r;
                if (r == Result::OK) {
@@ -237,6 +240,9 @@ void AudioEffectHidlTest::findAndCreateEffect(const Uuid& type) {
    findEffectInstance(type, &effectUuid);
    Return<void> ret = effectsFactory->createEffect(
            effectUuid, 1 /*session*/, 1 /*ioHandle*/,
#if MAJOR_VERSION >= 6
            0 /*device*/,
#endif
            [&](Result r, const sp<IEffect>& result, uint64_t /*effectId*/) {
                if (r == Result::OK) {
                    effect = result;
+1 −1
Original line number Diff line number Diff line
@@ -601,7 +601,7 @@ bca5379d5065e2e08b6ad7308ffc8a71a972fc0698bec678ea32eea786d01cb5 android.hardwar
8bc597d166e07e9eba633267fc2872c4c53d13d3f0025b778c98e13324a165de android.hardware.audio.effect@6.0::IDownmixEffect
9ee022c81e79da6051fde0836c1c1c4d5414e0c9a6cccc0ce17a90346ceb1391 android.hardware.audio.effect@6.0::IEffect
75c99a70577d543359910a0b378bcbf5a0d6076712e58e6864cd8803f76c8684 android.hardware.audio.effect@6.0::IEffectBufferProviderCallback
5910bdd600fc6501a67233a9a3f4f21dda86af08c05497322712600131d1fa8f android.hardware.audio.effect@6.0::IEffectsFactory
b138d519696f23af2c7cb92c532178c35f4b3a5c1b689260b1c308fe00249f8b android.hardware.audio.effect@6.0::IEffectsFactory
dd377f404a8e71f6191d295e10067db629b0f0c28e594af906f2bea5d87fe2cc android.hardware.audio.effect@6.0::IEnvironmentalReverbEffect
455e085e136767302ec34d02b51a085c310e79bf500b76dda7c96a7f3637f11a android.hardware.audio.effect@6.0::IEqualizerEffect
24b5e107a0cbd2b322f764a4d5f7fb8b5d8c337a060b9a4a26b9af050c57b5d0 android.hardware.audio.effect@6.0::ILoudnessEnhancerEffect