From patchwork Sun Dec 19 19:21:26 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: 32730 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695540iog; Sun, 19 Dec 2021 11:22:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEs+l/Ap41XY0c02ToLno+fHrYp2Sbjdy5XYXzdxP4GOnJdYusztOHU9HgYt7FZkXgNGI6 X-Received: by 2002:a50:bb2a:: with SMTP id y39mr12541420ede.348.1639941774465; Sun, 19 Dec 2021 11:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941774; cv=none; d=google.com; s=arc-20160816; b=BWD8NaywqWOGqgZS40fkQdGDaIPvMhLg5AnYDRidN3kO2iByeifgJoY63fv35x7fnq iI9oad8KkTABaqriM641pbQJcxJ56Jt3uf8ea+S6SQQlpyDabrNvnMcj+jul0FzArKLe qAST3MYrpF6jwqIKQlr9kSL6/Ymyx5Mf1vTOj6jWWraUHkW+Iq5ZxkkZqbrLCgiiw6Wx cdUsxDlrPBVOoB/Apq8PJmPsrKLkrX8DzhiPnIlvb6i7r+I+8pFCtld++LQCXEKtLTf+ +qC7vvN8QbbnQT73kpr61zLrxAVYm/IakqDlxbmR6NPxc1HHKm2WpMWbuZ7DHxyi8Nu/ CVgA== 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=gToRTJsqgdPnurE3xYO4uXhF9qAOzAi1knJwJOEHjU9SnznwA4A455khDkNiahMm5A aHjS/16l8NtJVT/GX+jqz6C96MWu7yZBCplnRueRLBdpA8RkLenWC/eRW6AwBrgrAPoP G27J0MGRYYCva+wdSUSiC9Mqb8SJGthLBNKuUQqFct+apE+ijTw+xjCFv3/dN3asRi4U Uee2LYVfDIsc/K1GA4we9O36lLxNZB0v75qvxgaw39Lf6ATCAZrUR2dpKcrHrTol3Vws AmIPMw+TnGkr3MzKLBwjyZYLllrVHm6hM3HGRF/YxU5YzvBnGx9I/9gWrDcqOhkOHm97 3WTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="b5HB1/m+"; 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 qb11si9755415ejc.903.2021.12.19.11.22.54; Sun, 19 Dec 2021 11:22:54 -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="b5HB1/m+"; 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 C4E4D68AF81; Sun, 19 Dec 2021 21:22:27 +0200 (EET) 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 9DC3268AF4F for ; Sun, 19 Dec 2021 21:22:26 +0200 (EET) Received: by mail-lf1-f54.google.com with SMTP id u13so9647525lff.12 for ; Sun, 19 Dec 2021 11:22:26 -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=b5HB1/m+okSuunD66q0ti1UBNyxzypkt2N67H+x3oyB8I5LbdGlIPM5rklll4snW9D mQHeHMUIRN3beX7GgBQsAdKg5+V5KzjeMtkgcVbDBBLj29QNDXlgDk3OwfNtwTx/U8Il /piQ0ctXd90UpRTeUpistg9sXUqpjXKpKLWJIWkg2MAPfaknPojspHCIu5udpSpSkJ8/ JMYMGdRUqlgZOhGMGKUkyRbLpcLsPjWZ3cbdNDHQPwf86DCv1QlCrSU4WJfDEihq/gMQ yoZ1pNYFkhRZ0XKlcVkI09dOoZ8o7p0pWjqWnLpuMqXkJrOX2zOagiaJ/gSHHhb3BneL /QZg== 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=rnt7QI6i0UWqBXvxImkFW/9w9OeRTRHJQOP3KDXt69SXgpDkQSTuSiIm9zs2+6uGel C3lp9WM104Lx6cUIeSQnkxp3woWafcxaZgSYSMG8UBNVGegcNb1xU2jnVDDy/CUx3TUb oe4m7fFskNVg4MfKhWuZNQ+mi+wSW9lZ6ClxJN+5cwQjf91EaY/+SUo1/jRdo6X0W6xP XAgzorSL305ztpFnJlw1DiEr+5HoXHpsMbOGNaqbhXPu9BSuDigafo5TePg8kqR7Rz8q iYVDhbI1QQ4udcp6y6MEm2lJrdVmZOstPPQXEf0nqkOYfAlXXh8pjIBp+OC4mdAXT+dt eQFw== X-Gm-Message-State: AOAM5321yYtvarCQplIJ3S37FazpKkK5jmryXsofNyX278O91YK0iZLL nugKVtDlDI/TDhxMrmTbvizqthE+mep22ZUO X-Received: by 2002:a19:6e0b:: with SMTP id j11mr2221634lfc.226.1639941745354; Sun, 19 Dec 2021 11:22:25 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id x26sm1536079lfn.121.2021.12.19.11.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:24 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:26 +0100 Message-Id: <20211219192134.1296-6-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211219192134.1296-1-dcnieho@gmail.com> References: <20211219192134.1296-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 05/13] 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: fnxR7Fw4ASs1 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);