From patchwork Tue Sep 20 14:08:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 608144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC3FFC6FA8E for ; Tue, 20 Sep 2022 14:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231579AbiITOIx (ORCPT ); Tue, 20 Sep 2022 10:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbiITOIi (ORCPT ); Tue, 20 Sep 2022 10:08:38 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D707A57267 for ; Tue, 20 Sep 2022 07:08:34 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id b35so4109860edf.0 for ; Tue, 20 Sep 2022 07:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date; bh=2m5NjiSQ3UFcFg+RUZgWJGP2l7gs/3+ArugwLslOKeE=; b=Qog8O021pF2YpCNSfKIFSrzglOkUJfYjp/+iykdEDhA2rUzeTskHBghLNIn667tEIx YRjgd/2WjIW8lAE5Te5Yd/KuQ6nhDQh3n/Gy4igXH4sV1xPYrK3VLZWa7iDQxRFkKDny LNH7AtkR12pvioQ8Xepwi/BClUJDOUtspbh0A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date; bh=2m5NjiSQ3UFcFg+RUZgWJGP2l7gs/3+ArugwLslOKeE=; b=n6qa5ZvfM/VkI9y6gJisUXuQWYKKKyFCMh5UeWcc5JU5mTP1rsfhOt32wOLREEeQUM tTOxJQ5cytMZeeosp1RWkWzkdiec3RrV6ouzNo8OqaZbsLo1tPz2jd+XrEjUuwdhWMKh Cl5zYFWRHkmMkufG6FtF7XpWfYpLRXUsiRTUdD8ioalkOnkpGIMQz42mBcmkUjStkCW6 iHVGYUOqxdeU9HfsOorLU1FzS+rzPljKfeJBPwV75iCjp52LJxYxbdXNznVGBNsFzTZs OvGzWEsC3bYTA2FmseJYUhgsom3q8IWBcfzCbgFwQzfe4AVcEzZxg7zQG8eLeRpmgpus 5muw== X-Gm-Message-State: ACrzQf3lQMKuLoQMfaTMbEPbq+iyLpFAfGzpuwvA0ypvrAi3Iz9Axp7k P7L6zl38bAF4F8Yi+2AyOtLNvg== X-Google-Smtp-Source: AMsMyM7Kttfu3Wsv8rxi19u3YeiT1tiXz9wHrvoFQFz4kKSYvS3PuNb1O521uebjBc0XlYZE2HrKoQ== X-Received: by 2002:a05:6402:1b06:b0:44e:a073:1dd8 with SMTP id by6-20020a0564021b0600b0044ea0731dd8mr19527488edb.391.1663682913102; Tue, 20 Sep 2022 07:08:33 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:935d:52b0:7461:88e1]) by smtp.gmail.com with ESMTPSA id j17-20020a17090623f100b0077016f4c6d4sm936564ejg.55.2022.09.20.07.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 07:08:32 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 20 Sep 2022 16:08:12 +0200 Subject: [PATCH v1 6/8] media: uvcvideo: Allow hw clock updates with buffers not full MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v1-6-e9c14b258404@chromium.org> References: <20220920-resend-hwtimestamp-v1-0-e9c14b258404@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v1-0-e9c14b258404@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: "hn.chen" , Ricardo Ribalda , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=1139; i=ribalda@chromium.org; h=from:subject:message-id; bh=e4J+nrDAhgtu8XgKC9q34sJueku2ku3RgCFGTHQq+rM=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjKclVPstkH2tqWY0nEWxBnkdg51HwzIUCHCT2SJIh 90evtTuJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCYynJVQAKCRDRN9E+zzrEiMh4EA CMsLkuVpPkdk5Dw96HZtyoD4QFh88Ekmm5Ugj05gyKL5+RNVrwIuaEvTQgneLKQ5i2ARyq2ZdnWmFt Lx/d+P7OXGibbi38Jqllt19Jv7qtFI0eD/ldJ1FuLDPsz/sYBgrD4yNQqHlSTlHoX6rN6FHCKVpG+f QXJeagc1ChxU9gIb+P0lGvomrAq1qIO3RHjipwd2d4Qnyr5GQ7hXxlw/jmHK0HpbJQXG8wp7iotWVU bhwQY9WXeHJEZ6K4I345bFFpeQGQw7y+koAtpdO2wcCdYT4NnIVMBZELONHgKilYgd9mA3skOzMRir u4j1W0faE/Ml5Wq8BnrtUNimXrfLGebTUNTVl7bxrARfeH7H/Caa/VAuEesHrH2OICMEsxVlwzM/hW J4XRPzEaoTgMlRBouzs6x+YbOMSb/l/SHIEQxywDiRSOom87Dfvacqxrdmgczi8e+AWtsUW6/wkhpE EY5EqMze+HehXjoPJvHKYAwf/SPtbeNSH06aK8LTRrF46l5QR9AY6+nTt8eViEH5b2HG0O7wFG2nFN MjsbObx7yVgT1OPC2rG9YRCrmjfYrpvu2wm9oUFW5iBs/jJjE0zOPXiLh8aXJc4tweTNMN8zDAixm1 4kKV9lMekTN3+T72giWH24O5uVNd0PTBlP/VRrDq+wARMBD0qUj1h298kOvA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org With UVC 1.5 we get as little as one clock sample per frame. Which means that it takes 32 frames to move from the software timestamp to the hardware timestamp method. This results in abrupt changes in the timestamping after 32 frames (~1 second), resulting in noticeable artifacts when used for encoding. With this patch we modify the update algorithm to work with whatever amount of values are available. Signed-off-by: Ricardo Ribalda diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 75c32e232f5d..7c7fb478aef7 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -742,10 +742,10 @@ void uvc_video_clock_update(struct uvc_streaming *stream, spin_lock_irqsave(&clock->lock, flags); - if (clock->count < clock->size) + if (clock->count < 2) goto done; - first = &clock->samples[clock->head]; + first = &clock->samples[(clock->head - clock->count) % clock->size]; last = &clock->samples[(clock->head - 1) % clock->size]; /* First step, PTS to SOF conversion. */