From patchwork Fri Aug 21 10:36:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 253540 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=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY,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 767D9C433E1 for ; Fri, 21 Aug 2020 10:38:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EF4820738 for ; Fri, 21 Aug 2020 10:38:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="P8vvNleH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727968AbgHUKiB (ORCPT ); Fri, 21 Aug 2020 06:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728738AbgHUKhX (ORCPT ); Fri, 21 Aug 2020 06:37:23 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FE65C061346 for ; Fri, 21 Aug 2020 03:37:23 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id d188so878023pfd.2 for ; Fri, 21 Aug 2020 03:37:23 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=ljhi/VG5P34Hs9+4uh6nLgqd8v+gNFS6fb+CvHrY46E=; b=P8vvNleHgwAynsmC6lsMKY3uwNUsNbZ452tZWs27SpnLxhe2UCnzODapTh66dRpnyW cCwYlU0eob1fTTdvoCMzGkcjlp1+7SWxMOF06GyRJReplD8lO+viqGBFPZffZ2j1PDpu m8gMb3YxQc5AJYYMpqR4GoYAPjzM9401B+4w0= 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=ljhi/VG5P34Hs9+4uh6nLgqd8v+gNFS6fb+CvHrY46E=; b=rKnoNhHU8RqkzvO2ijlD2i+szRlYmfWPEvtBKUIOWRxWB2sB1AHOcOKTffq+WDza+A mnSJ944Y8iVV+XuNsI+Z5cvuyKx96WEQW0nLOmEYHj+nXz1k0bmn+/IqjmKVcfyRn4Uu jdSw4V4SO16PLYNbkScN/BWIk129Yz4JEccl7y/AGNH1ZyZZMIRn/d9DxJpFYncglEd0 +hzBR9IYxurjuMBcegonLMKR2Vi+Y3ZIiW3Eaty6ORStBU+k6MKvuhWNSYoK1IuDIChk nCbdyqML7FpaTSXjZMEouBWRSFjOKdkIy6u9hWRD2sDCO+zfl4cI/f42CPx45oe5t9Gg 8F6Q== X-Gm-Message-State: AOAM532dzT7d6wwm+BGmXPqV2VGPQSR72yy/Yja2uzzoEbkW45KRlvZ3 fJ4SnSSFnmnS3DfjFKDACQXu+w== X-Google-Smtp-Source: ABdhPJxfUTmFDWyoXGgTXQnxxK5YQdD4uEr3YGTNDXasSVXq6ygIS2UJtCfWh+Z8fX1itWDOPrt+xg== X-Received: by 2002:a62:8416:: with SMTP id k22mr1930146pfd.293.1598006243121; Fri, 21 Aug 2020 03:37:23 -0700 (PDT) Received: from acourbot.tok.corp.google.com ([2401:fa00:8f:203:eeb1:d7ff:fe57:b7e5]) by smtp.gmail.com with ESMTPSA id y20sm2081525pfn.183.2020.08.21.03.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 03:37:22 -0700 (PDT) From: Alexandre Courbot To: Tiffany Lin , Andrew-CT Chen , Hans Verkuil , Yunfei Dong , Maoguang Meng , Matthias Brugger Cc: linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot Subject: [PATCH v4 15/17] media: mtk-vcodec: venc: support ENUM_FRAMESIZES on OUTPUT formats Date: Fri, 21 Aug 2020 19:36:06 +0900 Message-Id: <20200821103608.2310097-16-acourbot@chromium.org> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog In-Reply-To: <20200821103608.2310097-1-acourbot@chromium.org> References: <20200821103608.2310097-1-acourbot@chromium.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org v4l2-compliance requires ENUM_FRAMESIZES to support OUTPUT formats. Reuse mtk_venc_find_format() to make sure both queues are considered when serving an ENUM_FRAMESIZES. Signed-off-by: Alexandre Courbot --- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 71 +++++++++---------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c index f8d4fbe927f9..1b79185cf922 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c @@ -123,28 +123,44 @@ static int vidioc_enum_fmt(struct v4l2_fmtdesc *f, return 0; } +static const struct mtk_video_fmt *mtk_venc_find_format(u32 fourcc, + const struct mtk_vcodec_enc_pdata *pdata) +{ + const struct mtk_video_fmt *fmt; + unsigned int k; + + for (k = 0; k < pdata->num_capture_formats; k++) { + fmt = &pdata->capture_formats[k]; + if (fmt->fourcc == fourcc) + return fmt; + } + + for (k = 0; k < pdata->num_output_formats; k++) { + fmt = &pdata->output_formats[k]; + if (fmt->fourcc == fourcc) + return fmt; + } + + return NULL; +} + static int vidioc_enum_framesizes(struct file *file, void *fh, struct v4l2_frmsizeenum *fsize) { - const struct mtk_vcodec_enc_pdata *pdata = - fh_to_ctx(fh)->dev->venc_pdata; - int i = 0; + const struct mtk_video_fmt *fmt; if (fsize->index != 0) return -EINVAL; - for (i = 0; i < pdata->num_capture_formats; ++i) { - const struct mtk_video_fmt *fmt = &pdata->capture_formats[i]; + fmt = mtk_venc_find_format(fsize->pixel_format, + fh_to_ctx(fh)->dev->venc_pdata); + if (!fmt) + return -EINVAL; - if (fsize->pixel_format != fmt->fourcc) - continue; + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; + fsize->stepwise = mtk_venc_framesizes; - fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; - fsize->stepwise = mtk_venc_framesizes; - return 0; - } - - return -EINVAL; + return 0; } static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, @@ -222,27 +238,6 @@ static struct mtk_q_data *mtk_venc_get_q_data(struct mtk_vcodec_ctx *ctx, return &ctx->q_data[MTK_Q_DATA_DST]; } -static const struct mtk_video_fmt *mtk_venc_find_format(struct v4l2_format *f, - const struct mtk_vcodec_enc_pdata *pdata) -{ - const struct mtk_video_fmt *fmt; - unsigned int k; - - for (k = 0; k < pdata->num_capture_formats; k++) { - fmt = &pdata->capture_formats[k]; - if (fmt->fourcc == f->fmt.pix.pixelformat) - return fmt; - } - - for (k = 0; k < pdata->num_output_formats; k++) { - fmt = &pdata->output_formats[k]; - if (fmt->fourcc == f->fmt.pix.pixelformat) - return fmt; - } - - return NULL; -} - /* V4L2 specification suggests the driver corrects the format struct if any of * the dimensions is unsupported */ @@ -403,7 +398,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, void *priv, return -EINVAL; } - fmt = mtk_venc_find_format(f, pdata); + fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata); if (!fmt) { fmt = &ctx->dev->venc_pdata->capture_formats[0]; f->fmt.pix.pixelformat = fmt->fourcc; @@ -467,7 +462,7 @@ static int vidioc_venc_s_fmt_out(struct file *file, void *priv, return -EINVAL; } - fmt = mtk_venc_find_format(f, pdata); + fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata); if (!fmt) { fmt = &ctx->dev->venc_pdata->output_formats[0]; f->fmt.pix.pixelformat = fmt->fourcc; @@ -550,7 +545,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv, struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv); const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata; - fmt = mtk_venc_find_format(f, pdata); + fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata); if (!fmt) { fmt = &ctx->dev->venc_pdata->capture_formats[0]; f->fmt.pix.pixelformat = fmt->fourcc; @@ -570,7 +565,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv, struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv); const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata; - fmt = mtk_venc_find_format(f, pdata); + fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata); if (!fmt) { fmt = &ctx->dev->venc_pdata->output_formats[0]; f->fmt.pix.pixelformat = fmt->fourcc;