forked from mirrors/gstreamer-rs
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/1173>
This commit is contained in:
parent
d6cc452cf3
commit
dcfea9c35a
2 changed files with 20 additions and 10 deletions
|
@ -18,7 +18,6 @@ rust-version = "1.63"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
byteorder = "1"
|
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
once_cell = "1.0"
|
once_cell = "1.0"
|
||||||
ffi = { package = "gstreamer-gl-sys", path = "sys" }
|
ffi = { package = "gstreamer-gl-sys", path = "sys" }
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
use glib::translate::{from_glib, ToGlibPtr};
|
use glib::translate::{from_glib, ToGlibPtr};
|
||||||
use gst_video::video_frame::Readable;
|
use gst_video::video_frame::Readable;
|
||||||
|
|
||||||
use byteorder::{NativeEndian, ReadBytesExt};
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
pub trait VideoFrameGLExt {
|
pub trait VideoFrameGLExt {
|
||||||
|
@ -76,7 +75,14 @@ impl<'a> VideoFrameGLExt for gst_video::VideoFrameRef<&'a gst::BufferRef> {
|
||||||
if !res {
|
if !res {
|
||||||
Err(buffer)
|
Err(buffer)
|
||||||
} else {
|
} 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"
|
"Failed to fill in the values of GstVideoFrame"
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(gst_video::VideoFrameRef::from_glib_full(
|
let mut frame = frame.assume_init();
|
||||||
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;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut data = self.plane_data(idx).ok()?;
|
unsafe {
|
||||||
let id = &data.read_u32::<NativeEndian>().ok()?;
|
let ptr = (*self.as_ptr()).data[idx as usize] as *const u32;
|
||||||
|
Some(*ptr)
|
||||||
Some(*id)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue