mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-13 13:01:07 +00:00
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:
parent
805cd6c591
commit
4cda565a39
1 changed files with 27 additions and 0 deletions
|
@ -474,5 +474,32 @@ mod tests {
|
|||
res,
|
||||
&[(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]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue