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

Commit 8b7fc4a2 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "AudioFlinger: Create Client callback" into udc-qpr-dev-plus-aosp

parents 5b501b3a a9b24594
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -1035,7 +1035,7 @@ sp<Client> AudioFlinger::registerPid(pid_t pid)
    // (for which promote() is always != 0), otherwise create a new entry and Client.
    sp<Client> client = mClients.valueFor(pid).promote();
    if (client == 0) {
        client = new Client(this, pid);
        client = sp<Client>::make(sp<IAfClientCallback>::fromExisting(this), pid);
        mClients.add(pid, client);
    }

@@ -2310,16 +2310,16 @@ sp<IAfThreadBase> AudioFlinger::getEffectThread_l(audio_session_t sessionId,

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

Client::Client(const sp<AudioFlinger>& audioFlinger, pid_t pid)
Client::Client(const sp<IAfClientCallback>& afClientCallback, pid_t pid)
    :   RefBase(),
        mAudioFlinger(audioFlinger),
        mAfClientCallback(afClientCallback),
        mPid(pid),
        mClientAllocator(AllocatorFactory::getClientAllocator()) {}

// Client destructor must be called with AudioFlinger::mClientLock held
Client::~Client()
{
    mAudioFlinger->removeClient_l(mPid);
    mAfClientCallback->removeClient_l(mPid);
}

AllocatorFactory::ClientAllocator& Client::allocator()
+18 −12
Original line number Diff line number Diff line
@@ -123,6 +123,9 @@
#include "Client.h"
#include "ResamplerBufferProvider.h"

// TODO(b/291319167) remove me when AudioFlinger class not directly used by subcomponents
namespace android { class AudioFlinger; }

// include AudioFlinger component interfaces
#include "IAfPatchPanel.h"  // this should be listed before other IAf* interfaces.
#include "IAfEffect.h"
@@ -161,10 +164,10 @@ struct stream_type_t {

class AudioFlinger
    : public AudioFlingerServerAdapter::Delegate  // IAudioFlinger client interface
    , public IAfClientCallback
{
    friend class sp<AudioFlinger>;
    // TODO(b/291319167) Create interface and remove friends.
    friend class Client; // removeClient_l();
    friend class DeviceEffectManager;
    friend class DeviceEffectManagerCallback;
    friend class MelReporter;
@@ -358,6 +361,18 @@ public:

    // ---- end of IAudioFlinger interface

    // ---- begin IAfClientCallback interface

    Mutex& clientMutex() const final { return mClientLock; }
    void removeClient_l(pid_t pid) final;
    void removeNotificationClient(pid_t pid) final;
    status_t moveAuxEffectToIo(
            int effectId,
            const sp<IAfPlaybackThread>& dstThread,
            sp<IAfPlaybackThread>* srcThread) final;

    // ---- end of IAfClientCallback interface

    bool isAudioPolicyReady() const { return mAudioPolicyReady.load(); }

    /* List available audio ports and their attributes */
@@ -655,12 +670,6 @@ private:
              status_t moveEffectChain_l(audio_session_t sessionId,
            IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread);

public:
    // TODO(b/291319167) cluster together
              status_t moveAuxEffectToIo(int EffectId,
            const sp<IAfPlaybackThread>& dstThread, sp<IAfPlaybackThread>* srcThread);
private:

              // return thread associated with primary hardware device, or NULL
              IAfPlaybackThread* primaryPlaybackThread_l() const;
              DeviceTypeSet primaryOutputDevice_l() const;
@@ -677,9 +686,6 @@ private:
                      IAfPlaybackThread* thread,
                      const std::vector<audio_io_handle_t>& secondaryOutputs) const;


                void        removeClient_l(pid_t pid);
                void        removeNotificationClient(pid_t pid);
public:
    // TODO(b/291319167) cluster together
                bool isNonOffloadableGlobalEffectEnabled_l();
@@ -731,9 +737,9 @@ public:
                // must be locked after mLock and ThreadBase::mLock if both must be locked
                // avoids acquiring AudioFlinger::mLock from inside thread loop.

    // TODO(b/291319167) access by getter,
    mutable     Mutex                               mClientLock;
private:
    mutable Mutex mClientLock;

                // protected by mClientLock
                DefaultKeyedVector< pid_t, wp<Client> >     mClients;   // see ~Client()

+15 −4
Original line number Diff line number Diff line
@@ -19,23 +19,34 @@
// TODO(b/291318727) Move to nested namespace
namespace android {

class AudioFlinger;
class IAfPlaybackThread;

class IAfClientCallback : public virtual RefBase {
public:
    virtual Mutex& clientMutex() const = 0;
    virtual void removeClient_l(pid_t pid) = 0;
    virtual void removeNotificationClient(pid_t pid) = 0;
    virtual status_t moveAuxEffectToIo(
            int effectId,
            const sp<IAfPlaybackThread>& dstThread,
            sp<IAfPlaybackThread>* srcThread) = 0;
};

class Client : public RefBase {
public:
    Client(const sp<AudioFlinger>& audioFlinger, pid_t pid);
    Client(const sp<IAfClientCallback>& audioFlinger, pid_t pid);

    // TODO(b/289139675) make Client container.
    // Client destructor must be called with AudioFlinger::mClientLock held
    ~Client() override;
    AllocatorFactory::ClientAllocator& allocator();
    pid_t pid() const { return mPid; }
    sp<AudioFlinger> audioFlinger() const { return mAudioFlinger; }
    const auto& afClientCallback() const { return mAfClientCallback; }

private:
    DISALLOW_COPY_AND_ASSIGN(Client);

    const sp<AudioFlinger> mAudioFlinger;
    const sp<IAfClientCallback> mAfClientCallback;
    const pid_t mPid;
    AllocatorFactory::ClientAllocator mClientAllocator;
};
+1 −1
Original line number Diff line number Diff line
@@ -1886,7 +1886,7 @@ void EffectHandle::disconnect(bool unpinIfLast)
        }
        mCblkMemory.clear();    // free the shared memory before releasing the heap it belongs to
        // Client destructor must run with AudioFlinger client mutex locked
        Mutex::Autolock _l2(mClient->audioFlinger()->mClientLock);
        Mutex::Autolock _l2(mClient->afClientCallback()->clientMutex());
        mClient.clear();
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -276,7 +276,7 @@ TrackBase::~TrackBase()
    mCblkMemory.clear();    // free the shared memory before releasing the heap it belongs to
    if (mClient != 0) {
        // Client destructor must run with AudioFlinger client mutex locked
        Mutex::Autolock _l(mClient->audioFlinger()->mClientLock);
        Mutex::Autolock _l(mClient->afClientCallback()->clientMutex());
        // If the client's reference count drops to zero, the associated destructor
        // must run with AudioFlinger lock held. Thus the explicit clear() rather than
        // relying on the automatic clear() at end of scope.
@@ -1682,7 +1682,7 @@ status_t Track::attachAuxEffect(int EffectId)
    auto dstThread = thread->asIAfPlaybackThread();
    // srcThread is initialized by call to moveAuxEffectToIo()
    sp<IAfPlaybackThread> srcThread;
    sp<AudioFlinger> af = mClient->audioFlinger();
    const auto& af = mClient->afClientCallback();
    status_t status = af->moveAuxEffectToIo(EffectId, dstThread, &srcThread);

    if (EffectId != 0 && status == NO_ERROR) {