QCamera2: HAL3: Provide perf hint to CPP for snapshot

This fix provides hint to CPP to scale the clock which helps
the performance for offline reprocess and helps the power for
4K liveshot

Ack-by: Ashvin Deodhar

BUG=28930897
Change-Id: I42df8fa9260623ebe90d5eb99a1e84708b91b9e8
diff --git a/QCamera2/HAL3/QCamera3Channel.cpp b/QCamera2/HAL3/QCamera3Channel.cpp
index f7790ec..12b8930 100644
--- a/QCamera2/HAL3/QCamera3Channel.cpp
+++ b/QCamera2/HAL3/QCamera3Channel.cpp
@@ -3212,6 +3212,7 @@
             free(job);
         }
 
+        obj->resetCppPerfParam();
         return;
         // }
     } else {
@@ -3245,6 +3246,7 @@
     mYuvWidth = stream->width;
     mYuvHeight = stream->height;
     mStreamType = CAM_STREAM_TYPE_SNAPSHOT;
+    mPendingLiveSnapshotFrames = 0;
     // Use same pixelformat for 4K video case
     mStreamFormat = getStreamDefaultFormat(CAM_STREAM_TYPE_SNAPSHOT,
             stream->width, stream->height);
@@ -3406,6 +3408,11 @@
     // Start postprocessor
     startPostProc(reproc_cfg);
 
+    // Only set the perf mode for online cpp processing
+    if (reproc_cfg.reprocess_type == REPROCESS_TYPE_NONE) {
+        setCppPerfParam();
+    }
+
     // Queue jpeg settings
     rc = queueJpegSetting((uint32_t)index, metadata);
 
@@ -3684,6 +3691,61 @@
     return expectedReprocess;
 }
 
+/*===========================================================================
+ * FUNCTION   : setCppPerfParam
+ *
+ * DESCRIPTION: set the performance related stream params
+ *
+ * PARAMETERS : NONE
+ *
+ * RETURN     : NONE
+ *==========================================================================*/
+
+void QCamera3PicChannel::setCppPerfParam()
+{
+    if (mPendingLiveSnapshotFrames == 0) {
+        int32_t rc = 0;
+        QCamera3Stream *pStream = mStreams[0];
+        cam_stream_parm_buffer_t param;
+        memset(&param, 0, sizeof(cam_stream_parm_buffer_t));
+        param.type = CAM_STREAM_PARAM_TYPE_REQUEST_OPS_MODE;
+        param.perf_mode = CAM_PERF_SET;
+        rc = pStream->setParameter(param);
+        if (rc != NO_ERROR) {
+            LOGE("%s: setParameter for CAM_PERF_SET failed",
+                __func__);
+        }
+    }
+    mPendingLiveSnapshotFrames++;
+}
+
+/*===========================================================================
+ * FUNCTION   : resetCppPerfParam
+ *
+ * DESCRIPTION: reset the performance related stream params
+ *
+ * PARAMETERS : NONE
+ *
+ * RETURN     : NONE
+ *==========================================================================*/
+
+void QCamera3PicChannel::resetCppPerfParam()
+{
+    if (mPendingLiveSnapshotFrames > 0) {
+        int32_t rc = NO_ERROR;
+        QCamera3Stream *pStream = mStreams[0];
+        cam_stream_parm_buffer_t param;
+        memset(&param, 0, sizeof(cam_stream_parm_buffer_t));
+        param.type = CAM_STREAM_PARAM_TYPE_REQUEST_OPS_MODE;
+        param.perf_mode = CAM_PERF_RESET;
+        rc = pStream->setParameter(param);
+        if (rc != NO_ERROR) {
+            LOGE("%s: setParameter for CAM_PERF_RESET failed",
+                __func__);
+        }
+        mPendingLiveSnapshotFrames--;
+    }
+}
 
 /*===========================================================================
  * FUNCTION   : QCamera3ReprocessChannel
@@ -3899,8 +3961,8 @@
             obj->m_postprocessor.releasePPJobData(pp_job);
         }
         free(pp_job);
-        resetToCamPerfNormal(resultFrameNumber);
     }
+    resetToCamPerfNormal(resultFrameNumber);
     free(super_frame);
     return;
 }
@@ -4564,7 +4626,7 @@
         cam_stream_parm_buffer_t param;
         uint32_t numPendingPriorityFrames = 0;
 
-        if(isPriorityFrame && (mReprocessType != REPROCESS_TYPE_JPEG)) {
+        if(isPriorityFrame) {
             Mutex::Autolock lock(mPriorityFramesLock);
             /* read the length before pushing the frame number to check if
              * vector is empty */
