tttocea608: don't pad up to first input timestamp

When receiving data from a live upstream element, the first buffer
may have a non-0 timestamp (running time), and the element incorrectly
pushed padding buffers up to that timestamp, resulting in much confusion

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/527>
This commit is contained in:
Mathieu Duponchelle 2021-06-25 01:02:24 +02:00 committed by GStreamer Marge Bot
parent 9415c50200
commit 23219c3c09
2 changed files with 19 additions and 32 deletions

View file

@ -569,6 +569,11 @@ impl TtToCea608 {
let frame_no = pts.mul_div_round(fps_n, fps_d).unwrap().seconds();
if state.last_frame_no == 0 {
gst_debug!(CAT, obj: element, "Initial skip to frame no {}", frame_no);
state.last_frame_no = pts.mul_div_floor(fps_n, fps_d).unwrap().seconds();
}
state.max_frame_no = (pts + duration)
.mul_div_round(fps_n, fps_d)
.unwrap()
@ -809,6 +814,8 @@ impl TtToCea608 {
element: &super::TtToCea608,
buffer: gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
gst_log!(CAT, obj: element, "Handling {:?}", buffer);
let pts = buffer.pts().ok_or_else(|| {
gst::element_error!(
element,
@ -941,6 +948,18 @@ impl TtToCea608 {
);
let (timestamp, duration) = e.get();
if state.last_frame_no == 0 {
state.last_frame_no = timestamp.mul_div_floor(fps_n, fps_d).unwrap().seconds();
gst_debug!(
CAT,
obj: element,
"Initial skip to frame no {}",
state.last_frame_no
);
}
let frame_no = (timestamp + duration.unwrap())
.mul_div_round(fps_n, fps_d)
.unwrap()

View file

@ -68,16 +68,6 @@ fn test_one_timed_buffer_and_eos() {
assert_eq!(h.push(inbuf), Ok(gst::FlowSuccess::Ok));
loop {
let outbuf = h.pull().unwrap();
if outbuf.pts().unwrap() + outbuf.duration().unwrap() >= ClockTime::SECOND {
break;
}
let data = outbuf.map_readable().unwrap();
assert_eq!(&*data, &[0x80, 0x80]);
}
let expected: [(ClockTime, ClockTime, [u8; 2usize]); 7] = [
(
ClockTime::from_nseconds(1_000_000_000),
@ -361,17 +351,6 @@ fn test_one_timed_buffer_and_eos_roll_up2() {
let inbuf = new_timed_buffer(&"World", 2 * ClockTime::SECOND, ClockTime::from_nseconds(1));
assert_eq!(h.push(inbuf), Ok(gst::FlowSuccess::Ok));
/* Padding */
loop {
let outbuf = h.pull().unwrap();
if outbuf.pts().unwrap() + outbuf.duration().unwrap() >= ClockTime::SECOND {
break;
}
let data = outbuf.map_readable().unwrap();
assert_eq!(&*data, &[0x80, 0x80]);
}
let expected: [(ClockTime, ClockTime, [u8; 2usize]); 5] = [
(
ClockTime::from_nseconds(1_000_000_000),
@ -497,17 +476,6 @@ fn test_word_wrap_roll_up() {
let inbuf = new_timed_buffer(&"Hello World", ClockTime::SECOND, ClockTime::SECOND);
assert_eq!(h.push(inbuf), Ok(gst::FlowSuccess::Ok));
/* Padding */
loop {
let outbuf = h.pull().unwrap();
if outbuf.pts().unwrap() + outbuf.duration().unwrap() >= ClockTime::SECOND {
break;
}
let data = outbuf.map_readable().unwrap();
assert_eq!(&*data, &[0x80, 0x80]);
}
let expected: [(ClockTime, ClockTime, [u8; 2usize]); 11] = [
(
ClockTime::from_nseconds(1_000_000_000),