mirror of
https://github.com/librespot-org/librespot.git
synced 2025-01-07 17:24:04 +00:00
Add the ability to get backend latency
This commit is contained in:
parent
0cefd0ea66
commit
35b94bdc94
3 changed files with 31 additions and 0 deletions
|
@ -456,6 +456,23 @@ impl Sink for AlsaSink {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_latency_pcm(&mut self) -> u64 {
|
||||||
|
let buffer_len = self.period_buffer.len();
|
||||||
|
|
||||||
|
self.pcm
|
||||||
|
.as_mut()
|
||||||
|
.and_then(|pcm| {
|
||||||
|
pcm.status().ok().map(|status| {
|
||||||
|
let delay_frames = status.get_delay();
|
||||||
|
|
||||||
|
let frames_in_buffer = pcm.bytes_to_frames(buffer_len as isize);
|
||||||
|
|
||||||
|
(delay_frames + frames_in_buffer) as u64
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
sink_as_bytes!();
|
sink_as_bytes!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,9 @@ pub trait Sink {
|
||||||
fn stop(&mut self) -> SinkResult<()> {
|
fn stop(&mut self) -> SinkResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
fn get_latency_pcm(&mut self) -> u64 {
|
||||||
|
0
|
||||||
|
}
|
||||||
fn write(&mut self, packet: AudioPacket, converter: &mut Converter) -> SinkResult<()>;
|
fn write(&mut self, packet: AudioPacket, converter: &mut Converter) -> SinkResult<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,17 @@ impl Sink for PulseAudioSink {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_latency_pcm(&mut self) -> u64 {
|
||||||
|
self.sink
|
||||||
|
.as_mut()
|
||||||
|
.and_then(|sink| {
|
||||||
|
sink.get_latency()
|
||||||
|
.ok()
|
||||||
|
.map(|micro_sec| (micro_sec.as_secs_f64() * SAMPLE_RATE as f64).round() as u64)
|
||||||
|
})
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
sink_as_bytes!();
|
sink_as_bytes!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue