Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: audio source captures with "late" frames #207

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions libwebrtc/src/native/audio_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use cxx::SharedPtr;
use std::{sync::Arc, time::Duration};
use tokio::{
sync::{Mutex as AsyncMutex, MutexGuard},
time::interval,
time::{interval, MissedTickBehavior},
};
use webrtc_sys::audio_track as sys_at;

Expand Down Expand Up @@ -90,7 +90,7 @@ impl NativeAudioSource {
fn next_frame<'a>(
&self,
inner: &'a mut MutexGuard<'_, AudioSourceInner>, // The lock musts be guarded by capture_frame
frame: &'a AudioFrame<'a>,
frame: &'a AudioFrame<'_>,
) -> Option<&'a [i16]> {
let available_data = inner.len + frame.data.len() - inner.read_offset;
if available_data >= self.samples_10ms {
Expand Down Expand Up @@ -131,10 +131,11 @@ impl NativeAudioSource {
}

let mut inner = self.inner.lock().await;
let mut interval = inner
.interval
.take()
.unwrap_or(interval(Duration::from_millis(10)));
let mut interval = inner.interval.take().unwrap_or_else(|| {
let mut interval = interval(Duration::from_millis(10));
interval.set_missed_tick_behavior(MissedTickBehavior::Skip);
interval
});

loop {
let Some(data) = self.next_frame(&mut inner, frame) else {
Expand Down