How webrtc-sdk/libwebrtc works
1. This repository is a C++ wrapper layer around upstream WebRTC, intended to be built into platform-specific shared libraries like libwebrtc-*.dll / libwebrtc-*.so. The repo is not the WebRTC core itself; it adds a stable API, packaging, and platform integrations around a checked-out webrtc-sdk/webrtc source tree.
2. The public architecture boundary is the include/ directory. It exposes wrapper interfaces for core WebRTC concepts: peer connections, media streams/tracks, RTP senders/receivers/transceivers, ICE/DTLS, data channels, audio/video sources and devices, desktop capture, frame and packet cryptors, logging, and supporting types. This is the API that downstream consumers use instead of directly binding to upstream WebRTC internals.
3. The implementation boundary lives in src/. Most files are *_impl.cc/.h adapters that translate the public wrapper types into upstream WebRTC objects and lifecycle management. This is where object ownership, conversion between wrapper types and native WebRTC types, and API normalization happen.
4. A small base/utility layer under include/base/ and src/base/ provides portability and ownership primitives such as ref-counting helpers and fixed-size function wrappers. This layer exists to keep the wrapper ABI and memory model consistent across platforms and compilers.
5. Media handling is split into separate subsystems for audio and video. Audio wrappers cover devices, frames, processing, sources, tracks, and audio transport integration. Video wrappers cover frames, sources, tracks, devices, renderers, and sink adapters. The wrapper layer acts as the bridge between app-level media producers/consumers and WebRTC’s native media pipeline.
6. Desktop capture is its own subsystem, with public desktop-capture/device/media-list APIs and internal capture logic under src/internal/desktop_capturer.* plus wrapper implementations. This suggests the library supports screen-sharing and device enumeration as a first-class path rather than treating it as an app-specific add-on.
7. There is a custom internal audio transport path in src/internal/custom_audio_transport_impl.*, and the README calls out patches like custom_audio_source_m144.patch. That indicates the repo depends on specific upstream WebRTC versions and occasionally patches WebRTC internals to support custom audio source behavior required by downstream consumers.
8. Windows has a substantial platform-specific media backend under src/win/. It includes Media SDK / D3D allocators, codecs, encoder/decoder factories, capability probing, and utility code. This layer is the main hardware-accelerated media boundary on Windows and is separate from the cross-platform wrapper code.
9. The Windows subtree also vendors Intel Media SDK headers and libraries under src/win/include/ and src/win/lib/. That means the Windows build is not purely source-level integration; it carries third-party binary dependencies for encoding/decoding paths, which materially affects packaging and deployability.
10. Build and integration are GN/Ninja-centered, with repository-specific scripts for Windows, Linux, Android, and Apple under build/. The README shows that this repo is meant to be added as a GN target inside a larger WebRTC checkout, and CI is managed via GitHub Actions plus Conan packaging for consumers who want prebuilt artifacts or test packages.
11. The repository contains two validation surfaces: test/ for wrapper-level tests, and examples/wx_loop_back_demo/ for a concrete end-to-end loopback app. The example is useful architecturally because it exercises the full flow from public API → wrapper implementation → WebRTC media/connection stack → local rendering/capture, showing how consumers are expected to assemble the library.
12. Overall data flow is: application code calls the public wrapper API in include/, wrapper implementations in src/ map those calls into native WebRTC objects, media/data then flows through WebRTC peer connection and media pipelines, and platform-specific backends such as Windows capture/encode/decode provide optimized device access where needed. The main architectural boundary is therefore “portable C++ wrapper API” versus “upstream WebRTC + platform-specific backend integrations.”
Main entry points: rtc_peerconnection_impl.cc peer connection · src src/ impls · msdkvideoencoderfactory.cc windows media · BUILD.gn build
Components 19
Public API
Stable wrapper headers used by downstream consumers.
Wrapper Impl
Adapters that map wrapper types to upstream WebRTC objects.
- src/ impls · Implementation layer that converts public wrapper objects into native WebRTC objects and manages lifetimes.
src - src/base · Source-side portability helpers supporting the wrapper ABI and runtime behavior.
src/base - peer factory · Peer connection factory and peer connection implementation boundary.
src/rtc_peerconnection_factory_impl.cc - peer connection · Peer connection, session description, ICE candidate, and media constraints plumbing.
src/rtc_peerconnection_impl.cc - RTP stack · RTP sender, receiver, transceiver, capabilities, and parameter wrappers.
src/rtc_rtp_sender_impl.cc - data & crypto · Data channels plus frame and packet cryptors, DTLS, and DTMF sender wrappers.
src/rtc_data_channel_impl.cc - webrtc-sdk/webrtc · Checked-out upstream WebRTC source tree that the wrapper layer adapts and packages.
Media Subsystems
Audio, video, and desktop capture paths.
- audio · Audio device, source, track, processing, and frame interfaces plus their adapters.
include/rtc_audio_track.h - video · Video device, source, track, frame, renderer, and sink adapter interfaces plus their adapters.
include/rtc_video_track.h - desktop capture · Desktop capturer, device, and media list wrappers with internal capture logic.
src/internal/desktop_capturer.cc - custom audio · Internal custom audio transport path used to support patched upstream audio source behavior.
src/internal/custom_audio_transport_impl.cc
Platform Backends
Windows-specific accelerated media integration.
- windows media · Windows-specific encoder/decoder factories, capability probing, allocators, and media utilities.
src/win/msdkvideoencoderfactory.cc - Media SDK · Bundled Intel Media SDK headers and libraries used by the Windows media backend.
src/win/lib/x64/libmfx.lib
Build & Delivery
Build scripts, packaging, CI, and examples.
- build · Repository build scripts and GN integration for Windows, Linux, Android, and Apple.
BUILD.gn - packaging · Conan recipes, test package, and GitHub Actions workflow for distributing and validating artifacts.
conanfile.py - loopback demo · End-to-end wx loopback example that exercises public API, wrapper impls, and media paths.
examples/wx_loop_back_demo/main.cc - tests · Wrapper-level tests that validate the public API and connection behavior.
test/peerconnection.test.cc
Connections 21
- include/ → src/ impls: declares · Public interfaces are implemented by wrapper adapters.
- base → src/base: supports · Shared ABI and ownership primitives are mirrored by source-side helpers.
- src/ impls → webrtc-sdk/webrtc: adapts · Most implementation files translate wrapper calls into native WebRTC objects.
- src/base → webrtc-sdk/webrtc: stabilizes · Portable helpers support a consistent wrapper/runtime model over upstream code.
- peer factory → peer connection: creates · Factory constructs and configures peer connections.
- peer connection → RTP stack: routes media · Peer connections expose RTP sender/receiver/transceiver plumbing.
- peer connection → data & crypto: routes data · Peer connections also expose data channel and transport security paths.
- audio → custom audio: bridges · Audio wrappers connect to custom transport behavior when required.
- audio → webrtc-sdk/webrtc: feeds · Audio sources, tracks, and processing adapt into native WebRTC audio pipeline objects.
- video → webrtc-sdk/webrtc: feeds · Video sources, tracks, frames, and sink adapters connect into native WebRTC video objects.
- desktop capture → video: supplies · Desktop capture is exposed as a first-class source path for video consumers.
- desktop capture → webrtc-sdk/webrtc: captures · Internal capturer logic integrates with upstream capture and media plumbing.
- windows media → Media SDK: uses · Windows acceleration backend depends on bundled Media SDK binaries.
- windows media → webrtc-sdk/webrtc: extends · Windows backend plugs hardware encode/decode and capability probing into WebRTC media paths.
- build → src/ impls: builds · GN/Ninja scripts compile the wrapper implementation targets.
- build → windows media: builds · Platform build scripts include the Windows backend.
- packaging → build: packages · Conan and CI consume the build outputs for distribution.
- loopback demo → include/: uses · The demo application consumes the public wrapper headers.
- loopback demo → src/ impls: exercises · The demo drives the full wrapper-to-native flow end to end.
- tests → include/: verifies · Tests validate the public wrapper behavior.
- tests → peer connection: covers · Connection tests exercise peer connection setup and lifecycle.