Linux Media Controller development
 help / color / mirror / Atom feed
From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-media@vger.kernel.org, Hans Verkuil <hverkuil@xs4all.nl>
Subject: Re: [PATCH v8] uvcvideo: Add a metadata device node
Date: Wed, 13 Dec 2017 10:51:20 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1712131049140.29930@axis700.grange> (raw)
In-Reply-To: <1776907.6M9RIR1GJL@avalon>

Hi Laurent,

On Wed, 13 Dec 2017, Laurent Pinchart wrote:

> Hi Guennadi,
> 
> On Tuesday, 12 December 2017 10:30:39 EET Guennadi Liakhovetski wrote:
> > On Mon, 11 Dec 2017, Laurent Pinchart wrote:
> > > On Monday, 11 December 2017 23:44:09 EET Guennadi Liakhovetski wrote:
> > >> On Mon, 11 Dec 2017, Laurent Pinchart wrote:
> > >>> On Monday, 11 December 2017 22:16:23 EET Laurent Pinchart wrote:
> > >>>> On Wednesday, 6 December 2017 17:15:40 EET Guennadi Liakhovetski wrote:
> > >>>>> From: Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>
> > >>>>> 
> > >>>>> Some UVC video cameras contain metadata in their payload headers.
> > >>>>> This patch extracts that data, adding more clock synchronisation
> > >>>>> information, on both bulk and isochronous endpoints and makes it
> > >>>>> available to the user space on a separate video node, using the
> > >>>>> V4L2_CAP_META_CAPTURE capability and the V4L2_BUF_TYPE_META_CAPTURE
> > >>>>> buffer queue type. By default, only the V4L2_META_FMT_UVC pixel
> > >>>>> format is available from those nodes. However, cameras can be added to
> > >>>>> the device ID table to additionally specify their own metadata format,
> > >>>>> in which case that format will also become available from the metadata
> > >>>>> node.
> > >>>>> 
> > >>>>> Signed-off-by: Guennadi Liakhovetski
> > >>>>> <guennadi.liakhovetski@intel.com>
> > >>>>> ---
> > >>>>> 
> > >>>>> v8: addressed comments and integrated changes from Laurent, thanks
> > >>>>> again, e.g.:
> > >>>>> 
> > >>>>> - multiple stylistic changes
> > >>>>> - remove the UVC_DEV_FLAG_METADATA_NODE flag / quirk: nodes are now
> > >>>>>   created unconditionally
> > >>>>> - reuse uvc_ioctl_querycap()
> > >>>>> - reuse code in uvc_register_video()
> > >>>>> - set an error flag when the metadata buffer overflows
> > >>>>> 
> > >>>>>  drivers/media/usb/uvc/Makefile       |   2 +-
> > >>>>>  drivers/media/usb/uvc/uvc_driver.c   |  15 ++-
> > >>>>>  drivers/media/usb/uvc/uvc_isight.c   |   2 +-
> > >>>>>  drivers/media/usb/uvc/uvc_metadata.c | 179+++++++++++++++++++++++++++
> > >>>>>  drivers/media/usb/uvc/uvc_queue.c    |  44 +++++++--
> > >>>>>  drivers/media/usb/uvc/uvc_video.c    | 132 +++++++++++++++++++++++--
> > >>>>>  drivers/media/usb/uvc/uvcvideo.h     |  16 +++-
> > >>>>>  include/uapi/linux/uvcvideo.h        |  26 +++++
> > >>>>>  8 files changed, 394 insertions(+), 22 deletions(-)
> > >>>>>  create mode 100644 drivers/media/usb/uvc/uvc_metadata.c
> > >>>> 
> > >>>> [snip]
> > >>>> 
> > >>>>> diff --git a/drivers/media/usb/uvc/uvc_video.c
> > >>>>> b/drivers/media/usb/uvc/uvc_video.c index 13f459e..2fc0bf2 100644
> > >>>>> --- a/drivers/media/usb/uvc/uvc_video.c
> > >>>>> +++ b/drivers/media/usb/uvc/uvc_video.c
> > >>>> 
> > >>>> [snip]
> > >>>> 
> > >>>>> +static void uvc_video_decode_meta(struct uvc_streaming *stream,
> > >>>>> +				  struct uvc_buffer *meta_buf,
> > >>>>> +				  const u8 *mem, unsigned int length)
> > >>>>> +{
> > >>>>> +	struct uvc_meta_buf *meta;
> > >>>>> +	size_t len_std = 2;
> > >>>>> +	bool has_pts, has_scr;
> > >>>>> +	unsigned long flags;
> > >>>>> +	ktime_t time;
> > >>>>> +	const u8 *scr;
> 
> [snip]
> 
> > >>>>> +	meta = (struct uvc_meta_buf *)((u8 *)meta_buf->mem +
> > >>>>> meta_buf->bytesused);
> > >>>>> +	local_irq_save(flags);
> > >>>>> +	time = uvc_video_get_time();
> > >>>>> +	meta->sof = usb_get_current_frame_number(stream->dev->udev);
> > >>>> 
> > >>>> You need a put_unaligned here too. If you're fine with the patch
> > >>>> below there's no need to resubmit, and
> > >>> 
> > >>> One more thing, __put_unaligned_cpu16() and __put_unaligned_cpu64()
> > >>> don't compile on x86_64 with v4.12 (using media_build.git). I propose
> > >>> replacing them with put_unaligned() which compiles and should do the
> > >>> right thing.
> > >> 
> > >> Sure, thanks for catching! Shall I fix and resubmit?
> > > 
> > > If you're fine with
> > > 
> > > 	git://linuxtv.org/pinchartl/media.git uvc/next
> > 
> > I was a bit concerned about just using "int" for unaligned writing of a
> > 16-bit value, but looking at definitions, after a couple of macros
> > put_unaligned() currently resolves to one inline functions, which should
> > make that safe. However, at least theoretically, an arch could decide to
> > implement put_unaligned() as a macro, which might turn out to be unsafe
> > for this... Not sure how concerned should we be about such a possibility
> > :-) If you think, that's fine, then I'm ok with using the version from
> > that your branch.
> 
> Why do you think that would be unsafe ? The return type of 
> usb_get_current_frame_number() is int, so introducing an intermediate int 
> variable should at least not make things worse. If put_unaligned() is 
> implemented solely using macros I would still expect them to operate on the 
> type of the destination operand, and cast the source value appropriately.

