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

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

Fix issue 3157123.

Use a Mutex wherever atomic operations were used in AudioTrack,
AudioRecord, AudioFlinger and AudioEffect classes.

Change-Id: I6f55b2cabdcd93d64ef19446735b8f33720f8dbc
parent 9c950b41
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -403,7 +403,7 @@ public:
     static status_t guidToString(const effect_uuid_t *guid, char *str, size_t maxLen);
     static status_t guidToString(const effect_uuid_t *guid, char *str, size_t maxLen);


protected:
protected:
     volatile int32_t        mEnabled;           // enable state
     bool                    mEnabled;           // enable state
     int32_t                 mSessionId;         // audio session ID
     int32_t                 mSessionId;         // audio session ID
     int32_t                 mPriority;          // priority for effect control
     int32_t                 mPriority;          // priority for effect control
     status_t                mStatus;            // effect status
     status_t                mStatus;            // effect status
@@ -412,6 +412,7 @@ protected:
     void*                   mUserData;          // client context for callback function
     void*                   mUserData;          // client context for callback function
     effect_descriptor_t     mDescriptor;        // effect descriptor
     effect_descriptor_t     mDescriptor;        // effect descriptor
     int32_t                 mId;                // system wide unique effect engine instance ID
     int32_t                 mId;                // system wide unique effect engine instance ID
     Mutex                   mLock;               // Mutex for mEnabled access


private:
private:


+1 −1
Original line number Original line Diff line number Diff line
@@ -356,7 +356,7 @@ private:
    sp<IAudioRecord>        mAudioRecord;
    sp<IAudioRecord>        mAudioRecord;
    sp<IMemory>             mCblkMemory;
    sp<IMemory>             mCblkMemory;
    sp<ClientRecordThread>  mClientRecordThread;
    sp<ClientRecordThread>  mClientRecordThread;
    Mutex                   mRecordThreadLock;
    Mutex                   mLock;


    uint32_t                mFrameCount;
    uint32_t                mFrameCount;


+1 −0
Original line number Original line Diff line number Diff line
@@ -480,6 +480,7 @@ private:
    uint32_t                mFlags;
    uint32_t                mFlags;
    int                     mSessionId;
    int                     mSessionId;
    int                     mAuxEffectId;
    int                     mAuxEffectId;
    Mutex                   mLock;
};
};




+0 −1
Original line number Original line Diff line number Diff line
@@ -22,7 +22,6 @@
#include <utils/Vector.h>
#include <utils/Vector.h>
#include <utils/KeyedVector.h>
#include <utils/KeyedVector.h>
#include <media/AudioTrack.h>
#include <media/AudioTrack.h>
#include <cutils/atomic.h>


namespace android {
namespace android {


+27 −28
Original line number Original line Diff line number Diff line
@@ -27,7 +27,6 @@
#include <media/AudioEffect.h>
#include <media/AudioEffect.h>


#include <utils/Log.h>
#include <utils/Log.h>
#include <cutils/atomic.h>
#include <binder/IPCThreadState.h>
#include <binder/IPCThreadState.h>




@@ -207,18 +206,22 @@ status_t AudioEffect::setEnabled(bool enabled)
        return INVALID_OPERATION;
        return INVALID_OPERATION;
    }
    }


    status_t status = NO_ERROR;

    AutoMutex lock(mLock);
    if (enabled != mEnabled) {
        if (enabled) {
        if (enabled) {
            LOGV("enable %p", this);
            LOGV("enable %p", this);
        if (android_atomic_or(1, &mEnabled) == 0) {
            status = mIEffect->enable();
           return mIEffect->enable();
        }
        } else {
        } else {
            LOGV("disable %p", this);
            LOGV("disable %p", this);
        if (android_atomic_and(~1, &mEnabled) == 1) {
            status = mIEffect->disable();
           return mIEffect->disable();
        }
        }
        if (status == NO_ERROR) {
            mEnabled = enabled;
        }
        }
    return NO_ERROR;
    }
    return status;
}
}


status_t AudioEffect::command(uint32_t cmdCode,
status_t AudioEffect::command(uint32_t cmdCode,
@@ -232,26 +235,26 @@ status_t AudioEffect::command(uint32_t cmdCode,
        return INVALID_OPERATION;
        return INVALID_OPERATION;
    }
    }


    if ((cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) &&
    if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) {
            (replySize == NULL || *replySize != sizeof(status_t) || replyData == NULL)) {
        if (mEnabled == (cmdCode == EFFECT_CMD_ENABLE)) {
            return NO_ERROR;
        }
        if (replySize == NULL || *replySize != sizeof(status_t) || replyData == NULL) {
            return BAD_VALUE;
            return BAD_VALUE;
        }
        }
        mLock.lock();
    }


    status_t status = mIEffect->command(cmdCode, cmdSize, cmdData, replySize, replyData);
    status_t status = mIEffect->command(cmdCode, cmdSize, cmdData, replySize, replyData);
    if (status != NO_ERROR) {
        return status;
    }


    if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) {
    if (cmdCode == EFFECT_CMD_ENABLE || cmdCode == EFFECT_CMD_DISABLE) {
        if (status == NO_ERROR) {
            status = *(status_t *)replyData;
            status = *(status_t *)replyData;
        if (status != NO_ERROR) {
            return status;
        }
        }
        if (cmdCode == EFFECT_CMD_ENABLE) {
        if (status == NO_ERROR) {
            android_atomic_or(1, &mEnabled);
            mEnabled = (cmdCode == EFFECT_CMD_ENABLE);
        } else {
            android_atomic_and(~1, &mEnabled);
        }
        }
        mLock.unlock();
    }
    }


    return status;
    return status;
@@ -370,11 +373,7 @@ void AudioEffect::enableStatusChanged(bool enabled)
{
{
    LOGV("enableStatusChanged %p enabled %d mCbf %p", this, enabled, mCbf);
    LOGV("enableStatusChanged %p enabled %d mCbf %p", this, enabled, mCbf);
    if (mStatus == ALREADY_EXISTS) {
    if (mStatus == ALREADY_EXISTS) {
        if (enabled) {
        mEnabled = enabled;
            android_atomic_or(1, &mEnabled);
        } else {
            android_atomic_and(~1, &mEnabled);
        }
        if (mCbf) {
        if (mCbf) {
            mCbf(EVENT_ENABLE_STATUS_CHANGED, mUserData, &enabled);
            mCbf(EVENT_ENABLE_STATUS_CHANGED, mUserData, &enabled);
        }
        }
Loading