From 9aa881d5cc4902549aead18875042ef0651e492c Mon Sep 17 00:00:00 2001 From: Filip Kojro Date: Sun, 23 Aug 2026 20:45:44 +0200 Subject: [PATCH] change to pure rust opus lib --- Cargo.lock | 66 +++++++++++++++++++++++++--------------------- client/Cargo.toml | 2 +- client/src/main.rs | 25 +++++++++++------- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edb406e..fe636b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,17 +74,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "audiopus_sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62314a1546a2064e033665d658e88c620a62904be945f8147e6b16c3db9f8651" -dependencies = [ - "cmake", - "log", - "pkg-config", -] - [[package]] name = "autocfg" version = "1.5.1" @@ -112,6 +101,12 @@ version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" +[[package]] +name = "bytemuck" +version = "1.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797" + [[package]] name = "bytes" version = "1.12.1" @@ -191,24 +186,15 @@ version = "0.1.0" dependencies = [ "clap", "cpal", - "opus", "rand", "ringbuf", + "ropus", "serde", "serde_json", "shared", "tokio", ] -[[package]] -name = "cmake" -version = "0.1.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" -dependencies = [ - "cc", -] - [[package]] name = "colorchoice" version = "1.0.5" @@ -678,15 +664,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "opus" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d3809943dff6fbad5f0484449ea26bdb9cb7d8efdf26ed50d3c7f227f69eb5c" -dependencies = [ - "audiopus_sys", -] - [[package]] name = "parking_lot" version = "0.12.5" @@ -807,6 +784,16 @@ dependencies = [ "portable-atomic-util", ] +[[package]] +name = "ropus" +version = "0.12.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80804dadbfa2851c95fe45ff9ae8f4328d6371fdc0d51b14740d49a8b41d3758" +dependencies = [ + "cc", + "wide", +] + [[package]] name = "rustc_version" version = "0.4.1" @@ -822,6 +809,15 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" +[[package]] +name = "safe_arch" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b02de82ddbe1b636e6170c21be622223aea188ef2e139be0a5b219ec215323" +dependencies = [ + "bytemuck", +] + [[package]] name = "same-file" version = "1.0.6" @@ -1168,6 +1164,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "wide" +version = "0.7.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce5da8ecb62bcd8ec8b7ea19f69a51275e91299be594ea5cc6ef7819e16cd03" +dependencies = [ + "bytemuck", + "safe_arch", +] + [[package]] name = "winapi-util" version = "0.1.11" diff --git a/client/Cargo.toml b/client/Cargo.toml index 1e5223c..d01d0c0 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -12,4 +12,4 @@ serde_json = "1.0.151" tokio = { version = "1.53.1", features = ["full"] } rand = "0.10.2" clap = { version = "4.6.6", features = ["derive"] } -opus = "0.3.1" +ropus = "0.12.18" diff --git a/client/src/main.rs b/client/src/main.rs index 424a8c4..8e5d3fd 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -3,12 +3,12 @@ use cpal::{ Device, traits::{DeviceTrait, HostTrait, StreamTrait}, }; -use opus::{Decoder, Encoder}; use ringbuf::{ HeapRb, consumer, traits::{Consumer, Observer, Producer, Split}, wrap::caching::Caching, }; +use ropus::{Decoder, Encoder}; use shared::{AudioStreamInfo, ResponseStatus, TcpRequest, TcpResponse, TcpResponseData}; use std::{ collections::HashMap, @@ -157,11 +157,11 @@ async fn main() { consumer, ); - let channels: opus::Channels = { + let channels: ropus::Channels = { if audio_stream.channels == 1 { - opus::Channels::Mono + ropus::Channels::Mono } else { - opus::Channels::Stereo + ropus::Channels::Stereo } }; @@ -333,7 +333,11 @@ async fn main() { let mut decoder = decoder_mutex.lock().expect("failed to get encoder"); let decoded_len = decoder - .decode_float(audio_packet, &mut decoded_samples, false) + .decode_float( + audio_packet, + &mut decoded_samples, + ropus::DecodeMode::Normal, + ) .expect("failed to decode opus"); let mut active_streams_map = @@ -477,16 +481,17 @@ async fn audio_stream_spawner( let frames_needed = ((20.0 / 1000.0) * config.sample_rate as f32) as usize; let mut frame_buffer = vec![0.0; frames_needed]; - let channels: opus::Channels = { + let channels: ropus::Channels = { if config.channels == 1 { - opus::Channels::Mono + ropus::Channels::Mono } else { - opus::Channels::Stereo + ropus::Channels::Stereo } }; - let mut opus_encoder = Encoder::new(config.sample_rate, channels, opus::Application::Voip) - .expect("falied to create opus encoder"); + let mut opus_encoder = Encoder::builder(config.sample_rate, channels, ropus::Application::Voip) + .build() + .unwrap(); let mut encoded_frame_buffer = [0u8; 1024];