csi_camera.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Copyright (C) 2021 Alibaba Group Holding Limited
  3. * Author: LuChongzhi <chongzhi.lcz@alibaba-inc.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef __CSI_CAMERA_H__
  10. #define __CSI_CAMERA_H__
  11. #include <time.h>
  12. #include <csi_common.h>
  13. #include <csi_camera_property.h>
  14. #include <csi_camera_frame.h>
  15. #include <csi_frame_ex.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /*
  20. * Camera logical parts are below, including: input sensor and output channel
  21. * @------------------------------@
  22. * | Camera Settings _____|______ Channel Settings
  23. * | =================== | | =====================
  24. * | Exposure | channel[0] | configuration: width/height, pix_fmt
  25. * | R/G/B Gain |_____ ______| ---> Channel Events
  26. * | HDR mode _____|______
  27. * | ...... | |
  28. * | | channel[1] | configuration: width/height, pix_fmt
  29. * | |_____ ______| ---> Channel Events
  30. * | _____|______
  31. * | | |
  32. * | | channel[n] | configuration: width/height, pix_fmt
  33. * | |_____ ______| ---> Channel Events
  34. * | CAMERA |
  35. * @------------------------------@ ===> Camera Events (sensor, error, warning...)
  36. */
  37. #define CSI_CAMERA_VERSION_MAJOR 0
  38. #define CSI_CAMERA_VERSION_MINOR 2
  39. #define CSI_CAMERA_NAME_MAX_LEN 32
  40. typedef void *csi_cam_handle_t;
  41. typedef void *csi_cam_event_handle_t;
  42. typedef struct csi_cam_handle_info {
  43. int idx;
  44. } csi_cam_handle_info_t;
  45. #define MAX_FRAME_COUNT 1024
  46. typedef enum csi_frame_status_type {
  47. CSI_FRAME_IDLE = 1,
  48. CSI_FRAME_WORKING = 2,
  49. CSI_FRAME_READY = 3,
  50. CSI_FRAME_DISPATCHED = 4,
  51. } csi_frame_status_type_e;
  52. typedef struct frame_channel_info {
  53. unsigned char *frame_bufs[MAX_FRAME_COUNT];
  54. int frame_status[MAX_FRAME_COUNT];
  55. int refcount[MAX_FRAME_COUNT];
  56. int frame_cnt;
  57. csi_frame_s frame[MAX_FRAME_COUNT];
  58. } frame_channel_info_s;
  59. typedef struct camera_frame_info {
  60. unsigned char *frame_bufs;
  61. int frame_status;
  62. } camera_frame_info_s;
  63. #define CSI_CAMERA_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */
  64. #define CSI_CAMERA_CAP_META_CAPTURE 0x00800000 /* Is a metadata capture device */
  65. typedef struct csi_camera_info {
  66. char camera_name[CSI_CAMERA_NAME_MAX_LEN];
  67. char device_name[CSI_CAMERA_NAME_MAX_LEN];
  68. char bus_info[32]; /* e.g. "MIPI-CSI" */
  69. unsigned int capabilities; /* bit mask of CSI_CAMERA_CAP_xx */
  70. } csi_camera_info_s;
  71. #define CSI_CAMERA_MAX_COUNT 16
  72. typedef struct csi_camera_infos {
  73. unsigned int count;
  74. csi_camera_info_s info[CSI_CAMERA_MAX_COUNT];
  75. } csi_camera_infos_s;
  76. #define CSI_CAMERA_MODE_MAX_COUNT 16
  77. typedef struct csi_camera_modes {
  78. int count;
  79. struct {
  80. int mode_id;
  81. char description[128];
  82. } modes[CSI_CAMERA_MODE_MAX_COUNT];
  83. } csi_camera_modes_s;
  84. typedef struct csi_camera_mode_cfg {
  85. int mode_id;
  86. char *calibriation; /* set NULL to use default in system */
  87. char *lib3a; /* set NULL to use default in system */
  88. } csi_camera_mode_cfg_s;
  89. typedef enum csi_camera_property_type {
  90. CSI_CAMERA_PROPERTY_TYPE_INTEGER = 1,
  91. CSI_CAMERA_PROPERTY_TYPE_BOOLEAN = 2,
  92. CSI_CAMERA_PROPERTY_TYPE_ENUM = 3,
  93. CSI_CAMERA_PROPERTY_TYPE_STRING = 7,
  94. CSI_CAMERA_PROPERTY_TYPE_BITMASK = 8,
  95. } csi_camera_property_type_e;
  96. typedef union csi_camera_property_data {
  97. bool bool_value;
  98. int int_value;
  99. int enum_value;
  100. uint32_t bitmask_value;
  101. char str_value[32];
  102. } csi_camera_property_data_u;
  103. typedef struct csi_camera_property_description {
  104. unsigned int id; /* CSI_CAMERA_PID_xx */
  105. csi_camera_property_type_e type; /* data type */
  106. char name[32]; /* Whatever */
  107. int minimum; /* Note signedness */
  108. int maximum;
  109. int step;
  110. csi_camera_property_data_u default_value;
  111. csi_camera_property_data_u value; /*current value*/
  112. unsigned int flags;
  113. unsigned int reserved[2];
  114. } csi_camera_property_description_s;
  115. typedef struct csi_camera_property {
  116. unsigned int id;
  117. csi_camera_property_type_e type; /* data type */
  118. csi_camera_property_data_u value;
  119. } csi_camera_property_s;
  120. typedef struct csi_camera_properties {
  121. unsigned int count;
  122. csi_camera_property_s *property;
  123. } csi_camera_properties_s;
  124. typedef enum csi_camera_channel_id {
  125. CSI_CAMERA_CHANNEL_0 = 0,
  126. CSI_CAMERA_CHANNEL_1,
  127. CSI_CAMERA_CHANNEL_2,
  128. CSI_CAMERA_CHANNEL_3,
  129. CSI_CAMERA_CHANNEL_4,
  130. CSI_CAMERA_CHANNEL_5,
  131. CSI_CAMERA_CHANNEL_6,
  132. CSI_CAMERA_CHANNEL_7,
  133. CSI_CAMERA_CHANNEL_MAX_COUNT
  134. } csi_camera_channel_id_e;
  135. typedef enum csi_camera_channel_status {
  136. CSI_CAMERA_CHANNEL_INVALID = -1, /* channel can't be openned */
  137. CSI_CAMERA_CHANNEL_CLOSED,
  138. CSI_CAMERA_CHANNEL_OPENED,
  139. CSI_CAMERA_CHANNEL_RUNNING,
  140. CSI_CAMERA_CHANNEL_EXCEPTION,
  141. } csi_camera_channel_status_e;
  142. typedef enum csi_camera_channel_capture_type {
  143. CSI_CAMERA_CHANNEL_CAPTURE_VIDEO = (1 << 0),
  144. CSI_CAMERA_CHANNEL_CAPTURE_META = (1 << 1),
  145. } csi_camera_channel_capture_type_e;
  146. typedef struct csi_camera_channel_cfg {
  147. csi_camera_channel_id_e chn_id;
  148. unsigned int capture_type; /* bitmask of: csi_camera_channel_capture_type_e */
  149. unsigned int frm_cnt;
  150. csi_img_format_t img_fmt;
  151. csi_img_type_e img_type;
  152. unsigned int meta_fields; /* bitmask of: csi_camera_meta_id_e */
  153. csi_camera_channel_status_e status;
  154. } csi_camera_channel_cfg_s;
  155. typedef enum csi_camera_event_type {
  156. CSI_CAMERA_EVENT_TYPE_INVALID = -1,
  157. CSI_CAMERA_EVENT_TYPE_CAMERA,
  158. CSI_CAMERA_EVENT_TYPE_CHANNEL0,
  159. CSI_CAMERA_EVENT_TYPE_CHANNEL1,
  160. CSI_CAMERA_EVENT_TYPE_CHANNEL2,
  161. CSI_CAMERA_EVENT_TYPE_CHANNEL3,
  162. CSI_CAMERA_EVENT_TYPE_CHANNEL4,
  163. CSI_CAMERA_EVENT_TYPE_CHANNEL5,
  164. CSI_CAMERA_EVENT_TYPE_CHANNEL6,
  165. CSI_CAMERA_EVENT_TYPE_CHANNEL7,
  166. } csi_camera_event_type_e;
  167. typedef enum csi_camera_event_id {
  168. CSI_CAMERA_EVENT_WARNING = 1 << 0,
  169. CSI_CAMERA_EVENT_ERROR = 1 << 1,
  170. CSI_CAMERA_EVENT_SENSOR_FIRST_IMAGE_ARRIVE = 1 << 2,
  171. CSI_CAMERA_EVENT_ISP_3A_ADJUST_READY = 1 << 3,
  172. CSI_CAMERA_EVENT_MAX_COUNT = 32
  173. } csi_camera_event_id_e;
  174. typedef enum csi_camera_channel_event_id {
  175. CSI_CAMERA_CHANNEL_EVENT_FRAME_READY = 1 << 0,
  176. CSI_CAMERA_CHANNEL_EVENT_FRAME_PUT = 1 << 1,
  177. CSI_CAMERA_CHANNEL_EVENT_OVERFLOW = 1 << 2,
  178. CSI_CAMERA_CHANNEL_EVENT_MAX_COUNT = 32
  179. } csi_camera_channel_event_id_e;
  180. typedef struct csi_camera_event_subscription {
  181. csi_camera_event_type_e type;
  182. unsigned int id; /* bitmasks */
  183. } csi_camera_event_subscription_s;
  184. typedef struct csi_camera_event {
  185. csi_camera_event_type_e type;
  186. unsigned int id;
  187. struct timespec timestamp;
  188. union {
  189. char bin[128];
  190. };
  191. } csi_camera_event_s;
  192. int csi_camera_get_version(csi_api_version_u *version);
  193. int csi_camera_query_list(csi_camera_infos_s *infos);
  194. int csi_camera_open(csi_cam_handle_t *cam_handle, const char *device_name);
  195. int csi_camera_close(csi_cam_handle_t cam_handle);
  196. int csi_camera_get_modes(csi_cam_handle_t cam_handle,
  197. csi_camera_modes_s *modes);
  198. int csi_camera_set_mode(csi_cam_handle_t cam_handle,
  199. csi_camera_mode_cfg_s *cfg);
  200. int csi_camera_get_io_pattern(csi_cam_handle_t cam_handle, int *pattern);
  201. int csi_camera_get_frame_config(csi_cam_handle_t cam_handle, csi_img_format_t *img_fmt, csi_frame_config_s *frm_cfg);
  202. int csi_camera_set_frame_config(csi_cam_handle_t cam_handle, csi_img_format_t *img_fmt, csi_frame_config_s *frm_cfg);
  203. int csi_sensor_enable_colobar(csi_cam_handle_t cam_handle, int en);
  204. int csi_camera_query_property(csi_cam_handle_t cam_handle,
  205. csi_camera_property_description_s *desc);
  206. int csi_camera_get_property(csi_cam_handle_t cam_handle,
  207. csi_camera_properties_s *properties);
  208. int csi_camera_set_property(csi_cam_handle_t cam_handle,
  209. csi_camera_properties_s *properties);
  210. int csi_camera_channel_open(csi_cam_handle_t cam_handle,
  211. csi_camera_channel_cfg_s *cfg);
  212. int csi_camera_channel_close(csi_cam_handle_t cam_handle,
  213. csi_camera_channel_id_e chn_id);
  214. int csi_camera_channel_query(csi_cam_handle_t cam_handle,
  215. csi_camera_channel_cfg_s *cfg);
  216. int csi_camera_get_frame_count(csi_cam_handle_t cam_handle,
  217. csi_camera_channel_id_e chn_id);
  218. int csi_camera_get_frame(csi_cam_handle_t cam_handle,
  219. csi_camera_channel_id_e chn_id,
  220. csi_frame_s *frame, int timeout);
  221. int csi_camera_put_frame(csi_frame_s *frame);
  222. int csi_camera_dequeue_frame(csi_cam_handle_t cam_handle,
  223. csi_camera_channel_id_e chn_id,
  224. csi_frame_ex_s **frame,
  225. int timeout);
  226. int csi_camera_enqueue_frame(csi_cam_handle_t cam_handle,
  227. csi_camera_channel_id_e chn_id,
  228. csi_frame_ex_s *frame);
  229. int csi_camera_create_event(csi_cam_event_handle_t *event_handle,
  230. csi_cam_handle_t cam_handle);
  231. int csi_camera_destory_event(csi_cam_event_handle_t event_handle);
  232. int csi_camera_subscribe_event(csi_cam_event_handle_t event_handle,
  233. csi_camera_event_subscription_s *subscribe);
  234. int csi_camera_unsubscribe_event(csi_cam_event_handle_t event_handle,
  235. csi_camera_event_subscription_s *subscribe);
  236. int csi_camera_get_event(csi_cam_event_handle_t event_handle,
  237. csi_camera_event_s *event,
  238. int timeout);
  239. int csi_camera_channel_start(csi_cam_handle_t cam_handle,
  240. csi_camera_channel_id_e chn_id);
  241. int csi_camera_channel_stop(csi_cam_handle_t cam_handle,
  242. csi_camera_channel_id_e chn_id);
  243. #ifdef __cplusplus
  244. }
  245. #endif
  246. #endif /* __CSI_CAMERA_H__ */