diff --git a/lib/wp/spa-pod.c b/lib/wp/spa-pod.c index ee803421..d8f1f725 100644 --- a/lib/wp/spa-pod.c +++ b/lib/wp/spa-pod.c @@ -14,6 +14,7 @@ #include #include #include +#include #define WP_SPA_POD_BUILDER_REALLOC_STEP_SIZE 64 #define WP_SPA_POD_ID_PROPERTY_NAME_MAX 16 @@ -1811,6 +1812,41 @@ wp_spa_pod_fixate (WpSpaPod *self) return FALSE; } +/*! + * \brief Returns the intersection between \a self and \a filter + * + * This is typically used to intersect pods that describe formats, in order to + * find a common format that is accceptable by both sides. For that purpose, + * this is not exactly an intersection with its mathematical meaning. + * Object properties can be thought of as format constraints. When one side does + * not specify a specific property, it is considered to accept any value for it, + * so the value of this property from the other side is added in the result. + * + * Both input pods are left unmodified after this function call. + * + * If NULL is passed in the \a filter, this function just copies \a self and + * returns the copy. + * + * \param self the first pod + * \param filter (nullable): the second pod + * \return (transfer full) (nullable): a new pod that contains the intersection + * between \a self and \a filter, or NULL if the intersection was not possible + * to make + */ +WpSpaPod * +wp_spa_pod_filter (WpSpaPod *self, WpSpaPod *filter) +{ + char buffer[1024]; + struct spa_pod_builder b = SPA_POD_BUILDER_INIT(&buffer, sizeof(buffer)); + struct spa_pod *result = NULL; + + g_return_val_if_fail (self, NULL); + + if (spa_pod_filter(&b, &result, self->pod, filter ? filter->pod : NULL) >= 0) + return wp_spa_pod_new_wrap_copy (result); + return NULL; +} + /*! * \brief Increases the reference count of a spa pod builder * diff --git a/lib/wp/spa-pod.h b/lib/wp/spa-pod.h index 91edc10a..e926821b 100644 --- a/lib/wp/spa-pod.h +++ b/lib/wp/spa-pod.h @@ -289,6 +289,9 @@ WpIterator *wp_spa_pod_new_iterator (WpSpaPod *pod); WP_API gboolean wp_spa_pod_fixate (WpSpaPod *self); +WP_API +WpSpaPod *wp_spa_pod_filter (WpSpaPod *self, WpSpaPod *filter); + G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpSpaPod, wp_spa_pod_unref)