From patchwork Thu Dec 14 10:32:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lena X-Patchwork-Id: 45134 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4856759pzf; Thu, 14 Dec 2023 02:45:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJlwNu96fbGgS0DustZsdvUNewvt1ti5ox7SfweU2nufp0pQ4W70J6bomiKMcRDJsgXvhm X-Received: by 2002:a50:8ad9:0:b0:551:64cc:8a51 with SMTP id k25-20020a508ad9000000b0055164cc8a51mr2645728edk.19.1702550727879; Thu, 14 Dec 2023 02:45:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702550727; cv=none; d=google.com; s=arc-20160816; b=qYKjR2wr1IF+7B+8hhFI0pDVZio3l25kpQywvCYJk09QTeZsdF8Z/W66LW/Ih9yjHi jz8WFX6AQecoCMkuGe4YG6L6LhHPZrolhJQz+r+Bgg4kiV7Y8XG3rfIm+mJpFSGiyoLb m2xryCIfSfUSZzqqoizVEmuhusP2WbQ4JVL5lDqPS+28rTzOzGkPPqm878t8qGRZC6Q3 KsxS9RnpPT8UkKlCGexyXhK9dX+yHVl18fiqHeY1w4Hf4IAYYYrq6ljybNsiFiDy45p0 u6+RbMmAJ6hLkvg/t3eCwbEeR3rAroomqh3T4HgJrq9RFQJIw2DXhU0zN/lqOMNDmpj/ n5hw== 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:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:delivered-to; bh=Uiw+NjncNYZ7vcITGCiYhou8hDRDCScqADXiwOCkj+M=; fh=7qJYe4gFsOfbnMqngV1mcd//qjctri5r9dc0bvozjyE=; b=QSEFJ3z7hdHIKyMsBQzJcw4Uk0woc6FMrv8jeyY0aiDSfq3IM/YGX10PWScregLcZd HzFBRIioVe7bOWB9rrZeYxvy3ZWWfOMizHG0/dZcfhp/DXj8Kcu9VAy6Rj9iTCqs0meH H7fL0yiu9ZvOl0ldb93+KsgpD/lok6+YwQbtWWLxM+E3O/VXYn629Et0V7grvg3K26H2 8ELX6QIgR/mbC3abchYs9BaBzP047Rrwb1rbJoPD2Aon1alfMSRwJiwGuETM0u0TeAZw JeCw7pJqyR/jAMlxumlHUTkKgH5v0jubDem1SCIE6XrIrCDZq1VQsRJU/dOiFWM8UpYF mnoQ== ARC-Authentication-Results: i=1; mx.google.com; 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 w19-20020a05640234d300b0054cd4b591d3si6703615edc.390.2023.12.14.02.45.27; Thu, 14 Dec 2023 02:45:27 -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; 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 4AE1A68D268; Thu, 14 Dec 2023 12:45:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.nihil.gay (nihil.gay [157.90.242.5]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 279D168D1B2 for ; Thu, 14 Dec 2023 12:45:18 +0200 (EET) Received: by mail.nihil.gay (Postfix, from userid 114) id 03CB39D3ED; Thu, 14 Dec 2023 10:45:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on debian-4gb-fsn1-1 X-Spam-Status: No; tests=ALL_TRUSTED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED X-Spam-Score: -1.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's * domain * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. * See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block * for more information. * [URI: nihil.gay] * -0.0 T_SCC_BODY_TEXT_LINE No description available. Received: from localhost.localdomain (unknown [82.52.80.11]) (Authenticated sender: lena@nihil.gay) by mail.nihil.gay (Postfix) with ESMTPSA id 1A7BD9D34A; Thu, 14 Dec 2023 10:45:16 +0000 (UTC) To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 Dec 2023 11:32:44 +0100 Message-ID: <20231214103241.25089-4-lena@nihil.gay> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] gdigrab: Allow capturing a window by its handle 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: , X-Patchwork-Original-From: Lena via ffmpeg-devel From: Lena Reply-To: FFmpeg development discussions and patches Cc: Lena , Stefano Sabatini , Nicolas George , Remi Denis-Courmont , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KXrlpj31lv/L Updated the wording of the documentation, and added error checking for strtol. I looked at how other parts of the codebase check for errors on strtol and implemented it that way (iec61883, filter_units_bsf, etc). As for checking if the string value is larger/smaller than a long, i don't think there's a need, as the documentation says it'd just get set to LONG_MIN/LONG_MAX and fail anyway. x11grab can capture windows by their ID, but gdigrab can only capture windows by their names, internally calling FindWindowW to lookup its handle. This patch simply allows the user to specify a window handle directly. Signed-off-by: Lena --- doc/indevs.texi | 8 ++++++-- libavdevice/gdigrab.c | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 863536a34d..a0c684f545 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -722,7 +722,7 @@ Win32 GDI-based screen capture device. This device allows you to capture a region of the display on Windows. -There are two options for the input filename: +Amongst options for the imput filenames are such elements as: @example desktop @end example @@ -730,9 +730,13 @@ or @example title=@var{window_title} @end example +or +@example +hwnd=@var{window_hwnd} +@end example The first option will capture the entire desktop, or a fixed region of the -desktop. The second option will instead capture the contents of a single +desktop. The second and third options will instead capture the contents of a single window, regardless of its position on the screen. For example, to grab the entire desktop using @command{ffmpeg}: diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c index c069232472..3153b6f711 100644 --- a/libavdevice/gdigrab.c +++ b/libavdevice/gdigrab.c @@ -273,9 +273,22 @@ gdigrab_read_header(AVFormatContext *s1) } } else if (!strcmp(filename, "desktop")) { hwnd = NULL; + } else if (!strncmp(filename, "hwnd=", 5)) { + name = filename + 5; + char *p; + + hwnd = strtol(name, &p, 0); + + if (p == NULL || p == name || p[0] == '\0') + { + av_log(s1, AV_LOG_ERROR, + "Invalid window handle.\n"); + ret = AVERROR(EINVAL); + goto error; + } } else { av_log(s1, AV_LOG_ERROR, - "Please use \"desktop\" or \"title=\" to specify your target.\n"); + "Please use \"desktop\", \"title=\" or \"hwnd=\" to specify your target.\n"); ret = AVERROR(EIO); goto error; }