libmoq provides C bindings for the moq-lite library, enabling integration with C and C++ applications.
Overview
libmoq exposes a C API for:- Creating and managing MoQ sessions
- Publishing broadcasts and tracks
- Writing media frames
- Connecting to relays
Installation
Build from Source
- Static library:
target/release/libmoq.a(Unix) ortarget/release/moq.lib(Windows) - C header:
target/include/moq.h - pkg-config file:
target/moq.pc
Using CMake
libmoq includes aCMakeLists.txt for easy integration:
Using pkg-config
C API
The C API provides a simplified interface to moq-lite functionality.Initialize Logging
Create a Session
Connect to a MoQ relay:Create a Broadcast
Publish a broadcast:Create a Track
Add a track to a broadcast:Write Frames
Publish media frames:Cleanup
Close tracks, broadcasts, and sessions:Complete Example
API Reference
All functions are defined inmoq.h:
Logging
Session
Broadcast
Track
Return Values
All functions return:- ≥ 0: Success (ID or status code)
- < 0: Error code
Thread Safety
libmoq uses an internal Tokio runtime. All functions are thread-safe and can be called from multiple threads.Memory Management
libmoq manages memory internally:- No need to free returned IDs
- Input buffers are copied
- Call close functions to release resources
Building Static Library
The library is built as a static archive:Cargo.toml
- Linux:
-lpthread -ldl -lm - macOS:
-framework Security -framework Foundation - Windows:
ws2_32.lib userenv.lib
C++ Integration
Useextern "C" in C++ code:
Limitations
- Publish only: libmoq currently supports publishing, not subscribing
- Simplified API: Some advanced moq-lite features are not exposed
- Blocking: Some operations may block the calling thread
Resources
- Source Code - GitHub repository
- Header File - API definitions
- CMakeLists.txt - CMake integration
- moq-lite - Underlying Rust library
Next Steps
moq-lite
Learn about the full Rust API
hang
Media-specific functionality
moq-relay
Deploy a relay server
Getting Started
Build with Rust SDK