Commit graph

56 commits

Author SHA1 Message Date
columbarius 155fb8ad8f linux-pipewire: Support colour format GS_R10G10B10A2
PipeWire supports 10bit colour formats with little endian order.

Adding two new formats required increasing the buffer size for building
PipeWire buffers.

This formats are supported since PipeWire 0.3.41. To allow building
against
older PipeWire versions we will hide those formats. Complications when
running on a host with an older PipeWire version are not expected, since
format negotiation is only done via the numerical values.
2023-05-17 16:35:43 -03:00
Jim 8dbc4761a3 linux-pipewire: Reduce debug message verbosity 2023-05-02 01:50:13 -07:00
Translation Updater a0fbdc3c34 Update translations from Crowdin 2023-05-01 23:11:13 +00:00
Kurt Kartaltepe f0f704249f linux-pipewire: Only consider chunks with size set
Compositors did not agree on how to communicate invalid buffers until
recently, so e0a4d8628d resulted in
regressions on KDE. This restores our old behavior which is too
conservative but mostly works on old and new compositors (which contain
similar workarounds to pass in invalid but non-zero sizes for dma-bufs).

Once all old compositors are out of use we can remove this workaround
and then compositors can remove their random size workaround.
2023-04-22 16:45:50 -07:00
Asahi Lina 584de6b264 linux-pipewire: Use premultiplied alpha
Pipewire desktop portal capture assumes premultiplied alpha, so make
sure to use the right blend equation to make translucent pixels work
correctly.

This is still broken for emissive pixels (alpha < color) since OBS seems
to unpremultiply at some point during blending, but it works properly
for translucent pixels (emissive pixel support requires an end-to-end
premultiplied pipeline).
2023-04-01 16:11:19 -07:00
Translation Updater 7c5560bf1b Update translations from Crowdin 2023-03-27 13:39:03 +00:00
PatTheMav 349372b3b3 cmake: Add changes for CMake build framework 3.0
New code path only taken if OBS_CMAKE_VERSION is set to 3.0.0 or
greater, old functionality remains unchanged.
2023-03-26 18:20:38 -04:00
tytan652 4d5cf98de0 linux-pipewire: Add missing struct typedef for older PipeWire
This allows building against PipeWire versions lower than 0.3.62.

The missing structure is copied verbatim from:
https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1423
2023-03-25 22:02:29 -04:00
Kurt Kartaltepe 9bde0afc74 linux-pipewire: Report modifiers in hex
Use hex for modifiers because they are generally formed from a high byte
and low bytes. This makes it easier to see these bytes and identify
unusual modifiers.
2023-03-17 10:48:51 -03:00
Robert Mader 0a36dc9d80 linux-pipewire: Clear cursor texture on empty bitmap
If we receive an empty cursor bitmap - one without valid size - we
should hide the cursor. Do so by clearing the texture.

This fixes visible cursors when recording various games with Wayland
compositors.

Closes https://github.com/obsproject/obs-studio/issues/4895
2023-03-14 10:52:17 -03:00
Georges Basile Stavracas Neto f62f370edd linux-pipewire: Remove unnecessary variable
No functional changes. The code is just ever so slightly easier to
read now.
2023-03-01 20:47:49 -03:00
Georges Basile Stavracas Neto 436787c1f4 linux-pipewire: Check for effective crop region
Some compositors send buffer crop information even when the crop
matches the buffer size. It doesn't really matter in practice,
but it's good hygiene to check for the effective crop instead of
simply checking if crop exists.
2023-03-01 20:47:49 -03:00
Georges Basile Stavracas Neto d68b061d57 linux-pipewire: Adjust cosmetics
Move code into auxiliary functions, to improve the legibility of the
draw function. It also gets rid of these pesky switch fallthroughs.
No functional changes.
2023-03-01 20:47:49 -03:00
Georges Basile Stavracas Neto 925888b763 linux-pipewire: Fix wrong error message
In the non-DMA path, we are logging an error message saying that
the DMA format is wrong. That's not the DMA format, it's the raw
buffer format.

Fix the message.
2023-03-01 20:47:49 -03:00
Georges Basile Stavracas Neto f520b251fb linux-pipewire: Demote yet another error to debug
This was an oversight from commit be629b93c.
2023-03-01 20:47:49 -03:00
columbarius 8abc3528cf linux-pipewire: Read buffer transformation from PipeWire
PipeWire allows since 0.3.62 [1] to attach metadata to a buffer
describing a transformation of the buffercontent. Clients should then
undo that transformation to import it correctly.

We can enable this feature using macro guards and runtime server version
checks on supported systems.

[1] https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/1423
2023-02-25 11:49:51 -03:00
Jan Beich e98c9fbd65 linux-pipewire: Drop unused Linux-only header
<dma-buf.h> provides DMA_BUF_IOCTL_* which were never used by OBS.
2023-02-15 14:44:36 -05:00
Georges Basile Stavracas Neto be629b93ce linux-pipewire: Demote error to debug message
Receiving buffers flagged as corrupted, or empty, is a casualty of
how things are implemented in various compositors, and it's not
a critical situation to be afraid of. We can expect a few buffers
to be flagged as corrupted here and there, and that's fine.

Demote these warnings to debug messages, as they're still useful
for debugging.
2023-02-14 18:50:57 -03:00
Georges Basile Stavracas Neto fad7420198 linux-pipewire: Trivially shuffle some code around
A trivial cosmetic change. This groups the constructor and
destructor together. Two sides of the same coin, yin and yang,
bound by their nature, and linked by their position in code.
2023-02-13 12:28:09 -03:00
Georges Basile Stavracas Neto f8a7b13cd3 linux-pipewire: Rename obs_pipewire_data to obs_pipewire
Next commits will introduce new obs_pipewire_* types, so this
renaming will make it slightly easier to read the code with
different types.
2023-02-13 12:28:09 -03:00
Georges Basile Stavracas Neto b7daa89f85 linux-pipewire: Split initialization of core and streams
This commit introduces an important distinction in the initialization
process that is essential to future camera and audio work: it splits
creating and connecting to the PipeWire socket, from connecting to
specific PipeWire nodes.

Right now, for the only consumer in existence - the ScreenCast portal
code - this distinction is irrelevant, but from an API perspective it
just makes sense to model it this way.
2023-02-13 12:28:09 -03:00
Georges Basile Stavracas Neto 5065e86bb9 linux-pipewire: Remove unnecessary struct field
We don't actually need to restore the node id anymore, since this
is handled by the screencast-portal.c code now.

Remove the pipewire_node field, and just create the stream directly
from the passed file descriptor now.
2023-02-13 12:28:09 -03:00
Georges Basile Stavracas Neto 890ca94b0b linux-pipewire: Inline play_pipewire_stream()
This separation of obs_pipewire_create() and play_pipewire_stream()
was an artifact of how the original code was written, and there is
no reason to keep this separation anymore. Inlining it will help
future commits too.
2023-02-13 12:28:09 -03:00
columbarius 86be35ae99 linux-pipewire: Move stream properties to constructors
And let each portal pass the stream properties relevant to them.
This makes the pipewire.c more independent of the actual portal
by providing a wrapper to create a stream. This will be relevant
later, when linux-pipewire introduces more portals like the Camera
one.
2023-02-13 12:28:09 -03:00
Georges Basile Stavracas Neto 874c30cb88 linux-pipewire: Cleanup D-Bus proxy on unload
When the linux-pipewire plugin is unloaded, make sure to cleanup
the D-Bus proxy for the ScreenCast portal too. This effectively
doesn't change anything, but it's always good to keep up with the
code hygiene.
2023-02-13 12:28:09 -03:00
Georges Basile Stavracas Neto b8cfe1aab1 linux-pipewire: Return actual type in obs_pipewire_create
Instead of returning an opaque void* pointer, return the leaf
C type obs_pipewire_data*.

