From b97540a109888d3d471732b4d77da10825223906 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Tue, 5 May 2020 10:19:41 +0300
Subject: [PATCH] endpoint: add wp_endpoint_create_link method

---
 lib/wp/endpoint.c | 39 +++++++++++++++++++++++++++++++++++++++
 lib/wp/endpoint.h |  3 +++
 2 files changed, 42 insertions(+)

diff --git a/lib/wp/endpoint.c b/lib/wp/endpoint.c
index 017db5db..1ee3aef3 100644
--- a/lib/wp/endpoint.c
+++ b/lib/wp/endpoint.c
@@ -34,6 +34,7 @@
 #include <spa/pod/builder.h>
 #include <spa/pod/parser.h>
 #include <spa/pod/filter.h>
+#include <spa/utils/result.h>
 
 /* WpEndpoint */
 
@@ -422,6 +423,44 @@ wp_endpoint_iterate_streams (WpEndpoint * self)
   return wp_object_manager_iterate (priv->streams_om);
 }
 
+/**
+ * wp_endpoint_create_link:
+ * @self: the endpoint
+ * @props: the link properties
+ *
+ * Creates a #WpEndpointLink between @self and another endpoint, which
+ * must be specified in @props.
+ * @props may contain:
+ *  - `endpoint-link.output.endpoint`: the bound id of the endpoint
+ *        that is in the %WP_DIRECTION_OUTPUT direction
+ *  - `endpoint-link.output.stream`: the bound id of the endpoint stream
+ *        that is in the %WP_DIRECTION_OUTPUT direction
+ *  - `endpoint-link.input.endpoint`: the bound id of the endpoint
+ *        that is in the %WP_DIRECTION_INPUT direction
+ *  - `endpoint-link.input.stream`: the bound id of the endpoint stream
+ *        that is in the %WP_DIRECTION_INPUT direction
+ *
+ * If either stream id are not specified (or set to -1), then the first
+ * available stream of this endpoint is used for the link.
+ *
+ * The id of @self is not necessary to be specified, so only one of
+ * `endpoint-link.output.endpoint`, `endpoint-link.input.endpoint`
+ * is actually required.
+ */
+void
+wp_endpoint_create_link (WpEndpoint * self, WpProperties * props)
+{
+  WpEndpointPrivate *priv =
+      wp_endpoint_get_instance_private (WP_ENDPOINT (self));
+  int res;
+
+  res = pw_endpoint_create_link (priv->iface, wp_properties_peek_dict (props));
+  if (res < 0) {
+    wp_warning_object (self, "pw_endpoint_create_link: %d: %s", res,
+        spa_strerror (res));
+  }
+}
+
 /* WpImplEndpoint */
 
 enum {
diff --git a/lib/wp/endpoint.h b/lib/wp/endpoint.h
index bfaeda1e..e7beebc4 100644
--- a/lib/wp/endpoint.h
+++ b/lib/wp/endpoint.h
@@ -76,6 +76,9 @@ WpEndpointStream * wp_endpoint_find_stream (WpEndpoint * self, guint32 bound_id)
 WP_API
 WpIterator * wp_endpoint_iterate_streams (WpEndpoint * self);
 
+WP_API
+void wp_endpoint_create_link (WpEndpoint * self, WpProperties * props);
+
 G_END_DECLS
 
 #endif
-- 
GitLab