From patchwork Mon Jul 29 19:19:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fritz Koenig X-Patchwork-Id: 13745623 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 1F0E243AAB for ; Mon, 29 Jul 2024 19:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722281554; cv=none; b=edP7z+6kG0mhEbahwFNt2N7vHqxjap9kWdPbZ38ahyKi/McyEiiAayYAsynxWbI0Ei52VycXn1YfEbXqVgFYiRZ6x7Ii5l717DPMTlWMTkzrh0ht+4rQTLZ6NXlnGdKVVlG+f0p6NEJ7qPW7Ry5xZgLzZJbg3H+HHGtAn9JfxZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722281554; c=relaxed/simple; bh=nPB5R5zMUohDrDsw/pzurXea3MenbZ7xHK/QXg+oMRM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DVRFt3GHfNyMDhVCAT30O165netR7/Qu6seft8SJXuhS8lgUYS97u+nmDL3ascodkl2DuuO5fNjGf0efmilcRM41okofK83+eJpAlcl0HiKkyJkigjxA/7nAofGx/KbFmuIivPWIcZP2MDWAk/26udRcWJ5xeSeAbj43Ib235tI= 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=Ywstro0o; arc=none smtp.client-ip=209.85.214.177 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="Ywstro0o" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1fda7fa60a9so32201255ad.3 for ; Mon, 29 Jul 2024 12:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1722281552; x=1722886352; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CG1pkz7SlddZO0wW8RkMbL2xlw76r2Yw3/9eifPocFA=; b=Ywstro0obBqBUeu0/u5L0cZzGCzlwIbPH+4Ek7EOa6QUs8jtmmZjFWGqzEPIlQieE6 ltZssM93LrwoR6NckDX/uDYKQQR9mjtbYJxirAOCs32DLh5Uwi1BIxMK24De/JvHnMFB hys2pRydVs3ZETnEaxVta0L6SHQCzUYd7kCMA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722281552; x=1722886352; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CG1pkz7SlddZO0wW8RkMbL2xlw76r2Yw3/9eifPocFA=; b=e8EfFskjuYVYE7KETNt4gJfKhSbJubq60Xr1gvmUzd5cbVrl8vYSDcpjS2K7uLeR3R GYGO9ach6gLT6wmLF1t67+XGmZU3rhw2I0KKTxCUd5X6ZOtrEhfVPf/k+U/E4VYCZ0q6 y1gXnfDMcZ3nqYLevNtVzb0y1FXzKlGW83P0WGiybD2zIgBqZcbVvjzC4DnrwKM+9phO n8I332oNgM94iBZTbfssXQdVJ4yq1rXwRhoWp8PeGc7U0bZFC/vbOtbXG4NVJHOcgE0Z JHp7MoBtRArEYe6uEk0R9Zdap5jxC+9Vc7L6ZLETQrYXAjwLiMf8E/gdGQc130eq8eKj thmQ== X-Gm-Message-State: AOJu0YxwUSQUIYT7aEdUvxWP1o5QeLijDw4+GR6GFH4DHTwHxBYLCtKa 796CVzNzO1vg1lUweXH1Z/5uXgo2IKmBMZ/kzSBb5g7B1VVCNk2kY732mhCJJLfVyIKA9N8wzbE = X-Google-Smtp-Source: AGHT+IHCdNF5UPJKv0qx0uHW7PN+F14P9k1AUim99Iu4RGORosLOkXLDBw2tdT63gu7CvwntMhsHCA== X-Received: by 2002:a17:903:24e:b0:1fb:451a:449b with SMTP id d9443c01a7336-1ff048e1919mr128704715ad.60.1722281552085; Mon, 29 Jul 2024 12:32:32 -0700 (PDT) Received: from localhost ([2a00:79e0:2e13:6:5aa6:a2c1:9047:7da2]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fed7c86b05sm86652895ad.55.2024.07.29.12.32.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Jul 2024 12:32:31 -0700 (PDT) From: Fritz Koenig To: linux-media@vger.kernel.org Cc: mchehab@kernel.org, stanimir.k.varbanov@gmail.com, quic_vgarodia@quicinc.com, bryan.odonoghue@linaro.org, Fritz Koenig Subject: [PATCH v2 1/3] media: venus: Reorder encoder property setting Date: Mon, 29 Jul 2024 12:19:10 -0700 Message-ID: <20240729193219.1260463-2-frkoenig@chromium.org> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog In-Reply-To: <20240729193219.1260463-1-frkoenig@chromium.org> References: <20240729193219.1260463-1-frkoenig@chromium.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Configure the generic controls before the codec specific ones. Some codec specific controls can override the generic ones. Signed-off-by: Fritz Koenig --- v2: - requested testing methodology added to cover letter drivers/media/platform/qcom/venus/venc.c | 183 +++++++++++------------ 1 file changed, 91 insertions(+), 92 deletions(-) diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index 3ec2fb8d9fab..ae24de125c56 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -688,98 +688,6 @@ static int venc_set_properties(struct venus_inst *inst) if (ret) return ret; - if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264) { - struct hfi_h264_vui_timing_info info; - struct hfi_h264_entropy_control entropy; - struct hfi_h264_db_control deblock; - struct hfi_h264_8x8_transform h264_transform; - - ptype = HFI_PROPERTY_PARAM_VENC_H264_VUI_TIMING_INFO; - info.enable = 1; - info.fixed_framerate = 1; - info.time_scale = NSEC_PER_SEC; - - ret = hfi_session_set_property(inst, ptype, &info); - if (ret) - return ret; - - ptype = HFI_PROPERTY_PARAM_VENC_H264_ENTROPY_CONTROL; - entropy.entropy_mode = venc_v4l2_to_hfi( - V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE, - ctr->h264_entropy_mode); - entropy.cabac_model = HFI_H264_CABAC_MODEL_0; - - ret = hfi_session_set_property(inst, ptype, &entropy); - if (ret) - return ret; - - ptype = HFI_PROPERTY_PARAM_VENC_H264_DEBLOCK_CONTROL; - deblock.mode = venc_v4l2_to_hfi( - V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE, - ctr->h264_loop_filter_mode); - deblock.slice_alpha_offset = ctr->h264_loop_filter_alpha; - deblock.slice_beta_offset = ctr->h264_loop_filter_beta; - - ret = hfi_session_set_property(inst, ptype, &deblock); - if (ret) - return ret; - - ptype = HFI_PROPERTY_PARAM_VENC_H264_TRANSFORM_8X8; - h264_transform.enable_type = 0; - if (ctr->profile.h264 == V4L2_MPEG_VIDEO_H264_PROFILE_HIGH || - ctr->profile.h264 == V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_HIGH) - h264_transform.enable_type = ctr->h264_8x8_transform; - - ret = hfi_session_set_property(inst, ptype, &h264_transform); - if (ret) - return ret; - - } - - if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || - inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { - /* IDR periodicity, n: - * n = 0 - only the first I-frame is IDR frame - * n = 1 - all I-frames will be IDR frames - * n > 1 - every n-th I-frame will be IDR frame - */ - ptype = HFI_PROPERTY_CONFIG_VENC_IDR_PERIOD; - idrp.idr_period = 0; - ret = hfi_session_set_property(inst, ptype, &idrp); - if (ret) - return ret; - } - - if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC && - ctr->profile.hevc == V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10) { - struct hfi_hdr10_pq_sei hdr10; - unsigned int c; - - ptype = HFI_PROPERTY_PARAM_VENC_HDR10_PQ_SEI; - - for (c = 0; c < 3; c++) { - hdr10.mastering.display_primaries_x[c] = - ctr->mastering.display_primaries_x[c]; - hdr10.mastering.display_primaries_y[c] = - ctr->mastering.display_primaries_y[c]; - } - - hdr10.mastering.white_point_x = ctr->mastering.white_point_x; - hdr10.mastering.white_point_y = ctr->mastering.white_point_y; - hdr10.mastering.max_display_mastering_luminance = - ctr->mastering.max_display_mastering_luminance; - hdr10.mastering.min_display_mastering_luminance = - ctr->mastering.min_display_mastering_luminance; - - hdr10.cll.max_content_light = ctr->cll.max_content_light_level; - hdr10.cll.max_pic_average_light = - ctr->cll.max_pic_average_light_level; - - ret = hfi_session_set_property(inst, ptype, &hdr10); - if (ret) - return ret; - } - if (ctr->num_b_frames) { u32 max_num_b_frames = NUM_B_FRAMES_MAX; @@ -922,6 +830,97 @@ static int venc_set_properties(struct venus_inst *inst) if (ret) return ret; + if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264) { + struct hfi_h264_vui_timing_info info; + struct hfi_h264_entropy_control entropy; + struct hfi_h264_db_control deblock; + struct hfi_h264_8x8_transform h264_transform; + + ptype = HFI_PROPERTY_PARAM_VENC_H264_VUI_TIMING_INFO; + info.enable = 1; + info.fixed_framerate = 1; + info.time_scale = NSEC_PER_SEC; + + ret = hfi_session_set_property(inst, ptype, &info); + if (ret) + return ret; + + ptype = HFI_PROPERTY_PARAM_VENC_H264_ENTROPY_CONTROL; + entropy.entropy_mode = venc_v4l2_to_hfi( + V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE, + ctr->h264_entropy_mode); + entropy.cabac_model = HFI_H264_CABAC_MODEL_0; + + ret = hfi_session_set_property(inst, ptype, &entropy); + if (ret) + return ret; + + ptype = HFI_PROPERTY_PARAM_VENC_H264_DEBLOCK_CONTROL; + deblock.mode = venc_v4l2_to_hfi( + V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE, + ctr->h264_loop_filter_mode); + deblock.slice_alpha_offset = ctr->h264_loop_filter_alpha; + deblock.slice_beta_offset = ctr->h264_loop_filter_beta; + + ret = hfi_session_set_property(inst, ptype, &deblock); + if (ret) + return ret; + + ptype = HFI_PROPERTY_PARAM_VENC_H264_TRANSFORM_8X8; + h264_transform.enable_type = 0; + if (ctr->profile.h264 == V4L2_MPEG_VIDEO_H264_PROFILE_HIGH || + ctr->profile.h264 == V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_HIGH) + h264_transform.enable_type = ctr->h264_8x8_transform; + + ret = hfi_session_set_property(inst, ptype, &h264_transform); + if (ret) + return ret; + } + + if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || + inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) { + /* IDR periodicity, n: + * n = 0 - only the first I-frame is IDR frame + * n = 1 - all I-frames will be IDR frames + * n > 1 - every n-th I-frame will be IDR frame + */ + ptype = HFI_PROPERTY_CONFIG_VENC_IDR_PERIOD; + idrp.idr_period = 0; + ret = hfi_session_set_property(inst, ptype, &idrp); + if (ret) + return ret; + } + + if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC && + ctr->profile.hevc == V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10) { + struct hfi_hdr10_pq_sei hdr10; + unsigned int c; + + ptype = HFI_PROPERTY_PARAM_VENC_HDR10_PQ_SEI; + + for (c = 0; c < 3; c++) { + hdr10.mastering.display_primaries_x[c] = + ctr->mastering.display_primaries_x[c]; + hdr10.mastering.display_primaries_y[c] = + ctr->mastering.display_primaries_y[c]; + } + + hdr10.mastering.white_point_x = ctr->mastering.white_point_x; + hdr10.mastering.white_point_y = ctr->mastering.white_point_y; + hdr10.mastering.max_display_mastering_luminance = + ctr->mastering.max_display_mastering_luminance; + hdr10.mastering.min_display_mastering_luminance = + ctr->mastering.min_display_mastering_luminance; + + hdr10.cll.max_content_light = ctr->cll.max_content_light_level; + hdr10.cll.max_pic_average_light = + ctr->cll.max_pic_average_light_level; + + ret = hfi_session_set_property(inst, ptype, &hdr10); + if (ret) + return ret; + } + switch (inst->hfi_codec) { case HFI_VIDEO_CODEC_H264: profile = ctr->profile.h264; From patchwork Mon Jul 29 19:19:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fritz Koenig X-Patchwork-Id: 13745624 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 D24D415B555 for ; Mon, 29 Jul 2024 19:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722281555; cv=none; b=GcNW3cVYbXjpWZ3NIdX5/CiEorrRFVfpJ/pKJKg4SO2/tjCyz5/64iUSZHUeKnRKmOSWNueUcn+B47JjADkn3oiTBAdntWfEvvF2L6kGagslyLlOADcOrYkBfJgqowADmbLfQ53Fz/vXwDeipVsqyYBELCoZA6MXborBGAd5cGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722281555; c=relaxed/simple; bh=dS4paJRd+FnTxi5KMww6xVqqBMWNFPBaS+a9evtXShs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=etl/IWsWyNKjnDBDHTa95AZ/Yz5ZeQ0KPkdmLK2X7r4R1H7mzmSzN27sQ3iDnDtEcwOvrxUPIdkRT60rAYsA0RHMTVbycDg5vGQ/wRhDwjD9opW8fuKLYOb6g4E4xB302wyAB3Egwh8JyrbYpCS3SZ0PmthRCCwKJ38ACWL3vzM= 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=moMBXe6u; arc=none smtp.client-ip=209.85.214.173 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="moMBXe6u" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1fd66cddd07so22744675ad.2 for ; Mon, 29 Jul 2024 12:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1722281553; x=1722886353; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6cyD7v3Bb/QfCec3YwhycSMF/Uutpw6nqnCmheziynI=; b=moMBXe6uhl/j5QDI795nX4mZ10dsY9EVsOiIbSx6j2OFOtg6TUmJNnafFrQyBQQ60O MxMaJPMkQG24mVcrwH/uXhGJ5aYC77uB3rNwvObxLE+5K7N27fQIXou9NQih4SjPqzYp XX/+2pEpyy+BOlzGiswq4dKdmzoaoRQakzprw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722281553; x=1722886353; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6cyD7v3Bb/QfCec3YwhycSMF/Uutpw6nqnCmheziynI=; b=oT5P6jiKW5CEQ/zEMFv6RakVPDODwzHUY6ifcqRkeyzt3nDKNUFY4wsrqharPsLX5h Rda1VEt2ldmqNrGuoXILWOxMMjiC8TuC2G77sIW4UkuJPfFRcoJRV3GCBfgqRoeg7OF4 DyZwQ1tsYCan60U110Ta1EUsB8pKYcXYaSLELmOyUNlCs3Tn1uwK7dM98Lh5TdXJ+Ufd Oy+zYDl9hWyhH4Y3+Egkk0WBvVFd8aBAcOFdX6QWuEg3wGho97LQQjRt8x9zxaQ85dpE LnaOL0UEq+v8H3i1Rk7MH4hM+Z1jEfVAVfsXa0IbhRHm0Z5C1JVXasjQIs+gUE/+A+x3 F77A== X-Gm-Message-State: AOJu0Yy7/NPQOsttcwkHsHBiZG6uTd3pp1l1tS0gee+/0NJRhscoww2u 6gcVLE6GmEUOBF/OBM39puua3C9jSouWpSxXfV/s9b+7+aAPPC/7oKi24ZG3MbYNMfkf2+50wpg = X-Google-Smtp-Source: AGHT+IHVt0RmNyrPncbt03o1Gtk3ZHU126LmZwoWj8QmY44wo607z03A+W9EhSqOksN1P9Fbsp7lTg== X-Received: by 2002:a17:902:ce86:b0:1fc:71fb:10d6 with SMTP id d9443c01a7336-1ff04805c4bmr75795745ad.6.1722281552963; Mon, 29 Jul 2024 12:32:32 -0700 (PDT) Received: from localhost ([2a00:79e0:2e13:6:5aa6:a2c1:9047:7da2]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fed7d29228sm89066865ad.106.2024.07.29.12.32.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Jul 2024 12:32:32 -0700 (PDT) From: Fritz Koenig To: linux-media@vger.kernel.org Cc: mchehab@kernel.org, stanimir.k.varbanov@gmail.com, quic_vgarodia@quicinc.com, bryan.odonoghue@linaro.org, Fritz Koenig Subject: [PATCH v2 2/3] media: venus: Helper function for dynamically updating bitrate Date: Mon, 29 Jul 2024 12:19:11 -0700 Message-ID: <20240729193219.1260463-3-frkoenig@chromium.org> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog In-Reply-To: <20240729193219.1260463-1-frkoenig@chromium.org> References: <20240729193219.1260463-1-frkoenig@chromium.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move the dynamic bitrate updating functionality to a separate function so that it can be shared. No functionality changes. Signed-off-by: Fritz Koenig --- v2: - update commit message .../media/platform/qcom/venus/venc_ctrls.c | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media/platform/qcom/venus/venc_ctrls.c index d9d2a293f3ef..6304cc97d37f 100644 --- a/drivers/media/platform/qcom/venus/venc_ctrls.c +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c @@ -67,12 +67,27 @@ static int venc_calc_bpframes(u32 gop_size, u32 conseq_b, u32 *bf, u32 *pf) return 0; } +static int dynamic_bitrate_update(struct venus_inst *inst, u32 bitrate, + u32 layer_id) +{ + int ret = 0; + mutex_lock(&inst->lock); + if (inst->streamon_out && inst->streamon_cap) { + u32 ptype = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE; + struct hfi_bitrate brate = { .bitrate = bitrate, .layer_id = layer_id }; + + ret = hfi_session_set_property(inst, ptype, &brate); + } + mutex_unlock(&inst->lock); + + return ret; +} + static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl) { struct venus_inst *inst = ctrl_to_inst(ctrl); struct venc_controls *ctr = &inst->controls.enc; struct hfi_enable en = { .enable = 1 }; - struct hfi_bitrate brate; struct hfi_ltr_use ltr_use; struct hfi_ltr_mark ltr_mark; u32 bframes; @@ -85,19 +100,9 @@ static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl) break; case V4L2_CID_MPEG_VIDEO_BITRATE: ctr->bitrate = ctrl->val; - mutex_lock(&inst->lock); - if (inst->streamon_out && inst->streamon_cap) { - ptype = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE; - brate.bitrate = ctr->bitrate; - brate.layer_id = 0; - - ret = hfi_session_set_property(inst, ptype, &brate); - if (ret) { - mutex_unlock(&inst->lock); - return ret; - } - } - mutex_unlock(&inst->lock); + ret = dynamic_bitrate_update(inst, ctr->bitrate, 0); + if (ret) + return ret; break; case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: ctr->bitrate_peak = ctrl->val; From patchwork Mon Jul 29 19:19:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fritz Koenig X-Patchwork-Id: 13745625 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 01F69187324 for ; Mon, 29 Jul 2024 19:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722281556; cv=none; b=pjLKMLTEqm5inAFwuOqBXY3WZh2+vT8tHAOk6DM9w/Askhy2k8pdurBYGGGGW74DHc2z+H4oUUpJe3h/7FGuhPcHxUr0AR2N0wfBR4gu2poxVvJVRsLG2UheDccU509edCGOpbuFQmiQ8CM55kaWnYEKutK4SmdSL1K4081GqiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722281556; c=relaxed/simple; bh=LNoD2+pbavtvKAu5PYc7V/mZXMH1gzefksirxA8POWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ps0CQvh+s3NqRDeRjlPQj86+KdpKlvR5ZXUgUMT2W2+RtvwSq7jStpuGXmdwmiUijYNIq0ZQI0KnTvhhJedltSuUoSnfoz/YpWHjYLTIuGw6+Tgrl4D0hIq6b0qTaDQ8AQ6dwbdRaqhlVngjkhjcX7KKYQWl7PcsOtfJQN5fYNE= 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=bewE35Ot; arc=none smtp.client-ip=209.85.214.171 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="bewE35Ot" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fc692abba4so22915865ad.2 for ; Mon, 29 Jul 2024 12:32:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1722281554; x=1722886354; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fAYGHDekdM2SCbf/2ptxx9Mv3z3j6xxjhaqSJCtfArI=; b=bewE35OtKu6vz7mA1Gzhe7o2dljNEm27MtQK6K2v6/mCdqk/PR4OkunLcSyuCrDaX3 6grTTXhDMB2sk/vDyk+IzDangAMuX8x9mOiKUHmMdIVfebLs4/y4GiX7ePwWZOa/xfe/ VCr7n65W7RaMOQUqatM3D1XWoprADA3kDKMhk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722281554; x=1722886354; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fAYGHDekdM2SCbf/2ptxx9Mv3z3j6xxjhaqSJCtfArI=; b=VysOh6WbSFQj7mbk4LNFqYRqmdPw9SbQMK1lePsMTd5NmEK8xwR02hbWOC5A3AQO5A gVOTOigM4ECON4OpRw3P3sKzrJwDgh+baHlZeVqI3h+GUUNReNRvzeyRXElrF1Svs55g pSokqAkb4+LY9YqtfaoCN7WfhHoHo1nLrQQuc8VR/lUN+CagAtSDWdghQELiXhQpP6aF VYrQc13UaX8egZMV/IDW4wQ+gZDCygCBZhFR3qQSjg/1A116D2Lkx0c6G62zxKN10jlX 2sCqQvHe64MPaW2kh8ZhWe+bsTR6gA7tPJyfHbLO93wre8tBp7kNMaZ1qfirN+T7pG/O 55wA== X-Gm-Message-State: AOJu0Yyk5YNSnpI0Q8FtYB8IFb/pErxhMBs1nwOWmfjAYiMaUALXuCnn ekfdp9pWO4beT3OvqBZqeuhna6pfJMsFZpfBaNUuz/o1Qf4vLCrl255+OAkGPwSkqLLZHEYeu9U = X-Google-Smtp-Source: AGHT+IEQXfMiiYnjbH75kiR1p59qlKzo4PsAEjfVafvcJl3daV8K8yHf5HdxVKFGFKWMumdpseFBvA== X-Received: by 2002:a17:902:74ca:b0:1fc:4940:d3ad with SMTP id d9443c01a7336-1ff0487db67mr55661965ad.59.1722281554025; Mon, 29 Jul 2024 12:32:34 -0700 (PDT) Received: from localhost ([2a00:79e0:2e13:6:5aa6:a2c1:9047:7da2]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fed7f60539sm86435565ad.220.2024.07.29.12.32.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Jul 2024 12:32:33 -0700 (PDT) From: Fritz Koenig To: linux-media@vger.kernel.org Cc: mchehab@kernel.org, stanimir.k.varbanov@gmail.com, quic_vgarodia@quicinc.com, bryan.odonoghue@linaro.org, Fritz Koenig Subject: [PATCH v2 3/3] media: venus: Enable h.264 hierarchical coding Date: Mon, 29 Jul 2024 12:19:12 -0700 Message-ID: <20240729193219.1260463-4-frkoenig@chromium.org> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog In-Reply-To: <20240729193219.1260463-1-frkoenig@chromium.org> References: <20240729193219.1260463-1-frkoenig@chromium.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The series of V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING* controls provides the functionality for temporal layering. These controls allow for different framerates in a single stream. 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 --- v2: - update commit message drivers/media/platform/qcom/venus/core.h | 4 + drivers/media/platform/qcom/venus/venc.c | 24 ++++++ .../media/platform/qcom/venus/venc_ctrls.c | 84 +++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index 55202b89e1b9..fc9552311a71 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -274,6 +274,10 @@ struct venc_controls { s32 h264_loop_filter_beta; u32 h264_8x8_transform; + u32 h264_hier_enabled; + u32 h264_hier_p_layers; + u32 h264_hier_p_bitrate[6]; + u32 hevc_i_qp; u32 hevc_p_qp; u32 hevc_b_qp; diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index ae24de125c56..301b0015b356 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -875,6 +875,30 @@ static int venc_set_properties(struct venus_inst *inst) ret = hfi_session_set_property(inst, ptype, &h264_transform); if (ret) return ret; + + if (ctr->h264_hier_enabled) { + unsigned int i; + + ptype = HFI_PROPERTY_PARAM_VENC_HIER_P_MAX_NUM_ENH_LAYER; + ret = hfi_session_set_property(inst, ptype, &ctr->h264_hier_p_layers); + if (ret) + return ret; + + ptype = HFI_PROPERTY_CONFIG_VENC_HIER_P_ENH_LAYER; + ret = hfi_session_set_property(inst, ptype, &ctr->h264_hier_p_layers); + if (ret) + return ret; + + for (i = 0; i < ctr->h264_hier_p_layers; ++i) { + ptype = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE; + brate.bitrate = ctr->h264_hier_p_bitrate[i]; + brate.layer_id = i; + + ret = hfi_session_set_property(inst, ptype, &brate); + if (ret) + return ret; + } + } } if (inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media/platform/qcom/venus/venc_ctrls.c index 6304cc97d37f..4cad8058339a 100644 --- a/drivers/media/platform/qcom/venus/venc_ctrls.c +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c @@ -345,6 +345,52 @@ static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl) ctr->h264_8x8_transform = ctrl->val; break; + case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE: + if (ctrl->val != V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P) + return -EINVAL; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING: + ctr->h264_hier_enabled = ctrl->val; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER: + ctr->h264_hier_p_layers = ctrl->val; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR: + ctr->h264_hier_p_bitrate[0] = ctrl->val; + ret = dynamic_bitrate_update(inst, ctr->h264_hier_p_bitrate[0], 0); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR: + ctr->h264_hier_p_bitrate[1] = ctrl->val; + ret = dynamic_bitrate_update(inst, ctr->h264_hier_p_bitrate[1], 1); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR: + ctr->h264_hier_p_bitrate[2] = ctrl->val; + ret = dynamic_bitrate_update(inst, ctr->h264_hier_p_bitrate[2], 2); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR: + ctr->h264_hier_p_bitrate[3] = ctrl->val; + ret = dynamic_bitrate_update(inst, ctr->h264_hier_p_bitrate[3], 3); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR: + ctr->h264_hier_p_bitrate[4] = ctrl->val; + ret = dynamic_bitrate_update(inst, ctr->h264_hier_p_bitrate[4], 4); + if (ret) + return ret; + break; + case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR: + ctr->h264_hier_p_bitrate[5] = ctrl->val; + ret = dynamic_bitrate_update(inst, ctr->h264_hier_p_bitrate[5], 5); + if (ret) + return ret; + break; default: return -EINVAL; } @@ -627,6 +673,44 @@ int venc_ctrl_init(struct venus_inst *inst) V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD, 0, ((4096 * 2304) >> 8), 1, 0); + 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, + 6, 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 = inst->ctrl_handler.error; if (ret) goto err;