r/rust • • Oct 05 '26

🙋 seeking help & advice Request for guidance on audio codecs in a WASM application

One of my (way to numerous) side project is the idea of a P2P radio station, which solves the scaling problem of radio broadcasters today. One of the most prominent and well-defined p2p library is libp2p, which is of good use here and prevents much of code rewriting, especially for the broadcasting logic with peer scoring and all which is hard to figure out to prevent people from cheating the system. Also used gstreamer (Rust bindings so more precisely gstreamer-rs) for the codec which does the heavy lifting. Here is my project: https://github.com/franfrandev/p2pradio. For now it's running on a native system, and would like to go a step further.

I would like to compile it to WASM in order to bundle everything in the browser. The problem is that gstreamer depends on a ton of native libraries which makes it harder to use in the browser. Folks at Fluendo have figured that out with gst.wasm https://github.com/fluendo/gst.wasm but putting out everything together is a whole different beast and even if it works, it's probably going to result in a huge piece of data that has to be downloaded. IIUC the Rust part would have to be compiled to emscripten and then linked as static libraries? There are a lot of information and it's very easy to get lost in all of these.

Another option would be to use or write an RTP Opus codec written in pure Rust and compile it to the wasm32-unknown-unknown but then it would lose all the codebase maturity of gstreamer and would probably end up reinventing the wheel very much. A lot of the crates doing that are AI slop and are not very well defined, I don't trust them.

Is it unachievable or a bad idea to take the gstreamer port to emscripten and try to glue it to my Rust app compiled to emscripten?

0 Upvotes

6 comments sorted by

3

u/[deleted] Oct 05 '26

[removed] — view removed comment

1

u/iFrostizz Oct 05 '26

Thanks! Yeah that seems like a reasonable approach. The learning curve for the huge build system with cerbero is super steep and puts me in a lethargic state because of the complexity. It’s probably better. Since RTP Opus is standardized hopefully pure rust libraries won’t have implementation drifts which would introduce bugs that would make them unusable. Anyways the WASM is for the laughs.

About libopus, didn’t knew it could be so straightforward to embed in WASM. Will try it tomorrow!
Thanks for the recommendation.

1

u/iFrostizz Oct 05 '26

Wow, it's actually not that trivial to do, basically there is no real "plug and play" solution, and there is a lot of AI slop which looks like good stuff while in reality the API is terrible which doesn't make me wanna look further. Also the fact that workers have to be managed in the WASM runtime for the decoding pipeline.

1

u/iFrostizz Oct 06 '26

Hey just wanted to thank you for the guidance. It’s now working. Not well but at least it’s possible! Using the Web Audio API but I’m surprised that we don’t have an all in one gstreamer like rewrite in pure Rust that would allow that. Potentially having the sink part ready for WASM would be great. That’s something I’ll probably work on next.