diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2020-12-26 14:26:23 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2020-12-26 14:26:23 +0200 |
commit | 6e108d310a2fe145938fc6d9fc875032122d0ab6 (patch) | |
tree | 6c064d474b6b79cf92c18a40897d8336a7f72bda | |
parent | 9c84fa127a33e33e8dc5e93adb5e40d3a46b2dbc (diff) | |
download | gtk+-6e108d310a2fe145938fc6d9fc875032122d0ab6.tar.gz |
gtkmediafile: Only unmap the GstVideoFrame in the GBytes destroy notify
The memory pointed to by GstVideoFrame::plane_data becomes invalid after
unmapping causing the GBytes to point at some random memory if the
unmapping is not deferred until its destroy notify.
When the GStreamer buffer is backed by normal system memory this is not
a problem but if it is backed by e.g. an OpenGL texture, dmabuf or some
other hardware-specific memory this will otherwise cause interesting
problems.
-rw-r--r-- | modules/media/gtkgstsink.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/modules/media/gtkgstsink.c b/modules/media/gtkgstsink.c index 4959bb86f8..e923ea88d6 100644 --- a/modules/media/gtkgstsink.c +++ b/modules/media/gtkgstsink.c @@ -111,6 +111,13 @@ gtk_gst_memory_format_from_video (GstVideoFormat format) } } +static void +video_frame_free (GstVideoFrame *frame) +{ + gst_video_frame_unmap (frame); + g_free (frame); +} + static GdkTexture * gtk_gst_sink_texture_from_buffer (GtkGstSink *self, GstBuffer *buffer) @@ -124,15 +131,14 @@ gtk_gst_sink_texture_from_buffer (GtkGstSink *self, bytes = g_bytes_new_with_free_func (frame.data[0], frame.info.width * frame.info.stride[0], - (GDestroyNotify) gst_buffer_unref, - gst_buffer_ref (buffer)); + (GDestroyNotify) video_frame_free, + g_memdup (&frame, sizeof (frame))); texture = gdk_memory_texture_new (frame.info.width, frame.info.height, gtk_gst_memory_format_from_video (GST_VIDEO_FRAME_FORMAT (&frame)), bytes, frame.info.stride[0]); g_bytes_unref (bytes); - gst_video_frame_unmap (&frame); return texture; } |