ce52f64e52
Implement the xdg-desktop-portal ScreenCast backend via libportal: a
blocking portal handshake (interactive source picker), a PipeWire stream
on the portal's node enumerating BGRx/BGRA/RGBx/RGBA, and a latest-frame
slot handing frames to next_frame(). stop() is thread-safe; teardown
follows the order PipeWire requires. All proxy operations run under the
thread-loop lock to satisfy the protocol extension context checks
('impl_ext_end_proxy called from wrong context' otherwise).
The encoder now accepts padded strides for packed RGB inputs (real
PipeWire row pitches) and maps the new PixelFormat::Bgrx to
AV_PIX_FMT_BGRA.
Add tools/capture_smoke: a manual smoke tool (interactive, not in
meson test) that captures N frames, encodes them, and writes a
self-contained Annex-B elementary stream with prepended SPS/PPS.
Validated manually on Wayland/Hyprland: 2256x1504 H.264 elementary
stream, ffprobe clean. Phase 3 marked complete in docs/PHASES.md.
62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "screencast/capture/error.h"
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
namespace sc {
|
|
|
|
enum class PixelFormat {
|
|
Rgba,
|
|
Bgrx, // 4 bytes/pixel, memory order B, G, R, unused
|
|
Yuv420p,
|
|
};
|
|
|
|
// Opaque resource owned by the capture implementation.
|
|
struct CapturedFrame {
|
|
int width = 0;
|
|
int height = 0;
|
|
uint64_t timestamp_ns = 0; // capture clock, monotonic
|
|
PixelFormat pixel_format = PixelFormat::Rgba;
|
|
int stride = 0; // bytes per row for the first plane; 0 means packed
|
|
std::vector<std::byte> pixels;
|
|
};
|
|
|
|
// Capture target: whole monitor, specific window, or a region.
|
|
struct CaptureTargetWholeScreen {};
|
|
struct CaptureTargetWindow {
|
|
std::string window_id;
|
|
};
|
|
struct CaptureTargetRegion {
|
|
int x = 0;
|
|
int y = 0;
|
|
int width = 0;
|
|
int height = 0;
|
|
};
|
|
|
|
using CaptureTarget = std::variant<CaptureTargetWholeScreen, CaptureTargetWindow, CaptureTargetRegion>;
|
|
|
|
class CaptureSession {
|
|
public:
|
|
virtual ~CaptureSession() = default;
|
|
|
|
// Blocking call to acquire one frame. Returns std::nullopt on graceful stop.
|
|
virtual std::optional<CapturedFrame> next_frame() = 0;
|
|
|
|
// Request the session to stop. May be called from another thread.
|
|
virtual void stop() = 0;
|
|
};
|
|
|
|
// Factory for the PipeWire / xdg-desktop-portal capture backend.
|
|
class CaptureFactory {
|
|
public:
|
|
static CaptureResult<std::unique_ptr<CaptureSession>> create(CaptureTarget target);
|
|
};
|
|
|
|
} // namespace sc
|