diff --git a/modules/desktop_capture/linux/wayland/screencast_portal.cc b/modules/desktop_capture/linux/wayland/screencast_portal.cc index 3d28d42ba6..a473802176 100644 --- a/modules/desktop_capture/linux/wayland/screencast_portal.cc +++ b/modules/desktop_capture/linux/wayland/screencast_portal.cc @@ -80,9 +80,9 @@ void ScreenCastPortal::Stop() { proxy_ = nullptr; restore_token_ = ""; - if (pw_fd_ != -1) { + if (pw_fd_ != kInvalidPipeWireFd) { close(pw_fd_); - pw_fd_ = -1; + pw_fd_ = kInvalidPipeWireFd; } } @@ -456,7 +456,7 @@ void ScreenCastPortal::OnOpenPipeWireRemoteRequested(GDBusProxy* proxy, that->pw_fd_ = g_unix_fd_list_get(outlist.get(), index, error.receive()); - if (that->pw_fd_ == -1) { + if (that->pw_fd_ == kInvalidPipeWireFd) { RTC_LOG(LS_ERROR) << "Failed to get file descriptor from the list: " << error->message; that->OnPortalDone(RequestResponse::kError); diff --git a/modules/desktop_capture/linux/wayland/screencast_portal.h b/modules/desktop_capture/linux/wayland/screencast_portal.h index 3d59ce4ca0..2bf7800921 100644 --- a/modules/desktop_capture/linux/wayland/screencast_portal.h +++ b/modules/desktop_capture/linux/wayland/screencast_portal.h @@ -17,6 +17,7 @@ #include "modules/desktop_capture/desktop_capture_types.h" #include "modules/desktop_capture/linux/wayland/screen_capture_portal_interface.h" +#include "modules/portal/pipewire_utils.h" #include "modules/portal/portal_request_response.h" #include "modules/portal/xdg_desktop_portal_utils.h" #include "modules/portal/xdg_session_details.h" @@ -137,7 +138,7 @@ class RTC_EXPORT ScreenCastPortal // A PipeWire stream ID of stream we will be connecting to uint32_t pw_stream_node_id_ = 0; // A file descriptor of PipeWire socket - int pw_fd_ = -1; + int pw_fd_ = kInvalidPipeWireFd; // Restore token that can be used to restore previous session std::string restore_token_; diff --git a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc index 17c895088a..5b4e23c32d 100644 --- a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc +++ b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc @@ -448,7 +448,7 @@ bool SharedScreenCastStreamPrivate::StartScreenCastStream( { PipeWireThreadLoopLock thread_loop_lock(pw_main_loop_); - if (fd >= 0) { + if (fd != kInvalidPipeWireFd) { pw_core_ = pw_context_connect_fd( pw_context_, fcntl(fd, F_DUPFD_CLOEXEC, 0), nullptr, 0); } else { @@ -978,7 +978,7 @@ SharedScreenCastStream::CreateDefault() { } bool SharedScreenCastStream::StartScreenCastStream(uint32_t stream_node_id) { - return private_->StartScreenCastStream(stream_node_id, -1); + return private_->StartScreenCastStream(stream_node_id, kInvalidPipeWireFd); } bool SharedScreenCastStream::StartScreenCastStream( diff --git a/modules/desktop_capture/linux/wayland/test/test_screencast_stream_provider.cc b/modules/desktop_capture/linux/wayland/test/test_screencast_stream_provider.cc index ffba137753..ee5c17e7d7 100644 --- a/modules/desktop_capture/linux/wayland/test/test_screencast_stream_provider.cc +++ b/modules/desktop_capture/linux/wayland/test/test_screencast_stream_provider.cc @@ -312,7 +312,7 @@ void TestScreenCastStreamProvider::OnStreamAddBuffer(void* data, spa_data->type = SPA_DATA_MemFd; spa_data->fd = memfd_create("pipewire-test-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING); - if (spa_data->fd == -1) { + if (spa_data->fd == kInvalidPipeWireFd) { RTC_LOG(LS_ERROR) << "PipeWire test: Can't create memfd"; return; } diff --git a/modules/portal/pipewire_utils.h b/modules/portal/pipewire_utils.h index 0f5ccf3292..8344a8cefb 100644 --- a/modules/portal/pipewire_utils.h +++ b/modules/portal/pipewire_utils.h @@ -15,6 +15,8 @@ struct pw_thread_loop; namespace webrtc { +constexpr int kInvalidPipeWireFd = -1; + // Prepare PipeWire so that it is ready to be used. If it needs to be dlopen'd // this will do so. Note that this does not guarantee a PipeWire server is // running nor does it establish a connection to one. diff --git a/modules/video_capture/linux/camera_portal.cc b/modules/video_capture/linux/camera_portal.cc index d217dc7251..85b9f20228 100644 --- a/modules/video_capture/linux/camera_portal.cc +++ b/modules/video_capture/linux/camera_portal.cc @@ -13,6 +13,7 @@ #include #include +#include "modules/portal/pipewire_utils.h" #include "modules/portal/xdg_desktop_portal_utils.h" namespace webrtc { @@ -31,7 +32,8 @@ class CameraPortalPrivate { void Start(); private: - void OnPortalDone(xdg_portal::RequestResponse result, int fd = -1); + void OnPortalDone(xdg_portal::RequestResponse result, + int fd = kInvalidPipeWireFd); static void OnProxyRequested(GObject* object, GAsyncResult* result, @@ -216,7 +218,7 @@ void CameraPortalPrivate::OnOpenResponse(GDBusProxy* proxy, int fd = g_unix_fd_list_get(outlist.get(), index, error.receive()); - if (fd == -1) { + if (fd == kInvalidPipeWireFd) { RTC_LOG(LS_ERROR) << "Failed to get file descriptor from the list: " << error->message; that->OnPortalDone(RequestResponse::kError); diff --git a/modules/video_capture/linux/pipewire_session.cc b/modules/video_capture/linux/pipewire_session.cc index f628bfc8d5..2adb1cdb50 100644 --- a/modules/video_capture/linux/pipewire_session.cc +++ b/modules/video_capture/linux/pipewire_session.cc @@ -17,7 +17,6 @@ #include #include "common_video/libyuv/include/webrtc_libyuv.h" -#include "modules/portal/pipewire_utils.h" #include "modules/video_capture/device_info_impl.h" #include "rtc_base/logging.h" #include "rtc_base/string_encode.h" @@ -235,7 +234,7 @@ PipeWireSession::~PipeWireSession() { void PipeWireSession::Init(VideoCaptureOptions::Callback* callback, int fd) { callback_ = callback; - if (fd != -1) { + if (fd != kInvalidPipeWireFd) { InitPipeWire(fd); } else { portal_notifier_ = std::make_unique(this); diff --git a/modules/video_capture/linux/pipewire_session.h b/modules/video_capture/linux/pipewire_session.h index 54555edb1d..982b468838 100644 --- a/modules/video_capture/linux/pipewire_session.h +++ b/modules/video_capture/linux/pipewire_session.h @@ -20,6 +20,7 @@ #include "api/ref_counted_base.h" #include "api/scoped_refptr.h" +#include "modules/portal/pipewire_utils.h" #include "modules/video_capture/linux/camera_portal.h" #include "modules/video_capture/video_capture.h" #include "modules/video_capture/video_capture_options.h" @@ -83,7 +84,8 @@ class PipeWireSession : public rtc::RefCountedNonVirtual { PipeWireSession(); ~PipeWireSession(); - void Init(VideoCaptureOptions::Callback* callback, int fd = -1); + void Init(VideoCaptureOptions::Callback* callback, + int fd = kInvalidPipeWireFd); const std::deque& nodes() const { return nodes_; } diff --git a/modules/video_capture/video_capture_options.h b/modules/video_capture/video_capture_options.h index c90e035f37..6f72f7927e 100644 --- a/modules/video_capture/video_capture_options.h +++ b/modules/video_capture/video_capture_options.h @@ -13,6 +13,10 @@ #include "api/scoped_refptr.h" #include "rtc_base/system/rtc_export.h" +#if defined(WEBRTC_USE_PIPEWIRE) +#include "modules/portal/pipewire_utils.h" +#endif + namespace webrtc { #if defined(WEBRTC_USE_PIPEWIRE) @@ -69,7 +73,7 @@ class RTC_EXPORT VideoCaptureOptions { #endif #if defined(WEBRTC_USE_PIPEWIRE) bool allow_pipewire_ = false; - int pipewire_fd_ = -1; + int pipewire_fd_ = kInvalidPipeWireFd; rtc::scoped_refptr pipewire_session_; #endif };