From patchwork Sun Dec 19 19:21:25 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: 32729 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3695441iog; Sun, 19 Dec 2021 11:22:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1Aydp4fyJL5OWlibbHxT/7oSnOKUnwvwS/i+jvfYsLThSovufMAlBCCDF71TJLGws+mp/ X-Received: by 2002:a17:906:9756:: with SMTP id o22mr10071925ejy.324.1639941763006; Sun, 19 Dec 2021 11:22:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639941763; cv=none; d=google.com; s=arc-20160816; b=qkztAoJSJmxizdcdcOc1SnUzVIMZYkGXi2rKSQtTBswH2JPynscSlu2dqvpIinVpYs 3wdpVSXUoSUxyim/rkljCBriaz9GUcMsDpm8WNvw8b4HfMk7epdlIhunaQuB/HvLqBoR xXrp14jJofabYVHrZtyrgrMmdU2S0bDiGRevOIOPMpHzpncsVyF7/RLZjBDe7Secc43k knKemqjucndsrpLEJ3JlTw7MsWkjihe4pl52VF+U5A0teH+r7K1VmjP5+6FcpETWr+kt 1pKKXfoTianvXc/kt0YLdM9GYWI9CuFoCu/z3Q0jEOCyrMqyYR7Y+acMFGe230r+a0CZ B0oA== 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=XX8Lt2U0WNfQY21qlyEIN90dwEe5Exn0Pbdzs4hWIy/4p1Bt/MLC2VqCz/JwB/1SFX 9NvN5cOnOp01co1nCN/c1nME4fRtLHtuRgJyaTsml8J2A6MjIuft1qDUB45vUalAH9bw y/tBanCK2+EEgpRwrWdphxa4KXQokuvZ2+h+3JaVbbo21/noU8kDG1Hwb1jo3DFB1ZrZ 2H2M8EGFU5AAq6mLTLSFenXiQkCKasCypfm150gjitwqFAfXncnZuUN8DOVEteB4DyXK Xg+6Y6L3nwtaQ0oubLKsIAHH/ntSKMbaVazT9WN8T93jntYeiBPSqzdH+mf4KRG00lMC DTKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=CPt1VvIM; 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 jg19si542098ejc.796.2021.12.19.11.22.42; Sun, 19 Dec 2021 11:22: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=CPt1VvIM; 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 013AD68AF5B; Sun, 19 Dec 2021 21:22: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 11C3268AF36 for ; Sun, 19 Dec 2021 21:22:19 +0200 (EET) Received: by mail-lf1-f52.google.com with SMTP id b22so16914189lfb.9 for ; Sun, 19 Dec 2021 11:22:19 -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=CPt1VvIM24uHqOYlXm0Yv9XFq/jnvhTFH15qvjHIP2hrwBz3Fs62kmG3r2zQTGkI0s malzBd7oGBaER0EzhLEbdY6nrE/o3XLoi9gwbmkG7YOqNGnfm2PE4shsd+l15pl/mWoL IZzBSP4hIMICoFVR0VTTELc+rigSCPCwQ1SjY2es7/ZQqRT8j9h88zbwijPg9x5l+vdA pDPlFyjFhDszBNcqWbqT8Y5WXURMgto3S0lPVJhb/bxpoI9qc/4TQ/yZlKV7NDpF+rwr QXkopAmgWtWdSCh8ie4PnbidEKtM54XvDnn8swC0yDabZkECUvgWf2nw1LV5rVQmvtPw zP2A== 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=XTlEN6Ecd25ypis6V0FS0NcSG5BRJem9eSE6KALw0JkopDmKAuFpsjtfF7qLAIKUPV O9v8ajlGo33x1AbUiJxuWEb25JqnFy4iYzThs2v/octpeVpmayyuN5+bO+c94wOgjYD3 NtKpSBnV87RQUfBZ9OEXNHCg7YnTXK3Ay/VeR9Pr6M0lWxZCWmkBeDr55Pg3I4fOlxqZ 6TumJtGD0uMn9BnMMtLUuW/DjXncU8JnYQR4/IDUyKd72ZmnAKDDTiPFVsoeI0DxczNb 6tKoB9HQ8gFlN0B7jNAlQmKTu9eKtH/hxC1Zb/rt6poPWQA+dXvBpUHOijy1Z2Ze+yFD WFDA== X-Gm-Message-State: AOAM531JGGT1yGCcl5K7M6vZnFiXAhCz03fHwKHceOCxA/8YN68IAL8J HjzQyKJSCuO80BdxNqTUwRSWZbZA52X0H5Lg X-Received: by 2002:a05:6512:ac9:: with SMTP id n9mr5772183lfu.460.1639941738829; Sun, 19 Dec 2021 11:22:18 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id z24sm2127812lfh.289.2021.12.19.11.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Dec 2021 11:22:18 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Dec 2021 20:21:25 +0100 Message-Id: <20211219192134.1296-5-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 04/13] 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: 1Da1jFf2ASkK 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; }