Skip to content

Commit 78c9289

Browse files
committed
remove seek support for (lewton) vorbis
seek is broken, RustAudio/lewton#73. We could work around it by: - using unsafe to create an instance of Self - use mem::swap to turn the &mut self into a mut self - take out the underlying Read+Seek - make a new self and seek If this issue is fixed support use the implementation in commit: 3bafe32
1 parent 3bafe32 commit 78c9289

File tree

2 files changed

+15
-34
lines changed

2 files changed

+15
-34
lines changed

src/decoder/vorbis.rs

+13-32
Original file line numberDiff line numberDiff line change
@@ -76,39 +76,20 @@ where
7676
None
7777
}
7878

79+
/// seek is broken, https://github.com/RustAudio/lewton/issues/73.
80+
// We could work around it by:
81+
// - using unsafe to create an instance of Self
82+
// - use mem::swap to turn the &mut self into a mut self
83+
// - take out the underlying Read+Seek
84+
// - make a new self and seek
85+
//
86+
// If this issue is fixed support use the implementation in
87+
// commit: 3bafe32388b4eb7a48c6701e6c65044dc8c555e6
7988
#[inline]
80-
fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> {
81-
// note sample rate in vorbis encoding is constant
82-
let samples = pos.as_secs_f32() * self.sample_rate() as f32;
83-
self.stream_reader.seek_absgp_pg(samples as u64)?;
84-
85-
// first few frames (packets) sometimes fail to decode, if
86-
// that happens just retry a few times.
87-
let mut last_err = None;
88-
for _ in 0..10 {
89-
// 10 seemed to work best in testing
90-
let res = self.stream_reader.read_dec_packet_itl();
91-
match res {
92-
Ok(data) => {
93-
match data {
94-
Some(d) => self.current_data = d,
95-
None => self.current_data = Vec::new(),
96-
}
97-
// make sure the next seek returns the
98-
// sample for the correct speaker
99-
let to_skip = self.next % self.channels() as usize;
100-
for _ in 0..to_skip {
101-
self.next();
102-
}
103-
return Ok(());
104-
}
105-
Err(e) => last_err = Some(e),
106-
}
107-
}
108-
109-
Err(SeekError::LewtonDecoder(
110-
last_err.expect("is set if we get out of the for loop"),
111-
))
89+
fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> {
90+
Err(SeekError::NotSupported {
91+
underlying_source: std::any::type_name::<Self>(),
92+
})
11293
}
11394
}
11495

tests/seek.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ fn seek_does_not_break_channel_order() {
204204
is_silent(&samples, source.channels(), channel0),
205205
"channel0 should be silent,
206206
channel0 starts at idx: {channel0}
207-
seek offset: {offset:?}
207+
seek: {beep_start:?} + {offset:?}
208208
samples: {samples:?}"
209209
);
210210
let channel1 = (1 + channel_offset) % 2;
211211
assert!(
212212
!is_silent(&samples, source.channels(), channel1),
213213
"channel1 should not be silent,
214214
channel1; starts at idx: {channel1}
215-
seek offset: {offset:?}
215+
seek: {beep_start:?} + {offset:?}
216216
samples: {samples:?}"
217217
);
218218
}

0 commit comments

Comments
 (0)