@@ -4572,12 +4634,12 @@
             mPriorityFrames.push(frame->frameNumber);
         }
 
-        if(isPriorityFrame && !numPendingPriorityFrames &&
-            (mReprocessType != REPROCESS_TYPE_JPEG)) {
+        if(isPriorityFrame && !numPendingPriorityFrames) {
             memset(&param, 0, sizeof(cam_stream_parm_buffer_t));
             param.type = CAM_STREAM_PARAM_TYPE_REQUEST_OPS_MODE;
             param.perf_mode = CAM_PERF_HIGH_PERFORMANCE;
             rc = pStream->setParameter(param);
+
             if (rc != NO_ERROR) {
                 ALOGE("%s: setParameter for CAM_PERF_HIGH_PERFORMANCE failed",
                     __func__);
diff --git a/QCamera2/HAL3/QCamera3Channel.h b/QCamera2/HAL3/QCamera3Channel.h
index 0bb4f3a..baf3fe9 100644
--- a/QCamera2/HAL3/QCamera3Channel.h
+++ b/QCamera2/HAL3/QCamera3Channel.h
@@ -503,6 +503,8 @@
             void *userdata);
     static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame,
             void *userdata);
+    void setCppPerfParam();
+    void resetCppPerfParam();
 
 private:
     int32_t queueJpegSetting(uint32_t out_buf_index, metadata_buffer_t *metadata);
@@ -520,6 +522,7 @@
     Mutex mFreeBuffersLock;
     List<uint32_t> mFreeBufferList;
     uint32_t mFrameLen;
+    uint32_t mPendingLiveSnapshotFrames;
 };
 
 // reprocess channel class
diff --git a/QCamera2/HAL3/QCamera3PostProc.cpp b/QCamera2/HAL3/QCamera3PostProc.cpp
index e582d9a..73b6fe7 100644
--- a/QCamera2/HAL3/QCamera3PostProc.cpp
+++ b/QCamera2/HAL3/QCamera3PostProc.cpp
@@ -1832,7 +1832,7 @@
                                     // add into ongoing PP job Q
                                     pp_job->fwk_src_frame = fwk_frame;
                                     pme->m_ongoingPPQ.enqueue((void *)pp_job);
-                                    ret = pme->m_pReprocChannel->doReprocessOffline(fwk_frame);
+                                    ret = pme->m_pReprocChannel->doReprocessOffline(fwk_frame, true);
                                     if (NO_ERROR != ret) {
                                         // remove from ongoing PP job Q
                                         pme->m_ongoingPPQ.dequeue(false);
diff --git a/QCamera2/stack/common/cam_types.h b/QCamera2/stack/common/cam_types.h
index 5f67847..ca61ba5 100644
--- a/QCamera2/stack/common/cam_types.h
+++ b/QCamera2/stack/common/cam_types.h
@@ -2719,6 +2719,8 @@
     CAM_PERF_NORMAL = 0,
     CAM_PERF_HIGH,
     CAM_PERF_HIGH_PERFORMANCE,
+    CAM_PERF_RESET,
+    CAM_PERF_SET
 } cam_perf_mode_t;
 
 typedef struct {