From patchwork Tue Dec 21 13:53:28 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: 32793 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5444354iog; Tue, 21 Dec 2021 05:54:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUSjE2dD/JT21pOvLNIOhjcW+kMSlClw/Gmapk+MwgwrCIUWEX4ogjoZ6B2K+GExQ73a4T X-Received: by 2002:a05:6402:2793:: with SMTP id b19mr3269947ede.395.1640094882820; Tue, 21 Dec 2021 05:54:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640094882; cv=none; d=google.com; s=arc-20160816; b=VKkiJ3ldXh4O8RsEtAukU2pxVeqt8NeoGV1jSki+Cdr2iRzEIAR2j1vqw7PRh9lR3+ ZeoXaXfhtdHjIURIZ8ajD63VKIcE4kR4ZoBEFm+swny3ZrBo4CNSmjvIH73f+HHuxJ/4 GVsouFXoymgSwDfVFFbkFSFALkEZrzqEtslzzBShmAP1trHq8H25Dmr5yvVrr9p2UMLV dCNVYgEAfVjR2NzSGs8MrhkqTD9L8+waBW1WJ1geBs2abB2vfTRB5THV8TXRFKU1FbKu Mea39Pax49MTQ6TteZbgKJvf+P3v4ZFeA+E0z86+xqLb13iESaRONXo5iN0zjZJy+2xU iygQ== 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=CsyJmInIIqrJ4/bdutTZYqjA+qNMkcKjh/c0+QFZiQBOq7xpB+jLuGSZxeyUsZ+tR7 iuK7946XqQPe6qRozssZ+v/TohIlG5Z/IHnH1JKiJ6NQOipSifAMmbYHEY/B6+twSkDF gUyKRbsrma8cVvjeUZsdl8q51twFirwMDBN7M4n04KnYO3rLTqokcg5cA/0o8j4oVUxP 2VVOFn0CCcIXZQOrMcfTgstXtugueoidLrDnbAU5/J7+7/pkNjiDmw3Y1cFs9hEj8vks zWZm98Hgqx69ISjsoK7yHW+s5bEzYPZBfLtfUDnJ5HZ48bU3Hcjs+vN8nLs9yMRj+MUd KWSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=eGIyLzME; 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 du16si3653084ejc.647.2021.12.21.05.54.42; Tue, 21 Dec 2021 05:54:42 -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=eGIyLzME; 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 57C2C68AFCF; Tue, 21 Dec 2021 15:54:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 39C6D68AC7B for ; Tue, 21 Dec 2021 15:54:13 +0200 (EET) Received: by mail-lj1-f169.google.com with SMTP id bn20so21530990ljb.8 for ; Tue, 21 Dec 2021 05:54:13 -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=eGIyLzMEgBWKn+rCeLfzE8Qbh/7CYBGEgX5pJzh+tpeJuFXl52rTE3FMlAiiBmYGVU 07ezbYVQ4enpkdwboPjjfKHG8OWACR9JI/4XGB6CYF99W39gHb9lXZBjnFsICTUzrmHz 7tOzUoakurcxFT1cwNCZkzoOqPDYhLo/K5wif0OEp5Ufb+KcPnbhyfjOBxb4/q7p42ne z88hqqwCHEYTT7PJnx9I4GY/FUrWTVq9bBEynJf72NAl/Nd2NVx0tEm2YUIN3yGjGoMl ez0rYFRpUlmBGyHNBwV1aPxUpV610wdOqvO5H6zeYZZ9E+HtS0B72Ws1NTnS1+zXC3JE 6EmQ== 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=2zGH5naeKzQWHrbLsUWRwrpdzK5sXZi2JkezcTdlTX2RvDyC0xZOOw9DZn6mFDvWik hsE25P8vK+uwQGQ/Z14Sx9k1TuyB0lajvuavm92MSySDA9+xV+F91hRtzHQ0qH9jtPoR sh4iNJ5BoKACMlSpzEKOfJ6cNUPrtD8VwoFAycmohf4mAiHbHMgPvatHXnLwB6J+MSCD Ly3kh73JDvWIwaXI7mI7nLyOocbOvHWKgfMwwbC9YRq97mpDLRAns0wVVwTEk3+aN7hZ cTt8uu2ljQ//bby2YSJKPoaTkbyHhBnMpZt86C0XT0i4/Kz4EJea8bUeK3mk2So/5h9F HNPA== X-Gm-Message-State: AOAM532QnOZGLRBDNWduqydCgBNYwJznBj4eeLuOYYmZbxNhPSOa0DL1 Ftgev26RIQZ5DDfwkgYbCkhH6WiFho2nAw== X-Received: by 2002:a2e:a311:: with SMTP id l17mr2537756lje.9.1640094852998; Tue, 21 Dec 2021 05:54:12 -0800 (PST) Received: from localhost.localdomain ([196.244.192.13]) by smtp.gmail.com with ESMTPSA id r3sm101768ljd.4.2021.12.21.05.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:54:12 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 14:53:28 +0100 Message-Id: <20211221135337.1348-4-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 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: A/v+CvTW0Vcx 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; }