xref: /linux/drivers/media/platform/qcom/venus/venc_ctrls.c (revision 02680c23d7b3febe45ea3d4f9818c2b2dc89020a)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
4  * Copyright (C) 2017 Linaro Ltd.
5  */
6 #include <linux/types.h>
7 #include <media/v4l2-ctrls.h>
8 
9 #include "core.h"
10 #include "venc.h"
11 
12 #define BITRATE_MIN		32000
13 #define BITRATE_MAX		160000000
14 #define BITRATE_DEFAULT		1000000
15 #define BITRATE_DEFAULT_PEAK	(BITRATE_DEFAULT * 2)
16 #define BITRATE_STEP		100
17 #define SLICE_BYTE_SIZE_MAX	1024
18 #define SLICE_BYTE_SIZE_MIN	1024
19 #define SLICE_MB_SIZE_MAX	300
20 #define INTRA_REFRESH_MBS_MAX	300
21 #define AT_SLICE_BOUNDARY	\
22 	V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY
23 #define MAX_LTR_FRAME_COUNT 4
24 
25 static int venc_calc_bpframes(u32 gop_size, u32 conseq_b, u32 *bf, u32 *pf)
26 {
27 	u32 half = (gop_size - 1) >> 1;
28 	u32 b, p, ratio;
29 	bool found = false;
30 
31 	if (!gop_size)
32 		return -EINVAL;
33 
34 	*bf = *pf = 0;
35 
36 	if (!conseq_b) {
37 		*pf = gop_size -  1;
38 		return 0;
39 	}
40 
41 	b = p = half;
42 
43 	for (; b <= gop_size - 1; b++, p--) {
44 		if (b % p)
45 			continue;
46 
47 		ratio = b / p;
48 
49 		if (ratio == conseq_b) {
50 			found = true;
51 			break;
52 		}
53 
54 		if (ratio > conseq_b)
55 			break;
56 	}
57 
58 	if (!found)
59 		return -EINVAL;
60 
61 	if (b + p + 1 != gop_size)
62 		return -EINVAL;
63 
64 	*bf = b;
65 	*pf = p;
66 
67 	return 0;
68 }
69 
70 static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl)
71 {
72 	struct venus_inst *inst = ctrl_to_inst(ctrl);
73 	struct venc_controls *ctr = &inst->controls.enc;
74 	struct hfi_enable en = { .enable = 1 };
75 	struct hfi_bitrate brate;
76 	struct hfi_ltr_use ltr_use;
77 	struct hfi_ltr_mark ltr_mark;
78 	u32 bframes;
79 	u32 ptype;
80 	int ret;
81 
82 	switch (ctrl->id) {
83 	case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
84 		ctr->bitrate_mode = ctrl->val;
85 		break;
86 	case V4L2_CID_MPEG_VIDEO_BITRATE:
87 		ctr->bitrate = ctrl->val;
88 		mutex_lock(&inst->lock);
89 		if (inst->streamon_out && inst->streamon_cap) {
90 			ptype = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE;
91 			brate.bitrate = ctr->bitrate;
92 			brate.layer_id = 0;
93 
94 			ret = hfi_session_set_property(inst, ptype, &brate);
95 			if (ret) {
96 				mutex_unlock(&inst->lock);
97 				return ret;
98 			}
99 		}
100 		mutex_unlock(&inst->lock);
101 		break;
102 	case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
103 		ctr->bitrate_peak = ctrl->val;
104 		break;
105 	case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
106 		ctr->h264_entropy_mode = ctrl->val;
107 		break;
108 	case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
109 		ctr->profile.mpeg4 = ctrl->val;
110 		break;
111 	case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
112 		ctr->profile.h264 = ctrl->val;
113 		break;
114 	case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE:
115 		ctr->profile.hevc = ctrl->val;
116 		break;
117 	case V4L2_CID_MPEG_VIDEO_VP8_PROFILE:
118 		ctr->profile.vp8 = ctrl->val;
119 		break;
120 	case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
121 		ctr->level.mpeg4 = ctrl->val;
122 		break;
123 	case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
124 		ctr->level.h264 = ctrl->val;
125 		break;
126 	case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL:
127 		ctr->level.hevc = ctrl->val;
128 		break;
129 	case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
130 		ctr->h264_i_qp = ctrl->val;
131 		break;
132 	case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
133 		ctr->h264_p_qp = ctrl->val;
134 		break;
135 	case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP:
136 		ctr->h264_b_qp = ctrl->val;
137 		break;
138 	case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
139 		ctr->h264_min_qp = ctrl->val;
140 		break;
141 	case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP:
142 		ctr->h264_i_min_qp = ctrl->val;
143 		break;
144 	case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP:
145 		ctr->h264_p_min_qp = ctrl->val;
146 		break;
147 	case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MIN_QP:
148 		ctr->h264_b_min_qp = ctrl->val;
149 		break;
150 	case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
151 		ctr->h264_max_qp = ctrl->val;
152 		break;
153 	case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP:
154 		ctr->h264_i_max_qp = ctrl->val;
155 		break;
156 	case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP:
157 		ctr->h264_p_max_qp = ctrl->val;
158 		break;
159 	case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MAX_QP:
160 		ctr->h264_b_max_qp = ctrl->val;
161 		break;
162 	case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP:
163 		ctr->hevc_i_qp = ctrl->val;
164 		break;
165 	case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP:
166 		ctr->hevc_p_qp = ctrl->val;
167 		break;
168 	case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP:
169 		ctr->hevc_b_qp = ctrl->val;
170 		break;
171 	case V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP:
172 		ctr->hevc_min_qp = ctrl->val;
173 		break;
174 	case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MIN_QP:
175 		ctr->hevc_i_min_qp = ctrl->val;
176 		break;
177 	case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MIN_QP:
178 		ctr->hevc_p_min_qp = ctrl->val;
179 		break;
180 	case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MIN_QP:
181 		ctr->hevc_b_min_qp = ctrl->val;
182 		break;
183 	case V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP:
184 		ctr->hevc_max_qp = ctrl->val;
185 		break;
186 	case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MAX_QP:
187 		ctr->hevc_i_max_qp = ctrl->val;
188 		break;
189 	case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MAX_QP:
190 		ctr->hevc_p_max_qp = ctrl->val;
191 		break;
192 	case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MAX_QP:
193 		ctr->hevc_b_max_qp = ctrl->val;
194 		break;
195 	case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
196 		ctr->multi_slice_mode = ctrl->val;
197 		break;
198 	case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
199 		ctr->multi_slice_max_bytes = ctrl->val;
200 		break;
201 	case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
202 		ctr->multi_slice_max_mb = ctrl->val;
203 		break;
204 	case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA:
205 		ctr->h264_loop_filter_alpha = ctrl->val;
206 		break;
207 	case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA:
208 		ctr->h264_loop_filter_beta = ctrl->val;
209 		break;
210 	case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
211 		ctr->h264_loop_filter_mode = ctrl->val;
212 		break;
213 	case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
214 		ctr->header_mode = ctrl->val;
215 		mutex_lock(&inst->lock);
216 		if (inst->streamon_out && inst->streamon_cap) {
217 			if (ctrl->val == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE)
218 				en.enable = 0;
219 			else
220 				en.enable = 1;
221 			ptype = HFI_PROPERTY_CONFIG_VENC_SYNC_FRAME_SEQUENCE_HEADER;
222 			ret = hfi_session_set_property(inst, ptype, &en);
223 			if (ret) {
224 				mutex_unlock(&inst->lock);
225 				return ret;
226 			}
227 		}
228 		mutex_unlock(&inst->lock);
229 		break;
230 	case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
231 		break;
232 	case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
233 		ret = venc_calc_bpframes(ctrl->val, ctr->num_b_frames, &bframes,
234 					 &ctr->num_p_frames);
235 		if (ret)
236 			return ret;
237 
238 		ctr->gop_size = ctrl->val;
239 		break;
240 	case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
241 		ctr->h264_i_period = ctrl->val;
242 		break;
243 	case V4L2_CID_MPEG_VIDEO_VPX_MIN_QP:
244 		ctr->vp8_min_qp = ctrl->val;
245 		break;
246 	case V4L2_CID_MPEG_VIDEO_VPX_MAX_QP:
247 		ctr->vp8_max_qp = ctrl->val;
248 		break;
249 	case V4L2_CID_MPEG_VIDEO_B_FRAMES:
250 		ret = venc_calc_bpframes(ctr->gop_size, ctrl->val, &bframes,
251 					 &ctr->num_p_frames);
252 		if (ret)
253 			return ret;
254 
255 		ctr->num_b_frames = bframes;
256 		break;
257 	case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME:
258 		mutex_lock(&inst->lock);
259 		if (inst->streamon_out && inst->streamon_cap) {
260 			ptype = HFI_PROPERTY_CONFIG_VENC_REQUEST_SYNC_FRAME;
261 			ret = hfi_session_set_property(inst, ptype, &en);
262 
263 			if (ret) {
264 				mutex_unlock(&inst->lock);
265 				return ret;
266 			}
267 		}
268 		mutex_unlock(&inst->lock);
269 		break;
270 	case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
271 		ctr->rc_enable = ctrl->val;
272 		break;
273 	case V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY:
274 		ctr->const_quality = ctrl->val;
275 		break;
276 	case V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE:
277 		ctr->frame_skip_mode = ctrl->val;
278 		break;
279 	case V4L2_CID_MPEG_VIDEO_BASELAYER_PRIORITY_ID:
280 		ctr->base_priority_id = ctrl->val;
281 		break;
282 	case V4L2_CID_MPEG_VIDEO_AU_DELIMITER:
283 		ctr->aud_enable = ctrl->val;
284 		break;
285 	case V4L2_CID_MPEG_VIDEO_LTR_COUNT:
286 		ctr->ltr_count = ctrl->val;
287 		break;
288 	case V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX:
289 		mutex_lock(&inst->lock);
290 		if (inst->streamon_out && inst->streamon_cap) {
291 			ptype = HFI_PROPERTY_CONFIG_VENC_MARKLTRFRAME;
292 			ltr_mark.mark_frame = ctrl->val;
293 			ret = hfi_session_set_property(inst, ptype, &ltr_mark);
294 			if (ret) {
295 				mutex_unlock(&inst->lock);
296 				return ret;
297 			}
298 		}
299 		mutex_unlock(&inst->lock);
300 		break;
301 	case V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES:
302 		mutex_lock(&inst->lock);
303 		if (inst->streamon_out && inst->streamon_cap) {
304 			ptype = HFI_PROPERTY_CONFIG_VENC_USELTRFRAME;
305 			ltr_use.ref_ltr = ctrl->val;
306 			ltr_use.use_constrnt = true;
307 			ltr_use.frames = 0;
308 			ret = hfi_session_set_property(inst, ptype, &ltr_use);
309 			if (ret) {
310 				mutex_unlock(&inst->lock);
311 				return ret;
312 			}
313 		}
314 		mutex_unlock(&inst->lock);
315 		break;
316 	case V4L2_CID_COLORIMETRY_HDR10_CLL_INFO:
317 		ctr->cll = *ctrl->p_new.p_hdr10_cll;
318 		break;
319 	case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
320 		ctr->mastering = *ctrl->p_new.p_hdr10_mastering;
321 		break;
322 	default:
323 		return -EINVAL;
324 	}
325 
326 	return 0;
327 }
328 
329 static const struct v4l2_ctrl_ops venc_ctrl_ops = {
330 	.s_ctrl = venc_op_s_ctrl,
331 };
332 
333 int venc_ctrl_init(struct venus_inst *inst)
334 {
335 	int ret;
336 
337 	ret = v4l2_ctrl_handler_init(&inst->ctrl_handler, 57);
338 	if (ret)
339 		return ret;
340 
341 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
342 		V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
343 		V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
344 		~((1 << V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) |
345 		  (1 << V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) |
346 		  (1 << V4L2_MPEG_VIDEO_BITRATE_MODE_CQ)),
347 		V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
348 
349 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
350 		V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE,
351 		V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC,
352 		0, V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC);
353 
354 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
355 		V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE,
356 		V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY,
357 		~((1 << V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE) |
358 		  (1 << V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE)),
359 		V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE);
360 
361 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
362 		V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL,
363 		V4L2_MPEG_VIDEO_MPEG4_LEVEL_5,
364 		0, V4L2_MPEG_VIDEO_MPEG4_LEVEL_0);
365 
366 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
367 		V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
368 		V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
369 		~((1 << V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN) |
370 		  (1 << V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE) |
371 		  (1 << V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10)),
372 		V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN);
373 
374 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
375 		V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
376 		V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2,
377 		0, V4L2_MPEG_VIDEO_HEVC_LEVEL_1);
378 
379 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
380 		V4L2_CID_MPEG_VIDEO_H264_PROFILE,
381 		V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH,
382 		~((1 << V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
383 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
384 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
385 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_HIGH) |
386 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_STEREO_HIGH) |
387 		  (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH)),
388 		V4L2_MPEG_VIDEO_H264_PROFILE_HIGH);
389 
390 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
391 		V4L2_CID_MPEG_VIDEO_H264_LEVEL,
392 		V4L2_MPEG_VIDEO_H264_LEVEL_5_1,
393 		0, V4L2_MPEG_VIDEO_H264_LEVEL_1_0);
394 
395 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
396 		V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE,
397 		AT_SLICE_BOUNDARY,
398 		0, V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED);
399 
400 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
401 		V4L2_CID_MPEG_VIDEO_HEADER_MODE,
402 		V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME,
403 		~((1 << V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) |
404 		(1 << V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME)),
405 		V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME);
406 
407 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
408 		V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE,
409 		V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES,
410 		0, V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE);
411 
412 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
413 		V4L2_CID_MPEG_VIDEO_VP8_PROFILE,
414 		V4L2_MPEG_VIDEO_VP8_PROFILE_3,
415 		0, V4L2_MPEG_VIDEO_VP8_PROFILE_0);
416 
417 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
418 		V4L2_CID_MPEG_VIDEO_BITRATE, BITRATE_MIN, BITRATE_MAX,
419 		BITRATE_STEP, BITRATE_DEFAULT);
420 
421 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
422 		V4L2_CID_MPEG_VIDEO_BITRATE_PEAK, BITRATE_MIN, BITRATE_MAX,
423 		BITRATE_STEP, BITRATE_DEFAULT_PEAK);
424 
425 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
426 			  V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, 1, 51, 1, 26);
427 
428 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
429 			  V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 1, 51, 1, 28);
430 
431 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
432 			  V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP, 1, 51, 1, 30);
433 
434 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
435 			  V4L2_CID_MPEG_VIDEO_H264_MIN_QP, 1, 51, 1, 1);
436 
437 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
438 			  V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP, 1, 51, 1, 1);
439 
440 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
441 			  V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP, 1, 51, 1, 1);
442 
443 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
444 			  V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MIN_QP, 1, 51, 1, 1);
445 
446 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
447 			  V4L2_CID_MPEG_VIDEO_H264_MAX_QP, 1, 51, 1, 51);
448 
449 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
450 			  V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP, 1, 51, 1, 51);
451 
452 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
453 			  V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP, 1, 51, 1, 51);
454 
455 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
456 			  V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MAX_QP, 1, 51, 1, 51);
457 
458 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
459 			  V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP, 1, 63, 1, 26);
460 
461 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
462 			  V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP, 1, 63, 1, 28);
463 
464 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
465 			  V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP, 1, 63, 1, 30);
466 
467 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
468 			  V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP, 1, 63, 1, 1);
469 
470 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
471 			  V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MIN_QP, 1, 63, 1, 1);
472 
473 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
474 			  V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MIN_QP, 1, 63, 1, 1);
475 
476 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
477 			  V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MIN_QP, 1, 63, 1, 1);
478 
479 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
480 			  V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP, 1, 63, 1, 63);
481 
482 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
483 			  V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MAX_QP, 1, 63, 1, 63);
484 
485 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
486 			  V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MAX_QP, 1, 63, 1, 63);
487 
488 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
489 			  V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MAX_QP, 1, 63, 1, 63);
490 
491 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
492 		V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES, SLICE_BYTE_SIZE_MIN,
493 		SLICE_BYTE_SIZE_MAX, 1, SLICE_BYTE_SIZE_MIN);
494 
495 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
496 		V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB, 1,
497 		SLICE_MB_SIZE_MAX, 1, 1);
498 
499 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
500 		V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA, -6, 6, 1, 0);
501 
502 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
503 		V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA, -6, 6, 1, 0);
504 
505 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
506 		V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB,
507 		0, INTRA_REFRESH_MBS_MAX, 1, 0);
508 
509 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
510 		V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, (1 << 16) - 1, 1, 30);
511 
512 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
513 		V4L2_CID_MPEG_VIDEO_VPX_MIN_QP, 1, 128, 1, 1);
514 
515 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
516 		V4L2_CID_MPEG_VIDEO_VPX_MAX_QP, 1, 128, 1, 128);
517 
518 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
519 		V4L2_CID_MPEG_VIDEO_B_FRAMES, 0, 4, 1, 0);
520 
521 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
522 		V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, 0, (1 << 16) - 1, 1, 0);
523 
524 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
525 			  V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME, 0, 0, 0, 0);
526 
527 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
528 			  V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE, 0, 1, 1, 1);
529 
530 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
531 			  V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY, 0, 100, 1, 0);
532 
533 	v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops,
534 			       V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE,
535 			       V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT,
536 			       ~((1 << V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_DISABLED) |
537 			       (1 << V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT)),
538 			       V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_DISABLED);
539 
540 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
541 			  V4L2_CID_MPEG_VIDEO_BASELAYER_PRIORITY_ID, 0,
542 			  6, 1, 0);
543 
544 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
545 			  V4L2_CID_MPEG_VIDEO_AU_DELIMITER, 0, 1, 1, 0);
546 
547 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
548 			  V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES, 0,
549 			  ((1 << MAX_LTR_FRAME_COUNT) - 1), 0, 0);
550 
551 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
552 			  V4L2_CID_MPEG_VIDEO_LTR_COUNT, 0,
553 			  MAX_LTR_FRAME_COUNT, 1, 0);
554 
555 	v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops,
556 			  V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX, 0,
557 			  (MAX_LTR_FRAME_COUNT - 1), 1, 0);
558 
559 	v4l2_ctrl_new_std_compound(&inst->ctrl_handler, &venc_ctrl_ops,
560 				   V4L2_CID_COLORIMETRY_HDR10_CLL_INFO,
561 				   v4l2_ctrl_ptr_create(NULL));
562 
563 	v4l2_ctrl_new_std_compound(&inst->ctrl_handler, &venc_ctrl_ops,
564 				   V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY,
565 				   v4l2_ctrl_ptr_create(NULL));
566 
567 	ret = inst->ctrl_handler.error;
568 	if (ret)
569 		goto err;
570 
571 	ret = v4l2_ctrl_handler_setup(&inst->ctrl_handler);
572 	if (ret)
573 		goto err;
574 
575 	return 0;
576 err:
577 	v4l2_ctrl_handler_free(&inst->ctrl_handler);
578 	return ret;
579 }
580 
581 void venc_ctrl_deinit(struct venus_inst *inst)
582 {
583 	v4l2_ctrl_handler_free(&inst->ctrl_handler);
584 }
585