camera: intel: ipu6: Correct timestamp for RAW reprocessing case

Correct timestamp for RAW reprocessing case.
Fix LongProcessingRepeatingFlexibleYuv cts failed issue

BUG=b:149068439, b:149068672
TEST=Full tested pass for camera functions.

Change-Id: Ie6867d712fd10faf9b89381093df9970cb85ff49
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2594545
Tested-by: Zong Li <zong.li@intel.com>
Reviewed-by: Ren-Pei Zeng <kamesan@chromium.org>
Commit-Queue: Ren-Pei Zeng <kamesan@chromium.org>
diff --git a/camera/hal/intel/ipu6/src/core/CameraBuffer.cpp b/camera/hal/intel/ipu6/src/core/CameraBuffer.cpp
index 5961722..45842d2 100644
--- a/camera/hal/intel/ipu6/src/core/CameraBuffer.cpp
+++ b/camera/hal/intel/ipu6/src/core/CameraBuffer.cpp
@@ -157,7 +157,7 @@
 
     LOG1("%s: ubuffer->s.MemType: %d, addr: %p, fd: %d", __func__, ubuffer->s.memType,
          ubuffer->addr, ubuffer->dmafd);
-    //update the v4l2 buffer memory with user infro
+    //update the v4l2 buffer memory with user info
     switch (ubuffer->s.memType) {
         case V4L2_MEMORY_USERPTR:
             setAddr(ubuffer->addr, 0);
@@ -174,8 +174,16 @@
     }
 
     if (mU->s.streamType == CAMERA_STREAM_INPUT || ubuffer->sequence >= 0) {
+        // update timestamp if raw buffer is selected by user and timestamp is set
+        if (ubuffer->timestamp > 0) {
+            struct timeval timestamp = { 0 };
+            timestamp.tv_sec = ubuffer->timestamp / 1000000000LL;
+            timestamp.tv_usec = (ubuffer->timestamp - timestamp.tv_sec * 1000000000LL) / 1000LL;
+            mV.SetTimestamp(timestamp);
+        }
         mV.SetSequence(ubuffer->sequence);
-        LOG2("%s, input buffer sequence %lld", __func__, ubuffer->sequence);
+        LOG2("%s, input buffer sequence %lld, timestamp %ld", __func__, ubuffer->sequence,
+             ubuffer->timestamp);
     }
 }
 
diff --git a/camera/hal/intel/ipu6/src/core/psysprocessor/GPUExecutor.cpp b/camera/hal/intel/ipu6/src/core/psysprocessor/GPUExecutor.cpp
index ce5a461..92244ae 100644
--- a/camera/hal/intel/ipu6/src/core/psysprocessor/GPUExecutor.cpp
+++ b/camera/hal/intel/ipu6/src/core/psysprocessor/GPUExecutor.cpp
@@ -265,8 +265,12 @@
     CheckError(!totalGain, UNKNOWN_ERROR, "Invalid input");
     AiqResult* aiqResults =
         const_cast<AiqResult*>(AiqResultStorage::getInstance(mCameraId)->getAiqResult(seq));
-    CheckError(!aiqResults, UNKNOWN_ERROR, "Cannot find available aiq result.");
-
+    if (aiqResults == nullptr) {
+        LOGW("%s: no result for sequence %ld! use the latest instead", __func__, seq);
+        aiqResults =
+            const_cast<AiqResult*>(AiqResultStorage::getInstance(mCameraId)->getAiqResult());
+        CheckError((aiqResults == nullptr), INVALID_OPERATION, "Cannot find available aiq result.");
+    }
     *totalGain = (aiqResults->mAeResults.exposures[0].exposure->analog_gain *
                   aiqResults->mAeResults.exposures[0].exposure->digital_gain);
     return OK;