Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdg-desktop-portal-wlr capture sources (screen/window) can only ever be one and the same source #4815

Closed
Omar007 opened this issue Jun 5, 2021 · 13 comments
Labels
Dependency Issue Issue is in external library or dependency, not OBS itself Linux Affects Linux

Comments

@Omar007
Copy link

Omar007 commented Jun 5, 2021

Operating System Info

Other

Other OS

Arch Linux

OBS Studio Version

27.0.0

OBS Studio Version (Other)

No response

OBS Studio Log URL

N/A

OBS Studio Crash Log URL

No response

Expected Behavior

Each individual (new) Pipewire capture element to be isolated/unique in its configuration; each new Screen Capture can be a different screen and each new Window Capture can be a different window without affecting existing elements.

Current Behavior

After adding a new Pipewire capture element and selecting a different screen or window from the previously existing Pipewire capture elements, the old/existing ones are also changed to the new selection.

Steps to Reproduce

  1. Add a new Screen/Window Capture (Pipewire) element
  2. Select Monitor/Screen 1
  3. Add a new Screen/Window Capture (Pipewire) element
  4. Select Monitor/Screen 2
  5. See the first capture element also change to Monitor/Screen 2

Anything else we should know?

It's not just limited only to the one previously added element, you can continue adding for as long as you want; all existing ones will change to the new selection.
When you remove the most recently added capture element, the previous ones will switch back to the screen you selected before it. You can also keep doing this for as long as you want.
So if you have 3 screens (A, B, C) and add a unique/new capture element for each, first you have 1 with A, then 1+2 with B, then 1+2+3 with C at the end. Removing in the order 3, 2, 1 results in the reverse. Removing in the order 1, 2, 3 only ever keeps C showing, removing in the order 3, 1, 2 (or 1, 3, 2) makes it end with B (the selection for 2) never showing A again.

Aside from the above behaviour, it also looks like the Window Capture element is (doing) the same as the Screen Capture (both capture screen/output) but that looks to me to be a different issue, most likely not even an OBS issue.
Probably a problem with XDG Desktop Portal wlr and/or the selection tool being used (slurp) as both elements result in the same selection command execution (slurp -f %o -or) and thus returned data; the output/screen name).

Running Sway (wlroots based Wayland).

@kkartaltepe
Copy link
Collaborator

Provide a log from obs.

@Omar007
Copy link
Author

Omar007 commented Jun 5, 2021

'A' log or one that contains something specific/with a custom log setting or something? Because they show absolutely nothing in relation to the described behaviour at all. For the removal even less.

19:20:40.461: User added scene 'test'
19:20:40.461: User switched to scene 'test'
19:20:45.167: adding 64 milliseconds of audio buffering, total audio buffering is now 106 milliseconds (source: Mic/Aux)
19:20:45.167: 
19:20:48.292: PipeWire initialized (sender name: 1_397)
19:20:48.294: User added source 'Screen Capture (PipeWire)' (pipewire-desktop-capture-source) to scene 'test'
19:20:48.322: [pipewire] available cursor modes:
19:20:48.322: [pipewire]     - Always visible
19:20:48.322: [pipewire]     - Hidden
19:20:48.326: [pipewire] screencast session created
19:20:49.395: [pipewire] asking for desktop…
19:20:49.402: [pipewire] desktop selected, setting up screencast
19:20:49.408: [pipewire] created stream 0x555b5b448f30
19:20:49.408: [pipewire] playing stream…
19:20:57.588: PipeWire initialized (sender name: 1_397)
19:20:57.590: User added source 'Screen Capture (PipeWire) 2' (pipewire-desktop-capture-source) to scene 'test'
19:20:57.607: [pipewire] available cursor modes:
19:20:57.607: [pipewire]     - Always visible
19:20:57.607: [pipewire]     - Hidden
19:20:57.610: [pipewire] screencast session created
19:21:02.235: [pipewire] asking for desktop…
19:21:02.241: [pipewire] desktop selected, setting up screencast
19:21:02.288: [pipewire] created stream 0x555b5b48c700
19:21:02.288: [pipewire] playing stream…
19:21:13.647: User Removed source 'Screen Capture (PipeWire) 2' (pipewire-desktop-capture-source) from scene 'test'
19:21:21.676: User Removed source 'Screen Capture (PipeWire)' (pipewire-desktop-capture-source) from scene 'test'
19:21:25.038: User switched to scene 'Break / AFK'
19:21:25.038: User Removed scene 'test'

