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

Commit 4de4997e authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

PassthruPatchRecord: fix null timeOut case in obtainBuffer

Properly handle 'timeOut == nullptr' case in
PassthruPatchRecord::obtainBuffer.

Bug: 117564323
Test: make
Change-Id: Id352e47682c0992b817f26b3b594ec5913e663be
parent 7ae95c1a
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -2524,7 +2524,6 @@ status_t AudioFlinger::RecordThread::PassthruPatchRecord::obtainBuffer(
    if (!stream) return NO_INIT;  // If there is no stream, RecordThread is not reading.

    status_t result = NO_ERROR;
    struct timespec newTimeOut = *timeOut;
    size_t bytesRead = 0;
    {
        ATRACE_NAME("read");
@@ -2547,15 +2546,16 @@ status_t AudioFlinger::RecordThread::PassthruPatchRecord::obtainBuffer(
    ALOGW_IF(buffer->mFrameCount < bytesRead / mFrameSize,
            "Lost %zu frames obtained from HAL", bytesRead / mFrameSize - buffer->mFrameCount);
    mUnconsumedFrames = buffer->mFrameCount;
    // Correct newTimeOut by elapsed time.
    struct timespec newTimeOut;
    if (startTimeNs) {
        nsecs_t newTimeOutNs =
                audio_utils_ns_from_timespec(&newTimeOut) - (systemTime() - startTimeNs);
        // Correct the timeout by elapsed time.
        nsecs_t newTimeOutNs = audio_utils_ns_from_timespec(timeOut) - (systemTime() - startTimeNs);
        if (newTimeOutNs < 0) newTimeOutNs = 0;
        newTimeOut.tv_sec = newTimeOutNs / NANOS_PER_SECOND;
        newTimeOut.tv_nsec = newTimeOutNs - newTimeOut.tv_sec * NANOS_PER_SECOND;
        timeOut = &newTimeOut;
    }
    return PatchRecord::obtainBuffer(buffer, &newTimeOut);
    return PatchRecord::obtainBuffer(buffer, timeOut);

stream_error:
    stream->standby();