From patchwork Mon Jun 7 23:03:42 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: 28153 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp3891172iof; Mon, 7 Jun 2021 16:12:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywyElXyevZo71ScMIbE6kzs572yuR5HHogXES4PD0LD+UTgE8LB/M0cJ8sRhHERjR3Wx2J X-Received: by 2002:aa7:d755:: with SMTP id a21mr22732427eds.146.1623107561220; Mon, 07 Jun 2021 16:12:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623107561; cv=none; d=google.com; s=arc-20160816; b=x4D8aaclw78Vk/RHBPx1AQgYxTmtholqlZhexug02CUqFp5LNsqJkYhWKfLjfJ704t +G/qx+jvuBOiwMd63Wr2lUmrUAGu3jepCDJSaSRkZAa66kbcX2dbngyrNmyv1+QRQO7+ GyxpHOeMTu0yJoJVFlQl/i3Gglz3SgWL1VJ14lsc45D4bxfZ8MNNYPFXzlEsGh+rIPTx i3/dvp40D4WTl2WA7MteagpQxAy49iOyh6s7+dP1mx/H513ypEzdSjVu9dbRTHHmJWVG /Giv2AoBq3lX3t7mKBD80vKvUi6Z+6TATdmMTU6BYDXjkiPDYaevUdmrf49cVoooM2S+ rMeA== 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=aaMH+qt3GozJrxSuAMoOXCF/VLBYSwoL0o/ticBRciY=; b=iSoGfdPOBxEqIthNjYur8RLT/xtW4EcmGkcMJZTBx6izacugRnbVMxyUrETCRHWEbW Ou3iVbMMHxe/WCzCT9eX9Fa7K77Ic/Wspyac1qEE3gjIJ6XmPbnk6XJEGyefsDhpgRb1 0nOmQfXZVHq3/chv6uifRH3JcxhEYLeZQ5lPn01nbiPV7QCmDAnq/v/5nmjivnhW0Wg8 CMb8DAFsnnyWATkh6hdMEJOaLu92lRBo/oEqjRiw6Ujegnv/KGxTiMQAivhAc5Hh5PVp +UpdlSmVIA1nvMbpXzbUZCgvRXT5mB+xr9kDWohxd3Jd+f/l3N3+w5w/GhmmrJa4XTrw iJWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=ecrRTV0F; 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 v11si13155404edx.139.2021.06.07.16.12.40; Mon, 07 Jun 2021 16:12:41 -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=ecrRTV0F; 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 B8FB768979B; Tue, 8 Jun 2021 02:12:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2DC4D680524 for ; Tue, 8 Jun 2021 02:12:37 +0300 (EEST) Received: by mail-wr1-f47.google.com with SMTP id q5so19430866wrm.1 for ; Mon, 07 Jun 2021 16:12:37 -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=+/0FysBxSdwFGrBRyG5wiqWrNxXJfirYCGv3vtM9eOc=; b=ecrRTV0FW2nzhCpzHHHiOGPhVBnE6VRlLsX3iRmWKl7Ej2HBOHcJ2eiegYyqSsnWwg 1hrzcpW7lkpXlIoq9N6bH5j8ipjTViBJrsqtWIBGm0EKlQ0+d/RANJqI+VJCdXP0NWFn noqP0WV2nelmS1jQeNa1h5LldlWT8W5NYL0AyRESmOizkhHN+KXU+BXXGgTN3ut0JOgq 1I1CfwhLiJ9CkNTiGmoBFqQKSwc1Ij3C5yfqGUP9+LwcFlFM8CwDLf2F75/C/OCY1GM8 +kvLgQNdDhMDE/wGE9ta55MTWIR/ZgSse/5ZnkqJTRmbeEaCWCaAJswgmAG2Tlcjkd4n pwKA== 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=+/0FysBxSdwFGrBRyG5wiqWrNxXJfirYCGv3vtM9eOc=; b=kXCkDKFUUM/yDVsP2hUBYyU4MkygnC+wBWE4cmKU04DP2tmLBfLi2lEAQDF8Of7VVI oehLOPtfMDKyfr3AzpqyCDsDIsjXmRmAAW2O+6FUHx03ayjQMIHGNg8kz9tEq92Yz8hD AB7mmdF/PQQAyMhtg9eCMPezLMF6706U9yJ+ZvL81KUjOi/GzBwqQWqDEyKW/hnjthJ5 Ac7KGlE+SiCv2bvFnAfdTSCg6D7yeWgdPrvM6GchN0TAZNGocPb3p5m1CagjK3v31tBZ Gt3LY7onYfaOMrgQPSB1TDriSY4nv1rZ0c93ELwGsGj95A/JBWSYLTz767dvNVgvjCtH 0BXA== X-Gm-Message-State: AOAM530ricLiVgUG94szlpnDdcwOor2Zeb6sBBkjbb7UNBSVuuz+mVBu xPG9Go/MJeEIyTPTlWY8z1cbY0+Vn3jUjw== X-Received: by 2002:a05:6512:38cd:: with SMTP id p13mr12887958lft.419.1623107069425; Mon, 07 Jun 2021 16:04:29 -0700 (PDT) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id v9sm1999563ljv.131.2021.06.07.16.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 16:04:28 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Jun 2021 01:03:42 +0200 Message-Id: <20210607230414.612-4-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210607230414.612-1-dcnieho@gmail.com> References: <20210607230414.612-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/35] avdevice/dshow: query graph and sample time only once 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: gvcHuCt5Umus No need to query twice, use value we've already unconditionally got. Improve variable names Signed-off-by: Diederick Niehorster --- libavdevice/dshow_pin.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index ab0ead8041..1d0e880480 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -295,9 +295,10 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) uint8_t *buf; int buf_size; /* todo should be a long? */ int index; - int64_t curtime; - int64_t orig_curtime; + int64_t chosentime; + int64_t sampletime; int64_t graphtime; + int use_sample_time = 1; const char *devtypename = (devtype == VideoDevice) ? "video" : "audio"; IReferenceClock *clock = pin->filter->clock; int64_t dummy; @@ -313,24 +314,27 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) s = priv_data; ctx = s->priv_data; - IMediaSample_GetTime(sample, &orig_curtime, &dummy); - orig_curtime += pin->filter->start_time; + IMediaSample_GetTime(sample, &sampletime, &dummy); IReferenceClock_GetTime(clock, &graphtime); if (devtype == VideoDevice && !ctx->use_video_device_timestamps) { - /* PTS from video devices is unreliable. */ - IReferenceClock_GetTime(clock, &curtime); + /* PTS from video devices is unreliable. */ + chosentime = graphtime; + use_sample_time = 0; } else { - IMediaSample_GetTime(sample, &curtime, &dummy); - if(curtime > 400000000000000000LL) { + if (sampletime > 400000000000000000LL) { /* initial frames sometimes start < 0 (shown as a very large number here, - like 437650244077016960 which FFmpeg doesn't like. + 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", curtime); + "dshow dropping initial (or ending) frame with odd PTS too high %"PRId64"\n", sampletime); return S_OK; } - curtime += pin->filter->start_time; + chosentime = sampletime; } + // media sample time is relative to graph start time + sampletime += pin->filter->start_time; + if (use_sample_time) + chosentime += pin->filter->start_time; buf_size = IMediaSample_GetActualDataLength(sample); IMediaSample_GetPointer(sample, &buf); @@ -338,8 +342,8 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) av_log(NULL, AV_LOG_VERBOSE, "dshow passing through packet of type %s size %8d " "timestamp %"PRId64" orig timestamp %"PRId64" graph timestamp %"PRId64" diff %"PRId64" %s\n", - devtypename, buf_size, curtime, orig_curtime, graphtime, graphtime - orig_curtime, ctx->device_name[devtype]); - pin->filter->callback(priv_data, index, buf, buf_size, curtime, devtype); + devtypename, buf_size, chosentime, sampletime, graphtime, graphtime - sampletime, ctx->device_name[devtype]); + pin->filter->callback(priv_data, index, buf, buf_size, chosentime, devtype); return S_OK; }