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#

PathResponsibilities
crates/erikaThe core engine: the playback, renderer, audio, subtitle, danmaku, presenter, and other modules.
crates/erika_capiThe C ABI export layer; produces erika.h.
crates/erika_ffmpeg_sysFFmpeg bindings generated with bindgen.
packages/erika_flutterThe Flutter plugin covers seven platforms; Linux accepts prebuilt bundles or source builds through ERIKA_LIBRARY_DIR.
packages/erika_ohosThe 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, and DecoderBackend keep the Presenter platform-independent. Preferences are selected through RendererBackendPreference (PlatformNative / WgpuFallback) and VideoDecodePreference.

Adding a platform backend#

A new platform usually means three pieces of work, each behind #[cfg(target_os = ...)]:

  1. Decoding. Add a variant to DecoderBackend, configure the hardware device (see the D3D11VA and VideoToolbox paths), and produce a PlayerVideoFrame that the renderer can import with zero copy. Fall back to software decoding when interop is unavailable.
  2. Rendering. Implement RendererBackend in renderer/<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. Use renderer::pipeline for color and tone-mapping decisions so behavior matches the other backends. The D3D11 backend is the most recent complete example.
  3. Audio. Implement AudioOutputBackend: configure / start / pause / stop / push / set_volume / state / stats, plus clock_snapshot for A/V synchronization. Reuse BufferedAudioOutput / 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 contract#

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 to ErikaStatus_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 *_free function.
  • 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 in erika.h, you must update the two Swift mirror files in packages/erika_flutter at 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) and tests/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_LINEAR and 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 fmt and keep clippy clean.
  • Do not unwrap or panic in hot paths or across FFI. Return Result and map it to ErikaStatus at the boundary.
  • Match the surrounding code: naming, comment density, and the existing cfg structure. 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.
liberika v0.3.8 Section Project License MPL-2.0