From patchwork Mon Dec 13 07:21:34 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: 32406 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5072694iog; Sun, 12 Dec 2021 23:22:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3NBUtYxR2D2ZECVV/L6x4jW6g4iT+Dx9Lf516Qrn9ttjBHTUtUu8lEVDz7wonqz8wkiHh X-Received: by 2002:a05:6402:11d2:: with SMTP id j18mr64523357edw.318.1639380171947; Sun, 12 Dec 2021 23:22:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639380171; cv=none; d=google.com; s=arc-20160816; b=tt7xb4G21FzK65+Tg3NIcay04fQOpCTc6fWB9UskDgPTHRacjh7R/lo0aOC7lvQfBz 7ABPa3mN7ca8sRSqIFH2uyMHPL415UqyYUxwYpo+DaBhY+LnEKXq2eflrNgphU2B/Qlx NC5qooj51kfn9nLPjmVrborVRBVULbNN9DpNWRiCgh3DNvDYTtLoIG6iuC61wdssIJTp bANSEuJ9Lm9DAo8eia5uaaZghC+bfSYwAZ7oMykDzeBOULzhClN6YStf5Pv1aWS59FIO Wc71P0Ho8Jdkk81rNidbRZKLXAmGS0f4F/lTggRS+XoFwVtEiFde35yPczW0rghMK2Uu bQ2w== 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=IkAQMWZDRvT2JBsS8zGHixWDmE0nfvXgRbzBPxEJfJCE1rpKMh4beMWF2ZOaYSsyHd q/HtkDh6NT9efGWgTXdXXARbHlBG65TOkn9heX1I1S3/otUCX9TRZ1F/qIYtFKswog6j NsFizUdMCCIJjS1NyuNsKz1BsOUZWVHSOh8QyK9xvMLumflp7uvZk5rCHDGpHXMrnFGM WH2wFjMdh6i9x1feTpHHzNxOdz28jg4ImiBteR/hhUXiD9nowp65sD2ekykds4igCZzp jI9wJT5eIgQTVA7OD23+2sVDqWAJguNAUs0yXrOzXw0LU10w+MccuLGtR1hsJuLsjYXt /qzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=XyWnIL4G; 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 s5si20633133edd.18.2021.12.12.23.22.51; Sun, 12 Dec 2021 23:22:51 -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=XyWnIL4G; 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 0AE9B68AF1C; Mon, 13 Dec 2021 09:22:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ED5DC68AF2C for ; Mon, 13 Dec 2021 09:22:29 +0200 (EET) Received: by mail-lf1-f48.google.com with SMTP id b40so29028032lfv.10 for ; Sun, 12 Dec 2021 23:22:29 -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=XyWnIL4GulGWLTaaor5amkXHm/ZtyURxeZ/lcQ9m6Z/7xeoG67GstM1W0Z70fYuiWm FpcjgWfkKzpW4M+COBoSiQidUydWW538bE8qUTLhsc3eC6qDwRLU/u95wrzPRgrPunzF YvVfU2D9U5ZsT4CVMXyejDWrt1Q5qEZr0Gfry1MILvDtvYiPwb4WURa6YeEKIO1UHj+i LOKKTq+aKjS9zDySoSSo5Tn2R1nC13ygI3hOvzthjTMEnDYJpNHhORzeG1usYjR9YTkY ONrpanR6lpeL5x72KOfE4sptEuKX5EBHK97EkGVvXl3SB1bw3IQ0rC7Lc0KrW8ZsBP9h xB/w== 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=JT7ea6erM3BZAP8xijLqCp0V+C2CEscYvju+iw0toQSXoKfW3yeEtLFFbeWCztB6g0 hPcGmX5arvEoeK9pEOTC4vJ/1WJieh/OOCu9mOzRCM9G0Qish4F1VhyESqqmHaVscfis CFzRFVe2vS0zR4+Xz554Z9FwCUXg/Xn08PbRagGYO0pkBMhZl8p/ZmhoQ0hfNt00N53H gA7Wujx+CPgb+mcWEd8/6ccvSBFLvOAHP8awOLn3a8MhsdsYyS8ebpiPOa6X1faEDrZw TSUPSiqBSRIf4nlWMZ4R1blrQLaSoat4ZZtMu3TwkDZR9Nrw1lsn3sC3DpsoyROOzUtj 2iLQ== X-Gm-Message-State: AOAM533LJNiQI+HEAHvlmzYPDVwc/y3gizFpw4ghyNNmyqEb4cq+ma8r 9zVREdxjviqSqwomlVs0XRMHv8ODdCJ58g== X-Received: by 2002:a05:6512:1148:: with SMTP id m8mr26943297lfg.456.1639380148722; Sun, 12 Dec 2021 23:22:28 -0800 (PST) Received: from localhost.localdomain (84-217-56-54.customers.ownit.se. [84.217.56.54]) by smtp.gmail.com with ESMTPSA id w6sm1321544lfr.11.2021.12.12.23.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Dec 2021 23:22:28 -0800 (PST) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Dec 2021 08:21:34 +0100 Message-Id: <20211213072143.993-5-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211213072143.993-1-dcnieho@gmail.com> References: <20211213072143.993-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: J8si14Q4OH/n 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; }