From patchwork Mon Jun 7 23:03:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Diederick C. Niehorster" X-Patchwork-Id: 28156 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp3890021iof; Mon, 7 Jun 2021 16:10:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6Va3XCrc9lmKsgCirIFEjG24TCxGh320Pz7cCiNKpZ9/Cb9POZUZwAWxsn9zoOiKmU8wX X-Received: by 2002:a05:6402:845:: with SMTP id b5mr22115577edz.266.1623107455654; Mon, 07 Jun 2021 16:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623107455; cv=none; d=google.com; s=arc-20160816; b=r5w/Ufr9jZ0m+kakKoLs8Wu5vDLSEJeJsiXVqabJqSWWLPRSnY64xO4K7FjkIlhlIp Rkl6dDA629sS1pxpg6pKAUmNH2F/JokCAPfARl/rtjbP04azjB3bu2SQuWL/RrwNxrr0 3caY3ujssbCtrtsqU3RmXQH4YnSAhoHFX6qlUWiWBT2bC0LULQFhC/p2U3+T/JEVS2Hk wW7mX2RB9Bb/WTIOhvfhLgPangErCC2/3TroNMwRMPamgSL37If9QQw+cjGdUJAoAsjt GNbn6N03UGlky45jsxF884UpjM5NQuD04aOVNb0Z2zI54Tv059NHSJHxgv2p4xjk+0gH gLug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=uxhc0lREL3hlZNUBlWpd+7ODKhk4DZKCxj/H5B51W7U=; b=AG2ltNozraoJwr645s3oRsaprDazPIIAqsFhsMYfygDkYqqIQcjJxP0RumAvJMNjvV R+CJBevLO4DGdu8GgRQatt/u5Yel2cEVHmy86VcbEuOiigKrj0V9E0SjhCs6Xq6/7xQH BBZnKE8XtkNlD9nmRpFFGxU+LAwEUdhtwFHYilmZKBNczDdEKyt/OdZekX9WzRC71Ofk GBwytWzh2xRyOmaJ/Gu4fQ1E85l+4ZKJRsvaUwXekFV/tRYPRj23aKtYgdHigksZ5bVO /XOSJOIV0BuVg6tm8YKgxBe4r7K5QmO8Jim2h4cpsQHvjVhi3dv5kYbnJngFpeo5lZfO QYcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="KfcSnW7/"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j8si8973162edj.124.2021.06.07.16.10.55; Mon, 07 Jun 2021 16:10:55 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="KfcSnW7/"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 88E66688055; Tue, 8 Jun 2021 02:10:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AFDB56818DB for ; Tue, 8 Jun 2021 02:10:39 +0300 (EEST) Received: by mail-ed1-f43.google.com with SMTP id b11so22357799edy.4 for ; Mon, 07 Jun 2021 16:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HuLyuMU42sGh1fXMH20agcBjKGYt8amXpumK5Mpct/c=; b=KfcSnW7/IH1K5UoHoGka/kQAUC9rY3rOP2UK9DF7V4+7xZE9DRCqCJ82HwDCnjd28K oBqQEtTxdtBE9WVwlWFxKL3EtK3pMWDookn3rx578vvp+4HJf0DsSCMIwHG9/ZgqXEv/ oqFj/G4tXrALcc5WW8sQP6Cd5eXE0LpfXzCJHSh05l2gz0MsOH1xeAuT3RTp2+29yq1m x/2EteUUABdpClXs22BvP8aq6XmErCW2g8zRM5BKZqCOccpaGmSletarUE2/Dwr7ddOZ 1Et4j9wTySv5P+Zq/2XUL3m0Z/UEmhLcDMT+e+9HkNHRZDtu1R5reSngeLuE2ANqbMap LJQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HuLyuMU42sGh1fXMH20agcBjKGYt8amXpumK5Mpct/c=; b=Hpq/XaZ45qik3sW+7fqCz8YuMZTI6E/6qmNtPnK2TGkGRkJH/7OaeuqK30dlIpnKfv UOimESfExv35Sg44xuUwHBZLMUmofqrlE/paEernPob/VYPq/YGxWJR9q08QllVY33DR qdQpoNLeRaIvw3JBcpAHKgl7XAX/tfEDhXN4eF4D+UuzFelj6Nj7f89qQPHavTNumioD XjVNzCwpgYrEq5CAEqTPDW2UQwvCNc6y8ey6dAbmlfWZdKaZutrwSItq5NLofZMjwDNe IKu3RhE+Yr46G41S09zu/mCbGYC3NnjOxMbzge2fFxA9exNdjQOJsCiGiZpo+TBRNk7n vvMw== X-Gm-Message-State: AOAM532bpGd3m5SpTAgg+wcAlZ6yIhZnVzi+b6xFutB5/wegNyykpwA6 Gm9/CFWyqT/+EuDNS32czuZ9nnYhOXcmFw== X-Received: by 2002:a05:6512:3095:: with SMTP id z21mr13264543lfd.587.1623107067084; Mon, 07 Jun 2021 16:04:27 -0700 (PDT) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id v9sm1999563ljv.131.2021.06.07.16.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 16:04:26 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Jun 2021 01:03:40 +0200 Message-Id: <20210607230414.612-2-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210607230414.612-1-dcnieho@gmail.com> References: <20210607230414.612-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/35] avdevice/dshow: implement option to use device video timestamps X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Diederick Niehorster Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: LawKKY1DGwAc The dshow plugin ignores timestamps for video frames provided by the DirectShow device, instead using wallclock time, apparently because the implementer of this code had a device that provided unreliable timestamps. Me (and others) would like to use the device's timestamps. The new use_video_device_timestamps option for dshow device enables them to do so. Since the majority of video devices out there probably provide fine timestamps, this patch sets the default to using the device timestamps, which means best fidelity timestamps are used by default. Using the new option, the user can switch this off and revert to the old behavior, so a fall back remains available in case the device provides broken timestamps. Closes: #8620 Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 1 + libavdevice/dshow_capture.h | 1 + libavdevice/dshow_pin.c | 15 ++++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 8d0a6fcc09..2e9f9ddf3f 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -1317,6 +1317,7 @@ static const AVOption options[] = { { "audio_device_save", "save audio capture filter device (and properties) to file", OFFSET(audio_filter_save_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { "video_device_load", "load video capture filter device (and properties) from file", OFFSET(video_filter_load_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { "video_device_save", "save video capture filter device (and properties) to file", OFFSET(video_filter_save_file), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { "use_video_device_timestamps", "use device instead of wallclock timestamps for video frames", OFFSET(use_video_device_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DEC }, { NULL }, }; diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index 06ded2ba96..5a2691518c 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -312,6 +312,7 @@ struct dshow_ctx { char *audio_filter_save_file; char *video_filter_load_file; char *video_filter_save_file; + int use_video_device_timestamps; IBaseFilter *device_filter[2]; IPin *device_pin[2]; diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index 3dae405e65..ab0ead8041 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -309,12 +309,16 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) if (!sample) return E_POINTER; + priv_data = pin->filter->priv_data; + s = priv_data; + ctx = s->priv_data; + IMediaSample_GetTime(sample, &orig_curtime, &dummy); orig_curtime += pin->filter->start_time; IReferenceClock_GetTime(clock, &graphtime); - if (devtype == VideoDevice) { - /* PTS from video devices is unreliable. */ - IReferenceClock_GetTime(clock, &curtime); + if (devtype == VideoDevice && !ctx->use_video_device_timestamps) { + /* PTS from video devices is unreliable. */ + IReferenceClock_GetTime(clock, &curtime); } else { IMediaSample_GetTime(sample, &curtime, &dummy); if(curtime > 400000000000000000LL) { @@ -322,7 +326,7 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) like 437650244077016960 which FFmpeg doesn't like. TODO figure out math. For now just drop them. */ av_log(NULL, AV_LOG_DEBUG, - "dshow dropping initial (or ending) audio frame with odd PTS too high %"PRId64"\n", curtime); + "dshow dropping initial (or ending) frame with odd PTS too high %"PRId64"\n", curtime); return S_OK; } curtime += pin->filter->start_time; @@ -330,9 +334,6 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) buf_size = IMediaSample_GetActualDataLength(sample); IMediaSample_GetPointer(sample, &buf); - priv_data = pin->filter->priv_data; - s = priv_data; - ctx = s->priv_data; index = pin->filter->stream_index; av_log(NULL, AV_LOG_VERBOSE, "dshow passing through packet of type %s size %8d "