From patchwork Fri Jun 11 20:30:32 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: 28207 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp762297iol; Fri, 11 Jun 2021 13:32:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZNXO1hfCD9yW+u3nygluXLIkmrN7/IxCYRKw05jMNz+5lpOiUo8u+/dKDW9XSbXMvbFhu X-Received: by 2002:a50:d6c6:: with SMTP id l6mr5593195edj.3.1623443531344; Fri, 11 Jun 2021 13:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443531; cv=none; d=google.com; s=arc-20160816; b=uFlEFBbNHlkhErMrqkSl8HFln/YMg+vJ16YomL/7uhdCk1kBZIWr6d6orV/vy77dyF B4CaCOUFJ94ioVxbXYdtBVygLniymd2Wv/ADCteXd78JOQa5tIXUV1BptjNZ6J82HdZn 3BRoDtxCAl2tfm1W5Kf0aP2DkDUcVtltC6PWA9Dkd11Qk5tBtxfbt57LSLLSikT/12bS sqD7uT6Z/+MOsitCwcD55xXOYFsBg0c1ldbUlwkJAFGKjKUgkrzt+HxNta3htzpr6Q79 dFV/T144KbcwkPEw8kAp6CIJuZ5F2In0pbBZF/8K9jUKxV95yfCv6inreLX/OjRUFLLO BiGg== 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=kYAZYOZtF9xhwIuqeDYP34z4yQk0BzB2rqBgCkwN0Tk=; b=HoiJfyrjcrUvyNOxNhlr5lOcERiiGeuoYXpobEtf32WnDikGwdFTNXR7UNspoCsZD8 DWKqGFJHdmaBnUMuTUAMegg9Vxn0CNwIsC+hNtTYlA1c5jeXSTJnWmWkzej+aKzn8DQA 5Sr79ZYSZoXcX4FYbmyjnJQM88Z1cIFM+ravBvaQsuHxTvcotqSlHjWtmw76Iz3qNjpw 1K0TWWB/ePOxD4el94E5NvNbG3Ax0s6ZJ71D68B8QWIBrE2kQ1HjmhOA+12Up23NkwAD ImArBwa6dpLpglNm3ONLhS39IGzmMypbKcAxYCOlNgFUf3L1Cz4q1eBuV1ZbBWVlLRPX YvKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=oOvHHRk3; 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 h93si6210942edd.584.2021.06.11.13.32.05; Fri, 11 Jun 2021 13:32:11 -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=oOvHHRk3; 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 312A86809E6; Fri, 11 Jun 2021 23:32:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 559C76807AA for ; Fri, 11 Jun 2021 23:31:56 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id f30so10381614lfj.1 for ; Fri, 11 Jun 2021 13:31:56 -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=SbExGgeUT35U6RmVJmhZABx69VMLgDlfh0lckw2KIEE=; b=oOvHHRk3mfuLiFhs45N0OPRIwwpvEmlJcC2tVJDAC7Cly7F7C/lPgiLeVmZVcRsjDW eUvB32DkJRQpmg6CMoIQxoBzykKBdUgvoZdRFJZjNQfSBh5vTTh5YA4c91VyRF5U0N7E zjGBJ1ty0ClrsuoC8NKAuPl/eU/O6ngDITgo8qbQgp07wlUfN/au2piXeloUuAEubZBC gHUc/kQenpRYLdFowk5pI2OMlwQKHgyrRyqIxHUE/4svfQDpCyR3F+NOpIjduWY5jgG6 OoYesF4KTbJutdUSrPCYEVyO9ZHcbhVAEyt8k5XAVmFSMangp9P0k3b1XRtXIA5v8Wke xXeg== 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=SbExGgeUT35U6RmVJmhZABx69VMLgDlfh0lckw2KIEE=; b=TGwuFG4gjlnH/1JjDc26qyS5h2WoIlgOLea8xMNSSNrIHA0Qp5fxGQC8QHowEeuScX NuUzKwicdY10ZpzaS556KUuTLqtwo3p2akisJ3E7jy4ckOcxCpl/8igvgakku8z0iS2T irbrPQqdOBlKKxlijlXOutVho5/vKm15HALJAXRVRaDT8JTDSoyO2Y5G0Hm8ze7PPSvv dAyykpBUAFHB9DxhzDp8ioclgYfky92lMabzgxNoGikv/LeUeReV7FrkRUrmbrI6LwOT X8OvUZLlKMvwe50UNU6IDWcKWGy9LejSC/OtTKPav1QFy6lFzU/A4mDKygby3d8iXb4z XVPw== X-Gm-Message-State: AOAM532O4tnSdLpPSYz+y9C7cde2pymzxg8klJNr5gUdpErIAV8+Qk/Y qkDr60X4JTaRiMo8R39BP02bM+AC6FmRiA== X-Received: by 2002:a19:645e:: with SMTP id b30mr3650221lfj.577.1623443515366; Fri, 11 Jun 2021 13:31:55 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id o21sm684885lfr.253.2021.06.11.13.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:31:54 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:32 +0200 Message-Id: <20210611203104.1692-2-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 01/33] 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: igVi/AI538EN 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 | 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 "