Skip to content

Commit a4db8fb

Browse files
committed
prepare for release
1 parent 5829581 commit a4db8fb

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

changelog.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# v0.8.2 - May 27, 2023
2+
3+
- Fix errors when streaming some ogg files
4+
5+
Known issues:
6+
7+
- Seeking can cause errors with short ogg files
8+
- Reverse playback of ogg files results in garbled sound
9+
110
# v0.8.1 - May 26, 2023
211

312
- Added `StaticSoundData::from_media_source`

crates/kira/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "kira"
3-
version = "0.8.1"
3+
version = "0.8.2"
44
authors = ["Andrew Minnich <aminnich3@gmail.com>"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"

crates/kira/src/sound/streaming/sound/decode_scheduler.rs

+34-18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) struct DecodeScheduler<Error: Send + 'static> {
3030
sample_rate: u32,
3131
num_frames: usize,
3232
transport: Transport,
33+
decoder_current_frame_index: usize,
3334
decoded_chunk: Option<DecodedChunk>,
3435
command_consumer: HeapConsumer<DecodeSchedulerCommand>,
3536
frame_producer: HeapProducer<TimestampedFrame>,
@@ -67,6 +68,7 @@ impl<Error: Send + 'static> DecodeScheduler<Error> {
6768
sample_rate,
6869
num_frames,
6970
),
71+
decoder_current_frame_index: 0,
7072
decoded_chunk: None,
7173
command_consumer,
7274
frame_producer,
@@ -141,24 +143,33 @@ impl<Error: Send + 'static> DecodeScheduler<Error> {
141143
return Ok(Frame::ZERO);
142144
}
143145
let index: usize = index.try_into().expect("could not convert i64 into usize");
144-
match self
145-
.decoded_chunk
146-
.as_ref()
147-
.and_then(|chunk| chunk.frame_at_index(index))
148-
{
149-
Some(frame) => Ok(frame),
150-
None => {
151-
let new_chunk_start_index = self.decoder.seek(index)?;
152-
let frames = self.decoder.decode()?;
153-
let chunk = DecodedChunk {
154-
start_index: new_chunk_start_index,
155-
frames,
156-
};
157-
let frame = chunk
158-
.frame_at_index(index)
159-
.expect("did not get expected frame after seeking decoder");
160-
self.decoded_chunk = Some(chunk);
161-
Ok(frame)
146+
// if the requested frame is already loaded, return it
147+
if let Some(chunk) = &self.decoded_chunk {
148+
if let Some(frame) = chunk.frame_at_index(index) {
149+
return Ok(frame);
150+
}
151+
}
152+
/*
153+
otherwise, seek to the requested index and decode chunks sequentially
154+
until we get the frame we want. just because we seek to an index does
155+
not mean the next decoded chunk will have the frame we want (or any frame
156+
at all, for that matter), so we may need to decode multiple chunks to
157+
get the frame we care about.
158+
*/
159+
if index < self.decoder_current_frame_index {
160+
self.decoder_current_frame_index = self.decoder.seek(index)?;
161+
}
162+
loop {
163+
let decoded_chunk = DecodedChunk {
164+
start_index: self.decoder_current_frame_index,
165+
frames: self.decoder.decode()?,
166+
};
167+
self.decoder_current_frame_index += decoded_chunk.frames.len();
168+
self.decoded_chunk = Some(decoded_chunk);
169+
if let Some(chunk) = &self.decoded_chunk {
170+
if let Some(frame) = chunk.frame_at_index(index) {
171+
return Ok(frame);
172+
}
162173
}
163174
}
164175
}
@@ -177,6 +188,11 @@ impl<Error: Send + 'static> DecodeScheduler<Error> {
177188

178189
fn seek_to_index(&mut self, index: i64) -> Result<(), Error> {
179190
self.transport.seek_to(index);
191+
self.decoder_current_frame_index = self.decoder.seek(if index < 0 {
192+
0
193+
} else {
194+
index.try_into().expect("could not convert i64 into usize")
195+
})?;
180196
Ok(())
181197
}
182198
}

0 commit comments

Comments
 (0)