• 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_frame_info - per-frame information to pass to the firmware.
97  *
98  * @frm_count:		sequential number for this frame
99  * @skip_frm_count:	number of frames skipped so far while decoding
100  * @frm_type:		type of the frame, from enum venc_h264_frame_type
101  */
102 struct venc_frame_info {
103 	unsigned int frm_count;		/* per frame update */
104 	unsigned int skip_frm_count;	/* per frame update */
105 	unsigned int frm_type;		/* per frame update */
106 };
107 
108 /*
109  * struct venc_frm_buf - frame buffer information used in venc_if_encode()
110  * @fb_addr: plane frame buffer addresses
111  */
112 struct venc_frm_buf {
113 	struct mtk_vcodec_fb fb_addr[MTK_VCODEC_MAX_PLANES];
114 };
115 
116 /*
117  * struct venc_done_result - This is return information used in venc_if_encode()
118  * @bs_size: output bitstream size
119  * @is_key_frm: output is key frame or not
120  */
121 struct venc_done_result {
122 	unsigned int bs_size;
123 	bool is_key_frm;
124 };
125 
126 extern const struct venc_common_if venc_h264_if;
127 extern const struct venc_common_if venc_vp8_if;
128 
129 /*
130  * venc_if_init - Create the driver handle
131  * @ctx: device context
132  * @fourcc: encoder input format
133  * Return: 0 if creating handle successfully, otherwise it is failed.
134  */
135 int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc);
136 
137 /*
138  * venc_if_deinit - Release the driver handle
139  * @ctx: device context
140  * Return: 0 if releasing handle successfully, otherwise it is failed.
141  */
142 int venc_if_deinit(struct mtk_vcodec_ctx *ctx);
143 
144 /*
145  * venc_if_set_param - Set parameter to driver
146  * @ctx: device context
147  * @type: parameter type
148  * @in: input parameter
149  * Return: 0 if setting param successfully, otherwise it is failed.
150  */
151 int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
152 		      enum venc_set_param_type type,
153 		      struct venc_enc_param *in);
154 
155 /*
156  * venc_if_encode - Encode one frame
157  * @ctx: device context
158  * @opt: encode frame option
159  * @frm_buf: input frame buffer information
160  * @bs_buf: output bitstream buffer infomraiton
161  * @result: encode result
162  * Return: 0 if encoding frame successfully, otherwise it is failed.
163  */
164 int venc_if_encode(struct mtk_vcodec_ctx *ctx,
165 		   enum venc_start_opt opt,
166 		   struct venc_frm_buf *frm_buf,
167 		   struct mtk_vcodec_mem *bs_buf,
168 		   struct venc_done_result *result);
169 
170 #endif /* _VENC_DRV_IF_H_ */
171