Commit graph

45 commits

Author SHA1 Message Date
Vaxry
3c850a0336
Window sharing (#2)
* added window sharing support

* nix: add hyprland-protocols and streamline build

Co-authored-by: Mihai Fufezan <fufexan@protonmail.com>
2022-12-04 21:12:57 +00:00
vaxerski
2dc95fe02f Allow region sharing 2022-12-03 22:42:21 +00:00
columbarius
b5491df0c0 screencast: destroy session if output is removed
We teardown all existing screencast_instances using the removed output
by destroying the frame, removing all timers and then marking the
instance as ready for teardown so we can destroy it after the last connected
session is closed.

Any wlr_screencopy_frame_v1 has to be destroyed before the connected
output can be removed. Otherwise wlr_screencopy_frame_v1_destroy
segfaults the whole program. To ensure this we will make all frame
callbacks safe to be triggered for a previous destroyed frame.
2022-05-31 01:23:34 +02:00
columbarius
ab0a07142d screencast: use wl_array for format-modifier-pairs
wl_array is a better fit than wl_list. It's less intensive on memory and
fits nicely with the flow of dmabuf_feedback announcing all format
modifier pairs at once and reseting them on change.
2022-05-31 01:22:48 +02:00
columbarius
2219db7508 screencast: use dmabuf_feedback
The compositor can announce it's default rendering device via
linux_dmabuf_feedback as the main_device [1]. We should use this device
whenever possible. If aquiring this device fails we are adviced to use
force linear layout on buffers allocated with the implicit api.

With linux_dmabuf_v1 the modifier event is deprecated. Instead the
format_table event in combination with the tranches of
linux_dmabuf_feedback_v1 has to be used.

[1] https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/unstable/linux-dmabuf/feedback.rst
2022-05-26 09:00:40 +02:00
columbarius
18efde6dde screencast: add function to query supported modifiers for a format
This function follows the structure of the equivalent function in egl
operating on basis of the announced format modifier pairs by wlroots.
2022-04-24 21:46:39 +02:00
columbarius
2ca2b7b603 screencast: get supported format modifier pairs from wlroots
Registering a zwp_linux_dmabuf_v1_listener gives access to the supported
format modifier pairs of the compositor.

This handler emits events for each format modifier pair. Those are stored
and will later be used to announce capabilities via PipeWire.
2022-04-24 21:46:39 +02:00
columbarius
b9c4472c50 screencast: stop assuming that allocation with implicit modifier works
It has shown that the assumption: "Allocation with implicit modifier will
always be available" doesn't hold true in all cases. Thus if allocation
of any dmabuf fails we mark the session to avoid dmabufs, thus falling
back to shm transport.
2022-04-24 21:46:39 +02:00
columbarius
1a7276068b screencast: support multiplane buffers with xdpw_buffer 2022-04-24 21:46:39 +02:00
columbarius
2f32d17448 screencast: remove swap_buffer function
Dequeuing a new buffer imidiately creates a problem when the buffer is
destroid while renegotiation of a valid modifier because we can end up using
a buffer which was freed while waiting for the buffer_done event. Then
xdpw will segfault when requesting a copy with a nonexisting buffer. To fix
this we can just dequeue a buffer right before we need it. This makes
the fallback via on_process obsolete since we dequeue the buffer at the
lates possible time.
2022-04-24 21:46:39 +02:00
columbarius
d89631c792 screencast: allocate dmabuf with implicit modifier
This is using the older gbm api without support for explicit modifiers.
This is required to support AMD gpus using the GFX8 or older
architecture and older intel gpus.
2022-04-10 13:38:01 +02:00
columbarius
b2c5a94e8c screencast: add linux_dmabuf to registry 2022-04-10 13:38:01 +02:00
columbarius
9d620273e5 screencast: create gbm device
This is done by using the first device returned by getDRMDevices2
containing a render node (DRM_NODE_RENDER).
2022-04-10 13:38:01 +02:00
columbarius
12de0cd144 screencast: introduce buffer_type
We want to support WL_SHM and DMABUFS based buffers. The buffer_type
member tracks the type of a xdpw_buffer and screencopy_frame_info of the
screencast_instance will be an array with an element for each buffer type
indexed by the value of the buffer_type enum. Only members of the
xdpw_screencopy_frame_info relevant to the buffer type should be used.
2022-04-10 13:38:01 +02:00
columbarius
3a57c24437 screencast: use drm format instead of wl_shm
drm format defined by drm_fourcc.h is the standard to describe the
format of a buffer. This will be used when dealing with dmabufs and to
simplify things we should drm_formats for all internal structs.
2022-04-10 13:38:01 +02:00
columbarius
ce9d77c90c screencast: relax buffer flip
In case a client doesn't return a buffer early enough we can give it a
second chance by triggering on_process before we pass the buffer to
wlroots in the frame_buffer_done event.
2022-04-04 15:37:53 +02:00
columbarius
074e62d0c3 screencast: restructure the screencopy flow
The previous implemented way to use wlr_screencopy events to cicle the
screencast had issues, like halting the stream if it was paused and
resumed before PipeWire triggered a recreation of buffers. This came
from not returning a dequeued buffer. This is now mititgated by
enqueuing the current pw_buffer imidiately on a paused event and trying
to dequeue a buffer just before requesting a screencopy if none is
present.
2022-04-04 15:37:53 +02:00
columbarius
058bd97815 screencast: introduce xdpw_buffer
It showed that handling self contained buffers is much easier then have
the metadata of the buffer seperated from the actual buffer attached to
the screencast instance.

The goal of the following changes is to separate the meta informations
like requested buffer attributes and wlr_screencast data from the actual
buffers.

This enables us to:
* Simplify the flow between the PipeWire loop and the wlroots one
* Track and apply damage to each used buffer (ext_screencopy)
2022-04-04 15:37:53 +02:00
columbarius
e28f5e06e6 screencast: rename screencopy_frame to screencopy_frame_info 2022-04-04 15:37:53 +02:00
columbarius
10a07f7e90 screencast: don't use the PipeWire event to trigger screencast
Using the on_process event of the PipeWire can create a race condition
when a previous started screencast hasn't finished before the next
event.
2022-04-04 15:37:53 +02:00
columbarius
66db43ea0e screencast: introduce xdpw_frame_state and xdpw_wlr_stream_finish
The enum xdpw_frame_state is used to track the state of the xdpw_frame through
the screencopy callbacks. xdpw_wlr_stream_finish is used as the new
endpoint of the screencopy callbacks. Here we clean up the
screencopy_frame, enqueue the pipewire buffer and restart the screencopy
loop if needed.
2021-11-06 16:51:36 +01:00
columbarius
1534a6a17e screencast: only end the fps measurement when it was started before
Sometimes it can happen that the first frame of the active stream
triggers the renegotiation and destroy the frame without copy and with
that starting the fps_limit counter. This triggers an assert in
fps_limit_measure_end. To avoid it, we only engage the fps_limiter after
a frame was copied successfully.
2021-11-06 16:51:36 +01:00
columbarius
27d1e42ec0 screencast: cleanup screencopy_frame
Move duplicated information to xdpw_frame and remove them from
xdpw_screencopy_frame.
2021-11-06 16:51:36 +01:00
columbarius
f77b751649 screencast: rename xdpw_frame into xdpw_screencopy_frame 2021-11-06 16:51:36 +01:00
columbarius
566fb7c1a0 screencast: pipewire add import_wl_shm_buffer function
This function lets us create a wl_buffer from any shared memory
filedescriptor.
2021-11-06 16:51:36 +01:00
columbarius
9bf7367320 screencast: remove pipewire on_event callback
Since we are driving the screencast there are no events on the pipewire loop
calling the on_event callback. We want to import and export (if possible) on
every frame of the wlroots loop, so this event is no longer needed.
2021-11-06 16:51:36 +01:00
columbarius
4b03a5acfd screencast: pipewire add functions to dequeue and enqueue a buffer 2021-11-06 16:51:36 +01:00
columbarius
6cc3a01741 screencast: pipewire change to self allocation of shm buffers 2021-07-02 12:12:17 +02:00
columbarius
96d2789d8f screencast: don't rely on the structure of xdpw_screencast_instance to convert formats 2021-06-29 15:08:02 +02:00
columbarius
bb24b226e4 screencast: respect the maximal framerate negotiated by pipewire 2021-06-23 09:32:08 +02:00
columbarius
976fa8374d screencast: limit screencast framerate by output framerate 2021-06-23 09:32:08 +02:00
columbarius
9d78b21695 screencast: add outputchooser with config option
Supports "dmenu" chooser type, which is called with a dmenu type list
piped to stdin, "simple" type, which recieves nothing on stdin and
default, which tries the hardcoded choosers.
Choosers are required to return the name of the choosen output as given
by the xdg-output protocol.

Thanks to piater for closing overlooked pipes.
Thanks to ericonr for suggestions regarding fork and pipes.
2021-04-02 15:07:38 +02:00
Zsolt Donca
ab8ff54f4c Control how many frames are captured per second
The goal is to control the rate of capture while in screencast, as it
can represent a performance issue and can cause input lag and the
feeling of having a laggy mouse.

This commit addresses the issue reported in #66.

The code measures the time elapsed to make a single screen capture, and
calculates how much to wait for the next capture to achieve the targeted
frame rate. To delay the capturing of the next frame, the code
introduces timers into the event loop based on the event loop in
https://github.com/emersion/mako

Added a command-line argument and an entry in the config file as well
for the max FPS. The default value is 0, meaning no rate control.

Added code to measure the average FPS every 5 seconds and print it with
DEBUG level.
2021-03-08 16:59:17 +01:00
columbarius
07154bb1e3
Add support for config file
Closes: https://github.com/emersion/xdg-desktop-portal-wlr/issues/60
2021-03-03 10:29:56 +01:00
Simon Ser
a7ea407e2f Remove --pixelformat flag
This hack is not needed anymore.
2020-05-05 10:00:10 -04:00
Simon Ser
26b6bf69aa Advertise format with alpha channel stripped 2020-05-05 10:00:10 -04:00
danshick
55f873dac4
Screencast session support (#22)
* Initial session support WIP
Remove libdrm dependency

Remove display from context, add dbus properties

Use random names for shm and pw_stream, init the stream only for new cast instances

Separate cast initialized flag from refcount, cleanup names and comments

* Refactor and stability improvements

Properly report xdp screencast implementation version
2020-04-16 10:21:55 +02:00
Dan Shick
ccc8a31568 Remove pipewire workarounds after upstream fix 2020-04-01 13:38:38 -04:00
Dan Shick
bba347be4c Add pipewire 0.3 support. Workaround pipewire bugs. 2020-03-16 22:43:45 +01:00
Dan Shick
45699637d1 Fix CI with libpipewire02, libdrm. Remove png.h unused import. Cleanup style. 2020-03-13 21:01:32 +01:00
Dan Shick
eb229b708e Remove thread for pipewire and all locking. Add support for elogind in meson. 2020-03-13 21:01:32 +01:00
Dan Shick
b0c50ff911 Add proper logging 2020-03-13 21:01:32 +01:00
Dan Shick
080d519a0d Add xdg_output protocol for output selection 2020-03-13 21:01:32 +01:00
Dan Shick
7b699f3344 Use variable framerate, add CLI option to override pixelformat metadata 2020-03-13 21:01:32 +01:00
Dan Shick
2a31d2d922 Add thread for wlr screensharing 2020-03-13 21:01:32 +01:00