mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-09-02 09:43:48 +00:00
tttocea708: don't panic if a new service would overflow
Account for the addition of the service header when calculating the free space of the packet. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2283>
This commit is contained in:
parent
3332af9a24
commit
880d15d698
2 changed files with 58 additions and 1 deletions
|
@ -145,7 +145,16 @@ impl Cea708ServiceWriter {
|
|||
gst::trace!(CAT, "service is full");
|
||||
break;
|
||||
}
|
||||
if service.len() + code.byte_len() > available_bytes {
|
||||
let service_header_bytes = if service.is_empty() {
|
||||
if service.number() >= 7 {
|
||||
2
|
||||
} else {
|
||||
1
|
||||
}
|
||||
} else {
|
||||
0
|
||||
};
|
||||
if service_header_bytes + service.len() + code.byte_len() > available_bytes {
|
||||
gst::trace!(CAT, "packet is full");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -243,3 +243,51 @@ fn test_tttocea708_output_gaps() {
|
|||
let event = h.pull_event().unwrap();
|
||||
assert_eq!(event.type_(), gst::EventType::Eos);
|
||||
}
|
||||
|
||||
/* Here we verify that the element does not crash on large input buffers */
|
||||
#[test]
|
||||
fn test_tttocea708_large_input() {
|
||||
init();
|
||||
|
||||
let mut h = gst_check::Harness::new_parse("tttocea708 mode=roll-up");
|
||||
h.set_src_caps_str("text/x-raw");
|
||||
h.set_sink_caps_str("closedcaption/x-cea-708,format=cc_data,framerate=60/1");
|
||||
|
||||
while h.events_in_queue() != 0 {
|
||||
let _event = h.pull_event().unwrap();
|
||||
}
|
||||
|
||||
let inbuf = new_timed_buffer(" This is going to be a very long#& buffer that will exceed the output length of a single DTVCCPacket.#&", 0.nseconds(), ClockTime::SECOND);
|
||||
assert_eq!(h.push(inbuf), Ok(gst::FlowSuccess::Ok));
|
||||
|
||||
h.push_event(gst::event::Eos::new());
|
||||
|
||||
loop {
|
||||
let outbuf = h.pull().unwrap();
|
||||
println!("pts {}", outbuf.pts().unwrap().display());
|
||||
if outbuf.pts().unwrap() + outbuf.duration().unwrap() >= 200_000_000.nseconds() {
|
||||
break;
|
||||
}
|
||||
|
||||
let data = outbuf.map_readable().unwrap();
|
||||
println!("data {:?}", &*data);
|
||||
assert_ne!(&*data, &PADDING);
|
||||
}
|
||||
|
||||
/* Padding */
|
||||
loop {
|
||||
let outbuf = h.pull().unwrap();
|
||||
println!("pts {}", outbuf.pts().unwrap().display());
|
||||
if outbuf.pts().unwrap() + outbuf.duration().unwrap() >= 1_000_000_000.nseconds() {
|
||||
break;
|
||||
}
|
||||
|
||||
let data = outbuf.map_readable().unwrap();
|
||||
assert_eq!(&*data, &PADDING);
|
||||
}
|
||||
|
||||
assert_eq!(h.events_in_queue(), 1);
|
||||
|
||||
let event = h.pull_event().unwrap();
|
||||
assert_eq!(event.type_(), gst::EventType::Eos);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue