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

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

audo policy: add effects to record clients

Add list of active effects on input streams and record
clients for further reporting in AudioRecordingConfiguration.

Bug: 111438757
Test: make and dumpsys
Change-Id: I1ae00d2431c80b053f67e2b780f368d5a4822b01
parent 424993f0
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "AudioIODescriptorInterface.h"
#include "AudioPort.h"
#include "ClientDescriptor.h"
#include "EffectDescriptor.h"

namespace android {

@@ -62,7 +63,8 @@ public:
    bool isSoundTrigger() const;
    void setClientActive(const sp<RecordClientDescriptor>& client, bool active);
    int32_t activeCount() { return mGlobalActiveCount; }

    void trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled);
    EffectDescriptorCollection getEnabledEffects() const;
    // implementation of AudioIODescriptorInterface
    audio_config_base_t getConfig() const override;
    audio_patch_handle_t getPatchHandle() const override;
@@ -86,6 +88,9 @@ public:
    RecordClientVector clientsList(bool activeOnly = false,
        audio_source_t source = AUDIO_SOURCE_DEFAULT, bool preferredDeviceOnly = false) const;

    // implementation of ClientMapHandler<RecordClientDescriptor>
    void addClient(const sp<RecordClientDescriptor> &client) override;

 private:

    void updateClientRecordingConfiguration(int event, const sp<RecordClientDescriptor>& client);
@@ -101,6 +106,7 @@ public:
    SortedVector<audio_session_t> mPreemptedSessions;
    AudioPolicyClientInterface * const mClientInterface;
    int32_t mGlobalActiveCount = 0;  // non-client-specific activity ref count
    EffectDescriptorCollection mEnabledEffects;
};

class AudioInputCollection :
@@ -126,6 +132,8 @@ public:

    sp<AudioInputDescriptor> getInputForClient(audio_port_handle_t portId);

    void trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled);

    void dump(String8 *dst) const;
};

+5 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <utils/RefBase.h>
#include <utils/String8.h>
#include "AudioPatch.h"
#include "EffectDescriptor.h"
#include "RoutingStrategy.h"

namespace android {
@@ -119,13 +120,15 @@ public:
    void setAppState(app_state_t appState) { mAppState = appState; }
    app_state_t appState() { return mAppState; }
    bool isSilenced() const { return mAppState == APP_STATE_IDLE; }
    void trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled);
    EffectDescriptorCollection getEnabledEffects() const { return mEnabledEffects; }

private:
    const audio_source_t mSource;
    const audio_input_flags_t mFlags;
    const bool mIsSoundTrigger;
          app_state_t mAppState;

    EffectDescriptorCollection mEnabledEffects;
};

