From patchwork Tue Jul 6 09:19:47 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: 28805 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp4922627ios; Tue, 6 Jul 2021 02:26:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3m7TBLDF/u3wnLtSAMT0lSe7yWs9mPr6pGO1MT0OOzS9UN3vvUuUAkeNE8JwMWKlcaT73 X-Received: by 2002:a17:906:478b:: with SMTP id cw11mr17099279ejc.241.1625563588448; Tue, 06 Jul 2021 02:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625563588; cv=none; d=google.com; s=arc-20160816; b=07bz8uy92yJITp8gIMg3peRmDzQLlkeM18icYAbDE3gLrbe/8R5OWl4k0Wz6G4TuAS yXP8l2mWiHodZ4TG9ds78tDfNcGLUep+k6EWnlJNrOf8Oy4ibZUI4bKCTVsX8Vz75SxN HM9N3FjFSTuQt07P5mp8oYL8jJOWJAuKoVBXMAGrNJ0avTErU1E9t7LnRdRl2vm5y9i7 zk1Nbtr32EuTCB12A0rYFtcxsm2Z7Xl7nrxfSBT+J+eZP6VL5hSkIOwDXyl/b9uzNJle /gmLb5T1BeVP87PvETUetUet2v6ZpKGRz35Hz26J5ShFyj3vxPGKVDd8VEjf9nDG1vBr IzWQ== 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=w9fvL3VPvb5updXCNrPNVLTpUww3JZbdNfMaMZMwtfE=; b=K+WuQANfyfD6Cgar1gMx3AMEtVqRPBoiJEpxsBzqVpV0NCdZzNWzD1CiKnnN37kh6l Lv3Lm7xTpLtij/mAg+nHNSS7Hgjp7RXaHlGLAcvVZbL+JYiWzod/vv3JbjAAZnNnEeqz it+qzurxGOtXsJdomdxGBjfRJgMDoAfFkMMQ5kqQ5jd5j0l0ghXZFbEnoW2DXn9DPUdh pOdCEZpDwjLPyLjrrO4bcZ6mq/s43Omp0pWTA4fztLgE74OlJpkuGRYATEvuIxaKKnXC A/S3ZFxM1JJusVfGuRXUhzz3ihIZlS2th+WQ2C/D4/US4/fyl90KTS3u1sTZ/9j/hH6n zK8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=LWRpjXCx; 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 o8si16031008ejj.94.2021.07.06.02.26.28; Tue, 06 Jul 2021 02:26:28 -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=LWRpjXCx; 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 7F49768A8EE; Tue, 6 Jul 2021 12:26:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6286168A8E4 for ; Tue, 6 Jul 2021 12:26:18 +0300 (EEST) Received: by mail-lf1-f46.google.com with SMTP id q18so37146795lfc.7 for ; Tue, 06 Jul 2021 02:26:18 -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=jcjJhc+duK3r99E9G8l0evKr10lxN7y9j1qZpdQOThY=; b=LWRpjXCxYs35P/VVLVTcD+4v+rtF0fqDA/iH2xJIzT/rwck2ZZ7BPaO1D78J/FazwY fDpFCGulXjGv9CRkHBRgupDzTyqG8qN5PKhV9WcRcxt0oebMbWNoko0xvfE/9BUuwDwJ pgEFHOpn1h6cmpVE8r8uE8BGWv7PfyL3U8ks092yv2KVnlFq+s9y+KTAwGOY9jPsZcqn 6ba508NXFkxLqLiGPkEdmWXg416o+hycPzyTvjggojf+YnaGeOU2cj0OgK9u9q/cAP/C 7AwNbfwVA3ZeIrAEgwbpG4zHbJrGEFix9lJDt5S+agIVYU0chCOoNuGkua1uWPRpCBGw E9Ag== 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=jcjJhc+duK3r99E9G8l0evKr10lxN7y9j1qZpdQOThY=; b=IGXWV7JHiRB8+aTUrWVXkC1DAUeTwjqX/dnCDPABtsSD5Zf26Y5AAPUNweYTptDXMw TFeV7j56gvxpkJt6BcS1I9AFavvRim4KzBIZFoggQY32x4lLZF5Uedn+NGDhx3gXZXqY gJHynKDr+ixWAMmlhbtJPWxBkk8fvzjcMXzk3XtNy3dm2el+qZSBSLud6fAyW4kTLk2D +J2vZUOlrB5Tms0EtLxxNm3D1SUPTbf+0I9zdKGNtHr/354M9d/qJsG6VQ4ucGweoxu8 hXdDQUA/2BoEjiZwyQpkRBHisWze4glED5YWyhbNu9ng1e687xpBijQ3w3TI7jzFyT5w erzQ== X-Gm-Message-State: AOAM532x7KGDlbBGLJdiFtT0k1Sn1dldMY1ongFE/aLwYsZeot2VqAzF yaiUxeoR+uFRSWJu+DqK3Y20l8BVL+c= X-Received: by 2002:ac2:5a1d:: with SMTP id q29mr6436108lfn.550.1625563266181; Tue, 06 Jul 2021 02:21:06 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id 14sm1347305lfz.84.2021.07.06.02.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 02:21:05 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Jul 2021 11:19:47 +0200 Message-Id: <20210706092020.1057-2-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210706092020.1057-1-dcnieho@gmail.com> References: <20210706092020.1057-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 01/34] 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: 3E55PqJIAeQs The dshow avdevice 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 | 11 ++++++----- 3 files changed, 8 insertions(+), 5 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..8e56dccbfe 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -309,10 +309,14 @@ 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) { + if (devtype == VideoDevice && !ctx->use_video_device_timestamps) { /* PTS from video devices is unreliable. */ IReferenceClock_GetTime(clock, &curtime); } else { @@ -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 "