[RFC,05/17] v4l: Support s_crop and g_crop through s/g_selection

Message ID 1324412889-17961-5-git-send-email-sakari.ailus@maxwell.research.nokia.com (mailing list archive)
State RFC, archived
Headers

Commit Message

Sakari Ailus Dec. 20, 2011, 8:27 p.m. UTC
  From: Sakari Ailus <sakari.ailus@iki.fi>

Revert to s_selection if s_crop isn't implemented by a driver. Same for
g_selection / g_crop.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 drivers/media/video/v4l2-subdev.c |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)
  

Comments

Laurent Pinchart Jan. 5, 2012, 4:13 p.m. UTC | #1
Hi Sakari,

Thanks for the patch.

On Tuesday 20 December 2011 21:27:57 Sakari Ailus wrote:
> From: Sakari Ailus <sakari.ailus@iki.fi>
> 
> Revert to s_selection if s_crop isn't implemented by a driver. Same for
> g_selection / g_crop.

Shouldn't this say "Fall back" instead of "Revert" ?

> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  drivers/media/video/v4l2-subdev.c |   37
> +++++++++++++++++++++++++++++++++++-- 1 files changed, 35 insertions(+), 2
> deletions(-)
> 
> diff --git a/drivers/media/video/v4l2-subdev.c
> b/drivers/media/video/v4l2-subdev.c index e8ae098..f8de551 100644
> --- a/drivers/media/video/v4l2-subdev.c
> +++ b/drivers/media/video/v4l2-subdev.c
> @@ -226,6 +226,8 @@ static long subdev_do_ioctl(struct file *file, unsigned
> int cmd, void *arg)
> 
>  	case VIDIOC_SUBDEV_G_CROP: {
>  		struct v4l2_subdev_crop *crop = arg;
> +		struct v4l2_subdev_selection sel;
> +		int rval;
> 
>  		if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
>  		    crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> @@ -234,11 +236,27 @@ static long subdev_do_ioctl(struct file *file,
> unsigned int cmd, void *arg) if (crop->pad >= sd->entity.num_pads)
>  			return -EINVAL;
> 
> -		return v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
> +		rval = v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
> +		if (rval != -ENOIOCTLCMD)
> +			return rval;
> +
> +		memset(&sel, 0, sizeof(sel));
> +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;

Shouldn't sel.which be set to crop->which ?

> +		sel.pad = crop->pad;
> +		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
> +
> +		rval = v4l2_subdev_call(
> +			sd, pad, get_selection, subdev_fh, &sel);
> +
> +		crop->rect = sel.r;
> +
> +		return rval;
>  	}
> 
>  	case VIDIOC_SUBDEV_S_CROP: {
>  		struct v4l2_subdev_crop *crop = arg;
> +		struct v4l2_subdev_selection sel;
> +		int rval;
> 
>  		if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
>  		    crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
> @@ -247,7 +265,22 @@ static long subdev_do_ioctl(struct file *file,
> unsigned int cmd, void *arg) if (crop->pad >= sd->entity.num_pads)
>  			return -EINVAL;
> 
> -		return v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
> +		rval = v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
> +		if (rval != -ENOIOCTLCMD)
> +			return rval;
> +
> +		memset(&sel, 0, sizeof(sel));
> +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;

Same here.

> +		sel.pad = crop->pad;
> +		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
> +		sel.r = crop->rect;
> +
> +		rval = v4l2_subdev_call(
> +			sd, pad, set_selection, subdev_fh, &sel);
> +
> +		crop->rect = sel.r;
> +
> +		return rval;
>  	}
> 
>  	case VIDIOC_SUBDEV_ENUM_MBUS_CODE: {
  
Sakari Ailus Jan. 8, 2012, 8:54 p.m. UTC | #2
Hi Laurent,

Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thanks for the patch.
> 
> On Tuesday 20 December 2011 21:27:57 Sakari Ailus wrote:
>> From: Sakari Ailus <sakari.ailus@iki.fi>
>>
>> Revert to s_selection if s_crop isn't implemented by a driver. Same for
>> g_selection / g_crop.
> 
> Shouldn't this say "Fall back" instead of "Revert" ?

Fixed all issues you mentioned in this e-mail.

>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  drivers/media/video/v4l2-subdev.c |   37
>> +++++++++++++++++++++++++++++++++++-- 1 files changed, 35 insertions(+), 2
>> deletions(-)
>>
>> diff --git a/drivers/media/video/v4l2-subdev.c
>> b/drivers/media/video/v4l2-subdev.c index e8ae098..f8de551 100644
>> --- a/drivers/media/video/v4l2-subdev.c
>> +++ b/drivers/media/video/v4l2-subdev.c
>> @@ -226,6 +226,8 @@ static long subdev_do_ioctl(struct file *file, unsigned
>> int cmd, void *arg)
>>
>>  	case VIDIOC_SUBDEV_G_CROP: {
>>  		struct v4l2_subdev_crop *crop = arg;
>> +		struct v4l2_subdev_selection sel;
>> +		int rval;
>>
>>  		if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
>>  		    crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
>> @@ -234,11 +236,27 @@ static long subdev_do_ioctl(struct file *file,
>> unsigned int cmd, void *arg) if (crop->pad >= sd->entity.num_pads)
>>  			return -EINVAL;
>>
>> -		return v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
>> +		rval = v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
>> +		if (rval != -ENOIOCTLCMD)
>> +			return rval;
>> +
>> +		memset(&sel, 0, sizeof(sel));
>> +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> 
> Shouldn't sel.which be set to crop->which ?
> 
>> +		sel.pad = crop->pad;
>> +		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
>> +
>> +		rval = v4l2_subdev_call(
>> +			sd, pad, get_selection, subdev_fh, &sel);
>> +
>> +		crop->rect = sel.r;
>> +
>> +		return rval;
>>  	}
>>
>>  	case VIDIOC_SUBDEV_S_CROP: {
>>  		struct v4l2_subdev_crop *crop = arg;
>> +		struct v4l2_subdev_selection sel;
>> +		int rval;
>>
>>  		if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
>>  		    crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
>> @@ -247,7 +265,22 @@ static long subdev_do_ioctl(struct file *file,
>> unsigned int cmd, void *arg) if (crop->pad >= sd->entity.num_pads)
>>  			return -EINVAL;
>>
>> -		return v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
>> +		rval = v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
>> +		if (rval != -ENOIOCTLCMD)
>> +			return rval;
>> +
>> +		memset(&sel, 0, sizeof(sel));
>> +		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> 
> Same here.
> 
>> +		sel.pad = crop->pad;
>> +		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
>> +		sel.r = crop->rect;
>> +
>> +		rval = v4l2_subdev_call(
>> +			sd, pad, set_selection, subdev_fh, &sel);
>> +
>> +		crop->rect = sel.r;
>> +
>> +		return rval;
>>  	}
>>
>>  	case VIDIOC_SUBDEV_ENUM_MBUS_CODE: {
>
  

Patch

diff --git a/drivers/media/video/v4l2-subdev.c b/drivers/media/video/v4l2-subdev.c
index e8ae098..f8de551 100644
--- a/drivers/media/video/v4l2-subdev.c
+++ b/drivers/media/video/v4l2-subdev.c
@@ -226,6 +226,8 @@  static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 
 	case VIDIOC_SUBDEV_G_CROP: {
 		struct v4l2_subdev_crop *crop = arg;
+		struct v4l2_subdev_selection sel;
+		int rval;
 
 		if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
 		    crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
@@ -234,11 +236,27 @@  static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 		if (crop->pad >= sd->entity.num_pads)
 			return -EINVAL;
 
-		return v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
+		rval = v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
+		if (rval != -ENOIOCTLCMD)
+			return rval;
+
+		memset(&sel, 0, sizeof(sel));
+		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+		sel.pad = crop->pad;
+		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
+
+		rval = v4l2_subdev_call(
+			sd, pad, get_selection, subdev_fh, &sel);
+
+		crop->rect = sel.r;
+
+		return rval;
 	}
 
 	case VIDIOC_SUBDEV_S_CROP: {
 		struct v4l2_subdev_crop *crop = arg;
+		struct v4l2_subdev_selection sel;
+		int rval;
 
 		if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
 		    crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
@@ -247,7 +265,22 @@  static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 		if (crop->pad >= sd->entity.num_pads)
 			return -EINVAL;
 
-		return v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
+		rval = v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
+		if (rval != -ENOIOCTLCMD)
+			return rval;
+
+		memset(&sel, 0, sizeof(sel));
+		sel.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+		sel.pad = crop->pad;
+		sel.target = V4L2_SUBDEV_SEL_TGT_CROP_ACTIVE;
+		sel.r = crop->rect;
+
+		rval = v4l2_subdev_call(
+			sd, pad, set_selection, subdev_fh, &sel);
+
+		crop->rect = sel.r;
+
+		return rval;
 	}
 
 	case VIDIOC_SUBDEV_ENUM_MBUS_CODE: {