diff mbox

[4/6] uvcvideo: Set device_caps in VIDIOC_QUERYCAP

Message ID 1348758980-21683-5-git-send-email-laurent.pinchart@ideasonboard.com (mailing list archive)
State New, archived
Headers show

Commit Message

Laurent Pinchart Sept. 27, 2012, 3:16 p.m. UTC
Set the capabilities field to global capabilities, and the device_caps
field to the video node capabilities.

This issue was found by the v4l2-compliance tool.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/usb/uvc/uvc_driver.c |    5 +++++
 drivers/media/usb/uvc/uvc_v4l2.c   |   10 ++++++----
 drivers/media/usb/uvc/uvcvideo.h   |    2 ++
 3 files changed, 13 insertions(+), 4 deletions(-)

Comments

Hans Verkuil Nov. 16, 2012, 2 p.m. UTC | #1
On Thu September 27 2012 17:16:18 Laurent Pinchart wrote:
> Set the capabilities field to global capabilities, and the device_caps
> field to the video node capabilities.
> 
> This issue was found by the v4l2-compliance tool.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/media/usb/uvc/uvc_driver.c |    5 +++++
>  drivers/media/usb/uvc/uvc_v4l2.c   |   10 ++++++----
>  drivers/media/usb/uvc/uvcvideo.h   |    2 ++
>  3 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
> index 5967081..ae24f7d 100644
> --- a/drivers/media/usb/uvc/uvc_driver.c
> +++ b/drivers/media/usb/uvc/uvc_driver.c
> @@ -1741,6 +1741,11 @@ static int uvc_register_video(struct uvc_device *dev,
>  		return ret;
>  	}
>  
> +	if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
> +		stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
> +	else
> +		stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
> +
>  	atomic_inc(&dev->nstreams);
>  	return 0;
>  }
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index 3bd9373..b1aa55f 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -565,12 +565,14 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
>  		usb_make_path(stream->dev->udev,
>  			      cap->bus_info, sizeof(cap->bus_info));
>  		cap->version = LINUX_VERSION_CODE;
> +		cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
> +				  | chain->caps;
>  		if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
> -			cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
> -					  | V4L2_CAP_STREAMING;
> +			cap->device_caps = V4L2_CAP_VIDEO_CAPTURE
> +					 | V4L2_CAP_STREAMING;
>  		else
> -			cap->capabilities = V4L2_CAP_VIDEO_OUTPUT
> -					  | V4L2_CAP_STREAMING;
> +			cap->device_caps = V4L2_CAP_VIDEO_OUTPUT
> +					 | V4L2_CAP_STREAMING;

This seems weird. Wouldn't it be easier to do:

		cap->device_caps = chain->caps | V4L2_CAP_STREAMING;

You don't need the if/else here.

>  		break;
>  	}
>  
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 7244455..28ff015 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -371,6 +371,8 @@ struct uvc_video_chain {
>  	struct uvc_entity *selector;		/* Selector unit */
>  
>  	struct mutex ctrl_mutex;		/* Protects ctrl.info */
> +
> +	u32 caps;				/* V4L2 chain-wide caps */
>  };
>  
>  struct uvc_stats_frame {
> 

Regards,

	Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Laurent Pinchart Nov. 23, 2012, 12:20 p.m. UTC | #2
Hi Hans,

Thanks for the review.

On Friday 16 November 2012 15:00:29 Hans Verkuil wrote:
> On Thu September 27 2012 17:16:18 Laurent Pinchart wrote:
> > Set the capabilities field to global capabilities, and the device_caps
> > field to the video node capabilities.
> > 
> > This issue was found by the v4l2-compliance tool.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> > 
> >  drivers/media/usb/uvc/uvc_driver.c |    5 +++++
> >  drivers/media/usb/uvc/uvc_v4l2.c   |   10 ++++++----
> >  drivers/media/usb/uvc/uvcvideo.h   |    2 ++
> >  3 files changed, 13 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/media/usb/uvc/uvc_driver.c
> > b/drivers/media/usb/uvc/uvc_driver.c index 5967081..ae24f7d 100644
> > --- a/drivers/media/usb/uvc/uvc_driver.c
> > +++ b/drivers/media/usb/uvc/uvc_driver.c
> > @@ -1741,6 +1741,11 @@ static int uvc_register_video(struct uvc_device
> > *dev,
> >  		return ret;
> >  	}
> > 
> > +	if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
> > +		stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
> > +	else
> > +		stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
> > +
> >  	atomic_inc(&dev->nstreams);
> >  	return 0;
> >  }
> > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c
> > b/drivers/media/usb/uvc/uvc_v4l2.c index 3bd9373..b1aa55f 100644
> > --- a/drivers/media/usb/uvc/uvc_v4l2.c
> > +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> > @@ -565,12 +565,14 @@ static long uvc_v4l2_do_ioctl(struct file *file,
> > unsigned int cmd, void *arg)> 
> >  		usb_make_path(stream->dev->udev,
> >  			      cap->bus_info, sizeof(cap->bus_info));
> >  		cap->version = LINUX_VERSION_CODE;
> > +		cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
> > +				  | chain->caps;
> >  		if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
> > -			cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
> > -					  | V4L2_CAP_STREAMING;
> > +			cap->device_caps = V4L2_CAP_VIDEO_CAPTURE
> > +					 | V4L2_CAP_STREAMING;
> >  		else
> > -			cap->capabilities = V4L2_CAP_VIDEO_OUTPUT
> > -					  | V4L2_CAP_STREAMING;
> > +			cap->device_caps = V4L2_CAP_VIDEO_OUTPUT
> > +					 | V4L2_CAP_STREAMING;
> 
> This seems weird. Wouldn't it be easier to do:
> 
> 		cap->device_caps = chain->caps | V4L2_CAP_STREAMING;
> 
> You don't need the if/else here.

