From 7fe13be564f1382114758f87743d189904885eff Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Fri, 14 Jan 2022 23:24:43 +0100 Subject: [PATCH] Fix audio file streaming --- audio/src/fetch/receive.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/audio/src/fetch/receive.rs b/audio/src/fetch/receive.rs index 5d193062..5d19722b 100644 --- a/audio/src/fetch/receive.rs +++ b/audio/src/fetch/receive.rs @@ -96,6 +96,16 @@ async fn receive_data( drop(request.streamer); + let bytes_remaining = request.length - actual_length; + if bytes_remaining > 0 { + { + let missing_range = Range::new(offset, bytes_remaining); + let mut download_status = shared.download_status.lock(); + download_status.requested.subtract_range(&missing_range); + shared.cond.notify_all(); + } + } + shared .number_of_open_requests .fetch_sub(1, Ordering::SeqCst); @@ -139,10 +149,7 @@ impl AudioFileFetch { } if offset + length > self.shared.file_size { - return Err(Error::out_of_range(format!( - "Range {} +{} exceeds file size {}", - offset, length, self.shared.file_size - ))); + length = self.shared.file_size - offset; } let mut ranges_to_request = RangeSet::new();