From patchwork Tue Dec 21 12:12:30 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: 32779 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5360564iog; Tue, 21 Dec 2021 04:13:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYybd/A4vp3DFQW5kh4e7bwtJAeR/CyQUkht5uCx8rtGnV4sODpV+XmeoVNhM7tPL27+qv X-Received: by 2002:a50:c38c:: with SMTP id h12mr2983798edf.72.1640088818104; Tue, 21 Dec 2021 04:13:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640088818; cv=none; d=google.com; s=arc-20160816; b=rnae1eKdUCDWjj913WdODikvP68xBg2YoODNhPbLr29+y0q1d3k1OH6fEhDb2khLhC uYvnQmGU/rlh7NELL++UQ9aOUud45gev281dPrpil3yQn975wIVp4fEpofqNVLW1f+iE N/Hjp3JBhh/YrSye7PcvC1KFnbie/ahSwPnbIJJTMiIxuNFwQk6aEDQjbbi4bAa4a2W1 VE5PvAvqqxw4CCjnqP0v8o7MnR7AtABAq5wzPGVirBMt/09Y5d+R04RFow9mkwRrtcqv GpfyIQ1InswTGLnAMFrQ+BwPB24VL1JrtzeXcDvzDpTB7XrEkXf7c64itKB8KsTI+vrn /ZOA== 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=pa/7AoG/Tn1IKWdkErCmAui2uj/lRNPvOKfWL9u3LsY=; b=Lze6Y7dY7Y3kbn0Na3ee1B8/pJnkhV6ikBxsKItto8SSzd9zrf4cPVxmjPoFMlh/Ov gKJL52GTlAhY7RcpGIASMvvUpHB08uyEVOmbnMD8YQGnnIUFVp0ec6GhhcP79+PU3keO EA6u5eVVHuLDjn2uVRa+j3S9ghsh/KIZ3TPed0st46RgnXUzmbilQHm8h3mlq84tq4ug fGRbOEDrzOe6u7Kbqj8rPJ2TAvy6bJ3/YptrKqFo5+RwyG7hkTEU7cZqOVBpqKYMi7FY tCnie39xm3B/P/FJhmM/qfcmi0qlO9f8Z+QmKmuMbP2ZeXhZzK0cb9vNIqnVbu1m1UDp 6hmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ZCAODhnJ; 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 dz9si6080953edb.335.2021.12.21.04.13.37; Tue, 21 Dec 2021 04:13:38 -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=ZCAODhnJ; 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 9B91A68AF3B; Tue, 21 Dec 2021 14:13:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 141F368AEEA for ; Tue, 21 Dec 2021 14:13:15 +0200 (EET) Received: by mail-lj1-f178.google.com with SMTP id a37so21050760ljq.13 for ; Tue, 21 Dec 2021 04:13:15 -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=tLBGkU73btm2UY8VXqRWlX4bo6pvicPCF5lFX+SbDcM=; b=ZCAODhnJ0GTL3pPftF3YNiiIyZ0tIRUOSkKcKh+nlGQoNEAUyA46G2J2oVu89yfCBs cuTEjfwntkymRy4kMXccX3ZBlkWhAMgIXxpyyJd8j/u8Wp1xiAv2R0mVMD55QzjEpZxK sY8km9Zzi+ohjmc2fVMw3Enimr65z/o8sbeOlQsMEbrYMKSTqg7rJqaX2nLcGPDY/cGH P9AqvFP6Uzag5kRAee0PmmA45vBv2LUtrCwcUExfOkxt8nNCR3SfAlSKSxptykCZdrqf IDnbcBEih1WFJ1ZDtOdsGXj4U/PoYUn/nRTMgnyv+PQMa2CNqnl2laHCnJool9IJhiIO qOrQ== 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=tLBGkU73btm2UY8VXqRWlX4bo6pvicPCF5lFX+SbDcM=; b=wxMn5SPfPCDTLKqfiLM1R4wsPQV8efs086v26nayx09pbr0b67k45FYKLtUqtwayzl AlX4O2zzRH7QOdj3yZW0zBgONe4Ba76KLxUOBwwY0GaeukJZ/GzYTBZZUrmHcqBB3NgC wyGQao+r2uF71Y7Cz0r31A3AYXKO+PoXUd8QotujwNFoqat6LgPimQGMapD8uGU5tQ/f /YrkULUB7FIoZLeNDHqVUg6xUnYUJhRPP1oEIW04Mgl5J44nRRGXcoG0jkDxr3SoM8Wf QMgQtme9qUP4r/IuiNWlA/w+YlhfdWvU3oNdAFg64GFX27mWgkye2hcm57m/Y9D/ucE8 Ln4A== X-Gm-Message-State: AOAM531CAgaa6u6FtJj0/w1VXo3q2GEbcTTGj0NCUyYmWjN6mPHYc0My xWpth7TfOpA2kD2U0HfpLwzd13h/kWzpIA== X-Received: by 2002:a2e:9617:: with SMTP id v23mr2277938ljh.363.1640088793693; Tue, 21 Dec 2021 04:13:13 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id d5sm554482lfv.83.2021.12.21.04.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 04:13:13 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 13:12:30 +0100 Message-Id: <20211221121239.1201-4-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211221121239.1201-1-dcnieho@gmail.com> References: <20211221121239.1201-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 03/12] 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: UqEVnUbcL/B4 No need to query twice, use value we've already unconditionally got. Improve variable names Signed-off-by: Diederick Niehorster --- libavdevice/dshow_pin.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index 8e56dccbfe..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); + 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; }