From patchwork Wed Jun 2 09:33:01 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: 28047 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp375259iof; Wed, 2 Jun 2021 02:33:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSUj1wXCKd+f6+J/spYbSWOExVbV8NGizp6JN3Kwoz31yFPSm1oBIQYZTRmtQIbNo1FWtW X-Received: by 2002:a05:6402:3444:: with SMTP id l4mr8196309edc.259.1622626405350; Wed, 02 Jun 2021 02:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622626405; cv=none; d=google.com; s=arc-20160816; b=K8Vzu7O2HaXgZuv2vjUw4kRIoncDrzl5EnS+eFBWrk70TkGCDwLamOYyQTzJbJmh+d VUAdV6wr6LozHTCxUIHspBflgKLNhlrQm+hfXpuwE+8q0LyZsRmh4zoE0vWAZwLpC5WM Uz9WMIHoJbibQyX9xol78IgzFDKXPQeRVtHAlT4LAjq0fWCB6mNWlSOQjiPZ2ethJr+f KokSECLY6ICs33PNJB6Od/DwI8xe/R8q795PyC2xztMA9jWoP+caRy1pHlUFVKUl3URc s5FnXH4ro6ORnQ4ZW53INnshi+FHuzwdud737UwHs6bE4r0iW53AMy0ERRqUOXIkUI/f szLQ== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=xROJxQ0yQg3rO0hVwbswCpffEOiL7hblh0BvFwz7WRo=; b=SEybJzuJ1ZODPQnowBYLLYMhjS3JkEPv+wQkXNxTKao5T8iWDHZ4cY6bYprwyTFyw7 ndoO3xvt32PS4enQac5enIDJhlecEywdPI6rzyk96zGSRMA997rsG/tngzagLeAaM0Ss b8NkAkXjC+RfMY3G85lQjjwuV5Y/XXMxueP2fuRL+Oxnx3f85tUqqEKUHJYcu9cv67HV VCuN9/BmnNIAsLgvgydTCDgC+Te5PzOVF5zUe/oWFpuPJiYxghBQPcnSw1X3UH4W0eW0 2v9jl+V7576Oi/bd8D5kQ0A2V8rRA4VHzkZ74r9kUl4awCAb4sO/6Yt42ijCANXVD53j vmMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="N/t6CDAi"; 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 hr4si1915469ejc.433.2021.06.02.02.33.24; Wed, 02 Jun 2021 02:33:25 -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="N/t6CDAi"; 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 46848689B43; Wed, 2 Jun 2021 12:33:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 928C5689C2E for ; Wed, 2 Jun 2021 12:33:15 +0300 (EEST) Received: by mail-lf1-f54.google.com with SMTP id i10so2382508lfj.2 for ; Wed, 02 Jun 2021 02:33:15 -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:mime-version :content-transfer-encoding; bh=KM5WEoEEQrlrThx9dRfc9yWP0kM8PXa+JWrAryXyYCM=; b=N/t6CDAivIT2KLa1aLsI3x7vYnRVWG1+EkN9qZjpKh5BAtvQanUu8LsPqHAh1apV9x 0g6+gTiAC3XCJAVny2V4gn/aaVayVisPX19dLpWI0UZ1LfEr9Jql0aEu5lKItubDnNIm AMto2xFfzUSuPj2kQn8wH/H/Sr7jGQ5HWeUWZ6+2mXg1BBUujRUTbHBe9qxd5Sg2sa7A zU6p+3ryDAagx0piM/zFoM/3Ad/QxEdHZlIHePBKshDG+BdViazC4XHkBCeVM1O9Nf/H 4gMibwzfjZAmcvqCg8QKztUbzXUEuKIkXm+cwDCD+IfyeKdRK2vZC5428vixQe4rm3N+ JHAw== 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:mime-version :content-transfer-encoding; bh=KM5WEoEEQrlrThx9dRfc9yWP0kM8PXa+JWrAryXyYCM=; b=HLQSEvLSEcv/tXNZydv4iheO3kkb/O2nsd5/TIdvJ4Pj/ZwlbFjbwKlKy9qn9vEnvN XWzjnbCGKBdD2IY1X6mwlzXF8sMBNsuUxyohliQz/2hbkutqJvjI9jENtnxNue1I+tfA tZrH2gSBmNPwzEzCNRE5DofAEhD4V83PlAbN4fWOxoLFsC6fWRJ3Q5uuWc+KX6U4VPPy r0hocZCWkd1f72Lc6vZ8nnlyZ9ZDVuAZJtU/4Pz2isrBno9pa3JNRvBijxOiF0Q8XmsS 5ZutCwdcX7/2W+3TdrVGHx9pq2+Naa1JSzOAh9nOcsT0x+PkkupyWroYu5VXOGPWXjmi 8Kaw== X-Gm-Message-State: AOAM530DkQJRjgaURKc6O8Z1uQLKhpcuDciA7H9ELaYeQwvjtHE4Fc4a NVgZguQQC1cTfbI+UUoDFCUafm8uRy/rRA== X-Received: by 2002:a05:6512:20f:: with SMTP id a15mr5903751lfo.618.1622626394639; Wed, 02 Jun 2021 02:33:14 -0700 (PDT) Received: from localhost.localdomain (deedock.humlab.lu.se. [130.235.135.183]) by smtp.gmail.com with ESMTPSA id m4sm2469238ljp.9.2021.06.02.02.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 02:33:14 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Jun 2021 11:33:01 +0200 Message-Id: <20210602093301.2073-1-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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: BunCaO57nYb9 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 (default off) enables them to do so. It can be discussed if the default show be on, and users can switch it off to revert to old behavior. That means best fidelity timestamps are used by default, and a fall back remains available in case the device provides broken timestamps. Solves trac #8620. Signed-off-by: Diederick Niehorster --- libavdevice/dshow.c | 1 + libavdevice/dshow_capture.h | 1 + libavdevice/dshow_pin.c | 13 +++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 8d0a6fcc09..6e42613f21 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 = 0}, 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..ee0d4a1b42 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) { @@ -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 "