Skip to content

Commit

Permalink
Merge pull request #579 from RustAudio/fix_hang_seek_on_empty_queue
Browse files Browse the repository at this point in the history
Fix hang seek on empty queue
  • Loading branch information
dvdsk authored May 23, 2024
2 parents 11221a8 + 3d61bdd commit ee73f6d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

# Version 0.18.1 (2024-05-23)

### Fixed
- Seek no longer hangs if the sink is empty.

# Version 0.18.0 (2024-05-05)

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rodio"
version = "0.18.0"
version = "0.18.1"
license = "MIT OR Apache-2.0"
description = "Audio playback library"
keywords = ["audio", "playback", "gamedev"]
Expand Down
4 changes: 4 additions & 0 deletions examples/seek_mp3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ fn main() {
sink.try_seek(Duration::from_secs(4)).unwrap();

sink.sleep_until_end();

// wont do anything since the sound has ended already
sink.try_seek(Duration::from_secs(5)).unwrap();
println!("seek example ended");
}
8 changes: 7 additions & 1 deletion src/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl SeekOrder {
S::Item: Sample + Send,
{
let res = maybe_seekable.try_seek(self.pos);
let _ignore_reciever_dropped = self.feedback.send(res);
let _ignore_receiver_dropped = self.feedback.send(res);
}
}

Expand Down Expand Up @@ -222,6 +222,12 @@ impl Sink {
pub fn try_seek(&self, pos: Duration) -> Result<(), SeekError> {
let (order, feedback) = SeekOrder::new(pos);
*self.controls.seek.lock().unwrap() = Some(order);

if self.sound_count.load(Ordering::Acquire) == 0 {
// No sound is playing, seek will not be performed
return Ok(());
}

match feedback.recv() {
Ok(seek_res) => seek_res,
// The feedback channel closed. Probably another seekorder was set
Expand Down
10 changes: 6 additions & 4 deletions tests/seek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rstest_reuse::{self, *};

#[template]
#[rstest]
// note: disabled, broken decoder see issue: #516
// note: disabled, broken decoder see issue: #516 and #539
// #[cfg_attr(feature = "symphonia-vorbis"), case("ogg", true, "symphonia")],
#[cfg_attr(
all(feature = "minimp3", not(feature = "symphonia-mp3")),
Expand All @@ -23,7 +23,8 @@ use rstest_reuse::{self, *};
case("flac", false, "claxon")
)]
#[cfg_attr(feature = "symphonia-mp3", case("mp3", true, "symphonia"))]
#[cfg_attr(feature = "symphonia-isomp4", case("m4a", true, "symphonia"))]
// note: disabled, broken decoder see issue: #577
// #[cfg_attr(feature = "symphonia-isomp4", case("m4a", true, "symphonia"))]
#[cfg_attr(feature = "symphonia-wav", case("wav", true, "symphonia"))]
#[cfg_attr(feature = "symphonia-flac", case("flac", true, "symphonia"))]
fn all_decoders(
Expand All @@ -35,14 +36,15 @@ fn all_decoders(

#[template]
#[rstest]
// note: disabled, broken decoder see issue: #516
// note: disabled, broken decoder see issue: #516 and #539
// #[cfg_attr(feature = "symphonia-vorbis"), case("ogg", true, "symphonia")],
#[cfg_attr(
all(feature = "wav", not(feature = "symphonia-wav")),
case("wav", "hound")
)]
#[cfg_attr(feature = "symphonia-mp3", case("mp3", "symphonia"))]
#[cfg_attr(feature = "symphonia-isomp4", case("m4a", "symphonia"))]
// note: disabled, broken decoder see issue: #577
// #[cfg_attr(feature = "symphonia-isomp4", case("m4a", "symphonia"))]
#[cfg_attr(feature = "symphonia-wav", case("wav", "symphonia"))]
#[cfg_attr(feature = "symphonia-flac", case("flac", "symphonia"))]
fn supported_decoders(#[case] format: &'static str, #[case] decoder_name: &'static str) {}
Expand Down

0 comments on commit ee73f6d

Please sign in to comment.