diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-01-27 01:11:54 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-01-27 01:11:54 +0000 |
commit | ec9159f98356d005c08e11e6d2599a2f76e4b96e (patch) | |
tree | 1e50a0874de5fc2e450758533ad3a5cc5739a80b | |
parent | f3d77d1c21ab2702fdf951f4544bf94759274305 (diff) | |
parent | 00fd60aaa8ceb11b193c2b340c565f342799e387 (diff) | |
download | gtk+-ec9159f98356d005c08e11e6d2599a2f76e4b96e.tar.gz |
Merge branch 'gst-vaapi-fix-pre' into 'master'
Minor fixes to gtkgstsink
See merge request GNOME/gtk!3120
-rw-r--r-- | modules/media/gtkgstsink.c | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/modules/media/gtkgstsink.c b/modules/media/gtkgstsink.c index 1fb6719ee4..c546ec7ff6 100644 --- a/modules/media/gtkgstsink.c +++ b/modules/media/gtkgstsink.c @@ -172,6 +172,7 @@ gtk_gst_sink_propose_allocation (GstBaseSink *bsink, GstCaps *caps; guint size; gboolean need_pool; + GstVideoInfo info; if (!self->gst_context) return FALSE; @@ -187,22 +188,20 @@ gtk_gst_sink_propose_allocation (GstBaseSink *bsink, if (!gst_caps_features_contains (gst_caps_get_features (caps, 0), GST_CAPS_FEATURE_MEMORY_GL_MEMORY)) return FALSE; - if (need_pool) + if (!gst_video_info_from_caps (&info, caps)) { - GstVideoInfo info; + GST_DEBUG_OBJECT (self, "invalid caps specified"); + return FALSE; + } - if (!gst_video_info_from_caps (&info, caps)) - { - GST_DEBUG_OBJECT (self, "invalid caps specified"); - return FALSE; - } + /* the normal size of a frame */ + size = info.size; + if (need_pool) + { GST_DEBUG_OBJECT (self, "create new pool"); pool = gst_gl_buffer_pool_new (self->gst_context); - /* the normal size of a frame */ - size = info.size; - config = gst_buffer_pool_get_config (pool); gst_buffer_pool_config_set_params (config, caps, size, 0, 0); @@ -212,12 +211,13 @@ gtk_gst_sink_propose_allocation (GstBaseSink *bsink, gst_object_unref (pool); return FALSE; } - - /* we need at least 2 buffer because we hold on to the last one */ - gst_query_add_allocation_pool (query, pool, size, 2, 0); - gst_object_unref (pool); } + /* we need at least 2 buffer because we hold on to the last one */ + gst_query_add_allocation_pool (query, pool, size, 2, 0); + if (pool) + gst_object_unref (pool); + /* we also support various metadata */ gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, 0); @@ -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)); - - *pixel_aspect_ratio = ((double) frame.info.par_n) / ((double) frame.info.par_d); + *(guint *) frame->data[0], + frame->info.width, + frame->info.height, + (GDestroyNotify) video_frame_free, + frame); - 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; |