diff --git a/src/platform/linux/pipewire.cpp b/src/platform/linux/pipewire.cpp index 9d9a92c8552..ff25d3819a1 100644 --- a/src/platform/linux/pipewire.cpp +++ b/src/platform/linux/pipewire.cpp @@ -136,16 +136,12 @@ namespace pipewire { ~pipewire_t() { BOOST_LOG(debug) << "[pipewire] Destroying pipewire_t"sv; - if (loop) { - BOOST_LOG(debug) << "[pipewire] Stop PW thread loop"sv; - pw_thread_loop_stop(loop); - } try { cleanup_stream(); } catch (const std::exception &e) { - BOOST_LOG(error) << "[pipewire] Standard exception caught in ~pipewire_t: "sv << e.what(); + BOOST_LOG(error) << "[pipewire] Standard exception caught in ~pipewire_t cleanup_stream: "sv << e.what(); } catch (...) { - BOOST_LOG(error) << "[pipewire] Unknown exception caught in ~pipewire_t"sv; + BOOST_LOG(error) << "[pipewire] Unknown exception caught in ~pipewire_t cleanup_stream"sv; } pw_thread_loop_lock(loop); @@ -533,8 +529,13 @@ namespace pipewire { }; static void on_stream_state_changed(void *user_data, enum pw_stream_state old, enum pw_stream_state state, const char *err_msg) { - BOOST_LOG(debug) << "[pipewire] PipeWire stream state: " << pw_stream_state_as_string(old) - << " -> " << pw_stream_state_as_string(state); + if (err_msg != nullptr) { + BOOST_LOG(info) << "[pipewire] PipeWire stream error '" << err_msg << "' on state: " << pw_stream_state_as_string(old) + << " -> " << pw_stream_state_as_string(state); + } else { + BOOST_LOG(info) << "[pipewire] PipeWire stream state: " << pw_stream_state_as_string(old) + << " -> " << pw_stream_state_as_string(state); + } auto *d = static_cast(user_data); @@ -1003,18 +1004,18 @@ namespace pipewire { case platf::capture_e::timeout: if (!pull_free_image_cb(img_out)) { // Detect if shutdown is pending - BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> interrupt nudge"; + BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> shutdown pending -> interrupt nudge"; pipewire.frame_cv().notify_all(); return platf::capture_e::interrupted; } if (!push_captured_image_cb(std::move(img_out), false)) { - BOOST_LOG(debug) << "[pipewire] PipeWire: !push_captured_image_cb -> ok"; + BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> !push_captured_image_cb -> ok"; return platf::capture_e::ok; } break; case platf::capture_e::ok: if (!push_captured_image_cb(std::move(img_out), true)) { - BOOST_LOG(debug) << "[pipewire] PipeWire: !push_captured_image_cb -> ok"; + BOOST_LOG(debug) << "[pipewire] PipeWire: ok -> !push_captured_image_cb -> ok"; return platf::capture_e::ok; } break; diff --git a/src/thread_safe.h b/src/thread_safe.h index 692e3d243b4..de0fa9ecca6 100644 --- a/src/thread_safe.h +++ b/src/thread_safe.h @@ -49,6 +49,21 @@ namespace safe { _cv.notify_all(); } + /** + * @brief Try to remove and return the next queued item without any further wait + * + * @return Removed queue item, or empty result when the queue is stopped or empty. + */ + status_t try_pop() { + std::lock_guard lg {_lock}; + if (!_status) { + return util::false_v; + } + auto val = std::move(_status); + _status = util::false_v; + return val; + } + // pop and view should not be used interchangeably /** * @brief Remove and return the next queued item, waiting when requested. @@ -94,7 +109,7 @@ namespace safe { } auto val = std::move(_status); - _status.reset(); + _status = util::false_v; return val; } diff --git a/src/video.cpp b/src/video.cpp index ddf3c4fdad6..971e38308b1 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -1697,8 +1697,7 @@ namespace video { continue; } - while (capture_ctx->images->peek()) { - capture_ctx->images->pop(); + while (capture_ctx->images->try_pop()) { } ++capture_ctx;