From patchwork Mon Jan 29 18:31:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 45888 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp1713426pzb; Mon, 29 Jan 2024 10:39:47 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX3wsBAtUd93kCznSBM2o/zxcsb5Ml7oGAZljQpAvP5Garc7gP8qG+Uz776vWAcPyOnLnN6p22RAjLOeyjL+ccDNQ0znjFUe+WwJA== X-Google-Smtp-Source: AGHT+IEOlbG9GVAdgruST1oP820EBmWo5WxyyOzeslaSk40pmPnWGkusF4qJsA87wdA5kqempMKj X-Received: by 2002:a2e:5109:0:b0:2ce:1d5:c225 with SMTP id f9-20020a2e5109000000b002ce01d5c225mr4509940ljb.2.1706553587277; Mon, 29 Jan 2024 10:39:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706553586; cv=none; d=google.com; s=arc-20160816; b=DwMQALXEfOUEUZO9a17URTkTYYi/bPOT9fU5Qpgn1dE25ZlgM9ENRUrx+tDNapwcXv 1guHXr5q6gAc3Rs+na/VhyJEl8F+xVsGSK3EiS+8c+eGivpgF//0vSZRayN/a+a54XD7 kzcJ2wVsbLFF8pK8imdFrPROCYpwUCB76mvhy5KztzgevhflJrmRuBw5VhseLn745/ur GbHrus/lYzsA1Wlz2ZyPyabbbum/Lb7rYYtqwUJmcyqoqaDuOXvhRF0p6V9XeYKf3Iof NwblXqdtJA+ovZxUVBV68I1AoPWYszf/Den6KzKhVp4qomUKGcADGU1mgRCdjfy8qWnr t5Sg== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=NA9VUqGu2z0BqBXnla2WLyIrB9JRaxeBbBChOoOuahw=; fh=LnlYe9qYwgML7nWWXqAumr7YCmPjjpEPjQf6GasgJC0=; b=WNNpZt7EPnNLc811kj63nCVrFs/XGTUNYeLF2BrQwDH6Ddubx2vrWbbejjf6OBdWw5 aY+vK5rHasBnpZhEyrvG7SD68eFvxOKyHGutTHpIn1mOibvh9c2FtCJEyePrTb1boDWi KtE3KH0Ve0BArJ6jm3SyA/eRrGAOrm2HN8WqTzcaXY4DwLhGfMDUyGeXLG8u4Uorj/Gl /yt3nfLPx4C7u1bq6iCdIgJX5OApTOlPXe5CI9lFc2BiFCh2UwYSYzKigbmI0RVu/rOJ RjFWKuqQiuVjL6TNK9nv6DIyRE4FxohgDX8VQbob9NHqKdpEeTOeDFzARzGWbSYEUKUc qo8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b="DXJRdCy/"; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d21-20020a170906371500b00a359c48247csi1520070ejc.330.2024.01.29.10.39.46; Mon, 29 Jan 2024 10:39:46 -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=@khirnov.net header.s=mail header.b="DXJRdCy/"; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E35C468D238; Mon, 29 Jan 2024 20:39:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D743968D205 for ; Mon, 29 Jan 2024 20:39:36 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=DXJRdCy/; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id F117F19DB; Mon, 29 Jan 2024 19:39:35 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id sVRoag6OZo8J; Mon, 29 Jan 2024 19:39:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1706553574; bh=D4UdR7j5SbAsNTxw8aiICkMhF0v6CO0bMQzqWGs+vBk=; h=From:To:Cc:Subject:Date:From; b=DXJRdCy/6P9hWgrsbgBgZXhmhkwSI3wfz6FtyckIJ1k04RmNhoPG1gJpMx1+NfB9v dtPiROIJ2L+4b8f+PpauYIbgfxyjPoXWslnWucmThoYm0YByfyVYmTbeE7RXcn9rjK W96ulj3Ms1wJqpzNvNiA8C6qUpUwM+vpI6jwO/W05bE5gs/B9K3Pvl/WkEadDX+8RZ GPBUDueg6b26TGPY5B5F1sCpRQL+zI2Da5KCrMRrcXNCAHgFf3cMPXNJ//Q+I7Emna OMfyfXkBpwJPrgbIlrot2dGNKLWk0Q6PKQmACI9qTPLtEcf4qlKJrsUwheEiErjhX8 giAjTZWK02yPw== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id E657BEEB; Mon, 29 Jan 2024 19:39:34 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BF4663A02A0; Mon, 29 Jan 2024 19:39:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Jan 2024 19:31:38 +0100 Message-ID: <20240129183159.7140-1-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] lavfi/vsrc_ddagrab: add an option to avoid duplicating frames 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: Timo Rothenpieler Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: EnUOisOdllez Tested-by: Jiří Eliášek, Misha Aizatulin --- Now requested an infinite timeout from IDXGIOutputDuplication_AcquireNextFrame() when a frame is required. --- doc/filters.texi | 15 +++++++++++---- libavfilter/vsrc_ddagrab.c | 9 +++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 1d70f4d934..b9b539acee 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -28713,10 +28713,10 @@ it'll always be captured. @item framerate Maximum framerate at which the desktop will be captured - the interval between successive frames will not be smaller than the inverse of the framerate. When -the desktop is not being updated often enough, the filter will duplicate -a previous frame. Note that there is no background buffering going on, so when -the filter is not polled often enough then the actual inter-frame interval may -be significantly larger. +@var{dup_frames} is true (the default) and the desktop is not being updated +often enough, the filter will duplicate a previous frame. Note that there is no +background buffering going on, so when the filter is not polled often enough +then the actual inter-frame interval may be significantly larger. Defaults to 30 FPS. @@ -28749,6 +28749,13 @@ Passes all supported output formats to DDA and returns what DDA decides to use. Filter initialization will fail if 10 bit format is requested but unavailable. @end table +@item dup_frames +When this option is set to true (the default), the filter will duplicate frames +when the desktop has not been updated in order to maintain approximately +constant target framerate. When this option is set to false, the filter will +wait for the desktop to be updated (inter-frame intervals may vary significantly +in this case). + @end table @subsection Examples diff --git a/libavfilter/vsrc_ddagrab.c b/libavfilter/vsrc_ddagrab.c index 9c59faf53e..7109f5752b 100644 --- a/libavfilter/vsrc_ddagrab.c +++ b/libavfilter/vsrc_ddagrab.c @@ -101,6 +101,7 @@ typedef struct DdagrabContext { int out_fmt; int allow_fallback; int force_fmt; + int dup_frames; } DdagrabContext; #define OFFSET(x) offsetof(DdagrabContext, x) @@ -124,6 +125,8 @@ static const AVOption ddagrab_options[] = { OFFSET(allow_fallback), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, { "force_fmt", "exclude BGRA from format list (experimental, discouraged by Microsoft)", OFFSET(force_fmt), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, + { "dup_frames", "duplicate frames to maintain framerate", + OFFSET(dup_frames), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS }, { NULL } }; @@ -688,7 +691,7 @@ static int next_frame_internal(AVFilterContext *avctx, ID3D11Texture2D **desktop hr = IDXGIOutputDuplication_AcquireNextFrame( dda->dxgi_outdupl, - dda->time_timeout, + need_frame ? INFINITE : dda->time_timeout, &frame_info, &desktop_resource); if (hr == DXGI_ERROR_WAIT_TIMEOUT) { @@ -1067,7 +1070,9 @@ static int ddagrab_request_frame(AVFilterLink *outlink) now -= dda->first_pts; if (!dda->probed_texture) { - ret = next_frame_internal(avctx, &cur_texture, 0); + do { + ret = next_frame_internal(avctx, &cur_texture, !dda->dup_frames); + } while (ret == AVERROR(EAGAIN) && !dda->dup_frames); } else { cur_texture = dda->probed_texture; dda->probed_texture = NULL;