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

Commit 2267ba18 authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioTrack: extend callback thread sleep time

Do not force wake up the AudioTrack thread every 10ms if no timed
events (loop, markers..) have to be processed.
This will help reduce power consumption.

Change-Id: Icb425b13800690008dd07c27ffac84739e3dbba3
parent 74a0a0d7
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -1078,6 +1078,11 @@ bool AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread)
        frames = mRemainingFrames;
        frames = mRemainingFrames;
    }
    }


    int32_t waitCount = -1;
    if (mUpdatePeriod || (!mMarkerReached && mMarkerPosition) || mLoopCount) {
        waitCount = 1;
    }

    do {
    do {


        audioBuffer.frameCount = frames;
        audioBuffer.frameCount = frames;
@@ -1085,7 +1090,7 @@ bool AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread)
        // Calling obtainBuffer() with a wait count of 1
        // Calling obtainBuffer() with a wait count of 1
        // limits wait time to WAIT_PERIOD_MS. This prevents from being
        // limits wait time to WAIT_PERIOD_MS. This prevents from being
        // stuck here not being able to handle timed events (position, markers, loops).
        // stuck here not being able to handle timed events (position, markers, loops).
        status_t err = obtainBuffer(&audioBuffer, 1);
        status_t err = obtainBuffer(&audioBuffer, waitCount);
        if (err < NO_ERROR) {
        if (err < NO_ERROR) {
            if (err != TIMED_OUT) {
            if (err != TIMED_OUT) {
                LOGE_IF(err != status_t(NO_MORE_BUFFERS), "Error obtaining an audio buffer, giving up.");
                LOGE_IF(err != status_t(NO_MORE_BUFFERS), "Error obtaining an audio buffer, giving up.");