From patchwork Fri Jun 19 08:33:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Acereda X-Patchwork-Id: 20497 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9D9E144B246 for ; Fri, 19 Jun 2020 11:39:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7395468B69B; Fri, 19 Jun 2020 11:39:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8EF2E68AF97 for ; Fri, 19 Jun 2020 11:39:33 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id a6so4297480wmm.5 for ; Fri, 19 Jun 2020 01:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=Yh2v/QwYA34a9BFTQEMW9JBjTC+C/giP2HHUFPZ7Sfc=; b=KJCjFeCd7RkzR0+djZsl0/zDAhxrYG69tCFVZFhRtD9BZxKOlam+X/Rml74vbeD/72 kJG+PceoWfKrzVuVMFo635gv7wYEDKdtB8rfSgyp3kWOcl0hL9a7GdMNIMNbGfw3SbO6 oVJVO1FkUjWN7Npuag5I8btWBLtAxiBn+H6Y8uZ/bFZl8rkN1vwfJF1VubYIAYPOUpPj gfkM9REKLYc5YgtsIvBHTQCBcFQvIzrTrXfl2jj6AwZ5oqa0pPbDgdifbvUlLhHN1whc 2dZDDV2MDoWFvT3NRAQtTibllrf5Lo1fSz8WrqikrghT9KUIeixSizvt5d8XKW5Mz9DS s2Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=Yh2v/QwYA34a9BFTQEMW9JBjTC+C/giP2HHUFPZ7Sfc=; b=CHduJHS9HS7TTfxulWb1at7BqqyeG2ZFTP/Y+hrpaXa4qB6e0J1DQTplAKj9UCjcp3 scMZ2nlYze7k0j6TBUtMOq62rxIPjb08pi7yP4TzUVONBaJV6ATYPrWWAi7fPah5M8xh wO0KPl0enst0n+M9qhTEweGSJ0vgva7f32gbOt5ozpsoAcbZFuWz3OuSKuwWwjewYMrC wtFxoMwNOQb8Y9VppjWu4I5C2jihCoRxLKa9g3hgoGCQd0Egw2J6HTeh0LtgIIkADCh1 srPdV4ANT8kmR/ULh35BapWkpN33zbFj4wiHr1GlDsBKf6fcAR8AqOL+Oe+xI+ZHNxeJ VxVQ== X-Gm-Message-State: AOAM533h/bSQc10UC7rJOX6VXDy1vA24T9EjkbgWJD+UDUpyfasRyTOK ze6fOJ57xrCSGtZlNy5n9BHnB4E7 X-Google-Smtp-Source: ABdhPJzLEv+pZOUUZ9NPmPcyq8XukT6AAB+shnfwmlqPZ494esC1I7rL8vZBNcLUM83/HPjaOuOUDQ== X-Received: by 2002:a1c:2e58:: with SMTP id u85mr2486492wmu.123.1592555582617; Fri, 19 Jun 2020 01:33:02 -0700 (PDT) Received: from [192.168.1.50] (134.red-88-3-74.dynamicip.rima-tde.net. [88.3.74.134]) by smtp.gmail.com with ESMTPSA id t188sm6243709wmt.27.2020.06.19.01.33.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jun 2020 01:33:01 -0700 (PDT) From: Sergio Acereda Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Message-Id: <59E47B81-05C3-4C9E-A7DE-7A498A5B871D@gmail.com> Date: Fri, 19 Jun 2020 10:33:00 +0200 To: ffmpeg-devel@ffmpeg.org X-Mailer: Apple Mail (2.3445.9.1) Subject: [FFmpeg-devel] [PATCH] avdevice/gdigrab: client_only option to discard decorations such as titlebar or borders X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavdevice/gdigrab.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c index f4444406fa..b09c88d94d 100644 --- a/libavdevice/gdigrab.c +++ b/libavdevice/gdigrab.c @@ -52,6 +52,7 @@ struct gdigrab { int height; /**< Height of the grab frame (private option) */ int offset_x; /**< Capture x offset (private option) */ int offset_y; /**< Capture y offset (private option) */ + int client_only; /**< Discard decorations, such as titlebar (private option) */ HWND hwnd; /**< Handle of the window for the grab */ HDC source_hdc; /**< Source device context */ @@ -212,6 +213,20 @@ gdigrab_region_wnd_update(AVFormatContext *s1, struct gdigrab *gdigrab) } } +/** + * Fetch titlebar height from handle. + * + * @param hwnd Handle of the window. + * @return titlebar height + */ +static int +calc_titlebar_height(HWND hwnd) { + TITLEBARINFOEX tinfo; + tinfo.cbSize = sizeof(tinfo); + SendMessage(hwnd, WM_GETTITLEBARINFOEX, 0, (LPARAM)&tinfo); + return tinfo.rcTitleBar.bottom - tinfo.rcTitleBar.top; +} + /** * Initializes the gdi grab device demuxer (public device demuxer API). * @@ -284,6 +299,15 @@ gdigrab_read_header(AVFormatContext *s1) if (hwnd) { GetClientRect(hwnd, &virtual_rect); + if (gdigrab->client_only) { + int cxborder = GetSystemMetrics(SM_CXBORDER); + int cyborder = GetSystemMetrics(SM_CYBORDER); + int titlebar_height = calc_titlebar_height(hwnd); + virtual_rect.left += cxborder; + virtual_rect.right += -cxborder; + virtual_rect.top += cxborder + titlebar_height; + virtual_rect.bottom += -cyborder; + } /* window -- get the right height and width for scaling DPI */ virtual_rect.left = virtual_rect.left * desktophorzres / horzres; virtual_rect.right = virtual_rect.right * desktophorzres / horzres; @@ -639,6 +663,7 @@ static const AVOption options[] = { { "video_size", "set video frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, { "offset_x", "capture area x offset", OFFSET(offset_x), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC }, { "offset_y", "capture area y offset", OFFSET(offset_y), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC }, + { "client_only", "client only", OFFSET(client_only), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DEC }, { NULL }, };