Commit | Line | Data |
---|---|---|
1802d0be | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
4e855a6e TL |
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> | |
4e855a6e TL |
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 { | |
8b8130f0 | 100 | struct mtk_vcodec_fb fb_addr[MTK_VCODEC_MAX_PLANES]; |
4e855a6e TL |
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 | /* | |
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 | /* | |
122 | * venc_if_deinit - Release the driver handle | |
123 | * @ctx: device context | |
124 | * Return: 0 if releasing handle successfully, otherwise it is failed. | |
125 | */ | |
126 | int venc_if_deinit(struct mtk_vcodec_ctx *ctx); | |
127 | ||
128 | /* | |
129 | * venc_if_set_param - Set parameter to driver | |
130 | * @ctx: device context | |
131 | * @type: parameter type | |
132 | * @in: input parameter | |
133 | * Return: 0 if setting param successfully, otherwise it is failed. | |
134 | */ | |
135 | int venc_if_set_param(struct mtk_vcodec_ctx *ctx, | |
136 | enum venc_set_param_type type, | |
137 | struct venc_enc_param *in); | |
138 | ||
139 | /* | |
140 | * venc_if_encode - Encode one frame | |
141 | * @ctx: device context | |
142 | * @opt: encode frame option | |
143 | * @frm_buf: input frame buffer information | |
144 | * @bs_buf: output bitstream buffer infomraiton | |
145 | * @result: encode result | |
146 | * Return: 0 if encoding frame successfully, otherwise it is failed. | |
147 | */ | |
148 | int venc_if_encode(struct mtk_vcodec_ctx *ctx, | |
149 | enum venc_start_opt opt, | |
150 | struct venc_frm_buf *frm_buf, | |
151 | struct mtk_vcodec_mem *bs_buf, | |
152 | struct venc_done_result *result); | |
153 | ||
154 | #endif /* _VENC_DRV_IF_H_ */ |