nowrep / obs-vkcapture

OBS Linux Vulkan/OpenGL game capture
GNU General Public License v2.0
502 stars 24 forks source link

High CPU Usage #180

Closed Postnozet closed 8 months ago

Postnozet commented 8 months ago

Describe the bug When i run a game and the plugin starts capturing, obs starts using the CPU, seems like 1 thread at 100% even without recording or streaming. I tried disabling the preview in OBS but it does not help.

Screenshots or video Screenshot_20231108_194637 Screenshot_20231108_194719

System (please complete the following information):

OBS log:

OBS 29.1.3-1 log file uploaded at 2023-11-08, 19:41:46

19:40:17.962: Using EGL/X11
19:40:17.962: CPU Name: AMD Ryzen 5 5600X 6-Core Processor
19:40:17.962: CPU Speed: 3719.230MHz
19:40:17.962: Physical Cores: 6, Logical Cores: 12
19:40:17.962: Physical Memory: 32019MB Total, 23047MB Free
19:40:17.962: Kernel Version: Linux 6.5.9-arch2-1
19:40:17.962: Distribution: "Arch Linux" Unknown
19:40:17.962: Desktop Environment: KDE (KDE)
19:40:17.962: Session Type: x11
19:40:17.962: Window System: X11.0, Vendor: The X.Org Foundation, Version: 1.21.1
19:40:17.963: Qt Version: 6.6.0 (runtime), 6.5.1 (compiled)
19:40:17.963: Portable mode: false
19:40:17.993: OBS 29.1.3-1 (linux)
19:40:17.993: ---------------------------------
19:40:17.993: ---------------------------------
19:40:17.993: audio settings reset:
19:40:17.993:   samples per sec: 48000
19:40:17.993:   speakers:        2
19:40:17.993:   max buffering:   960 milliseconds
19:40:17.993:   buffering type:  dynamically increasing
19:40:17.994: ---------------------------------
19:40:17.994: Initializing OpenGL...
19:40:18.031: Loading up OpenGL on adapter AMD AMD Radeon RX 6800 XT (navi21, LLVM 16.0.6, DRM 3.54, 6.5.9-arch2-1)
19:40:18.031: OpenGL loaded successfully, version 4.6 (Core Profile) Mesa 23.2.1-arch1.2, shading language 4.60
19:40:18.051: ---------------------------------
19:40:18.051: video settings reset:
19:40:18.051:   base resolution:   2560x1440
19:40:18.051:   output resolution: 1920x1080
19:40:18.051:   downscale filter:  Bicubic
19:40:18.051:   fps:               60/1
19:40:18.051:   format:            NV12
19:40:18.051:   YUV mode:          Rec. 709/Partial
19:40:18.051: NV12 texture support not available
19:40:18.051: P010 texture support not available
19:40:18.053: Audio monitoring device:
19:40:18.053:   name: За замовчуванням
19:40:18.053:   id: default
19:40:18.053: ---------------------------------
19:40:18.058: Failed to load 'en-US' text for module: 'decklink-captions.so'
19:40:18.064: Failed to load 'en-US' text for module: 'decklink-output-ui.so'
19:40:18.068: A DeckLink iterator could not be created.  The DeckLink drivers may not be installed
19:40:18.068: Failed to initialize module 'decklink.so'
19:40:18.151: [pipewire] Available captures:
19:40:18.151: [pipewire]     - Desktop capture
19:40:18.151: [pipewire]     - Window capture
19:40:18.165: v4l2loopback not installed, virtual camera disabled
19:40:18.171: Failed to load 'uk-UA' text for module: 'linux-vkcapture.so'
19:40:18.171: [linux-vkcapture] plugin loaded successfully (version 1.4.4)
19:40:18.188: VAAPI: API version 1.20
19:40:18.189: FFmpeg VAAPI H264 encoding supported
19:40:18.194: FFmpeg VAAPI HEVC encoding supported
19:40:18.243: ---------------------------------
19:40:18.243:   Loaded Modules:
19:40:18.243:     text-freetype2.so
19:40:18.243:     rtmp-services.so
19:40:18.243:     obs-x264.so
19:40:18.243:     obs-vst.so
19:40:18.243:     obs-transitions.so
19:40:18.243:     obs-outputs.so
19:40:18.243:     obs-libfdk.so
19:40:18.243:     obs-filters.so
19:40:18.243:     obs-ffmpeg.so
19:40:18.243:     linux-vkcapture.so
19:40:18.243:     linux-v4l2.so
19:40:18.243:     linux-pulseaudio.so
19:40:18.243:     linux-pipewire.so
19:40:18.243:     linux-jack.so
19:40:18.243:     linux-capture.so
19:40:18.243:     linux-alsa.so
19:40:18.243:     image-source.so
19:40:18.243:     frontend-tools.so
19:40:18.243:     decklink-output-ui.so
19:40:18.243:     decklink-captions.so
19:40:18.243: ---------------------------------
19:40:18.243: ==== Startup complete ===============================================
19:40:18.271: All scene data cleared
19:40:18.271: ------------------------------------------------
19:40:18.273: pulse-input: Server name: 'PulseAudio (on PipeWire 0.3.84) 15.0.0'
19:40:18.273: pulse-input: Audio format: s24le, 48000 Hz, 2 channels
19:40:18.273: pulse-input: Sample format s24le not supported by OBS,using float32le instead for recording
19:40:18.273: pulse-input: Started recording from 'alsa_output.usb-ASUS_Xonar_U7_MKII-00.analog-stereo.monitor' (default)
19:40:18.273: [Loaded global audio device]: 'Пристрій відтворення'
19:40:18.274: pulse-input: Server name: 'PulseAudio (on PipeWire 0.3.84) 15.0.0'
19:40:18.274: pulse-input: Audio format: s24le, 48000 Hz, 1 channels
19:40:18.274: pulse-input: Sample format s24le not supported by OBS,using float32le instead for recording
19:40:18.274: pulse-input: Started recording from 'alsa_input.usb-3142_Fifine_Microphone-00.mono-fallback' (default)
19:40:18.274: [Loaded global audio device]: 'Мікрофон/Aux'
19:40:18.274: xshm-input: Geometry 2560x1440 @ 0,0
19:40:18.276: Switched to scene 'Сцена 2'
19:40:18.276: ------------------------------------------------
19:40:18.276: Loaded scenes:
19:40:18.276: - scene 'Сцена':
19:40:18.276:     - source: 'Game Capture' (vkcapture-source)
19:40:18.276: - scene 'Сцена 2':
19:40:18.276:     - source: 'Захоплення екрану (XSHM)' (xshm_input)
19:40:18.276: ------------------------------------------------
19:40:18.868: adding 21 milliseconds of audio buffering, total audio buffering is now 21 milliseconds (source: Мікрофон/Aux)
19:40:18.868: 
19:40:56.438: User switched to scene 'Сцена'
19:40:59.403: [linux-vkcapture] Client 1 connected (pid=12454)
19:41:04.420: [linux-vkcapture] Client 1 not responding, disconnecting...
19:41:04.420: [linux-vkcapture] Client 1 disconnected
19:41:09.794: [linux-vkcapture] Client 2 connected (pid=12454)
19:41:10.820: [linux-vkcapture] Creating texture from dmabuf 2560x1440 modifier:144115188622605059
19:41:10.820: [linux-vkcapture]  [0] fd:41 stride:10240 offset:0
19:41:10.820: [linux-vkcapture]  [1] fd:42 stride:3072 offset:15728640
19:41:30.020: [linux-vkcapture] Creating texture from dmabuf 2560x1440 modifier:144115188622605059
19:41:30.020: [linux-vkcapture]  [0] fd:52 stride:10240 offset:0
19:41:30.020: [linux-vkcapture]  [1] fd:53 stride:3072 offset:15728640

Game log:

[obs-vkcapture] ------------------- vulkan capture freed -------------------
[obs-vkcapture] Texture VK_FORMAT_B8G8R8A8_SRGB 2560x1440
[obs-vkcapture] ------------------ vulkan capture started ------------------
nowrep commented 8 months ago

Can you check thread name? In htop F2 -> Display options -> Show custom thread names

Postnozet commented 8 months ago

Can you check thread name? In htop F2 -> Display options -> Show custom thread names

Screenshot_20231108_233551

nowrep commented 8 months ago

Thanks.

Can you build from git in debug cmake -DCMAKE_BUILD_TYPE=Debug and then:

  1. run gdb --ex=r obs
  2. reproduce the high cpu usage
  3. press Ctrl+c
  4. thread apply all bt

and post the output.

Postnozet commented 8 months ago

Thanks.

Can you build from git in debug cmake -DCMAKE_BUILD_TYPE=Debug and then:

  1. run gdb --ex=r obs
  2. reproduce the high cpu usage
  3. press Ctrl+c
  4. thread apply all bt

and post the output.

Thread 1 "obs" received signal SIGINT, Interrupt.
0x00007ffff3f20f6f in poll () from /usr/lib/libc.so.6
(gdb) thread apply all bt

Thread 38 (Thread 0x7fff73fff6c0 (LWP 3703) "threaded-ml"):
#0  0x00007ffff3f20f6f in poll () at /usr/lib/libc.so.6
#1  0x00007fffe724b8c7 in  () at /usr/lib/libpulse.so.0
#2  0x00007fffe723546c in pa_mainloop_poll () at /usr/lib/libpulse.so.0
#3  0x00007fffe723f42c in pa_mainloop_iterate () at /usr/lib/libpulse.so.0
#4  0x00007fffe723f4e1 in pa_mainloop_run () at /usr/lib/libpulse.so.0
#5  0x00007fffe724fc02 in  () at /usr/lib/libpulse.so.0
#6  0x00007fffe5861c67 in  () at /usr/lib/pulseaudio/libpulsecommon-16.1.so
#7  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#8  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 19 (Thread 0x7fffa8f736c0 (LWP 3675) "linux-vkcapture"):
#0  0x00007ffff3f20f6f in poll () at /usr/lib/libc.so.6
#1  0x00007fffc00468eb in server_thread_run (data=0x0) at /home/oleh/.git/obs-vkcapture/src/vkcapture.c:760
#2  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#3  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 18 (Thread 0x7fffaa22e6c0 (LWP 3664) "scripting: defe"):
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3eb2980 in  () at /usr/lib/libc.so.6
#2  0x00007fffc810b546 in  () at /usr/lib/libobs-scripting.so.1
#3  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#4  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 17 (Thread 0x7fffaaa2f6c0 (LWP 3659) "libobs: graphic"):
#0  0x00007ffff3ef37f5 in clock_nanosleep () at /usr/lib/libc.so.6
#1  0x00007ffff3f058c7 in nanosleep () at /usr/lib/libc.so.6
#2  0x00007ffff65b5195 in os_sleepto_ns () at /usr/lib/libobs.so.0
#3  0x00007ffff6581aa3 in obs_graphics_thread_loop () at /usr/lib/libobs.so.0
#4  0x00007ffff65830f9 in obs_graphics_thread () at /usr/lib/libobs.so.0
#5  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#6  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 16 (Thread 0x7fffc09f96c0 (LWP 3658) "video-io: video"):
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3eb2980 in  () at /usr/lib/libc.so.6
--Type <RET> for more, q to quit, c to continue without paging--
#2  0x00007ffff65aa268 in  () at /usr/lib/libobs.so.0
#3  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#4  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 15 (Thread 0x7fffc15fa6c0 (LWP 3657) "obs:gl0"):
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3ea9d40 in pthread_cond_wait () at /usr/lib/libc.so.6
#2  0x00007fffc8ed1b5c in  () at /usr/lib/dri/radeonsi_dri.so
#3  0x00007fffc8f1ca0c in  () at /usr/lib/dri/radeonsi_dri.so
#4  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#5  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 14 (Thread 0x7fffc1dfb6c0 (LWP 3656) "obs:gdrv0"):
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3ea9d40 in pthread_cond_wait () at /usr/lib/libc.so.6
#2  0x00007fffc8ed1b5c in  () at /usr/lib/dri/radeonsi_dri.so
#3  0x00007fffc8f1ca0c in  () at /usr/lib/dri/radeonsi_dri.so
#4  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#5  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 13 (Thread 0x7fffc27fc6c0 (LWP 3655) "obs:shlo0"):
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3ea9d40 in pthread_cond_wait () at /usr/lib/libc.so.6
#2  0x00007fffc8ed1b5c in  () at /usr/lib/dri/radeonsi_dri.so
#3  0x00007fffc8f1ca0c in  () at /usr/lib/dri/radeonsi_dri.so
#4  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#5  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 12 (Thread 0x7fffc2ffd6c0 (LWP 3654) "obs:sh0"):
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3ea9d40 in pthread_cond_wait () at /usr/lib/libc.so.6
#2  0x00007fffc8ed1b5c in  () at /usr/lib/dri/radeonsi_dri.so
#3  0x00007fffc8f1ca0c in  () at /usr/lib/dri/radeonsi_dri.so
#4  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#5  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 11 (Thread 0x7fffc37fe6c0 (LWP 3653) "obs:disk$0"):
--Type <RET> for more, q to quit, c to continue without paging--
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3ea9d40 in pthread_cond_wait () at /usr/lib/libc.so.6
#2  0x00007fffc8ed1b5c in  () at /usr/lib/dri/radeonsi_dri.so
#3  0x00007fffc8f1ca0c in  () at /usr/lib/dri/radeonsi_dri.so
#4  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#5  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 10 (Thread 0x7fffc8d286c0 (LWP 3652) "obs:cs0"):
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3ea9d40 in pthread_cond_wait () at /usr/lib/libc.so.6
#2  0x00007fffc8ed1b5c in  () at /usr/lib/dri/radeonsi_dri.so
#3  0x00007fffc8f1ca0c in  () at /usr/lib/dri/radeonsi_dri.so
#4  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#5  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 9 (Thread 0x7fffcb7fe6c0 (LWP 3651) "audio-io: audio"):
#0  0x00007ffff3ef37f5 in clock_nanosleep () at /usr/lib/libc.so.6
#1  0x00007ffff3f058c7 in nanosleep () at /usr/lib/libc.so.6
#2  0x00007ffff3f2e349 in usleep () at /usr/lib/libc.so.6
#3  0x00007ffff65b5209 in os_sleepto_ns_fast () at /usr/lib/libobs.so.0
#4  0x00007ffff65a641a in  () at /usr/lib/libobs.so.0
#5  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#6  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 8 (Thread 0x7fffc3fff6c0 (LWP 3650) "tiny_tubular_ta"):
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3eb2980 in  () at /usr/lib/libc.so.6
#2  0x00007ffff65bc8a3 in  () at /usr/lib/libobs.so.0
#3  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#4  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 7 (Thread 0x7fffcbfff6c0 (LWP 3649) "libobs: hotkey "):
#0  0x00007ffff3ea74ae in  () at /usr/lib/libc.so.6
#1  0x00007ffff3eaa055 in pthread_cond_timedwait () at /usr/lib/libc.so.6
#2  0x00007ffff65b4d6a in os_event_timedwait () at /usr/lib/libobs.so.0
#3  0x00007ffff654be65 in obs_hotkey_thread () at /usr/lib/libobs.so.0
#4  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
--Type <RET> for more, q to quit, c to continue without paging--
#5  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 6 (Thread 0x7fffe0f266c0 (LWP 3648) "gdbus"):
#0  0x00007ffff3f20f6f in poll () at /usr/lib/libc.so.6
#1  0x00007ffff3190276 in  () at /usr/lib/libglib-2.0.so.0
#2  0x00007ffff3132b97 in g_main_loop_run () at /usr/lib/libglib-2.0.so.0
#3  0x00007fffe6ea214c in  () at /usr/lib/libgio-2.0.so.0
#4  0x00007ffff31639f5 in  () at /usr/lib/libglib-2.0.so.0
#5  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#6  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 5 (Thread 0x7fffe17536c0 (LWP 3647) "gmain"):
#0  0x00007ffff3f20f6f in poll () at /usr/lib/libc.so.6
#1  0x00007ffff3190276 in  () at /usr/lib/libglib-2.0.so.0
#2  0x00007ffff3130162 in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0
#3  0x00007ffff31301b2 in  () at /usr/lib/libglib-2.0.so.0
#4  0x00007ffff31639f5 in  () at /usr/lib/libglib-2.0.so.0
#5  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#6  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 4 (Thread 0x7fffe1f546c0 (LWP 3646) "pool-spawner"):
#0  0x00007ffff3f2c73d in syscall () at /usr/lib/libc.so.6
#1  0x00007ffff318b2b7 in g_cond_wait () at /usr/lib/libglib-2.0.so.0
#2  0x00007ffff30fd1b4 in  () at /usr/lib/libglib-2.0.so.0
#3  0x00007ffff3165a7e in  () at /usr/lib/libglib-2.0.so.0
#4  0x00007ffff31639f5 in  () at /usr/lib/libglib-2.0.so.0
#5  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#6  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 3 (Thread 0x7fffe27556c0 (LWP 3645) "QXcbEventQueue"):
#0  0x00007ffff3f20f6f in poll () at /usr/lib/libc.so.6
#1  0x00007ffff21e220b in  () at /usr/lib/libxcb.so.1
#2  0x00007ffff21e3f3d in xcb_wait_for_event () at /usr/lib/libxcb.so.1
#3  0x00007fffe3332cfe in  () at /usr/lib/qt6/plugins/platforms/../../../libQt6XcbQpa.so.6
#4  0x00007ffff46c97b3 in  () at /usr/lib/libQt6Core.so.6
#5  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#6  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6
--Type <RET> for more, q to quit, c to continue without paging--

