obsproject / obs-studio

OBS Studio - Free and open source software for live streaming and screen recording
https://obsproject.com
GNU General Public License v2.0
60.67k stars 8.02k forks source link

Pipewire "out of buffers" and render lag with Linux on Wayland #11580

Open lexano-ivs opened 18 hours ago

lexano-ivs commented 18 hours ago

Operating System Info

Ubuntu 24.04

Other OS

No response

OBS Studio Version

31.0.0-rc1

OBS Studio Version (Other)

No response

OBS Studio Log URL

https://obsproject.com/logs/ejZ0DoN56yhfNVBO

OBS Studio Crash Log URL

No response

Expected Behavior

I expect no render lag when using multiple pipewire screen capture sources (each using an individual application), and no messages of the following format in the debug log:

16:27:07.224: [pipewire] Out of buffers!

Current Behavior

Render lag count is increasing very frequently and also the skipped frames are incrementing as well. The debug log often output a single or sometimes a burst of messages of the form:

16:27:07.224: [pipewire] Out of buffers!

The presence of these "Out of buffers" messages seems to directly cause render lag counts to increment.

The exact line that is being tripped is https://github.com/obsproject/obs-studio/blob/c8e215be3da8d0a5cfd83bb35db4be045a7669b5/plugins/linux-pipewire/pipewire.c#L676

If I use fewer Pipewire application captures, the problem is reduced (or completely masked if there is only 1).

Steps to Reproduce

  1. Use Ubuntu 24.04 with Wayland an NVIDIA GPU (I don't think the GPU matters but I was using this)
  2. Install SuperTuxkart and glxgears
  3. Open a shell with multiple tabs
  4. Shell tab 1: Run glxgears
  5. Shell tab 2: Run supertuxkart --demo-mode=5 --demo-laps=3 --demo-karts=3. Configure SuperTuxkart with VSYNC on and set resolution to 1080p with maximum GPU detail. SuperTuxkart will run in demo mode if left alone for a few seconds.
  6. Open another shell, and run something like htop or nvidia-smi dmon just to get some activity
  7. Start OBS studio. I used the flatpak build.
  8. Configure canvas and output to 1440p.
  9. Add Pipewire Screen capture individual sources for glxgears, supertuxkart, and the shell with htop or similar.
  10. In OBS, open the stats window with View->Stats
  11. Add another Pipewire Screen capture source for the OBS Stats window.
  12. Add a Media Source and playback a local AVC file in a loop using HW Decode if available. I used a 1080p clip but anything similar will work. The Media Source in fact didn't seem to make a difference in my testing but reporting it for completeness.
  13. Arrange the scene into something suitable.
  14. Open the log file for local viewing: Help -> Log Files -> View Current Log
  15. Start streaming to Twitch.
  16. The log will eventually show "[pipewire] Out of buffers!" and the stats window will show render lag and skipped frames.

Anything else we should know?

The canvas and output are set to 2560x1440p for this test. The issue with pipewire running out of buffers also happens with 1080p, but much less frequently. Using 1440p makes it much easier to reproduce.

The issue becomes far more prevalent if using the TEB (Twitch Enhanced Broadcasting) beta flatpak build at https://github.com/amazon-contributing/upstreaming-to-obs-studio/wiki/TEB-Beta-Linux-Installation#teb-v40-build. In this case, multiple encodes are running in tandem and the number of "Out of buffers!" messages spikes in addition to the render lag count. While the stream is still running in this case, simply disabling all but 1 (any 1) pipewire capture from view stops the error messages and render lag counts.

lexano-ivs commented 18 hours ago

For reference, a screenshot of my configuration: Screenshot from 2024-12-02 16-51-26

kkartaltepe commented 15 hours ago

Your log is incomplete, replicate the issue and then restart obs and upload the previous log.

Use Ubuntu 24.04 with Wayland an NVIDIA GPU (I don't think the GPU matters but I was using this)

No this is probably the most important thing besides which compositor you are using. Please attempt to replicate with another vendor and another compositor.

tytan652 commented 8 hours ago

You will have to try to reproduce with either Fedora, Arch Linux or a distro that do have more recent dependencies. PipeWire get fixes but Ubuntu does not get them, and Debian based distro mess too much with patches around PipeWire.

lexano-ivs commented 1 hour ago

I setup the same configuration with EndeavourOS (Arch-based) with the Gnome desktop on Wayland, and applied all updates as of today. This is indeed much more stable than Ubuntu 24.04 in terms of the pipewire "Out of buffers" issue. I don't see the problem during steady-state in this configuration. It does point to a problem with a prior version of pipewire and/or differences in the desktop environment or compositor.

Update: The "Out of buffers" problem is happening with TEB enabled. The test above was with a 31.0.0-rc1 using a single output stream to Twitch. With TEB (between 3 and 5 output streams), I'm seeing many "Out of buffer" messages. The trigger seems to be several pipewire capture sessions and multiple output streams simultaneously.

Log file with TEB is at https://obsproject.com/logs/Z66AsQcbwBd67sLy