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

2023-12-27 Thread Abhishek Ojha
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 
---
 configure  |9 +
 libavdevice/Makefile   |1 +
 libavdevice/alldevices.c   |1 +
 libavdevice/pipewiregrab.c | 1815 
 4 files changed, 1826 insertions(+)
 create mode 100644 libavdevice/pipewiregrab.c

diff --git a/configure b/configure
index cd66e42850..375327d5fa 100755
--- a/configure
+++ b/configure
@@ -297,6 +297,7 @@ External library support:
   --enable-libxcb-shm  enable X11 grabbing shm communication [autodetect]
   --enable-libxcb-xfixes   enable X11 grabbing mouse rendering [autodetect]
   --enable-libxcb-shapeenable 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
@@ -3639,6 +3642,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
@@ -7102,6 +7106,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
+
 check_func_headers "windows.h" CreateDIBSection "$gdigrab_indev_extralibs"
 
 # check if building for desktop or uwp
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index c30449201d..f02960782d 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -49,6 +49,7 @@ OBJS-$(CONFIG_V4L2_INDEV)+= v4l2.o 
v4l2-common.o timefilter.o
 OBJS-$(CONFIG_V4L2_OUTDEV)   += v4l2enc.o v4l2-common.o
 OBJS-$(CONFIG_VFWCAP_INDEV)  += vfwcap.o
 OBJS-$(CONFIG_XCBGRAB_INDEV) += xcbgrab.o
+OBJS-$(CONFIG_PIPEWIREGRAB_INDEV)+= pipewiregrab.o
 OBJS-$(CONFIG_XV_OUTDEV) += xv.o
 
 # external libraries
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 8a90fcb5d7..1fa8563df4 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -53,6 +53,7 @@ extern const AVInputFormat  ff_v4l2_demuxer;
 extern const FFOutputFormat ff_v4l2_muxer;
 extern const AVInputFormat  ff_vfwcap_demuxer;
 extern const AVInputFormat  ff_xcbgrab_demuxer;
+extern const AVInputFormat  ff_pipewiregrab_demuxer;
 extern const FFOutputFormat ff_xv_muxer;
 
 /* external libraries */
diff --git 

[FFmpeg-devel] [PATCH 2/2] configure: disable locale use in spa plugin

2023-12-27 Thread Abhishek Ojha
This commit requires to resolve the compilation error of pipewiregrab
because Pipewire's spa plugin is requesting locale_t extension to
compile.
Which was added in POSIX 2008 but ffmpeg is using POSIX 2001 due to
which spa plugin complains. __LOCALE_C_ONLY flag is set to disable
the locale usage in spa plugin. Adding it in configure file fix both
the library test and source compilation issue.
Not sure if this is the right approach to fix the issue.
Feedback/Suggestions will be highly appreciated.

Signed-off-by: Abhishek Ojha 
---
 configure | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configure b/configure
index 375327d5fa..442d004258 100755
--- a/configure
+++ b/configure
@@ -7106,6 +7106,8 @@ if enabled libxcb; then
 enabled libxcb_xfixes && check_pkg_config libxcb_xfixes xcb-xfixes 
xcb/xfixes.h xcb_xfixes_get_cursor_image
 fi
 
+# _POSIX_C_SOURCE=200112 doesn't support locale
+add_cppflags -D__LOCALE_C_ONLY
 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
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] Pipewiregrab patch

2023-12-27 Thread Abhishek Ojha
I wanted to express my sincere gratitude to the entire FFMPEG community for
promptly reviewing the [1] patch I submitted.

Leo,
Your insightful comments and suggestions have been invaluable in improving the
quality of the code. I appreciate your time and effort to thoroughly assessing
the patch.I wanted to inform you that I have diligently incorporated all the
review comments provided for the recent patch submission. Your feedback has
been immensely helpful in refining the code and enhancing its overall quality.

Paul B Mahol,
Thanks for the review comments. Changes are incorporated and requesting you to
please review the updated patch.

llyyr,
Thank you for testing the patch and sharing your review comments. Two patches
were submitted simultaneously, and the [2] second patch addresses the issue you
mentioned in your comments. However, I am still in need of review comments
specifically for the second patch, I'm uncertain if this approach is the
optimal solution for resolving the issue and would greatly appreciate your
feedback on it.

As a newcomer to the community, I realized that my receive email settings were
not enabled, which unfortunately prevented me from replying in the original
mail chain. Hence starting new mail chain.


[1] https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2023-September/314633.html
[2] https://ffmpeg.org//pipermail/ffmpeg-devel/2023-September/314632.html

Refrences:
1. https://pipewire.org/
2. https://github.com/flatpak/xdg-desktop-portal/
3. https://docs.pipewire.org/video-src-reneg_8c-example.html
4. 
https://webrtc.googlesource.com/src/+/8d9d575920a906bbf2a7b4c5b10f0ccf046f1cb8/modules/desktop_capture/linux/base_capturer_pipewire.cc

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


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

2023-09-20 Thread Abhishek Ojha
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 
---
 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-shapeenable 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
+
 check_func_headers "windows.h" CreateDIBSection "$gdigrab_indev_extralibs"
 
 # d3d11va requires linking directly to dxgi and d3d11 if not building for
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index c30449201d..f02960782d 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -49,6 +49,7 @@ OBJS-$(CONFIG_V4L2_INDEV)+= v4l2.o 
v4l2-common.o timefilter.o
 OBJS-$(CONFIG_V4L2_OUTDEV)   += v4l2enc.o v4l2-common.o
 OBJS-$(CONFIG_VFWCAP_INDEV)  += vfwcap.o
 OBJS-$(CONFIG_XCBGRAB_INDEV) += xcbgrab.o
+OBJS-$(CONFIG_PIPEWIREGRAB_INDEV)+= pipewiregrab.o
 OBJS-$(CONFIG_XV_OUTDEV) += xv.o
 
 # external libraries
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 8a90fcb5d7..1fa8563df4 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -53,6 +53,7 @@ extern const AVInputFormat  ff_v4l2_demuxer;
 extern const FFOutputFormat ff_v4l2_muxer;
 extern const AVInputFormat  ff_vfwcap_demuxer;
 extern const AVInputFormat  ff_xcbgrab_demuxer;
+extern const AVInputFormat  ff_pipewiregrab_demuxer;
 extern const FFOutputFormat ff_xv_muxer;
 
 /* e

[FFmpeg-devel] [RFC PATCH 2/2] configure: disable locale use in spa plugin

2023-09-20 Thread Abhishek Ojha
This commit requires to resolve the compilation error of pipewiregrab
because Pipewire's spa plugin is requesting locale_t extension to
compile.
Which was added in POSIX 2008 but ffmpeg is using POSIX 2001 due to
which spa plugin complains. __LOCALE_C_ONLY flag is set to disable
the locale usage in spa plugin. Adding it in configure file fix both
the library test and source compilation issue.
Not sure if this is the right approach to fix the issue.
Feedback/Suggestions will be highly appreciated.

Signed-off-by: Abhishek Ojha 
---
 configure | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configure b/configure
index 325b10484f..e14a8e5bcb 100755
--- a/configure
+++ b/configure
@@ -7045,6 +7045,8 @@ if enabled libxcb; then
 enabled libxcb_xfixes && check_pkg_config libxcb_xfixes xcb-xfixes 
xcb/xfixes.h xcb_xfixes_get_cursor_image
 fi
 
+# _POSIX_C_SOURCE=200112 doesn't support locale
+add_cppflags -D__LOCALE_C_ONLY
 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
-- 
2.34.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".