summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHe Junyan <junyan.he@hotmail.com>2020-01-08 15:07:36 +0800
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2020-01-14 11:36:18 +0000
commit67e7e15408dd4077899c533cde2f9e537ff8dc38 (patch)
treeea735e15ab63c1865340ec4ffebd4f24853c7f75
parent0a2a25981cd280640be389883cca5f14c09792da (diff)
plugin: util: add helper function to detect profiles in caps.
-rw-r--r--gst/vaapi/gstvaapipluginutil.c63
-rw-r--r--gst/vaapi/gstvaapipluginutil.h8
2 files changed, 71 insertions, 0 deletions
diff --git a/gst/vaapi/gstvaapipluginutil.c b/gst/vaapi/gstvaapipluginutil.c
index dd7cb815..4db9b779 100644
--- a/gst/vaapi/gstvaapipluginutil.c
+++ b/gst/vaapi/gstvaapipluginutil.c
@@ -1008,3 +1008,66 @@ gst_vaapi_codecs_has_codec (GArray * codecs, GstVaapiCodec codec)
}
return FALSE;
}
+
+/**
+ * gst_vaapi_h26x_encoder_get_profiles_from_caps:
+ * @caps: a #GstCaps to detect
+ * @func: a #GstVaapiStrToProfileFunc
+ *
+ * This function will detect all profile strings in @caps and
+ * return the according GstVaapiProfile in array. This can just
+ * work for h264 and h265 now.
+ *
+ * Return: A #GArray of @GstVaapiProfile if succeed, %NULL if fail.
+ **/
+GArray *
+gst_vaapi_h26x_encoder_get_profiles_from_caps (GstCaps * caps,
+ GstVaapiStrToProfileFunc func)
+{
+ guint i, j;
+ GstVaapiProfile profile;
+ GArray *profiles = NULL;
+
+ if (!caps)
+ return NULL;
+
+ profiles = g_array_new (FALSE, FALSE, sizeof (GstVaapiProfile));
+ if (!profiles)
+ return NULL;
+
+ for (i = 0; i < gst_caps_get_size (caps); i++) {
+ GstStructure *const structure = gst_caps_get_structure (caps, i);
+ const GValue *const value = gst_structure_get_value (structure, "profile");
+
+ if (value && G_VALUE_HOLDS_STRING (value)) {
+ const gchar *str = g_value_get_string (value);
+ if (str) {
+ profile = func (str);
+ if (profile != GST_VAAPI_PROFILE_UNKNOWN)
+ g_array_append_val (profiles, profile);
+ }
+ } else if (value && GST_VALUE_HOLDS_LIST (value)) {
+ const GValue *v;
+ const gchar *str;
+ for (j = 0; j < gst_value_list_get_size (value); j++) {
+ v = gst_value_list_get_value (value, j);
+ if (!v || !G_VALUE_HOLDS_STRING (v))
+ continue;
+
+ str = g_value_get_string (v);
+ if (str) {
+ profile = func (str);
+ if (profile != GST_VAAPI_PROFILE_UNKNOWN)
+ g_array_append_val (profiles, profile);
+ }
+ }
+ }
+ }
+
+ if (profiles->len == 0) {
+ g_array_unref (profiles);
+ profiles = NULL;
+ }
+
+ return profiles;
+}
diff --git a/gst/vaapi/gstvaapipluginutil.h b/gst/vaapi/gstvaapipluginutil.h
index bba668b7..8ceb7ee1 100644
--- a/gst/vaapi/gstvaapipluginutil.h
+++ b/gst/vaapi/gstvaapipluginutil.h
@@ -29,6 +29,9 @@
#include <gst/vaapi/gstvaapisurface.h>
#include "gstvaapivideomemory.h"
+typedef GstVaapiProfile (*GstVaapiStrToProfileFunc) (const gchar * str);
+
+
G_GNUC_INTERNAL
gboolean
gst_vaapi_ensure_display (GstElement * element, GstVaapiDisplayType type);
@@ -152,4 +155,9 @@ G_GNUC_INTERNAL
gboolean
gst_vaapi_codecs_has_codec (GArray * codecs, GstVaapiCodec codec);
+G_GNUC_INTERNAL
+GArray *
+gst_vaapi_h26x_encoder_get_profiles_from_caps (GstCaps * caps,
+ GstVaapiStrToProfileFunc func);
+
#endif /* GST_VAAPI_PLUGIN_UTIL_H */