Thread 2 (Thread 0x7fffe2f566c0 (LWP 3644) "QDBusConnection"):
#0  0x00007ffff3f20f6f in poll () at /usr/lib/libc.so.6
#1  0x00007ffff3190276 in  () at /usr/lib/libglib-2.0.so.0
#2  0x00007ffff3130162 in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0
#3  0x00007ffff4797934 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt6Core.so.6
#4  0x00007ffff456cc5e in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt6Core.so.6
#5  0x00007ffff4649d6f in QThread::exec() () at /usr/lib/libQt6Core.so.6
#6  0x00007fffe6cb87ff in  () at /usr/lib/libQt6DBus.so.6
#7  0x00007ffff46c97b3 in  () at /usr/lib/libQt6Core.so.6
#8  0x00007ffff3eaa9eb in  () at /usr/lib/libc.so.6
#9  0x00007ffff3f2e7cc in  () at /usr/lib/libc.so.6

Thread 1 (Thread 0x7fffe3387f40 (LWP 3641) "obs"):
#0  0x00007ffff3f20f6f in poll () at /usr/lib/libc.so.6
#1  0x00007ffff3190276 in  () at /usr/lib/libglib-2.0.so.0
#2  0x00007ffff3130162 in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0
#3  0x00007ffff4797934 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt6Core.so.6
#4  0x00007ffff456cc5e in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt6Core.so.6
#5  0x00007ffff4565178 in QCoreApplication::exec() () at /usr/lib/libQt6Core.so.6
#6  0x00005555555f4ba8 in main ()

