Files
screen_cast/include/screencast/network/signaling.h
T
fegger 943596da6d feat(app): add PLI feedback, jitter reordering, and hardware decode
Loss recovery for the streaming path:

- PLI over signaling: the depacketizer now reports damaged frames
  (DepacketizeResult) and the receiver asks the sender for a keyframe
  (SessionPli, rate-limited to one per 500 ms). The sender keeps the
  signaling channel open during the session and honors PLIs through
  the new thread-safe SenderPipeline::request_keyframe(). Recovery
  takes one frame time instead of waiting out the GOP.
- RtpJitterBuffer: reorders RTP packets by sequence number (16 packets
  / 60 ms) before the in-order depacketizer, so Wi-Fi reordering is
  not misread as loss; in-order streams release immediately, and a
  straggler older than the delivered sequence is discarded.
- Hardware H.264 decode probe: DecoderFactory tries h264_v4l2m2m (the
  VideoCore path on the Pi) with an automatic software fallback and a
  clear journal line for the chosen path; --swdecode opts out.

Validated: PLI end-to-end with a probe that drops a mid-keyframe
packet over real UDP (receiver logged the damaged frame and the PLI
arrived with the session id); hardware probe fails cleanly and falls
back on this desktop; jitter reordering covered by unit tests.
meson test 5/5 in both build configurations, valgrind clean.
2026-09-08 16:54:09 +02:00

65 lines
2.0 KiB
C++

#pragma once
#include "screencast/network/error.h"
#include "screencast/network/transport.h"
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <variant>
namespace sc {
// JSON-based control messages exchanged before or during a session. The wire
// format is one JSON object per newline-terminated TCP line; a WebSocket
// transport can replace TCP in a later phase without changing these types.
struct SessionOffer {
std::string session_id;
std::string codec_name;
int width = 0; // informational; the stream carries its own SPS/PPS
int height = 0;
int frame_rate_num = 30;
int frame_rate_den = 1;
Endpoint rtp_endpoint; // unused by the receiver; kept for symmetry
};
struct SessionAnswer {
std::string session_id;
// The address may be empty: the sender then targets the address of its
// signaling connection and the port carried here.
Endpoint rtp_endpoint;
};
// Picture Loss Indication: the receiver asks the sender for a keyframe
// after discarding a damaged frame.
struct SessionPli {
std::string session_id;
};
using SignalingMessage = std::variant<SessionOffer, SessionAnswer, SessionPli>;
class SignalingChannel {
public:
using MessageCallback = std::function<void(const SignalingMessage&)>;
virtual ~SignalingChannel() = default;
// Client channels connect to a receiver's signaling server.
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:
// A client channel that connects to a receiver's signaling server.
static NetworkResult<std::unique_ptr<SignalingChannel>> create_client();
// A server channel listening on the given port; it keeps the most
// recent connection as its active peer.
static NetworkResult<std::unique_ptr<SignalingChannel>> create_server(uint16_t port);
};
} // namespace sc