Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4714307pxf; Tue, 30 Mar 2021 15:20:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3JC7eunil1CJB2SGDdl1WZkLc/crGTYe99BK0FWjf5VrRv+LL5TbU2GhntSri78XzXfQp X-Received: by 2002:a17:906:c0c8:: with SMTP id bn8mr301273ejb.445.1617142803391; Tue, 30 Mar 2021 15:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617142803; cv=none; d=google.com; s=arc-20160816; b=Ke2zP4v9bjM1rX5BKj3xf6TgYryqkZG1ElKQbAo6vOAmzSH6M7bkb1dEgwqKpO+4E8 b5vUZqNiGsyrDvGrzgslxJbxt9VDnoZ551yr35updYNNwLQ/Y5u5kUoKLhK+qrWikNX8 7aSbX7Tvp1xey1YZ2WhW0yRWVm747W8Bc8pgJqgxkfGD5WJynNL2SwI9z1rOTZnkJS7S PG6JaGer3nn1APJ1Vi9nkzzBSGrQIzPRthEI+KrgK/tcg+b6VOz0PbJu8bawmTi+UyOf 1vpkCQk7JFgQyWEK6OTY4mWpP6ksNscWcJHsn9PfI2pKI0hDKZ08x0BqnJyN44YNwJ0P sjuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=CEJVo99ddrzFsx+Y7vim0XaXbjg0vh0wW249qitilJc=; b=yp0YNZx9o0xBHr/afd3n6TKTcbVYrDZQD4cgTIX47T2PnplDfNceXeUqReINPTatZd +za4lrZAlg7kyrLTPY0EIn5SIvhUjLFuIW6pFgFa7LoKDH+KjWhJFckTyDHv7RuWuBMd dEFVmXlIyqzx7aQxcWrnskvgzg7YHkpoU1KToIbjNc3C1X+PnJgQzb/LgTxV88yWVsa5 ziq6HB5ItOb3WvreV91DIsBol7KAADG2Y8FFWraWf2YUgQLCFgrcyEAXsWM6F8tSqOVb N+mAHjgLBi/gfnMvrrZvcL68+TJHpycAxZj7IeYT6FMQDJw9L91yNITyosmp57bUbk1C oHqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=meUgQ8Xu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si203370edq.597.2021.03.30.15.19.40; Tue, 30 Mar 2021 15:20:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=meUgQ8Xu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232307AbhC3WPp (ORCPT + 99 others); Tue, 30 Mar 2021 18:15:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231951AbhC3WPO (ORCPT ); Tue, 30 Mar 2021 18:15:14 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7A33C061574 for ; Tue, 30 Mar 2021 15:15:14 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id t18so8474768pjs.3 for ; Tue, 30 Mar 2021 15:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CEJVo99ddrzFsx+Y7vim0XaXbjg0vh0wW249qitilJc=; b=meUgQ8XuuGX2w/BSIG4Hz4EF7XC9+2efqf9gHbw/McANGT1S0Z0TwooXm0EwVoeeC9 VE8+hDP4ClO6laZGUWRq3SVtNUY/kdGhkrNvjHfnz4qTguvnPvdB9sio+aLJYHTz63na 0F//yTUTwk/POk31IhOjDpQm/II1tGnLMgLPg= 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:mime-version :content-transfer-encoding; bh=CEJVo99ddrzFsx+Y7vim0XaXbjg0vh0wW249qitilJc=; b=cxn/Irm8EqX8UJ9s6toEUruFrIf6B1aSFyW4YYjWf4pSdcDeqPFmDQ3DcbGgSvRppj pYtIBN/Rm0ABylagetFdP7qphp4RMAPRgoZYWl5/k11tZ16tx62+c6ySL5dSEkVSkbg7 LF6Sq4l/iLQAxy5F/q4eROYuxnzUVIiiUN0y5gs1H1cgVnOVy3DLJVZXSiycWVXSUnDo YVa9/A5E+nPgH/8F2aE9QIOiCc62yMXjN2yznWB0fgs0cX3LkueNW72bHD87yZaXFHCJ kwYQ0x7nt2j9XLYJibhVv3yhlEKPgI43jmiP4/QIKstqZqDCUmMfkxwUEWuDy1PiN3iT VInA== X-Gm-Message-State: AOAM533l9sUXS+F5E+iYALUZsshhjziC5LdsFpcaDqThg8nK9kMQ7SsB Dlp7nprr/P1X4tB4F9Qd/s+uTg== X-Received: by 2002:a17:90a:8b07:: with SMTP id y7mr439343pjn.78.1617142514280; Tue, 30 Mar 2021 15:15:14 -0700 (PDT) Received: from localhost (201.59.83.34.bc.googleusercontent.com. [34.83.59.201]) by smtp.gmail.com with UTF8SMTPSA id q66sm124518pja.27.2021.03.30.15.15.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Mar 2021 15:15:13 -0700 (PDT) From: Fritz Koenig To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, tiffany.lin@mediatek.com, acourbot@chromium.org Cc: Fritz Koenig Subject: [PATCH] media: mtk-vcodec: vdec: Reduce padding in VIDIOC_TRY_FMT Date: Tue, 30 Mar 2021 22:15:06 +0000 Message-Id: <20210330221506.2278606-1-frkoenig@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the header has been parsed or the codec is stateless reduce the padding of the decoded frame. In stateless codecs width and height are specified by the application. Signed-off-by: Fritz Koenig --- .../platform/mtk-vcodec/mtk_vcodec_dec.c | 59 ++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c index 56d86e59421e..9c88454dc10c 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c @@ -653,7 +653,7 @@ static int vidioc_vdec_subscribe_evt(struct v4l2_fh *fh, } } -static int vidioc_try_fmt(struct v4l2_format *f, +static int vidioc_try_fmt(struct v4l2_format *f, void *priv, const struct mtk_video_fmt *fmt) { struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp; @@ -665,6 +665,7 @@ static int vidioc_try_fmt(struct v4l2_format *f, pix_fmt_mp->plane_fmt[0].bytesperline = 0; } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { int tmp_w, tmp_h; + struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv); pix_fmt_mp->height = clamp(pix_fmt_mp->height, MTK_VDEC_MIN_H, @@ -673,27 +674,45 @@ static int vidioc_try_fmt(struct v4l2_format *f, MTK_VDEC_MIN_W, MTK_VDEC_MAX_W); + tmp_w = pix_fmt_mp->width; + tmp_h = pix_fmt_mp->height; + + if (ctx->dev->vdec_pdata->uses_stateless_api || + ctx->state >= MTK_STATE_HEADER) { + v4l_bound_align_image(&pix_fmt_mp->width, + MTK_VDEC_MIN_W, + MTK_VDEC_MAX_W, 4, + &pix_fmt_mp->height, + MTK_VDEC_MIN_H, + MTK_VDEC_MAX_H, 5, 6); + + if (pix_fmt_mp->width < tmp_w && + (pix_fmt_mp->width + 16) <= MTK_VDEC_MAX_W) + pix_fmt_mp->width += 16; + if (pix_fmt_mp->height < tmp_h && + (pix_fmt_mp->height + 32) <= MTK_VDEC_MAX_H) + pix_fmt_mp->height += 32; + } else { /* - * Find next closer width align 64, heign align 64, size align + * Find next closer width align 64, height align 64, size align * 64 rectangle * Note: This only get default value, the real HW needed value * only available when ctx in MTK_STATE_HEADER state */ - tmp_w = pix_fmt_mp->width; - tmp_h = pix_fmt_mp->height; - v4l_bound_align_image(&pix_fmt_mp->width, - MTK_VDEC_MIN_W, - MTK_VDEC_MAX_W, 6, - &pix_fmt_mp->height, - MTK_VDEC_MIN_H, - MTK_VDEC_MAX_H, 6, 9); - - if (pix_fmt_mp->width < tmp_w && - (pix_fmt_mp->width + 64) <= MTK_VDEC_MAX_W) - pix_fmt_mp->width += 64; - if (pix_fmt_mp->height < tmp_h && - (pix_fmt_mp->height + 64) <= MTK_VDEC_MAX_H) - pix_fmt_mp->height += 64; + v4l_bound_align_image(&pix_fmt_mp->width, + MTK_VDEC_MIN_W, + MTK_VDEC_MAX_W, 6, + &pix_fmt_mp->height, + MTK_VDEC_MIN_H, + MTK_VDEC_MAX_H, 6, 9); + + if (pix_fmt_mp->width < tmp_w && + (pix_fmt_mp->width + 64) <= MTK_VDEC_MAX_W) + pix_fmt_mp->width += 64; + if (pix_fmt_mp->height < tmp_h && + (pix_fmt_mp->height + 64) <= MTK_VDEC_MAX_H) + pix_fmt_mp->height += 64; + } mtk_v4l2_debug(0, "before resize width=%d, height=%d, after resize width=%d, height=%d, sizeimage=%d", @@ -729,7 +748,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv, fmt = mtk_vdec_find_format(f); } - return vidioc_try_fmt(f, fmt); + return vidioc_try_fmt(f, priv, fmt); } static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv, @@ -749,7 +768,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv, return -EINVAL; } - return vidioc_try_fmt(f, fmt); + return vidioc_try_fmt(f, priv, fmt); } static int vidioc_vdec_g_selection(struct file *file, void *priv, @@ -875,7 +894,7 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv, return -EINVAL; q_data->fmt = fmt; - vidioc_try_fmt(f, q_data->fmt); + vidioc_try_fmt(f, priv, q_data->fmt); if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { q_data->sizeimage[0] = pix_mp->plane_fmt[0].sizeimage; q_data->coded_width = pix_mp->width; -- 2.31.0.291.g576ba9dcdaf-goog