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

Commit ad85d742 authored by Alexy Joseph's avatar Alexy Joseph Committed by Steve Kondik
Browse files

libmedia: Avoid timestamp queries for pcm offload

Timestamp queries for pcm offloaded tracks should be
avoided as the writes are very short. Timestamp
is calculated from common block.

CRs-Fixed: 786903
Change-Id: Id8234cb8f716f30d9cd402077c6b1caf12efbb2f
parent c62c01e8
Loading
Loading
Loading
Loading
+40 −27
Original line number Diff line number Diff line
@@ -2269,12 +2269,16 @@ status_t AudioTrack::getTimestamp(AudioTimestamp& timestamp)

    // The presented frame count must always lag behind the consumed frame count.
    // To avoid a race, read the presented frames first.  This ensures that presented <= consumed.
    status_t status = mAudioTrack->getTimestamp(timestamp);
    status_t status = NO_ERROR;
    if (!mUseSmallBuf) {
        status = mAudioTrack->getTimestamp(timestamp);
        if (status != NO_ERROR) {
            ALOGV_IF(status != WOULD_BLOCK, "getTimestamp error:%#x", status);
            return status;
        }
    if (isOffloadedOrDirect_l()) {
    }

    if (isOffloadedOrDirect_l() && !mUseSmallBuf) {
        if (isOffloaded_l() && (mState == STATE_PAUSED || mState == STATE_PAUSED_STOPPING)) {
            // use cached paused position in case another offloaded track is running.
            timestamp.mPosition = mPausedPosition;
@@ -2313,6 +2317,14 @@ status_t AudioTrack::getTimestamp(AudioTimestamp& timestamp)
        }
    } else {
        // Update the mapping between local consumed (mPosition) and server consumed (mServer)
        if (mUseSmallBuf) {
            uint32_t tempPos = 0;
            tempPos = (mState == STATE_STOPPED || mState == STATE_FLUSHED) ?
                0 : updateAndGetPosition_l();
            timestamp.mPosition = (tempPos / (mChannelCount * audio_bytes_per_sample(mFormat)));
            clock_gettime(CLOCK_MONOTONIC, &timestamp.mTime);
            return NO_ERROR;
        } else {
            (void) updateAndGetPosition_l();
            // Server consumed (mServer) and presented both use the same server time base,
            // and server consumed is always >= presented.
@@ -2337,6 +2349,7 @@ status_t AudioTrack::getTimestamp(AudioTimestamp& timestamp)
           // IAudioTrack.  And timestamp.mPosition is initially in server's
           // point of view, so we need to apply the same fudge factor to it.
        }
    }
    return status;
}