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