From patchwork Tue Mar 2 09:53:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 392232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7E1AC4151A for ; Wed, 3 Mar 2021 01:20:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8169064FA6 for ; Wed, 3 Mar 2021 01:20:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242074AbhCCBPW (ORCPT ); Tue, 2 Mar 2021 20:15:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1577806AbhCBJym (ORCPT ); Tue, 2 Mar 2021 04:54:42 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 144A6C061793 for ; Tue, 2 Mar 2021 01:54:02 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id dx17so6483526ejb.2 for ; Tue, 02 Mar 2021 01:54:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6IV5VLrP2K6hakTQn5ZKKEh0aLDdahbFbJ/jSG0w0Qk=; b=mt3f0nccW8Be+pKxoRLkK919cWp9XaFIhiLsVUFy/KTwAbqgTW6woAgd1dMFKsG70H x207CdNv0v7gLoleaAZAkJ1JnQSGbamQRHQXU8ZHfdnxZi7MBv7gepXNjjh/4hkwRhX0 +5aHRy+dpeexRDWzlpqglyXDJxJax166IZSGt8L485nBNtf7+Uvxgl0/ImtX9BCIOH+B mRJCKIQfKY8vG/kO8rb1VwPo5DXii8ro94/wq0NWdwbhGeWbFTAbjEP1Bgw8hc2a3YUT sciQC0UTDPuSvkXuilEryUsF8Gua4NWtjVk6/zA0rjZIA2jtV1MePeX7GCKMncKORt15 9KIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6IV5VLrP2K6hakTQn5ZKKEh0aLDdahbFbJ/jSG0w0Qk=; b=udspHPzcsHFtfduEt90jcu2Ov1jCQPX0z6NapUv0KuP9PPAbN35XAjhbV5iBPrVLRE 24Xc0CefqyHoB0M/2N5D2ZGaJxorK9Aei0+AiBNheOjpDy4F4r/cVTdC43J/NcQILQBR moyTCa8xUn5hCC1BvKMdrMDboKcIP0cxdA5qRmpF3ckR4TEDSx0xEvS8aCWw0QqUCuoP tHO35EJ86oeymjboE6aPY8rysiFLjLa9uegELFyyNE9ujVO+c2+Bs5XgE07JeQlrw0dt sJi7Gf0RviwR9S7V7xd5df7vIQF6h4Oq0+l06mAwSN3tyzGPdHxFkZaoiDxFm7oTl868 v/DA== X-Gm-Message-State: AOAM5314Sf/m4wNJc20TaxHtqRuJCigViPArfs+izW64aZFfhkj5kD/0 SNnwLnc/PklJdM2ZOaKTxqTPLw== X-Google-Smtp-Source: ABdhPJweNw/k9wLfEaT79zQYNRF7Yt7r5/uF5qc/QVfKMZNVlZ57jJrWf9GWgv+E/gGMWfJOLQTjiQ== X-Received: by 2002:a17:906:2a06:: with SMTP id j6mr19490245eje.164.1614678840805; Tue, 02 Mar 2021 01:54:00 -0800 (PST) Received: from localhost.localdomain (hst-208-217.medicom.bg. [84.238.208.217]) by smtp.gmail.com with ESMTPSA id be27sm2530535edb.47.2021.03.02.01.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 01:54:00 -0800 (PST) From: Stanimir Varbanov To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Cc: Ezequiel Garcia , nicolas.dufresne@collabora.com, Hans Verkuil , Stanimir Varbanov Subject: [PATCH v3 1/2] media: v4l2-ctrls: Add intra-refresh period control Date: Tue, 2 Mar 2021 11:53:39 +0200 Message-Id: <20210302095340.3584204-2-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210302095340.3584204-1-stanimir.varbanov@linaro.org> References: <20210302095340.3584204-1-stanimir.varbanov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add a control to set intra-refresh period. Signed-off-by: Stanimir Varbanov --- .../userspace-api/media/v4l/ext-ctrls-codec.rst | 12 ++++++++++++ drivers/media/v4l2-core/v4l2-ctrls.c | 2 ++ include/uapi/linux/v4l2-controls.h | 1 + 3 files changed, 15 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst index 00944e97d638..49e6d364ded7 100644 --- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst @@ -1104,6 +1104,18 @@ enum v4l2_mpeg_video_h264_entropy_mode - macroblocks is refreshed until the cycle completes and starts from the top of the frame. Applicable to H264, H263 and MPEG4 encoder. +``V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD (integer)`` + Intra macroblock refresh period. This sets the period to refresh + the whole frame. In other words, this defines the number of frames + for which the whole frame will be intra-refreshed. An example: + setting period to 1 means that the whole frame will be refreshed, + setting period to 2 means that the half of macroblocks will be + intra-refreshed on frameX and the other half of macroblocks + will be refreshed in frameX + 1 and so on. Setting period to zero + means no period is specified. Note that intra-refresh is mutually + exclusive with V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB control. + Applicable to H264 and HEVC encoders. + ``V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE (boolean)`` Frame level rate control enable. If this control is disabled then the quantization parameter for each frame type is constant and set diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index 016cf6204cbb..2ee463e08f1e 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -869,6 +869,7 @@ const char *v4l2_ctrl_get_name(u32 id) case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE: return "Decoder Slice Interface"; case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER: return "MPEG4 Loop Filter Enable"; case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: return "Number of Intra Refresh MBs"; + case V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD: return "Intra Refresh Period"; case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE: return "Frame Level Rate Control Enable"; case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE: return "H264 MB Level Rate Control"; case V4L2_CID_MPEG_VIDEO_HEADER_MODE: return "Sequence Header Mode"; @@ -1276,6 +1277,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, break; case V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE: case V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE: + case V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD: *type = V4L2_CTRL_TYPE_INTEGER; break; case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index 039c0d7add1b..1fddd9f0d4f1 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -428,6 +428,7 @@ enum v4l2_mpeg_video_multi_slice_mode { #define V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE (V4L2_CID_CODEC_BASE+228) #define V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME (V4L2_CID_CODEC_BASE+229) #define V4L2_CID_MPEG_VIDEO_BASELAYER_PRIORITY_ID (V4L2_CID_CODEC_BASE+230) +#define V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD (V4L2_CID_CODEC_BASE+231) /* CIDs for the MPEG-2 Part 2 (H.262) codec */ #define V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL (V4L2_CID_CODEC_BASE+270) From patchwork Tue Mar 2 09:53:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 392835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B7E0C28E88 for ; Wed, 3 Mar 2021 01:20:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE2CF64FA6 for ; Wed, 3 Mar 2021 01:20:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242117AbhCCBP1 (ORCPT ); Tue, 2 Mar 2021 20:15:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1577809AbhCBJyn (ORCPT ); Tue, 2 Mar 2021 04:54:43 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B74EEC0617A7 for ; Tue, 2 Mar 2021 01:54:02 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id dx17so6483578ejb.2 for ; Tue, 02 Mar 2021 01:54:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EdJzhp+FqGbnwXajAcOWTyezJi1vdCAgMV7g3U64BvE=; b=YgQInyUWTvGwp8jPCKBjOeGiWJ+75shBSiz2A4QcgVDROuE+TlXwnjpMluW1PmEwla n8+hC4No+gAM/JwGTfV7pfnKgiQqBlcI0L+rDNOlYbS/wcX3Bx1F6G2H9MCKc/pFM+KE QAlPtlHmGRmBLZydwere7wXRkYhlTVE5o3G5ruEKCQ1q7HS2R7YHbbN39Bwpyh2iigm7 8amWvGgi94kxuHupxsiKm0IV3vfe3hmoX4vz1WiYL1rBVNz2P/A82IYnx8DQou/Xu1pL uj267aAhg+TXRFgNxVo/tiGyFjqqFMcmY2w4Z0SrobsjltTnO1ZPavsA527EtokJf9iD Y1pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EdJzhp+FqGbnwXajAcOWTyezJi1vdCAgMV7g3U64BvE=; b=bQfgFGjm02fXmT96i/gO7GjhdbLFx2Mryml62DtITMtS3g9lc17my+trAefx5n7wwd ewt/aOJbnZCl5Wa3T3oPW66e3gy6H3Uo9dbMfcEX7KQvIB+ZAD3P/dYI9t6O/BdO00uW wvnb9yIZKi6ABzutXQm8ybGcS7yTagVkkS6hc7/FYIizzYecKPmaHka0PPDHn9PD9hAr 4CJS0Sjx4NGxviGV7JOl2L8dPVs1P28m2od1dQN1kyHLFsNimF9zgKdm007gUs87JLGf QOThCbcKOIS7sewSn+aOXeUQAChK3NJ0KNknHhi8TRMHcjH3Ijd5n5OrnQsy2S+M3ekP +Ctg== X-Gm-Message-State: AOAM530L5r0Xnl3qVJrQ1Y15T7Mj4etoW2BXPdoCmKXymy26Axb7bxQH b3gLW6lAav5nSY0EEUTsBcu566IeruAOJBAt X-Google-Smtp-Source: ABdhPJws8QMOHgtX0hmI2FudbbSYVTTdds5QWLCsp+oFND6r5MnM2K9QLLygahCAJqS28wkudoOfnQ== X-Received: by 2002:a17:906:4d44:: with SMTP id b4mr17521325ejv.338.1614678841487; Tue, 02 Mar 2021 01:54:01 -0800 (PST) Received: from localhost.localdomain (hst-208-217.medicom.bg. [84.238.208.217]) by smtp.gmail.com with ESMTPSA id be27sm2530535edb.47.2021.03.02.01.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 01:54:01 -0800 (PST) From: Stanimir Varbanov To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Cc: Ezequiel Garcia , nicolas.dufresne@collabora.com, Hans Verkuil , Stanimir Varbanov Subject: [PATCH v3 2/2] venus: venc: Add support for intra-refresh period Date: Tue, 2 Mar 2021 11:53:40 +0200 Message-Id: <20210302095340.3584204-3-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210302095340.3584204-1-stanimir.varbanov@linaro.org> References: <20210302095340.3584204-1-stanimir.varbanov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add support for intra-refresh period v4l2 control and drop cyclic intra-refresh macroblock control in the same time. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/core.h | 1 + drivers/media/platform/qcom/venus/venc.c | 28 +++++++++++++++++++ .../media/platform/qcom/venus/venc_ctrls.c | 13 ++++----- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index a252ed32cc14..8602b7af6a6f 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -222,6 +222,7 @@ struct venc_controls { u32 multi_slice_max_mb; u32 header_mode; + u32 intra_refresh_period; struct { u32 h264; diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index 6976ed553647..dcc9bd3475bf 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -546,6 +546,7 @@ static int venc_set_properties(struct venus_inst *inst) struct hfi_quantization quant; struct hfi_quantization_range quant_range; struct hfi_enable en; + struct hfi_intra_refresh intra_refresh = {}; u32 ptype, rate_control, bitrate; u32 profile, level; int ret; @@ -754,6 +755,33 @@ static int venc_set_properties(struct venus_inst *inst) if (ret) return ret; + if ((inst->fmt_cap->pixfmt == V4L2_PIX_FMT_H264 || + inst->fmt_cap->pixfmt == V4L2_PIX_FMT_HEVC) && + (rate_control == HFI_RATE_CONTROL_CBR_VFR || + rate_control == HFI_RATE_CONTROL_CBR_CFR)) { + intra_refresh.mode = HFI_INTRA_REFRESH_NONE; + intra_refresh.cir_mbs = 0; + + if (ctr->intra_refresh_period) { + u32 mbs; + + mbs = ALIGN(inst->width, 16) * ALIGN(inst->height, 16); + mbs /= 16 * 16; + if (mbs % ctr->intra_refresh_period) + mbs++; + mbs /= ctr->intra_refresh_period; + + intra_refresh.mode = HFI_INTRA_REFRESH_RANDOM; + intra_refresh.cir_mbs = mbs; + } + + ptype = HFI_PROPERTY_PARAM_VENC_INTRA_REFRESH; + + ret = hfi_session_set_property(inst, ptype, &intra_refresh); + if (ret) + return ret; + } + return 0; } diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media/platform/qcom/venus/venc_ctrls.c index a52b80055173..6909426882ac 100644 --- a/drivers/media/platform/qcom/venus/venc_ctrls.c +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c @@ -17,7 +17,6 @@ #define SLICE_BYTE_SIZE_MAX 1024 #define SLICE_BYTE_SIZE_MIN 1024 #define SLICE_MB_SIZE_MAX 300 -#define INTRA_REFRESH_MBS_MAX 300 #define AT_SLICE_BOUNDARY \ V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY @@ -224,8 +223,6 @@ static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl) } mutex_unlock(&inst->lock); break; - case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: - break; case V4L2_CID_MPEG_VIDEO_GOP_SIZE: ret = venc_calc_bpframes(ctrl->val, ctr->num_b_frames, &bframes, &ctr->num_p_frames); @@ -276,6 +273,9 @@ static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_MPEG_VIDEO_BASELAYER_PRIORITY_ID: ctr->base_priority_id = ctrl->val; break; + case V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD: + ctr->intra_refresh_period = ctrl->val; + break; default: return -EINVAL; } @@ -459,10 +459,6 @@ int venc_ctrl_init(struct venus_inst *inst) v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA, -6, 6, 1, 0); - v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, - V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB, - 0, INTRA_REFRESH_MBS_MAX, 1, 0); - v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, (1 << 16) - 1, 1, 30); @@ -497,6 +493,9 @@ int venc_ctrl_init(struct venus_inst *inst) v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, V4L2_CID_MPEG_VIDEO_BASELAYER_PRIORITY_ID, 0, 6, 1, 0); + v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, + V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD, 0, + ((4096 * 2304) >> 8), 1, 0); ret = inst->ctrl_handler.error; if (ret)