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 14:51:57 +0300 |
commit | b161f56a5c1b2215111cbdd368eb5d931e84b530 (patch) | |
tree | cc6c7b610795e4e5aa1aa946849247d82e79d2bc /video | |
parent | 570eb7463a3bddea1e30370f09a30da1e4bf3131 (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/1052>
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 8adcfd2c..0ebdb690 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, |