summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorHe Junyan <junyan.he@hotmail.com>2020-04-10 21:27:32 +0800
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2020-05-16 19:58:15 +0000
commit3583a4b86cc8a9398939ec84fbee8ca370a54ed1 (patch)
tree051ffd3738201fb27615785bcad6dacfa4a4f114 /gst
parent2b1809e9d384c143487ef6065af0cf0112669b06 (diff)
plugin: encode: extract the allowed caps maker as a helper function.
Extract all logic about making caps for encode's sink as a standalone helper function. It can be reused. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/315>
Diffstat (limited to 'gst')
-rw-r--r--gst/vaapi/gstvaapiencode.c42
-rw-r--r--gst/vaapi/gstvaapipluginutil.c59
-rw-r--r--gst/vaapi/gstvaapipluginutil.h5
3 files changed, 70 insertions, 36 deletions
diff --git a/gst/vaapi/gstvaapiencode.c b/gst/vaapi/gstvaapiencode.c
index 2cf75828..7671170d 100644
--- a/gst/vaapi/gstvaapiencode.c
+++ b/gst/vaapi/gstvaapiencode.c
@@ -358,13 +358,9 @@ static gboolean
ensure_allowed_sinkpad_caps (GstVaapiEncode * encode)
{
GstCaps *out_caps = NULL;
- GstCaps *raw_caps = NULL;
- GstCaps *va_caps, *dma_caps;
GArray *formats = NULL;
gboolean ret = FALSE;
GArray *profiles = NULL;
- guint i, size;
- GstStructure *structure;
gint min_width, min_height, max_width, max_height;
guint mem_types;
@@ -385,34 +381,10 @@ ensure_allowed_sinkpad_caps (GstVaapiEncode * encode)
if (!formats)
goto failed_get_attributes;
- raw_caps = gst_vaapi_video_format_new_template_caps_from_list (formats);
- if (!raw_caps)
- goto failed_create_raw_caps;
-
- /* 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);
-
- 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);
- }
+ out_caps = gst_vaapi_build_caps_from_formats (formats, min_width, min_height,
+ max_width, max_height, mem_types);
+ if (!out_caps)
+ goto failed_create_caps;
gst_caps_replace (&encode->allowed_sinkpad_caps, out_caps);
GST_INFO_OBJECT (encode, "Allowed sink caps %" GST_PTR_FORMAT,
@@ -428,8 +400,6 @@ bail:
g_array_unref (profiles);
if (out_caps)
gst_caps_unref (out_caps);
- if (raw_caps)
- gst_caps_unref (raw_caps);
if (formats)
g_array_unref (formats);
return ret;
@@ -439,9 +409,9 @@ failed_get_attributes:
GST_WARNING_OBJECT (encode, "failed to get surface attributes");
goto bail;
}
-failed_create_raw_caps:
+failed_create_caps:
{
- GST_WARNING_OBJECT (encode, "failed to create raw sink caps");
+ GST_WARNING_OBJECT (encode, "failed to create sink caps");
goto bail;
}
failed_get_profiles:
diff --git a/gst/vaapi/gstvaapipluginutil.c b/gst/vaapi/gstvaapipluginutil.c
index ba89b4a7..ce3179d5 100644
--- a/gst/vaapi/gstvaapipluginutil.c
+++ b/gst/vaapi/gstvaapipluginutil.c
@@ -24,6 +24,7 @@
#include "gstcompat.h"
#include "gstvaapivideocontext.h"
+#include <gst/vaapi/gstvaapiprofilecaps.h>
#if USE_DRM
# include <gst/vaapi/gstvaapidisplay_drm.h>
#endif
@@ -1079,3 +1080,61 @@ gst_vaapi_h26x_encoder_get_profiles_from_caps (GstCaps * caps,
return profiles;
}
+
+/**
+ * gst_vaapi_build_caps_from_formats:
+ * @formats: an array of supported #GstVideoFormat
+ * @min_width: the min supported width
+ * @min_height: the min supported height
+ * @max_width: the max supported width
+ * @max_height: the max supported height
+ * @mem_types: the supported VA mem types
+ *
+ * This function generates a #GstCaps based on the information such as
+ * formats, width and height.
+ *
+ * Return: A #GstCaps.
+ **/
+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;
+
+ 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);
+
+ 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);
+
+ return out_caps;
+}
diff --git a/gst/vaapi/gstvaapipluginutil.h b/gst/vaapi/gstvaapipluginutil.h
index 8ceb7ee1..99b6e133 100644
--- a/gst/vaapi/gstvaapipluginutil.h
+++ b/gst/vaapi/gstvaapipluginutil.h
@@ -160,4 +160,9 @@ GArray *
gst_vaapi_h26x_encoder_get_profiles_from_caps (GstCaps * caps,
GstVaapiStrToProfileFunc func);
+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);
+
#endif /* GST_VAAPI_PLUGIN_UTIL_H */