From 99ac072673c12e3f81cc2e774bb2536ace2508c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Mon, 25 May 2020 17:02:26 +0200 Subject: [PATCH] plugins: add gst_vaapi_caps_set_width_and_height_range() This utility function is called internally by gst_vaapi_build_caps_from_formats() and can be used outside. This function sets frame size and framerates ranges. Also gst_vaapi_build_caps_from_formats() is simplified. Part-of: --- gst/vaapi/gstvaapidecode.c | 35 ++++++------------------------ gst/vaapi/gstvaapipluginutil.c | 48 ++++++++++++++++++++++++------------------ gst/vaapi/gstvaapipluginutil.h | 5 +++++ 3 files changed, 40 insertions(+), 48 deletions(-) diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index afe2dd2..7563a2f 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -197,25 +197,6 @@ gst_vaapidecode_update_sink_caps (GstVaapiDecode * decode, GstCaps * caps) return TRUE; } -static inline void -caps_set_width_and_height_range (GstCaps * caps, gint min_width, - gint min_height, gint max_width, gint max_height) -{ - guint size, i; - GstStructure *structure; - - /* Set the width/height info to caps */ - size = gst_caps_get_size (caps); - for (i = 0; i < size; i++) { - structure = gst_caps_get_structure (caps, i); - if (!structure) - continue; - gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, min_width, - max_width, "height", GST_TYPE_INT_RANGE, min_height, max_height, - "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); - } -} - static gboolean gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode) { @@ -234,7 +215,7 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode) if (!decode->decoder) return FALSE; - out_caps = base_caps = raw_caps = va_caps = dma_caps = gltexup_caps = NULL; + dma_caps = gltexup_caps = NULL; formats = gst_vaapi_decoder_get_surface_attributes (decode->decoder, &min_width, &min_height, &max_width, &max_height, &mem_types); @@ -244,8 +225,8 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode) base_caps = gst_vaapi_video_format_new_template_caps_from_list (formats); if (!base_caps) goto bail; - caps_set_width_and_height_range (base_caps, min_width, min_height, max_width, - max_height); + gst_vaapi_caps_set_width_and_height_range (base_caps, min_width, min_height, + max_width, max_height); raw_caps = gst_vaapi_plugin_base_get_allowed_srcpad_raw_caps (GST_VAAPI_PLUGIN_BASE (decode), @@ -253,7 +234,7 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode) if (!raw_caps) goto bail; raw_caps = gst_caps_copy (raw_caps); - caps_set_width_and_height_range (raw_caps, min_width, min_height, + gst_vaapi_caps_set_width_and_height_range (raw_caps, min_width, min_height, max_width, max_height); va_caps = gst_caps_copy (base_caps); @@ -272,8 +253,8 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode) && gst_vaapi_display_has_opengl (GST_VAAPI_PLUGIN_BASE_DISPLAY (decode))) { gltexup_caps = gst_caps_from_string (GST_VAAPI_MAKE_GLTEXUPLOAD_CAPS); if (gltexup_caps) { - caps_set_width_and_height_range (base_caps, min_width, min_height, - max_width, max_height); + gst_vaapi_caps_set_width_and_height_range (base_caps, min_width, + min_height, max_width, max_height); } } #endif @@ -283,9 +264,7 @@ gst_vaapidecode_ensure_allowed_srcpad_caps (GstVaapiDecode * decode) gst_caps_append (out_caps, dma_caps); if (gltexup_caps) gst_caps_append (out_caps, gltexup_caps); - if (raw_caps) - gst_caps_append (out_caps, raw_caps); - + gst_caps_append (out_caps, gst_caps_copy (raw_caps)); decode->allowed_srcpad_caps = out_caps; GST_INFO_OBJECT (decode, "allowed srcpad caps: %" GST_PTR_FORMAT, diff --git a/gst/vaapi/gstvaapipluginutil.c b/gst/vaapi/gstvaapipluginutil.c index f5eb6d5..b98f305 100644 --- a/gst/vaapi/gstvaapipluginutil.c +++ b/gst/vaapi/gstvaapipluginutil.c @@ -1071,6 +1071,25 @@ gst_vaapi_encoder_get_profiles_from_caps (GstCaps * caps, return profiles; } +void +gst_vaapi_caps_set_width_and_height_range (GstCaps * caps, gint min_width, + gint min_height, gint max_width, gint max_height) +{ + guint size, i; + GstStructure *structure; + + /* Set the width/height info to caps */ + size = gst_caps_get_size (caps); + for (i = 0; i < size; i++) { + structure = gst_caps_get_structure (caps, i); + if (!structure) + continue; + gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, min_width, + max_width, "height", GST_TYPE_INT_RANGE, min_height, max_height, + "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); + } +} + /** * gst_vaapi_build_caps_from_formats: * @formats: an array of supported #GstVideoFormat @@ -1089,42 +1108,31 @@ GstCaps * gst_vaapi_build_caps_from_formats (GArray * formats, gint min_width, gint min_height, gint max_width, gint max_height, guint mem_types) { - GstCaps *out_caps = NULL; - GstCaps *raw_caps = NULL; - GstCaps *va_caps, *dma_caps; - guint i, size; - GstStructure *structure; + GstCaps *out_caps, *raw_caps, *va_caps, *dma_caps; + + dma_caps = NULL; raw_caps = gst_vaapi_video_format_new_template_caps_from_list (formats); if (!raw_caps) return NULL; - - /* Set the width/height info to caps */ - size = gst_caps_get_size (raw_caps); - for (i = 0; i < size; i++) { - structure = gst_caps_get_structure (raw_caps, i); - if (!structure) - continue; - gst_structure_set (structure, "width", GST_TYPE_INT_RANGE, min_width, - max_width, "height", GST_TYPE_INT_RANGE, min_height, max_height, NULL); - } - - out_caps = gst_caps_copy (raw_caps); + gst_vaapi_caps_set_width_and_height_range (raw_caps, min_width, min_height, + max_width, max_height); va_caps = gst_caps_copy (raw_caps); gst_caps_set_features_simple (va_caps, gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE)); - gst_caps_append (out_caps, va_caps); if (gst_vaapi_mem_type_supports (mem_types, GST_VAAPI_BUFFER_MEMORY_TYPE_DMA_BUF)) { dma_caps = gst_caps_copy (raw_caps); gst_caps_set_features_simple (dma_caps, gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF)); - gst_caps_append (out_caps, dma_caps); } - gst_caps_unref (raw_caps); + out_caps = va_caps; + if (dma_caps) + gst_caps_append (out_caps, dma_caps); + gst_caps_append (out_caps, raw_caps); return out_caps; } diff --git a/gst/vaapi/gstvaapipluginutil.h b/gst/vaapi/gstvaapipluginutil.h index 5ae79b8..236ccd3 100644 --- a/gst/vaapi/gstvaapipluginutil.h +++ b/gst/vaapi/gstvaapipluginutil.h @@ -162,6 +162,11 @@ gst_vaapi_encoder_get_profiles_from_caps (GstCaps * caps, GstVaapiStrToProfileFunc func); G_GNUC_INTERNAL +void +gst_vaapi_caps_set_width_and_height_range (GstCaps * caps, gint min_width, + gint min_height, gint max_width, gint max_height); + +G_GNUC_INTERNAL GstCaps * gst_vaapi_build_caps_from_formats (GArray * formats, gint min_width, gint min_height, gint max_width, gint max_height, guint mem_type); -- 2.7.4