Discord names a speaker's SSRC in the Speaking op only the first time they speak, and the op arrives after their first UDP packets. songbird 0.6.1 dropped the DAVE packets it could not decrypt yet, so the first ~100 ms of the first thing each person said after a join were lost (live 2026-11-18: "자비스 서울 날씨 어때" arrived as "아비 서울날씨 어때", and the first call after the 01:20 start as "아비스"). songbird is vendored in app/vendor/songbird with one patch: packets of an unnamed SSRC are held (1 s, 50 packets each, 32 SSRCs) and processed in arrival order once it is named, and the Speaking event is sent before the SSRC is named so handlers know the speaker first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
1.8 KiB
Rust
65 lines
1.8 KiB
Rust
use nonmax::NonMaxU32;
|
|
use std::time::Duration;
|
|
|
|
/// A type similar to [`std::time::Duration`] except using an `f32`.
|
|
///
|
|
/// This limits precision, only allowing by-second precision up to ~194 days,
|
|
/// but in turn shinks type size from `16` bytes to `4` bytes.
|
|
///
|
|
/// # Implementation Note
|
|
///
|
|
/// We actually store this as `NonMaxU32`, in order to get a niche to make `Option<FloatDuration>` the same size.
|
|
#[derive(Clone, Copy)]
|
|
pub struct FloatDuration(NonMaxU32);
|
|
|
|
impl FloatDuration {
|
|
/// Creates a [`FloatDuration`] from a raw `f32` value.
|
|
///
|
|
/// # Panics
|
|
/// This may panic if `value` is a NaN value.
|
|
#[must_use]
|
|
pub fn from_secs_f32(value: f32) -> Self {
|
|
Self(NonMaxU32::new(value.to_bits()).expect("value should not be NaN"))
|
|
}
|
|
|
|
/// Converts a [`FloatDuration`] to an `f32`.
|
|
///
|
|
/// This is cheaper than converting to a [`Duration`] and using [`Duration::as_secs_f32`] as it is more direct.
|
|
#[must_use]
|
|
pub fn as_secs_f32(self) -> f32 {
|
|
f32::from_bits(self.0.get())
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Debug for FloatDuration {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.debug_tuple("FloatDuration")
|
|
.field(&Duration::from(*self))
|
|
.finish()
|
|
}
|
|
}
|
|
|
|
impl PartialEq for FloatDuration {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
self.as_secs_f32() == other.as_secs_f32()
|
|
}
|
|
}
|
|
|
|
impl PartialOrd for FloatDuration {
|
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
self.as_secs_f32().partial_cmp(&other.as_secs_f32())
|
|
}
|
|
}
|
|
|
|
impl From<Duration> for FloatDuration {
|
|
fn from(value: Duration) -> Self {
|
|
Self::from_secs_f32(value.as_secs_f32())
|
|
}
|
|
}
|
|
|
|
impl From<FloatDuration> for Duration {
|
|
fn from(value: FloatDuration) -> Self {
|
|
Duration::from_secs_f32(value.as_secs_f32())
|
|
}
|
|
}
|