From 28eae3bd862192f45f61ed158164e41c3abbb369 Mon Sep 17 00:00:00 2001 From: Quantum Date: Fri, 20 Aug 2021 02:22:17 -0400 Subject: [PATCH] [host] linux: add skeleton pipewire capture backend --- host/platform/Linux/capture/CMakeLists.txt | 14 ++- host/platform/Linux/capture/XCB/src/xcb.c | 2 +- .../Linux/capture/pipewire/CMakeLists.txt | 15 +++ .../Linux/capture/pipewire/src/pipewire.c | 99 +++++++++++++++++++ 4 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 host/platform/Linux/capture/pipewire/CMakeLists.txt create mode 100644 host/platform/Linux/capture/pipewire/src/pipewire.c diff --git a/host/platform/Linux/capture/CMakeLists.txt b/host/platform/Linux/capture/CMakeLists.txt index 5fd4d17b..0e8673d8 100644 --- a/host/platform/Linux/capture/CMakeLists.txt +++ b/host/platform/Linux/capture/CMakeLists.txt @@ -3,7 +3,19 @@ project(capture LANGUAGES C) include("PreCapture") -add_capture("XCB") +option(USE_XCB "Enable XSHM Support" ON) +option(USE_PIPEWIRE "Enable Pipewire Support" OFF) + +if (USE_XCB) + add_capture("XCB") +endif() + +if (USE_PIPEWIRE) + add_capture("pipewire") +endif() + +add_feature_info(USE_XCB USE_XCB "XCB/XSHM capture backend.") +add_feature_info(USE_PIPEWIRE USE_PIPEWIRE "Pipewire Screencast capture backend.") include("PostCapture") diff --git a/host/platform/Linux/capture/XCB/src/xcb.c b/host/platform/Linux/capture/XCB/src/xcb.c index 046227e6..e4504892 100644 --- a/host/platform/Linux/capture/XCB/src/xcb.c +++ b/host/platform/Linux/capture/XCB/src/xcb.c @@ -48,7 +48,7 @@ struct xcb xcb_xfixes_get_cursor_image_cookie_t curC; }; -struct xcb * this = NULL; +static struct xcb * this = NULL; // forwards diff --git a/host/platform/Linux/capture/pipewire/CMakeLists.txt b/host/platform/Linux/capture/pipewire/CMakeLists.txt new file mode 100644 index 00000000..d5310292 --- /dev/null +++ b/host/platform/Linux/capture/pipewire/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.0) +project(capture_pipewire LANGUAGES C) + +add_library(capture_pipewire STATIC + src/pipewire.c +) + +target_link_libraries(capture_pipewire + lg_common +) + +target_include_directories(capture_pipewire + PRIVATE + src +) diff --git a/host/platform/Linux/capture/pipewire/src/pipewire.c b/host/platform/Linux/capture/pipewire/src/pipewire.c new file mode 100644 index 00000000..592cfcdf --- /dev/null +++ b/host/platform/Linux/capture/pipewire/src/pipewire.c @@ -0,0 +1,99 @@ +/** + * Looking Glass + * Copyright © 2017-2021 The Looking Glass Authors + * https://looking-glass.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "interface/capture.h" +#include "interface/platform.h" +#include "common/debug.h" +#include +#include + +struct pipewire +{ +}; + +static struct pipewire * this = NULL; + +// forwards + +static bool pipewire_deinit(); + +// implementation + +static const char * pipewire_getName(void) +{ + return "Pipewire"; +} + +static bool pipewire_create(CaptureGetPointerBuffer getPointerBufferFn, CapturePostPointerBuffer postPointerBufferFn) +{ + DEBUG_ASSERT(!this); + this = calloc(1, sizeof(*this)); + return true; +} + +static bool pipewire_init(void) +{ + goto fail; +fail: + pipewire_deinit(); + return false; +} + +static bool pipewire_deinit(void) +{ + return false; +} + +static void pipewire_free(void) +{ + free(this); + this = NULL; +} + +static CaptureResult pipewire_capture(void) +{ + return CAPTURE_RESULT_ERROR; +} + +static CaptureResult pipewire_waitFrame(CaptureFrame * frame, + const size_t maxFrameSize) +{ + return CAPTURE_RESULT_ERROR; +} + +static CaptureResult pipewire_getFrame(FrameBuffer * frame, + const unsigned int height, int frameIndex) +{ + return CAPTURE_RESULT_ERROR; +} + +struct CaptureInterface Capture_pipewire = +{ + .shortName = "pipewire", + .asyncCapture = false, + .getName = pipewire_getName, + .create = pipewire_create, + .init = pipewire_init, + .deinit = pipewire_deinit, + .free = pipewire_free, + .capture = pipewire_capture, + .waitFrame = pipewire_waitFrame, + .getFrame = pipewire_getFrame +};