30538fba73
Two quality improvements: Preset: ultrafast -> veryfast. Unlocks Main profile with CABAC entropy coding, hexagonal motion search, 3 reference frames, and adaptive quantization — typically 30-40% better quality at the same bitrate. The desktop handles the extra encoding cost trivially (150+ fps at 1080p). Downscaling: the receiver now advertises its display resolution in the signaling answer (display_width/display_height, 0 = unknown). When the capture exceeds the display (e.g. 2256x1504 source on a 1920x1080 receiver), the sender scales down preserving aspect ratio before encoding — the same sws_scale pass that already converts the pixel format also handles the resolution change, so there is no extra step. This concentrates the entire bitrate into pixels the display actually shows (~2.7x more bits per visible pixel at 4000 kbps when going from 2256x1504 to 1620x1080). The renderer caches the display size during window creation (native monitor resolution in fullscreen/KMSDRM; window size otherwise). The receiver includes it in every signaling answer; the sender pipeline computes aspect-preserving, even-rounded scaled dimensions when the display is smaller than the capture. meson test 5/5 in both configurations, valgrind clean.
74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include "screencast/capture/capture.h"
|
|
#include "screencast/codec/decoder.h"
|
|
#include "screencast/codec/encoder.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;
|
|
// 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};
|
|
// Session identity from signaling; written to the sender state file for
|
|
// status widgets (waybar) and one-click restarts.
|
|
std::string session_id;
|
|
// The receiver's display resolution (0 = unknown). The sender downscales
|
|
// to this before encoding so bitrate is not spent on pixels the display
|
|
// cannot show.
|
|
int max_encode_width = 0;
|
|
int max_encode_height = 0;
|
|
};
|
|
|
|
struct ReceiverPipelineConfig {
|
|
DecoderConfig decoder;
|
|
Endpoint local_rtp_endpoint;
|
|
std::optional<Endpoint> peer_signaling;
|
|
RendererConfig renderer;
|
|
// TCP port the signaling server listens on (offers arrive here).
|
|
std::uint16_t signaling_port = 5005;
|
|
};
|
|
|
|
// Sender pipeline: capture → encode → packetize → RTP/UDP.
|
|
class SenderPipeline {
|
|
public:
|
|
explicit SenderPipeline(SenderPipelineConfig config);
|
|
~SenderPipeline();
|
|
|
|
bool start();
|
|
void stop();
|
|
|
|
// Ask the sender to encode its next frame as a keyframe. Thread-safe;
|
|
// used by the PLI feedback path.
|
|
void request_keyframe();
|
|
|
|
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
|