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

Commit cc8bbc3f authored by Andy Hung's avatar Andy Hung
Browse files

AudioTrack: Prevent stop() from reissuing last marker event

Avoid a duplicate marker event race condition (1 in 30 or less)
by clearing marker reached in start() not stop().

Bug: 24497521
Change-Id: I9520d063c7d173d2e642174bf60a2bfe75edf085
parent 3ce2bdf3
Loading
Loading
Loading
Loading
+12 −3
Original line number Original line Diff line number Diff line
@@ -523,6 +523,15 @@ status_t AudioTrack::start()
        mTimestampStartupGlitchReported = false;
        mTimestampStartupGlitchReported = false;
        mRetrogradeMotionReported = false;
        mRetrogradeMotionReported = false;


        // If previousState == STATE_STOPPED, we reactivate markers (mMarkerPosition != 0)
        // as the position is reset to 0. This is legacy behavior. This is not done
        // in stop() to avoid a race condition where the last marker event is issued twice.
        // Note: the if is technically unnecessary because previousState == STATE_FLUSHED
        // is only for streaming tracks, and mMarkerReached is already set to false.
        if (previousState == STATE_STOPPED) {
            mMarkerReached = false;
        }

        // For offloaded tracks, we don't know if the hardware counters are really zero here,
        // For offloaded tracks, we don't know if the hardware counters are really zero here,
        // since the flush is asynchronous and stop may not fully drain.
        // since the flush is asynchronous and stop may not fully drain.
        // We save the time when the track is started to later verify whether
        // We save the time when the track is started to later verify whether
@@ -592,9 +601,9 @@ void AudioTrack::stop()


    mProxy->interrupt();
    mProxy->interrupt();
    mAudioTrack->stop();
    mAudioTrack->stop();
    // the playback head position will reset to 0, so if a marker is set, we need

    // to activate it again
    // Note: legacy handling - stop does not clear playback marker
    mMarkerReached = false;
    // and periodic update counter, but flush does for streaming tracks.


    if (mSharedBuffer != 0) {
    if (mSharedBuffer != 0) {
        // clear buffer position and loop count.
        // clear buffer position and loop count.