camera: update to AU_LINUX_ANDROID_LA.BF64.1.2.9.05.01.00.089.312

6ebe040 Revert "Camera3: Disable TNR by default"
100dffb QCamera2/HAL3: perf lock for HDR+
1688313 QCamera2: PowerHint moved to QCameraPerf Class for HAL/HAL3

Change-Id: If3494faec4270d88711b4a0c7171cf1e6352f68c
diff --git a/QCamera2/HAL/QCamera2HWI.cpp b/QCamera2/HAL/QCamera2HWI.cpp
index fcc60fb..5ea4e29 100644
--- a/QCamera2/HAL/QCamera2HWI.cpp
+++ b/QCamera2/HAL/QCamera2HWI.cpp
@@ -1068,7 +1068,6 @@
       m_bPreviewStarted(false),
       m_bRecordStarted(false),
       m_currentFocusState(CAM_AF_SCANNING),
-      m_pPowerModule(NULL),
       mDumpFrmCnt(0U),
       mDumpSkipCnt(0U),
       mThermalLevel(QCAMERA_THERMAL_NO_ADJUSTMENT),
@@ -1134,12 +1133,6 @@
 
     memset(m_BackendFileName, 0, QCAMERA_MAX_FILEPATH_LENGTH);
 
-#ifdef HAS_MULTIMEDIA_HINTS
-    if (hw_get_module(POWER_HARDWARE_MODULE_ID, (const hw_module_t **)&m_pPowerModule)) {
-        ALOGE("%s: %s module not found", __func__, POWER_HARDWARE_MODULE_ID);
-    }
-#endif
-
     memset(mDeffOngoingJobs, 0, sizeof(mDeffOngoingJobs));
     m_perfLock.lock_init();
 
@@ -2364,15 +2357,11 @@
         rc = startChannel(QCAMERA_CH_TYPE_VIDEO);
     }
 
-#ifdef HAS_MULTIMEDIA_HINTS
     if (rc == NO_ERROR) {
-        if (m_pPowerModule) {
-            if (m_pPowerModule->powerHint) {
-                m_pPowerModule->powerHint(m_pPowerModule, POWER_HINT_VIDEO_ENCODE, (void *)"state=1");
-            }
-        }
+        // Set power Hint for video encoding
+        m_perfLock.powerHint(POWER_HINT_VIDEO_ENCODE, 1);
     }
-#endif
+
     CDBG_HIGH("%s: X", __func__);
     return rc;
 }
@@ -2393,13 +2382,10 @@
     CDBG_HIGH("%s: E", __func__);
     int rc = stopChannel(QCAMERA_CH_TYPE_VIDEO);
 
-#ifdef HAS_MULTIMEDIA_HINTS
-    if (m_pPowerModule) {
-        if (m_pPowerModule->powerHint) {
-            m_pPowerModule->powerHint(m_pPowerModule, POWER_HINT_VIDEO_ENCODE, (void *)"state=0");
-        }
+    if (rc == NO_ERROR) {
+        // Disable power Hint
+        m_perfLock.powerHint(POWER_HINT_VIDEO_ENCODE, 0);
     }
-#endif
     CDBG_HIGH("%s: X", __func__);
     return rc;
 }
diff --git a/QCamera2/HAL/QCamera2HWI.h b/QCamera2/HAL/QCamera2HWI.h
index 415b3a0..5a6a841 100644
--- a/QCamera2/HAL/QCamera2HWI.h
+++ b/QCamera2/HAL/QCamera2HWI.h
@@ -31,7 +31,6 @@
 #define __QCAMERA2HARDWAREINTERFACE_H__
 
 #include <hardware/camera.h>
-#include <hardware/power.h>
 #include <utils/Log.h>
 #include <utils/Mutex.h>
 #include <utils/Condition.h>
@@ -548,8 +547,6 @@
     bool m_bLedAfAecLock;
     cam_autofocus_state_t m_currentFocusState;
 
-    power_module_t *m_pPowerModule;   // power module
-
     uint32_t mDumpFrmCnt;  // frame dump count
     uint32_t mDumpSkipCnt; // frame skip count
     mm_jpeg_exif_params_t mExifParams;
