Message ID | 20231020-uvc-event-v1-1-3baa0e9f6952@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp865549vqb; Thu, 19 Oct 2023 23:42:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeEMCM6Mik8yJQDiYv9JrkelEYh5ONnghdAUXkDUt+KqTRzpYT9+UpTtAVeMVIxIvCrEC5 X-Received: by 2002:a05:6a21:3d82:b0:154:b4cb:2e8c with SMTP id bj2-20020a056a213d8200b00154b4cb2e8cmr1002729pzc.24.1697784130828; Thu, 19 Oct 2023 23:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697784130; cv=none; d=google.com; s=arc-20160816; b=BjwKyimOiQNAJMGc5P5cxVs0fN06vkFh9fX2nk5oRZqJiINd+SgFc+LaOpO6Gr5RUH iBFJyxLHet2oOl4GLGdsxRfbEI0zKgUGdEb7pYIkII+pggBXau9A6tcFOCtCHMsen5UJ eMCN2eWOP4fyVbcq7049jPkAEGa+j+UPK/LnhfbXmL+qr2P/qHX7JyUOVvqopax4gunG FB1IlnqpaULa6eh/QTPH3389DjmFuJLVz7xVFJ2UIGfpmxD87c5Q9p0FOK8qB2CqpOJA SM8AK+UDepvZHU+Zi36xpjoMD1/QM5mW+eLcNydmI0Rq+2fm+exeeyYO7Sg+xC71CcKm GtNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=LOOBS4fShFQvZXeGJZoPo7g48H6f/x/nWjcHkmoHkOo=; fh=juUYT8HK8LGpjZXsXX23mnx6oe4bv7mQPkb8s5QbVrc=; b=d+B45UDuQUxDAaFSvacjOWcZ4QCXh4owypVAd2KViSrXqME2Kd6uZNYzJIhWDTC2a6 eSTFRtF8icbHPF+leSYH9xJuNueQvRSM6Tj1Un4DoZMNm7n7MTfBiVvL33cHTYPRtZcT AGCNWVsVjOa3iDLaqxoDn0aD994TtLR/dmLIoUjGIut7+NThLSRGHz08rXQXIOQD5s7Q 3gdmiPeKSTFwjwYI6leWlhpNymXX03r6YUgRog/UlGfHYvxN28W5jqpcbJvoO1L7Sr9S y1mSwmFKV5uJ4gRNn3bBja8Ma9bH1+vfB4SRjAAcCVhYy45ez/ZV7McJivGIfY+uZiVp ympA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="K/SHXtr7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id z9-20020a170903018900b001caa2904c09si1256544plg.351.2023.10.19.23.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 23:42:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="K/SHXtr7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id BB5D882E7B10; Thu, 19 Oct 2023 23:42:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235626AbjJTGly (ORCPT <rfc822;lkml4gm@gmail.com> + 25 others); Fri, 20 Oct 2023 02:41:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229644AbjJTGlv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 20 Oct 2023 02:41:51 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0193CCE for <linux-kernel@vger.kernel.org>; Thu, 19 Oct 2023 23:41:49 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-41cc7379b23so2710181cf.3 for <linux-kernel@vger.kernel.org>; Thu, 19 Oct 2023 23:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697784109; x=1698388909; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=LOOBS4fShFQvZXeGJZoPo7g48H6f/x/nWjcHkmoHkOo=; b=K/SHXtr7W1QlI/Iq0Cq64d2oeXyVXZS05ziIq3fWa8ZMKZGOdGxMraZaqltI6zRN+6 yhlGKLKNitps7vtGnc0S/QbUOHjxWOD0aE/LaAxQUS/yvyoaOvVSNIUOm/dWk8SUS7/f q038Fk8hJAwJdogy/hK4FWS4QNyadXPTjP+PM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697784109; x=1698388909; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LOOBS4fShFQvZXeGJZoPo7g48H6f/x/nWjcHkmoHkOo=; b=RQwl9b1hO74/vmT0HKFQzqAmJ9mJGoobVBSyA2NdmHpAcaHf9LIT4I0D+c3mGjyg2U twej3joJDSPoCDlj3IjnZep1hqs7NWNhzCMBZja/gYOeBloSzkk5VnPSwTcY1j7emQKI OHLpuJDpwkbYNJLmQwlO4ap3+3a+oFZYSE7553tGDd4hOXazOhiRGSqGm187wEnGZ2EV gGxY2o8w6wykcjdK9MidEr00UG4aIVVUyDE8F0+HEIoKfzwYs30l4I3QzD11EJW0wbwt 00sFfJzJoM0gwDFPC4m8UT50v77OGhotzlxVFTvoj7M9bJrdPFQscgeEhMLjMSvp/MN2 cd9A== X-Gm-Message-State: AOJu0Yxf6pwfABnSBr3Rn4Ftu+WGMz9RKVrqmLQh5EbOPcV01nZjUUt1 xMamgZghPxBazyauZWsBjCQPcQ== X-Received: by 2002:a05:622a:6:b0:418:2b:acb2 with SMTP id x6-20020a05622a000600b00418002bacb2mr938870qtw.30.1697784109079; Thu, 19 Oct 2023 23:41:49 -0700 (PDT) Received: from denia.c.googlers.com (112.49.199.35.bc.googleusercontent.com. [35.199.49.112]) by smtp.gmail.com with ESMTPSA id g3-20020ac842c3000000b0041977932fc6sm385334qtm.18.2023.10.19.23.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 23:41:48 -0700 (PDT) From: Ricardo Ribalda <ribalda@chromium.org> Date: Fri, 20 Oct 2023 06:41:45 +0000 Subject: [PATCH] media: uvcvideo: Implement V4L2_EVENT_FRAME_SYNC MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231020-uvc-event-v1-1-3baa0e9f6952@chromium.org> X-B4-Tracking: v=1; b=H4sIACghMmUC/x2NQQrDMAwEvxJ0rsB2bvlKyMGy5UZglGI3phDy9 4geZ5llLujchDss0wWNh3Q51MC/Jkh71DejZGMILszeBYfnSMiD9Yt5zp6IcqJQwHyKnZFa1LT bQ89abfw0LvL7B9btvh+GRYyrcAAAAA== To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>, Mauro Carvalho Chehab <mchehab@kernel.org>, Ricardo Ribalda <ribalda@chromium.org> Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Esker Wong <esker@chromium.org> X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 19 Oct 2023 23:42:08 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780255692686881900 X-GMAIL-MSGID: 1780255692686881900 |
Series |
media: uvcvideo: Implement V4L2_EVENT_FRAME_SYNC
|
|
Commit Message
Ricardo Ribalda
Oct. 20, 2023, 6:41 a.m. UTC
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. --- drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ drivers/media/usb/uvc/uvc_video.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) --- base-commit: ce55c22ec8b223a90ff3e084d842f73cfba35588 change-id: 20231020-uvc-event-d3d1bbbdcb2f Best regards,
Comments
Friendly ping (in text mode :P)
Hi Ricardo, Thank you for the patch. On Fri, Oct 20, 2023 at 06:41:45AM +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. Not surprising, especially for large resolutions. I'm curious though, what do you use this event for ? > --- > drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ > drivers/media/usb/uvc/uvc_video.c | 8 +++++++- > 2 files changed, 9 insertions(+), 1 deletion(-) > > 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..1d4b4807b005 100644 > --- a/drivers/media/usb/uvc/uvc_video.c > +++ b/drivers/media/usb/uvc/uvc_video.c > @@ -1073,9 +1073,15 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, > * that discontinuous sequence numbers always indicate lost frames. > */ > if (stream->last_fid != fid) { > - stream->sequence++; > + struct v4l2_event event = { > + .type = V4L2_EVENT_FRAME_SYNC, > + .u.frame_sync.frame_sequence = ++stream->sequence, Extra space before ++. It's easy to miss the ++ there when reading the code, would the following be more readable ? struct v4l2_event event = { .type = V4L2_EVENT_FRAME_SYNC, }; stream->sequence++; if (stream->sequence) uvc_video_stats_update(stream); .u.frame_sync.frame_sequence = stream->sequence; v4l2_event_queue(&stream->vdev, &event); > + }; > + > if (stream->sequence) > uvc_video_stats_update(stream); > + > + v4l2_event_queue(&stream->vdev, &event); > } > > uvc_video_clock_decode(stream, buf, data, len); > > --- > base-commit: ce55c22ec8b223a90ff3e084d842f73cfba35588 > change-id: 20231020-uvc-event-d3d1bbbdcb2f
On Mon, Nov 06, 2023 at 12:39:26PM +0200, Laurent Pinchart wrote: > On Fri, Oct 20, 2023 at 06:41:45AM +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. > > Not surprising, especially for large resolutions. I'm curious though, > what do you use this event for ? > > > --- > > drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ > > drivers/media/usb/uvc/uvc_video.c | 8 +++++++- > > 2 files changed, 9 insertions(+), 1 deletion(-) > > > > 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..1d4b4807b005 100644 > > --- a/drivers/media/usb/uvc/uvc_video.c > > +++ b/drivers/media/usb/uvc/uvc_video.c > > @@ -1073,9 +1073,15 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, > > * that discontinuous sequence numbers always indicate lost frames. > > */ > > if (stream->last_fid != fid) { > > - stream->sequence++; > > + struct v4l2_event event = { > > + .type = V4L2_EVENT_FRAME_SYNC, > > + .u.frame_sync.frame_sequence = ++stream->sequence, > > Extra space before ++. > > It's easy to miss the ++ there when reading the code, would the > following be more readable ? > > struct v4l2_event event = { > .type = V4L2_EVENT_FRAME_SYNC, > }; > > stream->sequence++; > if (stream->sequence) > uvc_video_stats_update(stream); > > .u.frame_sync.frame_sequence = stream->sequence; Obviously this should read event.u.frame_sync.frame_sequence = stream->sequence; > v4l2_event_queue(&stream->vdev, &event); > > > + }; > > + > > if (stream->sequence) > > uvc_video_stats_update(stream); > > + > > + v4l2_event_queue(&stream->vdev, &event); > > } > > > > uvc_video_clock_decode(stream, buf, data, len); > > > > --- > > base-commit: ce55c22ec8b223a90ff3e084d842f73cfba35588 > > change-id: 20231020-uvc-event-d3d1bbbdcb2f
Hi Laurent On Mon, 6 Nov 2023 at 11:42, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote: > > On Mon, Nov 06, 2023 at 12:39:26PM +0200, Laurent Pinchart wrote: > > On Fri, Oct 20, 2023 at 06:41:45AM +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. > > > > Not surprising, especially for large resolutions. I'm curious though, > > what do you use this event for ? I think Esker is using it to get more accurate power measurements of the camera stack. > > It's easy to miss the ++ there when reading the code, would the > > following be more readable ? Actually that was my original code, but I thought you would like this better :) Thanks for the review, a v2 is on its way. > -- > Regards, > > Laurent Pinchart
On Mon, Nov 06, 2023 at 11:51:06AM +0100, Ricardo Ribalda wrote: > On Mon, 6 Nov 2023 at 11:42, Laurent Pinchart wrote: > > On Mon, Nov 06, 2023 at 12:39:26PM +0200, Laurent Pinchart wrote: > > > On Fri, Oct 20, 2023 at 06:41:45AM +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. > > > > > > Not surprising, especially for large resolutions. I'm curious though, > > > what do you use this event for ? > > I think Esker is using it to get more accurate power measurements of > the camera stack. Esker, would you be able to provide more information ? > > > It's easy to miss the ++ there when reading the code, would the > > > following be more readable ? > > Actually that was my original code, but I thought you would like this better :) > > Thanks for the review, a v2 is on its way. Thank you.
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..1d4b4807b005 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1073,9 +1073,15 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, * that discontinuous sequence numbers always indicate lost frames. */ if (stream->last_fid != fid) { - stream->sequence++; + struct v4l2_event event = { + .type = V4L2_EVENT_FRAME_SYNC, + .u.frame_sync.frame_sequence = ++stream->sequence, + }; + if (stream->sequence) uvc_video_stats_update(stream); + + v4l2_event_queue(&stream->vdev, &event); } uvc_video_clock_decode(stream, buf, data, len);