hc
2024-08-12 233ab1bd4c5697f5cdec94e60206e8c6ac609b4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * rkisp_aiq_core.h
 *
 *  Copyright (c) 2019 Rockchip Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
 
#ifndef _RK_AIQ_HANDLE_H_
#define _RK_AIQ_HANDLE_H_
 
#include <map>
 
#include "rk_aiq_algo_types.h"
#include "rk_aiq_types.h"
#include "xcam_mutex.h"
#include "rk_aiq_pool.h"
 
namespace RkCam {
 
/*
 --------------------------------
|         :RkAiqHandle           |
 --------------------------------
|  rk_aiq_xxx_attrib_t mCurAtt;  |
|  rk_aiq_xxx_attrib_t mNewAtt;  |
|        Mutex mCfgMutex;        |
|        bool updateAtt;         |
 --------------------------------
|         updateConfig()         |
 --------------------------------
*/
 
class RkAiqCore;
struct RkAiqAlgosGroupShared_s;
 
class RkAiqHandle {
 public:
    explicit RkAiqHandle(RkAiqAlgoDesComm* des, RkAiqCore* aiqCore);
    virtual ~RkAiqHandle();
    void setEnable(bool enable) { mEnable = enable; };
    void setReConfig(bool reconfig) { mReConfig = reconfig; };
    bool getEnable() { return mEnable; };
    virtual XCamReturn prepare();
    virtual XCamReturn preProcess();
    virtual XCamReturn processing();
    virtual XCamReturn postProcess();
    virtual XCamReturn genIspResult(RkAiqFullParams* params, RkAiqFullParams* cur_params) { return XCAM_RETURN_NO_ERROR; };
    RkAiqAlgoContext* getAlgoCtx() { return mAlgoCtx; }
    const int getAlgoId() const { return mDes->id; }
    const int getAlgoType() const { return mDes->type; }
    void setGroupId(int32_t gId) {
        mGroupId = gId;
    }
    int32_t getGroupId() {
       return mGroupId;
    }
 
    void setNextHdl(RkAiqHandle* next) {
        mNextHdl = next;
    }
 
    void setParentHdl(RkAiqHandle* parent) {
        mParentHdl = parent;
    }
 
    RkAiqHandle* getNextHdl() {
       return mNextHdl;
    }
 
    RkAiqHandle* getParent() {
       return mParentHdl;
    }
 
    // rk algo running with custom algo concunrrently
    void setMulRun(bool isMulRun) {
        mIsMulRun = isMulRun;
        if (isMulRun && mDes->id == 0)
            mPostShared = false;
        else
            mPostShared = true;
    }
 
    void setGroupShared(void* grp_shared) {
        mAlogsGroupSharedParams = grp_shared;
    }
    void* getGroupShared() {
       return mAlogsGroupSharedParams;
    }
    virtual XCamReturn updateConfig(bool needSync) { return XCAM_RETURN_NO_ERROR; };
    virtual RkAiqAlgoResCom* getPreProcRes() {
        return mPreOutParam;
    }
    virtual RkAiqAlgoResCom* getProcProcRes() {
        return mProcOutParam;
    }
 protected:
    virtual void init() = 0;
    virtual void deInit();
    void waitSignal(rk_aiq_uapi_mode_sync_e sync = RK_AIQ_UAPI_MODE_DEFAULT);
    void sendSignal(rk_aiq_uapi_mode_sync_e sync = RK_AIQ_UAPI_MODE_DEFAULT);
    enum {
        RKAIQ_CONFIG_COM_PREPARE,
        RKAIQ_CONFIG_COM_PRE,
        RKAIQ_CONFIG_COM_PROC,
        RKAIQ_CONFIG_COM_POST,
    };
    virtual XCamReturn configInparamsCom(RkAiqAlgoCom* com, int type);
    RkAiqAlgoCom* mConfig;
    RkAiqAlgoCom* mPreInParam;
    RkAiqAlgoResCom* mPreOutParam;
    RkAiqAlgoCom* mProcInParam;
    RkAiqAlgoResCom* mProcOutParam;
    RkAiqAlgoCom* mPostInParam;
    RkAiqAlgoResCom* mPostOutParam;
    const RkAiqAlgoDesComm* mDes;
    RkAiqAlgoContext* mAlgoCtx;
    RkAiqCore* mAiqCore;
    bool mEnable;
    bool mReConfig;
    uint32_t mGroupId;
    void* mAlogsGroupSharedParams;
    XCam::Mutex mCfgMutex;
    mutable std::atomic<bool> updateAtt;
    XCam::Cond mUpdateCond;
    RkAiqHandle* mNextHdl;
    RkAiqHandle* mParentHdl;
    bool mIsMulRun;
    bool mPostShared;
};
 
template <typename T>
RkAiqHandle* createT(RkAiqAlgoDesComm* des, RkAiqCore* aiqCore) {
    return new T(des, aiqCore);
}
 
struct RkAiqHandleFactory {
    typedef std::map<std::string, RkAiqHandle* (*)(RkAiqAlgoDesComm* des, RkAiqCore* aiqCore)>
        map_type;
 
    ~RkAiqHandleFactory() {
        if (map != nullptr) {
            if (map->empty()) {
                delete map;
            }
        }
    }
 
    static RkAiqHandle* createInstance(std::string const& s, RkAiqAlgoDesComm* des,
                                       RkAiqCore* aiqCore) {
        map_type::iterator it = getMap()->find(s);
        if (it == getMap()->end()) return 0;
        return it->second(des, aiqCore);
    }
 
 protected:
    static map_type* getMap() {
        // never delete'ed. (exist until program termination)
        // because we can't guarantee correct destruction order
        if (!map) {
            map = new map_type;
        }
        return map;
    }
 
 private:
    static map_type* map;
};
 
template <typename T>
struct RkAiqHandleRegister : RkAiqHandleFactory {
    RkAiqHandleRegister(std::string const& s) : s_(s) { getMap()->insert(std::make_pair(s, &createT<T>)); }
    ~RkAiqHandleRegister() { getMap()->erase(s_); }
private:
    const std::string s_;
};
 
#define DECLARE_HANDLE_REGISTER_TYPE(NAME) static RkAiqHandleRegister<NAME> reg
 
#define DEFINE_HANDLE_REGISTER_TYPE(NAME) RkAiqHandleRegister<NAME> NAME::reg(#NAME)
 
};  // namespace RkCam
 
#endif