diff --git a/utils/livesync/src/livesync/imp.rs b/utils/livesync/src/livesync/imp.rs index 4d9f0e4d..96e8f291 100644 --- a/utils/livesync/src/livesync/imp.rs +++ b/utils/livesync/src/livesync/imp.rs @@ -1053,7 +1053,16 @@ impl LiveSync { None => None, Some(Item::Buffer(buffer, timestamp, lateness)) => { - if self.buffer_is_early(&state, timestamp) { + // Synchronize on the first buffer with timestamps to not output it too early + if let Some(Timestamps { start, .. }) = + state.out_timestamp.is_none().then_some(timestamp).flatten() + { + state.out_timestamp = Some(Timestamps { start, end: start }); + state + .queue + .push_front(Item::Buffer(buffer, timestamp, lateness)); + return Ok(gst::FlowSuccess::Ok); + } else if self.buffer_is_early(&state, timestamp) { // Try this buffer again on the next iteration state .queue @@ -1261,8 +1270,11 @@ impl LiveSync { return false; }; - // When out_timestamp is set, we also have an out_buffer - let slack = state.out_buffer.as_deref().unwrap().duration().unwrap(); + // When out_timestamp is set, we also have an out_buffer unless it is the first buffer + let Some(ref out_buffer) = state.out_buffer else { + return false; + }; + let slack = out_buffer.duration().unwrap(); if timestamp.start < out_timestamp.end + slack { return false; diff --git a/utils/livesync/tests/livesync.rs b/utils/livesync/tests/livesync.rs index 1f0e2f1f..d82f4ee9 100644 --- a/utils/livesync/tests/livesync.rs +++ b/utils/livesync/tests/livesync.rs @@ -138,6 +138,8 @@ fn test_livesync(h: &mut gst_check::Harness, o: u64, singlesegment: bool) { h.push_from_src().unwrap(); h.push_from_src().unwrap(); assert_eq!(h.pull_event().unwrap().type_(), gst::EventType::StreamStart); + // Caps are only output once waiting for the first buffer has finished + h.crank_single_clock_wait().unwrap(); assert_eq!(h.pull_event().unwrap().type_(), gst::EventType::Caps); assert_eq!(h.pull_event().unwrap().type_(), gst::EventType::Segment); assert_crank_pull(h, o, 0, 0, gst::BufferFlags::DISCONT, singlesegment);