xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rk_stream/include/rk_vi_user_api2_stream_cfg.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  Copyright (c) 2022 Rockchip Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef RK_AIQ_USER_API2_STREM_CFG_H
19 #define RK_AIQ_USER_API2_STREM_CFG_H
20 
21 #include <stdint.h>
22 #include "rk_aiq_offline_raw.h"
23 
24 #ifdef __ANDROID__
25 #include <functional>
26 #endif
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #define RKVI_MAX_SENSORS  12
33 
34 
35 typedef struct {
36     char* sns_ent_name;
37     char* dev0_name;
38     char* dev1_name;
39     char* dev2_name;
40     uint8_t use_offline;
41 } rkraw_vi_init_params_t;
42 
43 typedef struct {
44     uint32_t width;
45     uint32_t height;
46     uint32_t pix_fmt;
47     int hdr_mode;
48     int mem_mode;
49     uint8_t buf_memory_type;
50     uint8_t buf_cnt;
51 } rkraw_vi_prepare_params_t;
52 
53 typedef struct {
54     char ent_names[RKVI_MAX_SENSORS][32];
55 } rkraw_vi_sensor_info_t;
56 
57 struct _st_addrinfo_stream
58 {
59     unsigned int idx;
60     unsigned int fd;
61     unsigned int haddr;
62     unsigned int laddr;
63     unsigned int size;
64     uint64_t     timestamp;
65 }__attribute__ ((packed));
66 
67 struct rkraw2_plane
68 {
69     uint32_t mode;      // 0: only addr 1:contain real image
70     uint32_t idx;
71     uint32_t fd;
72     uint32_t size;
73     uint64_t addr;
74     uint64_t timestamp;
75 };
76 
77 typedef struct {
78     struct _raw_format _rawfmt;
79     struct rkraw2_plane plane[3];
80     rk_aiq_frame_info_t _finfo;
81 } rkrawstream_rkraw2_t;
82 
83 typedef struct rkraw_vi_ctx_s rkraw_vi_ctx_t;
84 
85 typedef void (*isp_trigger_readback_callback)(void *tg);
86 
87 #ifdef __ANDROID__
88 typedef std::function<void(int dev_index)> rkraw_vi_on_isp_process_done_callback;
89 typedef std::function<int(uint8_t *rkraw_data, uint32_t rkraw_len)> rkraw_vi_on_frame_capture_callback;
90 #else
91 typedef void (*rkraw_vi_on_isp_process_done_callback)(int dev_index);
92 typedef int (*rkraw_vi_on_frame_capture_callback)(uint8_t *rkraw_data, uint32_t rkraw_len);
93 #endif
94 
95 /*!
96  * \brief initialze rkrawstream user api
97  * Should call before any other APIs
98  *
99  * \param[in] sns_ent_name    active sensor media entity name. This represents the unique camera module\n
100  *                            in system. And the whole active pipeline could be retrieved by this.
101  * \param[in] iq_file_dir     define the search directory of the iq files.
102  * \param[in] err_cb          not mandatory. it's used to return system errors to user.
103  * \param[in] metas_cb        not mandatory. it's used to return the metas(sensor exposure settings,\n
104  *                            isp settings, etc.) for each frame
105  * \return return rkrawstream context if success, or NULL if failure.
106  */
107 rkraw_vi_ctx_t *rkrawstream_uapi_init();
108 
109 /*!
110  * \brief initialze rkrawstream user api
111  * Should call before any other APIs
112  *
113  * \param[in] isp dirver name  used for offline frames.
114  * \param[in] sensor name     used for offline frames.
115  * \return return rkrawstream context if success, or NULL if failure.
116  */
117 rkraw_vi_ctx_t *rkrawstream_uapi_init_offline(const char *isp_vir, const char *real_sns);
118 
119 /*!
120  * \brief deinitialze rkrawstream context
121  * Should not be called in started state
122  *
123  * \param[in] ctx             the context returned by rkrawstream_uapi_init
124  */
125 void rkrawstream_uapi_deinit(rkraw_vi_ctx_t *ctx);
126 
127 /*!
128  * \brief convert rkraw2 buffer to rkrawstream_rkraw2_t
129  * \param[in] rkraw2          a buffer contain rkraw2 data
130  * \param[out] rawdata        pointer to rkrawstream_rkraw2_t
131  *
132  * \return return 0 on success, -1 on failed
133  */
134 int rkrawstream_uapi_parase_rkraw2(uint8_t *rawdata, rkrawstream_rkraw2_t *rkraw2);
135 
136 /*!
137  * \brief initialze vicap
138  * set up media pipeline, open vicap device, select memory mode, etc.
139  *
140  * \param[in] ctx            the context returned by rkrawstream_uapi_init
141  * \param[in] p              see rkraw_vi_init_params_t for details.
142  */
143 int rkrawstream_vicap_init(rkraw_vi_ctx_t* ctx, rkraw_vi_init_params_t *p);
144 
145 /*!
146  * \brief setup vicap capture format
147  * Set up resolution, pixel format hdr mode, etc.
148  *
149  * \param[in] ctx            the context returned by rkrawstream_uapi_init
150  * \param[in] p              see rkraw_vi_prepare_params_t for details.
151  */
152 int rkrawstream_vicap_prepare(rkraw_vi_ctx_t* ctx, rkraw_vi_prepare_params_t *p);
153 
154 /*!
155  * \brief start vicap stream
156  *
157  * \param[in] ctx            the context returned by rkrawstream_uapi_init
158  * \param[in] cb             a user defined callback function, called when each frame comes\n
159  *                           user can get, modify raw data frome sensor here\n
160  *                           call rkrawstream_readback_set_buffer to send the frame to isp\n
161  *                           by default, frame return to driver after this function returned,\n
162  *                           see rkrawstream_vicap_buf_take for details.\n
163  */
164 int rkrawstream_vicap_start(rkraw_vi_ctx_t* ctx, rkraw_vi_on_frame_capture_callback cb);
165 
166 /*!
167  * \brief stop vicap stream
168  *
169  * \param[in] ctx            the context returned by rkrawstream_uapi_init
170  */
171 int rkrawstream_vicap_stop(rkraw_vi_ctx_t* ctx);
172 
173 /*!
174  * \brief shutdown vicap stream, but keep buffers
175  *
176  * \param[in] ctx            the context returned by rkrawstream_uapi_init
177  */
178 int rkrawstream_vicap_streamoff(rkraw_vi_ctx_t* ctx);
179 
180 /*!
181  * \brief release vicap buffers
182  * should be called when use rkrawstream_vicap_streamoff
183  *
184  * \param[in] ctx            the context returned by rkrawstream_uapi_init
185  */
186 int rkrawstream_vicap_release_buffer(rkraw_vi_ctx_t* ctx);
187 
188 /*!
189  * \brief keep a frame in user callback
190  * note this function can only be called during on_frame_capture_callback.
191  * if called, must call rkrawstream_vicap_buf_return after the buffer used.
192  *
193  * \param[in] ctx            the context returned by rkrawstream_uapi_init
194  */
195 void rkrawstream_vicap_buf_take(rkraw_vi_ctx_t* ctx);
196 
197 /*!
198  * \brief return a frame to vicap driver
199  *
200  * \param[in] ctx            the context returned by rkrawstream_uapi_init
201  */
202 void rkrawstream_vicap_buf_return(rkraw_vi_ctx_t* ctx, int dev_index);
203 
204 /*!
205  * \brief set dmabuf to vicap
206  *
207  * \param[in] ctx            the context returned by rkrawstream_uapi_init
208  * \param[in] dev_index      device index
209  * \param[in] buf_index      buffer index
210  * \param[in] fd             dma buffer fd
211  */
212 void rkrawstream_vicap_setdmabuf(rkraw_vi_ctx_t* ctx, int dev_index, int buf_index, int fd);
213 
214 /*!
215  * \brief initialze readback
216  * set up media pipeline, open readback device, select memory mode, etc.
217  *
218  * \param[in] ctx            the context returned by rkrawstream_uapi_init
219  * \param[in] p              see rkraw_vi_init_params_t for details.
220  */
221 int rkrawstream_readback_init(rkraw_vi_ctx_t* ctx, rkraw_vi_init_params_t *p);
222 
223 /*!
224  * \brief setup readback frame format
225  * Set up resolution, pixel format hdr mode, etc.
226  *
227  * \param[in] ctx            the context returned by rkrawstream_uapi_init
228  * \param[in] p              see rkraw_vi_prepare_params_t for details.
229  */
230 int rkrawstream_readback_prepare(rkraw_vi_ctx_t* ctx, rkraw_vi_prepare_params_t *p);
231 
232 /*!
233  * \brief start readback stream
234  *
235  * \param[in] ctx            the context returned by rkrawstream_uapi_init
236  * \param[in] cb             a user defined callback function, called when a frame processed\n
237  *                           done by isp.
238  */
239 int rkrawstream_readback_start(rkraw_vi_ctx_t* ctx, rkraw_vi_on_isp_process_done_callback cb);
240 
241 /*!
242  * \brief stop readback stream
243  *
244  * \param[in] ctx            the context returned by rkrawstream_uapi_init
245  */
246 int rkrawstream_readback_stop(rkraw_vi_ctx_t* ctx);
247 
248 /*!
249  * \brief send a raw frame to isp.
250  *
251  * \param[in] ctx            the context returned by rkrawstream_uapi_init.
252  * \param[in] rkraw_data     a buffer contain rkraw2 data.
253  */
254 int rkrawstream_readback_set_buffer(rkraw_vi_ctx_t* ctx, uint8_t *rkraw_data);
255 
256 /*!
257  * \brief send a raw frame to isp.
258  *
259  * \param[in] ctx            the context returned by rkrawstream_uapi_init.
260  * \param[in] rkraw2         a pointer to rkraw_vi_init_params_t.
261  */
262 int rkrawstream_readback_set_rkraw2(rkraw_vi_ctx_t* ctx, rkrawstream_rkraw2_t *rkraw2);
263 
264 int rkrawstream_setup_pipline_fmt(rkraw_vi_ctx_t* ctx, int width, int height);
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif
271