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 #include "helpers.h" 12 13 #define BITRATE_MIN 32000 14 #define BITRATE_MAX 160000000 15 #define BITRATE_DEFAULT 1000000 16 #define BITRATE_DEFAULT_PEAK (BITRATE_DEFAULT * 2) 17 #define BITRATE_STEP 100 18 #define SLICE_BYTE_SIZE_MAX 1024 19 #define SLICE_BYTE_SIZE_MIN 1024 20 #define SLICE_MB_SIZE_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 dynamic_bitrate_update(struct venus_inst *inst, u32 bitrate, 71 u32 layer_id) 72 { 73 int ret = 0; 74 75 mutex_lock(&inst->lock); 76 if (inst->streamon_out && inst->streamon_cap) { 77 u32 ptype = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE; 78 struct hfi_bitrate brate = { .bitrate = bitrate, .layer_id = layer_id }; 79 80 ret = hfi_session_set_property(inst, ptype, &brate); 81 } 82 mutex_unlock(&inst->lock); 83 84 return ret; 85 } 86 87 static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl) 88 { 89 struct venus_inst *inst = ctrl_to_inst(ctrl); 90 struct venc_controls *ctr = &inst->controls.enc; 91 struct hfi_enable en = { .enable = 1 }; 92 struct hfi_ltr_use ltr_use; 93 struct hfi_ltr_mark ltr_mark; 94 u32 bframes; 95 u32 ptype; 96 int ret; 97 98 switch (ctrl->id) { 99 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 100 ctr->bitrate_mode = ctrl->val; 101 break; 102 case V4L2_CID_MPEG_VIDEO_BITRATE: 103 ctr->bitrate = ctrl->val; 104 ret = dynamic_bitrate_update(inst, ctr->bitrate, 0); 105 if (ret) 106 return ret; 107 break; 108 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: 109 ctr->bitrate_peak = ctrl->val; 110 break; 111 case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: 112 ctr->h264_entropy_mode = ctrl->val; 113 break; 114 case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE: 115 ctr->profile.mpeg4 = ctrl->val; 116 break; 117 case V4L2_CID_MPEG_VIDEO_H264_PROFILE: 118 ctr->profile.h264 = ctrl->val; 119 break; 120 case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE: 121 ctr->profile.hevc = ctrl->val; 122 break; 123 case V4L2_CID_MPEG_VIDEO_VP8_PROFILE: 124 ctr->profile.vp8 = ctrl->val; 125 break; 126 case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: 127 ctr->level.mpeg4 = ctrl->val; 128 break; 129 case V4L2_CID_MPEG_VIDEO_H264_LEVEL: 130 ctr->level.h264 = ctrl->val; 131 break; 132 case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL: 133 ctr->level.hevc = ctrl->val; 134 break; 135 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: 136 ctr->h264_i_qp = ctrl->val; 137 break; 138 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: 139 ctr->h264_p_qp = ctrl->val; 140 break; 141 case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP: 142 ctr->h264_b_qp = ctrl->val; 143 break; 144 case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: 145 ctr->h264_min_qp = ctrl->val; 146 break; 147 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP: 148 ctr->h264_i_min_qp = ctrl->val; 149 break; 150 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP: 151 ctr->h264_p_min_qp = ctrl->val; 152 break; 153 case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MIN_QP: 154 ctr->h264_b_min_qp = ctrl->val; 155 break; 156 case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: 157 ctr->h264_max_qp = ctrl->val; 158 break; 159 case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP: 160 ctr->h264_i_max_qp = ctrl->val; 161 break; 162 case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP: 163 ctr->h264_p_max_qp = ctrl->val; 164 break; 165 case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MAX_QP: 166 ctr->h264_b_max_qp = ctrl->val; 167 break; 168 case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP: 169 ctr->hevc_i_qp = ctrl->val; 170 break; 171 case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP: 172 ctr->hevc_p_qp = ctrl->val; 173 break; 174 case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP: 175 ctr->hevc_b_qp = ctrl->val; 176 break; 177 case V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP: 178 ctr->hevc_min_qp = ctrl->val; 179 break; 180 case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MIN_QP: 181 ctr->hevc_i_min_qp = ctrl->val; 182 break; 183 case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MIN_QP: 184 ctr->hevc_p_min_qp = ctrl->val; 185 break; 186 case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MIN_QP: 187 ctr->hevc_b_min_qp = ctrl->val; 188 break; 189 case V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP: 190 ctr->hevc_max_qp = ctrl->val; 191 break; 192 case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MAX_QP: 193 ctr->hevc_i_max_qp = ctrl->val; 194 break; 195 case V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MAX_QP: 196 ctr->hevc_p_max_qp = ctrl->val; 197 break; 198 case V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MAX_QP: 199 ctr->hevc_b_max_qp = ctrl->val; 200 break; 201 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: 202 ctr->multi_slice_mode = ctrl->val; 203 break; 204 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: 205 ctr->multi_slice_max_bytes = ctrl->val; 206 break; 207 case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: 208 ctr->multi_slice_max_mb = ctrl->val; 209 break; 210 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA: 211 ctr->h264_loop_filter_alpha = ctrl->val; 212 break; 213 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA: 214 ctr->h264_loop_filter_beta = ctrl->val; 215 break; 216 case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE: 217 ctr->h264_loop_filter_mode = ctrl->val; 218 break; 219 case V4L2_CID_MPEG_VIDEO_HEADER_MODE: 220 ctr->header_mode = ctrl->val; 221 mutex_lock(&inst->lock); 222 if (inst->streamon_out && inst->streamon_cap) { 223 if (ctrl->val == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) 224 en.enable = 0; 225 else 226 en.enable = 1; 227 ptype = HFI_PROPERTY_CONFIG_VENC_SYNC_FRAME_SEQUENCE_HEADER; 228 ret = hfi_session_set_property(inst, ptype, &en); 229 if (ret) { 230 mutex_unlock(&inst->lock); 231 return ret; 232 } 233 } 234 mutex_unlock(&inst->lock); 235 break; 236 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: 237 ret = venc_calc_bpframes(ctrl->val, ctr->num_b_frames, &bframes, 238 &ctr->num_p_frames); 239 if (ret) 240 return ret; 241 242 ctr->gop_size = ctrl->val; 243 break; 244 case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD: 245 ctr->h264_i_period = ctrl->val; 246 break; 247 case V4L2_CID_MPEG_VIDEO_VPX_MIN_QP: 248 ctr->vp8_min_qp = ctrl->val; 249 break; 250 case V4L2_CID_MPEG_VIDEO_VPX_MAX_QP: 251 ctr->vp8_max_qp = ctrl->val; 252 break; 253 case V4L2_CID_MPEG_VIDEO_B_FRAMES: 254 ret = venc_calc_bpframes(ctr->gop_size, ctrl->val, &bframes, 255 &ctr->num_p_frames); 256 if (ret) 257 return ret; 258 259 ctr->num_b_frames = bframes; 260 break; 261 case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: 262 mutex_lock(&inst->lock); 263 if (inst->streamon_out && inst->streamon_cap) { 264 ptype = HFI_PROPERTY_CONFIG_VENC_REQUEST_SYNC_FRAME; 265 ret = hfi_session_set_property(inst, ptype, &en); 266 267 if (ret) { 268 mutex_unlock(&inst->lock); 269 return ret; 270 } 271 } 272 mutex_unlock(&inst->lock); 273 break; 274 case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE: 275 ctr->rc_enable = ctrl->val; 276 break; 277 case V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY: 278 ctr->const_quality = ctrl->val; 279 break; 280 case V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE: 281 ctr->frame_skip_mode = ctrl->val; 282 break; 283 case V4L2_CID_MPEG_VIDEO_BASELAYER_PRIORITY_ID: 284 ctr->base_priority_id = ctrl->val; 285 break; 286 case V4L2_CID_MPEG_VIDEO_AU_DELIMITER: 287 ctr->aud_enable = ctrl->val; 288 break; 289 case V4L2_CID_MPEG_VIDEO_LTR_COUNT: 290 ctr->ltr_count = ctrl->val; 291 break; 292 case V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX: 293 mutex_lock(&inst->lock); 294 if (inst->streamon_out && inst->streamon_cap) { 295 ptype = HFI_PROPERTY_CONFIG_VENC_MARKLTRFRAME; 296 ltr_mark.mark_frame = ctrl->val; 297 ret = hfi_session_set_property(inst, ptype, <r_mark); 298 if (ret) { 299 mutex_unlock(&inst->lock); 300 return ret; 301 } 302 } 303 mutex_unlock(&inst->lock); 304 break; 305 case V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES: 306 mutex_lock(&inst->lock); 307 if (inst->streamon_out && inst->streamon_cap) { 308 ptype = HFI_PROPERTY_CONFIG_VENC_USELTRFRAME; 309 ltr_use.ref_ltr = ctrl->val; 310 ltr_use.use_constrnt = true; 311 ltr_use.frames = 0; 312 ret = hfi_session_set_property(inst, ptype, <r_use); 313 if (ret) { 314 mutex_unlock(&inst->lock); 315 return ret; 316 } 317 } 318 mutex_unlock(&inst->lock); 319 break; 320 case V4L2_CID_COLORIMETRY_HDR10_CLL_INFO: 321 ctr->cll = *ctrl->p_new.p_hdr10_cll; 322 break; 323 case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY: 324 ctr->mastering = *ctrl->p_new.p_hdr10_mastering; 325 break; 326 case V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE: 327 ctr->intra_refresh_type = ctrl->val; 328 break; 329 case V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD: 330 ctr->intra_refresh_period = ctrl->val; 331 break; 332 case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM: 333 if (ctr->profile.h264 != V4L2_MPEG_VIDEO_H264_PROFILE_HIGH && 334 ctr->profile.h264 != V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_HIGH) 335 return -EINVAL; 336 337 /* 338 * In video firmware, 8x8 transform is supported only for 339 * high profile(HP) and constrained high profile(CHP). 340 * If client wants to disable 8x8 transform for HP/CHP, 341 * it is better to set profile as main profile(MP). 342 * Because there is no difference between HP and MP 343 * if we disable 8x8 transform for HP. 344 */ 345 346 347 ctr->h264_8x8_transform = ctrl->val; 348 break; 349 case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE: 350 if (ctrl->val != V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P) 351 return -EINVAL; 352 break; 353 case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING: 354 ctr->layer_bitrate = ctrl->val; 355 break; 356 case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER: 357 if (ctrl->val > VIDC_MAX_HIER_CODING_LAYER) 358 return -EINVAL; 359 ctr->h264_hier_layers = ctrl->val; 360 break; 361 case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR: 362 ctr->h264_hier_layer_bitrate[0] = ctrl->val; 363 ret = dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[0], 0); 364 if (ret) 365 return ret; 366 break; 367 case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR: 368 ctr->h264_hier_layer_bitrate[1] = ctrl->val; 369 ret = dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[1], 1); 370 if (ret) 371 return ret; 372 break; 373 case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR: 374 ctr->h264_hier_layer_bitrate[2] = ctrl->val; 375 ret = dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[2], 2); 376 if (ret) 377 return ret; 378 break; 379 case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR: 380 ctr->h264_hier_layer_bitrate[3] = ctrl->val; 381 ret = dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[3], 3); 382 if (ret) 383 return ret; 384 break; 385 case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR: 386 ctr->h264_hier_layer_bitrate[4] = ctrl->val; 387 ret = dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[4], 4); 388 if (ret) 389 return ret; 390 break; 391 case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR: 392 ctr->h264_hier_layer_bitrate[5] = ctrl->val; 393 ret = dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[5], 5); 394 if (ret) 395 return ret; 396 break; 397 398 default: 399 return -EINVAL; 400 } 401 402 return 0; 403 } 404 405 static int venc_op_g_volatile_ctrl(struct v4l2_ctrl *ctrl) 406 { 407 struct venus_inst *inst = ctrl_to_inst(ctrl); 408 struct hfi_buffer_requirements bufreq; 409 enum hfi_version ver = inst->core->res->hfi_version; 410 int ret; 411 412 switch (ctrl->id) { 413 case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: 414 ret = venus_helper_get_bufreq(inst, HFI_BUFFER_INPUT, &bufreq); 415 if (!ret) 416 ctrl->val = hfi_bufreq_get_count_min(&bufreq, ver); 417 break; 418 default: 419 return -EINVAL; 420 } 421 422 return 0; 423 } 424 425 static const struct v4l2_ctrl_ops venc_ctrl_ops = { 426 .s_ctrl = venc_op_s_ctrl, 427 .g_volatile_ctrl = venc_op_g_volatile_ctrl, 428 }; 429 430 int venc_ctrl_init(struct venus_inst *inst) 431 { 432 int ret; 433 struct v4l2_ctrl_hdr10_mastering_display p_hdr10_mastering = { 434 { 34000, 13250, 7500 }, 435 { 16000, 34500, 3000 }, 15635, 16450, 10000000, 500, 436 }; 437 struct v4l2_ctrl_hdr10_cll_info p_hdr10_cll = { 1000, 400 }; 438 439 ret = v4l2_ctrl_handler_init(&inst->ctrl_handler, 59); 440 if (ret) 441 return ret; 442 443 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 444 V4L2_CID_MPEG_VIDEO_BITRATE_MODE, 445 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 446 ~((1 << V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) | 447 (1 << V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) | 448 (1 << V4L2_MPEG_VIDEO_BITRATE_MODE_CQ)), 449 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR); 450 451 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 452 V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE, 453 V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC, 454 0, V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC); 455 456 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 457 V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE, 458 V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY, 459 ~((1 << V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE) | 460 (1 << V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE)), 461 V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE); 462 463 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 464 V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL, 465 V4L2_MPEG_VIDEO_MPEG4_LEVEL_5, 466 0, V4L2_MPEG_VIDEO_MPEG4_LEVEL_0); 467 468 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 469 V4L2_CID_MPEG_VIDEO_HEVC_PROFILE, 470 V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10, 471 ~((1 << V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN) | 472 (1 << V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE) | 473 (1 << V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10)), 474 V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN); 475 476 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 477 V4L2_CID_MPEG_VIDEO_HEVC_LEVEL, 478 V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2, 479 0, V4L2_MPEG_VIDEO_HEVC_LEVEL_1); 480 481 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 482 V4L2_CID_MPEG_VIDEO_H264_PROFILE, 483 V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH, 484 ~((1 << V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) | 485 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) | 486 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) | 487 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_HIGH) | 488 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_STEREO_HIGH) | 489 (1 << V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH)), 490 V4L2_MPEG_VIDEO_H264_PROFILE_HIGH); 491 492 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 493 V4L2_CID_MPEG_VIDEO_H264_LEVEL, 494 V4L2_MPEG_VIDEO_H264_LEVEL_5_1, 495 0, V4L2_MPEG_VIDEO_H264_LEVEL_1_0); 496 497 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 498 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE, 499 AT_SLICE_BOUNDARY, 500 0, V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED); 501 502 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 503 V4L2_CID_MPEG_VIDEO_HEADER_MODE, 504 V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME, 505 ~((1 << V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) | 506 (1 << V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME)), 507 V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME); 508 509 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 510 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE, 511 V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES, 512 0, V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE); 513 514 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 515 V4L2_CID_MPEG_VIDEO_VP8_PROFILE, 516 V4L2_MPEG_VIDEO_VP8_PROFILE_3, 517 0, V4L2_MPEG_VIDEO_VP8_PROFILE_0); 518 519 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 520 V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, 4, 11, 1, 4); 521 522 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 523 V4L2_CID_MPEG_VIDEO_BITRATE, BITRATE_MIN, BITRATE_MAX, 524 BITRATE_STEP, BITRATE_DEFAULT); 525 526 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 527 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK, BITRATE_MIN, BITRATE_MAX, 528 BITRATE_STEP, BITRATE_DEFAULT_PEAK); 529 530 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 531 V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, 1, 51, 1, 26); 532 533 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 534 V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 1, 51, 1, 28); 535 536 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 537 V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP, 1, 51, 1, 30); 538 539 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 540 V4L2_CID_MPEG_VIDEO_H264_MIN_QP, 1, 51, 1, 1); 541 542 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 543 V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP, 1, 51, 1, 1); 544 545 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 546 V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM, 0, 1, 1, 1); 547 548 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 549 V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP, 1, 51, 1, 1); 550 551 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 552 V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MIN_QP, 1, 51, 1, 1); 553 554 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 555 V4L2_CID_MPEG_VIDEO_H264_MAX_QP, 1, 51, 1, 51); 556 557 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 558 V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP, 1, 51, 1, 51); 559 560 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 561 V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP, 1, 51, 1, 51); 562 563 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 564 V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MAX_QP, 1, 51, 1, 51); 565 566 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 567 V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP, 1, 63, 1, 26); 568 569 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 570 V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP, 1, 63, 1, 28); 571 572 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 573 V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP, 1, 63, 1, 30); 574 575 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 576 V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP, 1, 63, 1, 1); 577 578 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 579 V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MIN_QP, 1, 63, 1, 1); 580 581 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 582 V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MIN_QP, 1, 63, 1, 1); 583 584 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 585 V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MIN_QP, 1, 63, 1, 1); 586 587 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 588 V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP, 1, 63, 1, 63); 589 590 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 591 V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MAX_QP, 1, 63, 1, 63); 592 593 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 594 V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MAX_QP, 1, 63, 1, 63); 595 596 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 597 V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MAX_QP, 1, 63, 1, 63); 598 599 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 600 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES, SLICE_BYTE_SIZE_MIN, 601 SLICE_BYTE_SIZE_MAX, 1, SLICE_BYTE_SIZE_MIN); 602 603 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 604 V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB, 1, 605 SLICE_MB_SIZE_MAX, 1, 1); 606 607 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 608 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA, -6, 6, 1, 0); 609 610 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 611 V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA, -6, 6, 1, 0); 612 613 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 614 V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, (1 << 16) - 1, 1, 30); 615 616 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 617 V4L2_CID_MPEG_VIDEO_VPX_MIN_QP, 1, 128, 1, 1); 618 619 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 620 V4L2_CID_MPEG_VIDEO_VPX_MAX_QP, 1, 128, 1, 128); 621 622 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 623 V4L2_CID_MPEG_VIDEO_B_FRAMES, 0, 4, 1, 0); 624 625 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 626 V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, 0, (1 << 16) - 1, 1, 0); 627 628 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 629 V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME, 0, 0, 0, 0); 630 631 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 632 V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE, 0, 1, 1, 1); 633 634 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 635 V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY, 0, 100, 1, 0); 636 637 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 638 V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE, 639 V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT, 640 ~((1 << V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_DISABLED) | 641 (1 << V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT)), 642 V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_DISABLED); 643 644 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 645 V4L2_CID_MPEG_VIDEO_BASELAYER_PRIORITY_ID, 0, 646 6, 1, 0); 647 648 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 649 V4L2_CID_MPEG_VIDEO_AU_DELIMITER, 0, 1, 1, 0); 650 651 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 652 V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES, 0, 653 ((1 << MAX_LTR_FRAME_COUNT) - 1), 0, 0); 654 655 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 656 V4L2_CID_MPEG_VIDEO_LTR_COUNT, 0, 657 MAX_LTR_FRAME_COUNT, 1, 0); 658 659 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 660 V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX, 0, 661 (MAX_LTR_FRAME_COUNT - 1), 1, 0); 662 663 v4l2_ctrl_new_std_compound(&inst->ctrl_handler, &venc_ctrl_ops, 664 V4L2_CID_COLORIMETRY_HDR10_CLL_INFO, 665 v4l2_ctrl_ptr_create(&p_hdr10_cll)); 666 667 v4l2_ctrl_new_std_compound(&inst->ctrl_handler, &venc_ctrl_ops, 668 V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY, 669 v4l2_ctrl_ptr_create((void *)&p_hdr10_mastering)); 670 671 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 672 V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE, 673 V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_CYCLIC, 674 0, V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_RANDOM); 675 676 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 677 V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD, 0, 678 ((4096 * 2304) >> 8), 1, 0); 679 680 if (IS_V4(inst->core) || IS_V6(inst->core)) { 681 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, 682 V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE, 683 V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P, 684 1, V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P); 685 686 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 687 V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING, 0, 1, 1, 0); 688 689 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 690 V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER, 0, 691 VIDC_MAX_HIER_CODING_LAYER, 1, 0); 692 693 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 694 V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR, 695 BITRATE_MIN, BITRATE_MAX, BITRATE_STEP, BITRATE_DEFAULT); 696 697 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 698 V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR, 699 BITRATE_MIN, BITRATE_MAX, 700 BITRATE_STEP, BITRATE_DEFAULT); 701 702 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 703 V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR, 704 BITRATE_MIN, BITRATE_MAX, 705 BITRATE_STEP, BITRATE_DEFAULT); 706 707 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 708 V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR, 709 BITRATE_MIN, BITRATE_MAX, 710 BITRATE_STEP, BITRATE_DEFAULT); 711 712 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 713 V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR, 714 BITRATE_MIN, BITRATE_MAX, 715 BITRATE_STEP, BITRATE_DEFAULT); 716 717 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, 718 V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR, 719 BITRATE_MIN, BITRATE_MAX, 720 BITRATE_STEP, BITRATE_DEFAULT); 721 } 722 723 ret = inst->ctrl_handler.error; 724 if (ret) 725 goto err; 726 727 ret = v4l2_ctrl_handler_setup(&inst->ctrl_handler); 728 if (ret) 729 goto err; 730 731 return 0; 732 err: 733 v4l2_ctrl_handler_free(&inst->ctrl_handler); 734 return ret; 735 } 736