Skip to content

Commit

Permalink
removes can_seek in favor of rolling back seek operations (requires PR
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdsk committed Oct 8, 2023
1 parent c29b442 commit 4e949ff
Show file tree
Hide file tree
Showing 38 changed files with 103 additions and 242 deletions.
6 changes: 2 additions & 4 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 0 additions & 6 deletions src/conversions/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 0 additions & 6 deletions src/conversions/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 0 additions & 6 deletions src/conversions/sample_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 0 additions & 5 deletions src/decoder/flac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
26 changes: 0 additions & 26 deletions src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions src/decoder/mp3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 0 additions & 5 deletions src/decoder/symphonia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ impl Source for SymphoniaDecoder {
Ok(_) => Ok(()),
}
}

#[inline]
fn can_seek(&self) -> bool {
true
}
}

impl Iterator for SymphoniaDecoder {
Expand Down
5 changes: 0 additions & 5 deletions src/decoder/vorbis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 0 additions & 5 deletions src/decoder/wav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
48 changes: 31 additions & 17 deletions src/dynamic_mixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Self>() })

// 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(())
// }
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 2 additions & 4 deletions src/source/amplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ where
self.input.try_seek(pos)
}

#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}


}
6 changes: 2 additions & 4 deletions src/source/blt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,8 @@ where
self.input.try_seek(pos)
}

#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}


}

#[derive(Clone, Debug)]
Expand Down
6 changes: 2 additions & 4 deletions src/source/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 2 additions & 4 deletions src/source/channel_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ where
self.input.try_seek(pos)
}

#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}


}
6 changes: 2 additions & 4 deletions src/source/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ where
self.input.try_seek(pos_without_delay)
}

#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}


}
6 changes: 2 additions & 4 deletions src/source/done.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ where
self.input.try_seek(pos)
}

#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}


}
6 changes: 2 additions & 4 deletions src/source/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ where
Err(SeekError::NotSupported { underlying_source: std::any::type_name::<Self>() })
}

#[inline]
fn can_seek(&self) -> bool {
true
}


}
6 changes: 2 additions & 4 deletions src/source/empty_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ where
Err(SeekError::NotSupported { underlying_source: std::any::type_name::<Self>() })
}

#[inline]
fn can_seek(&self) -> bool {
true
}


}
6 changes: 2 additions & 4 deletions src/source/fadein.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ where
self.input.try_seek(pos)
}

#[inline]
fn can_seek(&self) -> bool {
self.input.can_seek()
}


}
12 changes: 2 additions & 10 deletions src/source/from_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
33 changes: 16 additions & 17 deletions src/source/mix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Self>(),
})

// 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
}
}
Loading

0 comments on commit 4e949ff

Please sign in to comment.