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.
<!-- 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"]
license = "MIT OR Apache-2.0"
build = "build/build.rs"
publish = false
edition = "2018"
autobenches = false
include = [
+7 -8
View File
@@ -8,6 +8,7 @@ readme = "README.md"
keywords = ["teamspeak3", "ts3", "voip"]
categories = ["multimedia"]
license = "MIT OR Apache-2.0"
publish = false
edition = "2018"
include = [
"/Cargo.toml",
@@ -22,15 +23,13 @@ features = ["unstable"]
default = ["audio", "default-tls"]
# Enable the unstable api
unstable = []
audio = ["audiopus"]
audio = ["opus2"]
# Enable default reqwest features.
# Use default-features=false on tsclientlib to configure reqwest differently.
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]
audiopus = { version = "0.3.0-rc.0", optional = true }
opus2 = { version = "0.4", optional = true }
base64 = "0.22"
futures = "0.3"
git-testament = "0.2"
@@ -46,15 +45,15 @@ tokio-stream = "0.1"
tracing = "0.1"
hickory-net = "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-packets = { path = "../utils/tsproto-packets", version = "0.1" }
tsproto-types = { path = "../utils/tsproto-types", version = "0.1" }
tsproto-packets = { path = "../tsproto-packets", version = "0.1" }
tsproto-types = { path = "../tsproto-types", version = "0.1" }
url = "2"
[dev-dependencies]
anyhow = "1"
audiopus = "0.3.0-rc.0"
opus2 = "0.4"
cpal = "0.18"
once_cell = "1"
quickcheck = "1"
@@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::{Arc, Mutex};
use anyhow::{Result, format_err};
use audiopus::coder::Encoder;
use opus2::Encoder;
use cpal::traits::{DeviceTrait, StreamTrait};
use cpal::{Device, Stream, StreamConfig};
use futures::prelude::*;
@@ -63,9 +63,9 @@ impl AudioToTs {
};
let encoder = Encoder::new(
audiopus::SampleRate::Hz48000,
audiopus::Channels::Mono,
audiopus::Application::Voip,
48_000,
opus2::Channels::Mono,
opus2::Application::Voip,
)
.expect("Could not create encoder");
let mut callback = Callback {
+16 -38
View File
@@ -11,17 +11,14 @@ use std::convert::TryInto;
use std::fmt::Debug;
use std::hash::Hash;
use audiopus::coder::Decoder;
#[cfg(feature = "audiopus-unstable")]
use audiopus::coder::GenericCtl;
use audiopus::{Channels, SampleRate, packet};
use opus2::{Channels, Decoder, packet};
use thiserror::Error;
use tracing::{Span, debug, info_span, trace, warn};
use tsproto_packets::packets::{AudioData, CodecType, InAudioBuf};
use crate::ClientId;
const SAMPLE_RATE: SampleRate = SampleRate::Hz48000;
const SAMPLE_RATE: u32 = 48_000;
const CHANNELS: Channels = Channels::Stereo;
const CHANNEL_NUM: usize = 2;
/// 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]
pub enum Error {
#[error("Failed to create opus decoder: {0}")]
CreateDecoder(#[source] audiopus::Error),
CreateDecoder(#[source] opus2::Error),
#[error("Opus decode failed: {error} (packet: {packet:?})")]
Decode {
#[source]
error: audiopus::Error,
error: opus2::Error,
packet: Option<Vec<u8>>,
},
#[error("Get duplicate packet id {0}")]
Duplicate(u16),
#[error("Failed to get packet samples: {0}")]
GetPacketSample(#[source] audiopus::Error),
GetPacketSample(#[source] opus2::Error),
#[error("Audio queue is full, dropping")]
QueueFull,
#[error("Audio packet is too late, dropping (wanted {wanted}, got {got})")]
@@ -163,9 +160,8 @@ impl<T: Copy + Default + Ord> SlidingWindowMinimum<T> {
impl AudioQueue {
fn new(packet: InAudioBuf) -> Result<Self> {
let data = packet.data().data();
let opus_packet = data.data().try_into().map_err(Error::GetPacketSample)?;
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 {
return Err(Error::TooManySamples);
}
@@ -174,16 +170,6 @@ impl AudioQueue {
let whispering = matches!(data, AudioData::S2CWhisper { .. });
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 {
span: Span::current(),
decoder,
@@ -236,10 +222,8 @@ impl AudioQueue {
// End of stream
samples = 0;
} else {
let opus_packet =
packet.data().data().data().try_into().map_err(Error::GetPacketSample)?;
samples =
packet::nb_samples(opus_packet, SAMPLE_RATE).map_err(Error::GetPacketSample)?;
samples = packet::get_nb_samples(packet.data().data().data(), SAMPLE_RATE)
.map_err(Error::GetPacketSample)?;
if samples > MAX_BUFFER_SIZE {
return Err(Error::TooManySamples);
}
@@ -289,12 +273,12 @@ impl AudioQueue {
let packet_data;
let len;
if let Some(p) = packet {
packet_data =
Some(p.packet.data().data().data().try_into().map_err(Error::GetPacketSample)?);
packet_data = p.packet.data().data().data();
len = p.samples;
self.whispering = matches!(p.packet.data().data(), AudioData::S2CWhisper { .. });
} else {
packet_data = None;
// An empty slice signals packet loss to the decoder
packet_data = &[];
len = self.last_packet_samples;
}
self.packet_loss_num += 1;
@@ -303,13 +287,7 @@ impl AudioQueue {
self.decoded_buffer.resize(orig_buffer_len + len * CHANNEL_NUM, 0.0);
let len = self
.decoder
.decode_float(
packet_data,
(&mut self.decoded_buffer[orig_buffer_len..])
.try_into()
.map_err(Error::GetPacketSample)?,
fec,
)
.decode_float(packet_data, &mut self.decoded_buffer[orig_buffer_len..], fec)
.map_err(|e| Error::Decode {
error: e,
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)]
mod test {
use anyhow::{Result, bail};
use audiopus::coder::Encoder;
use opus2::Encoder;
use tsproto_packets::packets::{Direction, OutAudio};
use super::*;
@@ -616,9 +594,9 @@ mod test {
match a {
SimulateAction::CreateEncoder => {
encoder = Some(Encoder::new(
audiopus::SampleRate::Hz48000,
audiopus::Channels::Mono,
audiopus::Application::Voip,
48_000,
opus2::Channels::Mono,
opus2::Application::Voip,
)?);
}
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"
keywords = ["teamspeak3", "ts3"]
license = "MIT OR Apache-2.0"
publish = false
edition = "2018"
include = [
"/Cargo.toml",
+1
View File
@@ -7,6 +7,7 @@ repository = "https://github.com/ReSpeak/tsclientlib/tree/master/utils/tsproto-s
readme = "README.md"
keywords = ["teamspeak3", "ts3"]
license = "MIT OR Apache-2.0"
publish = false
edition = "2018"
include = [
"/Cargo.toml",
+1
View File
@@ -8,6 +8,7 @@ readme = "README.md"
keywords = ["teamspeak3", "ts3"]
license = "MIT OR Apache-2.0"
build = "build/build.rs"
publish = false
edition = "2018"
include = [
"/Cargo.toml",
+3 -2
View File
@@ -8,6 +8,7 @@ readme = "README.md"
keywords = ["teamspeak3", "ts3", "voip"]
categories = ["multimedia"]
license = "MIT OR Apache-2.0"
publish = false
edition = "2018"
autobenches = false
include = [
@@ -38,8 +39,8 @@ thiserror = "2"
time = { version = "0.3", features = ["formatting"] }
tokio = { version = "1", features = ["macros", "net", "sync", "time"] }
tracing = "0.1"
tsproto-packets = { path = "../utils/tsproto-packets", version = "0.1" }
tsproto-types = { path = "../utils/tsproto-types", version = "0.1" }
tsproto-packets = { path = "../tsproto-packets", version = "0.1" }
tsproto-types = { path = "../tsproto-types", version = "0.1" }
quicklz = "0.3"
[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"