Browse Source

linux-pipewire: Ensure the release point is always signaled

Since video rendering happens on a separate thread from PipeWire buffer
ingestion, it may happen that two buffers are ingested in quick
succession without the rendering thread ever getting to them. Since,
prior to this commit, the release sync point is only "primed" (set to
signal in the future) only on the video rendering thread, this results
in the buffer being returned to PipeWire's pool without anything ever
signaling the release point, effectively blocking it from ever getting
reused in the future. This quickly clogs up the buffer pool and leaves
only one buffer to circulate between the screencast source and OBS.

This commit adds a flag tracking whether the release point had been
primed. If, when ingesting a new PW buffer, the old buffer's release
point hadn't been primed, that means the video rendering thread never
got to that buffer, so the release point is immediately signaled,
marking the buffer reusable by the screencast source.
Ivan Molodetskikh 3 months ago
parent
commit
fb09098fd7
1 changed files with 11 additions and 0 deletions
  1. 11 0
      plugins/linux-pipewire/pipewire.c

+ 11 - 0
plugins/linux-pipewire/pipewire.c

@@ -144,6 +144,7 @@ struct _obs_pipewire_stream {
 		int release_syncobj_fd;
 		uint64_t acquire_point;
 		uint64_t release_point;
+		bool release_point_will_signal;
 		bool set;
 	} sync;
 };
@@ -766,6 +767,14 @@ static void process_video_sync(obs_pipewire_stream *obs_pw_stream)
 		}
 
 #if PW_CHECK_VERSION(1, 2, 0)
+		if (obs_pw_stream->sync.release_syncobj_fd != -1) {
+			if (!obs_pw_stream->sync.release_point_will_signal) {
+				gs_sync_signal_syncobj_timeline_point(obs_pw_stream->sync.release_syncobj_fd,
+								      obs_pw_stream->sync.release_point);
+				obs_pw_stream->sync.release_point_will_signal = true;
+			}
+		}
+
 		g_clear_fd(&obs_pw_stream->sync.acquire_syncobj_fd, NULL);
 		g_clear_fd(&obs_pw_stream->sync.release_syncobj_fd, NULL);
 
@@ -779,6 +788,7 @@ static void process_video_sync(obs_pipewire_stream *obs_pw_stream)
 			obs_pw_stream->sync.release_syncobj_fd =
 				fcntl(buffer->datas[planes + 1].fd, F_DUPFD_CLOEXEC, 5);
 			obs_pw_stream->sync.release_point = synctimeline->release_point;
+			obs_pw_stream->sync.release_point_will_signal = false;
 
 			obs_pw_stream->sync.set = true;
 		} else {
@@ -1384,6 +1394,7 @@ void obs_pipewire_stream_video_render(obs_pipewire_stream *obs_pw_stream, gs_eff
 		gs_sync_export_syncobj_timeline_point(release_sync, obs_pw_stream->sync.release_syncobj_fd,
 						      obs_pw_stream->sync.release_point);
 		gs_sync_destroy(release_sync);
+		obs_pw_stream->sync.release_point_will_signal = true;
 	}
 }