#include "modules/desktop_capture/linux/wayland/shared_screencast_stream.h"
#include <fcntl.h>
#include <libdrm/drm_fourcc.h>
#include <pipewire/pipewire.h>
#include <spa/param/video/format-utils.h>
#include <vector>
#include "absl/memory/memory.h"
#include "modules/desktop_capture/linux/wayland/egl_dmabuf.h"
#include "modules/desktop_capture/linux/wayland/screencast_stream_utils.h"
#include "modules/portal/pipewire_utils.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/sanitizer.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/time_utils.h"
namespace webrtc {
const int kBytesPerPixel = …;
const int kVideoDamageRegionCount = …;
constexpr int kCursorBpp = …;
constexpr int CursorMetaSize(int w, int h) { … }
constexpr PipeWireVersion kDmaBufModifierMinVersion = …;
constexpr PipeWireVersion kDropSingleModifierMinVersion = …;
class SharedScreenCastStreamPrivate { … };
void SharedScreenCastStreamPrivate::OnCoreError(void* data,
uint32_t id,
int seq,
int res,
const char* message) { … }
void SharedScreenCastStreamPrivate::OnCoreInfo(void* data,
const pw_core_info* info) { … }
void SharedScreenCastStreamPrivate::OnCoreDone(void* data,
uint32_t id,
int seq) { … }
void SharedScreenCastStreamPrivate::OnStreamStateChanged(
void* data,
pw_stream_state old_state,
pw_stream_state state,
const char* error_message) { … }
void SharedScreenCastStreamPrivate::OnStreamParamChanged(
void* data,
uint32_t id,
const struct spa_pod* format) { … }
void SharedScreenCastStreamPrivate::OnStreamProcess(void* data) { … }
void SharedScreenCastStreamPrivate::OnRenegotiateFormat(void* data, uint64_t) { … }
SharedScreenCastStreamPrivate::SharedScreenCastStreamPrivate() { … }
SharedScreenCastStreamPrivate::~SharedScreenCastStreamPrivate() { … }
RTC_NO_SANITIZE("cfi-icall")
bool SharedScreenCastStreamPrivate::StartScreenCastStream(
uint32_t stream_node_id,
int fd,
uint32_t width,
uint32_t height,
bool is_cursor_embedded,
DesktopCapturer::Callback* callback) { … }
RTC_NO_SANITIZE("cfi-icall")
void SharedScreenCastStreamPrivate::UpdateScreenCastStreamResolution(
uint32_t width,
uint32_t height) { … }
RTC_NO_SANITIZE("cfi-icall")
void SharedScreenCastStreamPrivate::UpdateScreenCastStreamFrameRate(
uint32_t frame_rate) { … }
void SharedScreenCastStreamPrivate::StopScreenCastStream() { … }
void SharedScreenCastStreamPrivate::StopAndCleanupStream() { … }
std::unique_ptr<SharedDesktopFrame>
SharedScreenCastStreamPrivate::CaptureFrame() { … }
std::unique_ptr<MouseCursor> SharedScreenCastStreamPrivate::CaptureCursor() { … }
DesktopVector SharedScreenCastStreamPrivate::CaptureCursorPosition() { … }
void SharedScreenCastStreamPrivate::UpdateFrameUpdatedRegions(
const spa_buffer* spa_buffer,
DesktopFrame& frame) { … }
RTC_NO_SANITIZE("cfi-icall")
void SharedScreenCastStreamPrivate::ProcessBuffer(pw_buffer* buffer) { … }
RTC_NO_SANITIZE("cfi-icall")
bool SharedScreenCastStreamPrivate::ProcessMemFDBuffer(
pw_buffer* buffer,
DesktopFrame& frame,
const DesktopVector& offset) { … }
RTC_NO_SANITIZE("cfi-icall")
bool SharedScreenCastStreamPrivate::ProcessDMABuffer(
pw_buffer* buffer,
DesktopFrame& frame,
const DesktopVector& offset) { … }
void SharedScreenCastStreamPrivate::ConvertRGBxToBGRx(uint8_t* frame,
uint32_t size) { … }
SharedScreenCastStream::SharedScreenCastStream()
: … { … }
SharedScreenCastStream::~SharedScreenCastStream() { … }
rtc::scoped_refptr<SharedScreenCastStream>
SharedScreenCastStream::CreateDefault() { … }
bool SharedScreenCastStream::StartScreenCastStream(uint32_t stream_node_id) { … }
bool SharedScreenCastStream::StartScreenCastStream(
uint32_t stream_node_id,
int fd,
uint32_t width,
uint32_t height,
bool is_cursor_embedded,
DesktopCapturer::Callback* callback) { … }
void SharedScreenCastStream::UpdateScreenCastStreamResolution(uint32_t width,
uint32_t height) { … }
void SharedScreenCastStream::UpdateScreenCastStreamFrameRate(
uint32_t frame_rate) { … }
void SharedScreenCastStream::SetUseDamageRegion(bool use_damage_region) { … }
void SharedScreenCastStream::SetObserver(
SharedScreenCastStream::Observer* observer) { … }
void SharedScreenCastStream::StopScreenCastStream() { … }
std::unique_ptr<SharedDesktopFrame> SharedScreenCastStream::CaptureFrame() { … }
std::unique_ptr<MouseCursor> SharedScreenCastStream::CaptureCursor() { … }
absl::optional<DesktopVector> SharedScreenCastStream::CaptureCursorPosition() { … }
}