csi_frame.h 4.0 KB

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