@lox-audioserver/node-librespot 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/lib.rs
CHANGED
|
@@ -550,6 +550,7 @@ impl Sink for ChannelSink {
|
|
|
550
550
|
self.last_pcm_at.store(now_ms, Ordering::Release);
|
|
551
551
|
}
|
|
552
552
|
// Pacing: throttle to approximate realtime based on sample count.
|
|
553
|
+
// Send first chunk immediately to minimize startup latency; apply pacing after forwarding.
|
|
553
554
|
let bytes_per_sample = match self.format {
|
|
554
555
|
AudioFormat::S24 => 3,
|
|
555
556
|
AudioFormat::S32 | AudioFormat::F32 => 4,
|
|
@@ -557,19 +558,17 @@ impl Sink for ChannelSink {
|
|
|
557
558
|
};
|
|
558
559
|
let samples = bytes.len() / (bytes_per_sample * self.channels as usize);
|
|
559
560
|
let duration = Duration::from_secs_f64(samples as f64 / self.sample_rate as f64);
|
|
561
|
+
if self.tx.try_send(bytes).is_err() {
|
|
562
|
+
// Drop chunk if JS side is backpressured to avoid blocking the player thread.
|
|
563
|
+
}
|
|
560
564
|
let start = self.start.get_or_insert_with(Instant::now);
|
|
561
565
|
self.expected_elapsed += duration;
|
|
562
566
|
let target = *start + self.expected_elapsed;
|
|
563
567
|
let now = Instant::now();
|
|
564
568
|
let sleep_dur = target.saturating_duration_since(now);
|
|
565
|
-
|
|
566
569
|
if !sleep_dur.is_zero() {
|
|
567
570
|
sleep(sleep_dur);
|
|
568
571
|
}
|
|
569
|
-
|
|
570
|
-
if self.tx.try_send(bytes).is_err() {
|
|
571
|
-
// Drop chunk if JS side is backpressured to avoid blocking the player thread.
|
|
572
|
-
}
|
|
573
572
|
Ok(())
|
|
574
573
|
}
|
|
575
574
|
}
|