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