Commit graph

187 commits

Author SHA1 Message Date
tytan652 1007a0cf42 linux-capture: Fix format-overflow warning 2023-01-19 13:08:46 -05:00
tytan652 2839837ed6 plugins: Fix -Wsign-compare on Linux 2023-01-19 13:08:46 -05:00
tytan652 7de0bd350f libobs,plugins: Remove one-case switches 2023-01-16 11:43:47 +01:00
Translation Updater 783bd52197 Update translations from Crowdin 2023-01-08 04:10:37 +00:00
PatTheMav ae01a626b6
linux-capture: Replace invocations of sprintf with snprintf
Fixes deprecation warnings in Xcode 14/clang on macOS and reduces
chance of buffer overflows.
2022-11-11 19:51:27 +01:00
Kurt Kartaltepe 1249ebe53d linux-capture: Fixup window name/class checking
There were a couple mistakes here that caused the fallback checks other
than window ID to fail to ever return valid results. This restores this
functionality that was broken since the c++/c transition.

fixes #7404
2022-09-24 20:42:57 -03:00
Kurt Kartaltepe b1c65af2b1 linux-capture: Ensure name pixmap is checked
The void cookie will never return an error unless we use the explicitly
checked version of this function.
2022-09-12 12:50:53 -03:00
Translation Updater cc2d0791ca Update translations from Crowdin 2022-08-30 09:00:44 +00:00
Translation Updater 4aaa07f93d Update translations from Crowdin 2022-08-17 04:22:50 +00:00
Translation Updater 81734be37c Update translations from Crowdin 2022-07-31 23:40:53 +00:00
Vainock eb06594381 Use property suffixes for units everywhere 2022-07-22 08:24:51 -04:00
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