diff --git a/QCamera2/HAL3/QCamera3HWI.cpp b/QCamera2/HAL3/QCamera3HWI.cpp
index 1394d63..b1c9c32 100644
--- a/QCamera2/HAL3/QCamera3HWI.cpp
+++ b/QCamera2/HAL3/QCamera3HWI.cpp
@@ -81,6 +81,7 @@
 #define DEFAULT_VIDEO_FPS      (30.0)
 #define MAX_HFR_BATCH_SIZE     (8)
 #define REGIONS_TUPLE_COUNT    5
+#define HDR_PLUS_PERF_TIME_OUT  (7000) // milliseconds
 
 #define METADATA_MAP_SIZE(MAP) (sizeof(MAP)/sizeof(MAP[0]))
 
@@ -337,7 +338,6 @@
       mMinProcessedFrameDuration(0),
       mMinJpegFrameDuration(0),
       mMinRawFrameDuration(0),
-      m_pPowerModule(NULL),
       mMetaFrameCount(0U),
       mUpdateDebugLevel(false),
       mCallbacks(callbacks),
@@ -349,7 +349,9 @@
       mPrevUrgentFrameNumber(0),
       mPrevFrameNumber(0),
       mNeedSensorRestart(false),
-      mLdafCalibExist(false)
+      mLdafCalibExist(false),
+      mPowerHintEnabled(false),
+      mLastCustIntentFrmNum(-1)
 {
     getLogLevel();
     m_perfLock.lock_init();
@@ -362,7 +364,6 @@
     // TODO: hardcode for now until mctl add support for min_num_pp_bufs
     //TBD - To see if this hardcoding is needed. Check by printing if this is filled by mctl to 3
     gCamCapability[cameraId]->min_num_pp_bufs = 3;
-
     pthread_cond_init(&mRequestCond, NULL);
     mPendingLiveRequest = 0;
     mCurrentRequestId = -1;
@@ -371,12 +372,6 @@
     for (size_t i = 0; i < CAMERA3_TEMPLATE_COUNT; i++)
         mDefaultMetadata[i] = NULL;
 
-#ifdef HAS_MULTIMEDIA_HINTS
-    if (hw_get_module(POWER_HARDWARE_MODULE_ID, (const hw_module_t **)&m_pPowerModule)) {
-        ALOGE("%s: %s module not found", __func__, POWER_HARDWARE_MODULE_ID);
-    }
-#endif
-
     // Getting system props of different kinds
     char prop[PROPERTY_VALUE_MAX];
     memset(prop, 0, sizeof(prop));
@@ -389,11 +384,11 @@
     memset(mLdafCalib, 0, sizeof(mLdafCalib));
 
     memset(prop, 0, sizeof(prop));
-    property_get("persist.camera.tnr.preview", prop, "0");
+    property_get("persist.camera.tnr.preview", prop, "1");
     m_bTnrPreview = (uint8_t)atoi(prop);
 
     memset(prop, 0, sizeof(prop));
-    property_get("persist.camera.tnr.video", prop, "0");
+    property_get("persist.camera.tnr.video", prop, "1");
     m_bTnrVideo = (uint8_t)atoi(prop);
 }
 
@@ -410,9 +405,9 @@
 {
     CDBG("%s: E", __func__);
 
-    /* Turn off video hint prior to acquiring perfLock in case they
+    /* Turn off current power hint before acquiring perfLock in case they
      * conflict with each other */
-    updatePowerHint(m_bIsVideo, false);
+    disablePowerHint();
 
     m_perfLock.lock_acq();
 
@@ -995,33 +990,41 @@
 }
 
 /*==============================================================================
- * FUNCTION   : updatePowerHint
+ * FUNCTION   : enablePowerHint
  *
- * DESCRIPTION: update power hint based on whether it's video mode or not.
+ * DESCRIPTION: enable single powerhint for preview and different video modes.
  *
  * PARAMETERS :
- *   @bWasVideo : whether video mode before the switch
- *   @bIsVideo  : whether new mode is video or not.
  *
  * RETURN     : NULL
  *
  *==========================================================================*/
