build: workspace for vendored crates, replace audiopus with opus2

- Root Cargo workspace (resolver 3) with the six vendored crates.
- Path deps adjusted to the flat crates/proto layout, publish = false.
- tsclientlib: audiopus (unmaintained, RUSTSEC-2026-0150) -> opus2 0.4.
- Stable rustfmt config for new crates; vendored crates keep their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
Claude committed 2026-09-25 12:52:44 +00:00
1 parent 1cb7b0bdf2
commit 8cd65e8deb
13 files changed
+87 -52

No files matched your search

+1
View File
@@ -0,0 +1 @@
/target/
+38
View File
@@ -0,0 +1,38 @@
[workspace]
resolver = "3"
members = [
"crates/proto/tsproto-types",
"crates/proto/tsproto-structs",
"crates/proto/tsproto-packets",
"crates/proto/tsproto",
"crates/proto/ts-bookkeeping",
"crates/proto/tsclientlib",
"tools/tsctl",
]
default-members = [
"crates/proto/tsproto-types",
"crates/proto/tsproto-structs",
"crates/proto/tsproto-packets",
"crates/proto/tsproto",
"crates/proto/ts-bookkeeping",
"crates/proto/tsclientlib",
"tools/tsctl",
]
[workspace.package]
edition = "2024"
rust-version = "1.94"
license = "MIT OR Apache-2.0"
repository = "https://github.com/Faumaray/teamspeak_client_rs"
publish = false
[workspace.lints.rust]
unsafe_code = "forbid"
[workspace.lints.clippy]
all = { level = "warn", priority = -1 }
[profile.dev.package.num-bigint]
# The Init1 puzzle does a large modular exponentiation on connect; unoptimized
# it takes seconds.
opt-level = 3
+6
View File
@@ -31,3 +31,9 @@ files in this directory is listed here, newest last, so it can be diffed
against or offered back to upstream. against or offered back to upstream.
<!-- patches --> <!-- patches -->
1. **Workspace integration.** Path dependencies point at the flat `crates/proto/<crate>`
layout; every crate gets `publish = false`.
2. **Replace `audiopus` with `opus2` 0.4** (`tsclientlib/src/audio.rs`,
`tsclientlib/examples/audio_utils/audio_to_ts.rs`, `tsclientlib/Cargo.toml`).
`audiopus` is unmaintained (RUSTSEC-2026-0150) and breaks with CMake 4. The
`audiopus-unstable` feature (decoder complexity/DRED via a fork) is dropped.
+1
View File
@@ -8,6 +8,7 @@ readme = "README.md"
keywords = ["teamspeak3", "ts3"] keywords = ["teamspeak3", "ts3"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
build = "build/build.rs" build = "build/build.rs"
publish = false
edition = "2018" edition = "2018"
autobenches = false autobenches = false
include = [ include = [
+7 -8
View File
@@ -8,6 +8,7 @@ readme = "README.md"
keywords = ["teamspeak3", "ts3", "voip"] keywords = ["teamspeak3", "ts3", "voip"]
categories = ["multimedia"] categories = ["multimedia"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
publish = false
edition = "2018" edition = "2018"
include = [ include = [
"/Cargo.toml", "/Cargo.toml",
@@ -22,15 +23,13 @@ features = ["unstable"]
default = ["audio", "default-tls"] default = ["audio", "default-tls"]
# Enable the unstable api # Enable the unstable api
unstable = [] unstable = []
audio = ["audiopus"] audio = ["opus2"]
# Enable default reqwest features. # Enable default reqwest features.
# Use default-features=false on tsclientlib to configure reqwest differently. # Use default-features=false on tsclientlib to configure reqwest differently.
default-tls = ["reqwest/charset", "reqwest/default-tls", "reqwest/http2"] default-tls = ["reqwest/charset", "reqwest/default-tls", "reqwest/http2"]
# Use API of audiopus fork at https://github.com/Flakebi/audiopus for more features
audiopus-unstable = []
[dependencies] [dependencies]
audiopus = { version = "0.3.0-rc.0", optional = true } opus2 = { version = "0.4", optional = true }
base64 = "0.22" base64 = "0.22"
futures = "0.3" futures = "0.3"
git-testament = "0.2" git-testament = "0.2"
@@ -46,15 +45,15 @@ tokio-stream = "0.1"
tracing = "0.1" tracing = "0.1"
hickory-net = "0.26" hickory-net = "0.26"
hickory-resolver = "0.26" hickory-resolver = "0.26"
ts-bookkeeping = { path = "../utils/ts-bookkeeping", version = "0.1" } ts-bookkeeping = { path = "../ts-bookkeeping", version = "0.1" }
tsproto = { path = "../tsproto", version = "0.2" } tsproto = { path = "../tsproto", version = "0.2" }
tsproto-packets = { path = "../utils/tsproto-packets", version = "0.1" } tsproto-packets = { path = "../tsproto-packets", version = "0.1" }
tsproto-types = { path = "../utils/tsproto-types", version = "0.1" } tsproto-types = { path = "../tsproto-types", version = "0.1" }
url = "2" url = "2"
[dev-dependencies] [dev-dependencies]
anyhow = "1" anyhow = "1"
audiopus = "0.3.0-rc.0" opus2 = "0.4"
cpal = "0.18" cpal = "0.18"
once_cell = "1" once_cell = "1"
quickcheck = "1" quickcheck = "1"
@@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use anyhow::{Result, format_err}; use anyhow::{Result, format_err};
use audiopus::coder::Encoder; use opus2::Encoder;
use cpal::traits::{DeviceTrait, StreamTrait}; use cpal::traits::{DeviceTrait, StreamTrait};
use cpal::{Device, Stream, StreamConfig}; use cpal::{Device, Stream, StreamConfig};
use futures::prelude::*; use futures::prelude::*;
@@ -63,9 +63,9 @@ impl AudioToTs {
}; };
let encoder = Encoder::new( let encoder = Encoder::new(
audiopus::SampleRate::Hz48000, 48_000,
audiopus::Channels::Mono, opus2::Channels::Mono,
audiopus::Application::Voip, opus2::Application::Voip,
) )
.expect("Could not create encoder"); .expect("Could not create encoder");
let mut callback = Callback { let mut callback = Callback {
+16 -38
View File
@@ -11,17 +11,14 @@ use std::convert::TryInto;
use std::fmt::Debug; use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
use audiopus::coder::Decoder; use opus2::{Channels, Decoder, packet};
#[cfg(feature = "audiopus-unstable")]
use audiopus::coder::GenericCtl;
use audiopus::{Channels, SampleRate, packet};
use thiserror::Error; use thiserror::Error;
use tracing::{Span, debug, info_span, trace, warn}; use tracing::{Span, debug, info_span, trace, warn};
use tsproto_packets::packets::{AudioData, CodecType, InAudioBuf}; use tsproto_packets::packets::{AudioData, CodecType, InAudioBuf};
use crate::ClientId; use crate::ClientId;
const SAMPLE_RATE: SampleRate = SampleRate::Hz48000; const SAMPLE_RATE: u32 = 48_000;
const CHANNELS: Channels = Channels::Stereo; const CHANNELS: Channels = Channels::Stereo;
const CHANNEL_NUM: usize = 2; const CHANNEL_NUM: usize = 2;
/// If this amount of packets is lost consecutively, we assume the stream stopped. /// If this amount of packets is lost consecutively, we assume the stream stopped.
@@ -48,17 +45,17 @@ type Result<T> = std::result::Result<T, Error>;
#[non_exhaustive] #[non_exhaustive]
pub enum Error { pub enum Error {
#[error("Failed to create opus decoder: {0}")] #[error("Failed to create opus decoder: {0}")]
CreateDecoder(#[source] audiopus::Error), CreateDecoder(#[source] opus2::Error),
#[error("Opus decode failed: {error} (packet: {packet:?})")] #[error("Opus decode failed: {error} (packet: {packet:?})")]
Decode { Decode {
#[source] #[source]
error: audiopus::Error, error: opus2::Error,
packet: Option<Vec<u8>>, packet: Option<Vec<u8>>,
}, },
#[error("Get duplicate packet id {0}")] #[error("Get duplicate packet id {0}")]
Duplicate(u16), Duplicate(u16),
#[error("Failed to get packet samples: {0}")] #[error("Failed to get packet samples: {0}")]
GetPacketSample(#[source] audiopus::Error), GetPacketSample(#[source] opus2::Error),
#[error("Audio queue is full, dropping")] #[error("Audio queue is full, dropping")]
QueueFull, QueueFull,
#[error("Audio packet is too late, dropping (wanted {wanted}, got {got})")] #[error("Audio packet is too late, dropping (wanted {wanted}, got {got})")]
@@ -163,9 +160,8 @@ impl<T: Copy + Default + Ord> SlidingWindowMinimum<T> {
impl AudioQueue { impl AudioQueue {
fn new(packet: InAudioBuf) -> Result<Self> { fn new(packet: InAudioBuf) -> Result<Self> {
let data = packet.data().data(); let data = packet.data().data();
let opus_packet = data.data().try_into().map_err(Error::GetPacketSample)?;
let last_packet_samples = let last_packet_samples =
packet::nb_samples(opus_packet, SAMPLE_RATE).map_err(Error::GetPacketSample)?; packet::get_nb_samples(data.data(), SAMPLE_RATE).map_err(Error::GetPacketSample)?;
if last_packet_samples > MAX_BUFFER_SIZE { if last_packet_samples > MAX_BUFFER_SIZE {
return Err(Error::TooManySamples); return Err(Error::TooManySamples);
} }
@@ -174,16 +170,6 @@ impl AudioQueue {
let whispering = matches!(data, AudioData::S2CWhisper { .. }); let whispering = matches!(data, AudioData::S2CWhisper { .. });
let decoder = Decoder::new(SAMPLE_RATE, CHANNELS).map_err(Error::CreateDecoder)?; let decoder = Decoder::new(SAMPLE_RATE, CHANNELS).map_err(Error::CreateDecoder)?;
// Enable DRED and NoLACE, ignore errors e.g. if unsupported
#[cfg(feature = "audiopus-unstable")]
let decoder = {
let mut decoder = decoder;
if let Err(error) = decoder.set_complexity(7) {
debug!(%error, "Failed setting opus decoder complexity, ignoring");
}
decoder
};
let mut res = Self { let mut res = Self {
span: Span::current(), span: Span::current(),
decoder, decoder,
@@ -236,10 +222,8 @@ impl AudioQueue {
// End of stream // End of stream
samples = 0; samples = 0;
} else { } else {
let opus_packet = samples = packet::get_nb_samples(packet.data().data().data(), SAMPLE_RATE)
packet.data().data().data().try_into().map_err(Error::GetPacketSample)?; .map_err(Error::GetPacketSample)?;
samples =
packet::nb_samples(opus_packet, SAMPLE_RATE).map_err(Error::GetPacketSample)?;
if samples > MAX_BUFFER_SIZE { if samples > MAX_BUFFER_SIZE {
return Err(Error::TooManySamples); return Err(Error::TooManySamples);
} }
@@ -289,12 +273,12 @@ impl AudioQueue {
let packet_data; let packet_data;
let len; let len;
if let Some(p) = packet { if let Some(p) = packet {
packet_data = packet_data = p.packet.data().data().data();
Some(p.packet.data().data().data().try_into().map_err(Error::GetPacketSample)?);
len = p.samples; len = p.samples;
self.whispering = matches!(p.packet.data().data(), AudioData::S2CWhisper { .. }); self.whispering = matches!(p.packet.data().data(), AudioData::S2CWhisper { .. });
} else { } else {
packet_data = None; // An empty slice signals packet loss to the decoder
packet_data = &[];
len = self.last_packet_samples; len = self.last_packet_samples;
} }
self.packet_loss_num += 1; self.packet_loss_num += 1;
@@ -303,13 +287,7 @@ impl AudioQueue {
self.decoded_buffer.resize(orig_buffer_len + len * CHANNEL_NUM, 0.0); self.decoded_buffer.resize(orig_buffer_len + len * CHANNEL_NUM, 0.0);
let len = self let len = self
.decoder .decoder
.decode_float( .decode_float(packet_data, &mut self.decoded_buffer[orig_buffer_len..], fec)
packet_data,
(&mut self.decoded_buffer[orig_buffer_len..])
.try_into()
.map_err(Error::GetPacketSample)?,
fec,
)
.map_err(|e| Error::Decode { .map_err(|e| Error::Decode {
error: e, error: e,
packet: packet.map(|p| p.packet.raw_data().to_vec()), packet: packet.map(|p| p.packet.raw_data().to_vec()),
@@ -558,7 +536,7 @@ impl<Id: Clone + Debug + Eq + Hash + PartialEq> AudioHandler<Id> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use audiopus::coder::Encoder; use opus2::Encoder;
use tsproto_packets::packets::{Direction, OutAudio}; use tsproto_packets::packets::{Direction, OutAudio};
use super::*; use super::*;
@@ -616,9 +594,9 @@ mod test {
match a { match a {
SimulateAction::CreateEncoder => { SimulateAction::CreateEncoder => {
encoder = Some(Encoder::new( encoder = Some(Encoder::new(
audiopus::SampleRate::Hz48000, 48_000,
audiopus::Channels::Mono, opus2::Channels::Mono,
audiopus::Application::Voip, opus2::Application::Voip,
)?); )?);
} }
SimulateAction::ReceivePacket(i, success) => { SimulateAction::ReceivePacket(i, success) => {
+1
View File
@@ -7,6 +7,7 @@ repository = "https://github.com/ReSpeak/tsclientlib/tree/master/utils/tsproto-p
readme = "README.md" readme = "README.md"
keywords = ["teamspeak3", "ts3"] keywords = ["teamspeak3", "ts3"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
publish = false
edition = "2018" edition = "2018"
include = [ include = [
"/Cargo.toml", "/Cargo.toml",
+1
View File
@@ -7,6 +7,7 @@ repository = "https://github.com/ReSpeak/tsclientlib/tree/master/utils/tsproto-s
readme = "README.md" readme = "README.md"
keywords = ["teamspeak3", "ts3"] keywords = ["teamspeak3", "ts3"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
publish = false
edition = "2018" edition = "2018"
include = [ include = [
"/Cargo.toml", "/Cargo.toml",
+1
View File
@@ -8,6 +8,7 @@ readme = "README.md"
keywords = ["teamspeak3", "ts3"] keywords = ["teamspeak3", "ts3"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
build = "build/build.rs" build = "build/build.rs"
publish = false
edition = "2018" edition = "2018"
include = [ include = [
"/Cargo.toml", "/Cargo.toml",
+3 -2
View File
@@ -8,6 +8,7 @@ readme = "README.md"
keywords = ["teamspeak3", "ts3", "voip"] keywords = ["teamspeak3", "ts3", "voip"]
categories = ["multimedia"] categories = ["multimedia"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
publish = false
edition = "2018" edition = "2018"
autobenches = false autobenches = false
include = [ include = [
@@ -38,8 +39,8 @@ thiserror = "2"
time = { version = "0.3", features = ["formatting"] } time = { version = "0.3", features = ["formatting"] }
tokio = { version = "1", features = ["macros", "net", "sync", "time"] } tokio = { version = "1", features = ["macros", "net", "sync", "time"] }
tracing = "0.1" tracing = "0.1"
tsproto-packets = { path = "../utils/tsproto-packets", version = "0.1" } tsproto-packets = { path = "../tsproto-packets", version = "0.1" }
tsproto-types = { path = "../utils/tsproto-types", version = "0.1" } tsproto-types = { path = "../tsproto-types", version = "0.1" }
quicklz = "0.3" quicklz = "0.3"
[dev-dependencies] [dev-dependencies]
+3
View File
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.94"
components = ["rustfmt", "clippy"]
+5
View File
@@ -0,0 +1,5 @@
# Stable subset of the vendored crates' style (crates/proto/.rustfmt.toml needs nightly).
edition = "2024"
hard_tabs = true
use_small_heuristics = "Max"
newline_style = "Unix"