NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.5k stars 13.68k forks source link

chromium is missing pipewire / #enable-webrtc-pipewire-capturer flag #89528

Closed jsravn closed 4 years ago

jsravn commented 4 years ago

Project description This flag is available in most other major distros. It is necessary to enable screen sharing on wayland inside of chromium, combined with xlr-desktop-portal-wlr and pipewire.

It requires the rtc_use_pipewire=true build flag and a dependency on libpipewire02. See https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/chromium as an example.

Metadata

primeos commented 4 years ago

@jsravn that would definitely be nice to have :) I actually also noticed this but unfortunately cannot test this easily as I'm not using screen sharing. If you could contribute a PR that would be awesome (but be aware that Chromium does unfortunately take quite some time to compile). Alternatively (but less preferably) we could make the required changes with the next update and test the core functionality (as always) and you could test screen sharing after the new version is available in the binary caches.

Additionally we would need to package xlr-desktop-portal-wlr in Nixpkgs to make this work on wlroots based compositors. On Gnome/KDE this might work out-of-the-box, but I don't know what they currently implement/provide.

jsravn commented 4 years ago

@primeos https://github.com/NixOS/nixpkgs/pull/83485#event-3411162020 was just merged w/ xlr-desktop-portal-wlr. I'll try building chromium w/ the flag - as you say it takes a while, so I can leave it overnight and give it a shot.

flokli commented 4 years ago

@jsravn how does the situation look like with google-chrome-*? Is the flag available there, as in, screensharing with wayland already works there?

jsravn commented 4 years ago

@flokli yes, it's available in google-chrome.

image

I'm still trying to get it to work with xlr-desktop-portal-wlr - I've done this in the past, but it's not working out of the box yet with https://github.com/NixOS/nixpkgs/pull/83485.

flokli commented 4 years ago

And just to make sure, you also did set

xdg.portal = {
  enable = true;
  extraPortals = with pkgs; [ xdg-desktop-portal-wlr ];
  gtkUsePortal = true;
};

services.pipewire.enable = true;

as described there?

jsravn commented 4 years ago

