| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. |
|---|
| 3 | 4 | * Copyright (C) 2017 Linaro Ltd. |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License version 2 and |
|---|
| 7 | | - * only version 2 as published by the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | | - * |
|---|
| 14 | 5 | */ |
|---|
| 15 | 6 | #include <linux/types.h> |
|---|
| 16 | 7 | #include <media/v4l2-ctrls.h> |
|---|
| .. | .. |
|---|
| 79 | 70 | { |
|---|
| 80 | 71 | struct venus_inst *inst = ctrl_to_inst(ctrl); |
|---|
| 81 | 72 | struct venc_controls *ctr = &inst->controls.enc; |
|---|
| 73 | + struct hfi_enable en = { .enable = 1 }; |
|---|
| 74 | + struct hfi_bitrate brate; |
|---|
| 82 | 75 | u32 bframes; |
|---|
| 76 | + u32 ptype; |
|---|
| 83 | 77 | int ret; |
|---|
| 84 | 78 | |
|---|
| 85 | 79 | switch (ctrl->id) { |
|---|
| .. | .. |
|---|
| 88 | 82 | break; |
|---|
| 89 | 83 | case V4L2_CID_MPEG_VIDEO_BITRATE: |
|---|
| 90 | 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); |
|---|
| 91 | 98 | break; |
|---|
| 92 | 99 | case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: |
|---|
| 93 | 100 | ctr->bitrate_peak = ctrl->val; |
|---|
| .. | .. |
|---|
| 101 | 108 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: |
|---|
| 102 | 109 | ctr->profile.h264 = ctrl->val; |
|---|
| 103 | 110 | break; |
|---|
| 111 | + case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE: |
|---|
| 112 | + ctr->profile.hevc = ctrl->val; |
|---|
| 113 | + break; |
|---|
| 104 | 114 | case V4L2_CID_MPEG_VIDEO_VP8_PROFILE: |
|---|
| 105 | | - ctr->profile.vpx = ctrl->val; |
|---|
| 115 | + ctr->profile.vp8 = ctrl->val; |
|---|
| 106 | 116 | break; |
|---|
| 107 | 117 | case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL: |
|---|
| 108 | 118 | ctr->level.mpeg4 = ctrl->val; |
|---|
| 109 | 119 | break; |
|---|
| 110 | 120 | case V4L2_CID_MPEG_VIDEO_H264_LEVEL: |
|---|
| 111 | 121 | ctr->level.h264 = ctrl->val; |
|---|
| 122 | + break; |
|---|
| 123 | + case V4L2_CID_MPEG_VIDEO_HEVC_LEVEL: |
|---|
| 124 | + ctr->level.hevc = ctrl->val; |
|---|
| 112 | 125 | break; |
|---|
| 113 | 126 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: |
|---|
| 114 | 127 | ctr->h264_i_qp = ctrl->val; |
|---|
| .. | .. |
|---|
| 173 | 186 | |
|---|
| 174 | 187 | ctr->num_b_frames = bframes; |
|---|
| 175 | 188 | break; |
|---|
| 189 | + case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: |
|---|
| 190 | + mutex_lock(&inst->lock); |
|---|
| 191 | + if (inst->streamon_out && inst->streamon_cap) { |
|---|
| 192 | + ptype = HFI_PROPERTY_CONFIG_VENC_REQUEST_SYNC_FRAME; |
|---|
| 193 | + ret = hfi_session_set_property(inst, ptype, &en); |
|---|
| 194 | + |
|---|
| 195 | + if (ret) { |
|---|
| 196 | + mutex_unlock(&inst->lock); |
|---|
| 197 | + return ret; |
|---|
| 198 | + } |
|---|
| 199 | + } |
|---|
| 200 | + mutex_unlock(&inst->lock); |
|---|
| 201 | + break; |
|---|
| 202 | + case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE: |
|---|
| 203 | + ctr->rc_enable = ctrl->val; |
|---|
| 204 | + break; |
|---|
| 205 | + case V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY: |
|---|
| 206 | + ctr->const_quality = ctrl->val; |
|---|
| 207 | + break; |
|---|
| 208 | + case V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE: |
|---|
| 209 | + ctr->frame_skip_mode = ctrl->val; |
|---|
| 210 | + break; |
|---|
| 176 | 211 | default: |
|---|
| 177 | 212 | return -EINVAL; |
|---|
| 178 | 213 | } |
|---|
| .. | .. |
|---|
| 188 | 223 | { |
|---|
| 189 | 224 | int ret; |
|---|
| 190 | 225 | |
|---|
| 191 | | - ret = v4l2_ctrl_handler_init(&inst->ctrl_handler, 27); |
|---|
| 226 | + ret = v4l2_ctrl_handler_init(&inst->ctrl_handler, 33); |
|---|
| 192 | 227 | if (ret) |
|---|
| 193 | 228 | return ret; |
|---|
| 194 | 229 | |
|---|
| .. | .. |
|---|
| 196 | 231 | V4L2_CID_MPEG_VIDEO_BITRATE_MODE, |
|---|
| 197 | 232 | V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, |
|---|
| 198 | 233 | ~((1 << V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) | |
|---|
| 199 | | - (1 << V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)), |
|---|
| 234 | + (1 << V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) | |
|---|
| 235 | + (1 << V4L2_MPEG_VIDEO_BITRATE_MODE_CQ)), |
|---|
| 200 | 236 | V4L2_MPEG_VIDEO_BITRATE_MODE_VBR); |
|---|
| 201 | 237 | |
|---|
| 202 | 238 | v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| .. | .. |
|---|
| 215 | 251 | V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL, |
|---|
| 216 | 252 | V4L2_MPEG_VIDEO_MPEG4_LEVEL_5, |
|---|
| 217 | 253 | 0, V4L2_MPEG_VIDEO_MPEG4_LEVEL_0); |
|---|
| 254 | + |
|---|
| 255 | + v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 256 | + V4L2_CID_MPEG_VIDEO_HEVC_PROFILE, |
|---|
| 257 | + V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10, |
|---|
| 258 | + ~((1 << V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN) | |
|---|
| 259 | + (1 << V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE) | |
|---|
| 260 | + (1 << V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10)), |
|---|
| 261 | + V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN); |
|---|
| 262 | + |
|---|
| 263 | + v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 264 | + V4L2_CID_MPEG_VIDEO_HEVC_LEVEL, |
|---|
| 265 | + V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2, |
|---|
| 266 | + 0, V4L2_MPEG_VIDEO_HEVC_LEVEL_1); |
|---|
| 218 | 267 | |
|---|
| 219 | 268 | v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 220 | 269 | V4L2_CID_MPEG_VIDEO_H264_PROFILE, |
|---|
| .. | .. |
|---|
| 245 | 294 | |
|---|
| 246 | 295 | v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 247 | 296 | V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE, |
|---|
| 248 | | - V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES, |
|---|
| 297 | + V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES, |
|---|
| 249 | 298 | 0, V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE); |
|---|
| 250 | 299 | |
|---|
| 251 | 300 | v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| .. | .. |
|---|
| 295 | 344 | 0, INTRA_REFRESH_MBS_MAX, 1, 0); |
|---|
| 296 | 345 | |
|---|
| 297 | 346 | v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 298 | | - V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, (1 << 16) - 1, 1, 12); |
|---|
| 347 | + V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, (1 << 16) - 1, 1, 30); |
|---|
| 299 | 348 | |
|---|
| 300 | 349 | v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 301 | 350 | V4L2_CID_MPEG_VIDEO_VPX_MIN_QP, 1, 128, 1, 1); |
|---|
| .. | .. |
|---|
| 309 | 358 | v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 310 | 359 | V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, 0, (1 << 16) - 1, 1, 0); |
|---|
| 311 | 360 | |
|---|
| 361 | + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 362 | + V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME, 0, 0, 0, 0); |
|---|
| 363 | + |
|---|
| 364 | + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 365 | + V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE, 0, 1, 1, 1); |
|---|
| 366 | + |
|---|
| 367 | + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 368 | + V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY, 0, 100, 1, 0); |
|---|
| 369 | + |
|---|
| 370 | + v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, |
|---|
| 371 | + V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE, |
|---|
| 372 | + V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT, |
|---|
| 373 | + ~((1 << V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_DISABLED) | |
|---|
| 374 | + (1 << V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT)), |
|---|
| 375 | + V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_DISABLED); |
|---|
| 376 | + |
|---|
| 312 | 377 | ret = inst->ctrl_handler.error; |
|---|
| 313 | 378 | if (ret) |
|---|
| 314 | 379 | goto err; |
|---|