-void QCamera3HardwareInterface::updatePowerHint(bool bWasVideo, bool bIsVideo)
+void QCamera3HardwareInterface::enablePowerHint()
 {
-#ifdef HAS_MULTIMEDIA_HINTS
-    if (bWasVideo == bIsVideo)
-        return;
-
-    if (m_pPowerModule && m_pPowerModule->powerHint) {
-        if (bIsVideo)
-            m_pPowerModule->powerHint(m_pPowerModule,
-                    POWER_HINT_VIDEO_ENCODE, (void *)"state=1");
-        else
-            m_pPowerModule->powerHint(m_pPowerModule,
-                    POWER_HINT_VIDEO_ENCODE, (void *)"state=0");
-     }
-#endif
+    if (!mPowerHintEnabled) {
+        m_perfLock.powerHint(POWER_HINT_VIDEO_ENCODE, 1);
+        mPowerHintEnabled = true;
+    }
 }
+
+/*==============================================================================
+ * FUNCTION   : disablePowerHint
+ *
+ * DESCRIPTION: disable current powerhint.
+ *
+ * PARAMETERS :
+ *
+ * RETURN     : NULL
+ *
+ *==========================================================================*/
+void QCamera3HardwareInterface::disablePowerHint()
+{
+    if (mPowerHintEnabled) {
+        m_perfLock.powerHint(POWER_HINT_VIDEO_ENCODE, 0);
+        mPowerHintEnabled = false;
+    }
+}
+
 /*===========================================================================
  * FUNCTION   : configureStreams
  *
@@ -1039,17 +1042,12 @@
 {
     ATRACE_CALL();
     int rc = 0;
-    bool bWasVideo = m_bIsVideo;
 
     // Acquire perfLock before configure streams
     m_perfLock.lock_acq();
     rc = configureStreamsPerfLocked(streamList);
     m_perfLock.lock_rel();
 
-    /* Update power hint after releasing perfLock in case they
-     * conflict with each other. */
-    updatePowerHint(bWasVideo, m_bIsVideo);
-
     return rc;
 }
 
@@ -2703,6 +2701,44 @@
 }
 
 /*===========================================================================
+ * FUNCTION   : hdrPlusPerfLock
+ *
+ * DESCRIPTION: perf lock for HDR+ using custom intent
+ *
+ * PARAMETERS : @metadata_buf: Metadata super_buf pointer
+ *
+ * RETURN     : None
+ *
+ *==========================================================================*/
+void QCamera3HardwareInterface::hdrPlusPerfLock(
+        mm_camera_super_buf_t *metadata_buf)
+{
+    if (NULL == metadata_buf) {
+        ALOGE("%s: metadata_buf is NULL", __func__);
+        return;
+    }
+    metadata_buffer_t *metadata =
+            (metadata_buffer_t *)metadata_buf->bufs[0]->buffer;
+    int32_t *p_frame_number_valid =
+            POINTER_OF_META(CAM_INTF_META_FRAME_NUMBER_VALID, metadata);
+    uint32_t *p_frame_number =
+            POINTER_OF_META(CAM_INTF_META_FRAME_NUMBER, metadata);
+
+    //acquire perf lock for 5 sec after the last HDR frame is captured
+    if (*p_frame_number_valid) {
+        if (mLastCustIntentFrmNum == (int32_t)*p_frame_number) {
+            m_perfLock.lock_acq_timed(HDR_PLUS_PERF_TIME_OUT);
+        }
+    }
+
+    //release lock after perf lock timer is expired. If lock is already released,
+    //isTimerReset returns false
+    if (m_perfLock.isTimerReset()) {
+        mLastCustIntentFrmNum = -1;
+        m_perfLock.lock_rel_timed();
+    }
+}
+/*===========================================================================
  * FUNCTION   : handleBufferWithLock
  *
  * DESCRIPTION: Handles image buffer callback with mMutex lock held.
@@ -3217,6 +3253,7 @@
         mWokenUpByDaemon = false;
         mPendingLiveRequest = 0;
         mFirstConfiguration = false;
+        enablePowerHint();
     }
 
     uint32_t frameNumber = request->frame_number;
@@ -3332,6 +3369,9 @@
         }
     }
 
+    if (mCaptureIntent == ANDROID_CONTROL_CAPTURE_INTENT_CUSTOM) {
+        mLastCustIntentFrmNum = frameNumber;
+    }
     /* Update pending request list and pending buffers map */
     PendingRequestInfo pendingRequest;
     pendingRequestIterator latestRequest;