@floki yes I did. I'm almost got it working I think. There are a few issues out of the box:

  1. google-chrome is missing the pipewire 0.2 runtime dependency, so I added it as (I'm on 20.03 so pkgs.pipewire is 0.2):

      (google-chrome.overrideAttrs (oldAttrs: rec {
        rpath = makeLibraryPath [ pkgs.pipewire ] + ":" + oldAttrs.rpath;
      }))
  2. unstable.pipewire service doesn't work - it doesn't seem to be setting up the path correctly. I'm trying to fix this now:

Jun 06 08:59:22 thor systemd[1215]: Started Multimedia Service.
Jun 06 08:59:22 thor pipewire[5052]: [E][000000100.218511][daemon-config.c:202 pw_daemon_config_run_commands()] could not run command exec: 'pipewire-media-session': No such file or directory
Jun 06 08:59:22 thor pipewire[5052]: [E][000000100.218527][main.c:123 main()] failed to run config commands: No such file or directory
Jun 06 08:59:22 thor pipewire[5052]: [W][000000100.218565][connection.c:313 prepare_packet()] old version detected
Jun 06 08:59:22 thor systemd[1215]: pipewire.service: Succeeded.
 systemctl --user cat pipewire.service
# /nix/store/6lmfx1qnx6675xnppfjzlnsippxhnif1-pipewire-0.3.5/lib/systemd/user/pipewire.service
[Unit]
Description=Multimedia Service

# We require pipewire.socket to be active before starting the daemon, because
# while it is possible to use the service without the socket, it is not clear
# why it would be desirable.
#
# A user installing pipewire and doing `systemctl --user start pipewire`
# will not get the socket started, which might be confusing and problematic if
# the server is to be restarted later on, as the client autospawn feature
# might kick in. Also, a start of the socket unit will fail, adding to the
# confusion.
#
# After=pipewire.socket is not needed, as it is already implicit in the
# socket-service relationship, see systemd.socket(5).
Requires=pipewire.socket

[Service]
Type=simple
ExecStart=/nix/store/6lmfx1qnx6675xnppfjzlnsippxhnif1-pipewire-0.3.5/bin/pipewire
Restart=on-failure

[Install]
Also=pipewire.socket
WantedBy=default.target
# ls /nix/store/6lmfx1qnx6675xnppfjzlnsippxhnif1-pipewire-0.3.5/bin
pipewire                pw-cat  pw-dot   pw-metadata  pw-midiplay    pw-mon   pw-profiler  pw-record    spa-monitor
pipewire-media-session  pw-cli  pw-jack  pw-mididump  pw-midirecord  pw-play  pw-pulse     spa-inspect  

My current config on 20.03 looks like:

    environment.systemPackages = with pkgs; [
      unstable.pipewire
    ];

    # Wayland screen sharing.
    systemd.packages = with pkgs; [ unstable.pipewire ];
    systemd.user.sockets.pipewire.wantedBy = [ "sockets.target" ];
    xdg.portal = {
      enable = true;
      extraPortals = with pkgs; [ my.xdg-desktop-portal-wlr xdg-desktop-portal-gtk ];
      gtkUsePortal = true;
    };

Where my.xdg-desktop-portal-wlr is the same package that was recently merged.

flokli commented 4 years ago

yeah, I'm currently already looking at it - pipewire wants to execute pipewire-media-session, but it's not in $PATH. We can patch /src/daemon/pipewire.conf.in to contain the absolute path. I'll check if it works and will get back to you.

flokli commented 4 years ago

Btw, we /really/ need a sway NixOS test, and better documentation on how to use sway.

I was trying stuff until it worked, and

      programs.sway.enable = true;

      services.xserver.enable = true;
      services.xserver.displayManager.sddm = {
        enable = true;
        autoLogin = {
          enable = true;
          user = "alice";
        };
      };
      services.xserver.displayManager.defaultSession = "sway";

does autologin me into a sway, but there might be a smarter way to do this, without also starting X.

jsravn commented 4 years ago

The sway recommendation is to just run sway from the terminal after login - that's how I do it at least.

I was able to workaround the environment issue by doing systemctl --user import-environment (but this is a kludge I think and shouldn't be necessary). But unfortunately it's now crashing and I'm not sure why:

Jun 06 09:25:15 thor systemd[1210]: Started Multimedia Service.
Jun 06 09:25:15 thor pipewire[4626]: [W][000000037.737658][connection.c:313 prepare_packet()] old version detected
Jun 06 09:25:15 thor pipewire[4626]: [W][000000037.737711][connection.c:313 prepare_packet()] old version detected
Jun 06 09:25:15 thor pipewire[4626]: [W][000000037.737959][connection.c:313 prepare_packet()] old version detected
Jun 06 09:25:15 thor pipewire[4626]: [W][000000037.738191][connection.c:313 prepare_packet()] old version detected
Jun 06 09:25:16 thor pipewire[4626]: [W][000000037.960958][module-protocol-native.c:964 on_before_hook()] client 0x223aee0: could not flush: Broken pipe
Jun 06 09:25:16 thor systemd-coredump[4634]: Process 4603 (.xdg-desktop-po) of user 1000 dumped core.
Jun 06 09:25:16 thor pipewire[4626]: [E][000000038.089767][bluez5-dbus.c:2003 get_managed_objects_reply()] GetManagedObjects() failed: org.freedesktop.DBus.Error.ServiceUnknown
flokli commented 4 years ago

Yeah, even my sddm config I also had to systemctl --user import-environment, otherwise pipewire complained about not being able to reach dbus:

machine # [   48.071876] pipewire[1344]: [E][000000047.980234][dbus.c:319 impl_get_connection()] Failed to connect to system bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

Afterwards, it segfaulted, as it wasn't able to find pipewire-media-session;

machine # [  125.055083] pipewire[3400]: [E][000000124.963161][daemon-config.c:202 pw_daemon_config_run_commands()] could not run command exec: 'pipewire-media-session': No such file or directory
machine # [  125.060703] pipewire[3400]: [E][000000124.966654][main.c:123 main()] failed to run config commands: No such file or directory
machine # [  125.080299] pipewire[3398]: [W][000000124.988479][module-rtkit.c:499 idle_func()] could not make thread realtime: No such file or directory
machine # [  125.089448] systemd[830]: pipewire.service: Succeeded.
machine # [  125.134033] systemd[830]: Started Multimedia Service.
machine # [  125.162899] pipewire[3404]: [W][000000125.070852][connection.c:313 prepare_packet()] old version detected
machine # [  125.166924] pipewire[3404]: [W][000000125.074206][connection.c:313 prepare_packet()] old version detected[  125.299964] show_signal_msg: 5 callbacks suppressed
machine # [  125.299966] pool-/nix/store[3401]: segfault at 75641733 ip 00007f1454b9399a sp 00007f143deaf958 error 4 in libc-2.30.so[7f1454a64000+144000]
machine # [  125.302876] Code: 80 7e 10 00 0f 84 f9 fe ff ff e9 81 0d f5 ff 90 89 f8 31 d2 c5 c5 ef ff 09 f0 25 ff 0f 00 00 3d 80 0f 00 00 0f 8f 56 03 00 00 <c5> fe 6f 0f c5 f5 74 06 c5 fd da c1 c5 fd 74 c7 c5 fd d7 c8 85 c9
machine # 
machine # [  125.176436] pipewire[3406]: [E][000000125.074376][daemon-config.c:202 pw_daemon_config_run_commands()] could not run command exec: 'pipewire-media-session': No such file or directory
machine # [  125.180207] pipewire[3406]: [E][000000125.074402][main.c:123 main()] failed to run config commands: No such file or directory
machine # [  125.209818] pipewire[3404]: [W][000000125.118348][module-rtkit.c:499 idle_func()] could not make thread realtime: No such file or directory
machine # [  125.222833] systemd[1]: Created slice system-systemd\x2dcoredump.slice.
machine # [  125.235957] systemd[1]: Started Process Core Dump (PID 3407/UID 0).

I patched pipewire to be able to find the path to pipewire-media-session, and that error message is gone. Now (apart from not being able to find bluez or rtkit) it /might/ only be some version incompatibilities, not sure:

machine # [  445.022968] pipewire[2890]: [W][000000444.931311][connection.c:313 prepare_packet()] old version detected
machine # [  445.033512] pipewire[2890]: [W][000000444.942225][connection.c:313 prepare_packet()] old version detected

I'll see if I can get as far with your chromium PR, will merge that then, and also submit the pipewire patch.

flokli commented 4 years ago

Okay, with the pipewire patch and google-chrome-beta, It seems I'm able to share at least my own application window :tada:.

I don't know yet why the alacritty window nearby isn't shown, and why "Entire Screen" is black, but that's probably due to me running sway inside X via ssdm.

flokli commented 4 years ago

pipewire PRs:

jsravn commented 4 years ago

@flokli I don't think you're using pipewire in that case. xdg-desktop-portal-wlr only supports full screen sharing atm. If it is black that means it's not working.

By the way I had to add pipewire_0_2 to my system packages to prevent xdg-desktop-portal from crashing. But now there seems to be some incompatibility in the pipewire service logs when chrome tries to connect:

Jun 06 09:59:36 thor pipewire[4493]: [E][000000137.346191][context.c:600 pw_context_debug_port_params()] params Spa:Enum:ParamId:EnumFormat: 0:0 (input format) Invalid argument
flokli commented 4 years ago

@jsravn you should be able to cherry-pick the pipewire patch from above to not have to manually add this to $PATH.

jsravn commented 4 years ago

Thanks!

I'm suspecting google-chrome is compiled with a too old version of pipewire. Enabling pipewire debug logs, it seems to be sending an incompatible format to the pipewire server (similar to https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/240). I have got this working with chromium compiled against pipewire 0.2.7 in the past, so I'm pretty sure it should work assuming the client library is recent enough. Once the chromium package has that flag enabled I'll try to retest.

jsravn commented 4 years ago

I just confirmed my last comment by building chromium locally w/ rtc_use_pipewire=true. It works perfectly for fullscreen sharing.

jsravn commented 4 years ago

Hmm take that back - it worked the first time but not anymore :/. Not sure what lib is missing where.

jsravn commented 4 years ago

Seems like xdg-desktop-portal is crashing:

Using host libthread_db library "/nix/store/9hy6c2hv8lcwc6clnc1p2jf09cs5q9dp-glibc-2.30/lib/libthread_db.so.1".
Core was generated by `/nix/store/8j915pk5hi81h1a8xs60iv0hpircwslf-xdg-desktop-portal-1.6.0/libexec/xd'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000000000042322d in append_parent_permissions.isra.0.constprop ()
[Current thread is 1 (Thread 0x7f30a8999700 (LWP 5057))]
(gdb) bt
#0  0x000000000042322d in append_parent_permissions.isra.0.constprop ()
#1  0x00000000004246db in handle_open_pipewire_remote ()
#2  0x00007f30b9947abd in ffi_call_unix64 () from /nix/store/qnk89y1996sbj1bhsxcia57x0iqwhgiq-libffi-3.3/lib/../lib64/libffi.so.7
#3  0x00007f30b994679c in ffi_call_int () from /nix/store/qnk89y1996sbj1bhsxcia57x0iqwhgiq-libffi-3.3/lib/../lib64/libffi.so.7
#4  0x00007f30b9e8e6ec in g_cclosure_marshal_generic () from /nix/store/k7q9yy1fk12hwfp4ziv914b45h84q99q-glib-2.64.1/lib/libgobject-2.0.so.0
#5  0x00007f30b9e8dec2 in g_closure_invoke () from /nix/store/k7q9yy1fk12hwfp4ziv914b45h84q99q-glib-2.64.1/lib/libgobject-2.0.so.0
#6  0x00007f30b9ea053e in signal_emit_unlocked_R () from /nix/store/k7q9yy1fk12hwfp4ziv914b45h84q99q-glib-2.64.1/lib/libgobject-2.0.so.0
#7  0x00007f30b9eab358 in g_signal_emitv () from /nix/store/k7q9yy1fk12hwfp4ziv914b45h84q99q-glib-2.64.1/lib/libgobject-2.0.so.0
#8  0x0000000000453cec in _xdp_screen_cast_skeleton_handle_method_call ()
#9  0x00007f30b9ff2370 in dispatch_in_thread_func () from /nix/store/k7q9yy1fk12hwfp4ziv914b45h84q99q-glib-2.64.1/lib/libgio-2.0.so.0
#10 0x00007f30b9f8610e in g_task_thread_pool_thread () from /nix/store/k7q9yy1fk12hwfp4ziv914b45h84q99q-glib-2.64.1/lib/libgio-2.0.so.0
#11 0x00007f30b9dcac44 in g_thread_pool_thread_proxy () from /nix/store/k7q9yy1fk12hwfp4ziv914b45h84q99q-glib-2.64.1/lib/libglib-2.0.so.0
#12 0x00007f30b9dca3dd in g_thread_proxy () from /nix/store/k7q9yy1fk12hwfp4ziv914b45h84q99q-glib-2.64.1/lib/libglib-2.0.so.0
#13 0x00007f30b9d34edd in start_thread () from /nix/store/jx19wa4xlh9n4324xdl9rjnykd19mmq3-glibc-2.30/lib/libpthread.so.0
#14 0x00007f30b9c65a4f in clone () from /nix/store/jx19wa4xlh9n4324xdl9rjnykd19mmq3-glibc-2.30/lib/libc.so.6
flokli commented 4 years ago

This might be yet another version incompatibility problem. I propose merging https://github.com/NixOS/nixpkgs/pull/89565 (as it's built with 0.2 everywhere else too), and then see if we can get it to work if the system pipewire also is 0.2.

I asked upstream about these problems in https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/240#note_524378 - maybe 0.3 needs to support 0.2 clients for some time until we should switch.

flokli commented 4 years ago

Heads-up: the bad client situation should have been fixed with the latest pipewire release, PR at https://github.com/NixOS/nixpkgs/pull/90039.

jsravn commented 4 years ago

Thanks for your help! I'm still getting the xdg-desktop-portal crash, however. I'm guessing there is something missing from my dbus environment - or perhaps it's trying to access a file/directory not available in nixos.

flokli commented 4 years ago

@jsravn could you open a new issue with some more details, like logs etc.?

jsravn commented 4 years ago

Okay, I made https://github.com/NixOS/nixpkgs/issues/91218.