Home/docs/project/Contributing
Contributing
Contributing
This page maps the codebase, lists every place you need to touch to change a platform, describes the constraints of the C ABI contract, and covers testing and commit conventions. Before you make changes, read the Architecture overview to understand the runtime model.
Repository layoutレイアウト#
| Path | Responsibilities |
|---|---|
| crates/erika | The core engine: the playback, renderer, audio, subtitle, danmaku, presenter, and other modules. |
| crates/erika_capi | The C ABI export layer; produces erika.h. |
| crates/erika_ffmpeg_sys | FFmpeg bindings generated with bindgen. |
| packages/erika_flutter | The Flutter plugin covers seven platforms; Linux accepts prebuilt bundles or source builds through ERIKA_LIBRARY_DIR. |
| packages/erika_ohos | The OpenHarmony native ArkTS / OHPM SDK. |
| examples/ | Verification and smoke-test programs. |
| xtask/ | Build orchestration for native dependencies. |
| third_party/ | Built native dependencies; this output is gitignored. |
Runtime modelランタイム#
Three facts determine where most changes land:
- PresenterRuntime owns the entire stack. The host calls
render_tick(time_seconds)every frame. The runtime pulls the decoded frame, updates the overlay (subtitles + danmaku), renders, and presents. The danmaku plan is gated by generation + media_time so it stays in sync with the video. - Audio is the master clock. Audio output runs on its own backend thread, and the playback scheduler aligns video presentation to the audio clock with vsync quantization.
- Backends are pluggable. The three traits
RendererBackend,AudioOutputBackend, andDecoderBackendkeep the Presenter platform-independent. Preferences are selected throughRendererBackendPreference(PlatformNative / WgpuFallback) andVideoDecodePreference.
Adding a platform backend新規バックエンド#
A new platform usually means three pieces of work, each behind #[cfg(target_os = ...)]:
- Decoding. Add a variant to
DecoderBackend, configure the hardware device (see the D3D11VA and VideoToolbox paths), and produce aPlayerVideoFramethat the renderer can import with zero copy. Fall back to software decoding when interop is unavailable. - Rendering. Implement
RendererBackendinrenderer/<backend>.rs: attach / detach / resize,upload_player_frame(which owns the imported GPU representation),render_current_frame(which composites the overlay), and optionally capture, runtime_stats, and set_luma_upscaler. Userenderer::pipelinefor color and tone-mapping decisions so behavior matches the other backends. The D3D11 backend is the most recent complete example. - Audio. Implement
AudioOutputBackend: configure / start / pause / stop / push / set_volume / state / stats, plusclock_snapshotfor A/V synchronization. ReuseBufferedAudioOutput/AudioRingBuffer. WASAPI is the reference implementation.
Then wire the backend into the Presenter's backend selection and add a <platform>_native_demo example for end-to-end verification.
The C ABI is a contractC ABI 契約#
erika_capi is the stable integration surface for every non-Rust host. When you change it:
- Keep panics inside. Every export wraps its body in
catch_unwind, and a panic maps toErikaStatus_Panic. An unwind must never cross the boundary. - Respect ownership. A string you hand out belongs to the caller, who frees it with the matching
*_freefunction. - Sync
erika.h. Update the header by hand to match, and add comments for new functions. - Sync the Swift mirror structs. The Apple plugin hand-writes Swift mirrors of the C structs (such as
ErikaPresenterStats). If you change a struct inerika.h, you must update the two Swift mirror files inpackages/erika_flutterat the same time. A mismatch corrupts the stack and can show up as a misleading autorelease-pool crash. - Document JSON methods. The Presenter's JSON bridge methods map one-to-one to the C surface. When you add one, update the method list as well.
Testing and verificationテスト#
cargo test --workspace cargo clippy --workspace cargo fmt --all
- Gate platform-specific code with
#[cfg]. When you change one branch, make sure every branch (macOS / iOS / Windows / Android / fallback) still compiles. Leave targets you cannot test locally to CI. - The neural upscaling weights are verified against the onnxruntime reference in
tests/artcnn_upscaler.rs(Metal) andtests/wgpu_artcnn.rs(tiled wgpu). Re-verify the corresponding path before you modify a kernel. - Android SDR playback and the explicit output fallback are verified. Until the active path on an API 35 HDR device passes
Rgba16Float + SCRGB_LINEARand the recovery checks, do not mark extended-linear scRGB as verified on real devices. - The native demos double as smoke tests:
cargo run -p macos_native_demo -- --smoke-seconds 3 "$SAMPLE"(Windows has an equivalent command). It prints the pipeline counters, which you use to confirm that hardware decoding and zero-copy interop still work.
Conventions規約#
- Edition 2024, Rust 1.92+. Run
cargo fmtand keep clippy clean. - Do not
unwraporpanicin hot paths or across FFI. ReturnResultand map it toErikaStatusat the boundary. - Match the surrounding code: naming, comment density, and the existing
cfgstructure. Keep platform glue in the platform module so it does not leak into the engine. - Keep the docs in sync. Reflect user-visible changes in this documentation set. The base language is English, with translations following.
- Keep PRs focused. State which platforms you built and tested on, and which you left to CI.