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

Commit 6de6b482 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "Issue 5298399: Lost speech after a crash in gTalk."

parents 3a1dccab cfe2ba6b
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -486,6 +486,7 @@ private:
    int                     mSessionId;
    int                     mSessionId;
    int                     mAuxEffectId;
    int                     mAuxEffectId;
    Mutex                   mLock;
    Mutex                   mLock;
    status_t                mRestoreStatus;
};
};




+14 −12
Original line number Original line Diff line number Diff line
@@ -262,7 +262,7 @@ status_t AudioTrack::set(
    mFlushed = false;
    mFlushed = false;
    mFlags = flags;
    mFlags = flags;
    AudioSystem::acquireAudioSessionId(mSessionId);
    AudioSystem::acquireAudioSessionId(mSessionId);

    mRestoreStatus = NO_ERROR;
    return NO_ERROR;
    return NO_ERROR;
}
}


@@ -1161,8 +1161,8 @@ status_t AudioTrack::restoreTrack_l(audio_track_cblk_t*& cblk, bool fromStart)
    status_t result;
    status_t result;


    if (!(android_atomic_or(CBLK_RESTORING_ON, &cblk->flags) & CBLK_RESTORING_MSK)) {
    if (!(android_atomic_or(CBLK_RESTORING_ON, &cblk->flags) & CBLK_RESTORING_MSK)) {
        LOGW("dead IAudioTrack, creating a new one from %s",
        LOGW("dead IAudioTrack, creating a new one from %s TID %d",
             fromStart ? "start()" : "obtainBuffer()");
             fromStart ? "start()" : "obtainBuffer()", gettid());


        // signal old cblk condition so that other threads waiting for available buffers stop
        // signal old cblk condition so that other threads waiting for available buffers stop
        // waiting now
        // waiting now
@@ -1217,33 +1217,35 @@ status_t AudioTrack::restoreTrack_l(audio_track_cblk_t*& cblk, bool fromStart)
            }
            }
            if (mActive) {
            if (mActive) {
                result = mAudioTrack->start();
                result = mAudioTrack->start();
                LOGW_IF(result != NO_ERROR, "restoreTrack_l() start() failed status %d", result);
            }
            }
            if (fromStart && result == NO_ERROR) {
            if (fromStart && result == NO_ERROR) {
                mNewPosition = mCblk->server + mUpdatePeriod;
                mNewPosition = mCblk->server + mUpdatePeriod;
            }
            }
        }
        }
        if (result != NO_ERROR) {
        if (result != NO_ERROR) {
            mActive = false;
            android_atomic_and(~CBLK_RESTORING_ON, &cblk->flags);
            LOGW_IF(result != NO_ERROR, "restoreTrack_l() failed status %d", result);
        }
        }

        mRestoreStatus = result;
        // signal old cblk condition for other threads waiting for restore completion
        // signal old cblk condition for other threads waiting for restore completion
        android_atomic_or(CBLK_RESTORED_ON, &cblk->flags);
        android_atomic_or(CBLK_RESTORED_ON, &cblk->flags);
        cblk->cv.broadcast();
        cblk->cv.broadcast();
    } else {
    } else {
        if (!(cblk->flags & CBLK_RESTORED_MSK)) {
        if (!(cblk->flags & CBLK_RESTORED_MSK)) {
            LOGW("dead IAudioTrack, waiting for a new one");
            LOGW("dead IAudioTrack, waiting for a new one TID %d", gettid());
            mLock.unlock();
            mLock.unlock();
            result = cblk->cv.waitRelative(cblk->lock, milliseconds(RESTORE_TIMEOUT_MS));
            result = cblk->cv.waitRelative(cblk->lock, milliseconds(RESTORE_TIMEOUT_MS));
            if (result == NO_ERROR) {
                result = mRestoreStatus;
            }
            cblk->lock.unlock();
            cblk->lock.unlock();
            mLock.lock();
            mLock.lock();
        } else {
        } else {
            LOGW("dead IAudioTrack, already restored");
            LOGW("dead IAudioTrack, already restored TID %d", gettid());
            result = NO_ERROR;
            result = mRestoreStatus;
            cblk->lock.unlock();
            cblk->lock.unlock();
        }
        }
        if (result != NO_ERROR || mActive == 0) {
            result = status_t(STOPPED);
        }
    }
    }
    LOGV("restoreTrack_l() status %d mActive %d cblk %p, old cblk %p flags %08x old flags %08x",
    LOGV("restoreTrack_l() status %d mActive %d cblk %p, old cblk %p flags %08x old flags %08x",
         result, mActive, mCblk, cblk, mCblk->flags, cblk->flags);
         result, mActive, mCblk, cblk, mCblk->flags, cblk->flags);
@@ -1254,7 +1256,7 @@ status_t AudioTrack::restoreTrack_l(audio_track_cblk_t*& cblk, bool fromStart)
    }
    }
    cblk->lock.lock();
    cblk->lock.lock();


    LOGW_IF(result != NO_ERROR, "restoreTrack_l() error %d", result);
    LOGW_IF(result != NO_ERROR, "restoreTrack_l() error %d TID %d", result, gettid());


    return result;
    return result;
}
}