style: add clang-format config and reformat scaffolding files
This commit is contained in:
@@ -7,19 +7,19 @@
|
||||
namespace sc {
|
||||
|
||||
struct SendCommand {
|
||||
std::string_view target = "monitor"; // monitor, window, region
|
||||
std::string_view peer_address; // optional
|
||||
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
|
||||
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[] );
|
||||
std::optional<Command> parse_cli(int argc, const char* argv[]);
|
||||
|
||||
} // namespace sc
|
||||
} // namespace sc
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#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"
|
||||
|
||||
@@ -30,11 +28,11 @@ struct ReceiverPipelineConfig {
|
||||
// Sender pipeline: capture → encode → packetize → RTP/UDP.
|
||||
class SenderPipeline {
|
||||
public:
|
||||
explicit SenderPipeline ( SenderPipelineConfig config );
|
||||
~SenderPipeline ();
|
||||
explicit SenderPipeline(SenderPipelineConfig config);
|
||||
~SenderPipeline();
|
||||
|
||||
bool start ();
|
||||
void stop ();
|
||||
bool start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
@@ -44,15 +42,15 @@ class SenderPipeline {
|
||||
// Receiver pipeline: RTP/UDP → depacketize → decode → render.
|
||||
class ReceiverPipeline {
|
||||
public:
|
||||
explicit ReceiverPipeline ( ReceiverPipelineConfig config );
|
||||
~ReceiverPipeline ();
|
||||
explicit ReceiverPipeline(ReceiverPipelineConfig config);
|
||||
~ReceiverPipeline();
|
||||
|
||||
bool start ();
|
||||
void stop ();
|
||||
bool start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace sc
|
||||
} // namespace sc
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -14,22 +15,22 @@ struct DiscoveredPeer {
|
||||
|
||||
class DiscoveryService {
|
||||
public:
|
||||
using PeerCallback = std::function<void ( const DiscoveredPeer & )>;
|
||||
using PeerCallback = std::function<void(const DiscoveredPeer&)>;
|
||||
|
||||
virtual ~DiscoveryService () = default;
|
||||
virtual ~DiscoveryService() = default;
|
||||
|
||||
// Announce this peer on the LAN.
|
||||
virtual bool announce ( const std::string &service_name, uint16_t signaling_port ) = 0;
|
||||
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 bool browse(PeerCallback on_peer) = 0;
|
||||
|
||||
virtual void stop () = 0;
|
||||
virtual void stop() = 0;
|
||||
};
|
||||
|
||||
class DiscoveryFactory {
|
||||
public:
|
||||
static std::unique_ptr<DiscoveryService> create_avahi ();
|
||||
static std::unique_ptr<DiscoveryService> create_avahi();
|
||||
};
|
||||
|
||||
} // namespace sc
|
||||
} // namespace sc
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
@@ -13,21 +14,21 @@ struct RtpHeader {
|
||||
bool extension = false;
|
||||
uint8_t csrc_count = 0;
|
||||
bool marker = false;
|
||||
uint7_t payload_type = 96; // dynamic
|
||||
uint8_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;
|
||||
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;
|
||||
std::vector<std::byte> serialize() const;
|
||||
static std::optional<RtpPacket> parse(std::span<const std::byte> in) noexcept;
|
||||
};
|
||||
|
||||
} // namespace sc
|
||||
} // namespace sc
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
#include "screencast/network/transport.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace sc {
|
||||
|
||||
@@ -28,20 +30,20 @@ using SignalingMessage = std::variant<SessionOffer, SessionAnswer>;
|
||||
|
||||
class SignalingChannel {
|
||||
public:
|
||||
using MessageCallback = std::function<void ( const SignalingMessage & )>;
|
||||
using MessageCallback = std::function<void(const SignalingMessage&)>;
|
||||
|
||||
virtual ~SignalingChannel () = default;
|
||||
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;
|
||||
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 );
|
||||
static std::unique_ptr<SignalingChannel> create_websocket_client();
|
||||
static std::unique_ptr<SignalingChannel> create_websocket_server(uint16_t port);
|
||||
};
|
||||
|
||||
} // namespace sc
|
||||
} // namespace sc
|
||||
|
||||
@@ -17,27 +17,27 @@ struct Endpoint {
|
||||
// UDP transport for RTP packets. Owned by the sender or receiver pipeline.
|
||||
class RtpTransport {
|
||||
public:
|
||||
using ReceiveCallback = std::function<void ( RtpPacket )>;
|
||||
using ReceiveCallback = std::function<void(RtpPacket)>;
|
||||
|
||||
virtual ~RtpTransport () = default;
|
||||
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;
|
||||
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;
|
||||
virtual bool send(const RtpPacket& packet) = 0;
|
||||
|
||||
// Set the peer endpoint dynamically (e.g. after signaling).
|
||||
virtual void set_peer ( const Endpoint &peer ) = 0;
|
||||
virtual void set_peer(const Endpoint& peer) = 0;
|
||||
|
||||
// Stop the transport and close sockets.
|
||||
virtual void stop () = 0;
|
||||
virtual void stop() = 0;
|
||||
};
|
||||
|
||||
class RtpTransportFactory {
|
||||
public:
|
||||
static std::unique_ptr<RtpTransport> create ();
|
||||
static std::unique_ptr<RtpTransport> create();
|
||||
};
|
||||
|
||||
} // namespace sc
|
||||
} // namespace sc
|
||||
|
||||
@@ -6,14 +6,14 @@ namespace sc {
|
||||
|
||||
// RTP clock rate for video is 90 kHz. Convert a monotonic nanosecond timestamp
|
||||
// into a 32-bit RTP timestamp. Overflows wrap around intentionally.
|
||||
constexpr uint32_t rtp_timestamp_from_ns ( uint64_t nanoseconds ) noexcept {
|
||||
constexpr uint32_t rtp_timestamp_from_ns(uint64_t nanoseconds) noexcept {
|
||||
// (nanoseconds * 90_000) / 1_000_000_000
|
||||
// Simplify: 90_000 / 1_000_000_000 = 9 / 100_000
|
||||
return static_cast<uint32_t> ( ( nanoseconds * 9ULL ) / 100'000ULL );
|
||||
return static_cast<uint32_t>((nanoseconds * 9ULL) / 100'000ULL);
|
||||
}
|
||||
|
||||
static_assert ( rtp_timestamp_from_ns ( 0 ) == 0 );
|
||||
static_assert ( rtp_timestamp_from_ns ( 1'000'000'000ULL ) == 90'000 );
|
||||
static_assert ( rtp_timestamp_from_ns ( 500'000'000ULL ) == 45'000 );
|
||||
static_assert(rtp_timestamp_from_ns(0) == 0);
|
||||
static_assert(rtp_timestamp_from_ns(1'000'000'000ULL) == 90'000);
|
||||
static_assert(rtp_timestamp_from_ns(500'000'000ULL) == 45'000);
|
||||
|
||||
} // namespace sc
|
||||
} // namespace sc
|
||||
|
||||
Reference in New Issue
Block a user