Screenshot_20231109_131248

nowrep commented 8 months ago

Thanks. Does it only happen after some client connects (after it starts capturing game) or right when starting obs? Also does it stop after the client disconnects?

Postnozet commented 8 months ago

Thanks. Does it only happen after some client connects (after it starts capturing game) or right when starting obs? Also does it stop after the client disconnects?

After some testing there are 2 scenarios:

  1. Firts run the game then OBS -> no CPU usage -> reopen the game -> high CPU usage
  2. First run OBS then the game -> high CPU usage

It does not stop after the client disconnects. So, even if I close the game it continues to use the CPU (except the 1 scenario before reopening the game)

Does it only happen after some client connects

Yes

nowrep commented 8 months ago

Please build with this patch and post obs log.

diff --git a/src/vkcapture.c b/src/vkcapture.c
index f595675..56a23df 100644
--- a/src/vkcapture.c
+++ b/src/vkcapture.c
@@ -756,9 +756,12 @@ static void *server_thread_run(void *data)
     server_add_fd(sockfd, POLLIN);
     server_add_fd(server.eventfd, POLLIN);

+        blog(LOG_INFO, "server fd %d eventfd %d", sockfd, server.eventfd);
+
     while (true) {
         int ret = poll(server.fds.array, server.fds.num, -1);
         if (ret <= 0) {
+            blog(LOG_ERROR, "poll ret=%d (%s)", ret, strerror(errno));
             continue;
         }

@@ -766,6 +769,14 @@ static void *server_thread_run(void *data)
             break;
         }

