Commit Graph

379 Commits

Author SHA1 Message Date
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
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
Simon Ser 7c0f352560 build: bump version to 0.5.0 2021-11-05 16:25:28 +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