From f0c4a6b5cd282b7cdb19205bdcea4572d47c23e1 Mon Sep 17 00:00:00 2001 From: Shuzhen Wang Date: Wed, 5 Sep 2018 09:36:14 -0700 Subject: [PATCH] Camera: Treat decreasing timestamp as BUFFER_ERROR Decreasing timestamp shouldn't happen in non ZSL or reprocessing case. When that happens, treat the buffer as error and return to buffer queue directly. Test: Camera CTS Bug: 113670946 Change-Id: I39d3417dd9307d6cc7c90ff357a82604566a9081 --- .../libcameraservice/device3/Camera3OutputStream.cpp | 10 ++++------ .../camera/libcameraservice/device3/Camera3Stream.cpp | 9 ++++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp index 84767110c0..ecbcf76c68 100644 --- a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp +++ b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp @@ -237,12 +237,14 @@ status_t Camera3OutputStream::returnBufferCheckedLocked( /** * Return buffer back to ANativeWindow */ - if (buffer.status == CAMERA3_BUFFER_STATUS_ERROR || mDropBuffers) { + if (buffer.status == CAMERA3_BUFFER_STATUS_ERROR || mDropBuffers || timestamp == 0) { // Cancel buffer if (mDropBuffers) { ALOGV("%s: Dropping a frame for stream %d.", __FUNCTION__, mId); - } else { + } else if (buffer.status == CAMERA3_BUFFER_STATUS_ERROR) { ALOGW("%s: A frame is dropped for stream %d due to buffer error.", __FUNCTION__, mId); + } else { + ALOGE("%s: Stream %d: timestamp shouldn't be 0", __FUNCTION__, mId); } res = currentConsumer->cancelBuffer(currentConsumer.get(), @@ -268,10 +270,6 @@ status_t Camera3OutputStream::returnBufferCheckedLocked( mTraceFirstBuffer = false; } - if (timestamp == 0) { - ALOGW("%s: Stream %d: timestamp shouldn't be 0", __FUNCTION__, mId); - } - /* Certain consumers (such as AudioSource or HardwareComposer) use * MONOTONIC time, causing time misalignment if camera timestamp is * in BOOTTIME. Do the conversion if necessary. */ diff --git a/services/camera/libcameraservice/device3/Camera3Stream.cpp b/services/camera/libcameraservice/device3/Camera3Stream.cpp index b208d9ffec..9238590b8c 100644 --- a/services/camera/libcameraservice/device3/Camera3Stream.cpp +++ b/services/camera/libcameraservice/device3/Camera3Stream.cpp @@ -662,9 +662,12 @@ status_t Camera3Stream::returnBuffer(const camera3_stream_buffer &buffer, removeOutstandingBuffer(buffer); + // Buffer status may be changed, so make a copy of the stream_buffer struct. + camera3_stream_buffer b = buffer; if (timestampIncreasing && timestamp != 0 && timestamp <= mLastTimestamp) { - ALOGW("%s: Stream %d: timestamp %" PRId64 " is not increasing. Prev timestamp %" PRId64, + ALOGE("%s: Stream %d: timestamp %" PRId64 " is not increasing. Prev timestamp %" PRId64, __FUNCTION__, mId, timestamp, mLastTimestamp); + b.status = CAMERA3_BUFFER_STATUS_ERROR; } mLastTimestamp = timestamp; @@ -676,9 +679,9 @@ status_t Camera3Stream::returnBuffer(const camera3_stream_buffer &buffer, * * Do this for getBuffer as well. */ - status_t res = returnBufferLocked(buffer, timestamp); + status_t res = returnBufferLocked(b, timestamp); if (res == OK) { - fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/true); + fireBufferListenersLocked(b, /*acquired*/false, /*output*/true); } // Even if returning the buffer failed, we still want to signal whoever is waiting for the