csi_venc.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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_VENC_H__
  10. #define __CSI_VENC_H__
  11. #include <unistd.h>
  12. #include <stdint.h>
  13. #include <stdbool.h>
  14. #include <csi_common.h>
  15. #include <csi_allocator.h>
  16. #include <csi_vcodec_common.h>
  17. #include <csi_venc_h264.h>
  18. #include <csi_venc_h265.h>
  19. #include <csi_venc_mjpeg.h>
  20. #include <csi_venc_property.h>
  21. #include <csi_frame.h>
  22. #include <csi_frame_ex.h>
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #define CSI_VENC_VERSION_MAJOR 0
  27. #define CSI_VENC_VERSION_MINOR 3
  28. typedef void *csi_venc_dev_t;
  29. typedef void *csi_venc_chn_t;
  30. typedef void *csi_venc_event_handle_t;
  31. #define CSI_VENC_NAME_MAX_LEN 32
  32. typedef struct csi_venc_info {
  33. char module_name[CSI_VENC_NAME_MAX_LEN];
  34. char device_name[CSI_VENC_NAME_MAX_LEN];
  35. uint64_t capabilities; /* bitmask of 1<<(csi_vcodec_id_e) */
  36. } csi_venc_info_s;
  37. #define CSI_VENC_MAX_COUNT 2
  38. typedef struct csi_venc_infos {
  39. uint32_t count;
  40. csi_venc_info_s info[CSI_VENC_MAX_COUNT];
  41. } csi_venc_infos_s;
  42. typedef struct csi_venc_chn_cfg {
  43. csi_venc_attr_s attr;
  44. csi_venc_gop_property_s gop;
  45. csi_venc_rc_property_s rc;
  46. } csi_venc_chn_cfg_s;
  47. typedef enum csi_venc_event_type {
  48. CSI_VENC_EVENT_TYPE_DECODER,
  49. CSI_VENC_EVENT_TYPE_CHANNEL,
  50. } csi_venc_event_type_e;
  51. /* the attribute of the roi */
  52. typedef struct csi_venc_chn_roi_prop {
  53. uint32_t index; /* Range:[0, 7]; Index of an ROI. The system supports indexes ranging from 0 to 7 */
  54. bool enable; /* Range:[0, 1]; Whether to enable this ROI */
  55. bool abs_qp; /* Range:[0, 1]; QP mode of an ROI.HI_FALSE: relative QP.HI_TURE: absolute QP.*/
  56. int32_t qp; /* Range:[-51, 51]; QP value,only relative mode can QP value less than 0. */
  57. csi_rect_s rect; /* Region of an ROI*/
  58. } csi_venc_chn_roi_prop_s;
  59. typedef enum csi_venc_ext_property_id {
  60. CSI_VENC_EXT_PROPERTY_ROI,
  61. } csi_venc_ext_property_id_e;
  62. typedef struct csi_venc_chn_ext_property {
  63. csi_venc_ext_property_id_e prop_id;
  64. union {
  65. csi_venc_chn_roi_prop_s roi_prop; // CSI_VENC_EXT_PROPERTY_ROI
  66. };
  67. } csi_venc_chn_ext_property_s;
  68. typedef enum csi_venc_event_id {
  69. CSI_VENC_EVENT_ID_ERROR = 1 << 0,
  70. } csi_venc_event_id_e;
  71. typedef enum csi_venc_chn_event_id {
  72. CSI_VENC_CHANNEL_EVENT_ID_ERROR = 1 << 0,
  73. CSI_VENC_CHANNEL_EVENT_ID_FRAME_READY = 1 << 1,
  74. } csi_venc_chn_event_id_e;
  75. typedef struct csi_venc_event_subscription {
  76. csi_venc_event_type_e type;
  77. unsigned int id; /* bitmasks */
  78. } csi_venc_event_subscription_s;
  79. typedef struct csi_venc_event {
  80. csi_venc_event_type_e type;
  81. unsigned int id;
  82. struct timespec timestamp;
  83. union {
  84. char bin[128];
  85. };
  86. } csi_venc_event_s;
  87. typedef union csi_venc_data_type {
  88. csi_venc_h264_nalu_e h264_type;
  89. csi_venc_h265_nalu_e h265_type;
  90. csi_venc_jpeg_pack_e jpeg_type;
  91. } csi_venc_data_type_u;
  92. typedef struct csi_stream {
  93. size_t size;
  94. union {
  95. int buf_fd; // stores in dma_buf memory
  96. void *phy_addr; // stores in phy contigous memory
  97. void *usr_addr; // stores in usr contigous memory
  98. };
  99. uint64_t pts;
  100. bool frame_end;
  101. csi_venc_data_type_u data_type;
  102. uint32_t data_num;
  103. } csi_stream_s;
  104. typedef enum csi_venc_prop_type {
  105. CSI_VENC_FRAME_PROP_NONE = 0,
  106. CSI_VENC_FRAME_PROP_FORCE_IDR, // Instantaneous Decoding Refresh
  107. CSI_VENC_FRAME_PROP_FORCE_SKIP,
  108. } csi_venc_prop_type_e;
  109. typedef struct csi_venc_prop {
  110. csi_venc_prop_type_e type;
  111. union {
  112. bool force_idr; // CSI_VENC_FRAME_PROP_FORCE_IDR
  113. bool force_skip; // CSI_VENC_FRAME_PROP_FORCE_SKIP
  114. };
  115. } csi_venc_frame_prop_s;
  116. /* the status of the venc chnl*/
  117. typedef struct csi_venc_chn_status {
  118. uint32_t left_pics; /* R; left picture number */
  119. uint32_t left_stream_bytes; /* R; left stream bytes*/
  120. uint32_t left_stream_frames; /* R; left stream frames*/
  121. uint32_t cur_packs; /* R; pack number of current frame*/
  122. uint32_t left_recv_pics; /* R; Number of frames to be received. This member is valid after HI_MPI_VENC_StartRecvPicEx is called.*/
  123. uint32_t left_enc_pics; /* R; Number of frames to be encoded. This member is valid after HI_MPI_VENC_StartRecvPicEx is called.*/
  124. bool jpeg_snap_end; /* R; the end of Snap.*/
  125. } csi_venc_chn_status_s;
  126. int csi_venc_get_version(csi_api_version_u *version);
  127. int csi_venc_query_list(csi_venc_infos_s *infos);
  128. int csi_venc_open(csi_venc_dev_t *enc, const char *device_name);
  129. int csi_venc_close(csi_venc_dev_t enc);
  130. int csi_venc_get_io_pattern(csi_venc_dev_t enc, int *pattern);
  131. int csi_venc_get_frame_config(csi_venc_dev_t enc, csi_img_format_t *img_fmt, csi_frame_config_s *frm_cfg);
  132. int csi_venc_set_frame_config(csi_venc_dev_t enc, csi_img_format_t *img_fmt, csi_frame_config_s *frm_cfg);
  133. int csi_venc_create_channel(csi_venc_chn_t *chn, csi_venc_dev_t enc, csi_venc_chn_cfg_s *cfg);
  134. int csi_venc_destory_channel(csi_venc_chn_t chn);
  135. //int csi_venc_set_memory_allocator(csi_venc_chn_t chn, csi_allocator_s *allocator);
  136. int csi_venc_set_ext_property(csi_venc_chn_t chn, csi_venc_chn_ext_property_s *prop);
  137. int csi_venc_get_ext_property(csi_venc_chn_t chn, csi_venc_chn_ext_property_s *prop);
  138. int csi_venc_start(csi_venc_chn_t chn);
  139. int csi_venc_stop(csi_venc_chn_t chn);
  140. int csi_venc_reset(csi_venc_chn_t chn);
  141. int csi_venc_send_frame(csi_venc_chn_t chn, csi_frame_s *frame, int timeout);
  142. int csi_venc_send_frame_ex(csi_venc_chn_t chn, csi_frame_s *frame, int timeout,
  143. csi_venc_frame_prop_s *prop, int prop_count);
  144. int csi_venc_enqueue_frame(csi_venc_chn_t chn, csi_frame_ex_s *frame);
  145. int csi_venc_enqueue_frame_ex(csi_venc_chn_t chn, csi_frame_ex_s *frame,
  146. csi_venc_frame_prop_s *prop, int prop_count);
  147. int csi_venc_dequeue_frame(csi_venc_chn_t chn, csi_frame_ex_s **frame, int timeout);
  148. int csi_venc_get_stream(csi_venc_chn_t chn, csi_stream_s *stream, int timeout);// Release by stream.release()
  149. int csi_venc_query_status(csi_venc_chn_t chn, csi_venc_chn_status_s *status);
  150. int csi_venc_create_event_handle(csi_venc_event_handle_t *chn, csi_venc_dev_t event_handle);
  151. int csi_venc_destory_event(csi_venc_event_handle_t event_handle);
  152. int csi_venc_subscribe_event(csi_venc_event_handle_t event_handle,
  153. csi_venc_event_subscription_s *subscribe);
  154. int csi_venc_unsubscribe_event(csi_venc_event_handle_t event_handle,
  155. csi_venc_event_subscription_s *subscribe);
  156. int csi_venc_get_event(csi_venc_event_handle_t event_handle,
  157. csi_venc_event_s *event, int timeout);
  158. #ifdef __cplusplus
  159. }
  160. #endif
  161. #endif /* __CSI_ENC_H__ */