class SourceClientDescriptor: public TrackClientDescriptor
@@ -172,7 +175,7 @@ public:
    virtual ~ClientMapHandler() = default;

    // Track client management
    void addClient(const sp<T> &client) {
    virtual void addClient(const sp<T> &client) {
        const audio_port_handle_t portId = client->portId();
        LOG_ALWAYS_FATAL_IF(!mClients.emplace(portId, client).second,
                "%s(%d): attempting to add client that already exists", __func__, portId);
+6 −4
Original line number Diff line number Diff line
@@ -25,12 +25,12 @@

namespace android {


class EffectDescriptor : public RefBase
{
public:
    void dump(String8 *dst) const;
    void dump(String8 *dst, int spaces = 0) const;

    int mId;                // effect unique ID
    int mIo;                // io the effect is attached to
    routing_strategy mStrategy; // routing strategy the effect is associated to
    int mSession;               // audio session the effect is on
@@ -46,12 +46,14 @@ public:
    status_t registerEffect(const effect_descriptor_t *desc, audio_io_handle_t io,
                            uint32_t strategy, int session, int id);
    status_t unregisterEffect(int id);
    sp<EffectDescriptor> getEffect(int id) const;
    status_t setEffectEnabled(int id, bool enabled);
    bool     isEffectEnabled(int id) const;
    uint32_t getMaxEffectsCpuLoad() const;
    uint32_t getMaxEffectsMemory() const;
    bool isNonOffloadableEffectEnabled();
    bool isNonOffloadableEffectEnabled() const;

    void dump(String8 *dst) const;
    void dump(String8 *dst, int spaces = 0, bool verbose = true) const;

private:
    status_t setEffectEnabled(const sp<EffectDescriptor> &effectDesc, bool enabled);
+49 −0
Original line number Diff line number Diff line
@@ -269,6 +269,16 @@ void AudioInputDescriptor::close()
    }
}

void AudioInputDescriptor::addClient(const sp<RecordClientDescriptor> &client) {
    ClientMapHandler<RecordClientDescriptor>::addClient(client);

    for (size_t i = 0; i < mEnabledEffects.size(); i++) {
        if (mEnabledEffects.valueAt(i)->mSession == client->session()) {
            client->trackEffectEnabled(mEnabledEffects.valueAt(i), true);
        }
    }
}

void AudioInputDescriptor::setClientActive(const sp<RecordClientDescriptor>& client, bool active)
{
    LOG_ALWAYS_FATAL_IF(getClient(client->portId()) == nullptr,
@@ -345,6 +355,33 @@ RecordClientVector AudioInputDescriptor::clientsList(bool activeOnly, audio_sour
    return clients;
}

void AudioInputDescriptor::trackEffectEnabled(const sp<EffectDescriptor> &effect,
                                              bool enabled)
{
    RecordClientVector clients = getClientsForSession((audio_session_t)effect->mSession);
    for (const auto& client : clients) {
        client->trackEffectEnabled(effect, enabled);
    }

    if (enabled) {
        mEnabledEffects.replaceValueFor(effect->mId, effect);
    } else {
        mEnabledEffects.removeItem(effect->mId);
    }
}

EffectDescriptorCollection AudioInputDescriptor::getEnabledEffects() const
{
    EffectDescriptorCollection enabledEffects;
    // report effects for highest priority active source as applied to all clients
    RecordClientVector clients =
        clientsList(true /*activeOnly*/, source(), false /*preferredDeviceOnly*/);
    if (clients.size() > 0) {
        enabledEffects = clients[0]->getEnabledEffects();
    }
    return enabledEffects;
}

void AudioInputDescriptor::dump(String8 *dst) const
{
    dst->appendFormat(" ID: %d\n", getId());
@@ -352,6 +389,7 @@ void AudioInputDescriptor::dump(String8 *dst) const
    dst->appendFormat(" Format: %d\n", mFormat);
    dst->appendFormat(" Channels: %08x\n", mChannelMask);
    dst->appendFormat(" Devices %08x\n", mDevice);
    getEnabledEffects().dump(dst, 1 /*spaces*/, false /*verbose*/);
    dst->append(" AudioRecord Clients:\n");
    ClientMapHandler<RecordClientDescriptor>::dump(dst);
    dst->append("\n");
@@ -424,6 +462,17 @@ sp<AudioInputDescriptor> AudioInputCollection::getInputForClient(audio_port_hand
    return 0;
}

void AudioInputCollection::trackEffectEnabled(const sp<EffectDescriptor> &effect,
                                            bool enabled)
{
    for (size_t i = 0; i < size(); i++) {
        sp<AudioInputDescriptor> inputDesc = valueAt(i);
        if (inputDesc->mIoHandle == effect->mIo) {
            return inputDesc->trackEffectEnabled(effect, enabled);
        }
    }
}

void AudioInputCollection::dump(String8 *dst) const
{
    dst->append("\nInputs dump:\n");
+10 −0
Original line number Diff line number Diff line
@@ -63,10 +63,20 @@ std::string TrackClientDescriptor::toShortString() const
    return ss.str();
}

void RecordClientDescriptor::trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled)
{
    if (enabled) {
        mEnabledEffects.replaceValueFor(effect->mId, effect);
    } else {
        mEnabledEffects.removeItem(effect->mId);
    }
}

void RecordClientDescriptor::dump(String8 *dst, int spaces, int index) const
{
    ClientDescriptor::dump(dst, spaces, index);
    dst->appendFormat("%*s- Source: %d flags: %08x\n", spaces, "", mSource, mFlags);
    mEnabledEffects.dump(dst, spaces + 2 /*spaces*/, false /*verbose*/);
}

SourceClientDescriptor::SourceClientDescriptor(audio_port_handle_t portId, uid_t uid,
Loading