xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/aiq_core/RkLumaCore.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * rkisp_aiq_core.h
3  *
4  *  Copyright (c) 2019 Rockchip Corporation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 
20 #ifndef _RK_LUMA_CORE_H_
21 #define _RK_LUMA_CORE_H_
22 
23 #include "xcam_thread.h"
24 #include "smartptr.h"
25 #include "safe_list.h"
26 #include "xcam_log.h"
27 #include "video_buffer.h"
28 #include "rk_aiq_luma.h"
29 #include "RkAiqCalibDbTypes.h"
30 #include "RkAiqCalibDbV2Helper.h"
31 #include "rk_aiq_types.h"
32 
33 using namespace XCam;
34 namespace RkCam {
35 
36 #define RKAIQLUMA_CORE_CHECK_RET(ret, format, ...) \
37     if (ret) { \
38         LOGE_ANALYZER(format, ##__VA_ARGS__); \
39         return ret; \
40     }
41 
42 #define LUMA_FIFO_CNT 2
43 
44 class RkLumaCore;
45 
46 class RkLumaAnalyzerCb {
47 public:
RkLumaAnalyzerCb()48     explicit RkLumaAnalyzerCb() {};
~RkLumaAnalyzerCb()49     virtual ~RkLumaAnalyzerCb() {};
50     virtual void rkLumaCalcDone(rk_aiq_luma_params_t luma_params) = 0;
51     virtual void rkLumaCalcFailed(const char* msg) = 0;
52 private:
53     XCAM_DEAD_COPY (RkLumaAnalyzerCb);
54 };
55 
56 class RkLumaCoreThread
57     : public Thread {
58 public:
RkLumaCoreThread(RkLumaCore * rkLumaCore)59     RkLumaCoreThread(RkLumaCore* rkLumaCore)
60         : Thread("RkLumaCoreThread")
61         , mRkLumaCore(rkLumaCore) {};
~RkLumaCoreThread()62     ~RkLumaCoreThread() {
63         mStatsQueue.clear ();
64     };
65 
triger_stop()66     void triger_stop() {
67         mStatsQueue.pause_pop ();
68     };
69 
triger_start()70     void triger_start() {
71         mStatsQueue.clear ();
72         mStatsQueue.resume_pop ();
73     };
74 
push_stats(const SmartPtr<VideoBuffer> & buffer)75     bool push_stats (const SmartPtr<VideoBuffer> &buffer) {
76         mStatsQueue.push (buffer);
77         return true;
78     };
79 
80 protected:
81     //virtual bool started ();
stopped()82     virtual void stopped () {
83         mStatsQueue.clear ();
84     };
85     virtual bool loop ();
86 private:
87     RkLumaCore* mRkLumaCore;
88     SafeList<VideoBuffer> mStatsQueue;
89 };
90 
91 class RkLumaCore {
92     friend class RkLumaCoreThread;
93 
94 public:
95     RkLumaCore();
96     virtual ~RkLumaCore();
97 
setAnalyzeResultCb(RkLumaAnalyzerCb * callback)98     bool setAnalyzeResultCb(RkLumaAnalyzerCb* callback) {
99         mCb = callback;
100         return true;
101     }
102 
103     // called only once
104     XCamReturn init(const CalibDbV2_LUMA_DETECT_t* lumaDetect);
105     // called only once
106     XCamReturn deInit();
107     // start analyze thread
108     XCamReturn start();
109     // stop analyze thread
110     XCamReturn stop();
111 
112     XCamReturn pushStats(SmartPtr<VideoBuffer> &buffer);
113 
114     XCamReturn prepare(int mode);
115 private:
116     // in analyzer thread
117     XCamReturn analyze(const SmartPtr<VideoBuffer> &buffer);
118 private:
119     enum rk_aiq_core_state_e {
120         RK_AIQ_CORE_STATE_INVALID,
121         RK_AIQ_CORE_STATE_INITED,
122         RK_AIQ_CORE_STATE_PREPARED,
123         RK_AIQ_CORE_STATE_STARTED,
124         RK_AIQ_CORE_STATE_STOPED,
125     };
126 
127     int mState;
128     int mWorkingMode;
129     RkLumaAnalyzerCb* mCb;
130     SmartPtr<RkLumaCoreThread> mRkLumaCoreTh;
131     SafeList<isp_luma_stat_t> mLumaQueueFIFO;
132     const CalibDbV2_LUMA_DETECT_t* calib;
133 
134     static uint16_t DEFAULT_POOL_SIZE;
135 };
136 
137 }
138 
139 #endif //_RK_LUMA_CORE_H_
140