diff mbox

[2/2] v4l: simulate old crop API using extcrop/compose

Message ID 1302079459-4018-3-git-send-email-t.stanislaws@samsung.com (mailing list archive)
State RFC
Headers show

Commit Message

Tomasz Stanislawski April 6, 2011, 8:44 a.m. UTC
This patch allows new drivers to work correctly with
applications that use old-style crop API.
The old crop ioctl is simulated by using extcrop/compose.

Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com>
---
 drivers/media/video/v4l2-ioctl.c |   94 +++++++++++++++++++++++++++++++++-----
 1 files changed, 82 insertions(+), 12 deletions(-)
diff mbox

Patch

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 3f69218..1e7d18d 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -1725,11 +1725,30 @@  static long __video_do_ioctl(struct file *file,
 	{
 		struct v4l2_crop *p = arg;
 
-		if (!ops->vidioc_g_crop)
-			break;
-
 		dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-		ret = ops->vidioc_g_crop(file, fh, p);
+
+		if (ops->vidioc_g_crop) {
+			ret = ops->vidioc_g_crop(file, fh, p);
+		} else {
+			struct v4l2_selection s = {
+				.type = p->type,
+				.target = V4L2_SEL_TARGET_ACTIVE,
+			};
+			/* simulate capture crop using extcrop */
+			if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
+				&& ops->vidioc_g_extcrop) {
+				ret = ops->vidioc_g_extcrop(file, fh, &s);
+			}
+			/* simulate output crop using compose */
+			if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT
+				&& ops->vidioc_g_compose) {
+				ret = ops->vidioc_g_compose(file, fh, &s);
+			}
+			/* copying results to old structure */
+			if (!ret)
+				p->c = s.r;
+		}
+
 		if (!ret)
 			dbgrect(vfd, "", &p->c);
 		break;
@@ -1738,11 +1757,28 @@  static long __video_do_ioctl(struct file *file,
 	{
 		struct v4l2_crop *p = arg;
 
-		if (!ops->vidioc_s_crop)
-			break;
 		dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
 		dbgrect(vfd, "", &p->c);
-		ret = ops->vidioc_s_crop(file, fh, p);
+
+		if (ops->vidioc_s_crop) {
+			ret = ops->vidioc_s_crop(file, fh, p);
+		} else {
+			struct v4l2_selection s = {
+				.type = p->type,
+				.target = V4L2_SEL_TARGET_ACTIVE,
+				.r = p->c,
+			};
+			/* simulate capture crop using extcrop */
+			if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
+				&& ops->vidioc_s_extcrop) {
+				ret = ops->vidioc_s_extcrop(file, fh, &s);
+			}
+			/* simulate output crop using compose */
+			if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT
+				&& ops->vidioc_s_compose) {
+				ret = ops->vidioc_s_compose(file, fh, &s);
+			}
+		}
 		break;
 	}
 	case VIDIOC_G_EXTCROP:
@@ -1801,12 +1837,46 @@  static long __video_do_ioctl(struct file *file,
 	{
 		struct v4l2_cropcap *p = arg;
 
-		/*FIXME: Should also show v4l2_fract pixelaspect */
-		if (!ops->vidioc_cropcap)
-			break;
-
 		dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-		ret = ops->vidioc_cropcap(file, fh, p);
+		if (ops->vidioc_cropcap) {
+			ret = ops->vidioc_cropcap(file, fh, p);
+		} else {
+			struct v4l2_selection s = { .type = p->type };
+			int (*func)(struct file *file, void *fh,
+				struct v4l2_selection *a) = NULL;
+			struct v4l2_rect bounds;
+
+			/* simulate capture crop using extcrop */
+			if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+				func = ops->vidioc_g_extcrop;
+			/* simulate output crop using compose */
+			if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
+				func = ops->vidioc_g_compose;
+			/* leave if cropcap can not be simulated */
+			if (func == NULL)
+				break;
+
+			/* obtaining bounds */
+			s.target = V4L2_SEL_TARGET_BOUNDS;
+			ret = func(file, fh, &s);
+			if (ret)
+				break;
+			bounds = s.r;
+
+			/* obtaining defrect */
+			s.target = V4L2_SEL_TARGET_DEFAULT;
+			ret = func(file, fh, &s);
+			if (ret)
+				break;
+
+			/* storing results */
+			p->bounds = bounds;
+			p->defrect = s.r;
+			p->pixelaspect.numerator = 1;
+			p->pixelaspect.denominator = 1;
+		}
+
+		/*FIXME: Should also show v4l2_fract pixelaspect */
 		if (!ret) {
 			dbgrect(vfd, "bounds ", &p->bounds);
 			dbgrect(vfd, "defrect ", &p->defrect);