xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/algos/aeis/eis_algo_service.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * eis_algo_service.h
3  *
4  *  Copyright (c) 2021 Rockchip Electronics Co.,Ltd
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  * Author: Cody Xie <cody.xie@rock-chips.com>
19  */
20 #ifndef ALGOS_AEIS_EIS_ALGO_H
21 #define ALGOS_AEIS_EIS_ALGO_H
22 
23 #include <map>
24 #include <memory>
25 #include <vector>
26 
27 #include "RkAiqCalibDbTypesV2.h"
28 #include "drm_device.h"
29 #include "dvs_app.h"
30 #include "eis_loader.h"
31 #include "imu_service.h"
32 #include "remap_backend.h"
33 #include "rk_aiq_algo_des.h"
34 #include "rk_aiq_types_priv.h"
35 #include "scaler_service.h"
36 #include "task_service.h"
37 #include "rk_aiq_algo_types.h"
38 #include "xcam_common.h"
39 
40 namespace XCam {
41 
42 class DmaVideoBuffer;
43 
44 }
45 
46 using namespace XCam;
47 
48 namespace RkCam {
49 
50 struct FecMeshConfig;
51 struct FecMeshBuffer;
52 class FecRemapBackend;
53 
54 class EisAlgoAdaptor : public std::enable_shared_from_this<EisAlgoAdaptor> {
55  public:
56     EisAlgoAdaptor() = default;
57     virtual ~EisAlgoAdaptor();
58     EisAlgoAdaptor(const EisAlgoAdaptor&) = delete;
59     const EisAlgoAdaptor& operator=(const EisAlgoAdaptor&) = delete;
60 
61     XCamReturn Config(const AlgoCtxInstanceCfg* config, const CalibDbV2_Eis_t* calib);
62     XCamReturn Prepare(const rk_aiq_mems_sensor_intf_t* mems_sensor_intf,
63                        const isp_drv_share_mem_ops_t* mem_ops);
IsValid()64     bool IsValid() { return valid_; }
IsEnabled()65     bool IsEnabled() { return enable_; }
66 
67     void Start();
68     void OnFrameEvent(const RkAiqAlgoProcAeis* input);
69     void GetProcResult(RkAiqAlgoProcResAeis* output);
70     void Stop();
71 
72  private:
73     XCamReturn LoadLibrary();
74     XCamReturn CreateImuService(const rk_aiq_mems_sensor_intf_t* mems_sensor_intf);
75     XCamReturn CreateScalerService();
76     XCamReturn CreateFecRemapBackend(const FecMeshConfig& config,
77                                      const isp_drv_share_mem_ops_t* mem_ops);
78 
79     int OnMeshCallback(struct dvsEngine* engine, struct meshxyFEC* mesh);
80 
81     // Import image buffers
82     // Alloc Drm Buffers if image mode enabled
83     void ImportImageBuffers(std::map<int, int> indexes);
84 
85     // Check if hardware compatible
86     bool valid_;
87     // Enable/Disable by user
88     bool enable_;
89     bool started_;
90     // Configs and calib data
91     const CalibDbV2_Eis_t* calib_;
92 
93     // DVS algo library
94     std::shared_ptr<DvsLibrary> lib_;
95     std::unique_ptr<struct dvsEngine> engine_;
96     std::map<int, std::unique_ptr<meshxyFEC>> dvs_meshes_;
97     std::map<int, std::unique_ptr<imageData>> dvs_images_;
98 
99     // The remap backend
100     std::unique_ptr<FecRemapBackend> remap_;
101     std::map<int, FecMeshBuffer*> remap_meshes_;
102     FecMeshBuffer* default_mesh_;
103 
104     // IMU Service Handler
105     std::unique_ptr<ImuService> imu_;
106 
107     // Scaler Service Handler
108     std::unique_ptr<ScalerService> scl_;
109     // Drm Buffer Manager
110     // DrmDevice should implement singlton
111     std::shared_ptr<DrmDevice> drm_dev_;
112     using ImageBuffer     = std::shared_ptr<DmaVideoBuffer>;
113     using ImageBufferList = std::vector<ImageBuffer>;
114     // index <unique>, original fd
115     std::map<int, int> image_indexes_;
116     // index <unique>, nr image, scaled images
117     std::tuple<int, ImageBuffer, ImageBufferList> image_groups_;
118 };
119 
120 }  // namespace RkCam
121 
122 #endif  // ALGOS_AEIS_EIS_ALGO_H
123