+        blog(LOG_INFO, "poll ret=%d", ret);
+        for (size_t i = 0; i < server.fds.num; ++i) {
+            struct pollfd *p = server.fds.array + i;
+            if (p->revents) {
+                blog(LOG_INFO, "fd event %d", p->fd);
+            }
+        }
+
         if (server_has_event_on_fd(sockfd)) {
             int clientfd = accept4(sockfd, NULL, NULL, SOCK_CLOEXEC | SOCK_NONBLOCK);
             if (clientfd >= 0) {
@@ -776,6 +787,7 @@ static void *server_thread_run(void *data)
                 pthread_mutex_lock(&server.mutex);
                 da_push_back(server.clients, &client);
                 pthread_mutex_unlock(&server.mutex);
+                blog(LOG_INFO, "client fd %d ", client.sockfd);
                 server_add_fd(client.sockfd, POLLIN);
                 struct ucred cred = {0};
                 socklen_t cred_len = sizeof(cred);
nowrep commented 8 months ago

Actually I have an idea what's going on, this should fix it:

diff --git a/src/vkcapture.c b/src/vkcapture.c
index f595675..8846399 100644
--- a/src/vkcapture.c
+++ b/src/vkcapture.c
@@ -762,8 +762,12 @@ static void *server_thread_run(void *data)
             continue;
         }

-        if (server_has_event_on_fd(server.eventfd) && server.quit) {
-            break;
+        if (server_has_event_on_fd(server.eventfd)) {
+            uint64_t q;
+            read(server.eventfd, &q, sizeof(q));
+            if (server.quit) {
+                break;
+            }
         }

         if (server_has_event_on_fd(sockfd)) {