[gtk/4.0-backports: 12/53] gtkgstsink: Use video_frame_free also for the GL path




commit c2235cee2d8e60e205816de7e8aae3ffc7c12d62
Author: Jan Alexander Steffens (heftig) <jan steffens gmail com>
Date:   Mon Jan 25 22:38:45 2021 +0100

    gtkgstsink: Use video_frame_free also for the GL path
    
    The video frame needs to stay mapped while the texture is in use.
    
    Avoid using g_memdup because the structure is not supposed to be moved.

 modules/media/gtkgstsink.c | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/modules/media/gtkgstsink.c b/modules/media/gtkgstsink.c
index 7375525c60..c546ec7ff6 100644
--- a/modules/media/gtkgstsink.c
+++ b/modules/media/gtkgstsink.c
@@ -259,44 +259,43 @@ gtk_gst_sink_texture_from_buffer (GtkGstSink *self,
                                   GstBuffer  *buffer,
                                   double     *pixel_aspect_ratio)
 {
-  GstVideoFrame frame;
+  GstVideoFrame *frame = g_new (GstVideoFrame, 1);
   GdkTexture *texture;
 
   if (self->gdk_context &&
-      gst_video_frame_map (&frame, &self->v_info, buffer, GST_MAP_READ | GST_MAP_GL))
+      gst_video_frame_map (frame, &self->v_info, buffer, GST_MAP_READ | GST_MAP_GL))
     {
       texture = gdk_gl_texture_new (self->gdk_context,
-                                    *(guint *) frame.data[0],
-                                    frame.info.width,
-                                    frame.info.height,
-                                    (GDestroyNotify) gst_buffer_unref,
-                                    gst_buffer_ref (buffer));
+                                    *(guint *) frame->data[0],
+                                    frame->info.width,
+                                    frame->info.height,
+                                    (GDestroyNotify) video_frame_free,
+                                    frame);
 
-     *pixel_aspect_ratio = ((double) frame.info.par_n) / ((double) frame.info.par_d);
-
-      gst_video_frame_unmap (&frame);
+      *pixel_aspect_ratio = ((double) frame->info.par_n) / ((double) frame->info.par_d);
     }
-  else if (gst_video_frame_map (&frame, &self->v_info, buffer, GST_MAP_READ))
+  else if (gst_video_frame_map (frame, &self->v_info, buffer, GST_MAP_READ))
     {
       GBytes *bytes;
 
-      bytes = g_bytes_new_with_free_func (frame.data[0],
-                                          frame.info.height * frame.info.stride[0],
+      bytes = g_bytes_new_with_free_func (frame->data[0],
+                                          frame->info.height * frame->info.stride[0],
                                           (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)),
+                                          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]);
+                                        frame->info.stride[0]);
       g_bytes_unref (bytes);
 
-     *pixel_aspect_ratio = ((double) frame.info.par_n) / ((double) frame.info.par_d);
+      *pixel_aspect_ratio = ((double) frame->info.par_n) / ((double) frame->info.par_d);
     }
   else
     {
       GST_ERROR_OBJECT (self, "Could not convert buffer to texture.");
       texture = NULL;
+      g_free (frame);
     }
 
   return texture;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]