• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef __QCAMERAPERF_H__
31 #define __QCAMERAPERF_H__
32 
33 // System dependencies
34 #include <utils/Mutex.h>
35 
36 // Camera dependencies
37 #include <android/hardware/power/1.2/IPower.h>
38 
39 using namespace android;
40 using android::hardware::power::V1_2::IPower;
41 using android::hardware::power::V1_2::PowerHint;
42 using ::android::hardware::Return;
43 using ::android::hardware::Void;
44 
45 namespace qcamera {
46 
47 #define DEFAULT_PERF_LOCK_TIMEOUT_MS 1000
48 
49 typedef int32_t (*perfLockAcquire)(int, int, int[], int);
50 typedef int32_t (*perfLockRelease)(int);
51 
52 typedef enum {
53     PERF_LOCK_OPEN_CAMERA,
54     PERF_LOCK_CLOSE_CAMERA,
55     PERF_LOCK_START_PREVIEW,
56     PERF_LOCK_STOP_PREVIEW    = PERF_LOCK_START_PREVIEW,
57     PERF_LOCK_START_RECORDING = PERF_LOCK_START_PREVIEW,
58     PERF_LOCK_STOP_RECORDING  = PERF_LOCK_STOP_PREVIEW,
59     PERF_LOCK_TAKE_SNAPSHOT,
60     PERF_LOCK_OFFLINE_REPROC  = PERF_LOCK_TAKE_SNAPSHOT,
61     PERF_LOCK_POWERHINT_PREVIEW,
62     PERF_LOCK_POWERHINT_ENCODE,
63     PERF_LOCK_COUNT
64 } PerfLockEnum;
65 
66 typedef enum {
67     LOCK_MGR_STATE_UNINITIALIZED,
68     LOCK_MGR_STATE_READY,
69     LOCK_MGR_STATE_ERROR
70 } PerfLockMgrStateEnum;
71 
72 
73 typedef struct {
74     int32_t      *perfLockParams;
75     uint32_t      perfLockParamsCount;
76 } PerfLockInfo;
77 
78 
79 class QCameraPerfLockIntf;
80 
81 class QCameraPerfLock {
82 public:
83     static QCameraPerfLock* create(PerfLockEnum perfLockType);
84     virtual ~QCameraPerfLock();
85 
86     bool releasePerfLock();
87     bool acquirePerfLock(bool     forceReacquirePerfLock,
88                          uint32_t timer = DEFAULT_PERF_LOCK_TIMEOUT_MS);
89     void powerHintInternal(PowerHint powerHint, int32_t time_out);
90 
91 protected:
92     QCameraPerfLock(PerfLockEnum perfLockType, QCameraPerfLockIntf *perfLockIntf);
93 
94 private:
95     Mutex                mMutex;
96     int32_t              mHandle;
97     uint32_t             mRefCount;
98     nsecs_t              mTimeOut;
99     PerfLockEnum         mPerfLockType;
100     QCameraPerfLockIntf *mPerfLockIntf;
101     bool                 mIsPerfdEnabled;
102 
103     static PerfLockInfo  mPerfLockInfo[PERF_LOCK_COUNT];
104 
105     void restartTimer(uint32_t timer);
106     bool isTimedOut();
107 };
108 
109 
110 class QCameraPerfLockIntf {
111 private:
112     static QCameraPerfLockIntf *mInstance;
113     static Mutex                mMutex;
114 
115     uint32_t         mRefCount;
116     perfLockAcquire  mPerfLockAcq;
117     perfLockRelease  mPerfLockRel;
118     void            *mDlHandle;
119 
120 protected:
QCameraPerfLockIntf()121     QCameraPerfLockIntf() { mRefCount = 0; mDlHandle = NULL; }
122     virtual ~QCameraPerfLockIntf();
123 
124 public:
125     static QCameraPerfLockIntf* createSingleton();
126     static void deleteInstance();
127 
perfLockAcq()128     inline perfLockAcquire perfLockAcq() { return mPerfLockAcq; }
perfLockRel()129     inline perfLockRelease perfLockRel() { return mPerfLockRel; }
130     bool powerHint(PowerHint hint, int32_t data);
131 };
132 
133 
134 class QCameraPerfLockMgr {
135 public:
136     QCameraPerfLockMgr();
137     virtual ~QCameraPerfLockMgr();
138 
139     bool releasePerfLock(PerfLockEnum perfLockType);
140     bool acquirePerfLock(PerfLockEnum perfLockType, uint32_t timer = DEFAULT_PERF_LOCK_TIMEOUT_MS);
141 
142     bool acquirePerfLockIfExpired(PerfLockEnum perfLockRnum,
143                                   uint32_t     timer = DEFAULT_PERF_LOCK_TIMEOUT_MS);
144     void powerHintInternal(PerfLockEnum perfLockType, PowerHint powerHint, int32_t time_out);
145 
146 private:
147     PerfLockMgrStateEnum mState;
148     Mutex                mMutex;
149     QCameraPerfLock*     mPerfLock[PERF_LOCK_COUNT];
150 
isValidPerfLockEnum(PerfLockEnum perfLockType)151     inline bool isValidPerfLockEnum(PerfLockEnum perfLockType)
152                     { return (perfLockType < PERF_LOCK_COUNT); }
153 };
154 
155 }; // namespace qcamera
156 
157 #endif /* __QCAMREAPERF_H__ */
158