From 362092e8ed3bc46dca0e20042dbb0f3dbf9a1292 Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Wed, 11 May 2022 18:12:39 +0800 Subject: [PATCH 42/42] waylandsink: Parse video size in propose_allocation() In some cases it would be called before set_caps(). Signed-off-by: Jeffy Chen --- ext/wayland/gstwaylandsink.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c index 5412b2ea..04b3194f 100644 --- a/ext/wayland/gstwaylandsink.c +++ b/ext/wayland/gstwaylandsink.c @@ -710,11 +710,10 @@ gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter) } static GstBufferPool * -gst_wayland_create_pool (GstWaylandSink * sink, GstCaps * caps) +gst_wayland_create_pool (GstWaylandSink * sink, GstCaps * caps, gsize size) { GstBufferPool *pool = NULL; GstStructure *structure; - gsize size = sink->video_info.size; GstAllocator *alloc; pool = g_object_new (gst_wayland_pool_get_type (), NULL); @@ -764,7 +763,7 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps) /* create a new pool for the new caps */ if (sink->pool) gst_object_unref (sink->pool); - sink->pool = gst_wayland_create_pool (sink, caps); + sink->pool = gst_wayland_create_pool (sink, caps, sink->video_info.size); if (!gst_wl_display_check_format_for_dmabuf (sink->display, format) && !gst_wl_display_check_format_for_shm (sink->display, format)) @@ -794,10 +793,15 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query) GstBufferPool *pool = NULL; gboolean need_pool; GstAllocator *alloc; + GstVideoInfo info; GstStructure *s; gint value; gst_query_parse_allocation (query, &caps, &need_pool); + if (!caps) + goto no_caps; + if (!gst_video_info_from_caps (&info, caps)) + goto invalid_caps; s = gst_caps_get_structure (caps, 0); if (gst_structure_get_int (s, "arm-afbc", &value) && value) { @@ -806,9 +810,9 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query) } if (need_pool) - pool = gst_wayland_create_pool (sink, caps); + pool = gst_wayland_create_pool (sink, caps, info.size); - gst_query_add_allocation_pool (query, pool, sink->video_info.size, 2, 0); + gst_query_add_allocation_pool (query, pool, info.size, 2, 0); if (pool) g_object_unref (pool); @@ -819,6 +823,16 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query) g_object_unref (alloc); return TRUE; +no_caps: + { + GST_DEBUG_OBJECT (bsink, "no caps specified"); + return FALSE; + } +invalid_caps: + { + GST_DEBUG_OBJECT (bsink, "invalid caps specified"); + return FALSE; + } } static void -- 2.20.1