Commit Graph

226 Commits

Author SHA1 Message Date
vaxerski 74128d2a97 minor fix for region sharing 2023-03-16 15:11:27 +00:00
vaxerski 8707444cf5 fix shell tab behavior in headers 2023-02-03 18:41:28 +00:00
vaxerski a0fa7909cd nuke toplevel_mgr_bind 2023-02-03 16:50:06 +00:00
vaxerski f8cdd28cc8 sanitize input to the picker 2023-02-03 12:14:28 +00:00
vaxerski 13db7db849 fix returnlist on no manager 2023-02-01 19:48:49 +00:00
vaxerski ee73fca9cc Bind toplevel protos once before first screencast
Also style.
2023-02-01 17:49:29 +00:00
vaxerski 101b58d9c5 add missing s 2022-12-13 18:55:32 +00:00
vaxerski 9fb4fae94b bring back qt wayland platform 2022-12-13 00:55:12 +00:00
Vaxry 3c4c9969cc
Toplevel sharing Rev2 impl (#3)
* toplevel sharing rev2

* nix: fix build

* updated protocols

Co-authored-by: Mihai Fufezan <fufexan@protonmail.com>
2022-12-12 14:51:37 +00:00
vaxerski 756789211e export HIS to the picker 2022-12-05 23:20:49 +00:00
vaxerski 2a634b0a60 log more about screencast 2022-12-05 23:11:13 +00:00
vaxerski 4ac6a9af82 export xcursor size to avoid odd-sized cursors 2022-12-05 18:53:51 +00:00
vaxerski cea7c28bae force wayland platform for qt in invoking picker 2022-12-05 00:37:10 +00:00
vaxerski bd91bd0d4e pass env to popen cmd picker 2022-12-05 00:13:36 +00:00
vaxerski 8a4e83da96 prevent segfaults on no toplevel proto available 2022-12-04 23:18:10 +00:00
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
Leftas 607ce73671
Change from wlr to hyprland so dbus would recognize different implementation 2022-12-04 19:57:30 +02:00
vaxerski e2cfaf3eee minor nix fixes 2022-12-03 23:42:56 +00:00
vaxerski 37c76fd7d8 start at pos 7 to avoid a warn 2022-12-03 23:40:08 +00:00
vaxerski 2dc95fe02f Allow region sharing 2022-12-03 22:42:21 +00:00
vaxerski 80775707ea Implement hyprland-share-picker 2022-12-03 21:27:49 +00:00
columbarius c83b3cc514 screenshot: Announce version property 2022-09-12 23:33:54 +02:00
columbarius 723934d0b0 screencast: check if a valid format was received from wlr_screencopy
When a screencast is started we do a roundtrip on get the offered
formats from wlr_screencopy. This roundtrip can fail [1]. In this case
the formats won't be initialized and we will just error out of the
screencast session.

[1] https://github.com/emersion/xdg-desktop-portal-wlr/issues/214
2022-06-09 11:19:54 +02:00
columbarius 0bbd652c1c screencast: send pesentation timestamp via PipeWire 2022-06-01 21:12:46 +02: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 2d54aeb36d screencast: fix handler logging for tranche_formats 2022-05-26 09:39:14 +02:00
columbarius e70a1efa43 screencast: skip duplicated format-modifier pairs 2022-05-26 09:00:40 +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 14852efb05 screencast: Remove MESA hack from the old gbm api fallback
Calling gbm_bo_create_with_modifiers2(...) and setting the modifiers
pointer to NULL for the same result as gmb_bo_create(...) is a MESA hack,
which I missed to remove from 84282e9b5f.
2022-05-05 18:13:02 +02:00
columbarius 29f86168b6 screencast: announce supported explicit modifiers
We query the supported modifiers via a wrapper and announce them via
PipeWire.

This wrapper queries the supported formats from wlroots and returns them
as a simple array. The purpose of this wrapper is to ease the use of the
query functions which are kept in the style of the equivalent egl
queries.
2022-04-24 21:46:39 +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 84282e9b5f screencast: fixate modifier from PipeWire format negotiation result
This implements the modifier fixation procedure. The producer of a
stream has to ensure that it can create a buffer with the negotiated
properties. To do that we will take the result of the intersection of
supported modifiers by PipeWire and select the "best" modifier from that
list.

To do this we do the following allocations and fixate on the
modifier of the created buffer should the allocation suceed.
* Try to allocate a buffer with explicit modifiers using the list
  provided by PipeWire
* Walk the list of modifiers and do single allocations for implicit and
  linear modifiers using the old api.

If none of the allocations above succeed we fall back to shm buffers.
This is implemented in the next commit.

If an allocation was successfull we fixate the modifier with
fixate_format().
This function creates an EnumFormat like build_format, but will only
announce support for a single modifier.
It is used to finish the negotiation process by announcing it together
with EnumFormats of our full supported formats.
2022-04-24 21:46:39 +02:00
columbarius a70a1195d4 screencast: check if pipewire returns a modifier list
Using SPA_POD_PROP_FLAG_DONT_FIXATE pipewire can return a list of
supported modifiers. In that case are we responsible to select one
modifier and fixate it.
2022-04-24 21:46:39 +02:00
columbarius 77bcd14ad2 screencast: support allocation of buffers with explicit modifiers 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 5799adeb57 screencast: enqueue pipewire when screencopy failed
Keeping a buffer when the copy failed has the risk of having this buffer
removed while we wait for the next buffer_done event. To prevent this we
just enqueue the buffer marking it as corrupt. A new buffer will be
dequeued at the buffer_done event.
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
Alias Gram 657b9edad5 chore(logging): change config file error to info 2022-04-18 18:44:47 +02:00
columbarius 6cec421f92 screencast: improve logging for pipewire events
We should log buffer add and remove events in the debug loglevel, since
they signal starts, stops and renegotiations of the buffer transfer.
Additionaly logging the negotiated pwr_format should help classify
issues from the DEBUG loglevel.
2022-04-10 13:38:01 +02:00
columbarius 852e1c95c7 screencast: HACK set an arbitrary chunk size for dmabufs
Clients have wrongly used the chunk size to detect if a buffer was valid
or not. Since dmabufs might not have a well defined buffer size we will
set an arbitrary value until clients are patched.
2022-04-10 13:38:01 +02:00
columbarius 0683f7ca7e screencast: add option to force implicit modifier to be linear
Linear buffer layouts are supported by most gpu vendors and as such
should be compatible in mixed mutli gpu setup where the implicit
modifier of one gpu is not supported by the other.

This option should make xdpw work in these environemnts.

The option is marked as experimental since it might be removed if
explicit modifiers provide a better solution.
2022-04-10 13:38:01 +02:00
columbarius 9085996111 screencast: announce implicit modifier via PipeWire 2022-04-10 13:38:01 +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 bae393a684 screencast: support modifiers in build_format
When announcing support for dmabufs via PipeWire this is done by adding
the SPA_FORMAT_VIDEO_modifier property to an EnumFormat. Producers can
choose between two different ways [1]:

* Supporting only implicit modifiers by adding the property as a sigle
  value together with the SPA_POD_PROP_FLAG_MANDATORY flag
* Support for multiple modifiers. This is done by announcing a
  SPA_CHOICE_ENUM array together with the use of the
  SPA_POD_PROP_FLAG_MANDATORY and SPA_POD_PROP_FLAG_DONT_FIXATE flag

[1] https://docs.pipewire.org/page_dma_buf.html
2022-04-10 13:38:01 +02:00
columbarius 6630525b7a screencast: implement wlr_frame_linux_dmabuf 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 88a8a9cb7e screencast: add build_buffer function
This function makes it easier to omit attributes like size or stride for
cases where they won't be well defined like muliplanar dmabufs
2022-04-10 13:38:01 +02:00
columbarius 0835d8287b screencast: introduce build_formats
We build EnumFormats from our supported format multiple times. This
commit just creates a function to do that. This makes it easier to
handle the announcement of multiple buffer types.
2022-04-10 13:38:01 +02:00
columbarius ba0f40e45c screencast: disable instance sharing
PipeWire currently will not renegotiate the used format of a stream when
a new client connects. This causes clients to get stuck when they are
incompatible with the format negotiated for the existing stream.
This will be problematic when some clients support dmabuf transport
while others won't. Thus we disable it until a solution is found.
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 21d26fe23e session: destroy screencast_instance directly when paused
A PipeWire client might pause the stream which enables us to stop
requesting buffers from the compositor. In this case the the quit bool
won't be enacted on and thus we should destroy it directly from here.
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 c34d09877c screencast: fix check on loop_iterate
According to the documentation [1] pw_loop_iterate (a macro for
spa_loop_control_iterate) will return the number of dispatched fd's
and thus we should check only negative return values.

[1] https://docs.pipewire.org/group__spa__loop.html#ga3bae0b32100f5752b3372a505c8e04f6
2022-01-20 16:27:35 +01:00
columbarius 55d73ab647 screencast: fix missing return value assignement 2022-01-18 13:30:17 +01:00
Quantum d0c6b7f3a9 Implement xdpw_format_pw_strip_alpha for 10-bit colour
This was missed in the original PR adding support for 10-bit colour.
2021-12-28 09:37:58 +01:00
Quantum 74307ceabf Add support for 10-bit colour formats
This makes PipeWire 0.3.41 the minimum required version.
2021-12-20 10:09:16 +01:00
columbarius b2f1a10023 screencast: use the pipewire callback process to start screencast
We can trigger that with pw_stream_trigger_process when we are the
driver of the stream. Additionally this let's us run passivly with the
consumer driving the stream.
2021-11-06 16:51:36 +01:00
columbarius 5eed00bb66 screencast: use asserts for fatal errors 2021-11-06 16:51:36 +01:00
columbarius 8f05ade2a2 screencast: mark buffer as invalid when screencopy fails 2021-11-06 16:51:36 +01:00
columbarius cd30bd0f8e screencast: don't fail when copy_buffer was unsuccessfull
When a buffer is destroyed while used in the copy_buffer request the
screencopy protocoll will answer with the failed event. This can happen
anytime when PipeWire calls the remove_buffer callback, eg. on
renegotiation. This is not fatal, so we don't need to close the
screencast.

cast->err should only be used for fatal errors.
2021-11-06 16:51:36 +01:00
columbarius 35cba50409 screencast: drop imported PipeWire buffer on remove_buffer
PipeWire can request to destroy the allocated buffers anytime. This
isn't a problem for us, since the screencopy protocol can handle
disappearing buffers. The only thing we have to do is not to use a
destroyed buffer.
2021-11-06 16:51:36 +01: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 b986020050 screencast: reorder screencopy callbacks
They callbacks are now in the order they are used by screencopy.
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 4d892f2a43 screencast: use pipewire buffers directly for wlroots screencopy
Instead of using one wl_buffer to export buffers from wlroots and then
copy the content into the buffer dequed from pipewire, we can create a
wl_buffer for each pipewire buffer directly at allocation time and
attach it to the data attribute. Those wl_buffers can be directly handed
over to the wlroots screencopy protocol and so removing one copy.
2021-11-06 16:51:36 +01:00
columbarius 78efdff460 screencast: implement buffer property checks wrt. xdpw_frame and xdpw_screencopy_frame
Since we gather the information of the currently used buffer on
importing it, we can check if the imported and the announce buffer by
wlroots are compatible.

Also the comparison between the announced buffer properties and the
format used by the pipewire stream was moved to wlr_frame_buffer_done.
This lets us implement all checks in the same callback and makes it
easier to extend those checks for future dmabuf sharing.
2021-11-06 16:51:36 +01:00
columbarius fc85f6738b screencast: only restart wlroots loop if stream is active
This prevents the wlroots loop from running after the first roundtrip to
query the buffer informations from the screencopy protocol.
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 11de00735f screencast: use dequeue/enqueue functions instead of on_process event to interact with pipewire 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
Tobias Langendorf 9ef1d6aa2b Fix exec_before/after leaving a zombie process behind 2021-09-01 21:54:08 +02:00
columbarius 5f5a29ccfd screencast: fix pipewire default id_node
The default node_id is SPA_ID_INVALID.

We are casting pipewire uint32_t node_id to int for printing since they are
currently staying in the range of low integer numbers. This makes
spotting an uninitialized node_id (casted to -1) much easier. Should be
corrected if that becomes an issue in the future.
2021-08-10 13:10:10 +02:00
columbarius 6cc3a01741 screencast: pipewire change to self allocation of shm buffers 2021-07-02 12:12:17 +02:00
columbarius a33034acce screencast: pipewire remove uneeded PW_STREAM_FLAG_MAP_BUFFERS flag 2021-07-02 12:12:17 +02:00
columbarius 6a3832277f screencast: pipewire move buffer information from pwr_on_event to pwr_handle_stream_add_buffer 2021-07-02 12:12:17 +02:00
columbarius 03146fa1d7 screencast: pipewire add {add,remove}_buffer handler 2021-07-02 12:12:17 +02:00
columbarius 9653abc330 screencast: announce supported buffer type 2021-07-02 12:12:17 +02:00
columbarius ac5c248340 screencast: update pipewire params on buffer change 2021-07-02 09:45:46 +02:00
columbarius f2d08cc5b5 screencast: create pwr_update_stream_param
This will let us notify pipewire that our buffer has changed and trigger a renegotiation cycle which will take care of reallocating the buffers
2021-07-02 09:45:46 +02:00
columbarius 50cb55ed1d screencast: add logging to pwr_handle_stream_param_changed in pipewire_sreencast.c 2021-07-02 09:45:46 +02:00
columbarius ab8e3bea00 pipewire: stop announcing a range as the video size
We can only serve a video with a size as send from the compositor,
so no need to announce any range.
2021-07-02 08:58:13 +02:00
columbarius dee06d015d pipewire: add the striped format inside of build_format 2021-07-02 08:58:13 +02:00
columbarius 773186d2ed pipewire: move enumformat creation into seperate function 2021-07-02 08:58:13 +02:00
GermainZ 668509e317 Fix potential memory corruption when reading bools
As per `man sd_bus_message_read`, boolean items should be read into an
int rather than a bool as the latter can cause memory corruption.
2021-07-01 13:49:31 +02:00
Simon Ser e23e109e41 Handle POLLHUP
This makes xdpw exit when either the D-Bus daemon, the Wayland
compositor or Pipewire is shut down. This avoids having dangling
non-functional xdpw instances, e.g. when restarting the compositor.

To test, start Sway nested in Sway, run xdpw with
WAYLAND_DISPLAY=wayland-2, and exit the nested Sway.
2021-07-01 11:58:26 +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