Skip to content

Commit db9699b

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. Pipewire state change logging is also move to information log level to improve initial issue analysis without enabling debug logging
1 parent fa4fbbd commit db9699b

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/platform/linux/pipewire.cpp

Lines changed: 12 additions & 5 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

@@ -853,18 +858,20 @@ namespace pipewire {
853858
case platf::capture_e::timeout:
854859
if (!pull_free_image_cb(img_out)) {
855860
// Detect if shutdown is pending
856-
BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> interrupt nudge";
861+
BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> shutdown pending -> interrupt nudge";
857862
pipewire.frame_cv().notify_all();
858863
return platf::capture_e::interrupted;
859864
}
860865
if (!push_captured_image_cb(std::move(img_out), false)) {
861-
BOOST_LOG(debug) << "[pipewire] PipeWire: !push_captured_image_cb -> ok";
866+
BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> !push_captured_image_cb -> ok";
867+
std::this_thread::sleep_for(100us); // Workaround: delay OK by 100us to avoid video stream freezing
862868
return platf::capture_e::ok;
863869
}
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(100us); // Workaround: delay OK by 100us to avoid video stream freezing
868875
return platf::capture_e::ok;
869876
}
870877
break;

0 commit comments

Comments
 (0)