A lightweight, cross-platform WebRTC implementation in pure C.
- Pure C99 implementation - No C++ dependencies
- Cross-platform - Linux, macOS, Windows, FreeBSD
- Full protocol stack:
- ICE/STUN/TURN for connectivity
- DTLS for key exchange
- SRTP for media encryption
- SCTP for data channels
- SDP parsing and generation
- Platform abstraction layer for portability
- Minimal dependencies - Only standard C library
- Simple API design - Easy to integrate
libwebrtc/
├── include/ # Public API headers
│ ├── webrtc.h # Main API
│ ├── webrtc_platform.h # Platform abstraction
│ ├── webrtc_ice.h # ICE protocol
│ ├── webrtc_stun.h # STUN protocol
│ ├── webrtc_sdp.h # SDP parser
│ ├── webrtc_dtls.h # DTLS security
│ ├── webrtc_srtp.h # SRTP encryption
│ └── webrtc_sctp.h # SCTP transport
├── src/
│ ├── api/ # PeerConnection API
│ ├── platform/ # Platform implementations
│ ├── net/ # Network layer (STUN)
│ └── transport/ # Transport protocols (ICE/DTLS/SRTP/SCTP/SDP)
├── examples/ # Example applications
└── tests/ # Unit tests
See ARCHITECTURE.md for detailed design documentation.
# Using CMake
mkdir build && cd build
cmake ..
make
# Or using Make directly
makemkdir build && cd build
cmake -G "Visual Studio 16 2019" ..
cmake --build .#include "webrtc.h"
static void on_ice_candidate(webrtc_peer_connection_t *pc,
const webrtc_ice_candidate_t *candidate,
void *userdata) {
printf("ICE Candidate: %s\n", candidate->candidate);
}
static void on_data_channel(webrtc_peer_connection_t *pc,
webrtc_data_channel_t *channel,
void *userdata) {
printf("Data Channel Created\n");
}
int main(void) {
webrtc_init();
// Configure ICE servers
webrtc_config_t config = {0};
const char *ice_servers[] = {"stun:stun.l.google.com:19302"};
config.ice_servers = (char**)ice_servers;
config.ice_server_count = 1;
// Set up callbacks
webrtc_callbacks_t callbacks = {
.on_ice_candidate = on_ice_candidate,
.on_data_channel = on_data_channel
};
// Create peer connection
webrtc_peer_connection_t *pc = webrtc_create_peer_connection(
&config, &callbacks, NULL);
// Create data channel
webrtc_data_channel_t *channel = webrtc_create_data_channel(pc, "test");
// Create and set offer
webrtc_session_description_t *offer;
webrtc_create_offer(pc, &offer);
webrtc_set_local_description(pc, offer);
// Send data
const char *msg = "Hello WebRTC!";
webrtc_data_channel_send(channel, (const uint8_t*)msg, strlen(msg));
// Cleanup
webrtc_data_channel_close(channel);
webrtc_destroy_peer_connection(pc);
webrtc_cleanup();
return 0;
}./example_simple./example_datachannel./example_integrationwebrtc_init()- Initialize librarywebrtc_cleanup()- Cleanup resources
webrtc_create_peer_connection()- Create peer connectionwebrtc_destroy_peer_connection()- Destroy peer connectionwebrtc_create_offer()- Create SDP offerwebrtc_create_answer()- Create SDP answerwebrtc_set_local_description()- Set local SDPwebrtc_set_remote_description()- Set remote SDPwebrtc_add_ice_candidate()- Add ICE candidate
webrtc_create_data_channel()- Create data channelwebrtc_data_channel_send()- Send datawebrtc_data_channel_close()- Close channel
ice_agent_create()- Create ICE agentice_agent_gather_candidates()- Gather candidatesstun_send_request()- Send STUN binding request
sdp_parse()- Parse SDP stringsdp_generate()- Generate SDP stringsdp_add_media()- Add media section
dtls_context_create()- Create DTLS contextdtls_generate_fingerprint()- Generate fingerprintsrtp_protect()- Encrypt RTP packetsrtp_unprotect()- Decrypt SRTP packet
sctp_context_create()- Create SCTP contextsctp_send()- Send SCTP datasctp_receive()- Receive SCTP data
The library abstracts platform-specific functionality:
- Threads:
webrtc_thread_* - Mutexes:
webrtc_mutex_* - Sockets:
webrtc_socket_* - Time:
webrtc_time_ms(),webrtc_sleep_ms() - Memory:
webrtc_malloc(),webrtc_free()
| Protocol | Status | Description |
|---|---|---|
| ICE | ✅ Implemented | Interactive Connectivity Establishment |
| STUN | ✅ Implemented | Session Traversal Utilities for NAT |
| TURN | 🚧 Partial | Traversal Using Relays around NAT |
| DTLS | ✅ Implemented | Datagram Transport Layer Security |
| SRTP | ✅ Implemented | Secure Real-time Transport Protocol |
| SCTP | ✅ Implemented | Stream Control Transmission Protocol |
| SDP | ✅ Implemented | Session Description Protocol |
- Platform abstraction layer
- ICE/STUN implementation
- DTLS key exchange
- SRTP encryption
- SCTP data channels
- SDP parsing/generation
- Full TURN relay support
- OpenSSL/BoringSSL integration
- Media codec support (Opus, VP8, H.264)
- Bandwidth estimation
- Congestion control
MIT License - see LICENSE file for details.
Contributions welcome! Please:
- Follow the existing code style (C99)
- Add tests for new features
- Update documentation
- Submit pull requests