From patchwork Fri Jun 11 20:30:35 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: 28210 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp762800iol; Fri, 11 Jun 2021 13:32:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwu5hv+q+fX0jo7kBwohrnuFKeLl3CbxaDg/LZt5VfLQkmJjsNJUwVryn2s8fmbhi12KIW X-Received: by 2002:a17:906:b24a:: with SMTP id ce10mr5273875ejb.83.1623443576075; Fri, 11 Jun 2021 13:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623443576; cv=none; d=google.com; s=arc-20160816; b=epVLp8tgENsbP8SV5sV89Za7fqym2sHarIL+ydR52DjLbSVTpy0M6NpwaVPh+e4tvx oTzyzptPK4xRnr/90TRajl/X9FeheOQjYpmgft8plpJtdn6lXgZgBUMHs51nS2kmIu0O qQ89c95jIReI23biJt72kquVR72efYj4RUPDVgQ2cr86HEZaBQbZk4bh/bib9Ocz923i tPjpJLF0A0fLDUa3OKQ3zSNZEbdowh/OuXP1eYpdQbhhpQKcb3vQig6jmuCRm+E+1nxv Ar8GoVCm4HeRN4uo9eYtkQ1lIoW/TBWxk2lX6QtvlJzmE7Oz0aWPy9YyXWzdnBEYWAPA oDNQ== 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=1GNbKic4/hTLN8/M2EuCDzyPjx1FXZ2iUnm51nzwk7Y=; b=WH2kA0lEi/ZjWxliknKFz7ClTJNR7Ga+/pm5YKjZW2mZzF3E3wudRks2thtdy9Y4xJ 4wZCm0yz6AFoOfXtH8kXutt7xcz7881H8hIrJE4M80C3FOvROCpuw1y0uQc0pft9lwOJ Dxlqv2uqPBut07T5hVgOSxAVKlH99aMImny7h2Z1mxBUxqqkbL6P+nArah456G64Izcs 1q/uNCLwftLbRC6VNyhgsdjmJLxef8keCebn4JTQwOaT5PGhmUKBxXNFbfA0bO85JLSE o84SsL/VORU45qLyGfTfzMyLqqu4Y+sxwB7PdjAPq4vLRB1dj7g0elrDAfpymV/DuZ0Z bupQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OfRfbW1s; 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 os28si6808038ejb.695.2021.06.11.13.32.55; Fri, 11 Jun 2021 13:32:56 -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=OfRfbW1s; 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 9077E687F27; Fri, 11 Jun 2021 23:32:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6EF486809E6 for ; Fri, 11 Jun 2021 23:32:47 +0300 (EEST) Received: by mail-lj1-f172.google.com with SMTP id 131so11323539ljj.3 for ; Fri, 11 Jun 2021 13:32:47 -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=adnbYYXt3y1rSvkqYNUbMSM3zzoFE+m4ORetAFLtEoA=; b=OfRfbW1smin6hQWURr2aaVXwaIYMsJa/J71OWLFZRsStezJ6yaJxU2sO+obfLNLBw2 PAMTIoE/kaSlh9SadgBdRxdPOtiV3tSDAlDZYp8J93cVLjbCFL9C7FJ6yMg4rzcnqdAs 4FVbdZteYwZfRXqfjfYriFksxPw+1Emucl0pHgmieRPoya9OHuq+S3e7fjvw3tMIYya+ qhMQSvohs4YOye8rz7SKE2UPv8QP16Za3WxAigRiFs4JjsziAu8m2g4ADNmf74mfP+wN damN4kDNUSE8c0UGm6TWm7fDNX721r8uboj+uDh3JANF9kUh5DnOiFRVae3TvvV17Nf9 IjhA== 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=adnbYYXt3y1rSvkqYNUbMSM3zzoFE+m4ORetAFLtEoA=; b=gd1Q6gsvj34lj1dtCoCHOsWfEuyUBF1VaYcoAGTZpPsvi+VahP8eukXhHzpzAtQNsl ihOV2deGv+ayl9oD040xnM0xIXf38faQTJdpvCWgKuMnmEgYCnIcSiO73NZlaszrqLiO JrUrLIl3bvw+3KivP2M80YzUTw+PoFwKP/PYpYJqEWyWl5QMTCviKw4m4puLPgo8x4sZ yhQe+37hmHTSO962tm7hs1/gIg8XQkZKxcK7FdPZuI8I2VGt5j1DD04ngVQ4haKCjYOP o7RR4GBY31aDen7asjstDStwRydSruUAmxTBPVj++a7HBcGKTyktkOm9rYoTAND2n+BR QETA== X-Gm-Message-State: AOAM533Lf+dGDhAo+Bc4g92TD4KdNE8Z84DNN/W382v2OTrO5MaYZ7mT g8TkDYWfyTfmRqTg7o6RrjsMY/eNCxWRvg== X-Received: by 2002:a2e:9bd3:: with SMTP id w19mr4341282ljj.381.1623443566006; Fri, 11 Jun 2021 13:32:46 -0700 (PDT) Received: from localhost.localdomain ([196.196.203.214]) by smtp.gmail.com with ESMTPSA id o17sm687248lfb.114.2021.06.11.13.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 13:32:45 -0700 (PDT) From: Diederick Niehorster To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Jun 2021 22:30:35 +0200 Message-Id: <20210611203104.1692-5-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 04/33] avdevice/dshow: handle unknown sample time 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: tFISaHTqkYCZ GetTime may return an error indication that the sample has not timestamps, or may return a NULL start time. In those cases, fall back to graph time. Better debug message in case sample dropped: could now be audio or video frame Signed-off-by: Diederick Niehorster --- libavdevice/dshow_pin.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libavdevice/dshow_pin.c b/libavdevice/dshow_pin.c index 1d0e880480..310f48c85e 100644 --- a/libavdevice/dshow_pin.c +++ b/libavdevice/dshow_pin.c @@ -295,14 +295,15 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) uint8_t *buf; int buf_size; /* todo should be a long? */ int index; - int64_t chosentime; - int64_t sampletime; - int64_t graphtime; + int64_t chosentime = 0; + int64_t sampletime = 0; + int64_t graphtime = 0; int use_sample_time = 1; const char *devtypename = (devtype == VideoDevice) ? "video" : "audio"; IReferenceClock *clock = pin->filter->clock; int64_t dummy; struct dshow_ctx *ctx; + HRESULT hr; dshowdebug("ff_dshow_meminputpin_Receive(%p)\n", this); @@ -314,22 +315,26 @@ long ff_dshow_meminputpin_Receive(DShowMemInputPin *this, IMediaSample *sample) s = priv_data; ctx = s->priv_data; - IMediaSample_GetTime(sample, &sampletime, &dummy); + hr = IMediaSample_GetTime(sample, &sampletime, &dummy); IReferenceClock_GetTime(clock, &graphtime); if (devtype == VideoDevice && !ctx->use_video_device_timestamps) { /* PTS from video devices is unreliable. */ chosentime = graphtime; use_sample_time = 0; } else { - if (sampletime > 400000000000000000LL) { + if (hr == VFW_E_SAMPLE_TIME_NOT_SET || sampletime == 0) { + chosentime = graphtime; + use_sample_time = 0; + } + else if (sampletime > 400000000000000000LL) { /* initial frames sometimes start < 0 (shown as a very large number here, 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", sampletime); return S_OK; - } - chosentime = sampletime; + } else + chosentime = sampletime; } // media sample time is relative to graph start time sampletime += pin->filter->start_time;