feat(app): implement Phase 5 local UDP sender->receiver loopback
Wire the first end-to-end pipeline: capture -> encode -> packetize -> UDP -> depacketize -> decode -> render. - UdpRtpTransport: raw POSIX UDP sockets (IPv4 via getaddrinfo), a receive jthread woken by socket close on stop; port 0 skips binding so the sender uses an OS-assigned source port. ASIO stays deferred to the signaling phase per ARCHITECTURE.md. - SdlRenderer: SDL3 window/renderer with RGBA texture upload; the texture is recreated on resolution change. RendererFactory now returns RendererResult so SDL init failures carry a message, mirroring the codec/capture error patterns. - screencast binary: parse_cli plus SenderPipeline/ReceiverPipeline per the app scaffolds; the sender creates its encoder once capture reports real dimensions, the receiver keeps a bounded 3-frame queue to hold latency down and renders on its own thread until the window closes. cli argv signature fixed to 'const char* const*' so main's argv converts implicitly. - Encoder: drop AV_CODEC_FLAG_GLOBAL_HEADER so libx264 repeats SPS/PPS in-band at each keyframe -- the receiver decodes from the bitstream alone, which also makes mid-stream joins and later PLI recovery work without out-of-band parameter negotiation. The round-trip test now exercises exactly that path. - tests: new udp-loopback integration test pushes synthetic frames through a real localhost socket and decodes 10/10 frames with the right dimensions; valgrind clean (loopback + codec). meson test 4/4. Manual validation on the desktop (receiver window shows the captured desktop) is documented in docs/RUNBOOK.md.
This commit is contained in:
@@ -20,6 +20,8 @@ struct ReceiveCommand {
|
||||
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[]);
|
||||
// `argv` is `char const* const*` so both `main`'s `char**` and const arrays
|
||||
// convert implicitly.
|
||||
std::optional<Command> parse_cli(int argc, const char* const argv[]);
|
||||
|
||||
} // namespace sc
|
||||
|
||||
@@ -16,6 +16,9 @@ struct SenderPipelineConfig {
|
||||
EncoderConfig encoder;
|
||||
Endpoint local_rtp_endpoint;
|
||||
std::optional<Endpoint> signaling_server;
|
||||
// Where encoded RTP packets are sent. Defaults to the local loopback so
|
||||
// a sender and receiver on one machine work without any configuration.
|
||||
Endpoint peer_rtp_endpoint{"127.0.0.1", 5004};
|
||||
};
|
||||
|
||||
struct ReceiverPipelineConfig {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace sc {
|
||||
|
||||
struct RendererError {
|
||||
std::string message;
|
||||
};
|
||||
|
||||
// C++20 does not provide std::expected. Use a variant-based result type so
|
||||
// fallible renderer operations do not rely on exceptions.
|
||||
template <typename T> using RendererResult = std::variant<T, RendererError>;
|
||||
|
||||
template <typename T> constexpr bool is_renderer_error(const RendererResult<T>& result) noexcept {
|
||||
return std::holds_alternative<RendererError>(result);
|
||||
}
|
||||
|
||||
template <typename T> T& renderer_value(RendererResult<T>& result) {
|
||||
return std::get<T>(result);
|
||||
}
|
||||
|
||||
template <typename T> const T& renderer_value(const RendererResult<T>& result) {
|
||||
return std::get<T>(result);
|
||||
}
|
||||
|
||||
template <typename T> RendererError& renderer_error(RendererResult<T>& result) {
|
||||
return std::get<RendererError>(result);
|
||||
}
|
||||
|
||||
template <typename T> const RendererError& renderer_error(const RendererResult<T>& result) {
|
||||
return std::get<RendererError>(result);
|
||||
}
|
||||
|
||||
} // namespace sc
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "screencast/codec/decoder.h"
|
||||
#include "screencast/render/error.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -29,7 +30,7 @@ class Renderer {
|
||||
|
||||
class RendererFactory {
|
||||
public:
|
||||
static std::unique_ptr<Renderer> create(const RendererConfig& config);
|
||||
static RendererResult<std::unique_ptr<Renderer>> create(const RendererConfig& config);
|
||||
};
|
||||
|
||||
} // namespace sc
|
||||
|
||||
Reference in New Issue
Block a user