Received: by 2002:a05:7412:4e10:b0:e2:908c:2ebd with SMTP id gb16csp1158rdb; Mon, 6 Nov 2023 21:13:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsdO2UyeATrBNmmaB4vq//rY+RwpepDkesnHFNel3lmK53lauhaVTksPeAzighPk0w7I+l X-Received: by 2002:a17:902:d50d:b0:1cc:339b:62af with SMTP id b13-20020a170902d50d00b001cc339b62afmr33713072plg.16.1699334018799; Mon, 06 Nov 2023 21:13:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699334018; cv=none; d=google.com; s=arc-20160816; b=gEbdkhQjxHP9+nWKTj5LdbrkMFdkopWy9rU4fnQiJXe3VbrEbGbHV+4pMGauNcfpo/ CH9HoTXPUCG4FZAKYt9y7rTGdDmV6skrUrqUd47QMxW2m/XP6R2UZ4TBsYU4CgkA7d+S WH0Elny5L8TgS8zXYpE7QBQkvxMmfgWUpNUfZcR1GnjqJn9HEkSTu5CFcnZx9ELG5Zlz FKoBnOdR7TNZqpEtK/2aS6oO8UxcOvD42wd+LCfVWBQXxKiCV2mRedbiUBbzqzMihByJ bLTdODPYGT/oPBOLqvw/FzM1NaHjpo46VllgsSXHQOLyqP6KL9vegIY5n5yGJwctu4G1 yPIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+MNdTKVIaJss4ZqgmyFYAFnq1SDnac/PDATg0+wIP+4=; fh=/SdepX2t9yW1i6eBagn//V6egCCD+YWGRRJzwevXInk=; b=EOylwSyMcnjyMRXnPHLUK386xnZYQnJl7H2IxUrxZNXqXpK/8QzDyy++vyHEzJ1yBc w9YkEEh/ZL6eYEWHZUrp2h/+s6bEfHJdkfXrx4HE/cLeZ7TL7WZcMmJ438JyxlRc8Jo4 pkEUNRm88M5pMUV0hyZmZ7RqbAsHRAfMU/NyRaf9HNz74MfYMNvUuKb4rwwmltzIgzNx 6UbkZ3M9dTGWwvCLa60ZqHwQ1eCcuS7hFbCjiIRGJK4+JSsNgDQR/j3whKzbuoXH5oSe OrBx9ZolUmSY2fzzb9Css4hvMQYTgEIEcDQKbbVS9eWAaIgCOUHJUcy9Z8MBBfKbG0dA sfzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YNPT0KnQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id e9-20020a170902744900b001bdcd2e1706si9342228plt.196.2023.11.06.21.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 21:13:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YNPT0KnQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 171D2802EEDF; Mon, 6 Nov 2023 21:13:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233448AbjKGFGh (ORCPT + 99 others); Tue, 7 Nov 2023 00:06:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjKGFGf (ORCPT ); Tue, 7 Nov 2023 00:06:35 -0500 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4D93114 for ; Mon, 6 Nov 2023 21:06:31 -0800 (PST) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-5a86b6391e9so63779927b3.0 for ; Mon, 06 Nov 2023 21:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1699333591; x=1699938391; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+MNdTKVIaJss4ZqgmyFYAFnq1SDnac/PDATg0+wIP+4=; b=YNPT0KnQMu7/pXc4vgx7kOO7SE3xd0AZQd7MyTJPdH55/QDL1z0w+DTeG3nc/13YVj MVJ6B4kb2/k35JKRoyrGA24Ge2v81J4HQOASSos+wxEhUXKlPbs+T/pkx+uETUrIN36i IvGMfwk/srcjUmgJHhdgpMWd1l+laja14JNng= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699333591; x=1699938391; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+MNdTKVIaJss4ZqgmyFYAFnq1SDnac/PDATg0+wIP+4=; b=V2lV2hMbAetQzsHSc/zoD5ldRxprqw2K6I5qZw/NmeQiNNmP6eG5sYGCpHLvq8HeKl 6T9h3XXzggbay708xhdR7HUJp0PjJvj80k4V++TDdyF/yesVjvoRsa/oqOPGBmbeziFe khUithXySm5vfHJhT6U9UpaS5CgpNfqSUWaxs8FSO+9HR9U9IBbW2SRUFNTixn3eysSp EU6J5ufc6uIq5ffqfQnU4FhRBR8m45lt52RCKWHcfLlHHqPV5l2DWb7jMEyPBf/WrtDe TUNlmFlCGUIdhAdj9cbDCb5+3vEodn4YqWijrepjLw4K/cW0M4IHMqrPYrf1zZEJNG9V eXTg== X-Gm-Message-State: AOJu0Ywt5ip82wSNeXheh6yxEVCkNBfKfL1V/SK8L8oa1q3v71xGlkR2 KqkvadQcDnxEY/al/yRhvHafcbR1ECFV2b9bN2/mZw== X-Received: by 2002:a0d:d890:0:b0:5a7:dbd6:14ae with SMTP id a138-20020a0dd890000000b005a7dbd614aemr13927520ywe.29.1699333591101; Mon, 06 Nov 2023 21:06:31 -0800 (PST) MIME-Version: 1.0 References: <20231106-uvc-event-v2-1-7d8e36f0df16@chromium.org> In-Reply-To: From: Esker Wong Date: Tue, 7 Nov 2023 13:06:20 +0800 Message-ID: Subject: Re: [PATCH v2] media: uvcvideo: Implement V4L2_EVENT_FRAME_SYNC To: Sakari Ailus Cc: Ricardo Ribalda , Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 06 Nov 2023 21:13:36 -0800 (PST) [send again in text mode] Hi Sakari, Sequence number is important to us. We need it to measure the latency from this event to the time we display the frame. Regards, Esker On Mon, Nov 6, 2023 at 7:06=E2=80=AFPM Sakari Ailus w= rote: > > 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 > > Tested-by: Esker Wong > > Signed-off-by: Ricardo Ribalda > > --- > > 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-3baa0e9= f6952@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/u= vc_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_str= eaming *stream, > > * that discontinuous sequence numbers always indicate lost frame= s. > > */ > > if (stream->last_fid !=3D fid) { > > + struct v4l2_event event =3D { > > + .type =3D V4L2_EVENT_FRAME_SYNC, > > + }; > > + > > stream->sequence++; > > if (stream->sequence) > > uvc_video_stats_update(stream); > > + > > + event.u.frame_sync.frame_sequence =3D 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 fra= me > 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 thi= s > but I'm not sure it's worth it. > > > } > > > > uvc_video_clock_decode(stream, buf, data, len); > > > > -- > Regards, > > Sakari Ailus