mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-15 22:11:01 +00:00
gl: Reset video frame size/stride/offset to 0 for GL mapped frames
The memory pointers are actually the GL texture IDs, and accessing them like raw video memory will read random memory areas. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1176>
This commit is contained in:
parent
c5672f12e1
commit
709c01ed65
2 changed files with 20 additions and 10 deletions
|
@ -18,7 +18,6 @@ rust-version = "1.63"
|
|||
|
||||
[dependencies]
|
||||
bitflags = "1.0"
|
||||
byteorder = "1"
|
||||
libc = "0.2"
|
||||
once_cell = "1.0"
|
||||
ffi = { package = "gstreamer-gl-sys", version = "0.19", path = "sys" }
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
use glib::translate::{from_glib, ToGlibPtr};
|
||||
use gst_video::video_frame::Readable;
|
||||
|
||||
use byteorder::{NativeEndian, ReadBytesExt};
|
||||
use std::mem;
|
||||
|
||||
pub trait VideoFrameGLExt {
|
||||
|
@ -76,7 +75,14 @@ impl<'a> VideoFrameGLExt for gst_video::VideoFrameRef<&'a gst::BufferRef> {
|
|||
if !res {
|
||||
Err(buffer)
|
||||
} else {
|
||||
Ok(gst_video::VideoFrame::from_glib_full(frame.assume_init()))
|
||||
let mut frame = frame.assume_init();
|
||||
// Reset size/stride/offset to 0 as the memory pointers
|
||||
// are the GL texture ID and accessing them would read
|
||||
// random memory.
|
||||
frame.info.size = 0;
|
||||
frame.info.stride.fill(0);
|
||||
frame.info.offset.fill(0);
|
||||
Ok(gst_video::VideoFrame::from_glib_full(frame))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,9 +123,14 @@ impl<'a> VideoFrameGLExt for gst_video::VideoFrameRef<&'a gst::BufferRef> {
|
|||
"Failed to fill in the values of GstVideoFrame"
|
||||
))
|
||||
} else {
|
||||
Ok(gst_video::VideoFrameRef::from_glib_full(
|
||||
frame.assume_init(),
|
||||
))
|
||||
let mut frame = frame.assume_init();
|
||||
// Reset size/stride/offset to 0 as the memory pointers
|
||||
// are the GL texture ID and accessing them would read
|
||||
// random memory.
|
||||
frame.info.size = 0;
|
||||
frame.info.stride.fill(0);
|
||||
frame.info.offset.fill(0);
|
||||
Ok(gst_video::VideoFrameRef::from_glib_full(frame))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,10 +147,10 @@ impl<'a> VideoFrameGLExt for gst_video::VideoFrameRef<&'a gst::BufferRef> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let mut data = self.plane_data(idx).ok()?;
|
||||
let id = &data.read_u32::<NativeEndian>().ok()?;
|
||||
|
||||
Some(*id)
|
||||
unsafe {
|
||||
let ptr = (*self.as_ptr()).data[idx as usize] as *const u32;
|
||||
Some(*ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue