linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: khalasa@piap.pl (Krzysztof Hałasa)
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media <linux-media@vger.kernel.org>,
	Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Subject: [PATCH 10/12] TW686x: handle non-NULL format in queue_setup()
Date: Thu, 28 Jan 2016 10:09:35 +0100	[thread overview]
Message-ID: <m3lh7acbow.fsf@t19.piap.pl> (raw)
In-Reply-To: <m337tif6om.fsf@t19.piap.pl> ("Krzysztof \=\?utf-8\?Q\?Ha\=C5\=82as\?\= \=\?utf-8\?Q\?a\=22's\?\= message of "Thu, 28 Jan 2016 09:29:29 +0100")

Signed-off-by: Krzysztof Hałasa <khalasa@piap.pl>

diff --git a/drivers/media/pci/tw686x/tw686x-video.c b/drivers/media/pci/tw686x/tw686x-video.c
index 12cc108..cfc15e7 100644
--- a/drivers/media/pci/tw686x/tw686x-video.c
+++ b/drivers/media/pci/tw686x/tw686x-video.c
@@ -82,6 +82,50 @@ static const struct tw686x_format *format_by_fourcc(unsigned fourcc)
 	return NULL;
 }
 
+static void tw686x_get_format(struct tw686x_video_channel *vc,
+			      struct v4l2_format *f)
+{
+	const struct tw686x_format *format;
+	unsigned width, height, height_div = 1;
+
+	format = format_by_fourcc(f->fmt.pix.pixelformat);
+	if (!format) {
+		format = &formats[0];
+		f->fmt.pix.pixelformat = format->fourcc;
+	}
+
+	width = 704;
+	if (f->fmt.pix.width < width * 3 / 4 /* halfway */)
+		width /= 2;
+
+	height = (vc->video_standard & V4L2_STD_625_50) ? 576 : 480;
+	if (f->fmt.pix.height < height * 3 / 4 /* halfway */)
+		height_div = 2;
+
+	switch (f->fmt.pix.field) {
+	case V4L2_FIELD_TOP:
+	case V4L2_FIELD_BOTTOM:
+		height_div = 2;
+		break;
+	case V4L2_FIELD_SEQ_BT:
+		if (height_div > 1)
+			f->fmt.pix.field = V4L2_FIELD_BOTTOM;
+		break;
+	default:
+		if (height_div > 1)
+			f->fmt.pix.field = V4L2_FIELD_TOP;
+		else
+			f->fmt.pix.field = V4L2_FIELD_SEQ_TB;
+	}
+	height /= height_div;
+
+	f->fmt.pix.width = width;
+	f->fmt.pix.height = height;
+	f->fmt.pix.bytesperline = f->fmt.pix.width * format->depth / 8;
+	f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
+	f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
+}
+
 /* video queue operations */
 
 static int tw686x_queue_setup(struct vb2_queue *vq, const void *arg,
@@ -90,12 +134,17 @@ static int tw686x_queue_setup(struct vb2_queue *vq, const void *arg,
 {
 	struct tw686x_video_channel *vc = vb2_get_drv_priv(vq);
 
-	sizes[0] = vc->width * vc->height * vc->format->depth / 8;
+	if (arg) {
+		struct v4l2_format fmt = *(const struct v4l2_format*)arg;
+		tw686x_get_format(vc, &fmt);
+		sizes[0] = fmt.fmt.pix.sizeimage;
+	} else
+		sizes[0] = vc->width * vc->height * vc->format->depth / 8;
+
 	alloc_ctxs[0] = vc->alloc_ctx;
 	*nplanes = 1;		/* packed formats only */
 	if (*nbuffers < 2)
 		*nbuffers = 2;
-
 	return 0;
 }
 
@@ -340,47 +389,7 @@ static int tw686x_g_fmt_vid_cap(struct file *file, void *priv,
 static int tw686x_try_fmt_vid_cap(struct file *file, void *priv,
 				  struct v4l2_format *f)
 {
-	struct tw686x_video_channel *vc = video_drvdata(file);
-	const struct tw686x_format *format;
-	unsigned width, height, height_div = 1;
-
-	format = format_by_fourcc(f->fmt.pix.pixelformat);
-	if (!format) {
-		format = &formats[0];
-		f->fmt.pix.pixelformat = format->fourcc;
-	}
-
-	width = 704;
-	if (f->fmt.pix.width < width * 3 / 4 /* halfway */)
-		width /= 2;
-
-	height = (vc->video_standard & V4L2_STD_625_50) ? 576 : 480;
-	if (f->fmt.pix.height < height * 3 / 4 /* halfway */)
-		height_div = 2;
-
-	switch (f->fmt.pix.field) {
-	case V4L2_FIELD_TOP:
-	case V4L2_FIELD_BOTTOM:
-		height_div = 2;
-		break;
-	case V4L2_FIELD_SEQ_BT:
-		if (height_div > 1)
-			f->fmt.pix.field = V4L2_FIELD_BOTTOM;
-		break;
-	default:
-		if (height_div > 1)
-			f->fmt.pix.field = V4L2_FIELD_TOP;
-		else
-			f->fmt.pix.field = V4L2_FIELD_SEQ_TB;
-	}
-	height /= height_div;
-
-	f->fmt.pix.width = width;
-	f->fmt.pix.height = height;
-	f->fmt.pix.bytesperline = f->fmt.pix.width * format->depth / 8;
-	f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
-	f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
-
+	tw686x_get_format(video_drvdata(file), f);
 	return 0;
 }
 
@@ -388,12 +397,8 @@ static int tw686x_s_fmt_vid_cap(struct file *file, void *priv,
 				struct v4l2_format *f)
 {
 	struct tw686x_video_channel *vc = video_drvdata(file);
-	int err;
-
-	err = tw686x_try_fmt_vid_cap(file, priv, f);
-	if (err)
-		return err;
 
+	tw686x_get_format(vc, f);
 	vc->format = format_by_fourcc(f->fmt.pix.pixelformat);
 	vc->field = f->fmt.pix.field;
 	vc->width = f->fmt.pix.width;

  parent reply	other threads:[~2016-01-28  9:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-28  8:29 [PATCH 0/12] TW686x driver Krzysztof Hałasa
2016-01-28  8:53 ` [PATCH 1/12] Add support for TW686[4589]-based frame grabbers Krzysztof Hałasa
2016-01-28  8:57 ` [PATCH 2/12] TW686x: Trivial changes suggested by Ezequiel Garcia Krzysztof Hałasa
2016-01-28  9:01 ` [PATCH 3/12] TW686x: Switch to devm_*() Krzysztof Hałasa
2016-01-28  9:01 ` [PATCH 4/12] TW686x: Fix s_std() / g_std() / g_parm() pointer to self Krzysztof Hałasa
2016-01-28  9:03 ` [PATCH 5/12] TW686x: Fix handling of TV standard values Krzysztof Hałasa
2016-01-28  9:04 ` [PATCH 6/12] TW686x: Fix try_fmt() color space Krzysztof Hałasa
2016-01-28  9:05 ` [PATCH 7/12] TW686x: Add enum_input() / g_input() / s_input() Krzysztof Hałasa
2016-01-28  9:06 ` [PATCH 8/12] TW686x: do not use pci_dma_supported() Krzysztof Hałasa
2016-01-28  9:08 ` [PATCH 9/12] TW686x: switch to vb2_v4l2_buffer Krzysztof Hałasa
2016-01-28  9:09 ` Krzysztof Hałasa [this message]
2016-01-28  9:10 ` [PATCH 11/12] TW686x: Track frame sequence numbers Krzysztof Hałasa
2016-01-28  9:11 ` [PATCH 12/12] TW686x: return VB2_BUF_STATE_ERROR frames on timeout/errors Krzysztof Hałasa
2016-01-28  9:13 ` [PATCH 0/12] TW686x driver Krzysztof Hałasa
2016-01-28  9:18 ` [PATCH 3/12] TW686x: Switch to devm_*() Krzysztof Hałasa
2016-01-28  9:19 ` [PATCH 4/12] TW686x: Fix s_std() / g_std() / g_parm() pointer to self Krzysztof Hałasa
2016-02-08 10:49 ` [PATCH 0/12] TW686x driver Hans Verkuil
2016-02-15 14:25   ` Krzysztof Hałasa
2016-02-16  9:09   ` Krzysztof Hałasa

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=m3lh7acbow.fsf@t19.piap.pl \
    --to=khalasa@piap.pl \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).