glupload: Add a helper function of _filter_caps_with_features()

We sometimes need to filter some special feature for the next step.
This helper function can help us to filter out un-needed features
in a caps.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3524>
This commit is contained in:
He Junyan 2023-06-01 18:34:31 +08:00 committed by GStreamer Marge Bot
parent 95707bb80d
commit 96ea1b8da9

View file

@ -117,6 +117,63 @@ struct _GstGLUploadPrivate
G_DEFINE_TYPE_WITH_CODE (GstGLUpload, gst_gl_upload, GST_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (GstGLUpload, gst_gl_upload, GST_TYPE_OBJECT,
G_ADD_PRIVATE (GstGLUpload) DEBUG_INIT); G_ADD_PRIVATE (GstGLUpload) DEBUG_INIT);
static gboolean
filter_features (GstCapsFeatures * features,
G_GNUC_UNUSED GstStructure * structure, gpointer user_data)
{
const GstCapsFeatures *user_features = user_data;
GQuark feature;
guint i, num;
if (gst_caps_features_is_any (features))
return TRUE;
num = gst_caps_features_get_size (user_features);
for (i = 0; i < num; i++) {
feature = gst_caps_features_get_nth_id (user_features, i);
if (gst_caps_features_contains_id (features, feature))
return TRUE;
}
return FALSE;
}
static gboolean
_filter_caps_with_features (const GstCaps * caps,
const GstCapsFeatures * features, GstCaps ** ret_caps)
{
GstCaps *tmp = NULL;
gboolean ret = TRUE;
if (gst_caps_is_empty (caps))
return FALSE;
if (gst_caps_is_any (caps)) {
if (ret_caps) {
tmp = gst_caps_new_empty ();
gst_caps_set_features_simple (tmp, gst_caps_features_copy (features));
*ret_caps = tmp;
}
return TRUE;
}
tmp = gst_caps_copy (caps);
gst_caps_filter_and_map_in_place (tmp, filter_features, (gpointer) features);
if (gst_caps_is_empty (tmp)) {
gst_clear_caps (&tmp);
ret = FALSE;
}
if (ret_caps)
*ret_caps = tmp;
else
gst_clear_caps (&tmp);
return ret;
}
static GstCaps * static GstCaps *
_set_caps_features_with_passthrough (const GstCaps * caps, _set_caps_features_with_passthrough (const GstCaps * caps,
const gchar * feature_name, GstCapsFeatures * passthrough) const gchar * feature_name, GstCapsFeatures * passthrough)