Scaffold C++20 screencast project with Meson, agent workflow, and phase plan

This commit is contained in:
2026-08-28 21:54:32 +02:00
commit 742611b841
25 changed files with 1322 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include <optional>
#include <string_view>
#include <variant>
namespace sc {
struct SendCommand {
std::string_view target = "monitor"; // monitor, window, region
std::string_view peer_address; // optional
int bitrate_kbps = 4000;
};
struct ReceiveCommand {
std::string_view peer_address; // optional
int local_rtp_port = 5004;
};
using Command = std::variant<SendCommand, ReceiveCommand>;
// Parse command line arguments. Prints usage and returns std::nullopt on error.
std::optional<Command> parse_cli ( int argc, const char *argv[] );
} // namespace sc
+58
View File
@@ -0,0 +1,58 @@
#pragma once
#include "screencast/capture/capture.h"
#include "screencast/codec/decoder.h"
#include "screencast/codec/encoder.h"
#include "screencast/network/discovery.h"
#include "screencast/network/signaling.h"
#include "screencast/network/transport.h"
#include "screencast/render/renderer.h"
#include <memory>
#include <optional>
namespace sc {
struct SenderPipelineConfig {
CaptureTarget capture_target;
EncoderConfig encoder;
Endpoint local_rtp_endpoint;
std::optional<Endpoint> signaling_server;
};
struct ReceiverPipelineConfig {
DecoderConfig decoder;
Endpoint local_rtp_endpoint;
std::optional<Endpoint> peer_signaling;
RendererConfig renderer;
};
// Sender pipeline: capture → encode → packetize → RTP/UDP.
class SenderPipeline {
public:
explicit SenderPipeline ( SenderPipelineConfig config );
~SenderPipeline ();
bool start ();
void stop ();
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
// Receiver pipeline: RTP/UDP → depacketize → decode → render.
class ReceiverPipeline {
public:
explicit ReceiverPipeline ( ReceiverPipelineConfig config );
~ReceiverPipeline ();
bool start ();
void stop ();
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace sc
+56
View File
@@ -0,0 +1,56 @@
#pragma once
#include <cstdint>
#include <memory>
#include <optional>
#include <span>
#include <string_view>
#include <variant>
#include <vector>
namespace sc {
// Opaque resource owned by the capture implementation.
struct CapturedFrame {
int width = 0;
int height = 0;
uint64_t timestamp_ns = 0; // capture clock, monotonic
std::vector<std::byte> pixels;
// TODO: pixel format, stride, FD handle for dmabuf
};
// Capture target: whole monitor, specific window, or a region.
struct CaptureTargetWholeScreen {};
struct CaptureTargetWindow {
std::string_view 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 std::unique_ptr<CaptureSession> create(CaptureTarget target);
};
} // namespace sc
+39
View File
@@ -0,0 +1,39 @@
#pragma once
#include "screencast/codec/encoder.h"
#include <cstdint>
#include <memory>
#include <optional>
#include <span>
#include <vector>
namespace sc {
struct DecodedFrame {
int width = 0;
int height = 0;
uint64_t capture_timestamp_ns = 0;
std::vector<std::byte> rgba_pixels;
};
struct DecoderConfig {
std::string_view codec_name = "h264";
int width = 0;
int height = 0;
};
class Decoder {
public:
virtual ~Decoder () = default;
// Feed one encoded frame. Returns decoded frames when available.
virtual std::vector<DecodedFrame> decode ( const EncodedFrame &frame ) = 0;
};
class DecoderFactory {
public:
static std::unique_ptr<Decoder> create ( const DecoderConfig &config );
};
} // namespace sc
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include "screencast/capture/capture.h"
#include <cstdint>
#include <memory>
#include <span>
#include <string_view>
#include <vector>
namespace sc {
struct EncodedFrame {
uint64_t capture_timestamp_ns = 0;
uint32_t rtp_timestamp = 0;
bool is_keyframe = false;
std::vector<std::byte> data; // Annex-B or AVCC depending on config
};
struct EncoderConfig {
std::string_view codec_name = "h264";
int width = 0;
int height = 0;
int frame_rate_num = 30;
int frame_rate_den = 1;
int bitrate_kbps = 4000;
bool hardware_accel = false;
};
class Encoder {
public:
virtual ~Encoder () = default;
// Encode one captured frame. Returns empty if the encoder emits no packet
// for this frame.
virtual std::vector<EncodedFrame> encode ( const CapturedFrame &frame ) = 0;
// Force the next output to be a keyframe.
virtual void request_keyframe () = 0;
};
class EncoderFactory {
public:
static std::unique_ptr<Encoder> create ( const EncoderConfig &config );
};
} // namespace sc
+35
View File
@@ -0,0 +1,35 @@
#pragma once
#include <functional>
#include <memory>
#include <string>
namespace sc {
struct DiscoveredPeer {
std::string service_name;
std::string host;
uint16_t signaling_port = 0;
};
class DiscoveryService {
public:
using PeerCallback = std::function<void ( const DiscoveredPeer & )>;
virtual ~DiscoveryService () = default;
// Announce this peer on the LAN.
virtual bool announce ( const std::string &service_name, uint16_t signaling_port ) = 0;
// Browse for peers; callback is invoked for each newly found service.
virtual bool browse ( PeerCallback on_peer ) = 0;
virtual void stop () = 0;
};
class DiscoveryFactory {
public:
static std::unique_ptr<DiscoveryService> create_avahi ();
};
} // namespace sc
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <cstdint>
#include <span>
#include <vector>
namespace sc {
// Minimal RTP header (RFC 3550) without extensions.
struct RtpHeader {
uint8_t version = 2;
bool padding = false;
bool extension = false;
uint8_t csrc_count = 0;
bool marker = false;
uint7_t payload_type = 96; // dynamic
uint16_t sequence_number = 0;
uint32_t timestamp = 0;
uint32_t ssrc = 0;
bool serialize ( std::span<std::byte, 12> out ) const noexcept;
static std::optional<RtpHeader> parse ( std::span<const std::byte, 12> in ) noexcept;
};
struct RtpPacket {
RtpHeader header;
std::vector<std::byte> payload;
std::vector<std::byte> serialize () const;
static std::optional<RtpPacket> parse ( std::span<const std::byte> in ) noexcept;
};
} // namespace sc
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include "screencast/network/transport.h"
#include <functional>
#include <memory>
#include <string>
namespace sc {
// JSON-based control messages exchanged before or during a session.
struct SessionOffer {
std::string session_id;
std::string codec_name;
int width = 0;
int height = 0;
int frame_rate_num = 30;
int frame_rate_den = 1;
Endpoint rtp_endpoint;
};
struct SessionAnswer {
std::string session_id;
Endpoint rtp_endpoint;
};
using SignalingMessage = std::variant<SessionOffer, SessionAnswer>;
class SignalingChannel {
public:
using MessageCallback = std::function<void ( const SignalingMessage & )>;
virtual ~SignalingChannel () = default;
virtual bool connect ( const Endpoint &server ) = 0;
virtual void send ( const SignalingMessage &message ) = 0;
virtual void on_message ( MessageCallback callback ) = 0;
virtual void disconnect () = 0;
};
class SignalingFactory {
public:
static std::unique_ptr<SignalingChannel> create_websocket_client ();
static std::unique_ptr<SignalingChannel> create_websocket_server ( uint16_t port );
};
} // namespace sc
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include "screencast/network/rtp_packet.h"
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
namespace sc {
struct Endpoint {
std::string address;
uint16_t port = 0;
};
// UDP transport for RTP packets. Owned by the sender or receiver pipeline.
class RtpTransport {
public:
using ReceiveCallback = std::function<void ( RtpPacket )>;
virtual ~RtpTransport () = default;
// Bind locally and start the receive loop. Callback is invoked on the
// transport's thread.
virtual bool start ( const Endpoint &local_endpoint, ReceiveCallback on_receive ) = 0;
// Send a packet to the configured peer.
virtual bool send ( const RtpPacket &packet ) = 0;
// Set the peer endpoint dynamically (e.g. after signaling).
virtual void set_peer ( const Endpoint &peer ) = 0;
// Stop the transport and close sockets.
virtual void stop () = 0;
};
class RtpTransportFactory {
public:
static std::unique_ptr<RtpTransport> create ();
};
} // namespace sc
+37
View File
@@ -0,0 +1,37 @@
#pragma once
#include "screencast/codec/decoder.h"
#include <cstdint>
#include <memory>
#include <optional>
#include <string_view>
namespace sc {
struct RendererConfig {
std::string_view window_title = "screencast receiver";
int initial_width = 1280;
int initial_height = 720;
};
class Renderer {
public:
virtual ~Renderer () = default;
// Present one decoded frame. Returns false if the window was closed.
virtual bool present ( const DecodedFrame &frame ) = 0;
// Pump events (window close, resize). Non-blocking.
virtual bool poll_events () = 0;
// Destroy the window and release GPU resources.
virtual void shutdown () = 0;
};
class RendererFactory {
public:
static std::unique_ptr<Renderer> create ( const RendererConfig &config );
};
} // namespace sc