From patchwork Thu May 5 09:39:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 756322 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p459eHRg006562 for ; Thu, 5 May 2011 09:40:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753171Ab1EEJkP (ORCPT ); Thu, 5 May 2011 05:40:15 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:28488 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751262Ab1EEJkO (ORCPT ); Thu, 5 May 2011 05:40:14 -0400 Received: from spt2.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by mailout1.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0LKP00DBKUV05D@mailout1.w1.samsung.com> for linux-media@vger.kernel.org; Thu, 05 May 2011 10:40:13 +0100 (BST) Received: from linux.samsung.com ([106.116.38.10]) by spt2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0LKP00A9OUUZ2B@spt2.w1.samsung.com> for linux-media@vger.kernel.org; Thu, 05 May 2011 10:40:11 +0100 (BST) Received: from localhost.localdomain (unknown [106.116.38.10]) by linux.samsung.com (Postfix) with ESMTP id 2E17627006F; Thu, 05 May 2011 11:41:32 +0200 (CEST) Date: Thu, 05 May 2011 11:39:56 +0200 From: Tomasz Stanislawski Subject: [PATCH 2/2] v4l: simulate old crop API using extended crop/compose API In-reply-to: <1304588396-7557-1-git-send-email-t.stanislaws@samsung.com> To: linux-media@vger.kernel.org Cc: m.szyprowski@samsung.com, kyungmin.park@samsung.com, hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, sakari.ailus@maxwell.research.nokia.com, Tomasz Stanislawski Message-id: <1304588396-7557-3-git-send-email-t.stanislaws@samsung.com> MIME-version: 1.0 X-Mailer: git-send-email 1.7.2.5 Content-type: TEXT/PLAIN Content-transfer-encoding: 7BIT References: <1304588396-7557-1-git-send-email-t.stanislaws@samsung.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 05 May 2011 09:40:18 +0000 (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 selection ioctls. Signed-off-by: Tomasz Stanislawski --- drivers/media/video/v4l2-ioctl.c | 85 +++++++++++++++++++++++++++++++++---- 1 files changed, 75 insertions(+), 10 deletions(-) diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c index aeef966..d0a4073 100644 --- a/drivers/media/video/v4l2-ioctl.c +++ b/drivers/media/video/v4l2-ioctl.c @@ -1723,11 +1723,31 @@ static long __video_do_ioctl(struct file *file, { struct v4l2_crop *p = arg; - if (!ops->vidioc_g_crop) + dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); + + if (ops->vidioc_g_crop) { + ret = ops->vidioc_g_crop(file, fh, p); + } else + if (ops->vidioc_g_selection) { + /* simulate capture crop using selection api */ + struct v4l2_selection s = { + .type = p->type, + .target = V4L2_SEL_CROP_ACTIVE, + }; + + /* crop means compose for output devices */ + if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) + s.target = V4L2_SEL_COMPOSE_ACTIVE; + + ret = ops->vidioc_g_selection(file, fh, &s); + + /* copying results to old structure on success */ + if (!ret) + p->c = s.r; + } else { break; + } - dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); - ret = ops->vidioc_g_crop(file, fh, p); if (!ret) dbgrect(vfd, "", &p->c); break; @@ -1736,11 +1756,25 @@ 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 { + /* simulate capture crop using selection api */ + struct v4l2_selection s = { + .type = p->type, + .target = V4L2_SEL_CROP_ACTIVE, + .r = p->c, + }; + + /* crop means compose for output devices */ + if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) + s.target = V4L2_SEL_COMPOSE_ACTIVE; + + ret = ops->vidioc_g_selection(file, fh, &s); + } break; } case VIDIOC_G_SELECTION: @@ -1773,12 +1807,43 @@ static long __video_do_ioctl(struct file *file, { struct v4l2_cropcap *p = arg; - /*FIXME: Should also show v4l2_fract pixelaspect */ - if (!ops->vidioc_cropcap) + dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); + if (ops->vidioc_cropcap) { + ret = ops->vidioc_cropcap(file, fh, p); + } else + if (ops->vidioc_g_selection) { + struct v4l2_selection s = { .type = p->type }; + struct v4l2_rect bounds; + + /* obtaining bounds */ + if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) + s.target = V4L2_SEL_COMPOSE_BOUNDS; + else + s.target = V4L2_SEL_CROP_BOUNDS; + ret = ops->vidioc_g_selection(file, fh, &s); + if (ret) + break; + bounds = s.r; + + /* obtaining defrect */ + if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) + s.target = V4L2_SEL_COMPOSE_DEFAULT; + else + s.target = V4L2_SEL_CROP_DEFAULT; + ret = ops->vidioc_g_selection(file, fh, &s); + if (ret) + break; + + /* storing results */ + p->bounds = bounds; + p->defrect = s.r; + p->pixelaspect.numerator = 1; + p->pixelaspect.denominator = 1; + } else { break; + } - dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); - ret = ops->vidioc_cropcap(file, fh, p); + /*FIXME: Should also show v4l2_fract pixelaspect */ if (!ret) { dbgrect(vfd, "bounds ", &p->bounds); dbgrect(vfd, "defrect ", &p->defrect);