How cisco/openh264 works
1. What this repository is
OpenH264 is a native H.264 codec stack centered on two major runtime products: an encoder and a decoder. The codebase also ships a processing/analysis library, CLI console tools, platform demo apps, a browser/plugin module, and a fairly large test and automation harness.
2. Top-level runtime architecture
The core data flow is split in two directions:
- Encode path: raw YUV 4:2:0 planar frames enter the encoder, are optionally preprocessed, then compressed into an Annex B H.264 byte stream.
- Decode path: H.264 Annex B bitstreams enter the decoder, are parsed and reconstructed into YUV 4:2:0 planar output.
The encoder and decoder are separate subsystems with their own core logic, plus a smaller shared foundation beneath them.
3. Public API boundary
The stable external interface lives in codec/api/wels/ (codec_api.h, codec_app_def.h, codec_def.h, codec_ver.h). Everything under codec/encoder, codec/decoder, codec/common, and codec/processing is implementation detail behind that API boundary. This is the main seam an integrator uses to embed the library into an application.
4. Encoder subsystem
codec/encoder/ contains the main compression pipeline: mode decision, motion estimation, rate control, slice/NAL packaging, reference management, parameter-set handling, and multi-threaded slice encoding. It supports features like temporal scalability, simulcast, LTR, dynamic bitrate/framerate changes, and arbitrary resolutions. The plus/ layer adds export/DLL-facing wrappers on top of the core encoder.
5. Decoder subsystem
codec/decoder/ performs Annex B parsing, CABAC/CAVLC entropy decoding, reference picture management, error concealment, deblocking, and frame reconstruction. The plus/ layer mirrors the encoder side with a decoder extension/export boundary. The decoder is single-threaded across slices according to the README, but still has its own internal threading abstractions for decoding work coordination.
6. Processing subsystem
codec/processing/ is a separate library of video pre/post-processing utilities used mainly by the encoder. It includes adaptive quantization, background detection, complexity analysis, denoise, downsample, image rotation, scene-change detection, scroll detection, and VAA calculation. Architecturally, this sits between raw frame ingestion and encoding decisions, influencing compression quality/efficiency rather than producing the bitstream directly.
7. Shared foundation
codec/common/ provides cross-cutting primitives used by all codec components: threading, task queues, locks, memory alignment, CPU feature detection, trace/logging, utility code, and architecture-specific optimized primitives. This layer is also where most of the platform and CPU dispatch happens, with separate implementations for x86, ARM/NEON, AArch64, MIPS, and LoongArch, plus C/C++ fallbacks.
8. Platform-specific optimized code
Performance-critical inner loops are heavily split by architecture:
- x86 assembly in codec/common/x86, codec/encoder/core/x86, codec/decoder/core/x86, codec/processing/src/x86
- ARM/NEON and AArch64/NEON in the corresponding arm and arm64 folders
- MIPS and LoongArch optimized sources where supported
This means the architecture is not just “library + app”; it is a portable core with pluggable CPU-specialized implementations selected at build/runtime.
9. Console applications
codec/console/ contains command-line frontends for encoder and decoder use cases. These are thin application wrappers around the library, intended for local testing, benchmarks, and sample usage rather than as the main product. They show how the public API is consumed from a standalone native executable.
10. Plugin/module integration
module/ contains gmp-openh264.cpp and supporting task utilities, indicating a browser/plugin packaging boundary (GMP-style module integration). This is a separate deployment form of the same codec engine, adapted to a host/plugin runtime rather than a normal executable or static/dynamic library.
11. Test architecture
test/ is organized by subsystem:
- test/api for API-level encoder/decoder behavior
- test/encoder, test/decoder, test/processing, test/common for unit coverage of internal modules
- test/encoder_binary_comparison for bitstream/regression comparisons against SHA1 tables
There are also platform-specific test app wrappers under test/build/ for Android, iOS, Windows, and Windows Phone, showing the project verifies both library behavior and platform packaging.
12. Automation, fixtures, and regression assets
autotest/ holds performance and unit test scripts across Android and iOS, while res/ stores the H.264 bitstreams and YUV inputs used by tests and demos. This repository is therefore not just source code: it includes golden media fixtures and scripted cross-platform validation flows as first-class assets.
13. Build and packaging boundaries
The project supports multiple build systems and targets:
- Make-based builds via build/
- Meson definitions throughout codec/*/meson.build and test/*/meson.build
- Gradle/Android NDK builds
- Xcode projects for iOS
- Visual Studio / Windows Phone project files
Build scripts also generate version metadata and export definitions, so packaging is an explicit part of the architecture rather than an afterthought.
14. How to read the overall diagram
An accurate architecture diagram should show:
- Applications/tests on the outside
- Public API boundary
- Encoder/decoder/processing as separate runtime libraries
- Common utilities and CPU-specific optimized code underneath
- Platform-specific wrappers, demos, and plugin/module integrations around the core
- Media fixtures and automation scripts feeding regression and performance validation
Main entry points: encoder/core Encoder core · wels Public API · decoder/core Decoder core · build Build system
Components 18
Runtime libraries
Core codec subsystems and shared foundation
- Public API · External embedding boundary for encoder and decoder clients.
codec/api/wels - Encoder core · Main H.264 encoding path: analysis, mode decision, motion estimation, rate control, slice/NAL packaging, and threading.
codec/encoder/core - Encoder plus · DLL-facing and extension layer above the encoder core.
codec/encoder/plus - Decoder core · Annex B parsing, entropy decoding, reference management, concealment, deblocking, and frame reconstruction.
codec/decoder/core - Decoder plus · Decoder extension and export boundary above the decoder core.
codec/decoder/plus - Processing lib · Adaptive quantization, denoise, downsample, rotation, scene/scroll detection, and VAA calculations that influence encoding decisions.
codec/processing - Common foundation · Threading, queues, locks, memory alignment, CPU detection, tracing, and shared utilities.
codec/common - CPU kernels · Performance-critical implementations split across x86, ARM/NEON, AArch64, MIPS, and LoongArch.
codec/common/x86
Integration surfaces
Console apps, plugin module, and platform demo wrappers
- Console apps · Standalone encoder and decoder command-line wrappers for testing and sample usage.
codec/console - Plugin module · Browser/plugin packaging boundary for the codec engine.
module - Platform demos · Android, iOS, Windows, and Windows Phone demo and wrapper projects around the codec stack.
codec/build
Validation assets
Tests, automation, and media fixtures
- API tests · Encoder/decoder behavior tests focused on the stable external interface.
test/api - Unit tests · Subsystem tests for encoder, decoder, processing, and common modules.
test - Binary regression · SHA1-based bitstream comparison harness and golden-case scripts.
test/encoder_binary_comparison - Automation · Cross-platform scripted runs for performance and unit validation.
autotest - Media fixtures · Reference H.264 bitstreams and YUV inputs used by tests and demos.
res
Build and packaging
Build systems and platform project files
- Build system · Make, Meson, Gradle, NDK, Xcode, and Visual Studio build definitions plus version/package metadata.
build - Docs · Doxygen and usage documentation for the public encoder and decoder interfaces.
docs/doxygen
Connections 28
- Public API → Encoder core: embeds · Consumers instantiate and drive the encoder through the stable API.
- Public API → Decoder core: embeds · Consumers instantiate and drive the decoder through the stable API.
- Encoder plus → Encoder core: wraps · Extension/export layer forwards into the encoding engine.
- Decoder plus → Decoder core: wraps · Extension/export layer forwards into the decoding engine.
- Encoder core → Processing lib: uses · Encoding consults preprocessing and analysis utilities before compression.
- Encoder core → Common foundation: depends on · Encoder shares threading, memory, logging, and utilities.
- Decoder core → Common foundation: depends on · Decoder shares threading, memory, logging, and utilities.
- Processing lib → Common foundation: depends on · Processing primitives reuse shared infrastructure.
- Common foundation → CPU kernels: dispatches to · Shared code selects architecture-specific implementations at build/runtime.
- Encoder core → CPU kernels: specializes · Encoder inner loops use CPU-tuned kernels where available.
- Decoder core → CPU kernels: specializes · Decoder inner loops use CPU-tuned kernels where available.
- Processing lib → CPU kernels: specializes · Processing filters and metrics use CPU-tuned kernels where available.
- Console apps → Public API: calls · CLI tools are thin consumers of the public codec API.
- Plugin module → Public API: calls · Plugin packaging integrates the same public codec API into host runtimes.
- Platform demos → Public API: calls · Platform sample apps exercise the library through its public interface.
- API tests → Public API: verifies · API tests validate expected external behavior.
- Unit tests → Encoder core: verifies · Encoder-focused unit coverage targets core internal modules.
- Unit tests → Decoder core: verifies · Decoder-focused unit coverage targets core internal modules.
- Unit tests → Processing lib: verifies · Processing tests exercise the analysis and filter subsystem.
- Unit tests → Common foundation: verifies · Common tests cover shared threading and utility code.
- Binary regression → Media fixtures: compares against · Golden media and SHA1 tables provide regression baselines.
- Automation → Media fixtures: feeds · Scripts run against stored media assets for performance and regression.
- Build system → Encoder core: builds · Build definitions assemble the encoder runtime.
- Build system → Decoder core: builds · Build definitions assemble the decoder runtime.
- Build system → Processing lib: builds · Build definitions assemble the processing library.
- Build system → Console apps: builds · Build definitions assemble the CLI frontends.
- Build system → Platform demos: packages · Platform project files package demos and wrappers.
- Docs → Public API: documents · Documentation centers on the stable API surface.