@@ -15,7 +15,7 @@ use tracing::debug;
1515// Current problem is generating an output timestamp that lines up with the input's timestamp
1616
1717struct MixerSource {
18- rx : Receiver < ( ffmpeg:: frame:: Audio , Timestamp ) > ,
18+ rx : std :: iter :: Peekable < flume :: IntoIter < ( ffmpeg:: frame:: Audio , Timestamp ) > > ,
1919 info : AudioInfo ,
2020 buffer : VecDeque < ( ffmpeg:: frame:: Audio , Timestamp ) > ,
2121 buffer_last : Option < ( Timestamp , Duration ) > ,
@@ -41,7 +41,7 @@ impl AudioMixerBuilder {
4141 pub fn add_source ( & mut self , info : AudioInfo , rx : Receiver < ( ffmpeg:: frame:: Audio , Timestamp ) > ) {
4242 self . sources . push ( MixerSource {
4343 info,
44- rx,
44+ rx : rx . into_iter ( ) . peekable ( ) ,
4545 buffer : VecDeque :: new ( ) ,
4646 buffer_last : None ,
4747 } ) ;
@@ -143,14 +143,14 @@ impl AudioMixer {
143143 48_000 ,
144144 2 ,
145145 ) ;
146- pub const BUFFER_TIMEOUT : Duration = Duration :: from_millis ( 10 ) ;
146+ pub const BUFFER_TIMEOUT : Duration = Duration :: from_millis ( 200 ) ;
147147
148148 fn buffer_sources ( & mut self , now : Timestamp ) {
149149 for source in & mut self . sources {
150150 let rate = source. info . rate ( ) ;
151151
152152 if let Some ( last) = source. buffer_last {
153- let last_end = & last. 0 + last. 1 ;
153+ let last_end = last. 0 + last. 1 ;
154154 if let Some ( elapsed_since_last) = now
155155 . duration_since ( self . timestamps )
156156 . checked_sub ( last_end. duration_since ( self . timestamps ) )
@@ -165,13 +165,14 @@ impl AudioMixer {
165165 chunk_samples,
166166 source. info . channel_layout ( ) ,
167167 ) ;
168+ frame. set_rate ( source. info . rate ( ) as u32 ) ;
169+
168170 for i in 0 ..frame. planes ( ) {
169171 frame. data_mut ( i) . fill ( 0 ) ;
170172 }
171173
172- frame. set_rate ( source. info . rate ( ) as u32 ) ;
173-
174174 let timestamp = last_end + ( elapsed_since_last - remaining) ;
175+ dbg ! ( timestamp) ;
175176 source. buffer_last = Some ( (
176177 timestamp,
177178 Duration :: from_secs_f64 ( chunk_samples as f64 / rate as f64 ) ,
@@ -183,7 +184,7 @@ impl AudioMixer {
183184 }
184185 }
185186
186- while let Ok ( ( frame, timestamp) ) = source. rx . try_recv ( ) {
187+ while let Some ( ( frame, timestamp) ) = source. rx . next ( ) {
187188 // if gap between incoming and last, insert silence
188189 if let Some ( ( buffer_last_timestamp, buffer_last_duration) ) = source. buffer_last {
189190 let timestamp_elapsed = timestamp. duration_since ( self . timestamps ) ;
@@ -216,6 +217,7 @@ impl AudioMixer {
216217 frame. set_rate ( source. info . rate ( ) as u32 ) ;
217218
218219 let timestamp = buffer_last_timestamp + gap;
220+ dbg ! ( timestamp) ;
219221 source. buffer_last = Some ( (
220222 timestamp,
221223 Duration :: from_secs_f64 ( silence_samples_count as f64 / rate as f64 ) ,
@@ -273,6 +275,7 @@ impl AudioMixer {
273275 frame. set_rate ( source. info . rate ( ) as u32 ) ;
274276
275277 let timestamp = start_timestamp + ( elapsed_since_start - remaining) ;
278+ dbg ! ( timestamp) ;
276279 source. buffer_last = Some ( (
277280 timestamp,
278281 Duration :: from_secs_f64 ( chunk_samples as f64 / rate as f64 ) ,
0 commit comments