From nobody Tue Nov 26 03:58:33 2024 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 368AD1BE23D for ; Tue, 22 Oct 2024 17:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618851; cv=none; b=TaL4SwU6E3Eh7FYQQgqxQfNrZE38Sxmz+Mc60aCzkMNJnRiejmzYfGPL8kgjnKd5OZ41X0O377DZui/xIjsI2g2SiVQhx77gViaGcq25TPuqmIWSKs4Xi7DwhPQUsi8kJTO2SzioxkKAzGYHYKNhig2hbKx7hYo/3RMIeJyWWc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618851; c=relaxed/simple; bh=8WD3EDDIY6nRwJgBILdejv1KXcxO/XEg4ymdZkEao40=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aZB/4aqxFjsqDxHt7vfTagVDNzXvgVgAWCB18lE93XlpYe0ugSpvyw6hjlC3EoSmBAGbHvW8MExcBuAlqcpluXGY9VdQWwRJpHFehWRtgVY6etgODBlnxDijVRUYCtY0PVZWkZcipZC5zrE1wMGxJ+efdn5mJdkgTMwUfGbe0vE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=XRLo+SY4; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XRLo+SY4" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-71e625b00bcso4345839b3a.3 for ; Tue, 22 Oct 2024 10:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729618847; x=1730223647; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hiI/WriZlF4yG6diNP/Nfp7ERYOSiUQCm9cUT10e9ls=; b=XRLo+SY4+2WfAF9ut5UjI9TFpjp2LjF1Cc1wtAn7ULHM4xFgiAij55b8Fw5qyvFJcK wZKC838u4ocYqYkG1WAP2jIAsOX+Vo3vd19F2DgDLEDeuVLXeZwO8NX2jiCCedDlQNIG vcfUK1mrpRveOyT34uwOvLoLYIOwFqaJKhiSY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618847; x=1730223647; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hiI/WriZlF4yG6diNP/Nfp7ERYOSiUQCm9cUT10e9ls=; b=d0+ewAFXZGf7QT5uyHE9trnrigK5sJf1isD1frQ5xfuDmdPKkxI+iXPJ1sSXm9jWJ6 MvmM5oLIEKf3/pa0nwNFUUgEBj7QzAT7D8zzK+VG2M8MIqA9qPFOZdfigZnOOuV++ocR f1VxCZGL0xHAb8fD/7ZTFTdrGU3FcyjMor1gJ4VpaEHIP1n8qGz1r3IxV8C+4GOiW0dJ tkVOJEFRAhG8cEIOC6hPiq7bPngg2p1WFrZJRWK4v/ZermcPt7gfgUWcBac53HlESi4B qx2OOD6RDA2YPkTILUWIlrBLhhqaTrqAIywC8yk09bBnROlncbcuniEX+87acSrXkKse Nlow== X-Forwarded-Encrypted: i=1; AJvYcCWhzgibBZCV55scyjZJe0Tn6/HLKhFqxxrOYCtmgJ0AD2UJjXcqv7zCqTWzZAW6TuY4aH8hZOGnxUT94a8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4mTqKuZKsGzJQmw/ikf0VgZtHRfMgmOw754/Wl30/CaeJ8KRI mBhGgAJm84tUiSl/5+8+25y7oymRQ9DXs72w6ESROyTDu6GNGPQ+TIkJP0KBrQ== X-Google-Smtp-Source: AGHT+IFf5IUrR4y71FXBLu1VA6iTSR+LrclnTni6VlVJv6JQ36EY8E78CmXkX/ydBf6WIxmAiparqw== X-Received: by 2002:a05:6a00:14c9:b0:71e:3b8:666b with SMTP id d2e1a72fcca58-72030a8069amr43653b3a.15.1729618847483; Tue, 22 Oct 2024 10:40:47 -0700 (PDT) Received: from zipper.pdx.corp.google.com ([2a00:79e0:2e13:6:158a:d1d:c077:7770]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec1312d6bsm4992423b3a.29.2024.10.22.10.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2024 10:40:47 -0700 (PDT) From: Fritz Koenig Date: Tue, 22 Oct 2024 10:40:43 -0700 Subject: [PATCH v5 2/2] media: venus: Enable h.264 hierarchical coding Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241022-submit-v5-2-552f0fec8cba@chromium.org> References: <20241022-submit-v5-0-552f0fec8cba@chromium.org> In-Reply-To: <20241022-submit-v5-0-552f0fec8cba@chromium.org> To: Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Mauro Carvalho Chehab , Dikshita Agarwal Cc: Nathan Hebert , linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Fritz Koenig X-Mailer: b4 0.15-dev-37811 HFI supports hierarchical P encoding and the ability to specify the bitrate for the different layers. Connect the controls that V4L2 provides and HFI supports. Signed-off-by: Fritz Koenig Reviewed-by: Dikshita Agarwal --- drivers/media/platform/qcom/venus/core.h | 4 ++ drivers/media/platform/qcom/venus/venc.c | 71 +++++++++++++------- drivers/media/platform/qcom/venus/venc_ctrls.c | 92 ++++++++++++++++++++++= ++++ 3 files changed, 144 insertions(+), 23 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platf= orm/qcom/venus/core.h index 55202b89e1b9..fd46a7778d8c 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -26,6 +26,7 @@ #define VIDC_CLKS_NUM_MAX 4 #define VIDC_VCODEC_CLKS_NUM_MAX 2 #define VIDC_RESETS_NUM_MAX 2 +#define VIDC_MAX_HIER_CODING_LAYER 6 =20 extern int venus_fw_debug; =20 @@ -255,6 +256,7 @@ struct venc_controls { u32 rc_enable; u32 const_quality; u32 frame_skip_mode; + u32 layer_bitrate; =20 u32 h264_i_period; u32 h264_entropy_mode; @@ -273,6 +275,8 @@ struct venc_controls { s32 h264_loop_filter_alpha; s32 h264_loop_filter_beta; u32 h264_8x8_transform; + u32 h264_hier_layers; + u32 h264_hier_layer_bitrate[VIDC_MAX_HIER_CODING_LAYER]; =20 u32 hevc_i_qp; u32 hevc_p_qp; diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platf= orm/qcom/venus/venc.c index 3ec2fb8d9fab..75b832ffc0f9 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -734,6 +734,29 @@ static int venc_set_properties(struct venus_inst *inst) if (ret) return ret; =20 + if (ctr->layer_bitrate) { + unsigned int i; + + ptype =3D HFI_PROPERTY_PARAM_VENC_HIER_P_MAX_NUM_ENH_LAYER; + ret =3D hfi_session_set_property(inst, ptype, &ctr->h264_hier_layers); + if (ret) + return ret; + + ptype =3D HFI_PROPERTY_CONFIG_VENC_HIER_P_ENH_LAYER; + ret =3D hfi_session_set_property(inst, ptype, &ctr->layer_bitrate); + if (ret) + return ret; + + for (i =3D 0; i < ctr->h264_hier_layers; ++i) { + ptype =3D HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE; + brate.bitrate =3D ctr->h264_hier_layer_bitrate[i]; + brate.layer_id =3D i; + + ret =3D hfi_session_set_property(inst, ptype, &brate); + if (ret) + return ret; + } + } } =20 if (inst->fmt_cap->pixfmt =3D=3D V4L2_PIX_FMT_H264 || @@ -823,18 +846,33 @@ static int venc_set_properties(struct venus_inst *ins= t) return ret; } =20 - if (!ctr->bitrate) - bitrate =3D 64000; - else - bitrate =3D ctr->bitrate; + if (!ctr->layer_bitrate) { + if (!ctr->bitrate) + bitrate =3D 64000; + else + bitrate =3D ctr->bitrate; =20 - ptype =3D HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE; - brate.bitrate =3D bitrate; - brate.layer_id =3D 0; + ptype =3D HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE; + brate.bitrate =3D bitrate; + brate.layer_id =3D 0; =20 - ret =3D hfi_session_set_property(inst, ptype, &brate); - if (ret) - return ret; + ret =3D hfi_session_set_property(inst, ptype, &brate); + if (ret) + return ret; + + if (!ctr->bitrate_peak) + bitrate *=3D 2; + else + bitrate =3D ctr->bitrate_peak; + + ptype =3D HFI_PROPERTY_CONFIG_VENC_MAX_BITRATE; + brate.bitrate =3D bitrate; + brate.layer_id =3D 0; + + ret =3D hfi_session_set_property(inst, ptype, &brate); + if (ret) + return ret; + } =20 if (inst->fmt_cap->pixfmt =3D=3D V4L2_PIX_FMT_H264 || inst->fmt_cap->pixfmt =3D=3D V4L2_PIX_FMT_HEVC) { @@ -849,19 +887,6 @@ static int venc_set_properties(struct venus_inst *inst) return ret; } =20 - if (!ctr->bitrate_peak) - bitrate *=3D 2; - else - bitrate =3D ctr->bitrate_peak; - - ptype =3D HFI_PROPERTY_CONFIG_VENC_MAX_BITRATE; - brate.bitrate =3D bitrate; - brate.layer_id =3D 0; - - ret =3D hfi_session_set_property(inst, ptype, &brate); - if (ret) - return ret; - ptype =3D HFI_PROPERTY_PARAM_VENC_SESSION_QP; if (inst->fmt_cap->pixfmt =3D=3D V4L2_PIX_FMT_HEVC) { quant.qp_i =3D ctr->hevc_i_qp; diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media= /platform/qcom/venus/venc_ctrls.c index 3e1f6f26eddf..e340783a4ef2 100644 --- a/drivers/media/platform/qcom/venus/venc_ctrls.c +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c @@ -346,6 +346,55 @@ static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl) =20 ctr->h264_8x8_transform =3D ctrl->val; break; + case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE: + if (ctrl->val !=3D V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P) + return -EINVAL; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING: + ctr->layer_bitrate =3D ctrl->val; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER: + if (ctrl->val > VIDC_MAX_HIER_CODING_LAYER) + return -EINVAL; + ctr->h264_hier_layers =3D ctrl->val; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR: + ctr->h264_hier_layer_bitrate[0] =3D ctrl->val; + ret =3D dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[0], 0); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR: + ctr->h264_hier_layer_bitrate[1] =3D ctrl->val; + ret =3D dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[1], 1); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR: + ctr->h264_hier_layer_bitrate[2] =3D ctrl->val; + ret =3D dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[2], 2); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR: + ctr->h264_hier_layer_bitrate[3] =3D ctrl->val; + ret =3D dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[3], 3); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR: + ctr->h264_hier_layer_bitrate[4] =3D ctrl->val; + ret =3D dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[4], 4); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR: + ctr->h264_hier_layer_bitrate[5] =3D ctrl->val; + ret =3D dynamic_bitrate_update(inst, ctr->h264_hier_layer_bitrate[5], 5); + if (ret) + return ret; + break; + default: return -EINVAL; } @@ -628,6 +677,49 @@ int venc_ctrl_init(struct venus_inst *inst) V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD, 0, ((4096 * 2304) >> 8), 1, 0); =20 + if (IS_V4(inst->core) || IS_V6(inst->core)) { + v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE, + V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P, + 1, V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING, 0, 1, 1, 0); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER, 0, + VIDC_MAX_HIER_CODING_LAYER, 1, 0); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR, + BITRATE_MIN, BITRATE_MAX, BITRATE_STEP, BITRATE_DEFAULT); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR, + BITRATE_MIN, BITRATE_MAX, + BITRATE_STEP, BITRATE_DEFAULT); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR, + BITRATE_MIN, BITRATE_MAX, + BITRATE_STEP, BITRATE_DEFAULT); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR, + BITRATE_MIN, BITRATE_MAX, + BITRATE_STEP, BITRATE_DEFAULT); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR, + BITRATE_MIN, BITRATE_MAX, + BITRATE_STEP, BITRATE_DEFAULT); + + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR, + BITRATE_MIN, BITRATE_MAX, + BITRATE_STEP, BITRATE_DEFAULT); + } + ret =3D inst->ctrl_handler.error; if (ret) goto err; --=20 2.47.0.105.g07ac214952-goog