[gtk: 1/2] gtkmediafile: Only unmap the GstVideoFrame in the GBytes destroy notify
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 1/2] gtkmediafile: Only unmap the GstVideoFrame in the GBytes destroy notify
- Date: Sun, 27 Dec 2020 06:17:37 +0000 (UTC)
commit 6e108d310a2fe145938fc6d9fc875032122d0ab6
Author: Sebastian Dröge <sebastian centricular com>
Date: Sat Dec 26 14:26:23 2020 +0200
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.
modules/media/gtkgstsink.c | 12 +++++++++---
1 file 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]