plugin: util: add helper function to detect profiles in caps.

This commit is contained in:
He Junyan 2020-01-08 15:07:36 +08:00 committed by Víctor Manuel Jáquez Leal
parent 0a2a25981c
commit 67e7e15408
2 changed files with 71 additions and 0 deletions

View file

@ -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;
}

View file

@ -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 */