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