From 4a22cc8fb3762001563dec54553a8d446c980e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Wed, 13 Dec 2023 10:20:33 +0100 Subject: [PATCH] va: no need to provide a buffer size for VA pool VA drivers allocate surfaces given their properties, so there's no need to provide a buffer size to the VA pool. Though, the buffer size is provided by the driver, or the canonical size is used for single planed surfaces. This patch removes the need to provide a size for the function gst_va_pool_new_with_config() and adds a helper method to retrieve the surface size, gst_va_pool_get_buffer_size(). Also change the callers accordingly. Changes for custom VA pool creation will be addressed in the following commits. Part-of: --- girs/GstVa-1.0.gir | 22 ++++++++++--- .../gst-libs/gst/va/gstvapool.c | 33 ++++++++++++++++--- .../gst-libs/gst/va/gstvapool.h | 4 ++- .../gst-plugins-bad/sys/msdk/gstmsdkdec.c | 4 +-- .../gst-plugins-bad/sys/msdk/gstmsdkenc.c | 5 ++- .../gst-plugins-bad/sys/msdk/gstmsdkvpp.c | 6 ++-- .../gst-plugins-bad/sys/qsv/gstqsvencoder.cpp | 6 ++-- .../gst-plugins-bad/sys/va/gstvaav1dec.c | 4 +-- .../gst-plugins-bad/sys/va/gstvabaseenc.c | 25 +++++--------- .../sys/va/gstvabasetransform.c | 28 ++++------------ .../gst-plugins-bad/sys/va/gstvacompositor.c | 13 ++++---- .../gst-plugins-bad/sys/va/gstvaencoder.c | 7 +--- 12 files changed, 81 insertions(+), 76 deletions(-) diff --git a/girs/GstVa-1.0.gir b/girs/GstVa-1.0.gir index 930fb410de..49f671b4cd 100644 --- a/girs/GstVa-1.0.gir +++ b/girs/GstVa-1.0.gir @@ -794,10 +794,6 @@ the most widely used VA drivers. the #GstCaps of the buffers handled by the new pool. - - the size of the frames to hold. - - minimum number of frames to create. @@ -825,6 +821,24 @@ the most widely used VA drivers. + + Helper function to retrieve the VA surface size provided by @pool. + + + whether the surface size was retrieved. + + + + + a #GstBufferPool + + + + the declared surface size + + + + Retuns: %TRUE if @pool always add #GstVideoMeta to its buffers. Otherwise, %FALSE. diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvapool.c b/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvapool.c index 3a82c9cada..2530cf1fbb 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvapool.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvapool.c @@ -465,7 +465,6 @@ gst_buffer_pool_config_set_va_alignment (GstStructure * config, gboolean gst_va_pool_requires_video_meta (GstBufferPool * pool) { - g_return_val_if_fail (GST_IS_VA_POOL (pool), FALSE); return GST_VA_POOL (pool)->force_videometa; @@ -474,7 +473,6 @@ gst_va_pool_requires_video_meta (GstBufferPool * pool) /** * gst_va_pool_new_with_config: * @caps: the #GstCaps of the buffers handled by the new pool. - * @size: the size of the frames to hold. * @min_buffers: minimum number of frames to create. * @max_buffers: maximum number of frames to create. * @usage_hint: VA usage hint @@ -490,7 +488,7 @@ gst_va_pool_requires_video_meta (GstBufferPool * pool) * Since: 1.22 */ GstBufferPool * -gst_va_pool_new_with_config (GstCaps * caps, guint size, guint min_buffers, +gst_va_pool_new_with_config (GstCaps * caps, guint min_buffers, guint max_buffers, guint usage_hint, GstVaFeature use_derived, GstAllocator * allocator, GstAllocationParams * alloc_params) { @@ -500,8 +498,8 @@ gst_va_pool_new_with_config (GstCaps * caps, guint size, guint min_buffers, pool = gst_va_pool_new (); config = gst_buffer_pool_get_config (pool); - gst_buffer_pool_config_set_params (config, caps, size, min_buffers, - max_buffers); + /* ignore the size since it's calculated by the driver */ + gst_buffer_pool_config_set_params (config, caps, 0, min_buffers, max_buffers); gst_buffer_pool_config_set_va_allocation_params (config, usage_hint, use_derived); gst_buffer_pool_config_set_allocator (config, allocator, alloc_params); @@ -512,3 +510,28 @@ gst_va_pool_new_with_config (GstCaps * caps, guint size, guint min_buffers, return pool; } + +/** + * gst_va_pool_get_buffer_size: + * @pool: a #GstBufferPool + * @size: (out) (allow-null-none): the declared surface size + * + * Helper function to retrieve the VA surface size provided by @pool. + * + * Returns: whether the surface size was retrieved. + * + * Since: 1.24 + */ +gboolean +gst_va_pool_get_buffer_size (GstBufferPool * pool, guint * size) +{ + gboolean ret; + GstStructure *config; + + g_return_val_if_fail (GST_IS_VA_POOL (pool), FALSE); + + config = gst_buffer_pool_get_config (pool); + ret = gst_buffer_pool_config_get_params (config, NULL, size, NULL, NULL); + gst_structure_free (config); + return ret && *size > 0; +} diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvapool.h b/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvapool.h index 86fe9dc60c..64f437aa0b 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvapool.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/va/gstvapool.h @@ -48,12 +48,14 @@ void gst_buffer_pool_config_set_va_alignment (GstStructure * con const GstVideoAlignment * align); GST_VA_API GstBufferPool * gst_va_pool_new_with_config (GstCaps * caps, - guint size, guint min_buffers, guint max_buffers, guint usage_hint, GstVaFeature use_derived, GstAllocator * allocator, GstAllocationParams * alloc_params); +GST_VA_API +gboolean gst_va_pool_get_buffer_size (GstBufferPool * pool, + guint * size); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c index fb9d9cbb5d..4a3e2170a8 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c @@ -1772,9 +1772,7 @@ gst_msdk_create_va_pool (GstMsdkDec * thiz, GstVideoInfo * info, caps = gst_video_info_to_caps (info); } - pool = - gst_va_pool_new_with_config (caps, - GST_VIDEO_INFO_SIZE (info), num_buffers, num_buffers, + pool = gst_va_pool_new_with_config (caps, num_buffers, num_buffers, VA_SURFACE_ATTRIB_USAGE_HINT_DECODER, GST_VA_FEATURE_AUTO, allocator, &alloc_params); diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c index b2700651a4..a6b5a2395f 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c @@ -1200,9 +1200,8 @@ gst_msdk_create_va_pool (GstMsdkEnc * thiz, GstVideoInfo * info, } else aligned_caps = gst_video_info_to_caps (info); - pool = - gst_va_pool_new_with_config (aligned_caps, GST_VIDEO_INFO_SIZE (info), - num_buffers, 0, VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC, GST_VA_FEATURE_AUTO, + pool = gst_va_pool_new_with_config (aligned_caps, num_buffers, 0, + VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC, GST_VA_FEATURE_AUTO, allocator, &alloc_params); gst_object_unref (allocator); diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c index 24102f8053..9f8ddf441b 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c @@ -429,10 +429,8 @@ gst_msdk_create_va_pool (GstMsdkVPP * thiz, GstVideoInfo * info, } else aligned_caps = gst_video_info_to_caps (info); - pool = - gst_va_pool_new_with_config (aligned_caps, - GST_VIDEO_INFO_SIZE (info), min_buffers, 0, - usage_hint, GST_VA_FEATURE_AUTO, allocator, &alloc_params); + pool = gst_va_pool_new_with_config (aligned_caps, min_buffers, 0, usage_hint, + GST_VA_FEATURE_AUTO, allocator, &alloc_params); gst_object_unref (allocator); gst_caps_unref (aligned_caps); diff --git a/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp b/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp index 4c3fa7418b..c33805e8d2 100644 --- a/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp +++ b/subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp @@ -981,8 +981,7 @@ gst_qsv_encoder_prepare_va_pool (GstQsvEncoder * self, gst_allocation_params_init (¶ms); - priv->internal_pool = gst_va_pool_new_with_config (caps, - GST_VIDEO_INFO_SIZE (aligned_info), 0, 0, + priv->internal_pool = gst_va_pool_new_with_config (caps, 0, 0, VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC, GST_VA_FEATURE_AUTO, allocator, ¶ms); gst_object_unref (allocator); @@ -1592,8 +1591,7 @@ gst_qsv_encoder_propose_allocation (GstVideoEncoder * encoder, GstQuery * query) return FALSE; } - pool = gst_va_pool_new_with_config (caps, - GST_VIDEO_INFO_SIZE (&info), priv->surface_pool->len, 0, + pool = gst_va_pool_new_with_config (caps, priv->surface_pool->len, 0, VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC, GST_VA_FEATURE_AUTO, allocator, ¶ms); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c b/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c index 9852547605..5730d2ac96 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c @@ -293,8 +293,8 @@ _create_internal_pool (GstVaAV1Dec * self, gint width, gint height) usage_hint = va_get_surface_usage_hint (base->display, VAEntrypointVLD, GST_PAD_SRC, FALSE); - pool = gst_va_pool_new_with_config (caps, GST_VIDEO_INFO_SIZE (&info), - 1, 0, usage_hint, GST_VA_FEATURE_AUTO, allocator, ¶ms); + pool = gst_va_pool_new_with_config (caps, 1, 0, usage_hint, + GST_VA_FEATURE_AUTO, allocator, ¶ms); gst_clear_caps (&caps); gst_object_unref (allocator); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c b/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c index 9d112a934f..082edbea74 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c @@ -201,7 +201,7 @@ _get_sinkpad_pool (GstElement * element, gpointer data) GstVaBaseEnc *base = GST_VA_BASE_ENC (element); GstAllocator *allocator; GstAllocationParams params = { 0, }; - guint size, usage_hint; + guint usage_hint; GArray *surface_formats = NULL; GstCaps *caps = NULL; @@ -219,8 +219,6 @@ _get_sinkpad_pool (GstElement * element, gpointer data) gst_allocation_params_init (¶ms); - size = GST_VIDEO_INFO_SIZE (&base->in_info); - surface_formats = gst_va_encoder_get_surface_formats (base->encoder); allocator = gst_va_allocator_new (base->display, surface_formats); @@ -228,8 +226,8 @@ _get_sinkpad_pool (GstElement * element, gpointer data) usage_hint = va_get_surface_usage_hint (base->display, VAEntrypointEncSlice, GST_PAD_SINK, FALSE); - base->priv->raw_pool = gst_va_pool_new_with_config (caps, size, 1, 0, - usage_hint, GST_VA_FEATURE_AUTO, allocator, ¶ms); + base->priv->raw_pool = gst_va_pool_new_with_config (caps, 1, 0, usage_hint, + GST_VA_FEATURE_AUTO, allocator, ¶ms); gst_clear_caps (&caps); if (!base->priv->raw_pool) { @@ -356,38 +354,33 @@ gst_va_base_enc_propose_allocation (GstVideoEncoder * venc, GstQuery * query) GstAllocationParams params = { 0, }; GstBufferPool *pool; GstCaps *caps; - GstVideoInfo info; gboolean need_pool = FALSE; - guint size, usage_hint; + guint size = 0, usage_hint; gst_query_parse_allocation (query, &caps, &need_pool); if (!caps) return FALSE; - if (!gst_video_info_from_caps (&info, caps)) { - GST_ERROR_OBJECT (base, "Cannot parse caps %" GST_PTR_FORMAT, caps); - return FALSE; - } - usage_hint = va_get_surface_usage_hint (base->display, VAEntrypointEncSlice, GST_PAD_SINK, gst_video_is_dma_drm_caps (caps)); - size = GST_VIDEO_INFO_SIZE (&info); - gst_allocation_params_init (¶ms); if (!(allocator = _allocator_from_caps (base, caps))) return FALSE; - pool = gst_va_pool_new_with_config (caps, size, 1, 0, usage_hint, + pool = gst_va_pool_new_with_config (caps, 1, 0, usage_hint, GST_VA_FEATURE_AUTO, allocator, ¶ms); if (!pool) { gst_object_unref (allocator); goto config_failed; } + if (!gst_va_pool_get_buffer_size (pool, &size)) + goto config_failed; + gst_query_add_allocation_param (query, allocator, ¶ms); - gst_query_add_allocation_pool (query, pool, size, 0, 0); + gst_query_add_allocation_pool (query, pool, size, 1, 0); GST_DEBUG_OBJECT (base, "proposing %" GST_PTR_FORMAT " with allocator %" GST_PTR_FORMAT, diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabasetransform.c b/subprojects/gst-plugins-bad/sys/va/gstvabasetransform.c index 98f9e8d4ac..9b262b5fef 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabasetransform.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvabasetransform.c @@ -240,7 +240,6 @@ gst_va_base_transform_propose_allocation (GstBaseTransform * trans, GstAllocationParams params = { 0, }; GstBufferPool *pool; GstCaps *caps; - GstVideoInfo info; gboolean update_allocator = FALSE; guint size, usage_hint; @@ -261,16 +260,9 @@ gst_va_base_transform_propose_allocation (GstBaseTransform * trans, if (!caps) return FALSE; - if (!gst_va_video_info_from_caps (&info, NULL, caps)) { - GST_ERROR_OBJECT (self, "Cannot parse caps %" GST_PTR_FORMAT, caps); - return FALSE; - } - usage_hint = va_get_surface_usage_hint (self->display, VAEntrypointVideoProc, GST_PAD_SINK, gst_video_is_dma_drm_caps (caps)); - size = GST_VIDEO_INFO_SIZE (&info); - if (gst_query_get_n_allocation_params (query) > 0) { gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms); if (!GST_IS_VA_DMABUF_ALLOCATOR (allocator) @@ -286,8 +278,8 @@ gst_va_base_transform_propose_allocation (GstBaseTransform * trans, return FALSE; } - pool = gst_va_pool_new_with_config (caps, size, 1 + self->extra_min_buffers, - 0, usage_hint, GST_VA_FEATURE_AUTO, allocator, ¶ms); + pool = gst_va_pool_new_with_config (caps, 1 + self->extra_min_buffers, 0, + usage_hint, GST_VA_FEATURE_AUTO, allocator, ¶ms); if (!pool) { gst_object_unref (allocator); goto config_failed; @@ -298,6 +290,9 @@ gst_va_base_transform_propose_allocation (GstBaseTransform * trans, else gst_query_add_allocation_param (query, allocator, ¶ms); + if (!gst_va_pool_get_buffer_size (pool, &size)) + goto config_failed; + gst_query_add_allocation_pool (query, pool, size, 1 + self->extra_min_buffers, 0); @@ -760,8 +755,7 @@ _get_sinkpad_pool (GstElement * element, gpointer data) GstAllocator *allocator; GstAllocationParams params = { 0, }; GstCaps *caps; - GstVideoInfo in_info; - guint size, usage_hint; + guint usage_hint; if (self->priv->sinkpad_pool) return self->priv->sinkpad_pool; @@ -787,21 +781,13 @@ _get_sinkpad_pool (GstElement * element, gpointer data) gst_caps_set_simple (caps, "height", G_TYPE_INT, self->priv->uncropped_height, NULL); - if (!gst_video_info_from_caps (&in_info, caps)) { - GST_ERROR_OBJECT (self, "Cannot parse caps %" GST_PTR_FORMAT, caps); - gst_caps_unref (caps); - return NULL; - } - usage_hint = va_get_surface_usage_hint (self->display, VAEntrypointVideoProc, GST_PAD_SINK, FALSE); - size = GST_VIDEO_INFO_SIZE (&in_info); - allocator = gst_va_base_transform_allocator_from_caps (self, caps); g_assert (GST_IS_VA_ALLOCATOR (allocator)); - self->priv->sinkpad_pool = gst_va_pool_new_with_config (caps, size, 1, 0, + self->priv->sinkpad_pool = gst_va_pool_new_with_config (caps, 1, 0, usage_hint, GST_VA_FEATURE_AUTO, allocator, ¶ms); if (!self->priv->sinkpad_pool) { gst_caps_unref (caps); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvacompositor.c b/subprojects/gst-plugins-bad/sys/va/gstvacompositor.c index 2131dc263b..924d209365 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvacompositor.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvacompositor.c @@ -580,8 +580,6 @@ gst_va_compositor_propose_allocation (GstAggregator * agg, usage_hint = va_get_surface_usage_hint (self->display, VAEntrypointVideoProc, GST_PAD_SINK, gst_video_is_dma_drm_caps (caps)); - size = GST_VIDEO_INFO_SIZE (&info); - if (gst_query_get_n_allocation_params (query) > 0) { gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms); if (!GST_IS_VA_DMABUF_ALLOCATOR (allocator) @@ -599,13 +597,16 @@ gst_va_compositor_propose_allocation (GstAggregator * agg, /* Now we have a VA-based allocator */ - pool = gst_va_pool_new_with_config (caps, size, 1, 0, usage_hint, + pool = gst_va_pool_new_with_config (caps, 1, 0, usage_hint, GST_VA_FEATURE_AUTO, allocator, ¶ms); if (!pool) { gst_object_unref (allocator); goto config_failed; } + if (!gst_va_pool_get_buffer_size (pool, &size)) + goto config_failed; + if (update_allocator) gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms); else @@ -803,7 +804,7 @@ _get_sinkpad_pool (GstElement * element, gpointer data) GstAllocationParams params = { 0, }; GstCaps *caps; GstVideoInfo info; - guint size, usage_hint; + guint usage_hint; if (pad->pool) return pad->pool; @@ -822,10 +823,8 @@ _get_sinkpad_pool (GstElement * element, gpointer data) usage_hint = va_get_surface_usage_hint (self->display, VAEntrypointVideoProc, GST_PAD_SINK, FALSE); - size = GST_VIDEO_INFO_SIZE (&info); - allocator = gst_va_compositor_allocator_from_caps (self, caps); - pad->pool = gst_va_pool_new_with_config (caps, size, 1, 0, usage_hint, + pad->pool = gst_va_pool_new_with_config (caps, 1, 0, usage_hint, GST_VA_FEATURE_AUTO, allocator, ¶ms); gst_caps_unref (caps); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvaencoder.c b/subprojects/gst-plugins-bad/sys/va/gstvaencoder.c index abe5171a03..e9e9291391 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvaencoder.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvaencoder.c @@ -310,7 +310,6 @@ _create_reconstruct_pool (GstVaDisplay * display, GArray * surface_formats, GstVideoInfo info; GstAllocationParams params = { 0, }; GstBufferPool *pool; - guint size; GstCaps *caps = NULL; gst_video_info_set_format (&info, format, coded_width, coded_height); @@ -318,17 +317,13 @@ _create_reconstruct_pool (GstVaDisplay * display, GArray * surface_formats, usage_hint = va_get_surface_usage_hint (display, VAEntrypointEncSlice, GST_PAD_SINK, FALSE); - size = GST_VIDEO_INFO_SIZE (&info); - caps = gst_video_info_to_caps (&info); gst_caps_set_features_simple (caps, gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_VA)); allocator = gst_va_allocator_new (display, surface_formats); - gst_allocation_params_init (¶ms); - - pool = gst_va_pool_new_with_config (caps, size, 0, max_buffers, usage_hint, + pool = gst_va_pool_new_with_config (caps, 0, max_buffers, usage_hint, GST_VA_FEATURE_AUTO, allocator, ¶ms); gst_clear_object (&allocator);