From 2fbb10ec92d6890ef7793f3bd26f87808d7c7959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 7 Apr 2020 13:40:53 +0300 Subject: [PATCH] gstreamer/buffer: Only unmap memory in buffer cursor seek impl if we have to move to a different memory Prevents some unnecessary unmaps. --- gstreamer/src/buffer_cursor.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gstreamer/src/buffer_cursor.rs b/gstreamer/src/buffer_cursor.rs index 2c30659e3..88ae37459 100644 --- a/gstreamer/src/buffer_cursor.rs +++ b/gstreamer/src/buffer_cursor.rs @@ -48,13 +48,6 @@ pub struct BufferRefCursor { macro_rules! define_seek_impl( ($get_buffer_ref:expr) => { fn seek(&mut self, pos: io::SeekFrom) -> Result { - 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;