hang-c
C bindings for the hang Media over QUIC library.
Building
Build the Rust library and generate C headers
This will:
- Build the shared library (
libhang.dylibon macOS,libhang.soon Linux,hang.dllon Windows) - Generate the C header file at
target/include/hang.h - Generate the pkg-config file at
target/hang.pc
The library is built as a cdylib by default. To build as a static library, edit Cargo.toml and change:
= ["cdylib"]
to:
= ["staticlib"]
Using with CMake
Option 1: Build from source
add_subdirectory(path/to/hang-c)
target_link_libraries(your_target PRIVATE hang::hang)
Option 2: Use pre-built library
find_package(hang REQUIRED)
target_link_libraries(your_target PRIVATE hang::hang)
CMake Options
BUILD_RUST_LIB(default: ON) - Build the Rust library using cargoRUST_LIB_DIR- Directory containing pre-built library (whenBUILD_RUST_LIB=OFF)RUST_HEADER_DIR- Directory containing header files (whenBUILD_RUST_LIB=OFF)
Using with pkg-config
After installation, you can use pkg-config:
In your build system:
CFLAGS +=
LDFLAGS +=
API
The library exposes the following C functions (see hang.h for full details):
hang_start_from_c
void ;
Start the MoQ client and connect to a server.
Safety: The caller must ensure that c_server_url and c_path are valid null-terminated C strings.
hang_stop_from_c
void ;
Stop the MoQ client.
hang_write_video_packet_from_c
void ;
Write a video packet to the stream.
Safety: The caller must ensure that data points to a valid buffer of at least size bytes.
Example Usage
int
Installation
Using CMake
&&
This will install:
- Header file to
/usr/local/include/hang.h - Shared library to
/usr/local/lib/libhang.{dylib,so,dll} - CMake config files to
/usr/local/lib/cmake/hang/ - pkg-config file to
/usr/local/lib/pkgconfig/hang.pc(if installed manually)
Manual Installation
# Build the library
# Copy header
# Copy library
# Copy and configure pkg-config file
Build System Integration
Makefile
CC =
CFLAGS =
LDFLAGS =
:
Meson
hang_dep = dependency('hang')
executable('myapp', 'myapp.c', dependencies: hang_dep)
Notes
- The library uses a background thread for async operations
- All string parameters must be null-terminated C strings
- The library handles memory management internally - don't free pointers returned by the library
- Video packets are copied internally, so you can free your buffers after calling
hang_write_video_packet_from_c