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

Commit 7119600d authored by Ari Hausman-Cohen's avatar Ari Hausman-Cohen Committed by Android (Google) Code Review
Browse files

Merge changes from topic "dynamic_stream_effects_master"

* changes:
  Add dynamic stream default effects
  Add helper method to convert usage to stream type.
  Update getEffectDescriptors() to include type
parents 7f1732ee 433722ee
Loading
Loading
Loading
Loading
+53 −3
Original line number Diff line number Diff line
@@ -430,14 +430,15 @@ status_t AudioEffect::queryEffect(uint32_t index, effect_descriptor_t *descripto
}

status_t AudioEffect::getEffectDescriptor(const effect_uuid_t *uuid,
        effect_descriptor_t *descriptor) /*const*/
                                          const effect_uuid_t *type,
                                          uint32_t preferredTypeFlag,
                                          effect_descriptor_t *descriptor)
{
    const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
    if (af == 0) return PERMISSION_DENIED;
    return af->getEffectDescriptor(uuid, descriptor);
    return af->getEffectDescriptor(uuid, type, preferredTypeFlag, descriptor);
}


status_t AudioEffect::queryDefaultPreProcessing(audio_session_t audioSession,
                                          effect_descriptor_t *descriptors,
                                          uint32_t *count)
@@ -446,6 +447,55 @@ status_t AudioEffect::queryDefaultPreProcessing(audio_session_t audioSession,
    if (aps == 0) return PERMISSION_DENIED;
    return aps->queryDefaultPreProcessing(audioSession, descriptors, count);
}

status_t AudioEffect::newEffectUniqueId(audio_unique_id_t* id)
{
    const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
    if (af == 0) return PERMISSION_DENIED;
    *id = af->newAudioUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT);
    return NO_ERROR;
}

status_t AudioEffect::addStreamDefaultEffect(const char *typeStr,
                                             const String16& opPackageName,
                                             const char *uuidStr,
                                             int32_t priority,
                                             audio_usage_t usage,
                                             audio_unique_id_t *id)
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;

    if (typeStr == NULL && uuidStr == NULL) return BAD_VALUE;

    // Convert type & uuid from string to effect_uuid_t.
    effect_uuid_t type;
    if (typeStr != NULL) {
        status_t res = stringToGuid(typeStr, &type);
        if (res != OK) return res;
    } else {
        type = *EFFECT_UUID_NULL;
    }

    effect_uuid_t uuid;
    if (uuidStr != NULL) {
        status_t res = stringToGuid(uuidStr, &uuid);
        if (res != OK) return res;
    } else {
        uuid = *EFFECT_UUID_NULL;
    }

    return aps->addStreamDefaultEffect(&type, opPackageName, &uuid, priority, usage, id);
}

status_t AudioEffect::removeStreamDefaultEffect(audio_unique_id_t id)
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;

    return aps->removeStreamDefaultEffect(id);
}

// -------------------------------------------------------------------------

status_t AudioEffect::stringToGuid(const char *str, effect_uuid_t *guid)
+10 −3
Original line number Diff line number Diff line
@@ -598,14 +598,18 @@ public:
    }

    virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid,
                                         const effect_uuid_t *pType,
                                         uint32_t preferredTypeFlag,
                                         effect_descriptor_t *pDescriptor) const
    {
        if (pUuid == NULL || pDescriptor == NULL) {
        if (pUuid == NULL || pType == NULL || pDescriptor == NULL) {
            return BAD_VALUE;
        }
        Parcel data, reply;
        data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
        data.write(pUuid, sizeof(effect_uuid_t));
        data.write(pType, sizeof(effect_uuid_t));
        data.writeUint32(preferredTypeFlag);
        status_t status = remote()->transact(GET_EFFECT_DESCRIPTOR, data, &reply);
        if (status != NO_ERROR) {
            return status;
@@ -1277,8 +1281,11 @@ status_t BnAudioFlinger::onTransact(
            CHECK_INTERFACE(IAudioFlinger, data, reply);
            effect_uuid_t uuid;
            data.read(&uuid, sizeof(effect_uuid_t));
            effect_uuid_t type;
            data.read(&type, sizeof(effect_uuid_t));
            uint32_t preferredTypeFlag = data.readUint32();
            effect_descriptor_t desc = {};
            status_t status = getEffectDescriptor(&uuid, &desc);
            status_t status = getEffectDescriptor(&uuid, &type, preferredTypeFlag, &desc);
            reply->writeInt32(status);
            if (status == NO_ERROR) {
                reply->write(&desc, sizeof(effect_descriptor_t));
+76 −1
Original line number Diff line number Diff line
@@ -81,7 +81,9 @@ enum {
    GET_MASTER_MONO,
    GET_STREAM_VOLUME_DB,
    GET_SURROUND_FORMATS,
    SET_SURROUND_FORMAT_ENABLED
    SET_SURROUND_FORMAT_ENABLED,
    ADD_STREAM_DEFAULT_EFFECT,
    REMOVE_STREAM_DEFAULT_EFFECT
};

#define MAX_ITEMS_PER_LIST 1024
@@ -866,6 +868,42 @@ public:
        }
        return reply.readInt32();
    }

    virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
                                            const String16& opPackageName,
                                            const effect_uuid_t *uuid,
                                            int32_t priority,
                                            audio_usage_t usage,
                                            audio_unique_id_t* id)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
        data.write(type, sizeof(effect_uuid_t));
        data.writeString16(opPackageName);
        data.write(uuid, sizeof(effect_uuid_t));
        data.writeInt32(priority);
        data.writeInt32((int32_t) usage);
        status_t status = remote()->transact(ADD_STREAM_DEFAULT_EFFECT, data, &reply);
        if (status != NO_ERROR) {
            return status;
        }
        status = static_cast <status_t> (reply.readInt32());
        *id = reply.readInt32();
        return status;
    }

    virtual status_t removeStreamDefaultEffect(audio_unique_id_t id)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
        data.writeInt32(id);
        status_t status = remote()->transact(REMOVE_STREAM_DEFAULT_EFFECT, data, &reply);
        if (status != NO_ERROR) {
            return status;
        }
        return static_cast <status_t> (reply.readInt32());
    }

};

IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
@@ -1561,6 +1599,43 @@ status_t BnAudioPolicyService::onTransact(
            return NO_ERROR;
        }

        case ADD_STREAM_DEFAULT_EFFECT: {
            CHECK_INTERFACE(IAudioPolicyService, data, reply);
            effect_uuid_t type;
            status_t status = data.read(&type, sizeof(effect_uuid_t));
            if (status != NO_ERROR) {
                return status;
            }
            String16 opPackageName;
            status = data.readString16(&opPackageName);
            if (status != NO_ERROR) {
                return status;
            }
            effect_uuid_t uuid;
            status = data.read(&uuid, sizeof(effect_uuid_t));
            if (status != NO_ERROR) {
                return status;
            }
            int32_t priority = data.readInt32();
            audio_usage_t usage = (audio_usage_t) data.readInt32();
            audio_unique_id_t id = 0;
            reply->writeInt32(static_cast <int32_t>(addStreamDefaultEffect(&type,
                                                                           opPackageName,
                                                                           &uuid,
                                                                           priority,
                                                                           usage,
                                                                           &id)));
            reply->writeInt32(id);
            return NO_ERROR;
        }

        case REMOVE_STREAM_DEFAULT_EFFECT: {
            CHECK_INTERFACE(IAudioPolicyService, data, reply);
            audio_unique_id_t id = static_cast<audio_unique_id_t>(data.readInt32());
            reply->writeInt32(static_cast <int32_t>(removeStreamDefaultEffect(id)));
            return NO_ERROR;
        }

        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
