gstreamer/buffer: Only unmap memory in buffer cursor seek impl if we have to move to a different memory

Prevents some unnecessary unmaps.
This commit is contained in:
Sebastian Dröge 2020-04-07 13:40:53 +03:00
parent 35f7c910a9
commit 2fbb10ec92

View file

@ -48,13 +48,6 @@ pub struct BufferRefCursor<T> {
macro_rules! define_seek_impl(
($get_buffer_ref:expr) => {
fn seek(&mut self, pos: io::SeekFrom) -> Result<u64, io::Error> {
if !self.map_info.memory.is_null() {
unsafe {
gst_sys::gst_memory_unmap(self.map_info.memory, &mut self.map_info);
self.map_info.memory = ptr::null_mut();
}
}
match pos {
io::SeekFrom::Start(off) => {
self.cur_offset = std::cmp::min(self.size, off);
@ -96,6 +89,14 @@ macro_rules! define_seek_impl(
let (idx, _, skip) = get_buffer_ref(self)
.find_memory(self.cur_offset as usize, None)
.expect("Failed to find memory");
if idx != self.cur_mem_idx && !self.map_info.memory.is_null() {
unsafe {
gst_sys::gst_memory_unmap(self.map_info.memory, &mut self.map_info);
self.map_info.memory = ptr::null_mut();
}
}
self.cur_mem_idx = idx;
self.cur_mem_offset = skip;