gstreamer: bufferlist: add another test for foreach_mut

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1446>
This commit is contained in:
Tim-Philipp Müller 2024-05-21 19:31:38 +01:00 committed by GStreamer Marge Bot
parent 805cd6c591
commit 4cda565a39

View file

@ -474,5 +474,32 @@ mod tests {
res, res,
&[(Some(ClockTime::ZERO), 0), (Some(3 * ClockTime::SECOND), 1)] &[(Some(ClockTime::ZERO), 0), (Some(3 * ClockTime::SECOND), 1)]
); );
// Try removing buffers from inside foreach_mut
let mut buffer_list = BufferList::new();
for i in 0..10 {
let buffer_list = buffer_list.get_mut().unwrap();
let mut buffer = Buffer::new();
buffer.get_mut().unwrap().set_pts(i * ClockTime::SECOND);
buffer_list.add(buffer);
}
assert_eq!(buffer_list.len(), 10);
let buffer_list_ref = buffer_list.make_mut();
buffer_list_ref.foreach_mut(|buf, _n| {
let keep_packet = (buf.pts().unwrap() / ClockTime::SECOND) % 3 != 0;
ControlFlow::Continue(keep_packet.then_some(buf))
});
assert_eq!(buffer_list.len(), 6);
let res = buffer_list
.iter()
.map(|buf| buf.pts().unwrap() / ClockTime::SECOND)
.collect::<Vec<_>>();
assert_eq!(res, &[1, 2, 4, 5, 7, 8]);
} }
} }