Commit Graph

176 Commits (0a218e06b7601c0e561db518b1b5878557cd1ebc)

Author SHA1 Message Date
tytan652 8409f72f60 plugins: Replace OBS_UNUSED with UNUSED_PARAMETER
OBS_UNUSED is not portable to MSVC.
2022-07-20 08:22:08 +02: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
Kurt Kartaltepe c6cb0838fd linux-capture: Silence log spam on xcomposite capture
It is expected that capture might fail, like when a window is minimized.
In these cases we dont want the log to be spammed by X11 errors so
install a noop error handler while we try to import.
2022-07-10 11:24:40 +10:00
Kurt Kartaltepe e9076da901 linux-capture: Retry capture if texture not created
This prevented OBS from re-aquiring capture when windows were minimized
or fullscreened.
2022-07-10 11:24:40 +10:00
Georges Basile Stavracas Neto ddb692ab2d linux-capture: Drop GLX code paths
Default to EGL and remove the sad amount of hacks from xcomposite.
2022-05-24 14:30:14 -03:00
Kurt Kartaltepe fb639e303c linux-capture: Fix map-like behavior for watcher
The original PR missed assigning the `idx` variable in unregister. When
compiled without asserts this would silently not delete sources. Instead
correctly assign idx and skip unregistration if the source doesnt appear
registered.

fixes #6532
2022-05-24 08:16:10 -03:00
Kurt Kartaltepe 9b6d39299e linux-capture: Add EGL support for xcomposite
When running on EGL we can use the new create_texture_from_pixmap
functions to implement xcomposite capture.

This removes the texture indirection previously implemented for GLX due
to not using the spriting functionality in the built in shaders. Now
that we texture directly from the pixmap we can remove the red/blue swap
workarounds.
2022-05-15 09:08:53 -03:00
Kurt Kartaltepe 1604400e48 linux-capture: Rewrite xcomposite
Generally moves all the plugin code into xcomposite-input.cpp and
removes all C++ dependencies.

Migrate as much as possible to xcb from Xlib to enable us to handle
errors and attribute them to the correct callers. This caused many other
knock on issues such as wrongly attributed errors and cleanup code
working incorrectly.

That allows us to use the xcursor-xcb implementation and delete the pure
Xlib implementation. We also add the missing functionality from the Xlib
implementation to the xcb implementation.

Capture glXCreatePixmap errors which occur most commonly on
nvidia+gnome due to nvidia's driver being unable to allocate more than 1
pixmap per window and gnome being the only compositor to read window
data via glx pixmaps.

Fix cleanup after failed glXCreatePixmap that might have leaked pixmaps
and prevented later captures on nvidia drivers for the same reason.
2022-05-14 17:01:08 -03:00
PatTheMav aae3a6a466 cmake: Fix diverging prefix padding for OBS status outputs
Status output related to OBS configuration is prefixed with the string
"OBS" and added padding for enabled and disabled features. This padding
was not aligned between platforms.

By moving the padding and prefix decoration into its own function,
both elements are controlled in a single place. CMake scripts were
changed to use this new function `obs_status` instead of using CMake's
`message` function directly.
2022-03-26 09:44:23 -04:00
Georges Basile Stavracas Neto a147315f33 project: Migrate PipeWire capture into linux-pipewire
The capture ids are preserved, so that it's compatible with the
previous code. No code changes were necessary whatsoever.
2022-03-20 20:53:39 -03:00
PatTheMav 49e9d49943
plugins: Update CMakeLists.txt for included plugins 2022-03-16 23:11:08 +01:00
Florian Zwoch d16950a2f6 linux-capture: Fix for pipewire capture leaking texture handles
Enter the graphics context before calling gs_texture_destroy() or
else the call will fail causing the texture handles to leak.
2022-02-19 20:06:03 -03:00
Translation Updater ac8dbf67be Update translations from Crowdin 2022-02-06 02:24:08 +00:00
Cenk Uluisik f52f34b614 linux-capture: Fix missing parameter for pipewire capture
Commit a3a6710 introduced the obs_pipewire_save() function in the
PipeWire code, but only set it to the monitor capture source. This
was an oversight, it should have been set to the window capture
source as well.

Set the .save vfunc of the window capture source as well.

Closes obsproject/obs-studio#5906
2022-02-04 13:09:12 -03:00
Tatsuyuki Ishi b684e01aad linux-capture: Disable strict binding for NVIDIA drivers
NVIDIA drivers appears to have a bug where binding would be excessively
slow. Apply a workaround similar to what [KWin] does to prevent the issue.

Also performs a refactor so that the code paths with and without the
workaround can be shared.

[KWin]: 4f2c3a00c4/src/libkwineffects/kwinglplatform.cpp

Fixes: 316f858c6 ("linux-capture: Fix capturing on software rasterization setups")
Closes: https://github.com/obsproject/obs-studio/issues/5685

Tested-By: univrsal <uni@vrsal.xyz>
2022-01-07 15:21:09 -08:00
Georges Basile Stavracas Neto a200001d2a linux-capture: Standardize gs_color_format variable names
Name them all to 'gs_format'. We need to be a bit strict with
naming here, since we're dealing with 3 format namespaces (OBS,
PipeWire, and DRM).
2021-12-30 18:41:04 -03:00
Georges Basile Stavracas Neto 64bb5a0974 linux-capture: Unify format lookups
Merge all format lookup functions into a single one, with all
out parameters optional.
2021-12-30 18:41:04 -03:00
Georges Basile Stavracas Neto f0026142f0 linux-capture: Move supported formats into a static table
We've been listing the supported formats in place whenever we
needed so far, but now we're doing it in too many different
places, which is getting confusing.

Move all these sparsely written rules into one single table
of formats, and adjust the code to lookup data on it.
2021-12-30 18:41:04 -03:00
Georges Basile Stavracas Neto d876e735e0 linux-capture: Split array into two variables
Split the 'f' array in two named variables, and move one of
these variables to the appropriate context where its used.

No functional changes.
2021-12-30 18:41:04 -03:00
Georges Basile Stavracas Neto 52a3a8817d linux-capture: Add preferred value out of the loop
Choice pods are built with the first element being the
preferred choice, followed by a list of possible choices.

We add the preferred choice inside the loop, which makes
the code slightly harder to follow.

Factor this out of the loop, into a separate step.
2021-12-30 18:41:04 -03:00
Georges Basile Stavracas Neto 37ba341d3a linux-capture: Rename a variable
'modifierless' is a bit non-descriptive given the lack of a
verb in the variable name. Rename it to 'use_modifiers', and
swap the logic.
2021-12-30 18:41:04 -03:00
columbarius 0532a5c1f0 linux-capture: Fix Ubuntu 21.10 builds
Ubuntu 21.10 provides PipeWire 0.3.32 which is missing the
`SPA_POD_PROP_FLAG_DONT_FIXATE` required for proper DMA-BUF negotiation.
Since this isn't implemented in the DE's of this Ubuntu version just
defining this flag won't have any impact.

Revert after support for Ubuntu 21.10 ended.
2021-12-22 14:27:53 -03:00
columbarius 13693bd199 linux-capture: Add fallback for PipeWire < 0.3.40
Proper DMA-BUF format and modifier negotiation is possible with PipeWire
0.3.40. This commit adds checks for older versions and allows to build
against them.

These are classified as follows:
* PipeWire server older than 0.3.24: Restrict to SHM only
* PipeWire server between 0.3.24 (incl.) and 0.3.40: Announce modifiers
  along with the old method. On failed import drop all modifiers.
* PipeWire server 0.3.40 and newer: Announce modifiers along with the
  old method. On failed import drop only a single modifier.
2021-12-22 14:27:53 -03:00
columbarius abbec90e7e linux-pipewire: Handle DMA-BUF import failure
Importing a DMA-BUF can fail even if the renderer announces support for
the used format modifier pair. This can be caused by a number of reasons
specific to the underlying hardware and api [1]. In that case we want to
remove that modifier from our list of supported ones and renegotiate.

This feature was added in PipeWire 0.3.40. On previous versions the best
we can do is drop all modifiers an fallback to DMA-BUF with another
format or directly to the SHM buffer transport. This mechanism is
demonstrated in [2].

[1] https://xdc2020.x.org/event/9/contributions/615/attachments/704/1301/XDC_2020__Allocation_Constraints.pdf
[2] https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/src/examples/video-play-fixate.c
2021-12-22 14:27:53 -03:00
columbarius c31aba9600 linux-capture: Announce supported modifiers via PipeWire
Sharing DMA-BUFs via PipeWire requires the client to announce all
formats together with their supported modifiers. [1]

[1] https://docs.pipewire.org/page_dma_buf.html
2021-12-22 14:27:53 -03:00
columbarius b57f7f0aed linux-capture: Bump minimal PipeWire version to 0.3.33
We require PipeWire 0.3.33 or later to make use of the introduces flags
`SPA_POD_PROP_FLAG_MANDATORY`  and `SPA_POD_PROP_FLAG_DONT_FIXATE`,
which are required for the negotiation process introduced in the
following commits.
2021-12-22 14:27:53 -03:00
Georges Basile Stavracas Neto e41e845272 linux-pipewire: Use DRM fourcc defines directly
It was naive to add these defines here to avoid a direct include when
the entire platform already depends on the DRM subsystem. Just include
it and let it provide the image formats.
2021-12-22 14:27:53 -03:00
Translation Updater 261345f9ef Update translations from Crowdin 2021-12-12 02:38:59 +00:00
Tatsuyuki Ishi 316f858c68 linux-capture: Fix capturing on software rasterization setups
The GLX_EXT_texture_from_pixmap spec says:

The contents of the texture after the drawable has been bound are defined
as the result of all rendering that has completed before the call to
glXBindTexImageEXT.  In other words, the results of any operation which
has caused damage on the drawable prior to the glXBindTexImageEXT call
will be represented in the texture.

Rendering to the drawable while it is bound to a texture will leave the
contents of the texture in an undefined state.  However, no
synchronization between rendering and texturing is done by GLX.  It is
the application's responsibility to implement any synchronization
required.

In practice, on most systems with a GPU this kept a directly binding to
the framebuffer, which made it work with the previous code. However,
on software rasterization setups using llvmpipe, a blit was done inside
the call to glXBindTexImageEXT. This was the cause of a notoriously
ignored bug where the captured image would "freeze" until the source
was reconfigured.
2021-12-12 11:13:24 +11:00
Kurt Kartaltepe 26f4d85398 linux-capture: Deinit pipewire only if we init'ed
If you don't have a xdg-desktop-portal backend then pipewire wont init,
however on exit we unconditionally deinit which can crash in pipewire
which does not handle this gracefully.
2021-12-12 10:05:02 +11:00
columbarius c1b87e70ef linux-capture: Fallback on older PipeWire versions to SHM
PipeWire server versions older than 0.3.24 can be incompatible with
clients build against a newer library version with respect to DMA-BUF
sharing. So we want to fallback to SHM transfer. This commit adds
checks for older versions.

These are classified as follows:
* PipeWire components older than 0.3.24: Restrict to SHM only
* PipeWire components with version 0.3.24 and newer: Announce DMA-BUF
  support via `SPA_PARAM_BUFFERS_dataType`
2021-11-28 19:43:24 -03:00
columbarius 9f7de79004 linux-capture: Query used PipeWire versions
This enables us in the following commit to announce different
capabilities wrt. those versions.
2021-11-28 19:43:24 -03:00
Georges Basile Stavracas Neto 26f1bfd05f linux-capture: Implement stream restoration
With the version 4 of the screencast portal, it is now possible
to request and use restore tokens [1] so that apps can restore a
previously configured screencast session without user interaction.

Add the corresponding code to linux-capture's PipeWire source.
Store the restore token in the source data, since each restore
token corresponds to an OBS source, and use it as soon as we try
to create a new session. Implement the obs_source_info.save vfunc,
and save the restore token when it's received by the Start()
response using obs_source_save().

[1] https://github.com/flatpak/xdg-desktop-portal/pull/638
2021-11-24 11:42:06 -08:00
Georges Basile Stavracas Neto 8537c7593c linux-capture: Add getter to screencast portal version
This will be used by the next commit to verify whether or not
to pass the restore token and persist mode options.
2021-11-24 11:42:06 -08:00
Rafael Franco c7de398309 linux-capture: Sort windows by name 2021-11-02 06:06:46 -07:00
Kurt Kartaltepe 3e2ad118b9 linux-capture: Fail when libdrm missing
I forgot to extend the FATAL_ERROR messages to include libdrm.
2021-09-25 15:27:51 -07:00
Vainock 11a690b038 Update translations from Crowdin 2021-09-24 09:42:08 -07:00
Kurt Kartaltepe 7384f6f061
linux-capture: Add libdrm dependency check (#5326)
We require libdrm for its header so add the cmake module and header path
to the build. We don't need to link libdrm though so we dont add it to
libraries.
2021-09-23 13:05:53 -05:00
columbarius 7bc06e0db6 linux-capture: Omit implicit modifier token when creating texture
DRM_FORMAT_MOD_INVALID is a token for implicit modifier. When importing
a DMA-BUF with implicit modifier we should call
gs_texture_create_from_dmabuf() without modifier.
2021-09-21 12:57:49 -03:00
Georges Basile Stavracas Neto ef0540c0d7 linux-capture: Lookup session handle without typechecks
g_variant_lookup() obligatorily receives the type of the variant to
lookup. This function is used when retrieving the session handle
from the portal's response, and the variant type passed is "s" (a
string).

However, xdg-desktop-portal had a bug: the documentation explicitly
mentions that the session handle is an object path (of variant type
"o"), but it passed a string (of variant type "s"). This mismatch
was fixed in the xdg-desktop-portal release 1.10 [1], but that broke
the PipeWire capture code, which was passing specifically the "s"
value to the variant lookup.

Fix this by not checking the variant type at all. Object paths ("o")
are simply strings with a few extra checks, and we don't actually need
to perform these checks.

This change probably broke other apps, and that makes me extremely sad :(

[1] https://github.com/flatpak/xdg-desktop-portal/pull/609
2021-09-17 08:36:56 -07:00
columbarius ed5749e466 pipewire: Create textures from multiplanar DMA-BUF
The gs_texture_create_from_dmabuf function is able to create textures
from multiplanar DMA-BUF data. However, the only in-tree consumer of
this function - the PipeWire capture - does not use that.

Make PipeWire create textures from multiplanar buffers.
2021-08-25 19:48:22 -07:00
Georges Basile Stavracas Neto 09b5290c7b linux-capture: Load XSHM capture on EGL/X11
Unlike Xcomposite, the XSHM plugin does not use GLX code, and thus
can be used on when EGL renderer is used. It still is X11-specific
though, and shouldn't be used on Wayland.

Rework the obs_module_load() function of linux-capture to use a
switch statement, and load XSHM both on EGL/X11 and GLX/X11.

Fixes https://github.com/obsproject/obs-studio/issues/5122
2021-08-15 00:13:00 -07:00
Georges Basile Stavracas Neto ec3e8146b2 pipewire: Properly pass sizes to gs_draw_sprite_subregion
The gs_draw_sprite_subregion() function is used when a cropping
rectangle is received from PipeWire. It is usually used by
compositors to implement window screencast - where a large and
mostly empty frame is sent, the window contents are only a small
part of it, and the crop rectangle tells us that.

Recently the wlroots implementation of portals started to use it
to implement cropping, and it exposed a bug in the PipeWire code
in OBS Studio. The gs_draw_sprite_subregion() function takes a pair
of integers representing position (x, y) and a pair of integers
representing size (width, height). The PipeWire code, however,
passes a second pair of positions (x2, y2) instead of sizes, and
it causes overrendering the crop area.

This bug wasn't hit yet because both GNOME and KDE implementations
always send (0, 0) as position, which practically never trigger
this condition.

Pass only width and height to gs_draw_sprite_subregion(), instead
of adding x and y to them.

Fixes https://github.com/obsproject/obs-studio/issues/4982
2021-07-08 08:32:55 -07:00
Georges Basile Stavracas Neto fdce267a9a linux-capture: Use portal's D-Bus on PipeWire captures
Intead of creating one pair of GDBusConnection + GDBusProxy objects
for each PipeWire capture, be it window or desktop, use the global
ones managed by portal.c.

Even if g_bus_get_sync() ends up reusing the same object under the
hood, it's still a net gain, since it has to perform some thread
synchronization routines that aren't necessary here. Creating the
proxy object was a worse offender, because despite being asynchronous,
it would still incur in a few socket messages + a cancellable fd +
thread synchronization.

Reuse these objects from portal.c. The biggest code change here is
that create_proxy() and on_proxy_created_cb() were merged into
init_obs_pipewire().
2021-06-30 01:51:02 -07:00
Georges Basile Stavracas Neto e1c38a1f77 linux-capture: Add getters for portal's D-Bus connection and proxy
It'll be used by the next commit to reuse these objects instead of creating
one per capture.
2021-06-30 01:51:02 -07:00
Georges Basile Stavracas Neto c18f1ea7ed linux-capture: Conditionally register PipeWire captures
Right now we just assume that every compositor and portal implementation
exposes both window and monitor captures, but that's not true, and in fact
the Desktop portal provides a simple mechanism to check which source types
are available: a D-Bus property called "AvailableSourceTypes".

Read this D-Bus property, and use it to conditionally register the desktop
and the window captures.

Related: https://github.com/obsproject/obs-studio/issues/4815
2021-06-30 01:51:02 -07:00
Georges Basile Stavracas Neto 6942bb814d pipewire: Properly account for cursor hotspot
The cursor bitmap is centered on the hotspot, so not accounting
for it means PipeWire captures were positioning the cursor sprite
slightly off.

Properly account for the hotspot by subtracting it from the cursor
position.

Related: https://github.com/obsproject/obs-studio/issues/4766
2021-06-22 19:36:15 -07:00
Translation ef2b1eb1c6 Update translations from Crowdin 2021-06-11 07:18:15 -07:00
Gol-D-Ace 90df8d44df Update translations from Crowdin 2021-05-30 20:33:35 +02:00
jpark37 9eaf2fa766 linux-capture: Add OBS_SOURCE_SRGB flag 2021-05-03 01:19:56 -07:00