No, because chain->caps can be V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT 
as a chain can contain several video nodes. We want to caps of this particular 
video node only here.

> >  		break;
> >  	}
Hans Verkuil Nov. 23, 2012, 12:36 p.m. UTC | #3
On Fri November 23 2012 13:20:10 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the review.
> 
> On Friday 16 November 2012 15:00:29 Hans Verkuil wrote:
> > On Thu September 27 2012 17:16:18 Laurent Pinchart wrote:
> > > Set the capabilities field to global capabilities, and the device_caps
> > > field to the video node capabilities.
> > > 
> > > This issue was found by the v4l2-compliance tool.
> > > 
> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > ---
> > > 
> > >  drivers/media/usb/uvc/uvc_driver.c |    5 +++++
> > >  drivers/media/usb/uvc/uvc_v4l2.c   |   10 ++++++----
> > >  drivers/media/usb/uvc/uvcvideo.h   |    2 ++
> > >  3 files changed, 13 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/media/usb/uvc/uvc_driver.c
> > > b/drivers/media/usb/uvc/uvc_driver.c index 5967081..ae24f7d 100644
> > > --- a/drivers/media/usb/uvc/uvc_driver.c
> > > +++ b/drivers/media/usb/uvc/uvc_driver.c
> > > @@ -1741,6 +1741,11 @@ static int uvc_register_video(struct uvc_device
> > > *dev,
> > >  		return ret;
> > >  	}
> > > 
> > > +	if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
> > > +		stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
> > > +	else
> > > +		stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
> > > +
> > >  	atomic_inc(&dev->nstreams);
> > >  	return 0;
> > >  }
> > > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c
> > > b/drivers/media/usb/uvc/uvc_v4l2.c index 3bd9373..b1aa55f 100644
> > > --- a/drivers/media/usb/uvc/uvc_v4l2.c
> > > +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> > > @@ -565,12 +565,14 @@ static long uvc_v4l2_do_ioctl(struct file *file,
> > > unsigned int cmd, void *arg)> 
> > >  		usb_make_path(stream->dev->udev,
> > >  			      cap->bus_info, sizeof(cap->bus_info));
> > >  		cap->version = LINUX_VERSION_CODE;
> > > +		cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
> > > +				  | chain->caps;
> > >  		if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
> > > -			cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
> > > -					  | V4L2_CAP_STREAMING;
> > > +			cap->device_caps = V4L2_CAP_VIDEO_CAPTURE
> > > +					 | V4L2_CAP_STREAMING;
> > >  		else
> > > -			cap->capabilities = V4L2_CAP_VIDEO_OUTPUT
> > > -					  | V4L2_CAP_STREAMING;
> > > +			cap->device_caps = V4L2_CAP_VIDEO_OUTPUT
> > > +					 | V4L2_CAP_STREAMING;
> > 
> > This seems weird. Wouldn't it be easier to do:
> > 
> > 		cap->device_caps = chain->caps | V4L2_CAP_STREAMING;
> > 
> > You don't need the if/else here.
> 
> No, because chain->caps can be V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT 
> as a chain can contain several video nodes. We want to caps of this particular 
> video node only here.

That explains it :-)

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Regards,

	Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 5967081..ae24f7d 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -1741,6 +1741,11 @@  static int uvc_register_video(struct uvc_device *dev,
 		return ret;
 	}
 
+	if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		stream->chain->caps |= V4L2_CAP_VIDEO_CAPTURE;
+	else
+		stream->chain->caps |= V4L2_CAP_VIDEO_OUTPUT;
+
 	atomic_inc(&dev->nstreams);
 	return 0;
 }
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 3bd9373..b1aa55f 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -565,12 +565,14 @@  static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 		usb_make_path(stream->dev->udev,
 			      cap->bus_info, sizeof(cap->bus_info));
 		cap->version = LINUX_VERSION_CODE;
+		cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
+				  | chain->caps;
 		if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
-			cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
-					  | V4L2_CAP_STREAMING;
+			cap->device_caps = V4L2_CAP_VIDEO_CAPTURE
+					 | V4L2_CAP_STREAMING;
 		else
-			cap->capabilities = V4L2_CAP_VIDEO_OUTPUT
-					  | V4L2_CAP_STREAMING;
+			cap->device_caps = V4L2_CAP_VIDEO_OUTPUT
+					 | V4L2_CAP_STREAMING;
 		break;
 	}
 
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 7244455..28ff015 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -371,6 +371,8 @@  struct uvc_video_chain {
 	struct uvc_entity *selector;		/* Selector unit */
 
 	struct mutex ctrl_mutex;		/* Protects ctrl.info */
+
+	u32 caps;				/* V4L2 chain-wide caps */
 };
 
 struct uvc_stats_frame {