All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tretter <m.tretter@pengutronix.de>
To: linux-media@vger.kernel.org, hverkuil-cisco@xs4all.nl
Cc: kernel@pengutronix.de, mchehab@kernel.org
Subject: [PATCH v2 04/18] media: allegro: implement S_FMT for CAPTURE
Date: Fri, 15 Jan 2021 10:34:59 +0100	[thread overview]
Message-ID: <20210115093459.2349588-1-m.tretter@pengutronix.de> (raw)
In-Reply-To: <d05eaf25-d935-d9a8-bb6e-8b2a0656fb9c@xs4all.nl>

In order to support different codecs, the driver must support changing
the format on CAPTURE. Therefore, the driver needs to handle S_FMT on
CAPTURE.

As the driver will have a different number of formats for OUTPUT and
CAPTURE, split the check for the format index in ENUM_FMT into CAPTURE
and OUTPUT.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
Changelog:

v2:
- Add check for busy queue when setting the format

 .../media/platform/allegro-dvt/allegro-core.c | 30 +++++++++++++++++--
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
index 6b5cbee05040..fb3269cc4789 100644
--- a/drivers/media/platform/allegro-dvt/allegro-core.c
+++ b/drivers/media/platform/allegro-dvt/allegro-core.c
@@ -2503,13 +2503,15 @@ static int allegro_querycap(struct file *file, void *fh,
 static int allegro_enum_fmt_vid(struct file *file, void *fh,
 				struct v4l2_fmtdesc *f)
 {
-	if (f->index)
-		return -EINVAL;
 	switch (f->type) {
 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+		if (f->index >= 1)
+			return -EINVAL;
 		f->pixelformat = V4L2_PIX_FMT_NV12;
 		break;
 	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		if (f->index >= 1)
+			return -EINVAL;
 		f->pixelformat = V4L2_PIX_FMT_H264;
 		break;
 	default:
@@ -2557,6 +2559,28 @@ static int allegro_try_fmt_vid_cap(struct file *file, void *fh,
 	return 0;
 }
 
+static int allegro_s_fmt_vid_cap(struct file *file, void *fh,
+				 struct v4l2_format *f)
+{
+	struct allegro_channel *channel = fh_to_channel(fh);
+	struct vb2_queue *vq;
+	int err;
+
+	err = allegro_try_fmt_vid_cap(file, fh, f);
+	if (err)
+		return err;
+
+	vq = v4l2_m2m_get_vq(channel->fh.m2m_ctx, f->type);
+	if (!vq)
+		return -EINVAL;
+	if (vb2_is_busy(vq))
+		return -EBUSY;
+
+	channel->codec = f->fmt.pix.pixelformat;
+
+	return 0;
+}
+
 static int allegro_g_fmt_vid_out(struct file *file, void *fh,
 				 struct v4l2_format *f)
 {
@@ -2769,7 +2793,7 @@ static const struct v4l2_ioctl_ops allegro_ioctl_ops = {
 	.vidioc_enum_fmt_vid_out = allegro_enum_fmt_vid,
 	.vidioc_g_fmt_vid_cap = allegro_g_fmt_vid_cap,
 	.vidioc_try_fmt_vid_cap = allegro_try_fmt_vid_cap,
-	.vidioc_s_fmt_vid_cap = allegro_try_fmt_vid_cap,
+	.vidioc_s_fmt_vid_cap = allegro_s_fmt_vid_cap,
 	.vidioc_g_fmt_vid_out = allegro_g_fmt_vid_out,
 	.vidioc_try_fmt_vid_out = allegro_try_fmt_vid_out,
 	.vidioc_s_fmt_vid_out = allegro_s_fmt_vid_out,
-- 
2.20.1


  reply	other threads:[~2021-01-15  9:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 11:00 [PATCH 00/18] media: allegro: add HEVC support Michael Tretter
2020-12-03 11:00 ` [PATCH 01/18] media: allegro: extract RBSP handler from H.264 NAL generator Michael Tretter
2020-12-03 11:00 ` [PATCH 02/18] media: allegro: add helper to report unsupported fields Michael Tretter
2020-12-03 11:00 ` [PATCH 03/18] media: allegro: add HEVC NAL unit generator Michael Tretter
2020-12-03 11:00 ` [PATCH 04/18] media: allegro: implement S_FMT for CAPTURE Michael Tretter
2021-01-07 11:55   ` Hans Verkuil
2021-01-15  9:34     ` Michael Tretter [this message]
2020-12-03 11:00 ` [PATCH 05/18] media: allegro: adjust channel after format change Michael Tretter
2020-12-03 11:00 ` [PATCH 06/18] media: allegro: move encoding options to channel Michael Tretter
2020-12-03 11:00 ` [PATCH 07/18] media: allegro: fix log2_max_poc in firmware 2019.1 Michael Tretter
2020-12-03 11:00 ` [PATCH 08/18] media: allegro: use handler_setup to configure channel Michael Tretter
2020-12-03 11:00 ` [PATCH 09/18] media: allegro: initialize bitrate using v4l2_ctrl Michael Tretter
2020-12-03 11:00 ` [PATCH 10/18] media: allegro: implement scaling of cpb size in SPS Michael Tretter
2020-12-03 11:00 ` [PATCH 11/18] media: allegro: remove cpb_size and gop_size from channel Michael Tretter
2020-12-03 11:01 ` [PATCH 12/18] media: allegro: remove profile and level " Michael Tretter
2020-12-03 11:01 ` [PATCH 13/18] media: allegro: use accessor functions for QP values Michael Tretter
2020-12-03 11:01 ` [PATCH 14/18] media: allegro: add helper to get entropy mode Michael Tretter
2020-12-03 11:01 ` [PATCH 15/18] media: allegro: rename codec specific functions Michael Tretter
2020-12-03 11:01 ` [PATCH 16/18] media: allegro: increase offset in CAPTURE buffer Michael Tretter
2020-12-03 11:01 ` [PATCH 17/18] media: allegro: activate v4l2-ctrls only for current codec Michael Tretter
2020-12-03 11:01 ` [PATCH 18/18] media: allegro: add support for HEVC encoding Michael Tretter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210115093459.2349588-1-m.tretter@pengutronix.de \
    --to=m.tretter@pengutronix.de \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=kernel@pengutronix.de \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.