feat: qbz-1 streaming, gapless prefetch, accurate scrobbling, Range-seek
Port proven playback architecture from qbqt fork: - Bounded VecDeque buffer with condvar backpressure (4MB cap) - decrypt_and_extract_frames for clean FLAC frame extraction from ISOBMFF - Cancel+restart seeking with sub-segment sample skipping - start_prefetch / QueueNext for gapless transitions with pre-started downloads - track_transitioned signaling for scrobbler during gapless playback - Range-request HTTP seeking for non-segmented (MP3) tracks - OnceLock HTTP client singleton with cancel-aware chunked downloads - Accumulated listening time scrobbling (prevents false scrobbles from seeking) - Array-format Last.fm scrobble params (artist[0], track[0], etc.) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,6 @@ const RING_BUFFER_SIZE: usize = 32 * 1024;
|
||||
|
||||
pub struct AudioOutput {
|
||||
ring_buf_producer: rb::Producer<f32>,
|
||||
viz_producer: Option<rb::Producer<f32>>,
|
||||
_stream: cpal::Stream,
|
||||
pub sample_rate: u32,
|
||||
pub channels: usize,
|
||||
@@ -52,17 +51,12 @@ impl AudioOutput {
|
||||
|
||||
Ok(Self {
|
||||
ring_buf_producer: producer,
|
||||
viz_producer: None,
|
||||
_stream: stream,
|
||||
sample_rate,
|
||||
channels,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_viz_producer(&mut self, producer: rb::Producer<f32>) {
|
||||
self.viz_producer = Some(producer);
|
||||
}
|
||||
|
||||
pub fn write(
|
||||
&mut self,
|
||||
decoded: AudioBufferRef<'_>,
|
||||
@@ -75,13 +69,13 @@ impl AudioOutput {
|
||||
);
|
||||
sample_buf.copy_interleaved_ref(decoded);
|
||||
let samples: Vec<f32> = sample_buf.samples().iter().map(|s| s * volume).collect();
|
||||
self.write_samples(&samples, stop)
|
||||
}
|
||||
|
||||
// Best-effort copy for visualizer (non-blocking, ok to drop samples)
|
||||
if let Some(ref mut viz) = self.viz_producer {
|
||||
let _ = viz.write(&samples);
|
||||
}
|
||||
|
||||
let mut remaining = &samples[..];
|
||||
/// Write pre-converted interleaved f32 samples directly to the ring buffer.
|
||||
/// Returns early (without error) if `stop` is set.
|
||||
pub fn write_samples(&mut self, samples: &[f32], stop: &Arc<AtomicBool>) -> Result<()> {
|
||||
let mut remaining = samples;
|
||||
while !remaining.is_empty() {
|
||||
if stop.load(Ordering::SeqCst) {
|
||||
return Ok(());
|
||||
|
||||
Reference in New Issue
Block a user