@@ -3713,6 +3753,7 @@
             handleBatchMetadata(metadata_buf,
                     true /* free_and_bufdone_meta_buf */);
         } else { /* mBatchSize = 0 */
+            hdrPlusPerfLock(metadata_buf);
             pthread_mutex_lock(&mMutex);
             handleMetadataWithLock(metadata_buf,
                     true /* free_and_bufdone_meta_buf */);
diff --git a/QCamera2/HAL3/QCamera3HWI.h b/QCamera2/HAL3/QCamera3HWI.h
index aa841ae..f890fc5 100644
--- a/QCamera2/HAL3/QCamera3HWI.h
+++ b/QCamera2/HAL3/QCamera3HWI.h
@@ -39,7 +39,6 @@
 #include "QCamera3Channel.h"
 #include "QCamera3CropRegionMapper.h"
 #include "QCameraPerf.h"
-#include <hardware/power.h>
 
 extern "C" {
 #include <mm_camera_interface.h>
@@ -87,7 +86,6 @@
 
 #define MODULE_ALL 0
 
-
 extern volatile uint32_t gCamHal3LogLevel;
 
 class QCamera3MetadataChannel;
@@ -256,7 +254,8 @@
     int32_t numOfSizesOnEncoder(const camera3_stream_configuration_t *streamList,
             const cam_dimension_t &maxViewfinderSize);
 
-    void updatePowerHint(bool bWasVideo, bool bIsVideo);
+    void enablePowerHint();
+    void disablePowerHint();
     int32_t getSensorOutputSize(cam_dimension_t &sensor_dim);
     int32_t dynamicUpdateMetaStreamInfo();
     int32_t startAllChannels();
@@ -266,6 +265,7 @@
 
     bool isOnEncoder(const cam_dimension_t max_viewfinder_size,
             uint32_t width, uint32_t height);
+    void hdrPlusPerfLock(mm_camera_super_buf_t *metadata_buf);
 
     int32_t setBundleInfo();
 
@@ -392,7 +392,6 @@
     int64_t mMinProcessedFrameDuration;
     int64_t mMinJpegFrameDuration;
     int64_t mMinRawFrameDuration;
-    power_module_t *m_pPowerModule;   // power module
 
     uint32_t mMetaFrameCount;
     bool    mUpdateDebugLevel;
@@ -418,6 +417,8 @@
     /* Ldaf calibration data */
     bool mLdafCalibExist;
     uint32_t mLdafCalib[2];
+    bool mPowerHintEnabled;
+    int32_t mLastCustIntentFrmNum;
 
     static const QCameraMap<camera_metadata_enum_android_control_effect_mode_t,
             cam_effect_mode_type> EFFECT_MODES_MAP[];
diff --git a/QCamera2/util/QCameraPerf.cpp b/QCamera2/util/QCameraPerf.cpp
index 399a97c..d082c83 100644
--- a/QCamera2/util/QCameraPerf.cpp
+++ b/QCamera2/util/QCameraPerf.cpp
@@ -65,7 +65,11 @@
         perf_lock_rel(NULL),
         mDlHandle(NULL),
         mPerfLockEnable(0),
-        mPerfLockHandle(-1)
+        mPerfLockHandle(-1),
+        mPerfLockHandleTimed(-1),
+        mTimerSet(0),
+        mPerfLockTimeout(0),
+        mStartTimeofLock(0)
 {
 }
 
@@ -108,6 +112,12 @@
 
     property_get("persist.camera.perflock.enable", value, "1");
     mPerfLockEnable = atoi(value);
+    mCurrentPowerHintEnable = 0;
+#ifdef HAS_MULTIMEDIA_HINTS
+    if (hw_get_module(POWER_HARDWARE_MODULE_ID, (const hw_module_t **)&m_pPowerModule)) {
+        ALOGE("%s: %s module not found", __func__, POWER_HARDWARE_MODULE_ID);
+    }
+#endif
 
     if (mPerfLockEnable) {
         perf_lock_acq = NULL;
@@ -127,13 +137,13 @@
 
         perf_lock_acq = (int (*) (int, int, int[], int))dlsym(mDlHandle, "perf_lock_acq");
         if ((rc = dlerror()) != NULL) {
-            ALOGE("failed to perf_lock_acq function handle");
+            ALOGE("%s: failed to perf_lock_acq function handle", __func__);
             goto cleanup;
         }
 
         perf_lock_rel = (int (*) (int))dlsym(mDlHandle, "perf_lock_rel");
         if ((rc = dlerror()) != NULL) {
-            ALOGE("failed to perf_lock_rel function handle");
+            ALOGE("%s: failed to perf_lock_rel function handle", __func__);
             goto cleanup;
         }
         CDBG("%s X", __func__);
@@ -180,6 +190,108 @@
 }
 
 /*===========================================================================
+ * FUNCTION   : isTimerReset
+ *
+ * DESCRIPTION: Check if timout duration is reached
+ *
+ * PARAMETERS : None
+ *
+ * RETURN     : true if timeout reached
+ *              false if timeout not reached
+ *
+ *==========================================================================*/
+bool QCameraPerfLock::isTimerReset()
+{
+    Mutex::Autolock lock(mLock);
+    if (mPerfLockEnable && mTimerSet) {
+        nsecs_t timeDiff = systemTime() - mStartTimeofLock;
+        if (ns2ms(timeDiff) > (uint32_t)mPerfLockTimeout) {
+            mTimerSet = 0;
+            return true;
+        }
+    }
+    return false;
+}
+
+/*===========================================================================
+ * FUNCTION   : start_timer
+ *
+ * DESCRIPTION: get the start of the timer
+ *
+ * PARAMETERS :
+ *  @timer_val: timer duration in milliseconds
+ *
+ * RETURN     : int32_t type of status
+ *              NO_ERROR  -- success
+ *              none-zero failure code
+ *
+ *==========================================================================*/
+void QCameraPerfLock::startTimer(uint32_t timer_val)
+{
+    mStartTimeofLock = systemTime();
+    mTimerSet = 1;
+    mPerfLockTimeout = timer_val;
+}
+
+/*===========================================================================
+ * FUNCTION   : lock_acq_timed
+ *
+ * DESCRIPTION: Acquire the performance lock for the specified duration.
+ *              If an existing lock timeout has not elapsed, extend the
+ *              lock further for the specified duration
+ *
+ * PARAMETERS :
+ *  @timer_val: lock duration
+ *
+ * RETURN     : int32_t type of status
+ *              NO_ERROR  -- success
+ *              none-zero failure code
+ *
+ *==========================================================================*/
+int32_t QCameraPerfLock::lock_acq_timed(int32_t timer_val)
+{
+    int32_t ret = -1;
+
+    CDBG("%s E", __func__);
+    Mutex::Autolock lock(mLock);
+
+    if (mPerfLockEnable) {
+        int32_t perf_lock_params[] = {
+                ALL_CPUS_PWR_CLPS_DIS,
+                CPU0_MIN_FREQ_TURBO_MAX,
+                CPU4_MIN_FREQ_TURBO_MAX
+        };
+        if (mTimerSet) {
+            nsecs_t curElapsedTime = systemTime() - mStartTimeofLock;
+            int32_t pendingTimeout = mPerfLockTimeout - ns2ms(curElapsedTime);
+            timer_val += pendingTimeout;
+        }
+        startTimer(timer_val);
+
+        // Disable power hint when acquiring the perf lock
+        if (mCurrentPowerHintEnable) {
+            CDBG_HIGH("%s mCurrentPowerHintEnable %d", __func__ ,mCurrentPowerHintEnable);
+            powerHintInternal(mCurrentPowerHint, 0);
+        }
+
+        if ((NULL != perf_lock_acq) && (mPerfLockHandleTimed < 0)) {
+            ret = (*perf_lock_acq)(mPerfLockHandleTimed, timer_val, perf_lock_params,
+                    sizeof(perf_lock_params) / sizeof(int32_t));
+            CDBG("%s ret %d", __func__, ret);
+            if (ret < 0) {
+                ALOGE("%s: failed to acquire lock", __func__);
+            } else {
+                mPerfLockHandleTimed = ret;
+            }
+        }
+        CDBG("%s perf_handle_acq %d ",__func__, mPerfLockHandleTimed);
+    }
+
+    CDBG("%s X", __func__);
+    return ret;
+}
+
+/*===========================================================================
  * FUNCTION   : lock_acq
  *
  * DESCRIPTION: acquire the performance lock
@@ -205,12 +317,18 @@
                 CPU0_MIN_FREQ_TURBO_MAX,
                 CPU4_MIN_FREQ_TURBO_MAX
         };
+
+        // Disable power hint when acquiring the perf lock
+        if (mCurrentPowerHintEnable) {
+            powerHintInternal(mCurrentPowerHint, 0);
+        }
+
         if ((NULL != perf_lock_acq) && (mPerfLockHandle < 0)) {
             ret = (*perf_lock_acq)(mPerfLockHandle, ONE_SEC, perf_lock_params,
                     sizeof(perf_lock_params) / sizeof(int32_t));
             CDBG("%s ret %d", __func__, ret);
             if (ret < 0) {
-                ALOGE("failed to acquire lock");
+                ALOGE("%s: failed to acquire lock", __func__);
             } else {
                 mPerfLockHandle = ret;
             }
@@ -223,6 +341,47 @@
 }
 
 /*===========================================================================
+ * FUNCTION   : lock_rel_timed
+ *
+ * DESCRIPTION: release the performance lock
+ *
+ * PARAMETERS :
+ *   None
+ *
+ * RETURN     : int32_t type of status
+ *              NO_ERROR  -- success
+ *              none-zero failure code
+ *
+ *==========================================================================*/
+int32_t QCameraPerfLock::lock_rel_timed()
+{
+    int ret = -1;
+    Mutex::Autolock lock(mLock);
+    if (mPerfLockEnable) {
+        CDBG("%s E", __func__);
+        if (mPerfLockHandleTimed < 0) {
+            ALOGE("%s: mPerfLockHandle < 0,check if lock is acquired", __func__);
+            return ret;
+        }
+        CDBG("%s perf_handle_rel %d ",__func__, mPerfLockHandleTimed);
+
+        if ((NULL != perf_lock_rel) && (0 <= mPerfLockHandleTimed)) {
+            ret = (*perf_lock_rel)(mPerfLockHandleTimed);
+            if (ret < 0) {
+                ALOGE("%s: failed to release lock", __func__);
+            }
+            mPerfLockHandleTimed = -1;
+        }
+
+        if ((mCurrentPowerHintEnable == 1) && (mTimerSet == 0)) {
+            powerHintInternal(mCurrentPowerHint, mCurrentPowerHintEnable);
+        }
+        CDBG("%s X", __func__);
+    }
+    return ret;
+}
+
+/*===========================================================================
  * FUNCTION   : lock_rel
  *
  * DESCRIPTION: release the performance lock
@@ -242,7 +401,7 @@
     if (mPerfLockEnable) {
         CDBG("%s E", __func__);
         if (mPerfLockHandle < 0) {
-            ALOGE("Error: mPerfLockHandle < 0,check if lock is acquired");
+            ALOGE("%s: mPerfLockHandle < 0,check if lock is acquired", __func__);
             return ret;
         }
         CDBG("%s perf_handle_rel %d ",__func__, mPerfLockHandle);
@@ -250,13 +409,66 @@
         if ((NULL != perf_lock_rel) && (0 <= mPerfLockHandle)) {
             ret = (*perf_lock_rel)(mPerfLockHandle);
             if (ret < 0) {
-                ALOGE("failed to release lock");
+                ALOGE("%s: failed to release lock", __func__);
             }
             mPerfLockHandle = -1;
         }
+
+        if ((mCurrentPowerHintEnable == 1) && (mTimerSet == 0)) {
+            powerHintInternal(mCurrentPowerHint, mCurrentPowerHintEnable);
+        }
         CDBG("%s X", __func__);
     }
     return ret;
 }
 
+/*===========================================================================
+ * FUNCTION   : powerHintInternal
+ *
+ * DESCRIPTION: Sets the requested power hint and state to power HAL.
+ *
+ * PARAMETERS :
+ * enable     : Enable power hint if set to 1. Disable if set to 0.
+ * RETURN     : void
+ *
+ *==========================================================================*/
+void QCameraPerfLock::powerHintInternal(power_hint_t hint, uint32_t enable)
+{
+#ifdef HAS_MULTIMEDIA_HINTS
+    if (m_pPowerModule != NULL) {
+        if (enable == 1) {
+            m_pPowerModule->powerHint(m_pPowerModule, hint, (void *)"state=1");
+        }
+        else {
+            m_pPowerModule->powerHint(m_pPowerModule, hint, (void *)"state=0");
+        }
+    }
+#endif
+}
+
+/*===========================================================================
+ * FUNCTION   : powerHint
+ *
+ * DESCRIPTION: Sets the requested power hint and state to power HAL.
+ *
+ * PARAMETERS :
+ * hint       : Power hint
+ * enable     : Enable power hint if set to 1. Disable if set to 0.
+ * RETURN     : void
+ *
+ *==========================================================================*/
+void QCameraPerfLock::powerHint(power_hint_t hint, uint32_t enable)
+{
+#ifdef HAS_MULTIMEDIA_HINTS
+    if (mCurrentPowerHintEnable) {
+        //disable previous hint
+        powerHintInternal(mCurrentPowerHint, 0);
+    }
+    powerHintInternal(hint, enable);
+
+    mCurrentPowerHint       = hint;
+    mCurrentPowerHintEnable = enable;
+#endif
+}
+
 }; // namespace qcamera
diff --git a/QCamera2/util/QCameraPerf.h b/QCamera2/util/QCameraPerf.h
index 6ff78ec..ca9000c 100644
--- a/QCamera2/util/QCameraPerf.h
+++ b/QCamera2/util/QCameraPerf.h
@@ -32,15 +32,20 @@
 
 #include <dlfcn.h>
 #include <utils/Mutex.h>
-
-#define ONE_SEC 1000
+#include <hardware/power.h>
 
 typedef enum {
+    ALL_CORES_ONLINE = 0x7FE,
     ALL_CPUS_PWR_CLPS_DIS = 0x101,
     CPU0_MIN_FREQ_TURBO_MAX = 0x2FE,
     CPU4_MIN_FREQ_TURBO_MAX = 0x1FFE,
 }perf_lock_params_t;
 
+/* Time related macros */
+#define ONE_SEC 1000
+typedef int64_t nsecs_t;
+#define NSEC_PER_SEC 1000000000LLU
+
 using namespace android;
 
 namespace qcamera {
@@ -54,13 +59,27 @@
     void    lock_deinit();
     int32_t lock_rel();
     int32_t lock_acq();
+    int32_t lock_acq_timed(int32_t timer_val);
+    int32_t lock_rel_timed();
+    bool    isTimerReset();
+    void    powerHintInternal(power_hint_t hint, uint32_t enable);
+    void    powerHint(power_hint_t hint, uint32_t enable);
+
 private:
     int32_t        (*perf_lock_acq)(int, int, int[], int);
     int32_t        (*perf_lock_rel)(int);
+    void            startTimer(uint32_t timer_val);
     void           *mDlHandle;
     uint32_t        mPerfLockEnable;
     Mutex           mLock;
     int32_t         mPerfLockHandle;  // Performance lock library handle
+    int32_t         mPerfLockHandleTimed;  // Performance lock library handle
+    power_module_t *m_pPowerModule;   // power module Handle
+    power_hint_t    mCurrentPowerHint;
+    uint32_t        mCurrentPowerHintEnable;
+    uint32_t        mTimerSet;
+    uint32_t        mPerfLockTimeout;
+    nsecs_t         mStartTimeofLock;
 };
 
 }; // namespace qcamera