Weird audio behavior: PipeWire/PulseAudio not working sometimes

Hi,

So I have been using PulseAudio but starting from ~2 weeks ago some really weird issues started to occur. The first time I start my Sway session and open up FireFox and play a YouTube video, sound works fine. But as soon as I open up a new video, there is suddenly no sound. At this point if I open up some other multimedia application such as VLC or Tidal there is no sound either. I would need to restart the Sway session (not refresh it) to make the sound work again. But after literally one YouTube video the sound stop working again.

I had not changed any of my audio settings for quite a while and I didn’t know what was going on. I figured it might be PulseAudio’s problem so I switched to PipeWire, but the same issues persists.

My pulseaudio config is pretty standard so I’m not posting it here. Here is my PipeWire config:

  # Pipewire to enable sound
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    wireplumber.enable = true;
    config.pipewire = {
      "context.properties" = {
        "link.max-buffers" = 16;
        "log.level" = 2; # https://docs.pipewire.org/page_daemon.html
      };
    };
    config.pipewire-pulse = {
      "context.properties" = { "log.level" = 2; };
      "context.modules" = [
        {
          name = "libpipewire-module-rtkit";
          args = {
            "nice.level" = -15;
            "rt.prio" = 88;
            "rt.time.soft" = 200000;
            "rt.time.hard" = 200000;
          };
          flags = [ "ifexists" "nofail" ];
        }
        { name = "libpipewire-module-protocol-native"; }
        { name = "libpipewire-module-client-node"; }
        { name = "libpipewire-module-adapter"; }
        { name = "libpipewire-module-metadata"; }
        {
          name = "libpipewire-module-protocol-pulse";
          args = {
            "pulse.min.req" = "32/48000";
            "pulse.default.req" = "32/48000";
            "pulse.max.req" = "32/48000";
            "pulse.min.quantum" = "32/48000";
            "pulse.max.quantum" = "32/48000";
            "server.address" = [ "unix:native" ];
          };
        }
      ];
      "stream.properties" = {
        "node.latency" = "32/48000";
        "resample.quality" = 1;
      };
    };
  };

I basically copy and paste it from the PipeWire Wiki.

I started some troubleshooting. Looks like the pipewire service is working fine:

$ systemctl --user status pipewire.service                                                 
● pipewire.service - PipeWire Multimedia Service
     Loaded: loaded (/etc/systemd/user/pipewire.service; linked-runtime; preset: enabled)
    Drop-In: /nix/store/d9735ahrgsz6kdj2y3fl7sv80n596kv7-user-units/pipewire.service.d
             └─overrides.conf
     Active: active (running) since Mon 2022-12-19 12:24:20 EST; 22min ago
TriggeredBy: ● pipewire.socket
   Main PID: 15809 (pipewire)
      Tasks: 5 (limit: 38159)
     Memory: 12.9M
        CPU: 2.489s
     CGroup: /user.slice/user-1000.slice/user@1000.service/session.slice/pipewire.service
             └─15809 /nix/store/0hdlg94l91r3x6wi6sj7izaiafh7vlyh-pipewire-0.3.63/bin/pipewire

Dec 19 12:24:20 nixos systemd[1688]: Started PipeWire Multimedia Service.
Dec 19 12:24:20 nixos pipewire[15809]: mod.rt: Can't find xdg-portal: (null)
Dec 19 12:24:20 nixos pipewire[15809]: mod.rt: found session bus but no portal
Dec 19 12:24:20 nixos pipewire[15809]: [0:40:44.040712370] [15809]  INFO IPAManager ipa_manager.cpp:143 libcamer>
Dec 19 12:24:20 nixos pipewire[15809]: [0:40:44.040841640] [15809]  INFO Camera camera_manager.cpp:293 libcamera>
Dec 19 12:24:20 nixos pipewire[15809]: ALSA lib parser.c:1194:(parse_sequence) error: sequence command 'devdisal>
Dec 19 12:34:12 nixos pipewire[15809]: [0:50:35.326702986] [15809]  INFO IPAManager ipa_manager.cpp:143 libcamer>
Dec 19 12:34:12 nixos pipewire[15809]: [0:50:35.326875705] [15809]  INFO Camera camera_manager.cpp:293 libcamera>
Dec 19 12:35:05 nixos pipewire[15809]: ALSA lib parser.c:1194:(parse_sequence) error: sequence command 'devdisal>
lines 1-22/22 (END)

But I did notice the warning mod.rt: Can't find xdg-portal: (null). Is this related to my weird audio behavior? I thought it might be because PipeWire was not able to detect user environment variables so based on the Sway wiki I did this:

      dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
      systemctl --user stop pipewire wireplumber xdg-desktop-portal xdg-desktop-portal-wlr
      systemctl --user start pipewire wireplumber xdg-desktop-portal xdg-desktop-portal-wlr

But it didn’t help. Notice here I’m using wireplumber, not pipewire-media-session.

But if I manually restart wireplumber service using systemctl the sound works again. But after one video it still stops working anymore.

I’m really lost at this point. It’s not that audio is entirely not working, but it stops working after a few video/audio playbacks, which is very frustrating and hard to troubleshoot. Any help is appreciated!

EDIT:
I’m on a ThinkPad X1 Carbon, if it matters at all. And everything is configured system-wide, in a single configuration.nix. I’m not using Home Manager.

EDIT EDIT:
Volume control (increase/decrease volume, mute, etc) has been working with no issues, at least when the audio is working.

1 Like

I wonder if it’s related but the wireplumber service is always stopped when I log in with gnome x11. I have been running wireplumber in my terminal for a couple of weeks :sweat_smile:

I had the exact same issues.

This seems to be due to a kernel bug. (Sound just gets lost (#2886) · Issues · PipeWire / pipewire · GitLab)

Using the 6.x kernel for now solved the problem for me:
boot.kernelPackages = pkgs.linuxPackages_latest;

3 Likes

Looks like issue resolved! Thank you so much!