How taojhlwkl/zlmediakit works
Project type and purpose
• ZLMediaKit is a cross-platform, high-performance C++11-based media streaming framework. It acts both as
• A server (RTSP/RTMP/HLS/HTTP-FLV/WebSocket-FLV) supporting protocol conversion and media distribution
• An SDK/C API library for embedding into applications (Android, iOS, Linux, Windows, macOS)
• It provides:
• Core media modules (codec, RTP/RTMP/RTSP/HLS pipelines, HTTP/WebSocket I/O, recording, playback, pushing)
• A C API wrapper (under api/) to expose functionality to other languages
• Example server app (under server/) and Android demo (under Android/)
Directory-level architecture
• 3rdpart/
• ZLToolKit – asynchronous network IO, event loop, thread pool
• jsoncpp – JSON parser for config and API
• src/ – core C++ modules arranged by feature area:
• Codec (AAC/H264/H265)
• Common utilities (config, media source/sink, parser, time stamping)
• Http (client, server, WebSocket)
• Player, Pusher, Record, Rtmp, Rtp, Rtsp, Shell interfaces
• Extension – protocol adapters, frame factories
• api/ – C wrapper: include/ (headers), source/ (implementation), tests/
• server/ – sample MediaServer executable using core modules
• Android/ – Android Studio project demonstrating JNI bindings to native library
• cmake/, build scripts, Dockerfiles – build and deployment support
• conf/ – configuration file templates
Key architectural patterns
• Modular pipeline: each protocol (RTSP, RTMP, HLS, HTTP-FLV, WebSocket-FLV) is implemented as a session/sessionMuxer layer that plugs into the event loop
• Asynchronous network IO with epoll (or equivalent) + thread-pool model provided by ZLToolKit
• Separation of concerns:
• Core media logic (decoding, encoding, muxing, demuxing)
• Network transport (TCP/UDP/HTTP/WebSocket)
• API boundary (C API wrappers, JNI for Android)
• Plugin-like extension points for new codecs, protocols, or transports
Main components and interactions
• ZLToolKit (Network & Event Loop)
• Provides: TCP/UDP servers, client connectors, epoll, thread pool
• Depended on by all session modules
• Core Media Modules
• Codec (H264/H265/AAC)
• Parser, Muxer, Demuxer, Recorder, Recorder Imp
• MediaSource/MediaSink abstractions
• Protocol Sessions
• RTSPSession, RTMPSession, HttpSession, WebSocketSession
• RTP/RTMP/RTSP muxers and demuxers
• HLS file server and segmenter
• C API Layer (api/)
• Wraps core modules into C-callable functions
• Used by external applications or bindings
• Sample Server App (server/)
• Instantiates TcpServer on configured ports
• Registers session classes (RtspSession, RtmpSession, HttpSession, HttpsSession)
• Android Demo (Android/)
• JNI layer (ZLMediaKit.java) calls into C API library compiled for multiple ABIs
• Presents UI and calls native-lib.cpp to start player/pusher