From patchwork Fri Aug 18 14:16:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 110394 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp890359obb; Fri, 18 Aug 2017 07:17:37 -0700 (PDT) X-Received: by 10.84.128.8 with SMTP id 8mr9820294pla.391.1503065857664; Fri, 18 Aug 2017 07:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503065857; cv=none; d=google.com; s=arc-20160816; b=OBapm7OUgU39YzRsJCQ+bhC9PwCGkGrObzgN8aBQXI1ED/T/iLnv2In6Tvz4QtwCN6 Zn0L8/7+4TcDogI6iXK73wgh6DkYcSe6EjRaq42T//zMhhcegNKz/vn4dihwNOiqTbPN /rD5C4StuUZWewK93xVSxOiuNZL8tPGaBubcgZh1BjFh2AvU8SLI9TeOLijiz6iQC7sX K67JKcPc3lzXu3b9PPzxmTc6E1Nh/QKNgaLhnamtwrEm1kjpxg0m3GWTU+4MfjURihhG hH+MIB/DFzjCqCVHnTLVRL5xM61H7mx5qj59Du/86DdIjXTtbqOmebonLtJ7B+VoGR/2 vo4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=JUcb4HvTZWV0yKtvl9xHmW1BdrAcrjHvWwV4dagX/qs=; b=ulaeEoTY4+6Pp3EHd5wyrf/zQ6Tn88mcOCMnkC7uBibc9pjCkTP5tvtWlshM48I69p 4Qo4DL8TVZp0zD26R3Hi3JIypmigPJMkrXdUyEmv1MGkec5ukL/WcTVDyFaJAnIPVgIN wvZumOWzyApjKF5p206uWVt9HbDOEEvN2SAoWycyGDiq9+aW0d5v5RAiCK17cioGRxGO dDSo4S8oGZak2qrPZ7+7SyAtwLBGKzeo+K4vWtmgEt+Evv2zEhzyDkQaeZSNSw64rKS3 IDjP+BzTQ6n9MZ8O73wDh27VZQAWyUz4MJg8oEop+MU6bLih5Ajnzbmo+eatFPdXq2tS 9Unw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eWncoVqo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 102si4026753ple.858.2017.08.18.07.17.36; Fri, 18 Aug 2017 07:17:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eWncoVqo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753594AbdHRORe (ORCPT + 26 others); Fri, 18 Aug 2017 10:17:34 -0400 Received: from mail-wr0-f169.google.com ([209.85.128.169]:33960 "EHLO mail-wr0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753462AbdHROQ5 (ORCPT ); Fri, 18 Aug 2017 10:16:57 -0400 Received: by mail-wr0-f169.google.com with SMTP id y96so68404912wrc.1 for ; Fri, 18 Aug 2017 07:16:56 -0700 (PDT) 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; bh=JUcb4HvTZWV0yKtvl9xHmW1BdrAcrjHvWwV4dagX/qs=; b=eWncoVqo8jLCgstxd8NQiipD69WhX9N4uYINDczdle4aScmNE0T34IA51Gy6ST0CU0 04T4+WJy3vhtS5wbCWIPWo/xmMUEYwGw9y8fBeMku1PMnHPI/iGcrukpdbLuOol1D6lp C5ozC98CxGMPeO4IvGTSNvTURL3ExvEASRU2Y= 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; bh=JUcb4HvTZWV0yKtvl9xHmW1BdrAcrjHvWwV4dagX/qs=; b=FRIbaZ56HmfHpB7C/tPaE9GmOrQtVLx+NHIhH3tByPeCwPewMQrCclo8YC0nuiRmXa tqd3C5S0BuKhVsDthHj9E/PUNROfltOvgKyNvCamhUKdjTV77xM7+1d1bDwbeTWT/1J0 YqmKCcKEd0ghDZTiUMYCcWACqZKKfAruioH8IshVF0dEkXNQh/k+WQCjmj/xGm5fjbIQ p7bELlYfSgvTJB+s38+bwf8lcjnjm0YwJy5FTKgUlhsqne9sGHotd6PZSZrfnKIAkkRJ VH46aFc5khPmYveomevxLEkkEPj/cxy6xDlfmw8ie4ZVwnq8O4bEDgyL58DnECKgz4nF qo9A== X-Gm-Message-State: AHYfb5h0JQhVU3iX1qrc4WfQkuMoh9QAbDdw00x5YM/e7wPp45wzGJg7 aNLkmdMvHFnOEeVF X-Received: by 10.223.136.104 with SMTP id e37mr1372440wre.152.1503065815857; Fri, 18 Aug 2017 07:16:55 -0700 (PDT) Received: from localhost.localdomain ([37.157.136.206]) by smtp.gmail.com with ESMTPSA id 55sm1387383wrv.32.2017.08.18.07.16.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 07:16:55 -0700 (PDT) From: Stanimir Varbanov To: Mauro Carvalho Chehab , Hans Verkuil Cc: Pawel Osciak , Marek Szyprowski , Kyungmin Park , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Stanimir Varbanov Subject: [PATCH 6/7] media: venus: use helper function to check supported codecs Date: Fri, 18 Aug 2017 17:16:05 +0300 Message-Id: <20170818141606.4835-7-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170818141606.4835-1-stanimir.varbanov@linaro.org> References: <20170818141606.4835-1-stanimir.varbanov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the helper function in decoder and encoder find_format to runtime check supported codecs. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/vdec.c | 24 +++++++++++++++++------- drivers/media/platform/qcom/venus/venc.c | 28 +++++++++++++++++++--------- 2 files changed, 36 insertions(+), 16 deletions(-) -- 2.11.0 diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index 32a1feb2fe6a..da611a5eb670 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -102,7 +102,8 @@ static const struct venus_format vdec_formats[] = { }, }; -static const struct venus_format *find_format(u32 pixfmt, u32 type) +static const struct venus_format * +find_format(struct venus_inst *inst, u32 pixfmt, u32 type) { const struct venus_format *fmt = vdec_formats; unsigned int size = ARRAY_SIZE(vdec_formats); @@ -116,11 +117,15 @@ static const struct venus_format *find_format(u32 pixfmt, u32 type) if (i == size || fmt[i].type != type) return NULL; + if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && + !venus_helper_check_codec(inst, fmt[i].pixfmt)) + return NULL; + return &fmt[i]; } static const struct venus_format * -find_format_by_index(unsigned int index, u32 type) +find_format_by_index(struct venus_inst *inst, unsigned int index, u32 type) { const struct venus_format *fmt = vdec_formats; unsigned int size = ARRAY_SIZE(vdec_formats); @@ -140,6 +145,10 @@ find_format_by_index(unsigned int index, u32 type) if (i == size) return NULL; + if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && + !venus_helper_check_codec(inst, fmt[i].pixfmt)) + return NULL; + return &fmt[i]; } @@ -154,7 +163,7 @@ vdec_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) memset(pfmt[0].reserved, 0, sizeof(pfmt[0].reserved)); memset(pixmp->reserved, 0, sizeof(pixmp->reserved)); - fmt = find_format(pixmp->pixelformat, f->type); + fmt = find_format(inst, pixmp->pixelformat, f->type); if (!fmt) { if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) pixmp->pixelformat = V4L2_PIX_FMT_NV12; @@ -162,7 +171,7 @@ vdec_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) pixmp->pixelformat = V4L2_PIX_FMT_H264; else return NULL; - fmt = find_format(pixmp->pixelformat, f->type); + fmt = find_format(inst, pixmp->pixelformat, f->type); pixmp->width = 1280; pixmp->height = 720; } @@ -364,11 +373,12 @@ vdec_querycap(struct file *file, void *fh, struct v4l2_capability *cap) static int vdec_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f) { + struct venus_inst *inst = to_inst(file); const struct venus_format *fmt; memset(f->reserved, 0, sizeof(f->reserved)); - fmt = find_format_by_index(f->index, f->type); + fmt = find_format_by_index(inst, f->index, f->type); if (!fmt) return -EINVAL; @@ -417,10 +427,10 @@ static int vdec_enum_framesizes(struct file *file, void *fh, struct venus_inst *inst = to_inst(file); const struct venus_format *fmt; - fmt = find_format(fsize->pixel_format, + fmt = find_format(inst, fsize->pixel_format, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); if (!fmt) { - fmt = find_format(fsize->pixel_format, + fmt = find_format(inst, fsize->pixel_format, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); if (!fmt) return -EINVAL; diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index bcb50d39f88a..9f459024aa07 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -91,7 +91,8 @@ static const struct venus_format venc_formats[] = { }, }; -static const struct venus_format *find_format(u32 pixfmt, u32 type) +static const struct venus_format * +find_format(struct venus_inst *inst, u32 pixfmt, u32 type) { const struct venus_format *fmt = venc_formats; unsigned int size = ARRAY_SIZE(venc_formats); @@ -105,11 +106,15 @@ static const struct venus_format *find_format(u32 pixfmt, u32 type) if (i == size || fmt[i].type != type) return NULL; + if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && + !venus_helper_check_codec(inst, fmt[i].pixfmt)) + return NULL; + return &fmt[i]; } static const struct venus_format * -find_format_by_index(unsigned int index, u32 type) +find_format_by_index(struct venus_inst *inst, unsigned int index, u32 type) { const struct venus_format *fmt = venc_formats; unsigned int size = ARRAY_SIZE(venc_formats); @@ -129,6 +134,10 @@ find_format_by_index(unsigned int index, u32 type) if (i == size) return NULL; + if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && + !venus_helper_check_codec(inst, fmt[i].pixfmt)) + return NULL; + return &fmt[i]; } @@ -246,9 +255,10 @@ venc_querycap(struct file *file, void *fh, struct v4l2_capability *cap) static int venc_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *f) { + struct venus_inst *inst = to_inst(file); const struct venus_format *fmt; - fmt = find_format_by_index(f->index, f->type); + fmt = find_format_by_index(inst, f->index, f->type); memset(f->reserved, 0, sizeof(f->reserved)); @@ -271,7 +281,7 @@ venc_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) memset(pfmt[0].reserved, 0, sizeof(pfmt[0].reserved)); memset(pixmp->reserved, 0, sizeof(pixmp->reserved)); - fmt = find_format(pixmp->pixelformat, f->type); + fmt = find_format(inst, pixmp->pixelformat, f->type); if (!fmt) { if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) pixmp->pixelformat = V4L2_PIX_FMT_H264; @@ -279,7 +289,7 @@ venc_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f) pixmp->pixelformat = V4L2_PIX_FMT_NV12; else return NULL; - fmt = find_format(pixmp->pixelformat, f->type); + fmt = find_format(inst, pixmp->pixelformat, f->type); pixmp->width = 1280; pixmp->height = 720; } @@ -524,10 +534,10 @@ static int venc_enum_framesizes(struct file *file, void *fh, fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; - fmt = find_format(fsize->pixel_format, + fmt = find_format(inst, fsize->pixel_format, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); if (!fmt) { - fmt = find_format(fsize->pixel_format, + fmt = find_format(inst, fsize->pixel_format, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); if (!fmt) return -EINVAL; @@ -554,10 +564,10 @@ static int venc_enum_frameintervals(struct file *file, void *fh, fival->type = V4L2_FRMIVAL_TYPE_STEPWISE; - fmt = find_format(fival->pixel_format, + fmt = find_format(inst, fival->pixel_format, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); if (!fmt) { - fmt = find_format(fival->pixel_format, + fmt = find_format(inst, fival->pixel_format, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); if (!fmt) return -EINVAL;