From 4e949ff5d7305235ff7bdcbdabcc6a6b10e6af3b Mon Sep 17 00:00:00 2001 From: dvdsk Date: Sun, 8 Oct 2023 13:34:05 +0200 Subject: [PATCH] removes can_seek in favor of rolling back seek operations (requires PR #510) --- src/buffer.rs | 6 ++--- src/conversions/channels.rs | 6 ----- src/conversions/sample.rs | 6 ----- src/conversions/sample_rate.rs | 6 ----- src/decoder/flac.rs | 5 ---- src/decoder/mod.rs | 26 ------------------ src/decoder/mp3.rs | 5 ---- src/decoder/symphonia.rs | 5 ---- src/decoder/vorbis.rs | 5 ---- src/decoder/wav.rs | 5 ---- src/dynamic_mixer.rs | 48 +++++++++++++++++++++------------ src/queue.rs | 5 ---- src/source/amplify.rs | 6 ++--- src/source/blt.rs | 6 ++--- src/source/buffered.rs | 6 ++--- src/source/channel_volume.rs | 6 ++--- src/source/delay.rs | 6 ++--- src/source/done.rs | 6 ++--- src/source/empty.rs | 6 ++--- src/source/empty_callback.rs | 6 ++--- src/source/fadein.rs | 6 ++--- src/source/from_iter.rs | 12 ++------- src/source/mix.rs | 33 +++++++++++------------ src/source/mod.rs | 23 +++++----------- src/source/pausable.rs | 6 ++--- src/source/periodic.rs | 6 ++--- src/source/repeat.rs | 6 ++--- src/source/samples_converter.rs | 6 ++--- src/source/sine.rs | 6 ++--- src/source/skip.rs | 6 ++--- src/source/skippable.rs | 6 ++--- src/source/spatial.rs | 6 ++--- src/source/speed.rs | 6 ++--- src/source/stoppable.rs | 6 ++--- src/source/take.rs | 6 ++--- src/source/uniform.rs | 14 ---------- src/source/zero.rs | 6 ++--- src/static_buffer.rs | 9 +++---- 38 files changed, 103 insertions(+), 242 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 5dda1d66..9bd97706 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -91,10 +91,8 @@ where Err(SeekError::NotSupported { underlying_source: std::any::type_name::() }) } - #[inline] - fn can_seek(&self) -> bool { - false - } + + } impl Iterator for SamplesBuffer diff --git a/src/conversions/channels.rs b/src/conversions/channels.rs index 25834c63..c42b0104 100644 --- a/src/conversions/channels.rs +++ b/src/conversions/channels.rs @@ -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 Iterator for ChannelCountConverter diff --git a/src/conversions/sample.rs b/src/conversions/sample.rs index 39fe3d8d..7ee97624 100644 --- a/src/conversions/sample.rs +++ b/src/conversions/sample.rs @@ -29,12 +29,6 @@ impl DataConverter { 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 Iterator for DataConverter diff --git a/src/conversions/sample_rate.rs b/src/conversions/sample_rate.rs index c059a6fe..36aa5a5a 100644 --- a/src/conversions/sample_rate.rs +++ b/src/conversions/sample_rate.rs @@ -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; diff --git a/src/decoder/flac.rs b/src/decoder/flac.rs index bf7dd9df..77fa73e7 100644 --- a/src/decoder/flac.rs +++ b/src/decoder/flac.rs @@ -85,11 +85,6 @@ where fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> { Err(SeekError::NotSupported { underlying_source: std::any::type_name::() }) } - - #[inline] - fn can_seek(&self) -> bool { - false - } } impl Iterator for FlacDecoder diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index 8566b38c..1fa7272a 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -179,22 +179,6 @@ impl DecoderImpl { }), } } - - 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 Decoder @@ -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 Iterator for LoopedDecoder @@ -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. diff --git a/src/decoder/mp3.rs b/src/decoder/mp3.rs index c001259d..78f19e8e 100644 --- a/src/decoder/mp3.rs +++ b/src/decoder/mp3.rs @@ -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 Iterator for Mp3Decoder diff --git a/src/decoder/symphonia.rs b/src/decoder/symphonia.rs index 0e426a27..7d69c316 100644 --- a/src/decoder/symphonia.rs +++ b/src/decoder/symphonia.rs @@ -166,11 +166,6 @@ impl Source for SymphoniaDecoder { Ok(_) => Ok(()), } } - - #[inline] - fn can_seek(&self) -> bool { - true - } } impl Iterator for SymphoniaDecoder { diff --git a/src/decoder/vorbis.rs b/src/decoder/vorbis.rs index 5b18ade8..033c6cda 100644 --- a/src/decoder/vorbis.rs +++ b/src/decoder/vorbis.rs @@ -84,11 +84,6 @@ where self.stream_reader.seek_absgp_pg(samples as u64)?; Ok(()) } - - #[inline] - fn can_seek(&self) -> bool { - true - } } impl Iterator for VorbisDecoder diff --git a/src/decoder/wav.rs b/src/decoder/wav.rs index 682f4732..0468db84 100644 --- a/src/decoder/wav.rs +++ b/src/decoder/wav.rs @@ -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 Iterator for WavDecoder diff --git a/src/dynamic_mixer.rs b/src/dynamic_mixer.rs index 0e0dd9b8..0db887ec 100644 --- a/src/dynamic_mixer.rs +++ b/src/dynamic_mixer.rs @@ -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(()) - } - - #[inline] - fn can_seek(&self) -> bool { - self.current_sources.iter().all(Source::can_seek) + fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> { + Err(SeekError::NotSupported { underlying_source: std::any::type_name::() }) + + // 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(()) + // } } } diff --git a/src/queue.rs b/src/queue.rs index e9f9bbd5..560fbfb5 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -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 Iterator for SourcesQueueOutput diff --git a/src/source/amplify.rs b/src/source/amplify.rs index 3b254002..bdb5324f 100644 --- a/src/source/amplify.rs +++ b/src/source/amplify.rs @@ -101,8 +101,6 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/blt.rs b/src/source/blt.rs index 1d32a99b..ac20307e 100644 --- a/src/source/blt.rs +++ b/src/source/blt.rs @@ -155,10 +155,8 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } #[derive(Clone, Debug)] diff --git a/src/source/buffered.rs b/src/source/buffered.rs index 1b720e31..908d9a30 100644 --- a/src/source/buffered.rs +++ b/src/source/buffered.rs @@ -247,10 +247,8 @@ where Err(SeekError::NotSupported { underlying_source: std::any::type_name::() }) } - #[inline] - fn can_seek(&self) -> bool { - true - } + + } impl Clone for Buffered diff --git a/src/source/channel_volume.rs b/src/source/channel_volume.rs index d1a724ad..ee60f952 100644 --- a/src/source/channel_volume.rs +++ b/src/source/channel_volume.rs @@ -146,8 +146,6 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/delay.rs b/src/source/delay.rs index 847b7dc3..d6cff305 100644 --- a/src/source/delay.rs +++ b/src/source/delay.rs @@ -114,8 +114,6 @@ where self.input.try_seek(pos_without_delay) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/done.rs b/src/source/done.rs index 06fb6f51..2ab03cbd 100644 --- a/src/source/done.rs +++ b/src/source/done.rs @@ -95,8 +95,6 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/empty.rs b/src/source/empty.rs index fa92a54c..5c9ae953 100644 --- a/src/source/empty.rs +++ b/src/source/empty.rs @@ -61,8 +61,6 @@ where Err(SeekError::NotSupported { underlying_source: std::any::type_name::() }) } - #[inline] - fn can_seek(&self) -> bool { - true - } + + } diff --git a/src/source/empty_callback.rs b/src/source/empty_callback.rs index dadfa14e..d003b4af 100644 --- a/src/source/empty_callback.rs +++ b/src/source/empty_callback.rs @@ -60,8 +60,6 @@ where Err(SeekError::NotSupported { underlying_source: std::any::type_name::() }) } - #[inline] - fn can_seek(&self) -> bool { - true - } + + } diff --git a/src/source/fadein.rs b/src/source/fadein.rs index 4c93bfc2..79a14c39 100644 --- a/src/source/fadein.rs +++ b/src/source/fadein.rs @@ -113,8 +113,6 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/from_iter.rs b/src/source/from_iter.rs index c3406762..67f64683 100644 --- a/src/source/from_iter.rs +++ b/src/source/from_iter.rs @@ -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)] diff --git a/src/source/mix.rs b/src/source/mix.rs index 7c54e414..adeb4dd3 100644 --- a/src/source/mix.rs +++ b/src/source/mix.rs @@ -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(()) - } - } - - #[inline] - fn can_seek(&self) -> bool { - self.input1.can_seek() && self.input2.can_seek() + fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> { + Err(SeekError::NotSupported { + underlying_source: std::any::type_name::(), + }) + + // 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 } } diff --git a/src/source/mod.rs b/src/source/mod.rs index fa7dcb18..b5e210ed 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -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 Source for Box + Send> @@ -448,10 +443,8 @@ where (**self).try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - (**self).can_seek() - } + + } impl Source for Box + Send + Sync> @@ -483,8 +476,6 @@ where (**self).try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - (**self).can_seek() - } + + } diff --git a/src/source/pausable.rs b/src/source/pausable.rs index ccd0b6af..05b3ead1 100644 --- a/src/source/pausable.rs +++ b/src/source/pausable.rs @@ -123,8 +123,6 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/periodic.rs b/src/source/periodic.rs index e2723c36..97671126 100644 --- a/src/source/periodic.rs +++ b/src/source/periodic.rs @@ -125,10 +125,8 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } #[cfg(test)] diff --git a/src/source/repeat.rs b/src/source/repeat.rs index be91b521..b9d39bd1 100644 --- a/src/source/repeat.rs +++ b/src/source/repeat.rs @@ -92,10 +92,8 @@ where self.inner.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.inner.can_seek() - } + + } impl Clone for Repeat diff --git a/src/source/samples_converter.rs b/src/source/samples_converter.rs index 28f99c09..637b7dea 100644 --- a/src/source/samples_converter.rs +++ b/src/source/samples_converter.rs @@ -103,8 +103,6 @@ where self.inner.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.inner.can_seek() - } + + } diff --git a/src/source/sine.rs b/src/source/sine.rs index 8c67c832..6c815b5f 100644 --- a/src/source/sine.rs +++ b/src/source/sine.rs @@ -66,8 +66,6 @@ impl Source for SineWave { // of seeking Ok(()) } - #[inline] - fn can_seek(&self) -> bool { - true - } + + } diff --git a/src/source/skip.rs b/src/source/skip.rs index 5fc8a6d3..e8ee170e 100644 --- a/src/source/skip.rs +++ b/src/source/skip.rs @@ -165,10 +165,8 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } #[cfg(test)] diff --git a/src/source/skippable.rs b/src/source/skippable.rs index c2051bba..c2413412 100644 --- a/src/source/skippable.rs +++ b/src/source/skippable.rs @@ -97,8 +97,6 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/spatial.rs b/src/source/spatial.rs index ca11c31e..1dc08c5b 100644 --- a/src/source/spatial.rs +++ b/src/source/spatial.rs @@ -125,8 +125,6 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/speed.rs b/src/source/speed.rs index 23e28bca..09db9168 100644 --- a/src/source/speed.rs +++ b/src/source/speed.rs @@ -107,8 +107,6 @@ where self.input.try_seek(pos_accounting_for_speedup) } - #[inline] - fn can_seek(&self) -> bool { - true - } + + } diff --git a/src/source/stoppable.rs b/src/source/stoppable.rs index a0bd69f7..af176858 100644 --- a/src/source/stoppable.rs +++ b/src/source/stoppable.rs @@ -96,8 +96,6 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/take.rs b/src/source/take.rs index 34ac1349..d843b495 100644 --- a/src/source/take.rs +++ b/src/source/take.rs @@ -184,8 +184,6 @@ where self.input.try_seek(pos) } - #[inline] - fn can_seek(&self) -> bool { - self.input.can_seek() - } + + } diff --git a/src/source/uniform.rs b/src/source/uniform.rs index 9a1ade4d..fcaee5c5 100644 --- a/src/source/uniform.rs +++ b/src/source/uniform.rs @@ -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 Take { pub fn inner_mut(&mut self) -> &mut I { &mut self.iter } - - #[inline] - pub fn inner(&self) -> &I { - &self.iter - } } impl Iterator for Take diff --git a/src/source/zero.rs b/src/source/zero.rs index 5a2bb71a..e1ceb3c9 100644 --- a/src/source/zero.rs +++ b/src/source/zero.rs @@ -85,8 +85,6 @@ where Ok(()) } - #[inline] - fn can_seek(&self) -> bool { - true - } + + } diff --git a/src/static_buffer.rs b/src/static_buffer.rs index aa356778..95184423 100644 --- a/src/static_buffer.rs +++ b/src/static_buffer.rs @@ -88,12 +88,9 @@ where #[inline] fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> { - Err(SeekError::NotSupported { underlying_source: std::any::type_name::() }) - } - - #[inline] - fn can_seek(&self) -> bool { - true + Err(SeekError::NotSupported { + underlying_source: std::any::type_name::(), + }) } }