[FFmpeg-devel] [RFC PATCH 1/2] libavdevice/pipewiregrab: add pipewire based grab

llyyr llyyr.public at gmail.com
Fri Sep 22 14:37:20 EEST 2023


On 9/21/23 00:10, Abhishek Ojha wrote:
> This is an proof of concept for pipewire grab to enable screen capture
> on wayland. Add a new Linux capture based on [1] PipeWire and the
> [2] Desktop portal.
> This new capture starts by asking the Desktop portal for a screencapture
> session.There are quite a few D-Bus calls involved in this, but the key
> points are:
> 
> 1. A connection to org.freedesktop.portal.ScreenCast is estabilished,
>     and the available cursor modes are updated. Currently only embedded
>     and hidden currsor mode enabled.
> 
> 2. Call CreateSession via dbus call. This is the first step of the
>     communication. Response callback return the status of created
>     session.
> 
> 3. Call SelectSources . This is when a system dialog pops up asking
>     the user to either select a monitor (desktop capture).Only monitor
>     capture is enabled in current implementation.
> 
> 4. Call Start . This signals the compositor that it can setup a PipeWire
>     stream, and start sending buffers.
> 
> Above flow is implemented as per the [2] xdg-desktop-portal. Once flow
> is completed, pipewire fd is received and using this pipewire stream is
> created and receive buffer from the created stream.
> 
> For cursor implementation, embedded cursor mode is enabled that means
> cursor metadata is not handled in current implementation and has no
> control over the cursor bitmap.
> 
> gdbus/pipewire logic, this is based on obs-xdg, gstpipewire and
> pipewire examples, and initial pipewire grab logic, this is based on
> libavdevice/xcbgrab and libavdevice/v4l2
> 
> This implementation shows the skeleton implementation and enables basic
> functionality. I'd like to hear opinions and suggestions to improve and
> properly use this.
> 
> [1] https://pipewire.org/
> [2] https://github.com/flatpak/xdg-desktop-portal/
> 
> Below are the arguments for pipewiregrab.
> ffplay -f pipewiregrab -draw_mouse 1 -i :0.0
> 
> Signed-off-by: Abhishek Ojha <abhishek.ojha at savoirfairelinux.com>
> ---
>   configure                  |    9 +
>   libavdevice/Makefile       |    1 +
>   libavdevice/alldevices.c   |    1 +
>   libavdevice/pipewiregrab.c | 1836 ++++++++++++++++++++++++++++++++++++
>   4 files changed, 1847 insertions(+)
>   create mode 100644 libavdevice/pipewiregrab.c
> 
> diff --git a/configure b/configure
> index e40dcce09e..325b10484f 100755
> --- a/configure
> +++ b/configure
> @@ -299,6 +299,7 @@ External library support:
>     --enable-libxcb-shm      enable X11 grabbing shm communication [autodetect]
>     --enable-libxcb-xfixes   enable X11 grabbing mouse rendering [autodetect]
>     --enable-libxcb-shape    enable X11 grabbing shape rendering [autodetect]
> +  --enable-libpipewire     enable screen grabbing using pipewire [autodetect]
>     --enable-libxvid         enable Xvid encoding via xvidcore,
>                              native MPEG-4/Xvid encoder exists [no]
>     --enable-libxml2         enable XML parsing using the C library libxml2, needed
> @@ -1788,6 +1789,8 @@ EXTERNAL_AUTODETECT_LIBRARY_LIST="
>       libxcb_shm
>       libxcb_shape
>       libxcb_xfixes
> +    libpipewire
> +    libgio_unix
>       lzma
>       mediafoundation
>       metal
> @@ -3621,6 +3624,7 @@ v4l2_outdev_suggest="libv4l2"
>   vfwcap_indev_deps="vfw32 vfwcap_defines"
>   xcbgrab_indev_deps="libxcb"
>   xcbgrab_indev_suggest="libxcb_shm libxcb_shape libxcb_xfixes"
> +pipewiregrab_indev_deps="libpipewire libgio_unix pthreads"
>   xv_outdev_deps="xlib_xv xlib_x11 xlib_xext"
>   
>   # protocols
> @@ -7041,6 +7045,11 @@ if enabled libxcb; then
>       enabled libxcb_xfixes && check_pkg_config libxcb_xfixes xcb-xfixes xcb/xfixes.h xcb_xfixes_get_cursor_image
>   fi
>   
> +enabled libpipewire && check_pkg_config libpipewire "libpipewire-0.3 >= 0.3.40" pipewire/pipewire.h pw_init
> +if enabled libpipewire; then
> +    enabled libgio_unix && check_pkg_config libgio_unix gio-unix-2.0 gio/gio.h g_main_loop_new
> +fi
> +
I just tried this and it failed to build due to missing locale_t and 
other locale related issues in pipewire's spa library. Upon further 
inspection, it seems Pipewire wants _XOPEN_SOURCE=700 but ffmpeg's 
configure sets _XOPEN_SOURCE=600. Not sure who's at fault here but I was 
able to get it to build after explicitly setting that.


More information about the ffmpeg-devel mailing list