How 2swap/swaptube works
Main Architectural Layers
a. Build System (CMake + Scripts)
b. Entry Point / CLI
c. Core Rendering Engine
d. External Dependencies & Services
e. Input Media & Output Artifacts
Break Out the Key Components
• Build System
– CMakeLists.txt & cmake/Find*.cmake
– go.sh / play.sh / record_audios.py
• Entry Point
– misc/Main.cpp (invoked by go.sh)
– Argument parser (project name, resolution, smoke-test flag)
• Core Engine
– Project Loader (src/Projects/*.cpp)
– Time Control
• Macroblock Manager
• Microblock Manager
– Scene Manager (src/Scenes/Scene.cpp + scene subclasses)
– State Manager (StateManager.cpp)
– DataObjects (src/DataObjects/**)
– Render Engine
• CPU modules (misc/Convolution.cpp, ColorScheme.cpp, etc.)
• GPU modules (src/CUDA/*.cu)
• I/O Subsystem
– VideoWriter (wrapping FFmpeg APIs)
– AudioWriter (PCM buffers)
– SubtitleWriter, SFX, DebugPlot (gnuplot), PathManager
– Media folder (input PNG, MP4, generated LaTeX)
– Out folder (output MP4, WAV, subtitle files, gnuplots)
• External Dependencies
– FFmpeg (libav* for encode/decode)
– CUDA
– GLM / Eigen (math)
– MicroTeX → SVG
– RSVG + GLib → rasterize SVG
– Cairo → final pixel surfaces
– gnuplot → debug plots
Relationships & Data Flows
1. Build Flow:
go.sh → CMake → compile all src/ into binary (in build/)
2. Runtime Initialization:
go.sh invokes binary → Main parses args → Project Loader instantiates a Scene
3. Rendering Loop:
For each Macroblock:
• Stage Macroblock (audio file / silence / generated)
• For each Microblock:
– Scene.render_microblock()
– StateManager updates numeric state
– DataObjects supply non-numeric data
– RenderEngine (CPU or CUDA) produces a frame buffer
– I/O: VideoWriter .pushFrame(buffer)
End
• AudioWriter writes audio samples per Macroblock
4. Post-processing:
• SubtitleWriter writes .srt
• record_audios.py reads record_list.tsv → helps record voiceovers
Architectural Patterns & Principles
– Separation of Concerns:
• CLI vs. Core Engine vs. I/O
• Scene vs. State vs. Data
– Two-Layer Time Control: Macroblocks & Microblocks
– Plugin-Style Scenes: Each scene is a subclass implementing render_microblock
– Hybrid CPU/GPU Rendering: Fallback to CPU modules vs. CUDA accelerated code
– External Service Pipelines: LaTeX → SVG → Cairo → pixels; Gnuplot → PNG