How kmansoft/srtc works
Main Components
• Peer Connection Module: Central component that handles the SDP offer/answer exchange, state management, and overall connection lifecycle.
• Media Packetization: Separate modules dealing with packetizing H264 video, Opus audio, and simulcast (e.g., “packetizer.cpp”, “packetizer_h264.cpp”, “packetizer_opus.cpp”).
• ICE/STUN Negotiation: Modules in the “stun” folder and the ICE agent (files like “ice_agent.cpp” and “stun/stun*.c/h”) that manage NAT traversal and connectivity checks.
• SRTP/SRTCP and Security: Components responsible for authentication and encryption (files like “srtp_connection.cpp”, “srtp_crypto.cpp”, “srtp_openssl.cpp”, “srtp_hmac_sha1.cpp”).
• SDP Encoding/Decoding: Components that prepare and interpret SDP offers and answers (sdp_offer.cpp, sdp_answer.cpp).
• Utility and Error Management: Helper modules for logging, buffering, random generation, and error handling (e.g., “logging.cpp”, “byte_buffer.cpp”, “error.cpp”, “random_generator.cpp”).
Relationships and Interactions
• Data Flow: Illustrate the flow from the application layer to the Peer Connection, which then triggers the underlying ICE/STUN procedures, negotiates DTLS, and subsequently establishes the SRTP connection.
• Packet Handling: Show how encoded media samples provided by the application are passed to the packetizer modules which then prepare them for transmission over the established connection.
• Control & Error Flow: Indicate that the Peer Connection monitors connectivity through periodic STUN probes and error logging, triggering re-connection attempts as needed.
• SDP Role: Mark a distinct section where the SDP offer/answer mechanism integrates with external HTTP libraries (as mentioned in the README) to communicate with a WHIP server.
• Simulcast Support: Indicate a branch where additional layers and codec-specific configurations are managed (e.g., “packetizer_h264.cpp” and related codec-specific methods).
Architectural Patterns and Design Principles
• Modularity: Each core function (networking, security, media processing) is encapsulated into separate modules and source files.
• Separation of Concerns: The design keeps media encoding out of scope while taking care of packetization, ensuring that each component does one task (e.g., ICE negotiation is separate from packetization).
• Lightweight Threading: Emphasize that a single worker thread is used per PeerConnection, which is critical for scaling to hundreds or thousands of sessions.
• Cross-Cutting Utilities: Utility modules (like logging and error handling) support and are integrated with multiple other components.
Relevant Technologies and Frameworks
• C++ 17 (or C++ 14 with minor modification) – conservative and portable code.
• OpenSSL/BoringSSL – for cryptographic operations in DTLS/SRTP.
• Networking protocols – ICE, STUN, DTLS, and SRTP, represented by dedicated modules.