From patchwork Fri Jun 11 20:30: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: 28231 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp767369iol; Fri, 11 Jun 2021 13:40:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7MvMQGEQo3IAJ4AGKPeo+Vj0Mtp6WoBNkoiNuSq8nPlJoWGBG7YFavzOWSHLqULBUpHYC X-Received: by 2002:a17:906:5289:: with SMTP id c9mr5232435ejm.342.1623444043810; Fri, 11 Jun 2021 13:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623444043; cv=none; d=google.com; s=arc-20160816; b=tuKVVdYdiIOpsWVAdmep4Tw25Xlw20GrUvKKgyIaftfZ7jLGciNX8Rk9EIyCNcbaYX 1MBS8lS1/M380eVAMAFCvGiWYXKR1bIkEOUIAV4cNCC3AfkD6cqfqbsSXjdCXn6UoBly jQcUvgSYqAml3LlLr2kZr5BjJs92ifaZkFsARLcmP7vSwftfTMhgSdOwZwpB/SWpzfp1 KwMqdcGza4AApXhtkfyFykSUPmgSDgTze0xqO1Kyeb5RbF3AWDoruB/w7N9Xu/pR6ogZ HrT9rSegn4ovPRf3oCepxQOG0gBPczTfEmHzkZzFYrHEgqzwXwSHcT20dRFG0R1p3O2R K4zg== 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=77meImzbdS3Wg123h/r5CNEltt37/ZM5vmYIz1Fu0zM=; b=Zr24R14mgVwDp/rqfGqZEbGxDldkGoD17KvwS4Dkn46Z4mf53ZYZuqZ4rMkwZhM/Fg AKk3ouxMjnI3I/gFlADP2HYwWg7bwz3bIIeI6MKbXa0D0wQz6+RvCGm8ktpZiMgnkNwD KZLgV2XxiUMMnMoqg804cQT8W+DxjPoE9Hx7FFnXT/wlYnXBH/E7wSvzt0er1yIa4DZX 3UrMx4IrVxzXdFfRMUdfMPk7YerLEiQ3f+c5YaxdPlxGqb3uCPITkSPS9lrCnn1lMhQF HRcrRK07OZFCBJc5YHkrKcj8Ya4RgBYAoBZ+sPFK6o+GkScBRbvGGfYOtMmKqM7S3BGL PNRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WRIurASa; 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 t6si5732092edw.27.2021.06.11.13.40.43; Fri, 11 Jun 2021 13:40:43 -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=WRIurASa; 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 7DBD4680204; Fri, 11 Jun 2021 23:40:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A47368993B for ; Fri, 11 Jun 2021 23:40:32 +0300 (EEST) Received: by mail-wr1-f44.google.com with SMTP id n7so1198275wri.3 for ; Fri, 11 Jun 2021 13:40:32 -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=B7Y54CkZrOXtX1X35Gx+Xt+gMNhJm6+AeCVPasFc/hs=; b=WRIurASaXnpf/OT/QzYTuJtijNL7NRj9Ok4FB39P+G0dJZ68bKhjHFQgxXi0zJThGK HU7LJqiaDQSjK1dpCEtn9v3t2HOCtSjkEh7O3AqWedyqxDTApnaZOS9C/7p4ZjRGfcAD Gfa7IYAYSKKO9Te8e9NALu8NAf97mLJFAho0X3pIJCcS0NFYY2G2/NeGqzc6UqepOG0w AOjJzG3S4PLI4iftMZmVicwXMaBKi9sbJ1MZpqBKI+13O+EdCD9mMerFHi9HaP2Kg4Kq IvYHjqo7iqAK+lOtAJ+EbZ04s4Q3GzrfA8arLZDGQzYmUpXdknVRspzyYkHMEbcy0EC/ 1jUA== 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=B7Y54CkZrOXtX1X35Gx+Xt+gMNhJm6+AeCVPasFc/hs=; b=g+4HXe6SFlCnnSO57jvi/wXmWB2w7pfOILN8CbIEGre7Age0pGLgFVrL49moreCv1j IFKCWKs2SNgl7rnqfaP7H5MRMnnmtby01/t5CU2jQ7FMToq3O1+g7rzKTxXFYWsCNUId pOKbVOU85eEgc2hP7oCmHZ+Ntjvyk+qYhGc01aEeHmdcuToL7V2ZWwH49xpqrOP8649o d9Uc7L4/yDHrl2ZpqZsgGOLkpBmdaFVawBPYNyI5q+Z1e5cK08VV8zmMH9KqL3GjRWYT /A68hv07TWmnPP1X7HETG3MhUOQUkTwCOYYU0x7KqxaLa/xOxXlnJhgIeoY9DEcBZtJJ jjLA== X-Gm-Message-State: AOAM5319BieLB5TqKvV4/ulrdcEP09vaWj2hvtjzKfkNhfOU3XVA6lNx QoePe5hbsPbUAZ0Xg1cMwzafJww4oxETjw== X-Received: by 2002:a2e:9007:: with SMTP id h7mr4372113ljg.390.1623443549247; Fri, 11 Jun 2021 13:32:29 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id u24sm684691lfc.162.2021.06.11.13.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:32:28 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:34 +0200 Message-Id: <20210611203104.1692-4-dcnieho@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20210611203104.1692-1-dcnieho@gmail.com> References: <20210611203104.1692-1-dcnieho@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 03/33] 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: Gtv1XTLbYIq5 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; }