Make sure that decoder picks up where it left of going from paused to play

Since we are including the pipeline latency in the position we need to seek to the correct position when going from paused to play.

We can also drop the ALSA and PulseAudio buffers instead of draining them since their latency's are factored in.
This commit is contained in:
JasonLG1979 2023-07-02 03:52:40 -05:00
parent 3dafb5904e
commit 74e3f938da
3 changed files with 7 additions and 11 deletions

View file

@ -52,9 +52,6 @@ enum AlsaError {
#[error("<AlsaSink> Device {device} May be Invalid, Busy, or Already in Use, {e}")]
PcmSetUp { device: String, e: alsa::Error },
#[error("<AlsaSink> Failed to Drain PCM Buffer, {0}")]
DrainFailure(alsa::Error),
#[error("<AlsaSink> {0}")]
OnWrite(alsa::Error),
@ -76,7 +73,7 @@ impl From<AlsaError> for SinkError {
use AlsaError::*;
let es = e.to_string();
match e {
DrainFailure(_) | OnWrite(_) => SinkError::OnWrite(es),
OnWrite(_) => SinkError::OnWrite(es),
PcmSetUp { .. } => SinkError::ConnectionRefused(es),
_ => SinkError::InvalidParams(es),
}
@ -239,11 +236,8 @@ impl Sink for AlsaSink {
}
fn stop(&mut self) -> SinkResult<()> {
self.write_buf()?;
if let Some(pcm) = self.pcm.take() {
pcm.drain().map_err(AlsaError::DrainFailure)?;
}
self.period_buffer.clear();
self.pcm = None;
Ok(())
}

View file

@ -137,7 +137,7 @@ impl Sink for PulseAudioSink {
fn stop(&mut self) -> SinkResult<()> {
if let Some(sink) = self.sink.take() {
sink.drain().map_err(PulseError::DrainFailure)?;
sink.flush().map_err(PulseError::DrainFailure)?;
}
Ok(())

View file

@ -676,7 +676,7 @@ impl PlayerState {
Paused {
track_id,
play_request_id,
decoder,
mut decoder,
audio_item,
normalisation_data,
stream_loader_controller,
@ -686,6 +686,8 @@ impl PlayerState {
suggested_to_preload_next_track,
is_explicit,
} => {
let stream_position_ms = decoder.seek(stream_position_ms).unwrap_or_default();
*self = Playing {
track_id,
play_request_id,