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

Commit 5ee81383 authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "Fix direct/offload AudoTrack playback head position on flush & re-use"...

Merge "Fix direct/offload AudoTrack playback head position on flush & re-use" am: 1494f05c am: 30127284

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2200356



Change-Id: I981912d292bcb662e99914386da1a5843d284ff8
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 661a1dd1 30127284
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -1598,13 +1598,16 @@ status_t AudioTrack::getPosition(uint32_t *position)
    }

    AutoMutex lock(mLock);
    // IAudioTrack::stop() isn't synchronous; we don't know when presentation completes
    if (mState == STATE_STOPPED || mState == STATE_FLUSHED) {
        *position = 0;
        return NO_ERROR;
    }
    // FIXME: offloaded and direct tracks call into the HAL for render positions
    // for compressed/synced data; however, we use proxy position for pure linear pcm data
    // as we do not know the capability of the HAL for pcm position support and standby.
    // There may be some latency differences between the HAL position and the proxy position.
    if (isOffloadedOrDirect_l() && !isPurePcmData_l()) {
        uint32_t dspFrames = 0;

        if (isOffloaded_l() && ((mState == STATE_PAUSED) || (mState == STATE_PAUSED_STOPPING))) {
            ALOGV("%s(%d): called in paused state, return cached position %u",
                __func__, mPortId, mPausedPosition);
@@ -1612,13 +1615,15 @@ status_t AudioTrack::getPosition(uint32_t *position)
            return NO_ERROR;
        }

        uint32_t dspFrames = 0;
        if (mOutput != AUDIO_IO_HANDLE_NONE) {
            uint32_t halFrames; // actually unused
            (void) AudioSystem::getRenderPosition(mOutput, &halFrames, &dspFrames);
            // FIXME: on getRenderPosition() error, we return OK with frame position 0.
            if (AudioSystem::getRenderPosition(mOutput, &halFrames, &dspFrames) != NO_ERROR) {
                *position = 0;
                return NO_ERROR;
            }
        }
        // FIXME: dspFrames may not be zero in (mState == STATE_STOPPED || mState == STATE_FLUSHED)
        // due to hardware latency. We leave this behavior for now.
        *position = dspFrames;
    } else {
        if (mCblk->mFlags & CBLK_INVALID) {
@@ -1626,11 +1631,9 @@ status_t AudioTrack::getPosition(uint32_t *position)
            // FIXME: for compatibility with the Java API we ignore the restoreTrack_l()
            // error here (e.g. DEAD_OBJECT) and return OK with the last recorded server position.
        }

        // IAudioTrack::stop() isn't synchronous; we don't know when presentation completes
        *position = (mState == STATE_STOPPED || mState == STATE_FLUSHED) ?
                0 : updateAndGetPosition_l().value();
        *position = updateAndGetPosition_l().value();
    }

    return NO_ERROR;
}

+2 −1
Original line number Diff line number Diff line
@@ -6253,7 +6253,8 @@ void AudioFlinger::DirectOutputThread::onAddNewTrack_l()
                mFlushPending = true;
            }
        } else /* mType == OFFLOAD */ {
            if (previousTrack->sessionId() != latestTrack->sessionId()) {
            if (previousTrack->sessionId() != latestTrack->sessionId() ||
                previousTrack->isFlushPending()) {
                mFlushPending = true;
            }
        }