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

Commit 65bfe916 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

AudioPolicyManager: AudioInputDescriptor open ref count cleanup

Always initialize the mOpenRefCount field.
Add functions for management for open ref count.

Change-Id: I0bbd021283047abfebbc108ced68c79e29297f25
parent 0a62162a
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ public:
    void setIoHandle(audio_io_handle_t ioHandle);
    audio_port_handle_t getId() const;
    audio_module_handle_t getModuleHandle() const;
    void changeOpenRefCount(int delta);
    uint32_t getOpenRefCount() const;

    status_t    dump(int fd);

@@ -43,9 +45,8 @@ public:
    audio_devices_t               mDevice;         // current device this input is routed to
    AudioMix                      *mPolicyMix;     // non NULL when used by a dynamic policy
    audio_patch_handle_t          mPatchHandle;
    uint32_t                      mRefCount;       // number of AudioRecord clients using
    uint32_t                      mRefCount;       // number of AudioRecord clients active on
                                                   // this input
    uint32_t                      mOpenRefCount;
    audio_source_t                mInputSource;    // input source selected by application
    //(mediarecorder.h)
    const sp<IOProfile>           mProfile;        // I/O profile this output derives from
@@ -63,6 +64,7 @@ public:

private:
    audio_port_handle_t           mId;
    uint32_t                      mOpenRefCount;
    // Because a preemtible capture session can preempt another one, we end up in an endless loop
    // situation were each session is allowed to restart after being preempted,
    // thus preempting the other one which restarts and so on.
+18 −1
Original line number Diff line number Diff line
@@ -29,7 +29,8 @@ namespace android {
AudioInputDescriptor::AudioInputDescriptor(const sp<IOProfile>& profile)
    : mIoHandle(0),
      mDevice(AUDIO_DEVICE_NONE), mPolicyMix(NULL), mPatchHandle(0), mRefCount(0),
      mInputSource(AUDIO_SOURCE_DEFAULT), mProfile(profile), mIsSoundTrigger(false), mId(0)
      mInputSource(AUDIO_SOURCE_DEFAULT), mProfile(profile), mIsSoundTrigger(false), mId(0),
      mOpenRefCount(0)
{
    if (profile != NULL) {
        mSamplingRate = profile->pickSamplingRate();
@@ -55,6 +56,22 @@ audio_module_handle_t AudioInputDescriptor::getModuleHandle() const
    return mProfile->getModuleHandle();
}

void AudioInputDescriptor::changeOpenRefCount(int delta)
{
    if ((delta + (int)mOpenRefCount) < 0) {
        ALOGW("changeOpenRefCount() invalid delta %d, refCount %d",  delta, mOpenRefCount);
        mOpenRefCount = 0;
        return;
    }
    mOpenRefCount += delta;
    ALOGV("changeOpenRefCount() count %d", mOpenRefCount);
}

uint32_t AudioInputDescriptor::getOpenRefCount() const
{
    return mOpenRefCount;
}

audio_port_handle_t AudioInputDescriptor::getId() const
{
    return mId;
+5 −5
Original line number Diff line number Diff line
@@ -1456,7 +1456,6 @@ status_t AudioPolicyManager::getInputForAttr(const audio_attributes_t *attr,
    sp<AudioInputDescriptor> inputDesc = new AudioInputDescriptor(profile);
    inputDesc->mInputSource = inputSource;
    inputDesc->mRefCount = 0;
    inputDesc->mOpenRefCount = 1;
    inputDesc->mSamplingRate = profileSamplingRate;
    inputDesc->mFormat = profileFormat;
    inputDesc->mChannelMask = profileChannelMask;
@@ -1464,6 +1463,7 @@ status_t AudioPolicyManager::getInputForAttr(const audio_attributes_t *attr,
    inputDesc->mSessions.add(session);
    inputDesc->mIsSoundTrigger = isSoundTrigger;
    inputDesc->mPolicyMix = policyMix;
    inputDesc->changeOpenRefCount(1);

    ALOGV("getInputForAttr() returns input type = %d", *inputType);

@@ -1648,12 +1648,12 @@ void AudioPolicyManager::releaseInput(audio_io_handle_t input,
        return;
    }
    inputDesc->mSessions.remove(session);
    if (inputDesc->mOpenRefCount == 0) {
        ALOGW("releaseInput() invalid open ref count %d", inputDesc->mOpenRefCount);
    if (inputDesc->getOpenRefCount() == 0) {
        ALOGW("releaseInput() invalid open ref count %d", inputDesc->getOpenRefCount());
        return;
    }
    inputDesc->mOpenRefCount--;
    if (inputDesc->mOpenRefCount > 0) {
    inputDesc->changeOpenRefCount(-1);
    if (inputDesc->getOpenRefCount() > 0) {
        ALOGV("releaseInput() exit > 0");
        return;
    }