csi_frame.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_FRAME_H__
  10. #define __CSI_FRAME_H__
  11. #include <stddef.h>
  12. #include <stdint.h>
  13. #include <unistd.h>
  14. #include <sys/types.h>
  15. /*
  16. * CSI frame defination is below, including
  17. *
  18. * @-- [frm_id] ----------------@
  19. * | __________ ___________ |
  20. * | | | | | |
  21. * | | img_info | | meta_info | |
  22. * | |__________| |___________| |
  23. * | |
  24. * @------- csi_frame_s --------@
  25. */
  26. #define CSI_IMAGE_MAX_PLANES 3
  27. #define CSI_IMAGE_I420_PLANES 2
  28. typedef enum csi_pixel_fmt {
  29. CSI_PIX_FMT_I420, // YYYYYYYY UU VV, alias: YUV420P/YU12/IYUV
  30. CSI_PIX_FMT_NV12, // YYYYYYYY UV UV, alias: YUV420SP
  31. CSI_PIX_FMT_BGR,
  32. CSI_PIX_FMT_RAW_8BIT,/*default no align*/
  33. CSI_PIX_FMT_RAW_10BIT,
  34. CSI_PIX_FMT_RAW_12BIT,
  35. CSI_PIX_FMT_RAW_14BIT,
  36. CSI_PIX_FMT_RAW_16BIT,
  37. CSI_PIX_FMT_RGB_PLANAR_888,
  38. CSI_PIX_FMT_RGB_INTEVLEAVED_888,
  39. CSI_PIX_FMT_YUV_PLANAR_422,
  40. CSI_PIX_FMT_YUV_PLANAR_420,
  41. CSI_PIX_FMT_YUV_PLANAR_444,
  42. CSI_PIX_FMT_YUV_SEMIPLANAR_422,
  43. CSI_PIX_FMT_YUV_SEMIPLANAR_420,
  44. CSI_PIX_FMT_YUV_SEMIPLANAR_444,
  45. CSI_PIX_FMT_YUV_TEVLEAVED_422,
  46. CSI_PIX_FMT_YUV_TEVLEAVED_420,
  47. CSI_PIX_FMT_YUV_TEVLEAVED_444,
  48. } csi_pixel_fmt_e;
  49. typedef enum csi_color_gamut {
  50. CSI_COLOR_GAMUT_DEFAULT = 0,
  51. CSI_COLOR_GAMUT_BT601,
  52. CSI_COLOR_GAMUT_BT709,
  53. CSI_COLOR_GAMUT_BT2020,
  54. } csi_color_gamut_e;
  55. typedef enum csi_meta_type {
  56. CSI_META_TYPE_SYSTEM,
  57. CSI_META_TYPE_CAMERA,
  58. CSI_META_TYPE_VDEC,
  59. CSI_META_TYPE_GPU,
  60. CSI_META_TYPE_G2D,
  61. } csi_meta_type_e;
  62. typedef enum csi_img_type {
  63. CSI_IMG_TYPE_DMA_BUF, // memory allocated via dma-buf
  64. CSI_IMG_TYPE_SYSTEM_CONTIG, // memory allocated via kmalloc
  65. CSI_IMG_TYPE_CARVEOUT, // memory allocated from reserved memory
  66. CSI_IMG_TYPE_UMALLOC, // memory allocated from user mode malloc
  67. CSI_IMG_TYPE_SHM, // memory allocated from share memory(<sys/shm.h>)
  68. } csi_img_type_e;
  69. typedef enum csi_meta_value_type {
  70. CSI_META_VALUE_TYPE_BOOL,
  71. CSI_META_VALUE_TYPE_INT,
  72. CSI_META_VALUE_TYPE_UINT,
  73. CSI_META_VALUE_TYPE_STR,
  74. CSI_META_VALUE_TYPE_TIMEVAL,
  75. } csi_meta_value_type_e;
  76. /*
  77. * CSI frame config design
  78. *
  79. * line_stride -->|
  80. * img_width -->| |
  81. * _____________|___| __ start addr of frame/image, alignment (such as 4096)
  82. * | | |
  83. * | img_content | |
  84. * |_____________|___| __ end addr of image, No alignment requirement
  85. * | extra_data |
  86. * |_________________| __ end addr of frame, No alignment requirement
  87. */
  88. typedef struct csi_img_format {
  89. uint32_t width;
  90. uint32_t height;
  91. csi_pixel_fmt_e pix_fmt;
  92. } csi_img_format_t;
  93. typedef struct {
  94. int32_t stride_alignment; // should >= to the width of the image according to IP design
  95. int32_t addr_alignment; // physical begin address alignment according to IP design
  96. int32_t extra_size; // storaging platform private data according to IP design (meta data storage is suggested)
  97. int32_t min_buffers_count; // minimum number of buffers required
  98. } csi_frame_config_s; // New defined structure
  99. typedef struct {
  100. int fds; // stores in dma_buf memory(s)
  101. unsigned long offset;
  102. } cam_frame_dmabuf_t;
  103. typedef struct csi_img {
  104. csi_img_type_e type;
  105. size_t size;
  106. uint32_t width;
  107. uint32_t height;
  108. csi_pixel_fmt_e pix_format;
  109. csi_color_gamut_e color_gamut;
  110. uint32_t num_planes;
  111. union {
  112. cam_frame_dmabuf_t dmabuf[CSI_IMAGE_MAX_PLANES]; // stores in dma_buf memory(s)
  113. int fds[CSI_IMAGE_MAX_PLANES]; // stores in dma_buf memory(s)
  114. void *phy_addr[CSI_IMAGE_MAX_PLANES]; // stores in phy contigous memory(s)
  115. void *usr_addr[CSI_IMAGE_MAX_PLANES]; // stores in usr contigous memory(s)
  116. };
  117. uint32_t strides[CSI_IMAGE_MAX_PLANES];
  118. uint32_t offsets[CSI_IMAGE_MAX_PLANES];
  119. uint64_t modifier;
  120. void *priv;
  121. } csi_img_s;
  122. typedef struct csi_meta {
  123. csi_meta_type_e type;
  124. size_t size;
  125. void *data;
  126. } csi_meta_s;
  127. typedef struct csi_frame {
  128. csi_img_s img;
  129. csi_meta_s meta;
  130. } csi_frame_s;
  131. int csi_frame_reference(csi_frame_s *frame_dest, csi_frame_s *frame_src);
  132. int csi_frame_release(csi_frame_s *frame);
  133. void *csi_frame_mmap(csi_frame_s *frame);
  134. int csi_frame_munmap(csi_frame_s *frame);
  135. #endif /* __CSI_FRAME_H__ */