mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@iki.fi>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Esker Wong <esker@chromium.org>
Subject: Re: [PATCH v2] media: uvcvideo: Implement V4L2_EVENT_FRAME_SYNC
Date: Mon, 6 Nov 2023 11:05:58 +0000	[thread overview]
Message-ID: <ZUjIlq0cxSv9Cut0@valkosipuli.retiisi.eu> (raw)
In-Reply-To: <20231106-uvc-event-v2-1-7d8e36f0df16@chromium.org>

Hi Ricardo,

On Mon, Nov 06, 2023 at 10:52:27AM +0000, Ricardo Ribalda wrote:
> Add support for the frame_sync event, so user-space can become aware
> earlier of new frames.
> 
> Suggested-by: Esker Wong <esker@chromium.org>
> Tested-by: Esker Wong <esker@chromium.org>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> We have measured a latency of around 30msecs between frame sync
> and dqbuf.
> ---
> Changes in v2:
> - Suggested by Laurent. Split sequence++ and event init.
> - Link to v1: https://lore.kernel.org/r/20231020-uvc-event-v1-1-3baa0e9f6952@chromium.org
> ---
>  drivers/media/usb/uvc/uvc_v4l2.c  | 2 ++
>  drivers/media/usb/uvc/uvc_video.c | 7 +++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
> index f4988f03640a..9f3fb5fd2375 100644
> --- a/drivers/media/usb/uvc/uvc_v4l2.c
> +++ b/drivers/media/usb/uvc/uvc_v4l2.c
> @@ -1352,6 +1352,8 @@ static int uvc_ioctl_subscribe_event(struct v4l2_fh *fh,
>  	switch (sub->type) {
>  	case V4L2_EVENT_CTRL:
>  		return v4l2_event_subscribe(fh, sub, 0, &uvc_ctrl_sub_ev_ops);
> +	case V4L2_EVENT_FRAME_SYNC:
> +		return v4l2_event_subscribe(fh, sub, 0, NULL);
>  	default:
>  		return -EINVAL;
>  	}
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 28dde08ec6c5..4f3a510ca4fe 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -1073,9 +1073,16 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
>  	 * that discontinuous sequence numbers always indicate lost frames.
>  	 */
>  	if (stream->last_fid != fid) {
> +		struct v4l2_event event = {
> +			.type = V4L2_EVENT_FRAME_SYNC,
> +		};
> +
>  		stream->sequence++;
>  		if (stream->sequence)
>  			uvc_video_stats_update(stream);
> +
> +		event.u.frame_sync.frame_sequence = stream->sequence,
> +		v4l2_event_queue(&stream->vdev, &event);

uvc_video_decode_start() is called when the reception of the entire frame
has been completed. However, the documentation for V4L2_EVENT_FRAME_SYNC
says that the event is "Triggered immediately when the reception of a frame
has begun.". The functionality here doesn't seem to fit to this patch.

Wouldn't V4L2_EVENT_VSYNC be a better fit, even if we don't really have a
concept of vertical sync in the case of USB? That event doesn't have the
sequence though but I guess it's not an issue at least if your case.

Another technically correct option could be to create a new event for this
but I'm not sure it's worth it.

>  	}
>  
>  	uvc_video_clock_decode(stream, buf, data, len);
> 

-- 
Regards,

Sakari Ailus

  reply	other threads:[~2023-11-06 11:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 10:52 Ricardo Ribalda
2023-11-06 11:05 ` Sakari Ailus [this message]
2023-11-06 11:58   ` Ricardo Ribalda
2023-11-07  5:06   ` Esker Wong
2023-11-07  7:36     ` Sakari Ailus
2023-11-07 10:58       ` Ricardo Ribalda
2023-11-07 19:27     ` nicolas
2023-11-08  6:53       ` Esker Wong
2023-11-08  7:04         ` Ricardo Ribalda
2023-11-08 20:32           ` nicolas
2023-11-08 22:10             ` Laurent Pinchart
2023-11-08 22:46             ` Ricardo Ribalda
2023-11-09  0:03               ` Laurent Pinchart
2023-11-09  0:27                 ` Ricardo Ribalda
2023-11-23 18:22                   ` Nicolas Dufresne
2023-11-24  9:58                     ` Ricardo Ribalda
2023-11-09  0:59                 ` Esker Wong
2023-11-09 11:34                   ` Laurent Pinchart
2023-11-09 11:41                     ` Esker Wong

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=ZUjIlq0cxSv9Cut0@valkosipuli.retiisi.eu \
    --to=sakari.ailus@iki.fi \
    --cc=esker@chromium.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.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

all inboxes | Powered by JetHome®