venc_drv_if.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (c) 2016 MediaTek Inc.
  3. * Author: Daniel Hsiao <daniel.hsiao@mediatek.com>
  4. * Jungchang Tsao <jungchang.tsao@mediatek.com>
  5. * Tiffany Lin <tiffany.lin@mediatek.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #ifndef _VENC_DRV_IF_H_
  18. #define _VENC_DRV_IF_H_
  19. #include "mtk_vcodec_drv.h"
  20. #include "mtk_vcodec_util.h"
  21. /*
  22. * enum venc_yuv_fmt - The type of input yuv format
  23. * (VPU related: If you change the order, you must also update the VPU codes.)
  24. * @VENC_YUV_FORMAT_I420: I420 YUV format
  25. * @VENC_YUV_FORMAT_YV12: YV12 YUV format
  26. * @VENC_YUV_FORMAT_NV12: NV12 YUV format
  27. * @VENC_YUV_FORMAT_NV21: NV21 YUV format
  28. */
  29. enum venc_yuv_fmt {
  30. VENC_YUV_FORMAT_I420 = 3,
  31. VENC_YUV_FORMAT_YV12 = 5,
  32. VENC_YUV_FORMAT_NV12 = 6,
  33. VENC_YUV_FORMAT_NV21 = 7,
  34. };
  35. /*
  36. * enum venc_start_opt - encode frame option used in venc_if_encode()
  37. * @VENC_START_OPT_ENCODE_SEQUENCE_HEADER: encode SPS/PPS for H264
  38. * @VENC_START_OPT_ENCODE_FRAME: encode normal frame
  39. */
  40. enum venc_start_opt {
  41. VENC_START_OPT_ENCODE_SEQUENCE_HEADER,
  42. VENC_START_OPT_ENCODE_FRAME,
  43. };
  44. /*
  45. * enum venc_set_param_type - The type of set parameter used in
  46. * venc_if_set_param()
  47. * (VPU related: If you change the order, you must also update the VPU codes.)
  48. * @VENC_SET_PARAM_ENC: set encoder parameters
  49. * @VENC_SET_PARAM_FORCE_INTRA: force an intra frame
  50. * @VENC_SET_PARAM_ADJUST_BITRATE: adjust bitrate (in bps)
  51. * @VENC_SET_PARAM_ADJUST_FRAMERATE: set frame rate
  52. * @VENC_SET_PARAM_GOP_SIZE: set IDR interval
  53. * @VENC_SET_PARAM_INTRA_PERIOD: set I frame interval
  54. * @VENC_SET_PARAM_SKIP_FRAME: set H264 skip one frame
  55. * @VENC_SET_PARAM_PREPEND_HEADER: set H264 prepend SPS/PPS before IDR
  56. * @VENC_SET_PARAM_TS_MODE: set VP8 temporal scalability mode
  57. */
  58. enum venc_set_param_type {
  59. VENC_SET_PARAM_ENC,
  60. VENC_SET_PARAM_FORCE_INTRA,
  61. VENC_SET_PARAM_ADJUST_BITRATE,
  62. VENC_SET_PARAM_ADJUST_FRAMERATE,
  63. VENC_SET_PARAM_GOP_SIZE,
  64. VENC_SET_PARAM_INTRA_PERIOD,
  65. VENC_SET_PARAM_SKIP_FRAME,
  66. VENC_SET_PARAM_PREPEND_HEADER,
  67. VENC_SET_PARAM_TS_MODE,
  68. };
  69. /*
  70. * struct venc_enc_prm - encoder settings for VENC_SET_PARAM_ENC used in
  71. * venc_if_set_param()
  72. * @input_fourcc: input yuv format
  73. * @h264_profile: V4L2 defined H.264 profile
  74. * @h264_level: V4L2 defined H.264 level
  75. * @width: image width
  76. * @height: image height
  77. * @buf_width: buffer width
  78. * @buf_height: buffer height
  79. * @frm_rate: frame rate in fps
  80. * @intra_period: intra frame period
  81. * @bitrate: target bitrate in bps
  82. * @gop_size: group of picture size
  83. */
  84. struct venc_enc_param {
  85. enum venc_yuv_fmt input_yuv_fmt;
  86. unsigned int h264_profile;
  87. unsigned int h264_level;
  88. unsigned int width;
  89. unsigned int height;
  90. unsigned int buf_width;
  91. unsigned int buf_height;
  92. unsigned int frm_rate;
  93. unsigned int intra_period;
  94. unsigned int bitrate;
  95. unsigned int gop_size;
  96. };
  97. /*
  98. * struct venc_frm_buf - frame buffer information used in venc_if_encode()
  99. * @fb_addr: plane frame buffer addresses
  100. */
  101. struct venc_frm_buf {
  102. struct mtk_vcodec_mem fb_addr[MTK_VCODEC_MAX_PLANES];
  103. };
  104. /*
  105. * struct venc_done_result - This is return information used in venc_if_encode()
  106. * @bs_size: output bitstream size
  107. * @is_key_frm: output is key frame or not
  108. */
  109. struct venc_done_result {
  110. unsigned int bs_size;
  111. bool is_key_frm;
  112. };
  113. /*
  114. * venc_if_init - Create the driver handle
  115. * @ctx: device context
  116. * @fourcc: encoder input format
  117. * Return: 0 if creating handle successfully, otherwise it is failed.
  118. */
  119. int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc);
  120. /*
  121. * venc_if_deinit - Release the driver handle
  122. * @ctx: device context
  123. * Return: 0 if releasing handle successfully, otherwise it is failed.
  124. */
  125. int venc_if_deinit(struct mtk_vcodec_ctx *ctx);
  126. /*
  127. * venc_if_set_param - Set parameter to driver
  128. * @ctx: device context
  129. * @type: parameter type
  130. * @in: input parameter
  131. * Return: 0 if setting param successfully, otherwise it is failed.
  132. */
  133. int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
  134. enum venc_set_param_type type,
  135. struct venc_enc_param *in);
  136. /*
  137. * venc_if_encode - Encode one frame
  138. * @ctx: device context
  139. * @opt: encode frame option
  140. * @frm_buf: input frame buffer information
  141. * @bs_buf: output bitstream buffer infomraiton
  142. * @result: encode result
  143. * Return: 0 if encoding frame successfully, otherwise it is failed.
  144. */
  145. int venc_if_encode(struct mtk_vcodec_ctx *ctx,
  146. enum venc_start_opt opt,
  147. struct venc_frm_buf *frm_buf,
  148. struct mtk_vcodec_mem *bs_buf,
  149. struct venc_done_result *result);
  150. #endif /* _VENC_DRV_IF_H_ */