This commit introduces no functional changes.
2023-02-13 12:28:09 -03:00
columbarius e0a4d8628d linux-pipewire: Reject invalid buffers
PipeWire supports two flags to signal an invalid buffer:
SPA_META_HEADER_FLAG_CORRUPTED signals that the whole buffer is invalid
and should not be used
SPA_CHUNK_FLAG_CORRUPTED signals that one single buffer plane is invalid

Skipping a buffer because of size 0 was moved to only the SHM case.
For DMA-BUFs the size of a single plane is not relevant and should be
ignored [1].

Compatibility note:
GNOME pre 43 sets the chunk size to 0 when a buffer copy failed.
Luckily GNOME doesn't use the META_Header and thus we can detect if we
should use the new or old style of invalid buffer detection.
This workaround should be dropped when reasonable.

[1] https://docs.pipewire.org/page_dma_buf.html
2023-01-26 21:40:05 -03:00
Translation Updater 783bd52197 Update translations from Crowdin 2023-01-08 04:10:37 +00:00
columbarius d8b7906954 linux-pipewire: Check format availablity against DRM only for dmabufs
Whe using a software renderer there will be no formats available for
using with dmabufs. We should only consider those formats wrt. to
modifiers and as such move this check after adding general support for
that format.

fixes #7985
2023-01-07 15:42:34 -08:00
Aleix Pol 6fb83abaeb linux-pipewire: Close sessions as we are done with them
This way the stream can be cleaned up. Otherwise, we closed them all
when OBS closes which works but is not entirely correct.
2022-09-27 11:50:49 -03:00
Translation Updater cc2d0791ca Update translations from Crowdin 2022-08-30 09:00:44 +00:00
columbarius 76e9c64f41 Revert "linux-capture: Fix Ubuntu 21.10 builds"
This reverts commit 0532a5c1f0.

Ubuntu 21.10 is from OBS 28 onwards not longer supported and as such we
can raise the requirement of the PipeWire dependency to 0.3.33.
2022-08-06 09:28:58 -03:00
Translation Updater 81734be37c Update translations from Crowdin 2022-07-31 23:40:53 +00:00
Norihiro Kamae 7e3656ab33 plugins: Cleanup unused-parameters
- Remove unnecessary UNUSED_PARAMETER
- Add OBS_UNUSED attribute to unused parameters
- Also removes unused variables
2022-07-19 11:01:00 -04:00
columbarius e14f6280c2 linux-pipewire: Log modifier
The used modifier is important to debug subtle issues when the imported
buffer appears to be currupt.
2022-06-27 13:56:16 -03:00
Georges Basile Stavracas Neto f740033c93 linux-pipewire: Shuffle screencast D-Bus proxy around
Move the screencast D-Bus proxy, and related functions, to where
they fit in now: screencast-portal.c.
2022-06-24 10:29:10 -03:00
Georges Basile Stavracas Neto 6f1521e944 linux-pipewire: Cleanup includes
We can remove and shuffle some includes now.
2022-06-24 10:28:47 -03:00
Georges Basile Stavracas Neto 0e9c208fc5 linux-pipewire: Move all portal code to screencast-portal.c
Sorry this is such a massive commit. The entangled nature of the
code in pipewire.c makes it impossible to reasonably split this
in smaller commits.

Move all D-Bus / portals code from pipewire.c into the recently
introduced screencast-portal.c.
2022-06-24 10:28:45 -03:00
Georges Basile Stavracas Neto 45afcf1997 linux-pipewire: Introduce proxy struct for screencast portal
Right now it's completely useless, but this commit lays out the
foundational steps to populate this struct.
2022-06-24 10:27:56 -03:00
Georges Basile Stavracas Neto 5ffc8ef663 linux-pipewire: Shuffle some code around
This is the start of what will be a rather incisive surgery on
pipewire.c. Move a couple of functions to portal.c, since they're
not really related to the PipeWire code.
2022-06-24 10:26:51 -03:00
Georges Basile Stavracas Neto 8a46b9e455 linux-pipewire: Rename pipewire-capture to screencast-portal
As we slowly split portal code from PipeWire code, what is currently
called pipewire-capture will become the screencast portal specific
code.

