hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
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
/*
 * eis_algo_service.h
 *
 *  Copyright (c) 2021 Rockchip Electronics Co.,Ltd
 *
 * 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.
 *
 * Author: Cody Xie <cody.xie@rock-chips.com>
 */
#ifndef ALGOS_AEIS_EIS_ALGO_H
#define ALGOS_AEIS_EIS_ALGO_H
 
#include <map>
#include <memory>
#include <vector>
 
#include "RkAiqCalibDbTypesV2.h"
#include "drm_device.h"
#include "dvs_app.h"
#include "eis_loader.h"
#include "imu_service.h"
#include "remap_backend.h"
#include "rk_aiq_algo_des.h"
#include "rk_aiq_algo_types_int.h"
#include "rk_aiq_types_priv.h"
#include "scaler_service.h"
#include "task_service.h"
#include "xcam_common.h"
 
namespace XCam {
 
class DmaVideoBuffer;
 
}
 
using namespace XCam;
 
namespace RkCam {
 
struct FecMeshConfig;
struct FecMeshBuffer;
class FecRemapBackend;
 
class EisAlgoAdaptor : public std::enable_shared_from_this<EisAlgoAdaptor> {
 public:
    EisAlgoAdaptor() = default;
    virtual ~EisAlgoAdaptor();
    EisAlgoAdaptor(const EisAlgoAdaptor&) = delete;
    const EisAlgoAdaptor& operator=(const EisAlgoAdaptor&) = delete;
 
    XCamReturn Config(const AlgoCtxInstanceCfgInt* config, const CalibDbV2_Eis_t* calib);
    XCamReturn Prepare(const rk_aiq_mems_sensor_intf_t* mems_sensor_intf,
                       const isp_drv_share_mem_ops_t* mem_ops);
    bool IsValid() { return valid_; }
    bool IsEnabled() { return enable_; }
 
    void Start();
    void OnFrameEvent(const RkAiqAlgoProcAeisInt* input);
    void GetProcResult(RkAiqAlgoProcResAeisInt* output);
    void Stop();
 
 private:
    XCamReturn LoadLibrary();
    XCamReturn CreateImuService(const rk_aiq_mems_sensor_intf_t* mems_sensor_intf);
    XCamReturn CreateScalerService();
    XCamReturn CreateFecRemapBackend(const FecMeshConfig& config,
                                     const isp_drv_share_mem_ops_t* mem_ops);
 
    int OnMeshCallback(struct dvsEngine* engine, struct meshxyFEC* mesh);
 
    // Import image buffers
    // Alloc Drm Buffers if image mode enabled
    void ImportImageBuffers(std::map<int, int> indexes);
 
    // Check if hardware compatible
    bool valid_;
    // Enable/Disable by user
    bool enable_;
    bool started_;
    // Configs and calib data
    const CalibDbV2_Eis_t* calib_;
 
    // DVS algo library
    std::shared_ptr<DvsLibrary> lib_;
    std::unique_ptr<struct dvsEngine> engine_;
    std::map<int, std::unique_ptr<meshxyFEC>> dvs_meshes_;
    std::map<int, std::unique_ptr<imageData>> dvs_images_;
 
    // The remap backend
    std::unique_ptr<FecRemapBackend> remap_;
    std::map<int, FecMeshBuffer*> remap_meshes_;
    FecMeshBuffer* default_mesh_;
 
    // IMU Service Handler
    std::unique_ptr<ImuService> imu_;
 
    // Scaler Service Handler
    std::unique_ptr<ScalerService> scl_;
    // Drm Buffer Manager
    // DrmDevice should implement singlton
    std::shared_ptr<DrmDevice> drm_dev_;
    using ImageBuffer     = std::shared_ptr<DmaVideoBuffer>;
    using ImageBufferList = std::vector<ImageBuffer>;
    // index <unique>, original fd
    std::map<int, int> image_indexes_;
    // index <unique>, nr image, scaled images
    std::tuple<int, ImageBuffer, ImageBufferList> image_groups_;
};
 
}  // namespace RkCam
 
#endif  // ALGOS_AEIS_EIS_ALGO_H