csi_vdec.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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_VDEC_H__
  10. #define __CSI_VDEC_H__
  11. #include <unistd.h>
  12. #include <stdint.h>
  13. #include <stdbool.h>
  14. #include "csi_common.h"
  15. #include "csi_vcodec_common.h"
  16. #include "csi_allocator.h"
  17. #include "csi_frame.h"
  18. #include "csi_frame_ex.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define CSI_VDEC_VERSION_MAJOR 0
  23. #define CSI_VDEC_VERSION_MINOR 2
  24. typedef void *csi_vdec_dev_t;
  25. typedef void *csi_vdec_chn_t;
  26. typedef void *csi_vdec_event_handle_t;
  27. typedef enum csi_vdec_status {
  28. CSI_VDEC_STATUS_OK = 0,
  29. CSI_VDEC_STATUS_MORE_FRAME_BUFFER = 1,
  30. CSI_VDEC_STATUS_MORE_BITSTREAM = 2,
  31. CSI_VDEC_STATUS_HAS_INFO = 3,
  32. CSI_VDEC_STATUS_PIC_DECODED = 4,
  33. CSI_VDEC_STATUS_NO_FRAME_BUFFER = 5,
  34. CSI_VDEC_STATUS_EOS = 6,
  35. CSI_VDEC_STATUS_TIMEOUT = 7,
  36. CSI_VDEC_STATUS_SKIPPED = 8,
  37. CSI_VDEC_STATUS_PIC_OUTPUT = 9,
  38. CSI_VDEC_STATUS_FLUSHED = 10,
  39. /* error codes < 0 */
  40. CSI_VDEC_ERR_UNKOWN = -1,
  41. CSI_VDEC_ERR_UNSUPPORTED = -2,
  42. CSI_VDEC_ERR_INSUFFICIENT_RESOURCES = -3,
  43. CSI_VDEC_ERR_WRONG_PARAM = -4,
  44. CSI_VDEC_ERR_BAD_STREAM = -5,
  45. CSI_VDEC_ERR_NOT_INTIALIZED = -6,
  46. CSI_VDEC_ERR_MEMORY = -7,
  47. /* add more ... */
  48. /* warnings > 0 */
  49. CSI_VDEC_WRN_DEVICE_BUSY = 256,
  50. CSI_VDEC_WRN_INCOMPATIBLE_PARAM = 257,
  51. CSI_VDEC_WRN_NOT_IMPLEMENTED = 258,
  52. /* add more ... */
  53. } csi_vdec_status_e;
  54. typedef enum csi_vdec_event_type {
  55. CSI_VDEC_EVENT_TYPE_DECODER,
  56. CSI_VDEC_EVENT_TYPE_CHANNEL,
  57. } csi_vdec_event_type_e;
  58. typedef enum csi_vdec_event_id {
  59. CSI_VDEC_EVENT_ID_ERROR = 1 << 0,
  60. } csi_vdec_event_id_e;
  61. typedef enum csi_vdec_channel_event_id {
  62. CSI_VDEC_CHANNEL_EVENT_ID_ERROR = 1 << 0,
  63. CSI_VDEC_CHANNEL_EVENT_ID_FRAME_READY = 1 << 1,
  64. } csi_vdec_channel_event_id_e;
  65. typedef enum csi_framebuf_source {
  66. CSI_FB_SOURCE_DMABUF,
  67. CSI_FB_SOURCE_CARVEOUT,
  68. } csi_framebuf_source_e;
  69. typedef enum csi_vdec_input_mode {
  70. CSI_VDEC_INPUT_MODE_STREAM,
  71. CSI_VDEC_INPUT_MODE_FRAME,
  72. } csi_vdec_input_mode_e;
  73. typedef enum csi_vdec_img_type {
  74. CSI_VDEC_MODE_I = CSI_VCODEC_I_FRAME,
  75. CSI_VDEC_MODE_IP = (CSI_VCODEC_I_FRAME | CSI_VCODEC_P_FRAME),
  76. CSI_VDEC_MODE_IPB = (CSI_VCODEC_I_FRAME | CSI_VCODEC_P_FRAME | CSI_VCODEC_B_FRAME),
  77. } csi_vdec_img_type_e;
  78. typedef enum csi_vdec_output_order {
  79. CSI_VDEC_OUTPUT_ORDER_DISP = 0,
  80. CSI_VDEC_OUTPUT_ORDER_DEC,
  81. } csi_vdec_output_order_e;
  82. typedef enum csi_vdec_pp_rotate {
  83. CSI_VDEC_PP_ROTATE_0,
  84. CSI_VDEC_PP_ROTATE_90,
  85. CSI_VDEC_PP_ROTATE_180,
  86. CSI_VDEC_PP_ROTATE_270
  87. } csi_vdec_pp_rotate_t;
  88. #define CSI_VDEC_NAME_MAX_LEN 32
  89. typedef struct csi_vdec_info {
  90. char module_name[CSI_VDEC_NAME_MAX_LEN];
  91. char device_name[CSI_VDEC_NAME_MAX_LEN];
  92. uint64_t capabilities; /* bitmask of 1<<(csi_vcodec_id_e) */
  93. } csi_vdec_info_t;
  94. #define CSI_VDEC_MAX_COUNT 2
  95. typedef struct csi_vdec_infos {
  96. uint32_t count;
  97. csi_vdec_info_t info[CSI_VDEC_MAX_COUNT];
  98. } csi_vdec_infos_s;
  99. typedef struct csi_vdec_stream {
  100. uint32_t length;
  101. uint64_t pts;
  102. bool eos;
  103. char *data;
  104. } csi_vdec_stream_s;
  105. typedef struct csi_vdec_mode {
  106. csi_framebuf_source_e fb_source;
  107. bool low_latency_mode;
  108. bool mini_buf_mode;
  109. } csi_vdec_mode_s;
  110. typedef struct csi_vdec_video_264 {
  111. } csi_vdec_video_264_s;
  112. typedef struct csi_vdec_video_265 {
  113. } csi_vdec_video_265_s;
  114. typedef struct csi_vdec_picture_jpeg {
  115. } csi_vdec_picture_jpeg_s;
  116. typedef struct csi_vdec_config {
  117. csi_vcodec_id_e dec_vcodec_id;
  118. uint32_t dec_frame_buf_cnt;
  119. uint32_t dec_frame_buf_size;
  120. union {
  121. csi_vdec_video_264_s video_264_param;
  122. csi_vdec_video_265_s video_265_param;
  123. csi_vdec_picture_jpeg_s picture_jpeg_param;
  124. };
  125. csi_vdec_input_mode_e input_mode;
  126. uint32_t input_stream_buf_size;
  127. csi_vdec_img_type_e output_img_type;
  128. csi_pixel_fmt_e output_format;
  129. uint32_t output_width;
  130. uint32_t output_height;
  131. csi_vdec_output_order_e output_order;
  132. } csi_vdec_config_s;
  133. typedef struct csi_vdec_pp_config {
  134. csi_vdec_pp_rotate_t rotate;
  135. bool h_flip;
  136. bool v_flip;
  137. csi_rect_s crop; /* width or height to be zero means no crop */
  138. } csi_vdec_pp_config_s;
  139. typedef struct csi_vdec_error_stats {
  140. int32_t format_err; /* R; format error. eg: do not support filed */
  141. int32_t pic_size_err_set; /* R; picture width or height is larger than chnnel width or height*/
  142. int32_t stream_unsupprt; /* R; unsupport the stream specification */
  143. int32_t pack_err; /* R; stream package error */
  144. int32_t prtcl_num_err_set; /* R; protocol num is not enough. eg: slice, pps, sps */
  145. int32_t ref_err_set; /* R; refrence num is not enough */
  146. int32_t pic_buf_size_err_set; /* R; the buffer size of picture is not enough */
  147. int32_t stream_size_over; /* R; the stream size is too big and and force discard stream */
  148. int32_t vdec_stream_not_release;/* R; the stream not released for too long time */
  149. } csi_vdec_error_stats_s;
  150. typedef struct csi_vdec_chn_status {
  151. csi_vcodec_id_e dec_vcodec_id; /* R; video type to be decoded */
  152. uint32_t left_stream_bytes; /* R; left stream bytes waiting for decode */
  153. uint32_t left_stream_frames; /* R; left frames waiting for decode,only valid for VIDEO_MODE_FRAME*/
  154. uint32_t left_pics; /* R; pics waiting for output */
  155. bool recv_stream_started; /* R; had started recv stream? */
  156. uint32_t recv_stream_frames; /* R; how many frames of stream has been received. valid when send by frame. */
  157. uint32_t decode_stream_frames; /* R; how many frames of stream has been decoded. valid when send by frame. */
  158. csi_vdec_error_stats_s stVdecDecErr; /* R; information about decode error */
  159. } csi_vdec_chn_status_s;
  160. typedef struct csi_vdec_event_subscription {
  161. csi_vdec_event_type_e type;
  162. unsigned int id; /* bitmasks */
  163. } csi_vdec_event_subscription_t;
  164. typedef struct csi_vdec_event {
  165. csi_vdec_event_type_e type;
  166. unsigned int id;
  167. struct timespec timestamp;
  168. union {
  169. char bin[128];
  170. };
  171. } csi_vdec_event_s;
  172. int csi_vdec_get_version(csi_api_version_u *version);
  173. int csi_vdec_query_list(csi_vdec_infos_s *infos);
  174. int csi_vdec_open(csi_vdec_dev_t *dec, const char *device_name);
  175. int csi_vdec_close(csi_vdec_dev_t dec);
  176. int csi_vdec_get_io_pattern(csi_vdec_dev_t dec, int *pattern);
  177. int csi_vdec_create_channel(csi_vdec_chn_t *chn, csi_vdec_dev_t dec, csi_vdec_config_s *cfg);
  178. int csi_vdec_destory_channel(csi_vdec_chn_t chn);
  179. int csi_vdec_get_frame_config(csi_vdec_chn_t chn, csi_img_format_t *img_fmt, csi_frame_config_s *frm_cfg);
  180. int csi_vdec_set_frame_config(csi_vdec_chn_t chn, csi_img_format_t *img_fmt, csi_frame_config_s *frm_cfg);
  181. //int csi_vdec_set_memory_allocator(csi_vdec_chn_t chn, csi_allocator_s *allocator);
  182. int csi_vdec_set_mode(csi_vdec_chn_t chn, csi_vdec_mode_s *mode);
  183. int csi_vdec_get_mode(csi_vdec_chn_t chn, csi_vdec_mode_s *mode);
  184. int csi_vdec_set_chn_config(csi_vdec_chn_t chn, csi_vdec_config_s *cfg);
  185. int csi_vdec_get_chn_config(csi_vdec_chn_t chn, csi_vdec_config_s *cfg);
  186. int csi_vdec_set_pp_config(csi_vdec_chn_t chn, csi_vdec_pp_config_s *cfg);
  187. int csi_vdec_get_pp_config(csi_vdec_chn_t chn, csi_vdec_pp_config_s *cfg);
  188. int csi_vdec_start(csi_vdec_chn_t chn);
  189. int csi_vdec_stop(csi_vdec_chn_t chn);
  190. int csi_vdec_reset(csi_vdec_chn_t chn);
  191. //int csi_vdec_get_frame_info(csi_vdec_chn_t chn, csi_vdec_frame_info *stream_info, csi_vdec_stream_s *stream);
  192. int csi_vdec_send_stream_buf(csi_vdec_chn_t chn, csi_vdec_stream_s *stream, int32_t timeout);
  193. int csi_vdec_register_frames(csi_vdec_chn_t chn, csi_frame_s *frame[], int count);
  194. int csi_vdec_put_frame(csi_vdec_chn_t chn, csi_frame_s *frame);
  195. int csi_vdec_get_frame(csi_vdec_chn_t chn, csi_frame_s **frame, int32_t timeout);// Release by frame.release()
  196. int csi_vdec_enqueue_frame(csi_vdec_chn_t chn, csi_frame_ex_s *frame);
  197. int csi_vdec_dequeue_frame(csi_vdec_chn_t chn, csi_frame_ex_s **frame, int32_t timeout);
  198. int csi_vdec_query_status(csi_vdec_chn_t chn, csi_vdec_chn_status_s *pstStatus);
  199. int csi_vdec_create_event_handle(csi_vdec_event_handle_t *chn, csi_vdec_dev_t event_handle);
  200. int csi_vdec_destory_event(csi_vdec_event_handle_t event_handle);
  201. int csi_vdec_subscribe_event(csi_vdec_event_handle_t event_handle,
  202. csi_vdec_event_subscription_t *subscribe);
  203. int csi_vdec_unsubscribe_event(csi_vdec_event_handle_t event_handle,
  204. csi_vdec_event_subscription_t *subscribe);
  205. int csi_vdec_get_event(csi_vdec_event_handle_t event_handle,
  206. csi_vdec_event_s *event, int timeout);
  207. #ifdef __cplusplus
  208. }
  209. #endif
  210. #endif /* __CSI_VDEC_H__ */