Preemptively rename the corresponding files and functions. Next commits
will continue the excision of portal code from pipewire.c.
2022-06-24 10:26:33 -03:00
Georges Basile Stavracas Neto 042c6c078c linux-pipewire: Always load PipeWire captures
After the removal of GLX, we effectively always load the PipeWire
captures. Remove the switch statement.
2022-06-22 11:44:16 -03:00
Georges Basile Stavracas Neto d00d1e2926 linux-pipewire: Remove unused variable
A fallout from a147315f33
2022-06-22 11:37:01 -03:00
tytan652 a9cb952628 linux-pipewire: Restore PipeWire minimim version requirement
a147315f33 removed it without adding it to linux-pipewire.
2022-06-15 13:50:33 -03:00
Georges Basile Stavracas Neto ca2d02c2ce Drop GLX renderer
"They must often change, who would be constant in happiness or wisdom"

 - Confucius
2022-05-24 14:31:48 -03:00
Georges Basile Stavracas Neto 3d7663f417 linux-pipewire: Explicitly enumerate portal capture types
This is very much like previous commit, but there's a catch: there
already was an enumeration in place, which is replaced in this
commit. The obs_pw_capture_type enum was introduced before splitting
the portal code into a separate file, and the enum itself is specific
to the screencast portal, so the appropriate place to enumerate it
is in portal.h.

For completude, PORTAL_CAPTURE_TYPE_VIRTUAL was added to the enum,
even though we never used, and probably never will.

The values are still the same, since both the old and this new enum
were extracted from the screencast portal [1].

https://github.com/flatpak/xdg-desktop-portal/blob/main/data/org.freedesktop.portal.ScreenCast.xml#L290-300
2022-04-09 16:45:02 -07:00
Georges Basile Stavracas Neto e7815dff66 linux-pipewire: Explicitly enumerate cursor modes
The ScreenCast portal defines 3 cursor modes [1]:

 * Hidden: no visible cursor (value: 1)
 * Embedded: cursor is drawn in the frames (value: 2)
 * Metadata: cursor is sent as stream metadata (value: 4)

The values are power-of-two due to be used as flags.

Explicitly listing these values in an enum improves legibility
of the code, so do that instead of hardcoding 1, 2, and 4.

[1] https://github.com/flatpak/xdg-desktop-portal/blob/main/data/org.freedesktop.portal.ScreenCast.xml#L302-L316
2022-04-09 16:45:02 -07:00
Georges Basile Stavracas Neto 1267081e5c linux-pipewire: Move fetching cursor mode to portal.c
The portal.c file was introduced after the PipeWire code landed, and
handles acquiring a D-Bus connection to the portal interface, and also
has helpers to get properties from portals. The available cursor modes
property fits nicely in portal.c.

Move fetching the cursor mode to portal.c.
2022-04-09 16:45:02 -07:00
Georges Basile Stavracas Neto 2534e549f9 linux-pipewire: Remove ellipses from log messages
Ellipses in log messages bring a tone of vagueness and insecurity
that does not match the geist of the OBS Studio community. We're
a bold, industry-leading community producing software that is at
the heart of the biggest services of today's world. When it comes
to PipeWire and Wayland adoption, we're quite literally the app
that protocols and portals are designed for.

Therefore, it is unacceptable that the log messages in the PipeWire
capture don't communicate how strong of a community we are. Not
only that, these ellipses bring harm on the long run. After all,
who on their right mind would design protocols, portals, and user
interactions for an app that doesn't even log their messages in
accordance to its community values?

Our logs must shout strength. They must reflect that OBS Studio
is here to stay. Readers of such logs must fasten their seatbelts
before opening these files. Competition tremble with dread and
fear when presented with these logs. Only extreme metal singers
should be able to read these logs out loud.

No compromise.

Remove ellipses from PipeWire log messages.
2022-04-09 16:45:02 -07:00
Georges Basile Stavracas Neto 25fe22a489 linux-pipewire: Properly capitalize log messages
They are inconsistently capitalized, some with sentence capitalization,
some completely lower-cased.

Capitalize all log messages using sentence capitalization.
2022-04-09 16:45:02 -07:00