Well, you *can* implement that badly - check the destination type, which 
in this case is 16 bit, and use the address of the first argument to get 
16 bits from there... But yes, I agree, that would be a bug, so, maybe 
it's ok to rely on those implementations being bug-free.

Thanks
Guennadi

      reply	other threads:[~2017-12-13  9:51 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08 16:00 [PATCH 0/3 v7] uvcvideo: metadata nodes Guennadi Liakhovetski
2017-11-08 16:00 ` [PATCH 1/3 v7] V4L: Add a UVC Metadata format Guennadi Liakhovetski
2017-11-28 15:20   ` Laurent Pinchart
2017-11-28 15:26     ` Guennadi Liakhovetski
2017-11-08 16:00 ` [PATCH 2/3 v7] uvcvideo: add extensible device information Guennadi Liakhovetski
2017-11-28 15:55   ` Laurent Pinchart
2017-11-28 16:20     ` Guennadi Liakhovetski
2017-11-08 16:00 ` [PATCH 3/3 v7] uvcvideo: add a metadata device node Guennadi Liakhovetski
2017-12-05  0:24   ` Laurent Pinchart
2017-12-05  1:03     ` Laurent Pinchart
2017-12-05  8:06       ` Guennadi Liakhovetski
2017-12-05  9:44         ` Laurent Pinchart
2017-12-05 10:56     ` Guennadi Liakhovetski
2017-12-05 13:35       ` Laurent Pinchart
2017-12-05 13:44         ` Guennadi Liakhovetski
2017-12-05 13:49           ` Laurent Pinchart
2017-12-05 14:00             ` Guennadi Liakhovetski
2017-12-06 15:08               ` Guennadi Liakhovetski
2017-12-11 19:53                 ` Laurent Pinchart
2017-12-06 15:15             ` [PATCH v8] uvcvideo: Add " Guennadi Liakhovetski
2017-12-11 20:16               ` Laurent Pinchart
2017-12-11 21:15                 ` Laurent Pinchart
2017-12-11 21:44                   ` Guennadi Liakhovetski
2017-12-11 21:53                     ` Laurent Pinchart
2017-12-12  8:30                       ` Guennadi Liakhovetski
2017-12-13  9:41                         ` Laurent Pinchart
2017-12-13  9:51                           ` Guennadi Liakhovetski [this message]

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=alpine.DEB.2.20.1712131049140.29930@axis700.grange \
    --to=g.liakhovetski@gmx.de \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --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