1From 00a2a00ba8e95ad9d339cb9479e512c2439b1888 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Wed, 11 May 2022 18:12:39 +0800
4Subject: [PATCH 33/41] waylandsink: Parse video size in propose_allocation()
5
6In some cases it would be called before set_caps().
7
8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
9---
10 ext/wayland/gstwaylandsink.c | 24 +++++++++++++++++++-----
11 1 file changed, 19 insertions(+), 5 deletions(-)
12
13diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c
14index 262805e..183529a 100644
15--- a/ext/wayland/gstwaylandsink.c
16+++ b/ext/wayland/gstwaylandsink.c
17@@ -766,11 +766,10 @@ gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
18 }
19
20 static GstBufferPool *
21-gst_wayland_create_pool (GstWaylandSink * self, GstCaps * caps)
22+gst_wayland_create_pool (GstWaylandSink * self, GstCaps * caps, gsize size)
23 {
24   GstBufferPool *pool = NULL;
25   GstStructure *structure;
26-  gsize size = self->video_info.size;
27   GstAllocator *alloc;
28
29   pool = gst_wl_video_buffer_pool_new ();
30@@ -819,7 +818,7 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
31   /* create a new pool for the new caps */
32   if (self->pool)
33     gst_object_unref (self->pool);
34-  self->pool = gst_wayland_create_pool (self, caps);
35+  self->pool = gst_wayland_create_pool (self, caps, self->video_info.size);
36
37   use_dmabuf = gst_caps_features_contains (gst_caps_get_features (caps, 0),
38       GST_CAPS_FEATURE_MEMORY_DMABUF);
39@@ -858,10 +857,15 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
40   GstBufferPool *pool = NULL;
41   gboolean need_pool;
42   GstAllocator *alloc;
43+  GstVideoInfo info;
44   GstStructure *s;
45   gint value;
46
47   gst_query_parse_allocation (query, &caps, &need_pool);
48+  if (!caps)
49+    goto no_caps;
50+  if (!gst_video_info_from_caps (&info, caps))
51+    goto invalid_caps;
52
53   s = gst_caps_get_structure (caps, 0);
54   if (gst_structure_get_int (s, "arm-afbc", &value) && value) {
55@@ -870,9 +874,9 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
56   }
57
58   if (need_pool)
59-    pool = gst_wayland_create_pool (self, caps);
60+    pool = gst_wayland_create_pool (self, caps, info.size);
61
62-  gst_query_add_allocation_pool (query, pool, self->video_info.size, 2, 0);
63+  gst_query_add_allocation_pool (query, pool, info.size, 2, 0);
64   if (pool)
65     g_object_unref (pool);
66
67@@ -883,6 +887,16 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
68   g_object_unref (alloc);
69
70   return TRUE;
71+no_caps:
72+  {
73+    GST_DEBUG_OBJECT (bsink, "no caps specified");
74+    return FALSE;
75+  }
76+invalid_caps:
77+  {
78+    GST_DEBUG_OBJECT (bsink, "invalid caps specified");
79+    return FALSE;
80+  }
81 }
82
83 static void
84--
852.20.1
86
87