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

Commit 349223e0 authored by Satya Krishna Pindiproli's avatar Satya Krishna Pindiproli Committed by Giulio Cervera
Browse files

libstagefright: Fix for seek before end of clip issue

- When the clip is seeked to just before the end of the clip,
  the control skips to next track instead of the remaining part
  of the clip being played.
- When the clip is seeked, in LPAPlayerALSA, fillBuffer() is
  called which sets mReachedEOS to true when the last buffer
  is reached. AwesomePlayer on the other hand calls
  onCheckAudioStatus() after seek complete which in turn
  checks if reachedEOS() returns true in LPAPlayerALSA and
  calls postStreamDoneEvent(). Currently, reachedEOS() returns
  mReachedEOS which is incorrect because there still are
  buffers to be written to the DSP.
- Before postAudioEOS() is called, mReachedOutputEOS is set to
  true and is returned by reachedEOS().

CRs-Fixed: 339602 359591
(cherry picked from commit fe2345716be459f38088df2af79b53b1acf71d36)

Change-Id: I1334c8b0ab1e1d6cc386cc770c73ddc50af25c2e
parent e991a3ae
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -270,6 +270,7 @@ private:
    bool mSeeking;
    bool mInternalSeeking;
    bool mReachedEOS;
    bool mReachedOutputEOS;
    status_t mFinalStatus;
    int64_t mSeekTimeUs;
    int64_t mPauseTime;
+12 −3
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ mNumA2DPBytesPlayed(0),
mSeeking(false),
mInternalSeeking(false),
mReachedEOS(false),
mReachedOutputEOS(false),
mFinalStatus(OK),
mStarted(false),
mIsFirstBuffer(false),
@@ -304,6 +305,7 @@ void LPAPlayer::handleA2DPSwitch() {
        mInternalSeeking = true;
        mNumA2DPBytesPlayed = 0;
        mReachedEOS = false;
        mReachedOutputEOS = false;
        pthread_cond_signal(&a2dp_notification_cv);
    } else {
        if (isPaused)
@@ -485,6 +487,7 @@ status_t LPAPlayer::seekTo(int64_t time_us) {
    LOGV("seekTo: time_us %ld", time_us);
    if ( mReachedEOS ) {
        mReachedEOS = false;
        mReachedOutputEOS = false;
    }
    mSeeking = true;

@@ -767,6 +770,7 @@ void LPAPlayer::reset() {
    mSeeking = false;
    mInternalSeeking = false;
    mReachedEOS = false;
    mReachedOutputEOS = false;
    mFinalStatus = OK;
    mStarted = false;
}
@@ -779,10 +783,9 @@ bool LPAPlayer::isSeeking() {

bool LPAPlayer::reachedEOS(status_t *finalStatus) {
    *finalStatus = OK;

    Mutex::Autolock autoLock(mLock);
    *finalStatus = mFinalStatus;
    return mReachedEOS;
    return mReachedOutputEOS;
}


@@ -872,6 +875,7 @@ void LPAPlayer::decoderThreadEntry() {
                  all input buffers have been decoded and response queue is empty*/
                if(mObserver && mReachedEOS && memBuffersResponseQueue.empty()) {
                    LOGV("Posting EOS event..zero byte buffer and response queue is empty");
                    mReachedOutputEOS = true;
                    mObserver->postAudioEOS();
                }
                continue;
@@ -1006,6 +1010,7 @@ void LPAPlayer::eventThreadEntry() {
            LOGV("Timeout %d: Posting EOS event to AwesomePlayer",timeout);
            isPaused = true;
            mPauseTime = mSeekTimeUs + getTimeStamp(A2DP_DISABLED);
            mReachedOutputEOS = true;
            mObserver->postAudioEOS();
            audioEOSPosted = true;
            timeout = -1;
@@ -1082,7 +1087,8 @@ void LPAPlayer::A2DPThreadEntry() {

        //TODO: Remove this
        pthread_mutex_lock(&mem_response_mutex);
        if (memBuffersResponseQueue.empty() || !mAudioSinkOpen || isPaused || !bIsA2DPEnabled) {
        if (memBuffersResponseQueue.empty() || !mAudioSinkOpen || isPaused
			|| !bIsA2DPEnabled || mReachedOutputEOS) {
            LOGV("A2DPThreadEntry:: responseQ empty %d mAudioSinkOpen %d isPaused %d bIsA2DPEnabled %d",
                 memBuffersResponseQueue.empty(), mAudioSinkOpen, isPaused, bIsA2DPEnabled);
            LOGV("A2DPThreadEntry:: Waiting on a2dp_cv");
@@ -1154,6 +1160,7 @@ void LPAPlayer::A2DPThreadEntry() {
            }
            if (mObserver && !asyncReset && mReachedEOS && memBuffersResponseQueue.empty()) {
                LOGV("Posting EOS event to AwesomePlayer");
                mReachedOutputEOS = true;
                mObserver->postAudioEOS();
            }
            pthread_mutex_lock(&mem_request_mutex);
@@ -1320,6 +1327,7 @@ void LPAPlayer::A2DPNotificationThreadEntry() {
        else {
            mInternalSeeking = true;
            mReachedEOS = false;
            mReachedOutputEOS = false;
            mSeekTimeUs += getTimeStamp(A2DP_DISCONNECT);
            mNumA2DPBytesPlayed = 0;
            pthread_cond_signal(&a2dp_cv);
@@ -1702,6 +1710,7 @@ void LPAPlayer::onPauseTimeOut() {
        // 1.) Set seek flags
        mInternalSeeking = true;
        mReachedEOS = false;
        mReachedOutputEOS = false;
        mSeekTimeUs += getTimeStamp(A2DP_DISABLED);

        // 2.) Flush the buffers and transfer everything to request queue