Skip to content

Commit b29d83a

Browse files
committed
fix(linux/pipewire): avoid video stream freeze (on display switch)
This is a trial-and-error workaround to avoid video stream freezing when display switching that somehow happens when not using the added thread sleeps due to a racecondition that needs to be further diagnosed. Also changes the order checks are done on capture timeout to be in a logical order (capture_cb before free_cb) as well as logging state changes as info messages again including any error messages.
1 parent 815a835 commit b29d83a

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/platform/linux/pipewire.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,13 @@ namespace pipewire {
420420
};
421421

422422
static void on_stream_state_changed(void *user_data, enum pw_stream_state old, enum pw_stream_state state, const char *err_msg) {
423-
BOOST_LOG(debug) << "[pipewire] PipeWire stream state: " << pw_stream_state_as_string(old)
424-
<< " -> " << pw_stream_state_as_string(state);
423+
if (err_msg != nullptr) {
424+
BOOST_LOG(info) << "[pipewire] PipeWire stream error '" << err_msg << "' on state: " << pw_stream_state_as_string(old)
425+
<< " -> " << pw_stream_state_as_string(state);
426+
} else {
427+
BOOST_LOG(info) << "[pipewire] PipeWire stream state: " << pw_stream_state_as_string(old)
428+
<< " -> " << pw_stream_state_as_string(state);
429+
}
425430

426431
auto *d = static_cast<stream_data_t *>(user_data);
427432

@@ -851,20 +856,22 @@ namespace pipewire {
851856
pipewire.frame_cv().notify_all();
852857
return status;
853858
case platf::capture_e::timeout:
859+
if (!push_captured_image_cb(std::move(img_out), false)) {
860+
BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> !push_captured_image_cb -> ok";
861+
std::this_thread::sleep_for(1ms); // Delay OK by 1 ms to avoid video stream freezing
862+
return platf::capture_e::ok;
863+
}
854864
if (!pull_free_image_cb(img_out)) {
855865
// Detect if shutdown is pending
856-
BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> interrupt nudge";
866+
BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> shutdown pending -> interrupt nudge";
857867
pipewire.frame_cv().notify_all();
858868
return platf::capture_e::interrupted;
859869
}
860-
if (!push_captured_image_cb(std::move(img_out), false)) {
861-
BOOST_LOG(debug) << "[pipewire] PipeWire: !push_captured_image_cb -> ok";
862-
return platf::capture_e::ok;
863-
}
864870
break;
865871
case platf::capture_e::ok:
866872
if (!push_captured_image_cb(std::move(img_out), true)) {
867-
BOOST_LOG(debug) << "[pipewire] PipeWire: !push_captured_image_cb -> ok";
873+
BOOST_LOG(debug) << "[pipewire] PipeWire: ok -> !push_captured_image_cb -> ok";
874+
std::this_thread::sleep_for(1ms); // Delay OK by 1 ms to avoid video stream freezing
868875
return platf::capture_e::ok;
869876
}
870877
break;

0 commit comments

Comments
 (0)