+85 −5
Original line number Diff line number Diff line
@@ -90,27 +90,34 @@ public:
     */
    static status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor);


    /*
     * Returns the descriptor for the specified effect uuid.
     * Returns a descriptor for the specified effect uuid or type.
     *
     * Lookup an effect by uuid, or if that's unspecified (EFFECT_UUID_NULL),
     * do so by type and preferred flags instead.
     *
     * Parameters:
     *      uuid:       pointer to effect uuid.
     *      type:       pointer to effect type uuid.
     *      preferredTypeFlags: if multiple effects of the given type exist,
     *                  one with a matching type flag will be chosen over one without.
     *                  Use EFFECT_FLAG_TYPE_MASK to indicate no preference.
     *      descriptor: address where the effect descriptor should be returned.
     *
     * Returned status (from utils/Errors.h) can be:
     *      NO_ERROR        successful operation.
     *      PERMISSION_DENIED could not get AudioFlinger interface
     *      NO_INIT         effect library failed to initialize
     *      BAD_VALUE       invalid uuid or descriptor pointers
     *      BAD_VALUE       invalid type or descriptor pointers
     *      NAME_NOT_FOUND  no effect with this uuid found
     *
     * Returned value
     *   *descriptor updated with effect descriptor
     */
    static status_t getEffectDescriptor(const effect_uuid_t *uuid,
                                        effect_descriptor_t *descriptor) /*const*/;

                                        const effect_uuid_t *type,
                                        uint32_t preferredTypeFlag,
                                        effect_descriptor_t *descriptor);

    /*
     * Returns a list of descriptors corresponding to the pre processings enabled by default
@@ -143,6 +150,79 @@ public:
                                              effect_descriptor_t *descriptors,
                                              uint32_t *count);

    /*
     * Gets a new system-wide unique effect id.
     *
     * Parameters:
     *      id: The address to return the generated id.
     *
     * Returned status (from utils/Errors.h) can be:
     *      NO_ERROR        successful operation.
     *      PERMISSION_DENIED could not get AudioFlinger interface
     *                        or caller lacks required permissions.
     * Returned value
     *   *id:  The new unique system-wide effect id.
     */
    static status_t newEffectUniqueId(audio_unique_id_t* id);

    /*
     * Static methods for adding/removing system-wide effects.
     */

    /*
     * Adds an effect to the list of default output effects for a given stream type.
     *
     * If the effect is no longer available when a stream of the given type
     * is created, the system will continue without adding it.
     *
     * Parameters:
     *   typeStr:  Type uuid of effect to be a default: can be null if uuidStr is specified.
     *             This may correspond to the OpenSL ES interface implemented by this effect,
     *             or could be some vendor-defined type.
     *   opPackageName: The package name used for app op checks.
     *   uuidStr:  Uuid of effect to be a default: can be null if type is specified.
     *             This uuid corresponds to a particular implementation of an effect type.
     *             Note if both uuidStr and typeStr are specified, typeStr is ignored.
     *   priority: Requested priority for effect control: the priority level corresponds to the
     *             value of priority parameter: negative values indicate lower priorities, positive
     *             values higher priorities, 0 being the normal priority.
     *   usage:    The usage this effect should be a default for. Unrecognized values will be
     *             treated as AUDIO_USAGE_UNKNOWN.
     *   id:       Address where the system-wide unique id of the default effect should be returned.
     *
     * Returned status (from utils/Errors.h) can be:
     *      NO_ERROR        successful operation.
     *      PERMISSION_DENIED could not get AudioFlinger interface
     *                        or caller lacks required permissions.
     *      NO_INIT         effect library failed to initialize.
     *      BAD_VALUE       invalid type uuid or implementation uuid.
     *      NAME_NOT_FOUND  no effect with this uuid or type found.
     *
     * Returned value
     *   *id:  The system-wide unique id of the added default effect.
     */
    static status_t addStreamDefaultEffect(const char* typeStr,
                                           const String16& opPackageName,
                                           const char* uuidStr,
                                           int32_t priority,
                                           audio_usage_t usage,
                                           audio_unique_id_t* id);

    /*
     * Removes an effect from the list of default output effects for a given stream type.
     *
     * Parameters:
     *      id: The system-wide unique id of the effect that should no longer be a default.
     *
     * Returned status (from utils/Errors.h) can be:
     *      NO_ERROR        successful operation.
     *      PERMISSION_DENIED could not get AudioFlinger interface
     *                        or caller lacks required permissions.
     *      NO_INIT         effect library failed to initialize.
     *      BAD_VALUE       invalid id.
     */
    static status_t removeStreamDefaultEffect(audio_unique_id_t id);

    /*
     * Events used by callback function (effect_callback_t).
     */
+38 −32
Original line number Diff line number Diff line
@@ -19,18 +19,9 @@
#include <system/audio.h>

static inline
audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
audio_stream_type_t audio_usage_to_stream_type(const audio_usage_t usage)
{
    // flags to stream type mapping
    if ((attr->flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) == AUDIO_FLAG_AUDIBILITY_ENFORCED) {
        return AUDIO_STREAM_ENFORCED_AUDIBLE;
    }
    if ((attr->flags & AUDIO_FLAG_SCO) == AUDIO_FLAG_SCO) {
        return AUDIO_STREAM_BLUETOOTH_SCO;
    }

    // usage to stream type mapping
    switch (attr->usage) {
    switch(usage) {
        case AUDIO_USAGE_MEDIA:
        case AUDIO_USAGE_GAME:
        case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
@@ -64,6 +55,21 @@ audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *at
    }
}

static inline
audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
{
    // flags to stream type mapping
    if ((attr->flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) == AUDIO_FLAG_AUDIBILITY_ENFORCED) {
        return AUDIO_STREAM_ENFORCED_AUDIBLE;
    }
    if ((attr->flags & AUDIO_FLAG_SCO) == AUDIO_FLAG_SCO) {
        return AUDIO_STREAM_BLUETOOTH_SCO;
    }

    // usage to stream type mapping
    return audio_usage_to_stream_type(attr->usage);
}

static inline
void stream_type_to_audio_attributes(audio_stream_type_t streamType,
                                     audio_attributes_t *attr) {
Loading