emersion / xdg-desktop-portal-wlr

xdg-desktop-portal backend for wlroots
MIT License
596 stars 59 forks source link

Black screen using chromium #157

Closed mightyiam closed 3 years ago

mightyiam commented 3 years ago

What's wrong

I'm using this page to test and the capture is all black.

Chromium output

[222318:222354:0720/134510.251776:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.Notifications.GetCapabilities: object_path= /org/freedesktop/Notifications: org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
[222318:222423:0720/134510.287836:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[222318:222423:0720/134510.288228:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[222318:222423:0720/134510.288629:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.UPower.EnumerateDevices: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[222350:222350:0720/134510.335512:ERROR:sandbox_linux.cc(374)] InitializeSandbox() called with multiple threads in process gpu-process.
[222318:222318:0720/134512.720227:ERROR:base_capturer_pipewire.cc(972)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.ScreenCast” on object at path /org/freedesktop/portal/desktop
[222318:222318:0720/134513.945627:ERROR:base_capturer_pipewire.cc(972)] Failed to create a screen cast session: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.ScreenCast” on object at path /org/freedesktop/portal/desktop

Troubleshooting

The following is me going through the troubleshooting page one point at a time.

This page contains a checklist to verify you've set up xdg-desktop-portal-wlr and the rest of the screensharing software stack correctly. If you want a more in-depth explanation of why things might not work out of the box look at systemd user services and environment page

I read that page about the environment variables and systemd.

  1. Does the screen-sharing application support PipeWire for screen-sharing?

For Firefox and Chromium, upstream's binaries link to the PipeWire 0.2 client library, whereas your actual PipeWire service is likely to be 0.3. If this is the case for you, check if your distro has a package for the PipeWire compat client library; this library allows programs to use the 0.2 client API to talk to the 0.3 service. Alternatively, some distros patch Firefox and/or Chromium to use PipeWire 0.3 directly. Check this table for what your distro does.

It seems that the chromium I'm using is built against pipewire 0.3, because I'm using nixpkgs 21.05 and here's the package for chromium depending on pipewire: https://github.com/NixOS/nixpkgs/blob/21.05/pkgs/applications/networking/browsers/chromium/default.nix#L5 And here's pipewire: https://github.com/NixOS/nixpkgs/blob/nixos-21.05/pkgs/development/libraries/pipewire/default.nix#L49

For Firefox, also ensure the media.peerconnection.enabled flag in about:config is set to true and not false.

I'm skipping firefox for now.

For Chromium, also ensure the WebRTC PipeWire support flag at chrome://flags/#enable-webrtc-pipewire-capturer is set to Enabled.

It's enabled. I'm looking at the chrome://flags page and it's right on top, marked in blue and says "Enabled" on the drop down.

  1. Is the PipeWire service running?

systemctl --user status pipewire.socket pipewire should show active (running) for both.

● pipewire.socket - Multimedia System
     Loaded: loaded (/nix/store/7cz4k6ab3z87cgrvcjfw4193jbh6y1vz-pipewire-0.3.30/share/systemd/user/pipewire.socket; enabled; vendor preset: enabled)
    Drop-In: /nix/store/zd14k1i4rmkb9gk0qq9whbcqadp8hrid-user-units/pipewire.socket.d
             └─overrides.conf
     Active: active (running) since Tue 2021-07-20 09:46:45 +07; 3h 41min ago
   Triggers: ● pipewire.service
     Listen: /run/user/1001/pipewire-0 (Stream)
      Tasks: 0 (limit: 38367)
     Memory: 0B
        CPU: 0
     CGroup: /user.slice/user-1001.slice/user@1001.service/app.slice/pipewire.socket

Jul 20 09:46:45 mightyiam-desktop systemd[2683]: Listening on Multimedia System.

● pipewire.service - Multimedia Service
     Loaded: loaded (/nix/store/7cz4k6ab3z87cgrvcjfw4193jbh6y1vz-pipewire-0.3.30/share/systemd/user/pipewire.service; enabled; vendor preset: enabled)
    Drop-In: /nix/store/zd14k1i4rmkb9gk0qq9whbcqadp8hrid-user-units/pipewire.service.d
             └─overrides.conf
     Active: active (running) since Tue 2021-07-20 12:53:03 +07; 35min ago
TriggeredBy: ● pipewire.socket
   Main PID: 177502 (pipewire)
      Tasks: 2 (limit: 38367)
     Memory: 4.3M
        CPU: 70ms
     CGroup: /user.slice/user-1001.slice/user@1001.service/session.slice/pipewire.service
             └─177502 /nix/store/7cz4k6ab3z87cgrvcjfw4193jbh6y1vz-pipewire-0.3.30/bin/pipewire

Jul 20 12:53:03 mightyiam-desktop systemd[2683]: Started Multimedia Service.

If you installed PipeWire just for the sake of xdpw, make sure to run systemctl --user enable pipewire.socket so that it starts automatically when you log in.

Let's skip this part and see that we can capture manually for now.

  1. Is the Pipewire Multimedia Session Manager service running?

systemctl --user status pipewire-media-session should show active (running).

If the service does not exist, your distro may package it as a separate package named something like pipewire-media-session. Screencasts will be stuck in the "paused" state without a session manager.

● pipewire-media-session.service - Multimedia Service Session Manager
     Loaded: loaded (/nix/store/jdk83j88bkblxiimvdp99srm9yg88i1g-pipewire-0.3.30-mediaSession/share/systemd/user/pipewire-media-session.service; enabled; vendor preset: enabled)
    Drop-In: /nix/store/zd14k1i4rmkb9gk0qq9whbcqadp8hrid-user-units/pipewire-media-session.service.d
             └─overrides.conf
     Active: active (running) since Tue 2021-07-20 12:53:03 +07; 38min ago
   Main PID: 177503 (pipewire-media-)
      Tasks: 2 (limit: 38367)
     Memory: 4.3M
        CPU: 217ms
     CGroup: /user.slice/user-1001.slice/user@1001.service/session.slice/pipewire-media-session.service
             └─177503 /nix/store/jdk83j88bkblxiimvdp99srm9yg88i1g-pipewire-0.3.30-mediaSession/bin/pipewire-media-session

Jul 20 12:53:03 mightyiam-desktop systemd[2683]: Started Multimedia Service Session Manager.
Jul 20 12:53:03 mightyiam-desktop pipewire-media-session[177503]: GetManagedObjects() failed: org.freedesktop.DBus.Error.ServiceUnknown

Is this failure an issue?

If you installed PipeWire just for the sake of xdpw, make sure to run systemctl --user enable pipewire-media-session so that it starts automatically when you log in.

Skipping for now.

  1. Is the xdp service running?

systemctl --user status xdg-desktop-portal should show active (running).

● xdg-desktop-portal.service - Portal service
     Loaded: loaded (/nix/store/9g60zywp490345kfz6hxv955qvlgi2bg-xdg-desktop-portal-1.8.1/share/systemd/user/xdg-desktop-portal.service; static)
     Active: active (running) since Tue 2021-07-20 12:53:16 +07; 40min ago
   Main PID: 177749 (.xdg-desktop-po)
      Tasks: 4 (limit: 38367)
     Memory: 2.1M
        CPU: 70ms
     CGroup: /user.slice/user-1001.slice/user@1001.service/app.slice/xdg-desktop-portal.service
             └─177749 /nix/store/9g60zywp490345kfz6hxv955qvlgi2bg-xdg-desktop-portal-1.8.1/libexec/xdg-desktop-portal

Jul 20 12:53:16 mightyiam-desktop systemd[2683]: Starting Portal service...
Jul 20 12:53:16 mightyiam-desktop systemd[2683]: Started Portal service.
  1. Does the xdp service know your wayland socket?

env | grep '^WAYLAND_DISPLAY=' will show the value of the WAYLAND_DISPLAY environment variable set by your Wayland compositor.

WAYLAND_DISPLAY=wayland-1

< "/proc/$(pidof xdg-desktop-portal)/environ" tr '\0' '\n' | grep '^WAYLAND_DISPLAY=' should print the same value. If it does not print anything, run:

# Import the WAYLAND_DISPLAY env var from sway into the systemd user session.
dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=$compositor_name

# Stop any services that are running, so that they receive the new env var when they restart.
systemctl --user stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
systemctl --user start pipewire-media-session

Replace the "$compositor_name" in XDG_CURRENT_DESKTOP=$compositor_name with the name of your compositor, according to what it's called in the UseIn= line of /usr/share/xdg-desktop-portal/portals/wlr.portal. That is, XDG_CURRENT_DESKTOP=sway for sway, XDG_CURRENT_DESKTOP=Wayfire for wayfire, and XDG_CURRENT_DESKTOP=river for river.

You should use your compositor's method for autostart commands to run those commands when the compositor starts:

  • For sway, put them in a script that is execd from your sway config. Because the commands must run in sequence, you should put them in a script rather than execing them individually, since sway runs individual exec'd commands in parallel.

  • For Wayfire, TODO EDIT ME IF YOU KNOW HOW.

  • For river, TODO EDIT ME IF YOU KNOW HOW.

WAYLAND_DISPLAY=wayland-1
  1. Does the xdp service know what your compositor is?

< "/proc/$(pidof xdg-desktop-portal)/environ" tr '\0' '\n' | grep '^XDG_CURRENT_DESKTOP=' should print XDG_CURRENT_DESKTOP=$compositor_name. If it does not, running the commands suggested in the previous list item will handle it.

If multiple portals are installed (GNOME, KDE, xdpw, etc), the xdp service looks at the XDG_CURRENT_DESKTOP env var to know which portal to use. Just like the WAYLAND_DISPLAY env var above, this env var needs to be defined on the xdp service. Technically this is only necessary if you have multiple portals installed, but it's a good idea to set it anyway.

XDG_CURRENT_DESKTOP=sway

It's also a good idea to define XDG_CURRENT_DESKTOP=$compositor_name in the shell that you used to start your compositor, because some applications also benefit from having the env var set.

Not sure how it's done, but it seems that it is done somehow correctly.

3lpsy commented 3 years ago

So I'm running arch/sway with wofi. My screensharing broke today. However, I made a config change that fixed it. I think the issue was to do with screen selection based on the fix. Anyway, here's the change I made. You'll need to augment if wofi is not installed.

Create the following file: ~/.config/xdg-desktop-portal-wlr/config

[screencast]
chooser_type=dmenu
chooser_cmd=wofi --show=dmenu

Someone posted that on reddit a month ago and for some reason it fixed it. To test, I restarted the xdg and xdg wlr services and it started working the mozilla gum test and obs (thought I had to restart obs of course).

The reason I think it has to do with screen/output selection is the config just changes how the output is chosen. I imagine rofi would also work as well (if you had the correct command. Your problem may be unrelated but the above is worth a shot.

mightyiam commented 3 years ago

I am able to share screen now. I don't know what changed. I made some package upgrades. I rebooted. This issue should be closed. Thanks a lot for this project.

3lpsy commented 3 years ago

I think when I fixed it, it had nothing to do with the recommendation above. I think just restarting xdg-desktop-portal-wlr and xdg-desktop-portal (without restarting pipewire afterwards) is what did it for me.