# webrtc-sdk/libwebrtc architecture

> Architecture diagram of the GitHub repository webrtc-sdk/libwebrtc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/webrtc-sdk/libwebrtc
- Repository: https://github.com/webrtc-sdk/libwebrtc

## Overview

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: [`src/rtc_peerconnection_impl.cc`](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/rtc_peerconnection_impl.cc) (peer connection), [`src`](https://github.com/webrtc-sdk/libwebrtc/tree/main/src) (src/ impls), [`src/win/msdkvideoencoderfactory.cc`](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/win/msdkvideoencoderfactory.cc) (windows media), [`BUILD.gn`](https://github.com/webrtc-sdk/libwebrtc/blob/main/BUILD.gn) (build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public_api["Public API"]
  node_include_api["include/<br/>public wrapper API"]
  node_include_base["base<br/>ABI primitives"]
end

subgraph group_implementation["Wrapper Impl"]
  node_src_wrappers["src/ impls<br/>wrapper adapters"]
  node_src_base["src/base<br/>portable helpers"]
  node_pc_factory["peer factory<br/>connection setup"]
  node_pc_core["peer connection<br/>session/control"]
  node_rtp_stack["RTP stack<br/>send/recv plumbing"]
  node_data_and_crypto["data & crypto<br/>data/secure channels"]
  node_upstream_webrtc[("webrtc-sdk/webrtc<br/>upstream core")]
end

subgraph group_media["Media Subsystems"]
  node_audio_api["audio<br/>[rtc_audio_track.h]"]
  node_video_api["video<br/>[rtc_video_track.h]"]
  node_desktop_capture["desktop capture<br/>screen-sharing path"]
  node_custom_audio["custom audio<br/>audio transport bridge"]
end

subgraph group_platform["Platform Backends"]
  node_win_media["windows media<br/>accelerated backend"]
  node_win_msdk[("Media SDK<br/>third-party binaries<br/>[libmfx.lib]")]
end

subgraph group_delivery["Build & Delivery"]
  node_build_system["build<br/>gn/ninja integration<br/>[BUILD.gn]"]
  node_packaging["packaging<br/>conan/ci<br/>[conanfile.py]"]
  node_example_app["loopback demo<br/>example app<br/>[main.cc]"]
  node_tests["tests<br/>validation"]
end

node_include_api -->|"declares"| node_src_wrappers
node_include_base -->|"supports"| node_src_base
node_src_wrappers -->|"adapts"| node_upstream_webrtc
node_src_base -.->|"stabilizes"| node_upstream_webrtc
node_pc_factory -->|"creates"| node_pc_core
node_pc_core -->|"routes media"| node_rtp_stack
node_pc_core -->|"routes data"| node_data_and_crypto
node_audio_api -->|"bridges"| node_custom_audio
node_audio_api -->|"feeds"| node_upstream_webrtc
node_video_api -->|"feeds"| node_upstream_webrtc
node_desktop_capture -->|"supplies"| node_video_api
node_desktop_capture -->|"captures"| node_upstream_webrtc
node_win_media -->|"uses"| node_win_msdk
node_win_media -->|"extends"| node_upstream_webrtc
node_build_system -->|"builds"| node_src_wrappers
node_build_system -->|"builds"| node_win_media
node_packaging -->|"packages"| node_build_system
node_example_app -->|"uses"| node_include_api
node_example_app -.->|"exercises"| node_src_wrappers
node_tests -->|"verifies"| node_include_api
node_tests -.->|"covers"| node_pc_core

click node_include_api "https://github.com/webrtc-sdk/libwebrtc/tree/main/include"
click node_include_base "https://github.com/webrtc-sdk/libwebrtc/tree/main/include/base"
click node_src_wrappers "https://github.com/webrtc-sdk/libwebrtc/tree/main/src"
click node_src_base "https://github.com/webrtc-sdk/libwebrtc/tree/main/src/base"
click node_pc_factory "https://github.com/webrtc-sdk/libwebrtc/blob/main/src/rtc_peerconnection_factory_impl.cc"
click node_pc_core "https://github.com/webrtc-sdk/libwebrtc/blob/main/src/rtc_peerconnection_impl.cc"
click node_rtp_stack "https://github.com/webrtc-sdk/libwebrtc/blob/main/src/rtc_rtp_sender_impl.cc"
click node_data_and_crypto "https://github.com/webrtc-sdk/libwebrtc/blob/main/src/rtc_data_channel_impl.cc"
click node_audio_api "https://github.com/webrtc-sdk/libwebrtc/blob/main/include/rtc_audio_track.h"
click node_video_api "https://github.com/webrtc-sdk/libwebrtc/blob/main/include/rtc_video_track.h"
click node_desktop_capture "https://github.com/webrtc-sdk/libwebrtc/blob/main/src/internal/desktop_capturer.cc"
click node_custom_audio "https://github.com/webrtc-sdk/libwebrtc/blob/main/src/internal/custom_audio_transport_impl.cc"
click node_win_media "https://github.com/webrtc-sdk/libwebrtc/blob/main/src/win/msdkvideoencoderfactory.cc"
click node_win_msdk "https://github.com/webrtc-sdk/libwebrtc/blob/main/src/win/lib/x64/libmfx.lib"
click node_build_system "https://github.com/webrtc-sdk/libwebrtc/blob/main/BUILD.gn"
click node_packaging "https://github.com/webrtc-sdk/libwebrtc/blob/main/conanfile.py"
click node_example_app "https://github.com/webrtc-sdk/libwebrtc/blob/main/examples/wx_loop_back_demo/main.cc"
click node_tests "https://github.com/webrtc-sdk/libwebrtc/blob/main/test/peerconnection.test.cc"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_include_api,node_include_base toneBlue
class node_src_wrappers,node_src_base,node_pc_factory,node_pc_core,node_rtp_stack,node_data_and_crypto,node_upstream_webrtc toneAmber
class node_audio_api,node_video_api,node_desktop_capture,node_custom_audio toneMint
class node_win_media,node_win_msdk toneRose
class node_build_system,node_packaging,node_example_app,node_tests toneIndigo
```

## Components

### Public API

Stable wrapper headers used by downstream consumers.

- [include/](https://github.com/webrtc-sdk/libwebrtc/tree/main/include): public wrapper API · Main stable surface for peer connections, media, transports, crypto, logging, and supporting types. · `include`
- [base](https://github.com/webrtc-sdk/libwebrtc/tree/main/include/base): ABI primitives · Portable ref-counting and function-wrapper utilities used to keep the ABI and ownership model stable. · `include/base`

### Wrapper Impl

Adapters that map wrapper types to upstream WebRTC objects.

- [src/ impls](https://github.com/webrtc-sdk/libwebrtc/tree/main/src): wrapper adapters · Implementation layer that converts public wrapper objects into native WebRTC objects and manages lifetimes. · `src`
- [src/base](https://github.com/webrtc-sdk/libwebrtc/tree/main/src/base): portable helpers · Source-side portability helpers supporting the wrapper ABI and runtime behavior. · `src/base`
- [peer factory](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/rtc_peerconnection_factory_impl.cc): connection setup · Peer connection factory and peer connection implementation boundary. · `src/rtc_peerconnection_factory_impl.cc`
- [peer connection](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/rtc_peerconnection_impl.cc): session/control · Peer connection, session description, ICE candidate, and media constraints plumbing. · `src/rtc_peerconnection_impl.cc`
- [RTP stack](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/rtc_rtp_sender_impl.cc): send/recv plumbing · RTP sender, receiver, transceiver, capabilities, and parameter wrappers. · `src/rtc_rtp_sender_impl.cc`
- [data & crypto](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/rtc_data_channel_impl.cc): data/secure channels · Data channels plus frame and packet cryptors, DTLS, and DTMF sender wrappers. · `src/rtc_data_channel_impl.cc`
- **webrtc-sdk/webrtc**: upstream core · Checked-out upstream WebRTC source tree that the wrapper layer adapts and packages.

### Media Subsystems

Audio, video, and desktop capture paths.

- [audio](https://github.com/webrtc-sdk/libwebrtc/blob/main/include/rtc_audio_track.h): audio wrappers · Audio device, source, track, processing, and frame interfaces plus their adapters. · `include/rtc_audio_track.h`
- [video](https://github.com/webrtc-sdk/libwebrtc/blob/main/include/rtc_video_track.h): video wrappers · Video device, source, track, frame, renderer, and sink adapter interfaces plus their adapters. · `include/rtc_video_track.h`
- [desktop capture](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/internal/desktop_capturer.cc): screen-sharing path · Desktop capturer, device, and media list wrappers with internal capture logic. · `src/internal/desktop_capturer.cc`
- [custom audio](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/internal/custom_audio_transport_impl.cc): audio transport bridge · 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](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/win/msdkvideoencoderfactory.cc): accelerated backend · Windows-specific encoder/decoder factories, capability probing, allocators, and media utilities. · `src/win/msdkvideoencoderfactory.cc`
- [Media SDK](https://github.com/webrtc-sdk/libwebrtc/blob/main/src/win/lib/x64/libmfx.lib): third-party binaries · 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](https://github.com/webrtc-sdk/libwebrtc/blob/main/BUILD.gn): gn/ninja integration · Repository build scripts and GN integration for Windows, Linux, Android, and Apple. · `BUILD.gn`
- [packaging](https://github.com/webrtc-sdk/libwebrtc/blob/main/conanfile.py): conan/ci · Conan recipes, test package, and GitHub Actions workflow for distributing and validating artifacts. · `conanfile.py`
- [loopback demo](https://github.com/webrtc-sdk/libwebrtc/blob/main/examples/wx_loop_back_demo/main.cc): example app · End-to-end wx loopback example that exercises public API, wrapper impls, and media paths. · `examples/wx_loop_back_demo/main.cc`
- [tests](https://github.com/webrtc-sdk/libwebrtc/blob/main/test/peerconnection.test.cc): validation · Wrapper-level tests that validate the public API and connection behavior. · `test/peerconnection.test.cc`

## Connections

- 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.