Log for the described reproduction steps; added 1 for display A, 2 for display B (both show display B at that point), then removed 2 (1 switches back to A) then 1.

@kkartaltepe
Copy link
Collaborator

Just like the template specifies, a full log from when you experienced the issue. Please do not trim the log and provide it as is unaltered.

@Omar007
Copy link
Author

Omar007 commented Jun 5, 2021

Template didn't specify and only talked about a URL which I don't have? I assume if the application crashes it allows you to upload something or w/e but it's not crashing or anything. Just pulled this from ~/.config/obs-studio/logs 🤷‍♂️

I'll attach the full thing when I get back.

EDIT:

20:33:11.875: Platform: Wayland
20:33:11.890: CPU Name: AMD Ryzen Threadripper 2990WX 32-Core Processor
20:33:11.890: CPU Speed: 3000.000MHz
20:33:11.892: Physical Cores: 32, Logical Cores: 64
20:33:11.892: Physical Memory: 64274MB Total, 30760MB Free
20:33:11.892: Kernel Version: Linux 5.12.9-arch1-1
20:33:11.892: Distribution: "Arch Linux" Unknown
20:33:11.892: Session Type: wayland
20:33:11.892: Portable mode: false
20:33:11.922: OBS 27.0.0-1 (linux)
20:33:11.922: ---------------------------------
20:33:11.922: ---------------------------------
20:33:11.922: audio settings reset:
20:33:11.922: 	samples per sec: 48000
20:33:11.922: 	speakers:        2
20:33:11.924: ---------------------------------
20:33:11.924: Initializing OpenGL...
20:33:11.924: Using EGL/Wayland
20:33:11.924: Initialized EGL 1.5
20:33:11.939: Loading up OpenGL on adapter AMD Radeon RX Vega (VEGA10, DRM 3.40.0, 5.12.9-arch1-1, LLVM 11.1.0)
20:33:11.939: OpenGL loaded successfully, version 4.6 (Core Profile) Mesa 21.1.1, shading language 4.60
20:33:11.954: ---------------------------------
20:33:11.954: video settings reset:
20:33:11.954: 	base resolution:   1920x1080
20:33:11.954: 	output resolution: 1920x1080
20:33:11.954: 	downscale filter:  Bicubic
20:33:11.954: 	fps:               60/1
20:33:11.954: 	format:            NV12
20:33:11.954: 	YUV mode:          709/Partial
20:33:11.954: NV12 texture support not available
20:33:11.958: Audio monitoring device:
20:33:11.958: 	name: Default
20:33:11.958: 	id: default
20:33:11.958: ---------------------------------
20:33:11.959: Failed to load 'en-US' text for module: 'decklink-captions.so'
20:33:11.961: Failed to load 'en-US' text for module: 'decklink-ouput-ui.so'
20:33:11.962: os_dlopen(/usr//lib/obs-plugins/frontend-tools.so->/usr//lib/obs-plugins/frontend-tools.so): libluajit-5.1.so.2: cannot open shared object file: No such file or directory
20:33:11.962:
20:33:11.962: Module '/usr//lib/obs-plugins/frontend-tools.so' not loaded
20:33:11.963: Failed to load 'en-US' text for module: 'liblooking-glass-obs.so'
20:33:11.966: A DeckLink iterator could not be created.  The DeckLink drivers may not be installed
20:33:11.966: No blackmagic support
20:33:11.972: os_dlopen(libnvidia-encode.so.1->libnvidia-encode.so.1): libnvidia-encode.so.1: cannot open shared object file: No such file or directory
20:33:11.972:
20:33:11.972: FFMPEG VAAPI supported
20:33:11.978: ---------------------------------
20:33:11.978:   Loaded Modules:
20:33:11.978:     text-freetype2.so
20:33:11.978:     sndio.so
20:33:11.978:     rtmp-services.so
20:33:11.978:     obs-x264.so
20:33:11.978:     obs-transitions.so
20:33:11.978:     obs-outputs.so
20:33:11.978:     obs-libfdk.so
20:33:11.978:     obs-filters.so
20:33:11.978:     obs-ffmpeg.so
20:33:11.978:     linux-v4l2.so
20:33:11.978:     linux-pulseaudio.so
20:33:11.978:     linux-jack.so
20:33:11.978:     linux-decklink.so
20:33:11.979:     linux-capture.so
20:33:11.979:     linux-alsa.so
20:33:11.979:     liblooking-glass-obs.so
20:33:11.979:     image-source.so
20:33:11.979:     decklink-ouput-ui.so
20:33:11.979:     decklink-captions.so
20:33:11.979: ---------------------------------
20:33:11.979: ==== Startup complete ===============================================
20:33:11.979: obs-data.c: [obs_data_create_from_json] Failed reading json string (-1): wrong arguments
20:33:11.981: All scene data cleared
20:33:11.981: ------------------------------------------------
20:33:11.984: Switched to scene 'Scene'
20:33:11.984: ------------------------------------------------
20:33:11.984: Loaded scenes:
20:33:11.984: - scene 'Scene':
20:33:11.984: ------------------------------------------------
20:33:17.779: PipeWire initialized (sender name: 1_418)
20:33:17.782: User added source 'Screen Capture (PipeWire)' (pipewire-desktop-capture-source) to scene 'Scene'
20:33:17.801: [pipewire] available cursor modes:
20:33:17.801: [pipewire]     - Always visible
20:33:17.801: [pipewire]     - Hidden
20:33:17.804: [pipewire] screencast session created
20:33:18.736: [pipewire] asking for desktop…
20:33:18.741: [pipewire] desktop selected, setting up screencast
20:33:18.748: [pipewire] created stream 0x559efb83d690
20:33:18.749: [pipewire] playing stream…
20:33:24.902: PipeWire initialized (sender name: 1_418)
20:33:24.904: User added source 'Screen Capture (PipeWire) 2' (pipewire-desktop-capture-source) to scene 'Scene'
20:33:24.918: [pipewire] available cursor modes:
20:33:24.918: [pipewire]     - Always visible
20:33:24.918: [pipewire]     - Hidden
20:33:24.921: [pipewire] screencast session created
20:33:26.356: [pipewire] asking for desktop…
20:33:26.362: [pipewire] desktop selected, setting up screencast
20:33:26.366: [pipewire] created stream 0x559efb8448c0
20:33:26.367: [pipewire] playing stream…
20:33:36.761: User Removed source 'Screen Capture (PipeWire) 2' (pipewire-desktop-capture-source) from scene 'Scene'
20:33:41.726: User Removed source 'Screen Capture (PipeWire)' (pipewire-desktop-capture-source) from scene 'Scene'
20:33:43.183: ==== Shutting down ==================================================
20:33:43.184: All scene data cleared
20:33:43.184: ------------------------------------------------
20:33:43.230: Freeing OBS context data
20:33:43.246: == Profiler Results =============================
20:33:43.246: run_program_init: 216.93 ms
20:33:43.246:  ┣OBSApp::AppInit: 1.49 ms
20:33:43.246:  ┃ ┗OBSApp::InitLocale: 0.624 ms
20:33:43.246:  ┗OBSApp::OBSInit: 134.441 ms
20:33:43.246:    ┣obs_startup: 17.129 ms
20:33:43.246:    ┗OBSBasic::OBSInit: 87.109 ms
20:33:43.246:      ┣OBSBasic::InitBasicConfig: 0.077 ms
20:33:43.246:      ┣OBSBasic::ResetAudio: 0.163 ms
20:33:43.246:      ┣OBSBasic::ResetVideo: 35.923 ms
20:33:43.246:      ┣OBSBasic::InitOBSCallbacks: 0.004 ms
20:33:43.246:      ┣OBSBasic::InitHotkeys: 0.04 ms
20:33:43.246:      ┣obs_load_all_modules: 19.96 ms
20:33:43.247:      ┃ ┣obs_init_module(decklink-captions.so): 0.027 ms
20:33:43.247:      ┃ ┣obs_init_module(decklink-ouput-ui.so): 0.522 ms
20:33:43.247:      ┃ ┣obs_init_module(image-source.so): 0.006 ms
20:33:43.247:      ┃ ┣obs_init_module(liblooking-glass-obs.so): 0.004 ms
20:33:43.247:      ┃ ┣obs_init_module(linux-alsa.so): 0.001 ms
20:33:43.247:      ┃ ┣obs_init_module(linux-capture.so): 0.191 ms
20:33:43.247:      ┃ ┣obs_init_module(linux-decklink.so): 0.062 ms
20:33:43.247:      ┃ ┣obs_init_module(linux-jack.so): 0.001 ms
20:33:43.247:      ┃ ┣obs_init_module(linux-pulseaudio.so): 0.001 ms
20:33:43.247:      ┃ ┣obs_init_module(linux-v4l2.so): 0.037 ms
20:33:43.247:      ┃ ┣obs_init_module(obs-ffmpeg.so): 0.124 ms
20:33:43.247:      ┃ ┃ ┗nvenc_check: 0.108 ms
20:33:43.247:      ┃ ┣obs_init_module(obs-filters.so): 0.016 ms
20:33:43.247:      ┃ ┣obs_init_module(obs-libfdk.so): 0 ms
20:33:43.247:      ┃ ┣obs_init_module(obs-outputs.so): 0.001 ms
20:33:43.247:      ┃ ┣obs_init_module(obs-transitions.so): 0.006 ms
20:33:43.247:      ┃ ┣obs_init_module(obs-x264.so): 0.001 ms
20:33:43.247:      ┃ ┣obs_init_module(rtmp-services.so): 0.441 ms
20:33:43.247:      ┃ ┣obs_init_module(sndio.so): 0.003 ms
20:33:43.247:      ┃ ┗obs_init_module(text-freetype2.so): 0.006 ms
20:33:43.247:      ┣OBSBasic::ResetOutputs: 0.27 ms
20:33:43.247:      ┣OBSBasic::CreateHotkeys: 0.028 ms
20:33:43.247:      ┣OBSBasic::InitService: 1.086 ms
20:33:43.247:      ┣OBSBasic::InitPrimitives: 0.089 ms
20:33:43.247:      ┗OBSBasic::Load: 3.189 ms
20:33:43.247: obs_hotkey_thread(25 ms): min=0 ms, median=0 ms, max=0.001 ms, 99th percentile=0.001 ms, 100% below 25 ms
20:33:43.247: audio_thread(Audio): min=0 ms, median=0.019 ms, max=0.087 ms, 99th percentile=0.042 ms
20:33:43.247: obs_graphics_thread(16,6667 ms): min=0.145 ms, median=0.401 ms, max=19.374 ms, 99th percentile=0.828 ms, 99.9467% below 16.667 ms
20:33:43.247:  ┣tick_sources: min=0 ms, median=0.004 ms, max=0.145 ms, 99th percentile=0.009 ms
20:33:43.247:  ┣output_frame: min=0.062 ms, median=0.166 ms, max=4.477 ms, 99th percentile=0.441 ms
20:33:43.247:  ┃ ┗gs_context(video->graphics): min=0.061 ms, median=0.166 ms, max=4.477 ms, 99th percentile=0.44 ms
20:33:43.247:  ┃   ┣render_video: min=0.013 ms, median=0.05 ms, max=1.142 ms, 99th percentile=0.115 ms
20:33:43.247:  ┃   ┃ ┗render_main_texture: min=0.011 ms, median=0.047 ms, max=1.134 ms, 99th percentile=0.111 ms
20:33:43.247:  ┃   ┗gs_flush: min=0.041 ms, median=0.105 ms, max=3.319 ms, 99th percentile=0.364 ms
20:33:43.247:  ┗render_displays: min=0.004 ms, median=0.179 ms, max=18.95 ms, 99th percentile=0.386 ms
20:33:43.247: =================================================
20:33:43.247: == Profiler Time Between Calls ==================
20:33:43.247: obs_hotkey_thread(25 ms): min=25.046 ms, median=25.083 ms, max=25.373 ms, 100% within ±2% of 25 ms (0% lower, 0% higher)
20:33:43.247: obs_graphics_thread(16,6667 ms): min=13.926 ms, median=16.667 ms, max=19.381 ms, 99.8933% within ±2% of 16.667 ms (0.0533618% lower, 0.0533618% higher)
20:33:43.247: =================================================
20:33:43.253: Number of memory leaks: 3

Full/complete OBS run of clean project; run OBS -> replication steps -> shutdown

@WizardCM WizardCM added the Linux Affects Linux label Jun 7, 2021
@GeorgesStavracas
Copy link
Member

It seems to me that it's an issue in wlroots. On OBS side, each capture source spawns one separate thread and PipeWire loop, and they basically don't interact with each other. This seems like the internal state of xdg-desktop-portal-wlr gets confused with two streams.

@Omar007
Copy link
Author

Omar007 commented Jun 10, 2021

That sounds like it could be plausible. I did not find anything about such a limitation but that doesn't eliminate the possibility it isn't an upstream bug.
I'll see if I can create a similar situation using XDG Desktop Portal directly to see if I can reproduce the problem there 🤔

The side-note/additional thing I mentioned in the "Anything else" segment (about the Window Capture == Screen Capture) is indeed xdg-desktop-portal-wlr related. Looks like that isn't supported yet and there is an open item for it emersion/xdg-desktop-portal-wlr#107

@kkartaltepe kkartaltepe added the Dependency Issue Issue is in external library or dependency, not OBS itself label Jun 10, 2021
@kkartaltepe kkartaltepe changed the title Pipewire capture elements (screen/window) can only ever be one and the same source xdg-desktop-portal-wlr capture sources (screen/window) can only ever be one and the same source Jun 10, 2021
@GeorgesStavracas
Copy link
Member

We cannot do anything on OBS side to work around this missing implementation, but it made me realize showing the window capture there is wrong and fixable. Incoming PR soon.

GeorgesStavracas added a commit to GeorgesStavracas/obs-studio that referenced this issue Jun 11, 2021
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: obsproject#4815
@GeorgesStavracas
Copy link
Member

@Omar007 would you please test the pull request above, and let us know if the "Window Capture (PipeWire)" entry is still visible on your machine?

GeorgesStavracas added a commit to GeorgesStavracas/obs-studio that referenced this issue Jun 13, 2021
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: obsproject#4815
@Omar007
Copy link
Author

Omar007 commented Jun 14, 2021

@GeorgesStavracas Sure, I can probably do so later today 👍

@Omar007
Copy link
Author

Omar007 commented Jun 14, 2021

Looks like that works and hides the unsupported capture mode.

Before
screenshot_2021-06-14T17:15:57

After
screenshot_2021-06-14T17:16:16

Windows Capture (second to last item) is not shown in the "After" 👍

On the subject of OBS related improvements, as another unrelated side-note, I also noticed on start the screen for Screen Capture needed to be reselected every time OBS was started with one of those in a scene.

Putting the side-notes aside for a bit and going back to the main/OG issue, I haven't gotten around to verifying the main issue outside of OBS yet so I can't confirm or deny whether or not the suspicion is correct. I should be able to do so this week. If it ends up being replicable outside of OBS I'll close this as an upstream issue.

@kkartaltepe
Copy link
Collaborator

On the subject of OBS related improvements, as another unrelated side-note, I also noticed on start the screen for Screen Capture needed to be reselected every time OBS was started with one of those in a scene.

That is a limitation of the xdg-desktop-portal protocol.

@Omar007
Copy link
Author

Omar007 commented Jun 14, 2021

Ah alright, fair enough. I thought I read it can be done without a chooser (requiring the user to supply it directly which I figured could be done as a property/setting on the OBS Scene Capture component) but maybe that was something specifically for xdg-desktop-portal-wlr 🤷‍♂️

EDIT: yea it was indeed. Specific config file for xdg-desktop-portal-wlr; https://github.com/emersion/xdg-desktop-portal-wlr/blob/master/xdg-desktop-portal-wlr.5.scd
That seems like a slight/sad oversight for xdg-desktop-portal that would've enabled setting up re-usable templates/presets.

@Omar007
Copy link
Author

Omar007 commented Jun 14, 2021

Alright I was able to do a test of the OG problem using both OBS and Firefox. Using OBS to select 1 screen, then running Firefox with a screenshare using https://mozilla.github.io/webrtc-landing/gum_test.html and selecting another, it's showing the same behaviour crossing program borders as well so it's def. an xdg-desktop-portal-wlr issue.

Thanks for all the info (and the tangent improvement on OBS 😁 ). Closing this for being an upstream problem 👍

@Omar007 Omar007 closed this as completed Jun 14, 2021
jp9000 pushed a commit that referenced this issue Jun 30, 2021
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: #4815
tommyvct pushed a commit to tommyvct/obs-studio that referenced this issue Jul 3, 2021
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: obsproject#4815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dependency Issue Issue is in external library or dependency, not OBS itself Linux Affects Linux
Projects
None yet
Development

No branches or pull requests

4 participants