Commit graph

409 commits

Author SHA1 Message Date
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
3591fd2a6c meson: bump version and replace deprecated functions 2022-05-06 21:51:58 +02:00
columbarius
4516d8b79e protocols: Use protocols from the wayland-protocols dependency
We can generate protocol code for wayland-protocols directly from the
dependency instead of shipping our own copy.
2022-05-06 21:51:58 +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
Guido Günther
371138e4c7 Add phosh to portal's UseIn list
The compositor is phoc but XDG_CURRENT_DESKTOP has "Phosh".
2022-04-30 22:12:25 +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
e1e0f5e143 protocols: add wayland protocol linux-dmabuf-unstable-v1 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
7c7cb88d8f builds: add gbm and libdrm to the build environment 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
699e6ecf77 build: define _GNU_SOURCE for PipeWire 0.3.49
PipeWire 0.3.49 added locale aware string functions to the spa library,
which are only available defining _GNU_SOURCE [1]. This will be fixed in
the next PipeWire release [2]

[1] 5f4d031db0
[2] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1206/
2022-04-04 13:08:47 +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
Birger Schacht
3febd04acd Fix typo 2021-12-23 18:25:44 +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
3ee4c5cca2 screencast: bump the prefered amount of pipewire buffers to 4
This tells pipewire, we prefere to use 4 pw_buffers in the pipe. This
should remove most "out of buffer" occourences.
2021-11-06 16:51:36 +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
7b3a17bae0 meson: bump required pipewire version to 0.3.34 2021-11-06 16:51:36 +01:00
columbarius
5eed00bb66 screencast: use asserts for fatal errors 2021-11-06 16:51:36 +01:00