removes can_seek in favor of rolling back seek operations (requires PR #510)

This commit is contained in:
dvdsk 2023-10-08 13:34:05 +02:00
parent 5d44bfe636
commit 10262f8134
No known key found for this signature in database
GPG key ID: 6CF9D20C5709A836
38 changed files with 101 additions and 240 deletions

View file

@ -91,10 +91,8 @@ where
Err(SeekError::NotSupported { underlying_source: std::any::type_name::<Self>() })
}
#[inline]
fn can_seek(&self) -> bool {
false
}
}
impl<S> Iterator for SamplesBuffer<S>

View file

@ -50,12 +50,6 @@ where
pub fn inner_mut(&mut self) -> &mut I {
&mut self.input
}
/// Get a reference to the iterator
#[inline]
pub fn inner(&self) -> &I {
&self.input
}
}
impl<I> Iterator for ChannelCountConverter<I>

View file

@ -29,12 +29,6 @@ impl<I, O> DataConverter<I, O> {
pub fn inner_mut(&mut self) -> &mut I {
&mut self.input
}
/// get a reference to the iterator
#[inline]
pub fn inner(&self) -> &I {
&self.input
}
}
impl<I, O> Iterator for DataConverter<I, O>

View file

@ -108,12 +108,6 @@ where
&mut self.input
}
/// get a reference to the iterator
#[inline]
pub fn inner(&self) -> &I {
&self.input
}
fn next_input_frame(&mut self) {
self.current_frame_pos_in_chunk += 1;

View file

@ -85,11 +85,6 @@ where
fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> {
Err(SeekError::NotSupported { underlying_source: std::any::type_name::<Self>() })
}
#[inline]
fn can_seek(&self) -> bool {
false
}
}
impl<R> Iterator for FlacDecoder<R>

View file

@ -179,22 +179,6 @@ impl<R: Read + Seek> DecoderImpl<R> {
}),
}
}
fn can_seek(&self) -> bool {
match self {
#[cfg(all(feature = "wav", not(feature = "symphonia-wav")))]
DecoderImpl::Wav(source) => source.can_seek(),
#[cfg(all(feature = "vorbis", not(feature = "symphonia-vorbis")))]
DecoderImpl::Vorbis(source) => source.can_seek(),
#[cfg(all(feature = "flac", not(feature = "symphonia-flac")))]
DecoderImpl::Flac(source) => source.can_seek(),
#[cfg(all(feature = "minimp3", not(feature = "symphonia-mp3")))]
DecoderImpl::Mp3(source) => source.can_seek(),
#[cfg(feature = "symphonia")]
DecoderImpl::Symphonia(source) => source.can_seek(),
DecoderImpl::None(_) => false,
}
}
}
impl<R> Decoder<R>
@ -437,11 +421,6 @@ where
fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> {
self.0.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.0.can_seek()
}
}
impl<R> Iterator for LoopedDecoder<R>
@ -540,11 +519,6 @@ where
fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> {
self.0.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.0.can_seek()
}
}
/// Error that can happen when creating a decoder.

View file

@ -74,11 +74,6 @@ where
// as the seek only takes effect after the current frame is done
self.decoder.seek_samples(pos)?;
Ok(())
}
fn can_seek(&self) -> bool {
true
}
}
impl<R> Iterator for Mp3Decoder<R>

View file

@ -166,11 +166,6 @@ impl Source for SymphoniaDecoder {
Ok(_) => Ok(()),
}
}
#[inline]
fn can_seek(&self) -> bool {
true
}
}
impl Iterator for SymphoniaDecoder {

View file

@ -84,11 +84,6 @@ where
self.stream_reader.seek_absgp_pg(samples as u64)?;
Ok(())
}
#[inline]
fn can_seek(&self) -> bool {
true
}
}
impl<R> Iterator for VorbisDecoder<R>

View file

@ -135,11 +135,6 @@ where
let samples = pos.as_secs_f32() * self.sample_rate() as f32;
self.reader.reader.seek(samples as u32).map_err(SeekError::HoundDecoder)
}
#[inline]
fn can_seek(&self) -> bool {
true
}
}
impl<R> Iterator for WavDecoder<R>

View file

@ -108,23 +108,37 @@ where
}
#[inline]
fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> {
for source in &self.current_sources {
if !source.can_seek() {
return Err(SeekError::NotSupported {
underlying_source: "unknown, one of the sources added to the DynamicMixer",
});
}
}
for source in &mut self.current_sources {
source.try_seek(pos).expect("we just verified they can")
}
Ok(())
}
fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> {
Err(SeekError::NotSupported { underlying_source: std::any::type_name::<Self>() })
#[inline]
fn can_seek(&self) -> bool {
self.current_sources.iter().all(Source::can_seek)
// uncomment when #510 is implemented (query position of playback)
// let mut org_positions = Vec::with_capacity(self.current_sources.len());
// let mut encounterd_err = None;
//
// for source in &mut self.current_sources {
// let pos = /* source.playback_pos() */ todo!();
// if let Err(e) = source.try_seek(pos) {
// encounterd_err = Some(e);
// break;
// } else {
// // store pos in case we need to roll back
// org_positions.push(pos);
// }
// }
//
// if let Some(e) = encounterd_err {
// // rollback seeks that happend before err
// for (pos, source) in org_positions
// .into_iter()
// .zip(self.current_sources.iter_mut())
// {
// source.try_seek(pos)?;
// }
// Err(e)
// } else {
// Ok(())
// }
}
}

View file

@ -174,11 +174,6 @@ where
fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> {
self.current.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.current.can_seek()
}
}
impl<S> Iterator for SourcesQueueOutput<S>

View file

@ -101,8 +101,6 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -155,10 +155,8 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}
#[derive(Clone, Debug)]

View file

@ -247,10 +247,8 @@ where
Err(SeekError::NotSupported { underlying_source: std::any::type_name::<Self>() })
}
#[inline]
fn can_seek(&self) -> bool {
true
}
}
impl<I> Clone for Buffered<I>

View file

@ -146,8 +146,6 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -114,8 +114,6 @@ where
self.input.try_seek(pos_without_delay)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -95,8 +95,6 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -61,8 +61,6 @@ where
Err(SeekError::NotSupported { underlying_source: std::any::type_name::<Self>() })
}
#[inline]
fn can_seek(&self) -> bool {
true
}
}

View file

@ -60,8 +60,6 @@ where
Err(SeekError::NotSupported { underlying_source: std::any::type_name::<Self>() })
}
#[inline]
fn can_seek(&self) -> bool {
true
}
}

View file

@ -113,8 +113,6 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -147,16 +147,8 @@ where
}
}
#[inline]
fn can_seek(&self) -> bool {
if let Some(source) = &self.current_source {
source.can_seek()
} else {
// no seeking would happen in this case,
// so the seek operation cant fail
true
}
}
}
#[cfg(test)]

View file

@ -123,22 +123,21 @@ where
/// Will only attempt a seek if both underlying sources support seek.
#[inline]
fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> {
// if a source can not seek we call try_seek only on that source
// such that we get its SeekError::NotSupported error
if !self.input1.can_seek() {
self.input1.try_seek(pos)
} else if !self.input2.can_seek() {
self.input2.try_seek(pos)
} else {
self.input1.try_seek(pos)?;
self.input2.try_seek(pos)?;
Ok(())
}
}
fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> {
Err(SeekError::NotSupported {
underlying_source: std::any::type_name::<Self>(),
})
#[inline]
fn can_seek(&self) -> bool {
self.input1.can_seek() && self.input2.can_seek()
// uncomment when #510 is implemented (query position of playback)
// let org_pos = self.input1.playback_pos();
// self.input1.try_seek(pos)?;
//
// let res = self.input2.try_seek(pos);
// if res.is_err() { // rollback seek in input1
// self.input1.try_seek(org_pos)?;
// }
//
// res
}
}

View file

@ -358,11 +358,8 @@ where
/// Try to seek to a pos, returns [`SeekNotSupported`] if seeking is not
/// supported by the current source.
fn try_seek(&mut self, _: Duration) -> Result<(), SeekError>;
/// Returns if seeking is possible. If it is not [`try_seek`] will return
/// Err([`SeekNotSupported`])
fn can_seek(&self) -> bool;
}
// we might add decoders requiring new error types, would non_exhaustive
// this would break users builds
#[non_exhaustive]
@ -413,10 +410,8 @@ where
(**self).try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
(**self).can_seek()
}
}
impl<S> Source for Box<dyn Source<Item = S> + Send>
@ -448,10 +443,8 @@ where
(**self).try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
(**self).can_seek()
}
}
impl<S> Source for Box<dyn Source<Item = S> + Send + Sync>
@ -483,8 +476,6 @@ where
(**self).try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
(**self).can_seek()
}
}

View file

@ -123,8 +123,6 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -125,10 +125,8 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}
#[cfg(test)]

View file

@ -92,10 +92,8 @@ where
self.inner.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.inner.can_seek()
}
}
impl<I> Clone for Repeat<I>

View file

@ -103,8 +103,6 @@ where
self.inner.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.inner.can_seek()
}
}

View file

@ -66,8 +66,6 @@ impl Source for SineWave {
// of seeking
Ok(())
}
#[inline]
fn can_seek(&self) -> bool {
true
}
}

View file

@ -165,10 +165,8 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}
#[cfg(test)]

View file

@ -97,8 +97,6 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -125,8 +125,6 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -107,8 +107,6 @@ where
self.input.try_seek(pos_accounting_for_speedup)
}
#[inline]
fn can_seek(&self) -> bool {
true
}
}

View file

@ -96,8 +96,6 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -184,8 +184,6 @@ where
self.input.try_seek(pos)
}
#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}
}

View file

@ -153,15 +153,6 @@ where
Ok(())
}
}
#[inline]
fn can_seek(&self) -> bool {
if let Some(input) = self.inner.as_ref() {
input.inner().inner().inner().inner().can_seek()
} else {
true
}
}
}
#[derive(Clone, Debug)]
@ -175,11 +166,6 @@ impl<I> Take<I> {
pub fn inner_mut(&mut self) -> &mut I {
&mut self.iter
}
#[inline]
pub fn inner(&self) -> &I {
&self.iter
}
}
impl<I> Iterator for Take<I>

View file

@ -85,8 +85,6 @@ where
Ok(())
}
#[inline]
fn can_seek(&self) -> bool {
true
}
}

View file

@ -88,12 +88,9 @@ where
#[inline]
fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> {
Err(SeekError::NotSupported { underlying_source: std::any::type_name::<Self>() })
}
#[inline]
fn can_seek(&self) -> bool {
true
Err(SeekError::NotSupported {
underlying_source: std::any::type_name::<Self>(),
})
}
}