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

Commit 14aabae6 authored by Atneya Nair's avatar Atneya Nair
Browse files

Fix mCallback race. Protect repeat set.

Protecting mCallback with a lock for thread correctness.
Check if we call set twice, this breaks invariants.

Test: Compiles
Change-Id: I81cfbe63308ff1202da6a6b935163314895b66f8
parent 58d6ef80
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -537,6 +537,8 @@ status_t AudioTrack::set(
        float maxRequiredSpeed,
        audio_port_handle_t selectedDeviceId)
{
    LOG_ALWAYS_FATAL_IF(mInitialized, "%s: should not be called twice", __func__);
    mInitialized = true;
    status_t status;
    uint32_t channelCount;
    pid_t callingPid;
@@ -1591,12 +1593,12 @@ void AudioTrack::setLoop_l(uint32_t loopStart, uint32_t loopEnd, int loopCount)

status_t AudioTrack::setMarkerPosition(uint32_t marker)
{
    AutoMutex lock(mLock);
    // The only purpose of setting marker position is to get a callback
    if (!mCallback.promote() || isOffloadedOrDirect()) {
    if (!mCallback.promote() || isOffloadedOrDirect_l()) {
        return INVALID_OPERATION;
    }

    AutoMutex lock(mLock);
    mMarkerPosition = marker;
    mMarkerReached = false;

@@ -1624,12 +1626,12 @@ status_t AudioTrack::getMarkerPosition(uint32_t *marker) const

status_t AudioTrack::setPositionUpdatePeriod(uint32_t updatePeriod)
{
    AutoMutex lock(mLock);
    // The only purpose of setting position update period is to get a callback
    if (!mCallback.promote() || isOffloadedOrDirect()) {
    if (!mCallback.promote() || isOffloadedOrDirect_l()) {
        return INVALID_OPERATION;
    }

    AutoMutex lock(mLock);
    mNewPosition = updateAndGetPosition_l() + updatePeriod;
    mUpdatePeriod = updatePeriod;

+1 −0
Original line number Diff line number Diff line
@@ -1348,6 +1348,7 @@ public:
    sp<IAudioTrackCallback> mLegacyCallbackWrapper;      // wrapper for legacy callback interface
    // for notification APIs

    bool                    mInitialized = false;   // Set after track is initialized
    // next 2 fields are const after constructor or set()
    uint32_t                mNotificationFramesReq; // requested number of frames between each
                                                    // notification callback,