forked from irlserver/belacoder
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Overview
This issue tracks the potential migration of belacoder from C to Rust.
Current State
belacoder is a ~800-line C application that:
- Parses CLI arguments and a GStreamer pipeline file
- Constructs and runs a GStreamer pipeline
- Pulls samples from an
appsinkand sends them over SRT - Polls SRT statistics and adjusts encoder bitrate
- Handles signals for graceful shutdown and config reload
Why Rust?
- Memory safety - Eliminates buffer overflows, use-after-free at compile time
- Better error handling -
Result<T, E>forces explicit error handling - No undefined behavior - Safer signal handling
- GStreamer bindings are mature -
gstreamer-rsis well-maintained - No GC latency - Critical for real-time video
- Performance parity with C - Zero-cost abstractions
Key Dependencies
| Dependency | C Binding | Rust Binding |
|---|---|---|
| GStreamer | Native | gstreamer-rs (mature) |
| GLib | Native | glib-rs (mature) |
| libsrt | Native | srt-rs (exists, less active) |
| POSIX signals | Native | signal-hook (mature) |
Risks
- SRT bindings maturity -
srt-rsless actively maintained than libsrt - Build complexity - Cross-compilation for Jetson ARM needs setup
- Team familiarity - Rust learning curve
Incremental Migration Path
Phase 1: Preparation (C) ✅
- Fix signal handling safety
- Add proper error handling
- Clean up resource leaks
- Refactor into modules with clear interfaces
- Add integration tests
Phase 2: Bitrate Controller in Rust
- Create Rust crate for bitrate controller (no GStreamer dependency)
- Expose via C FFI
- Integrate into C main
- Test in production
Phase 3: SRT Sender in Rust
- Evaluate
srt-rsbindings - Implement SRT sender module
- Wire up appsink callback to call Rust
- Test reliability and performance
Phase 4: Full Port
- GStreamer pipeline construction in Rust
- CLI parsing with
clap - Signal handling with
signal-hook - Deprecate C version
Recommended Rust Crates
[dependencies]
gstreamer = "0.22"
gstreamer-app = "0.22"
glib = "0.19"
clap = "4"
anyhow = "1"
signal-hook = "0.3"
log = "0.4"Effort Estimate
| Component | Complexity | Estimate |
|---|---|---|
| CLI parsing | Low | 2-4 hours |
| Pipeline construction | Medium | 1-2 days |
| Appsink + SRT send | Medium | 1-2 days |
| Bitrate controller | Low | 4-8 hours |
| Signal handling | Low | 2-4 hours |
| Testing | High | 2-3 days |
| Total | 1-2 weeks |
Recommendation
Short-term (0-6 months): Stay with C, focus on code quality and tests
Medium-term (6-12 months): Start with bitrate controller in Rust (self-contained, easy to test)
Long-term: Full port only if incremental modules succeed
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request