Skip to content

Commit

Permalink
fix: create audio_source interval in an async context
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Sep 4, 2023
1 parent c8badf8 commit b4d2f50
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions livekit-webrtc/src/native/audio_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl NativeAudioSource {
buf: vec![0; samples_10ms].into_boxed_slice(),
len: 0,
read_offset: 0,
interval: Some(interval(Duration::from_millis(10))),
interval: None, // interval must be created from a tokio runtime context
})),
sample_rate,
num_channels,
Expand Down Expand Up @@ -131,11 +131,14 @@ impl NativeAudioSource {
}

let mut inner = self.inner.lock().await;
let mut interval = inner.interval.take().unwrap(); // How can I avoid double mut borrow?
let mut interval = inner
.interval
.take()
.unwrap_or(interval(Duration::from_millis(10)));

loop {
let Some(data) = self.next_frame(&mut inner, frame) else {
inner.interval = Some(interval);
inner.interval = Some(interval); // Is there a better way to avoid double mut reference than taking the Option?
break;
};

Expand Down

0 comments on commit b4d2f50

Please sign in to comment.