|
1 | 1 | use cap_media_info::AudioInfo; |
2 | 2 | use cap_timestamp::{Timestamp, Timestamps}; |
3 | 3 | use futures::channel::{mpsc, oneshot}; |
| 4 | +#[cfg(not(any(target_os = "macos", windows)))] |
| 5 | +use std::time::Instant; |
4 | 6 | use std::{ |
5 | 7 | collections::VecDeque, |
6 | 8 | sync::{ |
7 | 9 | Arc, |
8 | 10 | atomic::{AtomicBool, Ordering}, |
9 | 11 | }, |
10 | | - time::{Duration, Instant}, |
| 12 | + time::Duration, |
11 | 13 | }; |
12 | 14 | use tracing::{debug, info}; |
13 | 15 |
|
@@ -238,43 +240,10 @@ impl AudioMixer { |
238 | 240 | fn buffer_sources(&mut self, now: Timestamp) { |
239 | 241 | for source in &mut self.sources { |
240 | 242 | let rate = source.info.rate(); |
241 | | - let buffer_timeout = source.buffer_timeout; |
| 243 | + let _buffer_timeout = source.buffer_timeout; |
242 | 244 |
|
243 | | - if let Some(last) = source.buffer_last { |
244 | | - let last_end = last.0 + last.1; |
245 | | - if let Some(elapsed_since_last) = now |
246 | | - .duration_since(self.timestamps) |
247 | | - .checked_sub(last_end.duration_since(self.timestamps)) |
248 | | - { |
249 | | - let mut remaining = elapsed_since_last; |
250 | | - |
251 | | - while remaining > buffer_timeout { |
252 | | - let chunk_samples = samples_for_timeout(rate, buffer_timeout); |
253 | | - let frame_duration = duration_from_samples(chunk_samples, rate); |
254 | | - |
255 | | - let mut frame = ffmpeg::frame::Audio::new( |
256 | | - source.info.sample_format, |
257 | | - chunk_samples, |
258 | | - source.info.channel_layout(), |
259 | | - ); |
260 | | - frame.set_rate(source.info.rate() as u32); |
261 | | - |
262 | | - for i in 0..frame.planes() { |
263 | | - frame.data_mut(i).fill(0); |
264 | | - } |
265 | | - |
266 | | - let timestamp = last_end + (elapsed_since_last - remaining); |
267 | | - source.buffer_last = Some((timestamp, frame_duration)); |
268 | | - source.buffer.push_back(AudioFrame::new(frame, timestamp)); |
269 | | - |
270 | | - if frame_duration.is_zero() { |
271 | | - break; |
272 | | - } |
273 | | - |
274 | | - remaining = remaining.saturating_sub(frame_duration); |
275 | | - } |
276 | | - } |
277 | | - } |
| 245 | + // Do not inject silence based on wall-clock pacing. We only bridge actual gaps |
| 246 | + // when a new frame arrives (below), to keep emission data-driven. |
278 | 247 |
|
279 | 248 | while let Ok(Some(AudioFrame { |
280 | 249 | inner: frame, |
|
0 commit comments