Skip to content

Commit fb6b625

Browse files
committed
fix audio skip fail on macos
1 parent 1526bb3 commit fb6b625

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

crates/enc-avfoundation/src/mp4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl MP4Encoder {
246246
};
247247

248248
if !audio_input.is_ready_for_more_media_data() {
249-
return Err(QueueAudioFrameError::NotReady);
249+
return Ok(());
250250
}
251251

252252
let audio_desc = cat::audio::StreamBasicDesc::common_f32(

crates/recording/src/sources/audio_mixer.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl AudioMixer {
156156
.checked_sub(last_end.duration_since(self.timestamps))
157157
{
158158
let mut remaining = elapsed_since_last;
159+
159160
while remaining > Self::BUFFER_TIMEOUT {
160161
let chunk_samples =
161162
(Self::BUFFER_TIMEOUT.as_secs_f64() * rate as f64) as usize;
@@ -172,11 +173,7 @@ impl AudioMixer {
172173
}
173174

174175
let timestamp = last_end + (elapsed_since_last - remaining);
175-
dbg!(timestamp);
176-
source.buffer_last = Some((
177-
timestamp,
178-
Duration::from_secs_f64(chunk_samples as f64 / rate as f64),
179-
));
176+
source.buffer_last = Some((timestamp, Self::BUFFER_TIMEOUT));
180177
source.buffer.push_back((frame, timestamp));
181178

182179
remaining -= Self::BUFFER_TIMEOUT;
@@ -217,7 +214,6 @@ impl AudioMixer {
217214
frame.set_rate(source.info.rate() as u32);
218215

219216
let timestamp = buffer_last_timestamp + gap;
220-
dbg!(timestamp);
221217
source.buffer_last = Some((
222218
timestamp,
223219
Duration::from_secs_f64(silence_samples_count as f64 / rate as f64),
@@ -275,7 +271,6 @@ impl AudioMixer {
275271
frame.set_rate(source.info.rate() as u32);
276272

277273
let timestamp = start_timestamp + (elapsed_since_start - remaining);
278-
dbg!(timestamp);
279274
source.buffer_last = Some((
280275
timestamp,
281276
Duration::from_secs_f64(chunk_samples as f64 / rate as f64),

crates/timestamp/src/macos.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ use std::{
55
};
66

77
#[derive(Clone, Copy, Debug)]
8-
pub struct MachAbsoluteTimestamp(u64);
8+
pub struct MachAbsoluteTimestamp(
9+
// Nanoseconds
10+
u64,
11+
);
912

1013
impl MachAbsoluteTimestamp {
11-
pub fn new(value: u64) -> Self {
12-
Self(value)
14+
pub fn new(nanos: u64) -> Self {
15+
Self(nanos)
1316
}
1417

1518
pub fn now() -> Self {
@@ -37,7 +40,7 @@ impl Add<Duration> for MachAbsoluteTimestamp {
3740
let info = TimeBaseInfo::new();
3841
let freq = info.numer as f64 / info.denom as f64;
3942

40-
Self((self.0 as f64 + rhs.as_secs_f64() * freq) as u64)
43+
Self((self.0 as f64 + rhs.as_nanos() as f64 * freq) as u64)
4144
}
4245
}
4346

@@ -48,6 +51,19 @@ impl Sub<Duration> for MachAbsoluteTimestamp {
4851
let info = TimeBaseInfo::new();
4952
let freq = info.numer as f64 / info.denom as f64;
5053

51-
Self((self.0 as f64 - rhs.as_secs_f64() * freq) as u64)
54+
Self((self.0 as f64 - rhs.as_nanos() as f64 * freq) as u64)
55+
}
56+
}
57+
58+
#[cfg(test)]
59+
mod test {
60+
use super::*;
61+
62+
#[test]
63+
fn test() {
64+
let a = MachAbsoluteTimestamp::new(0);
65+
66+
dbg!(MachAbsoluteTimestamp::now());
67+
dbg!(a + Duration::from_secs(1));
5268
}
5369
}

0 commit comments

Comments
 (0)