diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2023-01-19 14:49:22 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2023-01-19 16:40:03 +0300 |
commit | 2a68be20001bab9b21fb31dd1db1630e6acff6fd (patch) | |
tree | e0ae7c7bd84898e4bb0ed4924378709179cc370a /video | |
parent | 3ea77d7a740013df8fc10fff9f9d200faa330a70 (diff) |
gtk4: Keep `GstGLMemory` alive as long as it is used inside GDK
Otherwise the texture might be released in the meantime and GDK would
use an invalid GL texture ID.
Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/287
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1053>
Diffstat (limited to 'video')
-rw-r--r-- | video/gtk4/src/sink/frame.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/video/gtk4/src/sink/frame.rs b/video/gtk4/src/sink/frame.rs index 8adcfd2c1..0ebdb690c 100644 --- a/video/gtk4/src/sink/frame.rs +++ b/video/gtk4/src/sink/frame.rs @@ -96,7 +96,7 @@ fn video_frame_to_memory_texture( #[cfg(any(target_os = "macos", feature = "gst_gl"))] fn video_frame_to_gl_texture( - frame: &gst_video::VideoFrame<gst_video::video_frame::Readable>, + frame: gst_video::VideoFrame<gst_video::video_frame::Readable>, cached_textures: &mut HashMap<usize, gdk::Texture>, used_textures: &mut HashSet<usize>, gdk_context: &gdk::GLContext, @@ -119,8 +119,17 @@ fn video_frame_to_gl_texture( sync_meta.wait(gst_context); let texture = unsafe { - gdk::GLTexture::new(gdk_context, texture_id as u32, width as i32, height as i32) - .upcast::<gdk::Texture>() + gdk::GLTexture::with_release_func( + gdk_context, + texture_id as u32, + width as i32, + height as i32, + move || { + // Unmap and drop the GStreamer GL texture once GTK is done with it and not earlier + drop(frame); + }, + ) + .upcast::<gdk::Texture>() }; cached_textures.insert(texture_id, texture.clone()); @@ -149,7 +158,7 @@ impl Frame { { if let (Some(gdk_ctx), Some(gst_ctx)) = (gdk_context, self.gst_context.as_ref()) { video_frame_to_gl_texture( - &self.frame, + self.frame, cached_textures, &mut used_textures, gdk_ctx, |