From patchwork Tue Dec 21 13:53:29 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: 32794 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5444484iog; Tue, 21 Dec 2021 05:54:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmtBjUY2e4TWLtxrICKbc+zNrja4dPtZbMLUN+Ln2Tzix5OnJATGy+0b1M1G/aN0bqsuO1 X-Received: by 2002:a17:906:eb56:: with SMTP id mc22mr2766346ejb.331.1640094893574; Tue, 21 Dec 2021 05:54:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094893; cv=none; d=google.com; s=arc-20160816; b=a0WJOwmMuDjXNF5xvRuKNSR7UfsMLBjQ/Gp2fqdT/TA90pDlIKZnx8kx6W+i1zJyn7 yttUUgkez61LehxCcqQeXehGDo6hOtzIBKYKnNsYmF9b3r1nfZceUk2NkTvz60BJ2KOx w1GzbUiJArE9e+0+QtHCbNKgl9AucJUz5SGnbDXQfrP+vxNYt8IiLmepv/eH5+3B1GQq smVqttaAz840hUG2lDQH+eHir27gzeQFaK9o5o3MoZCuI3oAi/MYRKqLQy9jFCiZRnBa 3oCiJ+seZDOpG2l5Zc7keNE+Lo/YKjpFwZH71HishefAHIcqECUlPuPoQNsTuUkySSLv HL4A== 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=bvagzn3t9ZMTbvWzqNQ6CQDKu2uFNdHK7+XCxBMIVPs=; b=TpTYjuJMd6zajpCl7AN5vBRwf6wEk9CmufHTAb5JS7rBy6Ib8TjQWkHwUqN5+sj/BC oChOpof83LzYwFj9tR2Gx3zEI1hKsHz+rabcoJZTiy6qEKKTNn2B4q30CSg6PGLBFYat CV7q7CW2FdO1ClCNbRKt4pqFwrKt9ZOe/5/1/9dyWDSA9zlfE6cHll9hvwC/Empwf3ag tE+iKy6WGWi///rQUxbGfCUs2tJT4N1BzboYIG7fH1XKVktddPIPE86Q2BLdmcxb5ddy 9QwdeZBsVplHSDc3HXtPlFtOxPh9Qyg/2oPhjlp/tfPoFLapVhccDmgkbkuMJWhHaJMm DHLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=a9B+k5wA; 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 h14si14886197edl.521.2021.12.21.05.54.53; Tue, 21 Dec 2021 05:54:53 -0800 (PST) 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=20210112 header.b=a9B+k5wA; 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 609CC68AFD9; Tue, 21 Dec 2021 15:54:22 +0200 (EET) 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 E904268A921 for ; Tue, 21 Dec 2021 15:54:20 +0200 (EET) Received: by mail-lf1-f52.google.com with SMTP id g26so13694006lfv.11 for ; Tue, 21 Dec 2021 05:54:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DA8hT6RJYqezw3uqiFxtsp6o5kao2G6PRwqIa6ifWcI=; b=a9B+k5wA2g/lpbne0BrOP7Afsw9DxU9wMagcLoEtKA7HlB0Jq6tfKi9vZc6IeXAtJw 3f2RHiOm9ANLvUMopX9kpgo9Jiuuf+5P4sdDo9ITV63rNBFXy5XR3WmzdhgRRth5qF4C z9GGrBkWxG/SsmxDppTBaWksF8Y6HewA7dv3MevkpDbIXsbbdzOvW9HDbcpsCBez67bv 0aRwFGAteygnQRNlxd2mkP1ficbxMWRINJZxPv81mhB+BaSkIX8BpGxj4IR5GRYXsKKi F/xEuvj7kfcEwsWk3FJeHxYJuTpvayroHUT1awRCDQQ9nYGKCzpwskOyoDCQNfzw8RvE ro9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DA8hT6RJYqezw3uqiFxtsp6o5kao2G6PRwqIa6ifWcI=; b=nwacyptFktoxcwgvU4W8ULsUZxO+t6P9rwsFLFku65cmG8CLvhIyIAHJVDyl1z/lnL mWkRKWvM7hX7aibmvGOeDWNI8H81gLdxEKAnJVVrVl/fMT7NxTUmkLFF1UyWdnLWnyk1 txBThr/rQEi6/siRp6u+yNCYLUCGwvWAcKh9zTUOOgCYfAXW5xVj+fcK035yfPH0ZyYx 44p2ple1egV8b3ntqcZFUWrUzAgs+AnKSY1gq0AU611E8BRd8CQch6eo4/m8u2mnbaeT r2X19RiEnjPO1Oyl7ZZTWKU3qrEYTZu5r3pA5ZeqFb022CqPnw4UXePpUN1uyCCmPDcn 7Sdw== X-Gm-Message-State: AOAM531NlwTPclo65H1htzKgloynb3qhnIn2wkbtxdf4TbZaO/1t4sBh 90d48PLwJU7XkuRB9ExXAkFxwmAT0hrzXg== X-Received: by 2002:a05:6512:39ca:: with SMTP id k10mr1955847lfu.496.1640094859751; Tue, 21 Dec 2021 05:54:19 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id u23sm2750910lji.56.2021.12.21.05.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:19 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:29 +0100 Message-Id: <20211221135337.1348-5-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221135337.1348-1-dcnieho@gmail.com> References: <20211221135337.1348-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 04/12] avdevice/dshow: handle unknown sample time 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: COZsM0tUPTDR GetTime may return an error indication that the sample has not timestamps, or may return a NULL start time. In those cases, fall back to graph time. Emit log when that happens. Improve logging in the frame receive function: now logged against correct avclass instead of NULL. Better debug message in case sample dropped: could now be audio or video frame. Signed-off-by: Diederick Niehorster --- libavdevice/dshow_pin.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index 1d0e880480..2d1fa0e882 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -295,14 +295,15 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) uint8_t *buf; int buf_size; /* todo should be a long? */ int index; - int64_t chosentime; - int64_t sampletime; - int64_t graphtime; + int64_t chosentime = 0; + int64_t sampletime = 0; + int64_t graphtime = 0; int use_sample_time = 1; const char *devtypename = (devtype == VideoDevice) ? "video" : "audio"; IReferenceClock *clock = pin->filter->clock; int64_t dummy; struct dshow_ctx *ctx; + HRESULT hr; dshowdebug("ff_dshow_meminputpin_Receive(%p)\n", this); @@ -314,22 +315,28 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) s = priv_data; ctx = s->priv_data; - IMediaSample_GetTime(sample, &sampletime, &dummy); + hr = IMediaSample_GetTime(sample, &sampletime, &dummy); IReferenceClock_GetTime(clock, &graphtime); if (devtype == VideoDevice && !ctx->use_video_device_timestamps) { /* PTS from video devices is unreliable. */ chosentime = graphtime; use_sample_time = 0; } else { - if (sampletime > 400000000000000000LL) { + if (hr == VFW_E_SAMPLE_TIME_NOT_SET || sampletime == 0) { + chosentime = graphtime; + use_sample_time = 0; + av_log(s, AV_LOG_DEBUG, + "frame with missing sample timestamp encountered, falling back to graph timestamp\n"); + } + else if (sampletime > 400000000000000000LL) { /* initial frames sometimes start < 0 (shown as a very large number here, 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) frame with odd PTS too high %"PRId64"\n", sampletime); + av_log(s, AV_LOG_DEBUG, + "dropping initial (or ending) sample with odd PTS too high %"PRId64"\n", sampletime); return S_OK; - } - chosentime = sampletime; + } else + chosentime = sampletime; } // media sample time is relative to graph start time sampletime += pin->filter->start_time; @@ -340,7 +347,7 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) IMediaSample_GetPointer(sample, &buf); index = pin->filter->stream_index; - av_log(NULL, AV_LOG_VERBOSE, "dshow passing through packet of type %s size %8d " + av_log(s, AV_LOG_VERBOSE, "passing through packet of type %s size %8d " "timestamp %"PRId64" orig timestamp %"PRId64" graph timestamp %"PRId64" diff %"PRId64" %s\n", devtypename, buf_size, chosentime, sampletime, graphtime, graphtime - sampletime, ctx->device_name[devtype]); pin->filter->callback(priv_data, index, buf, buf_size, chosentime, devtype);