proxy: unify common info/params API in the WpProxy base class

This commit is contained in:
George Kiagiadakis
2020-01-22 10:34:56 +02:00
parent 6f2844ac13
commit 5c47f1df2c
31 changed files with 795 additions and 914 deletions

View File

@@ -15,12 +15,6 @@
#include <spa/pod/builder.h>
#include <spa/pod/parser.h>
enum {
PROXY_PROP_0,
PROXY_PROP_INFO,
PROXY_PROP_PROPERTIES,
};
enum {
EXPORTED_PROP_0,
EXPORTED_PROP_GLOBAL_ID,
@@ -99,25 +93,11 @@ G_DEFINE_INTERFACE (WpEndpoint, wp_endpoint, G_TYPE_OBJECT)
static void
wp_endpoint_default_init (WpEndpointInterface * klass)
{
g_object_interface_install_property (klass,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the object", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
signals[SIGNAL_CONTROL_CHANGED] = g_signal_new (
"control-changed", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT);
}
WpProperties *
wp_endpoint_get_properties (WpEndpoint * self)
{
g_return_val_if_fail (WP_IS_ENDPOINT (self), NULL);
g_return_val_if_fail (WP_ENDPOINT_GET_IFACE (self)->get_properties, NULL);
return WP_ENDPOINT_GET_IFACE (self)->get_properties (self);
}
const gchar *
wp_endpoint_get_name (WpEndpoint * self)
{
@@ -188,7 +168,7 @@ wp_endpoint_set_control (WpEndpoint * self, guint32 control_id,
const struct spa_pod * value)
{
g_return_val_if_fail (WP_IS_ENDPOINT (self), FALSE);
g_return_val_if_fail (WP_ENDPOINT_GET_IFACE (self)->get_properties, FALSE);
g_return_val_if_fail (WP_ENDPOINT_GET_IFACE (self)->set_control, FALSE);
return WP_ENDPOINT_GET_IFACE (self)->set_control (self, control_id, value);
}
@@ -255,24 +235,80 @@ wp_proxy_endpoint_finalize (GObject * object)
}
static void
wp_proxy_endpoint_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
wp_proxy_endpoint_augment (WpProxy * proxy, WpProxyFeatures features)
{
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (object);
/* call the parent impl first to ensure we have a pw proxy if necessary */
WP_PROXY_CLASS (wp_proxy_endpoint_parent_class)->augment (proxy, features);
switch (property_id) {
case PROXY_PROP_INFO:
g_value_set_pointer (value, self->info);
break;
case PROXY_PROP_PROPERTIES:
g_value_set_boxed (value, self->properties);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
if (features & WP_PROXY_ENDPOINT_FEATURE_CONTROLS) {
struct pw_endpoint *pw_proxy = NULL;
uint32_t ids[] = { SPA_PARAM_Props };
pw_proxy = (struct pw_endpoint *) wp_proxy_get_pw_proxy (proxy);
if (!pw_proxy)
return;
pw_endpoint_enum_params (pw_proxy, 0, SPA_PARAM_PropInfo, 0, -1, NULL);
pw_endpoint_subscribe_params (pw_proxy, ids, SPA_N_ELEMENTS (ids));
}
}
static gconstpointer
wp_proxy_endpoint_get_info (WpProxy * proxy)
{
return WP_PROXY_ENDPOINT (proxy)->info;
}
static WpProperties *
wp_proxy_endpoint_get_properties (WpProxy * proxy)
{
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (proxy);
return wp_properties_ref (self->properties);
}
static gint
wp_proxy_endpoint_enum_params (WpProxy * self, guint32 id, guint32 start,
guint32 num, const struct spa_pod *filter)
{
struct pw_endpoint *pwp;
int endpoint_enum_params_result;
pwp = (struct pw_endpoint *) wp_proxy_get_pw_proxy (self);
endpoint_enum_params_result = pw_endpoint_enum_params (pwp, 0, id, start, num,
filter);
g_warn_if_fail (endpoint_enum_params_result >= 0);
return endpoint_enum_params_result;
}
static gint
wp_proxy_endpoint_subscribe_params (WpProxy * self, guint32 n_ids, guint32 *ids)
{
struct pw_endpoint *pwp;
int endpoint_subscribe_params_result;
pwp = (struct pw_endpoint *) wp_proxy_get_pw_proxy (self);
endpoint_subscribe_params_result = pw_endpoint_subscribe_params (pwp, ids,
n_ids);
g_warn_if_fail (endpoint_subscribe_params_result >= 0);
return endpoint_subscribe_params_result;
}
static gint
wp_proxy_endpoint_set_param (WpProxy * self, guint32 id, guint32 flags,
const struct spa_pod *param)
{
struct pw_endpoint *pwp;
int endpoint_set_param_result;
pwp = (struct pw_endpoint *) wp_proxy_get_pw_proxy (self);
endpoint_set_param_result = pw_endpoint_set_param (pwp, id, flags, param);
g_warn_if_fail (endpoint_set_param_result >= 0);
return endpoint_set_param_result;
}
static void
endpoint_event_info (void *data, const struct pw_endpoint_info *info)
{
@@ -287,11 +323,25 @@ endpoint_event_info (void *data, const struct pw_endpoint_info *info)
wp_proxy_set_feature_ready (WP_PROXY (self), WP_PROXY_FEATURE_INFO);
}
static const struct pw_endpoint_events endpoint_events = {
PW_VERSION_ENDPOINT_EVENTS,
.info = endpoint_event_info,
.param = wp_proxy_handle_event_param,
};
static void
endpoint_event_param (void *data, int seq, uint32_t id, uint32_t index,
uint32_t next, const struct spa_pod *param)
wp_proxy_endpoint_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
{
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (data);
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (proxy);
pw_endpoint_add_listener ((struct pw_endpoint *) pw_proxy,
&self->listener, &endpoint_events, self);
}
static void
wp_proxy_endpoint_param (WpProxy * proxy, gint seq, guint32 id, guint32 index,
guint32 next, const struct spa_pod *param)
{
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (proxy);
g_autoptr (GArray) changed_ids = NULL;
guint32 prop_id;
@@ -314,61 +364,21 @@ endpoint_event_param (void *data, int seq, uint32_t id, uint32_t index,
}
}
static const struct pw_endpoint_events endpoint_events = {
PW_VERSION_ENDPOINT_EVENTS,
.info = endpoint_event_info,
.param = endpoint_event_param,
};
static void
wp_proxy_endpoint_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
{
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (proxy);
pw_endpoint_add_listener ((struct pw_endpoint *) pw_proxy,
&self->listener, &endpoint_events, self);
}
static void
wp_proxy_endpoint_augment (WpProxy * proxy, WpProxyFeatures features)
{
/* call the parent impl first to ensure we have a pw proxy if necessary */
WP_PROXY_CLASS (wp_proxy_endpoint_parent_class)->augment (proxy, features);
if (features & WP_PROXY_ENDPOINT_FEATURE_CONTROLS) {
struct pw_endpoint *pw_proxy = NULL;
uint32_t ids[] = { SPA_PARAM_Props };
pw_proxy = (struct pw_endpoint *) wp_proxy_get_pw_proxy (proxy);
if (!pw_proxy)
return;
pw_endpoint_enum_params (pw_proxy, 0, SPA_PARAM_PropInfo, 0, -1, NULL);
pw_endpoint_subscribe_params (pw_proxy, ids, SPA_N_ELEMENTS (ids));
}
}
static WpProperties *
wp_proxy_endpoint_get_properties (WpEndpoint * endpoint)
{
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (endpoint);
return wp_properties_ref (self->properties);
}
const gchar *
static const gchar *
wp_proxy_endpoint_get_name (WpEndpoint * endpoint)
{
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (endpoint);
return self->info->name;
}
const gchar *
static const gchar *
wp_proxy_endpoint_get_media_class (WpEndpoint * endpoint)
{
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (endpoint);
return self->info->media_class;
}
WpDirection
static WpDirection
wp_proxy_endpoint_get_direction (WpEndpoint * endpoint)
{
WpProxyEndpoint *self = WP_PROXY_ENDPOINT (endpoint);
@@ -414,22 +424,21 @@ wp_proxy_endpoint_class_init (WpProxyEndpointClass * klass)
WpProxyClass *proxy_class = (WpProxyClass *) klass;
object_class->finalize = wp_proxy_endpoint_finalize;
object_class->get_property = wp_proxy_endpoint_get_property;
proxy_class->augment = wp_proxy_endpoint_augment;
proxy_class->get_info = wp_proxy_endpoint_get_info;
proxy_class->get_properties = wp_proxy_endpoint_get_properties;
proxy_class->enum_params = wp_proxy_endpoint_enum_params;
proxy_class->subscribe_params = wp_proxy_endpoint_subscribe_params;
proxy_class->set_param = wp_proxy_endpoint_set_param;
proxy_class->pw_proxy_created = wp_proxy_endpoint_pw_proxy_created;
proxy_class->augment = wp_proxy_endpoint_augment;
g_object_class_install_property (object_class, PROXY_PROP_INFO,
g_param_spec_pointer ("info", "info", "The native info structure",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_override_property (object_class, PROXY_PROP_PROPERTIES,
"properties");
proxy_class->param = wp_proxy_endpoint_param;
}
static void
wp_proxy_endpoint_iface_init (WpEndpointInterface * iface)
{
iface->get_properties = wp_proxy_endpoint_get_properties;
iface->get_name = wp_proxy_endpoint_get_name;
iface->get_media_class = wp_proxy_endpoint_get_media_class;
iface->get_direction = wp_proxy_endpoint_get_direction;
@@ -437,13 +446,6 @@ wp_proxy_endpoint_iface_init (WpEndpointInterface * iface)
iface->set_control = wp_proxy_endpoint_set_control;
}
const struct pw_endpoint_info *
wp_proxy_endpoint_get_info (WpProxyEndpoint * self)
{
g_return_val_if_fail (WP_IS_PROXY_ENDPOINT (self), NULL);
return self->info;
}
/* exported */
typedef struct _WpExportedEndpointPrivate WpExportedEndpointPrivate;
@@ -648,16 +650,7 @@ wp_exported_endpoint_get_proxy (WpExported * self)
return priv->client_ep ? g_object_ref (priv->client_ep) : NULL;
}
static WpProperties *
wp_exported_endpoint_get_properties (WpEndpoint * endpoint)
{
WpExportedEndpointPrivate *priv =
wp_exported_endpoint_get_instance_private (WP_EXPORTED_ENDPOINT (endpoint));
return wp_properties_ref (priv->properties);
}
const gchar *
static const gchar *
wp_exported_endpoint_get_name (WpEndpoint * endpoint)
{
WpExportedEndpointPrivate *priv =
@@ -665,7 +658,7 @@ wp_exported_endpoint_get_name (WpEndpoint * endpoint)
return priv->info.name;
}
const gchar *
static const gchar *
wp_exported_endpoint_get_media_class (WpEndpoint * endpoint)
{
WpExportedEndpointPrivate *priv =
@@ -673,7 +666,7 @@ wp_exported_endpoint_get_media_class (WpEndpoint * endpoint)
return priv->info.media_class;
}
WpDirection
static WpDirection
wp_exported_endpoint_get_direction (WpEndpoint * endpoint)
{
WpExportedEndpointPrivate *priv =
@@ -728,14 +721,17 @@ wp_exported_endpoint_class_init (WpExportedEndpointClass * klass)
g_param_spec_uint ("global-id", "global-id",
"The pipewire global id of the exported endpoint", 0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_override_property (object_class, EXPORTED_PROP_PROPERTIES,
"properties");
g_object_class_install_property (object_class, EXPORTED_PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the object", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
static void
wp_exported_endpoint_iface_init (WpEndpointInterface * iface)
{
iface->get_properties = wp_exported_endpoint_get_properties;
iface->get_name = wp_exported_endpoint_get_name;
iface->get_media_class = wp_exported_endpoint_get_media_class;
iface->get_direction = wp_exported_endpoint_get_direction;
@@ -771,6 +767,15 @@ wp_exported_endpoint_get_global_id (WpExportedEndpoint * self)
return priv->info.id;
}
WpProperties *
wp_exported_endpoint_get_properties (WpExportedEndpoint * self)
{
WpExportedEndpointPrivate *priv =
wp_exported_endpoint_get_instance_private (WP_EXPORTED_ENDPOINT (self));
return wp_properties_ref (priv->properties);
}
void
wp_exported_endpoint_set_property (WpExportedEndpoint * self,
const gchar * key, const gchar * value)

View File

@@ -40,8 +40,6 @@ struct _WpEndpointInterface
{
GTypeInterface parent;
WpProperties * (*get_properties) (WpEndpoint * self);
const gchar * (*get_name) (WpEndpoint * self);
const gchar * (*get_media_class) (WpEndpoint * self);
WpDirection (*get_direction) (WpEndpoint * self);
@@ -53,9 +51,6 @@ struct _WpEndpointInterface
// void (*create_link) (WpEndpoint * self, WpProperties * props);
};
WP_API
WpProperties * wp_endpoint_get_properties (WpEndpoint * self);
WP_API
const gchar * wp_endpoint_get_name (WpEndpoint * self);
@@ -110,10 +105,6 @@ WP_API
G_DECLARE_FINAL_TYPE (WpProxyEndpoint, wp_proxy_endpoint,
WP, PROXY_ENDPOINT, WpProxy)
WP_API
const struct pw_endpoint_info * wp_proxy_endpoint_get_info (
WpProxyEndpoint * self);
/* exported */
#define WP_TYPE_EXPORTED_ENDPOINT (wp_exported_endpoint_get_type ())
@@ -132,6 +123,9 @@ WpExportedEndpoint * wp_exported_endpoint_new (WpCore * core);
WP_API
guint32 wp_exported_endpoint_get_global_id (WpExportedEndpoint * self);
WP_API
WpProperties * wp_exported_endpoint_get_properties (WpExportedEndpoint * self);
WP_API
void wp_exported_endpoint_set_property (WpExportedEndpoint * self,
const gchar * key, const gchar * value);

View File

@@ -14,6 +14,8 @@
#include "object-manager.h"
#include "proxy.h"
#include <stdint.h>
G_BEGIN_DECLS
/* core */
@@ -92,8 +94,8 @@ WpProxy * wp_proxy_new_global (WpCore * core, WpGlobal * global);
void wp_proxy_set_feature_ready (WpProxy * self, WpProxyFeatures feature);
void wp_proxy_augment_error (WpProxy * self, GError * error);
void wp_proxy_register_async_task (WpProxy * self, int seq, GTask * task);
GTask * wp_proxy_find_async_task (WpProxy * self, int seq, gboolean steal);
void wp_proxy_handle_event_param (void * proxy, int seq, uint32_t id,
uint32_t index, uint32_t next, const struct spa_pod *param);
/* spa props */

View File

@@ -20,12 +20,6 @@ struct _WpProxyClient
struct spa_hook listener;
};
enum {
PROP_0,
PROP_INFO,
PROP_PROPERTIES,
};
G_DEFINE_TYPE (WpProxyClient, wp_proxy_client, WP_TYPE_PROXY)
static void
@@ -43,23 +37,16 @@ wp_proxy_client_finalize (GObject * object)
G_OBJECT_CLASS (wp_proxy_client_parent_class)->finalize (object);
}
static void
wp_proxy_client_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
static gconstpointer
wp_proxy_client_get_info (WpProxy * self)
{
WpProxyClient *self = WP_PROXY_CLIENT (object);
return WP_PROXY_CLIENT (self)->info;
}
switch (property_id) {
case PROP_INFO:
g_value_set_pointer (value, self->info);
break;
case PROP_PROPERTIES:
g_value_take_boxed (value, wp_proxy_client_get_properties (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
WpProperties *
wp_proxy_client_get_properties (WpProxy * self)
{
return wp_properties_new_wrap_dict (WP_PROXY_CLIENT (self)->info->props);
}
static void
@@ -96,30 +83,11 @@ wp_proxy_client_class_init (WpProxyClientClass * klass)
WpProxyClass *proxy_class = (WpProxyClass *) klass;
object_class->finalize = wp_proxy_client_finalize;
object_class->get_property = wp_proxy_client_get_property;
proxy_class->get_info = wp_proxy_client_get_info;
proxy_class->get_properties = wp_proxy_client_get_properties;
proxy_class->pw_proxy_created = wp_proxy_client_pw_proxy_created;
g_object_class_install_property (object_class, PROP_INFO,
g_param_spec_pointer ("info", "info", "The struct pw_client_info *",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the proxy", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
const struct pw_client_info *
wp_proxy_client_get_info (WpProxyClient * self)
{
return self->info;
}
WpProperties *
wp_proxy_client_get_properties (WpProxyClient * self)
{
return wp_properties_new_wrap_dict (self->info->props);
}
void

View File

@@ -13,19 +13,12 @@
G_BEGIN_DECLS
struct pw_client_info;
struct pw_permission;
#define WP_TYPE_PROXY_CLIENT (wp_proxy_client_get_type ())
WP_API
G_DECLARE_FINAL_TYPE (WpProxyClient, wp_proxy_client, WP, PROXY_CLIENT, WpProxy)
WP_API
const struct pw_client_info * wp_proxy_client_get_info (WpProxyClient * self);
WP_API
WpProperties * wp_proxy_client_get_properties (WpProxyClient * self);
WP_API
void wp_proxy_client_update_permissions (WpProxyClient * self,
guint n_perm, ...);

View File

@@ -7,7 +7,6 @@
*/
#include "proxy-device.h"
#include "error.h"
#include "private.h"
#include <pipewire/pipewire.h>
@@ -21,12 +20,6 @@ struct _WpProxyDevice
struct spa_hook listener;
};
enum {
PROP_0,
PROP_INFO,
PROP_PROPERTIES,
};
G_DEFINE_TYPE (WpProxyDevice, wp_proxy_device, WP_TYPE_PROXY)
static void
@@ -44,23 +37,45 @@ wp_proxy_device_finalize (GObject * object)
G_OBJECT_CLASS (wp_proxy_device_parent_class)->finalize (object);
}
static void
wp_proxy_device_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
static gconstpointer
wp_proxy_device_get_info (WpProxy * self)
{
WpProxyDevice *self = WP_PROXY_DEVICE (object);
return WP_PROXY_DEVICE (self)->info;
}
switch (property_id) {
case PROP_INFO:
g_value_set_pointer (value, self->info);
break;
case PROP_PROPERTIES:
g_value_take_boxed (value, wp_proxy_device_get_properties (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
static WpProperties *
wp_proxy_device_get_properties (WpProxy * self)
{
return wp_properties_new_wrap_dict (WP_PROXY_DEVICE (self)->info->props);
}
static gint
wp_proxy_device_enum_params (WpProxy * self, guint32 id, guint32 start,
guint32 num, const struct spa_pod *filter)
{
struct pw_device *pwp;
int device_enum_params_result;
pwp = (struct pw_device *) wp_proxy_get_pw_proxy (self);
device_enum_params_result = pw_device_enum_params (pwp, 0, id, start, num,
filter);
g_warn_if_fail (device_enum_params_result >= 0);
return device_enum_params_result;
}
static gint
wp_proxy_device_set_param (WpProxy * self, guint32 id, guint32 flags,
const struct spa_pod *param)
{
struct pw_device *pwp;
int device_set_param_result;
pwp = (struct pw_device *) wp_proxy_get_pw_proxy (self);
device_set_param_result = pw_device_set_param (pwp, id, flags, param);
g_warn_if_fail (device_set_param_result >= 0);
return device_set_param_result;
}
static void
@@ -80,6 +95,7 @@ device_event_info(void *data, const struct pw_device_info *info)
static const struct pw_device_events device_events = {
PW_VERSION_DEVICE_EVENTS,
.info = device_event_info,
.param = wp_proxy_handle_event_param,
};
static void
@@ -97,22 +113,11 @@ wp_proxy_device_class_init (WpProxyDeviceClass * klass)
WpProxyClass *proxy_class = (WpProxyClass *) klass;
object_class->finalize = wp_proxy_device_finalize;
object_class->get_property = wp_proxy_device_get_property;
proxy_class->get_info = wp_proxy_device_get_info;
proxy_class->get_properties = wp_proxy_device_get_properties;
proxy_class->enum_params = wp_proxy_device_enum_params;
proxy_class->set_param = wp_proxy_device_set_param;
proxy_class->pw_proxy_created = wp_proxy_device_pw_proxy_created;
g_object_class_install_property (object_class, PROP_INFO,
g_param_spec_pointer ("info", "info", "The struct pw_device_info *",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the proxy", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
WpProperties *
wp_proxy_device_get_properties (WpProxyDevice * self)
{
return wp_properties_new_wrap_dict (self->info->props);
}

View File

@@ -17,9 +17,6 @@ G_BEGIN_DECLS
WP_API
G_DECLARE_FINAL_TYPE (WpProxyDevice, wp_proxy_device, WP, PROXY_DEVICE, WpProxy)
WP_API
WpProperties * wp_proxy_device_get_properties (WpProxyDevice * self);
G_END_DECLS
#endif

View File

@@ -20,12 +20,6 @@ struct _WpProxyLink
struct spa_hook listener;
};
enum {
PROP_0,
PROP_INFO,
PROP_PROPERTIES,
};
G_DEFINE_TYPE (WpProxyLink, wp_proxy_link, WP_TYPE_PROXY)
static void
@@ -43,23 +37,16 @@ wp_proxy_link_finalize (GObject * object)
G_OBJECT_CLASS (wp_proxy_link_parent_class)->finalize (object);
}
static void
wp_proxy_link_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
static gconstpointer
wp_proxy_link_get_info (WpProxy * self)
{
WpProxyLink *self = WP_PROXY_LINK (object);
return WP_PROXY_LINK (self)->info;
}
switch (property_id) {
case PROP_INFO:
g_value_set_pointer (value, self->info);
break;
case PROP_PROPERTIES:
g_value_take_boxed (value, wp_proxy_link_get_properties (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
static WpProperties *
wp_proxy_link_get_properties (WpProxy * self)
{
return wp_properties_new_wrap_dict (WP_PROXY_LINK (self)->info->props);
}
static void
@@ -96,28 +83,9 @@ wp_proxy_link_class_init (WpProxyLinkClass * klass)
WpProxyClass *proxy_class = (WpProxyClass *) klass;
object_class->finalize = wp_proxy_link_finalize;
object_class->get_property = wp_proxy_link_get_property;
proxy_class->get_info = wp_proxy_link_get_info;
proxy_class->get_properties = wp_proxy_link_get_properties;
proxy_class->pw_proxy_created = wp_proxy_link_pw_proxy_created;
g_object_class_install_property (object_class, PROP_INFO,
g_param_spec_pointer ("info", "info", "The struct pw_link_info *",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the proxy", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
const struct pw_link_info *
wp_proxy_link_get_info (WpProxyLink * self)
{
return self->info;
}
WpProperties *
wp_proxy_link_get_properties (WpProxyLink * self)
{
return wp_properties_new_wrap_dict (self->info->props);
}

View File

@@ -13,18 +13,10 @@
G_BEGIN_DECLS
struct pw_link_info;
#define WP_TYPE_PROXY_LINK (wp_proxy_link_get_type ())
WP_API
G_DECLARE_FINAL_TYPE (WpProxyLink, wp_proxy_link, WP, PROXY_LINK, WpProxy)
WP_API
const struct pw_link_info * wp_proxy_link_get_info (WpProxyLink * self);
WP_API
WpProperties * wp_proxy_link_get_properties (WpProxyLink * self);
G_END_DECLS
#endif

View File

@@ -7,11 +7,9 @@
*/
#include "proxy-node.h"
#include "error.h"
#include "private.h"
#include <pipewire/pipewire.h>
#include <spa/pod/builder.h>
struct _WpProxyNode
{
@@ -22,19 +20,6 @@ struct _WpProxyNode
struct spa_hook listener;
};
enum {
PROP_0,
PROP_INFO,
PROP_PROPERTIES,
};
enum {
SIGNAL_PARAM,
N_SIGNALS
};
static guint32 signals[N_SIGNALS];
G_DEFINE_TYPE (WpProxyNode, wp_proxy_node, WP_TYPE_PROXY)
static void
@@ -52,23 +37,57 @@ wp_proxy_node_finalize (GObject * object)
G_OBJECT_CLASS (wp_proxy_node_parent_class)->finalize (object);
}
static void
wp_proxy_node_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
static gconstpointer
wp_proxy_node_get_info (WpProxy * self)
{
WpProxyNode *self = WP_PROXY_NODE (object);
return WP_PROXY_NODE (self)->info;
}
switch (property_id) {
case PROP_INFO:
g_value_set_pointer (value, self->info);
break;
case PROP_PROPERTIES:
g_value_take_boxed (value, wp_proxy_node_get_properties (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
static WpProperties *
wp_proxy_node_get_properties (WpProxy * self)
{
return wp_properties_new_wrap_dict (WP_PROXY_NODE (self)->info->props);
}
static gint
wp_proxy_node_enum_params (WpProxy * self, guint32 id, guint32 start,
guint32 num, const struct spa_pod *filter)
{
struct pw_node *pwp;
int node_enum_params_result;
pwp = (struct pw_node *) wp_proxy_get_pw_proxy (self);
node_enum_params_result = pw_node_enum_params (pwp, 0, id, start, num, filter);
g_warn_if_fail (node_enum_params_result >= 0);
return node_enum_params_result;
}
static gint
wp_proxy_node_subscribe_params (WpProxy * self, guint32 n_ids, guint32 *ids)
{
struct pw_node *pwp;
int node_subscribe_params_result;
pwp = (struct pw_node *) wp_proxy_get_pw_proxy (self);
node_subscribe_params_result = pw_node_subscribe_params (pwp, ids, n_ids);
g_warn_if_fail (node_subscribe_params_result >= 0);
return node_subscribe_params_result;
}
static gint
wp_proxy_node_set_param (WpProxy * self, guint32 id, guint32 flags,
const struct spa_pod *param)
{
struct pw_node *pwp;
int node_set_param_result;
pwp = (struct pw_node *) wp_proxy_get_pw_proxy (self);
node_set_param_result = pw_node_set_param (pwp, id, flags, param);
g_warn_if_fail (node_set_param_result >= 0);
return node_set_param_result;
}
static void
@@ -85,28 +104,10 @@ node_event_info(void *data, const struct pw_node_info *info)
wp_proxy_set_feature_ready (WP_PROXY (self), WP_PROXY_FEATURE_INFO);
}
static void
node_event_param (void *data, int seq, uint32_t id, uint32_t index,
uint32_t next, const struct spa_pod *param)
{
WpProxyNode *self = WP_PROXY_NODE (data);
GTask *task;
g_signal_emit (self, signals[SIGNAL_PARAM], 0, seq, id, index, next, param);
/* if this param event was emited because of enum_params_collect(),
* copy the param in the result array of that API */
task = wp_proxy_find_async_task (WP_PROXY (self), seq, FALSE);
if (task) {
GPtrArray *array = g_task_get_task_data (task);
g_ptr_array_add (array, spa_pod_copy (param));
}
}
static const struct pw_node_events node_events = {
PW_VERSION_NODE_EVENTS,
.info = node_event_info,
.param = node_event_param,
.param = wp_proxy_handle_event_param,
};
static void
@@ -124,172 +125,12 @@ wp_proxy_node_class_init (WpProxyNodeClass * klass)
WpProxyClass *proxy_class = (WpProxyClass *) klass;
object_class->finalize = wp_proxy_node_finalize;
object_class->get_property = wp_proxy_node_get_property;
proxy_class->get_info = wp_proxy_node_get_info;
proxy_class->get_properties = wp_proxy_node_get_properties;
proxy_class->enum_params = wp_proxy_node_enum_params;
proxy_class->subscribe_params = wp_proxy_node_subscribe_params;
proxy_class->set_param = wp_proxy_node_set_param;
proxy_class->pw_proxy_created = wp_proxy_node_pw_proxy_created;
g_object_class_install_property (object_class, PROP_INFO,
g_param_spec_pointer ("info", "info", "The struct pw_node_info *",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the proxy", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
signals[SIGNAL_PARAM] = g_signal_new ("param", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 5,
G_TYPE_INT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_POINTER);
}
const struct pw_node_info *
wp_proxy_node_get_info (WpProxyNode * self)
{
return self->info;
}
WpProperties *
wp_proxy_node_get_properties (WpProxyNode * self)
{
return wp_properties_new_wrap_dict (self->info->props);
}
static void
enum_params_done (WpCore * core, GAsyncResult * res, gpointer data)
{
int seq = GPOINTER_TO_INT (g_task_get_source_tag (G_TASK (data)));
WpProxy *proxy = g_task_get_source_object (G_TASK (data));
g_autoptr (GTask) task = NULL;
g_autoptr (GError) error = NULL;
/* finish the sync task */
wp_core_sync_finish (core, res, &error);
/* find the enum params task in the hash table to steal the reference */
task = wp_proxy_find_async_task (proxy, seq, TRUE);
g_return_if_fail (task != NULL);
if (error)
g_task_return_error (task, g_steal_pointer (&error));
else {
GPtrArray *params = g_task_get_task_data (task);
g_task_return_pointer (task, g_ptr_array_ref (params),
(GDestroyNotify) g_ptr_array_unref);
}
}
void
wp_proxy_node_enum_params_collect (WpProxyNode * self,
guint32 id, const struct spa_pod *filter,
GCancellable * cancellable, GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr (GTask) task = NULL;
int seq;
GPtrArray *params;
g_return_if_fail (WP_IS_PROXY_NODE (self));
/* create task for enum_params */
task = g_task_new (self, cancellable, callback, user_data);
params = g_ptr_array_new_with_free_func (free);
g_task_set_task_data (task, params, (GDestroyNotify) g_ptr_array_unref);
/* call enum_params */
seq = wp_proxy_node_enum_params (self, id, filter);
if (G_UNLIKELY (seq < 0)) {
g_task_return_new_error (task, WP_DOMAIN_LIBRARY,
WP_LIBRARY_ERROR_OPERATION_FAILED, "enum_params failed: %s",
g_strerror (-seq));
return;
}
wp_proxy_register_async_task (WP_PROXY (self), seq, g_object_ref (task));
g_task_set_source_tag (task, GINT_TO_POINTER (seq));
/* call sync */
g_autoptr (WpCore) core = wp_proxy_get_core (WP_PROXY (self));
wp_core_sync (core, cancellable, (GAsyncReadyCallback) enum_params_done,
task);
}
/**
* wp_proxy_node_enum_params_collect_finish:
*
* Returns: (transfer full) (element-type spa_pod*):
* the collected params
*/
GPtrArray *
wp_proxy_node_enum_params_collect_finish (WpProxyNode * self,
GAsyncResult * res, GError ** error)
{
g_return_val_if_fail (WP_IS_PROXY_NODE (self), NULL);
g_return_val_if_fail (g_task_is_valid (res, self), NULL);
return g_task_propagate_pointer (G_TASK (res), error);
}
gint
wp_proxy_node_enum_params (WpProxyNode * self,
guint32 id, const struct spa_pod *filter)
{
struct pw_node *pwp;
int enum_params_result;
g_return_val_if_fail (WP_IS_PROXY_NODE (self), -EINVAL);
pwp = (struct pw_node *) wp_proxy_get_pw_proxy (WP_PROXY (self));
g_return_val_if_fail (pwp != NULL, -EINVAL);
enum_params_result = pw_node_enum_params (pwp, 0, id, 0, -1, filter);
g_warn_if_fail (enum_params_result >= 0);
return enum_params_result;
}
void
wp_proxy_node_subscribe_params (WpProxyNode * self, guint32 n_ids, ...)
{
va_list args;
guint32 *ids = g_alloca (n_ids * sizeof (guint32));
va_start (args, n_ids);
for (gint i = 0; i < n_ids; i++)
ids[i] = va_arg (args, guint32);
va_end (args);
wp_proxy_node_subscribe_params_array (self, n_ids, ids);
}
void
wp_proxy_node_subscribe_params_array (WpProxyNode * self, guint32 n_ids,
guint32 *ids)
{
struct pw_node *pwp;
int node_subscribe_params_result;
g_return_if_fail (WP_IS_PROXY_NODE (self));
pwp = (struct pw_node *) wp_proxy_get_pw_proxy (WP_PROXY (self));
g_return_if_fail (pwp != NULL);
node_subscribe_params_result = pw_node_subscribe_params (
pwp, ids, n_ids);
g_warn_if_fail (node_subscribe_params_result >= 0);
}
void
wp_proxy_node_set_param (WpProxyNode * self, guint32 id,
guint32 flags, const struct spa_pod *param)
{
struct pw_node *pwp;
int node_set_param_result;
g_return_if_fail (WP_IS_PROXY_NODE (self));
pwp = (struct pw_node *) wp_proxy_get_pw_proxy (WP_PROXY (self));
g_return_if_fail (pwp != NULL);
node_set_param_result = pw_node_set_param (pwp, id, flags, param);
g_warn_if_fail (node_set_param_result >= 0);
}

View File

@@ -13,44 +13,10 @@
G_BEGIN_DECLS
struct spa_pod;
struct pw_node_info;
#define WP_TYPE_PROXY_NODE (wp_proxy_node_get_type ())
WP_API
G_DECLARE_FINAL_TYPE (WpProxyNode, wp_proxy_node, WP, PROXY_NODE, WpProxy)
WP_API
const struct pw_node_info * wp_proxy_node_get_info (WpProxyNode * self);
WP_API
WpProperties * wp_proxy_node_get_properties (WpProxyNode * self);
WP_API
void wp_proxy_node_enum_params_collect (WpProxyNode * self,
guint32 id, const struct spa_pod *filter,
GCancellable * cancellable, GAsyncReadyCallback callback,
gpointer user_data);
WP_API
GPtrArray * wp_proxy_node_enum_params_collect_finish (WpProxyNode * self,
GAsyncResult * res, GError ** error);
WP_API
gint wp_proxy_node_enum_params (WpProxyNode * self,
guint32 id, const struct spa_pod *filter);
WP_API
void wp_proxy_node_subscribe_params (WpProxyNode * self, guint32 n_ids, ...);
WP_API
void wp_proxy_node_subscribe_params_array (WpProxyNode * self, guint32 n_ids,
guint32 *ids);
WP_API
void wp_proxy_node_set_param (WpProxyNode * self, guint32 id,
guint32 flags, const struct spa_pod *param);
G_END_DECLS
#endif

View File

@@ -7,12 +7,9 @@
*/
#include "proxy-port.h"
#include "error.h"
#include "private.h"
#include <pipewire/pipewire.h>
#include <spa/pod/builder.h>
#include <spa/pod/iter.h>
struct _WpProxyPort
{
@@ -23,19 +20,6 @@ struct _WpProxyPort
struct spa_hook listener;
};
enum {
PROP_0,
PROP_INFO,
PROP_PROPERTIES,
};
enum {
SIGNAL_PARAM,
N_SIGNALS
};
static guint32 signals[N_SIGNALS];
G_DEFINE_TYPE (WpProxyPort, wp_proxy_port, WP_TYPE_PROXY)
static void
@@ -53,23 +37,43 @@ wp_proxy_port_finalize (GObject * object)
G_OBJECT_CLASS (wp_proxy_port_parent_class)->finalize (object);
}
static void
wp_proxy_port_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
static gconstpointer
wp_proxy_port_get_info (WpProxy * self)
{
WpProxyPort *self = WP_PROXY_PORT (object);
return WP_PROXY_PORT (self)->info;
}
switch (property_id) {
case PROP_INFO:
g_value_set_pointer (value, self->info);
break;
case PROP_PROPERTIES:
g_value_take_boxed (value, wp_proxy_port_get_properties (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
static WpProperties *
wp_proxy_port_get_properties (WpProxy * self)
{
return wp_properties_new_wrap_dict (WP_PROXY_PORT (self)->info->props);
}
static gint
wp_proxy_port_enum_params (WpProxy * self, guint32 id, guint32 start,
guint32 num, const struct spa_pod *filter)
{
struct pw_port *pwp;
int port_enum_params_result;
pwp = (struct pw_port *) wp_proxy_get_pw_proxy (self);
port_enum_params_result = pw_port_enum_params (pwp, 0, id, start, num, filter);
g_warn_if_fail (port_enum_params_result >= 0);
return port_enum_params_result;
}
static gint
wp_proxy_port_subscribe_params (WpProxy * self, guint32 n_ids, guint32 *ids)
{
struct pw_port *pwp;
int port_subscribe_params_result;
pwp = (struct pw_port *) wp_proxy_get_pw_proxy (self);
port_subscribe_params_result = pw_port_subscribe_params (pwp, ids, n_ids);
g_warn_if_fail (port_subscribe_params_result >= 0);
return port_subscribe_params_result;
}
static void
@@ -86,28 +90,10 @@ port_event_info(void *data, const struct pw_port_info *info)
wp_proxy_set_feature_ready (WP_PROXY (self), WP_PROXY_FEATURE_INFO);
}
static void
port_event_param(void *data, int seq, uint32_t id, uint32_t index,
uint32_t next, const struct spa_pod *param)
{
WpProxyPort *self = WP_PROXY_PORT (data);
GTask *task;
g_signal_emit (self, signals[SIGNAL_PARAM], 0, seq, id, index, next, param);
/* if this param event was emited because of enum_params_collect(),
* copy the param in the result array of that API */
task = wp_proxy_find_async_task (WP_PROXY (self), seq, FALSE);
if (task) {
GPtrArray *array = g_task_get_task_data (task);
g_ptr_array_add (array, spa_pod_copy (param));
}
}
static const struct pw_port_events port_events = {
PW_VERSION_PORT_EVENTS,
.info = port_event_info,
.param = port_event_param,
.param = wp_proxy_handle_event_param,
};
static void
@@ -125,155 +111,11 @@ wp_proxy_port_class_init (WpProxyPortClass * klass)
WpProxyClass *proxy_class = (WpProxyClass *) klass;
object_class->finalize = wp_proxy_port_finalize;
object_class->get_property = wp_proxy_port_get_property;
proxy_class->get_info = wp_proxy_port_get_info;
proxy_class->get_properties = wp_proxy_port_get_properties;
proxy_class->enum_params = wp_proxy_port_enum_params;
proxy_class->subscribe_params = wp_proxy_port_subscribe_params;
proxy_class->pw_proxy_created = wp_proxy_port_pw_proxy_created;
g_object_class_install_property (object_class, PROP_INFO,
g_param_spec_pointer ("info", "info", "The struct pw_port_info *",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the proxy", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
signals[SIGNAL_PARAM] = g_signal_new ("param", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 5,
G_TYPE_INT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_POINTER);
}
const struct pw_port_info *
wp_proxy_port_get_info (WpProxyPort * self)
{
return self->info;
}
WpProperties *
wp_proxy_port_get_properties (WpProxyPort * self)
{
return wp_properties_new_wrap_dict (self->info->props);
}
static void
enum_params_done (WpCore * core, GAsyncResult * res, gpointer data)
{
int seq = GPOINTER_TO_INT (g_task_get_source_tag (G_TASK (data)));
WpProxy *proxy = g_task_get_source_object (G_TASK (data));
g_autoptr (GTask) task = NULL;
g_autoptr (GError) error = NULL;
/* finish the sync task */
wp_core_sync_finish (core, res, &error);
/* find the enum params task in the hash table to steal the reference */
task = wp_proxy_find_async_task (proxy, seq, TRUE);
g_return_if_fail (task != NULL);
if (error)
g_task_return_error (task, g_steal_pointer (&error));
else {
GPtrArray *params = g_task_get_task_data (task);
g_task_return_pointer (task, g_ptr_array_ref (params),
(GDestroyNotify) g_ptr_array_unref);
}
}
void
wp_proxy_port_enum_params_collect (WpProxyPort * self,
guint32 id, const struct spa_pod *filter,
GCancellable * cancellable, GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr (GTask) task = NULL;
int seq;
GPtrArray *params;
g_return_if_fail (WP_IS_PROXY_PORT (self));
/* create task for enum_params */
task = g_task_new (self, cancellable, callback, user_data);
params = g_ptr_array_new_with_free_func (free);
g_task_set_task_data (task, params, (GDestroyNotify) g_ptr_array_unref);
/* call enum_params */
seq = wp_proxy_port_enum_params (self, id, filter);
if (G_UNLIKELY (seq < 0)) {
g_task_return_new_error (task, WP_DOMAIN_LIBRARY,
WP_LIBRARY_ERROR_OPERATION_FAILED, "enum_params failed: %s",
g_strerror (-seq));
return;
}
wp_proxy_register_async_task (WP_PROXY (self), seq, g_object_ref (task));
g_task_set_source_tag (task, GINT_TO_POINTER (seq));
/* call sync */
g_autoptr (WpCore) core = wp_proxy_get_core (WP_PROXY (self));
wp_core_sync (core, cancellable, (GAsyncReadyCallback) enum_params_done,
task);
}
/**
* wp_proxy_port_enum_params_collect_finish:
*
* Returns: (transfer full) (element-type spa_pod*):
* the collected params
*/
GPtrArray *
wp_proxy_port_enum_params_collect_finish (WpProxyPort * self,
GAsyncResult * res, GError ** error)
{
g_return_val_if_fail (WP_IS_PROXY_PORT (self), NULL);
g_return_val_if_fail (g_task_is_valid (res, self), NULL);
return g_task_propagate_pointer (G_TASK (res), error);
}
gint
wp_proxy_port_enum_params (WpProxyPort * self,
guint32 id, const struct spa_pod *filter)
{
struct pw_port *pwp;
int enum_params_result;
g_return_val_if_fail (WP_IS_PROXY_PORT (self), -EINVAL);
pwp = (struct pw_port *) wp_proxy_get_pw_proxy (WP_PROXY (self));
g_return_val_if_fail (pwp != NULL, -EINVAL);
enum_params_result = pw_port_enum_params (pwp, 0, id, 0, -1, filter);
g_warn_if_fail (enum_params_result >= 0);
return enum_params_result;
}
void
wp_proxy_port_subscribe_params (WpProxyPort * self, guint32 n_ids, ...)
{
va_list args;
guint32 *ids = g_alloca (n_ids * sizeof (guint32));
va_start (args, n_ids);
for (gint i = 0; i < n_ids; i++)
ids[i] = va_arg (args, guint32);
va_end (args);
wp_proxy_port_subscribe_params_array (self, n_ids, ids);
}
void
wp_proxy_port_subscribe_params_array (WpProxyPort * self, guint32 n_ids,
guint32 *ids)
{
struct pw_port *pwp;
int port_subscribe_params_result;
g_return_if_fail (WP_IS_PROXY_PORT (self));
pwp = (struct pw_port *) wp_proxy_get_pw_proxy (WP_PROXY (self));
g_return_if_fail (pwp != NULL);
port_subscribe_params_result = pw_port_subscribe_params (pwp, ids, n_ids);
g_warn_if_fail (port_subscribe_params_result >= 0);
}

View File

@@ -13,40 +13,10 @@
G_BEGIN_DECLS
struct spa_pod;
struct pw_port_info;
#define WP_TYPE_PROXY_PORT (wp_proxy_port_get_type ())
WP_API
G_DECLARE_FINAL_TYPE (WpProxyPort, wp_proxy_port, WP, PROXY_PORT, WpProxy)
WP_API
const struct pw_port_info * wp_proxy_port_get_info (WpProxyPort * self);
WP_API
WpProperties * wp_proxy_port_get_properties (WpProxyPort * self);
WP_API
void wp_proxy_port_enum_params_collect (WpProxyPort * self,
guint32 id, const struct spa_pod *filter,
GCancellable * cancellable, GAsyncReadyCallback callback,
gpointer user_data);
WP_API
GPtrArray * wp_proxy_port_enum_params_collect_finish (WpProxyPort * self,
GAsyncResult * res, GError ** error);
WP_API
gint wp_proxy_port_enum_params (WpProxyPort * self,
guint32 id, const struct spa_pod *filter);
WP_API
void wp_proxy_port_subscribe_params (WpProxyPort * self, guint32 n_ids, ...);
WP_API
void wp_proxy_port_subscribe_params_array (WpProxyPort * self, guint32 n_ids,
guint32 *ids);
G_END_DECLS
#endif

View File

@@ -28,6 +28,8 @@
#include <pipewire/extensions/session-manager.h>
#include <spa/debug/types.h>
#include <spa/pod/builder.h>
#include <spa/utils/result.h>
typedef struct _WpProxyPrivate WpProxyPrivate;
struct _WpProxyPrivate
@@ -63,14 +65,17 @@ enum {
PROP_INTERFACE_TYPE,
PROP_INTERFACE_VERSION,
PROP_LOCAL_OBJECT,
PROP_PW_PROXY,
PROP_FEATURES,
PROP_PW_PROXY,
PROP_INFO,
PROP_PROPERTIES,
};
enum
{
SIGNAL_PW_PROXY_CREATED,
SIGNAL_PW_PROXY_DESTROYED,
SIGNAL_PARAM,
LAST_SIGNAL,
};
@@ -170,20 +175,9 @@ proxy_event_destroy (void *data)
}
}
static void
proxy_event_done (void *data, int seq)
{
WpProxy *self = WP_PROXY (data);
g_autoptr (GTask) task;
if ((task = wp_proxy_find_async_task (self, seq, TRUE)))
g_task_return_boolean (task, TRUE);
}
static const struct pw_proxy_events proxy_events = {
PW_VERSION_PROXY_EVENTS,
.destroy = proxy_event_destroy,
.done = proxy_event_done,
};
static void
@@ -298,7 +292,8 @@ static void
wp_proxy_get_property (GObject * object, guint property_id, GValue * value,
GParamSpec * pspec)
{
WpProxyPrivate *priv = wp_proxy_get_instance_private (WP_PROXY(object));
WpProxy *self = WP_PROXY (object);
WpProxyPrivate *priv = wp_proxy_get_instance_private (self);
switch (property_id) {
case PROP_CORE:
@@ -322,11 +317,17 @@ wp_proxy_get_property (GObject * object, guint property_id, GValue * value,
case PROP_LOCAL_OBJECT:
g_value_set_pointer (value, priv->local_object);
break;
case PROP_FEATURES:
g_value_set_flags (value, priv->ft_ready);
break;
case PROP_PW_PROXY:
g_value_set_pointer (value, priv->pw_proxy);
break;
case PROP_FEATURES:
g_value_set_flags (value, priv->ft_ready);
case PROP_INFO:
g_value_set_pointer (value, (gpointer) wp_proxy_get_info (self));
break;
case PROP_PROPERTIES:
g_value_take_boxed (value, wp_proxy_get_properties (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -421,13 +422,22 @@ wp_proxy_class_init (WpProxyClass * klass)
"The local object this proxy refers to, if any",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_FEATURES,
g_param_spec_flags ("features", "features",
"The ready WpProxyFeatures on this proxy", WP_TYPE_PROXY_FEATURES, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PW_PROXY,
g_param_spec_pointer ("pw-proxy", "pw-proxy", "The struct pw_proxy *",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_FEATURES,
g_param_spec_flags ("features", "features",
"The ready WpProxyFeatures on this proxy", WP_TYPE_PROXY_FEATURES, 0,
g_object_class_install_property (object_class, PROP_INFO,
g_param_spec_pointer ("info", "info", "The native info structure",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the object", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/* Signals */
@@ -440,6 +450,11 @@ wp_proxy_class_init (WpProxyClass * klass)
"pw-proxy-destroyed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (WpProxyClass, pw_proxy_destroyed), NULL, NULL, NULL,
G_TYPE_NONE, 0);
wp_proxy_signals[SIGNAL_PARAM] = g_signal_new (
"param", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (WpProxyClass, param), NULL, NULL, NULL, G_TYPE_NONE, 5,
G_TYPE_INT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_POINTER);
}
WpProxy *
@@ -678,9 +693,44 @@ wp_proxy_get_pw_proxy (WpProxy * self)
}
/**
* wp_proxy_register_async_task: (skip)
* wp_proxy_get_info:
* @self: the proxy
*
* Returns: the pipewire info structure of this object
* (pw_node_info, pw_port_info, etc...)
*/
void
gconstpointer
wp_proxy_get_info (WpProxy * self)
{
g_return_val_if_fail (WP_IS_PROXY (self), NULL);
WpProxyPrivate *priv = wp_proxy_get_instance_private (self);
g_warn_if_fail (priv->ft_ready & WP_PROXY_FEATURE_INFO);
return (WP_PROXY_GET_CLASS (self)->get_info) ?
WP_PROXY_GET_CLASS (self)->get_info (self) : NULL;
}
/**
* wp_proxy_get_properties:
* @self: the proxy
*
* Returns: (transfer full): the pipewire properties of this object;
* normally these are the properties that are part of the info structure
*/
WpProperties *
wp_proxy_get_properties (WpProxy * self)
{
g_return_val_if_fail (WP_IS_PROXY (self), NULL);
WpProxyPrivate *priv = wp_proxy_get_instance_private (self);
g_warn_if_fail (priv->ft_ready & WP_PROXY_FEATURE_INFO);
return (WP_PROXY_GET_CLASS (self)->get_properties) ?
WP_PROXY_GET_CLASS (self)->get_properties (self) : NULL;
}
static void
wp_proxy_register_async_task (WpProxy * self, int seq, GTask * task)
{
WpProxyPrivate *priv;
@@ -692,10 +742,7 @@ wp_proxy_register_async_task (WpProxy * self, int seq, GTask * task)
g_hash_table_insert (priv->async_tasks, GINT_TO_POINTER (seq), task);
}
/**
* wp_proxy_find_async_task: (skip)
*/
GTask *
static GTask *
wp_proxy_find_async_task (WpProxy * self, int seq, gboolean steal)
{
WpProxyPrivate *priv;
@@ -712,3 +759,238 @@ wp_proxy_find_async_task (WpProxy * self, int seq, gboolean steal)
return task;
}
/**
* wp_proxy_enum_params:
* @self: the proxy
* @id: the parameter id to enum or PW_ID_ANY for all
* @start: the start index or 0 for the first param
* @num: the maximum number of params to retrieve
* @filter: (nullable): a param filter or NULL
*
* Starts enumeration of object parameters. For each param, the
* #WpProxy::param signal will be emited.
*
* This method gives access to the low level `enum_params` method of the object,
* if it exists. For most use cases, prefer using a higher level API, such as
* wp_proxy_enum_params_collect() or something from the subclasses of #WpProxy
*
* Returns: On success, this returns a sequence number that can be used
* to track which emissions of the #WpProxy::param signal are responses
* to this call. On failure, it returns a negative number, which could be:
* * -EINVAL: An invalid parameter was passed
* * -EIO: The object is not ready to receive this method call
* * -ENOTSUP: this method is not supported on this object
*/
gint
wp_proxy_enum_params (WpProxy * self, guint32 id, guint32 start,
guint32 num, const struct spa_pod *filter)
{
g_return_val_if_fail (WP_IS_PROXY (self), -EINVAL);
WpProxyPrivate *priv = wp_proxy_get_instance_private (self);
g_return_val_if_fail (priv->pw_proxy, -EIO);
return (WP_PROXY_GET_CLASS (self)->enum_params) ?
WP_PROXY_GET_CLASS (self)->enum_params (self, id, start, num, filter) :
-ENOTSUP;
}
static void
enum_params_done (WpCore * core, GAsyncResult * res, gpointer data)
{
int seq = GPOINTER_TO_INT (g_task_get_source_tag (G_TASK (data)));
WpProxy *proxy = g_task_get_source_object (G_TASK (data));
g_autoptr (GTask) task = NULL;
g_autoptr (GError) error = NULL;
/* finish the sync task */
wp_core_sync_finish (core, res, &error);
/* find the enum params task in the hash table to steal the reference */
task = wp_proxy_find_async_task (proxy, seq, TRUE);
g_return_if_fail (task != NULL);
if (error)
g_task_return_error (task, g_steal_pointer (&error));
else {
GPtrArray *params = g_task_get_task_data (task);
g_task_return_pointer (task, g_ptr_array_ref (params),
(GDestroyNotify) g_ptr_array_unref);
}
}
/**
* wp_proxy_enum_params_collect:
* @self: the proxy
* @id: the parameter id to enum or PW_ID_ANY for all
* @start: the start index or 0 for the first param
* @num: the maximum number of params to retrieve
* @filter: (nullable): a param filter or NULL
* @cancellable: (nullable): a cancellable for the async operation
* @callback: (scope async): a callback to call with the result
* @user_data: (closure): data to pass to @callback
*
* Enumerate object parameters. This will asynchronously return the result,
* or an error, by calling the given @callback. The result is going to
* be a #GPtrArray containing spa_pod pointers, which can be retrieved
* with wp_proxy_enum_params_collect_finish().
*/
void
wp_proxy_enum_params_collect (WpProxy * self,
guint32 id, guint32 start, guint32 num, const struct spa_pod *filter,
GCancellable * cancellable, GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr (GTask) task = NULL;
int seq;
GPtrArray *params;
g_return_if_fail (WP_IS_PROXY (self));
/* create task for enum_params */
task = g_task_new (self, cancellable, callback, user_data);
params = g_ptr_array_new_with_free_func (free);
g_task_set_task_data (task, params, (GDestroyNotify) g_ptr_array_unref);
/* call enum_params */
seq = wp_proxy_enum_params (self, id, start, num, filter);
if (G_UNLIKELY (seq < 0)) {
g_task_return_new_error (task, WP_DOMAIN_LIBRARY,
WP_LIBRARY_ERROR_OPERATION_FAILED, "enum_params failed: %s",
spa_strerror (seq));
return;
}
g_task_set_source_tag (task, GINT_TO_POINTER (seq));
wp_proxy_register_async_task (self, seq, g_object_ref (task));
/* call sync */
g_autoptr (WpCore) core = wp_proxy_get_core (self);
wp_core_sync (core, cancellable, (GAsyncReadyCallback) enum_params_done,
task);
}
/**
* wp_proxy_enum_params_collect_finish:
*
* Returns: (transfer full) (element-type spa_pod*):
* the collected params
*/
GPtrArray *
wp_proxy_enum_params_collect_finish (WpProxy * self,
GAsyncResult * res, GError ** error)
{
g_return_val_if_fail (WP_IS_PROXY (self), NULL);
g_return_val_if_fail (g_task_is_valid (res, self), NULL);
return g_task_propagate_pointer (G_TASK (res), error);
}
/**
* wp_proxy_subscribe_params: (skip)
* @self: the proxy
* @n_ids: the number of IDs specified in the the variable arugments list
*
* Sets up the proxy to automatically emit the #WpProxy::param signal for
* the given ids when they are changed.
*
* Returns: A positive number or zero on success. On failure, it returns
* a negative number. Well known failure codes are:
* * -EINVAL: An invalid parameter was passed
* * -EIO: The object is not ready to receive this method call
* * -ENOTSUP: this method is not supported on this object
*/
gint
wp_proxy_subscribe_params (WpProxy * self, guint32 n_ids, ...)
{
g_return_val_if_fail (WP_IS_PROXY (self), -EINVAL);
g_return_val_if_fail (n_ids != 0, -EINVAL);
va_list args;
guint32 *ids = g_alloca (n_ids * sizeof (guint32));
va_start (args, n_ids);
for (gint i = 0; i < n_ids; i++)
ids[i] = va_arg (args, guint32);
va_end (args);
return wp_proxy_subscribe_params_array (self, n_ids, ids);
}
/**
* wp_proxy_subscribe_params_array: (rename-to wp_proxy_subscribe_params)
* @self: the proxy
* @n_ids: the number of IDs specified in @ids
* @ids: (array length=n_ids): a list of param IDs to subscribe to
*
* Sets up the proxy to automatically emit the #WpProxy::param signal for
* the given ids when they are changed.
*
* Returns: A positive number or zero on success. On failure, it returns
* a negative number. Well known failure codes are:
* * -EINVAL: An invalid parameter was passed
* * -EIO: The object is not ready to receive this method call
* * -ENOTSUP: this method is not supported on this object
*/
gint
wp_proxy_subscribe_params_array (WpProxy * self, guint32 n_ids, guint32 *ids)
{
g_return_val_if_fail (WP_IS_PROXY (self), -EINVAL);
g_return_val_if_fail (n_ids != 0, -EINVAL);
g_return_val_if_fail (ids != NULL, -EINVAL);
WpProxyPrivate *priv = wp_proxy_get_instance_private (self);
g_return_val_if_fail (priv->pw_proxy, -EIO);
return (WP_PROXY_GET_CLASS (self)->subscribe_params) ?
WP_PROXY_GET_CLASS (self)->subscribe_params (self, n_ids, ids) :
-ENOTSUP;
}
/**
* wp_proxy_set_param:
* @self: the proxy
* @id: the parameter id to set
* @flags: extra parameter flags
* @param: the parameter to set
*
* Sets a parameter on the object.
*
* Returns: A positive number or zero on success. On failure, it returns
* a negative number. Well known failure codes are:
* * -EINVAL: An invalid parameter was passed
* * -EIO: The object is not ready to receive this method call
* * -ENOTSUP: this method is not supported on this object
*/
gint
wp_proxy_set_param (WpProxy * self, guint32 id, guint32 flags,
const struct spa_pod *param)
{
g_return_val_if_fail (WP_IS_PROXY (self), -EINVAL);
WpProxyPrivate *priv = wp_proxy_get_instance_private (self);
g_return_val_if_fail (priv->pw_proxy, -EIO);
return (WP_PROXY_GET_CLASS (self)->set_param) ?
WP_PROXY_GET_CLASS (self)->set_param (self, id, flags, param) :
-ENOTSUP;
}
void
wp_proxy_handle_event_param (void * proxy, int seq, uint32_t id,
uint32_t index, uint32_t next, const struct spa_pod *param)
{
WpProxy *self = WP_PROXY (proxy);
GTask *task;
g_signal_emit (self, wp_proxy_signals[SIGNAL_PARAM], 0, seq, id, index, next,
param);
/* if this param event was emited because of enum_params_collect(),
* copy the param in the result array of that API */
task = wp_proxy_find_async_task (self, seq, FALSE);
if (task) {
GPtrArray *array = g_task_get_task_data (task);
g_ptr_array_add (array, spa_pod_copy (param));
}
}

View File

@@ -17,6 +17,7 @@
G_BEGIN_DECLS
struct pw_proxy;
struct spa_pod;
typedef struct _WpCore WpCore;
typedef enum { /*< flags >*/
@@ -37,14 +38,29 @@ struct _WpProxyClass
void (*augment) (WpProxy *self, WpProxyFeatures features);
gconstpointer (*get_info) (WpProxy * self);
WpProperties * (*get_properties) (WpProxy * self);
gint (*enum_params) (WpProxy * self, guint32 id, guint32 start, guint32 num,
const struct spa_pod * filter);
gint (*subscribe_params) (WpProxy * self, guint32 n_ids, guint32 *ids);
gint (*set_param) (WpProxy * self, guint32 id, guint32 flags,
const struct spa_pod * param);
/* signals */
void (*pw_proxy_created) (WpProxy * self, struct pw_proxy * proxy);
void (*pw_proxy_destroyed) (WpProxy * self);
void (*param) (WpProxy * self, gint seq, guint32 id, guint32 index,
guint32 next, const struct spa_pod *param);
};
WP_API
WpProxy * wp_proxy_new_wrap (WpCore * core, struct pw_proxy * proxy,
const char *type, guint32 version, gpointer local_object);
/* features API */
WP_API
void wp_proxy_augment (WpProxy *self,
WpProxyFeatures wanted_features, GCancellable * cancellable,
@@ -57,9 +73,13 @@ gboolean wp_proxy_augment_finish (WpProxy * self, GAsyncResult * res,
WP_API
WpProxyFeatures wp_proxy_get_features (WpProxy * self);
/* the owner core */
WP_API
WpCore * wp_proxy_get_core (WpProxy * self);
/* global object API */
WP_API
gboolean wp_proxy_is_global (WpProxy * self);
@@ -72,15 +92,54 @@ guint32 wp_proxy_get_global_permissions (WpProxy * self);
WP_API
WpProperties * wp_proxy_get_global_properties (WpProxy * self);
/* the pipewire type & version */
WP_API
const char * wp_proxy_get_interface_type (WpProxy * self);
WP_API
guint32 wp_proxy_get_interface_version (WpProxy * self);
/* native pw_proxy object getter (requires FEATURE_PW_PROXY) */
WP_API
struct pw_proxy * wp_proxy_get_pw_proxy (WpProxy * self);
/* native info structure + wrappers (requires FEATURE_INFO) */
WP_API
gconstpointer wp_proxy_get_info (WpProxy * self);
WP_API
WpProperties * wp_proxy_get_properties (WpProxy * self);
/* common API of most proxied objects */
WP_API
gint wp_proxy_enum_params (WpProxy * self, guint32 id, guint32 start,
guint32 num, const struct spa_pod *filter);
WP_API
void wp_proxy_enum_params_collect (WpProxy * self,
guint32 id, guint32 start, guint32 num, const struct spa_pod *filter,
GCancellable * cancellable, GAsyncReadyCallback callback,
gpointer user_data);
WP_API
GPtrArray * wp_proxy_enum_params_collect_finish (WpProxy * self,
GAsyncResult * res, GError ** error);
WP_API
gint wp_proxy_subscribe_params (WpProxy * self, guint32 n_ids, ...);
WP_API
gint wp_proxy_subscribe_params_array (WpProxy * self, guint32 n_ids,
guint32 *ids);
WP_API
gint wp_proxy_set_param (WpProxy * self, guint32 id, guint32 flags,
const struct spa_pod *param);
G_END_DECLS
#endif

View File

@@ -15,12 +15,6 @@
#include <spa/pod/builder.h>
#include <spa/pod/parser.h>
enum {
PROXY_PROP_0,
PROXY_PROP_INFO,
PROXY_PROP_PROPERTIES,
};
enum {
EXPORTED_PROP_0,
EXPORTED_PROP_GLOBAL_ID,
@@ -87,26 +81,12 @@ G_DEFINE_INTERFACE (WpSession, wp_session, G_TYPE_OBJECT)
static void
wp_session_default_init (WpSessionInterface * klass)
{
g_object_interface_install_property (klass,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the object", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
signals[SIGNAL_DEFAULT_ENDPOINT_CHANGED] = g_signal_new (
"default-endpoint-changed", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2,
WP_TYPE_DEFAULT_ENDPOINT_TYPE, G_TYPE_UINT);
}
WpProperties *
wp_session_get_properties (WpSession * self)
{
g_return_val_if_fail (WP_IS_SESSION (self), NULL);
g_return_val_if_fail (WP_SESSION_GET_IFACE (self)->get_properties, NULL);
return WP_SESSION_GET_IFACE (self)->get_properties (self);
}
guint32
wp_session_get_default_endpoint (WpSession * self,
WpDefaultEndpointType type)
@@ -161,23 +141,60 @@ wp_proxy_session_finalize (GObject * object)
G_OBJECT_CLASS (wp_proxy_session_parent_class)->finalize (object);
}
static void
wp_proxy_session_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
static gconstpointer
wp_proxy_session_get_info (WpProxy * proxy)
{
WpProxySession *self = WP_PROXY_SESSION (object);
return WP_PROXY_SESSION (proxy)->info;
}
switch (property_id) {
case PROXY_PROP_INFO:
g_value_set_pointer (value, self->info);
break;
case PROXY_PROP_PROPERTIES:
g_value_set_boxed (value, self->properties);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
static WpProperties *
wp_proxy_session_get_properties (WpProxy * proxy)
{
WpProxySession *self = WP_PROXY_SESSION (proxy);
return wp_properties_ref (self->properties);
}
static gint
wp_proxy_session_enum_params (WpProxy * self, guint32 id, guint32 start,
guint32 num, const struct spa_pod *filter)
{
struct pw_session *pwp;
int session_enum_params_result;
pwp = (struct pw_session *) wp_proxy_get_pw_proxy (self);
session_enum_params_result = pw_session_enum_params (pwp, 0, id, start, num,
filter);
g_warn_if_fail (session_enum_params_result >= 0);
return session_enum_params_result;
}
static gint
wp_proxy_session_subscribe_params (WpProxy * self, guint32 n_ids, guint32 *ids)
{
struct pw_session *pwp;
int session_subscribe_params_result;
pwp = (struct pw_session *) wp_proxy_get_pw_proxy (self);
session_subscribe_params_result = pw_session_subscribe_params (pwp, ids,
n_ids);
g_warn_if_fail (session_subscribe_params_result >= 0);
return session_subscribe_params_result;
}
static gint
wp_proxy_session_set_param (WpProxy * self, guint32 id, guint32 flags,
const struct spa_pod *param)
{
struct pw_session *pwp;
int session_set_param_result;
pwp = (struct pw_session *) wp_proxy_get_pw_proxy (self);
session_set_param_result = pw_session_set_param (pwp, id, flags, param);
g_warn_if_fail (session_set_param_result >= 0);
return session_set_param_result;
}
static void
@@ -194,11 +211,25 @@ session_event_info (void *data, const struct pw_session_info *info)
wp_proxy_set_feature_ready (WP_PROXY (self), WP_PROXY_FEATURE_INFO);
}
static const struct pw_session_events session_events = {
PW_VERSION_SESSION_EVENTS,
.info = session_event_info,
.param = wp_proxy_handle_event_param,
};
static void
session_event_param (void *data, int seq, uint32_t id, uint32_t index,
uint32_t next, const struct spa_pod *param)
wp_proxy_session_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
{
WpProxySession *self = WP_PROXY_SESSION (data);
WpProxySession *self = WP_PROXY_SESSION (proxy);
pw_session_add_listener ((struct pw_session *) pw_proxy,
&self->listener, &session_events, self);
}
static void
wp_proxy_session_param (WpProxy * proxy, gint seq, guint32 id, guint32 index,
guint32 next, const struct spa_pod *param)
{
WpProxySession *self = WP_PROXY_SESSION (proxy);
g_autoptr (GArray) changed_ids = NULL;
guint32 prop_id;
gint32 value;
@@ -226,20 +257,6 @@ session_event_param (void *data, int seq, uint32_t id, uint32_t index,
}
}
static const struct pw_session_events session_events = {
PW_VERSION_SESSION_EVENTS,
.info = session_event_info,
.param = session_event_param,
};
static void
wp_proxy_session_pw_proxy_created (WpProxy * proxy, struct pw_proxy * pw_proxy)
{
WpProxySession *self = WP_PROXY_SESSION (proxy);
pw_session_add_listener ((struct pw_session *) pw_proxy,
&self->listener, &session_events, self);
}
static void
wp_proxy_session_augment (WpProxy * proxy, WpProxyFeatures features)
{
@@ -259,13 +276,6 @@ wp_proxy_session_augment (WpProxy * proxy, WpProxyFeatures features)
}
}
static WpProperties *
wp_proxy_session_get_properties (WpSession * session)
{
WpProxySession *self = WP_PROXY_SESSION (session);
return wp_properties_ref (self->properties);
}
static guint32
wp_proxy_session_get_default_endpoint (WpSession * session,
WpDefaultEndpointType type)
@@ -307,33 +317,25 @@ wp_proxy_session_class_init (WpProxySessionClass * klass)
WpProxyClass *proxy_class = (WpProxyClass *) klass;
object_class->finalize = wp_proxy_session_finalize;
object_class->get_property = wp_proxy_session_get_property;
proxy_class->augment = wp_proxy_session_augment;
proxy_class->get_info = wp_proxy_session_get_info;
proxy_class->get_properties = wp_proxy_session_get_properties;
proxy_class->enum_params = wp_proxy_session_enum_params;
proxy_class->subscribe_params = wp_proxy_session_subscribe_params;
proxy_class->set_param = wp_proxy_session_set_param;
proxy_class->pw_proxy_created = wp_proxy_session_pw_proxy_created;
proxy_class->augment = wp_proxy_session_augment;
g_object_class_install_property (object_class, PROXY_PROP_INFO,
g_param_spec_pointer ("info", "info", "The native info structure",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_override_property (object_class, PROXY_PROP_PROPERTIES,
"properties");
proxy_class->param = wp_proxy_session_param;
}
static void
wp_proxy_session_iface_init (WpSessionInterface * iface)
{
iface->get_properties = wp_proxy_session_get_properties;
iface->get_default_endpoint = wp_proxy_session_get_default_endpoint;
iface->set_default_endpoint = wp_proxy_session_set_default_endpoint;
}
const struct pw_session_info *
wp_proxy_session_get_info (WpProxySession * self)
{
g_return_val_if_fail (WP_IS_PROXY_SESSION (self), NULL);
return self->info;
}
/* exported */
typedef struct _WpExportedSessionPrivate WpExportedSessionPrivate;
@@ -544,15 +546,6 @@ wp_exported_session_get_proxy (WpExported * self)
return priv->client_sess ? g_object_ref (priv->client_sess) : NULL;
}
static WpProperties *
wp_exported_session_get_properties (WpSession * session)
{
WpExportedSessionPrivate *priv =
wp_exported_session_get_instance_private (WP_EXPORTED_SESSION (session));
return wp_properties_ref (priv->properties);
}
static guint32
wp_exported_session_get_default_endpoint (WpSession * session,
WpDefaultEndpointType type)
@@ -603,14 +596,16 @@ wp_exported_session_class_init (WpExportedSessionClass * klass)
g_param_spec_uint ("global-id", "global-id",
"The pipewire global id of the exported session", 0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_override_property (object_class, EXPORTED_PROP_PROPERTIES,
"properties");
g_object_class_install_property (object_class, EXPORTED_PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The pipewire properties of the object", WP_TYPE_PROPERTIES,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
static void
wp_exported_session_iface_init (WpSessionInterface * iface)
{
iface->get_properties = wp_exported_session_get_properties;
iface->get_default_endpoint = wp_exported_session_get_default_endpoint;
iface->set_default_endpoint = wp_exported_session_set_default_endpoint;
}
@@ -643,6 +638,15 @@ wp_exported_session_get_global_id (WpExportedSession * self)
return priv->info.id;
}
WpProperties *
wp_exported_session_get_properties (WpExportedSession * self)
{
WpExportedSessionPrivate *priv =
wp_exported_session_get_instance_private (WP_EXPORTED_SESSION (self));
return wp_properties_ref (priv->properties);
}
void
wp_exported_session_set_property (WpExportedSession * self,
const gchar * key, const gchar * value)

View File

@@ -28,17 +28,12 @@ struct _WpSessionInterface
{
GTypeInterface parent;
WpProperties * (*get_properties) (WpSession * self);
guint32 (*get_default_endpoint) (WpSession * self,
WpDefaultEndpointType type);
void (*set_default_endpoint) (WpSession * self,
WpDefaultEndpointType type, guint32 id);
};
WP_API
WpProperties * wp_session_get_properties (WpSession * self);
WP_API
guint32 wp_session_get_default_endpoint (WpSession * self,
WpDefaultEndpointType type);
@@ -57,9 +52,6 @@ typedef enum { /*< flags >*/
WP_API
G_DECLARE_FINAL_TYPE (WpProxySession, wp_proxy_session, WP, PROXY_SESSION, WpProxy)
WP_API
const struct pw_session_info * wp_proxy_session_get_info (WpProxySession * self);
/* exported */
#define WP_TYPE_EXPORTED_SESSION (wp_exported_session_get_type ())
@@ -77,6 +69,9 @@ WpExportedSession * wp_exported_session_new (WpCore * core);
WP_API
guint32 wp_exported_session_get_global_id (WpExportedSession * self);
WP_API
WpProperties * wp_exported_session_get_properties (WpExportedSession * self);
WP_API
void wp_exported_session_set_property (WpExportedSession * self,
const gchar * key, const gchar * value);

View File

@@ -18,7 +18,7 @@ client_added (WpObjectManager * om, WpProxyClient *client, gpointer data)
g_debug ("Client added: %d", id);
properties = wp_proxy_client_get_properties (client);
properties = wp_proxy_get_properties (WP_PROXY (client));
access = wp_properties_get (properties, PW_KEY_ACCESS);
if (!g_strcmp0 (access, "flatpak") || !g_strcmp0 (access, "restricted")) {

View File

@@ -105,8 +105,7 @@ on_node_added (WpObjectManager *om, WpProxy *proxy, gpointer d)
WpConfigEndpointContext *self = d;
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
g_autoptr (WpConfiguration) config = wp_configuration_get_instance (core);
WpProxyNode *proxy_node = WP_PROXY_NODE (proxy);
g_autoptr (WpProperties) props = wp_proxy_node_get_properties (proxy_node);
g_autoptr (WpProperties) props = wp_proxy_get_properties (proxy);
g_autoptr (WpConfigParser) parser = NULL;
const struct WpParserEndpointData *endpoint_data = NULL;
GVariantBuilder b;
@@ -116,7 +115,7 @@ on_node_added (WpObjectManager *om, WpProxy *proxy, gpointer d)
/* Get the linked and ep streams data */
parser = wp_configuration_get_parser (config, WP_PARSER_ENDPOINT_EXTENSION);
endpoint_data = wp_config_parser_get_matched_data (parser, proxy_node);
endpoint_data = wp_config_parser_get_matched_data (parser, proxy);
if (!endpoint_data)
return;

View File

@@ -210,12 +210,12 @@ static gconstpointer
wp_parser_endpoint_get_matched_data (WpConfigParser *parser, gpointer data)
{
WpParserEndpoint *self = WP_PARSER_ENDPOINT (parser);
WpProxyNode *node = WP_PROXY_NODE (data);
WpProxy *proxy = WP_PROXY (data);
const struct WpParserEndpointData *d = NULL;
g_autoptr (WpProperties) props = NULL;
g_return_val_if_fail (node, NULL);
props = wp_proxy_node_get_properties (node);
g_return_val_if_fail (proxy, NULL);
props = wp_proxy_get_properties (proxy);
/* Find the first data that matches node */
for (guint i = 0; i < self->datas->len; i++) {

View File

@@ -72,8 +72,7 @@ static void
on_device_added (WpObjectManager *om, WpProxy *proxy, gpointer p)
{
WpConfigStaticNodesContext *self = p;
g_autoptr (WpProperties) dev_props =
wp_proxy_device_get_properties (WP_PROXY_DEVICE (proxy));
g_autoptr (WpProperties) dev_props = wp_proxy_get_properties (proxy);
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
g_autoptr (WpConfiguration) config = wp_configuration_get_instance (core);
g_autoptr (WpConfigParser) parser = NULL;

View File

@@ -100,7 +100,7 @@ endpoint_get_properties (WpBaseEndpoint * ep)
{
WpPwAudioSoftdspEndpoint *self = WP_PW_AUDIO_SOFTDSP_ENDPOINT (ep);
return wp_proxy_node_get_properties (self->proxy_node);
return wp_proxy_get_properties (WP_PROXY (self->proxy_node));
}
static const char *
@@ -232,7 +232,7 @@ do_export (WpPwAudioSoftdspEndpoint *self)
// wp_exported_endpoint_register_control (self->exported_ep,
// WP_ENDPOINT_CONTROL_CHANNEL_VOLUMES);
props = wp_proxy_node_get_properties (self->proxy_node);
props = wp_proxy_get_properties (WP_PROXY (self->proxy_node));
extra_props = wp_properties_new_empty ();
wp_properties_setf (extra_props, PW_KEY_NODE_ID, "%d",
@@ -317,7 +317,7 @@ on_audio_adapter_created(GObject *initable, GAsyncResult *res,
if (!self->adapter)
return;
props = wp_proxy_node_get_properties (self->proxy_node);
props = wp_proxy_get_properties (WP_PROXY (self->proxy_node));
/* Set the role */
self->role = g_strdup (wp_properties_get (props, PW_KEY_MEDIA_ROLE));

View File

@@ -39,7 +39,7 @@ G_DEFINE_TYPE_WITH_CODE (WpAudioAdapter, wp_audio_adapter, WP_TYPE_AUDIO_STREAM,
wp_audio_adapter_async_initable_init))
static void
on_proxy_enum_format_done (WpProxyNode *proxy, GAsyncResult *res,
on_proxy_enum_format_done (WpProxy *proxy, GAsyncResult *res,
WpAudioAdapter *self)
{
g_autoptr (GPtrArray) formats = NULL;
@@ -50,7 +50,7 @@ on_proxy_enum_format_done (WpProxyNode *proxy, GAsyncResult *res,
struct spa_pod_builder pod_builder = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
struct spa_pod *param;
formats = wp_proxy_node_enum_params_collect_finish (proxy, res, &error);
formats = wp_proxy_enum_params_collect_finish (proxy, res, &error);
if (error) {
g_message("WpAudioAdapter:%p enum format error: %s", self, error->message);
wp_audio_stream_init_task_finish (WP_AUDIO_STREAM (self),
@@ -84,7 +84,7 @@ on_proxy_enum_format_done (WpProxyNode *proxy, GAsyncResult *res,
/* set the chosen device/client format on the node */
param = spa_format_audio_raw_build (&pod_builder, SPA_PARAM_Format,
&self->format);
wp_proxy_node_set_param (proxy, SPA_PARAM_Format, 0, param);
wp_proxy_set_param (proxy, SPA_PARAM_Format, 0, param);
/* now choose the DSP format: keep the chanels but use F32 plannar @ 48K */
self->format.format = SPA_AUDIO_FORMAT_F32P;
@@ -120,8 +120,8 @@ wp_audio_adapter_init_async (GAsyncInitable *initable, int io_priority,
wp_audio_adapter_parent_interface->init_async (initable, io_priority,
cancellable, callback, data);
wp_proxy_node_enum_params_collect (proxy, SPA_PARAM_EnumFormat, NULL, NULL,
(GAsyncReadyCallback) on_proxy_enum_format_done, self);
wp_proxy_enum_params_collect (WP_PROXY (proxy), SPA_PARAM_EnumFormat, 0, -1,
NULL, NULL, (GAsyncReadyCallback) on_proxy_enum_format_done, self);
}
static void

View File

@@ -86,10 +86,10 @@ on_audio_convert_running(WpAudioConvert *self)
}
static void
wp_audio_convert_event_info (WpProxyNode * proxy, GParamSpec *spec,
wp_audio_convert_event_info (WpProxy * proxy, GParamSpec *spec,
WpAudioConvert * self)
{
const struct pw_node_info *info = wp_proxy_node_get_info (proxy);
const struct pw_node_info *info = wp_proxy_get_info (proxy);
/* Handle the different states */
switch (info->state) {
@@ -164,7 +164,7 @@ wp_audio_convert_init_async (GAsyncInitable *initable, int io_priority,
/* Create the properties */
node = wp_audio_stream_get_proxy_node (self->target);
props = wp_properties_copy (wp_proxy_node_get_properties (node));
props = wp_properties_copy (wp_proxy_get_properties (WP_PROXY (node)));
wp_properties_setf (props, PW_KEY_OBJECT_PATH, "%s:%s",
wp_properties_get(props, PW_KEY_OBJECT_PATH),

View File

@@ -138,12 +138,12 @@ on_node_proxy_augmented (WpProxy * proxy, GAsyncResult * res,
g_signal_connect_object (proxy, "param",
(GCallback) audio_stream_event_param, self, 0);
wp_proxy_node_subscribe_params (WP_PROXY_NODE (proxy), 1, SPA_PARAM_Props);
wp_proxy_subscribe_params (proxy, 1, SPA_PARAM_Props);
priv->ports_om = wp_object_manager_new ();
/* Get the node id */
info = wp_proxy_node_get_info (WP_PROXY_NODE (proxy));
info = wp_proxy_get_info (proxy);
node_id = g_strdup_printf ("%u", info->id);
/* set a constraint: the port's "node.id" must match
@@ -368,28 +368,28 @@ wp_audio_stream_get_info (WpAudioStream * self)
{
WpAudioStreamPrivate *priv = wp_audio_stream_get_instance_private (self);
return wp_proxy_node_get_info (priv->proxy);
return wp_proxy_get_info (WP_PROXY (priv->proxy));
}
static void
port_proxies_foreach_func(gpointer data, gpointer user_data)
{
WpAudioStream *self = user_data;
WpProxy *port = WP_PROXY (data);
WpAudioStream *self = WP_AUDIO_STREAM (user_data);
WpAudioStreamPrivate *priv = wp_audio_stream_get_instance_private (self);
WpProxyPort *port = data;
const struct pw_node_info *node_info;
const struct pw_port_info *port_info;
g_autoptr (WpProperties) props = NULL;
const gchar *channel;
uint32_t channel_n = SPA_AUDIO_CHANNEL_UNKNOWN;
node_info = wp_proxy_node_get_info (priv->proxy);
node_info = wp_proxy_get_info (WP_PROXY (priv->proxy));
g_return_if_fail (node_info);
port_info = wp_proxy_port_get_info (port);
port_info = wp_proxy_get_info (port);
g_return_if_fail (port_info);
props = wp_proxy_port_get_properties (port);
props = wp_proxy_get_properties (port);
channel = wp_properties_get (props, PW_KEY_AUDIO_CHANNEL);
if (channel) {
const struct spa_type_info *t = spa_type_audio_channel;
@@ -452,7 +452,7 @@ wp_audio_stream_set_volume (WpAudioStream * self, gfloat volume)
/* Make sure the proxy is valid */
g_return_if_fail (priv->proxy);
wp_proxy_node_set_param (priv->proxy,
wp_proxy_set_param (WP_PROXY (priv->proxy),
SPA_PARAM_Props, 0,
spa_pod_builder_add_object (&b,
SPA_TYPE_OBJECT_Props, SPA_PARAM_Props,
@@ -469,7 +469,7 @@ wp_audio_stream_set_mute (WpAudioStream * self, gboolean mute)
/* Make sure the proxy is valid */
g_return_if_fail (priv->proxy);
wp_proxy_node_set_param (priv->proxy,
wp_proxy_set_param (WP_PROXY (priv->proxy),
SPA_PARAM_Props, 0,
spa_pod_builder_add_object (&b,
SPA_TYPE_OBJECT_Props, SPA_PARAM_Props,
@@ -511,7 +511,7 @@ wp_audio_stream_set_port_config (WpAudioStream * self,
{
WpAudioStreamPrivate *priv = wp_audio_stream_get_instance_private (self);
wp_proxy_node_set_param (priv->proxy, SPA_PARAM_PortConfig, 0, param);
wp_proxy_set_param (WP_PROXY (priv->proxy), SPA_PARAM_PortConfig, 0, param);
}
void

View File

@@ -38,7 +38,8 @@ select_new_default_ep (struct module_data * data, WpDefaultEndpointType type,
if (g_strcmp0 (media_class, wp_endpoint_get_media_class (ep)) != 0)
continue;
g_autoptr (WpProperties) properties = wp_endpoint_get_properties (ep);
g_autoptr (WpProperties) properties =
wp_exported_endpoint_get_properties (WP_EXPORTED_ENDPOINT (ep));
priority_str = wp_properties_get (properties, "endpoint.priority");
if (priority_str)

View File

@@ -40,7 +40,7 @@ static WpProperties *
wp_endpoint_audiotestsrc_get_properties (WpBaseEndpoint * ep)
{
WpEndpointAudiotestsrc *self = WP_ENDPOINT_AUDIOTESTSRC (ep);
return wp_proxy_node_get_properties (self->proxy_node);
return wp_proxy_get_properties (WP_PROXY (self->proxy_node));
}
static const char *

View File

@@ -257,7 +257,7 @@ test_endpoint_basic (TestEndpointFixture *fixture, gconstpointer data)
/* verify properties are set before export */
{
g_autoptr (WpProperties) props =
wp_endpoint_get_properties (WP_ENDPOINT (endpoint));
wp_exported_endpoint_get_properties (endpoint);
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
"test-value");
}
@@ -292,7 +292,7 @@ test_endpoint_basic (TestEndpointFixture *fixture, gconstpointer data)
{
g_autoptr (WpProperties) props =
wp_endpoint_get_properties (WP_ENDPOINT (fixture->proxy_endpoint));
wp_proxy_get_properties (fixture->proxy_endpoint);
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
"test-value");
}
@@ -382,13 +382,13 @@ test_endpoint_basic (TestEndpointFixture *fixture, gconstpointer data)
{
g_autoptr (WpProperties) props =
wp_endpoint_get_properties (WP_ENDPOINT (endpoint));
wp_exported_endpoint_get_properties (endpoint);
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
"changed-value");
}
{
g_autoptr (WpProperties) props =
wp_endpoint_get_properties (WP_ENDPOINT (fixture->proxy_endpoint));
wp_proxy_get_properties (fixture->proxy_endpoint);
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
"changed-value");
}

View File

@@ -163,14 +163,14 @@ test_proxy_node_param (WpProxyNode *node, int seq, guint id, guint index,
}
static void
test_proxy_node_enum_params_done (WpProxyNode *node, GAsyncResult *res,
test_proxy_node_enum_params_done (WpProxy *node, GAsyncResult *res,
TestProxyNodeParamData *data)
{
g_autoptr (GPtrArray) params = NULL;
g_autoptr (GError) error = NULL;
guint i;
params = wp_proxy_node_enum_params_collect_finish (node, res, &error);
params = wp_proxy_enum_params_collect_finish (node, res, &error);
g_assert_no_error (error);
g_assert_nonnull (params);
@@ -202,14 +202,13 @@ test_proxy_node_object_added (WpObjectManager *om, WpProxy *proxy,
g_assert_nonnull (wp_proxy_get_pw_proxy (proxy));
g_assert_true (WP_IS_PROXY_NODE (proxy));
info = wp_proxy_node_get_info (WP_PROXY_NODE (proxy));
info = wp_proxy_get_info (proxy);
g_assert_nonnull (info);
g_assert_cmpint (wp_proxy_get_global_id (proxy), ==, info->id);
{
const char *id;
g_autoptr (WpProperties) props =
wp_proxy_node_get_properties (WP_PROXY_NODE (proxy));
g_autoptr (WpProperties) props = wp_proxy_get_properties (proxy);
g_assert_nonnull (props);
g_assert_true (wp_properties_peek_dict (props) == info->props);
@@ -223,7 +222,7 @@ test_proxy_node_object_added (WpObjectManager *om, WpProxy *proxy,
g_signal_connect (proxy, "param", (GCallback) test_proxy_node_param,
param_data);
wp_proxy_node_enum_params_collect (WP_PROXY_NODE (proxy), SPA_PARAM_PropInfo,
wp_proxy_enum_params_collect (proxy, SPA_PARAM_PropInfo, 0, -1,
NULL, NULL, (GAsyncReadyCallback) test_proxy_node_enum_params_done,
param_data);
}

View File

@@ -253,7 +253,7 @@ test_session_basic (TestSessionFixture *fixture, gconstpointer data)
/* verify properties are set before export */
{
g_autoptr (WpProperties) props =
wp_session_get_properties (WP_SESSION (session));
wp_exported_session_get_properties (session);
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
"test-value");
}
@@ -286,7 +286,7 @@ test_session_basic (TestSessionFixture *fixture, gconstpointer data)
{
g_autoptr (WpProperties) props =
wp_session_get_properties (WP_SESSION (fixture->proxy_session));
wp_proxy_get_properties (fixture->proxy_session);
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
"test-value");
}
@@ -359,13 +359,13 @@ test_session_basic (TestSessionFixture *fixture, gconstpointer data)
{
g_autoptr (WpProperties) props =
wp_session_get_properties (WP_SESSION (session));
wp_exported_session_get_properties (session);
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
"changed-value");
}
{
g_autoptr (WpProperties) props =
wp_session_get_properties (WP_SESSION (fixture->proxy_session));
wp_proxy_get_properties (fixture->proxy_session);
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
"changed-value");
}

View File

@@ -183,13 +183,13 @@ device_node_props (WpObjectManager * om, struct WpCliData * d)
g_print ("Capture device nodes:\n");
for (i = 0; i < arr->len; i++) {
WpProxyNode *node = g_ptr_array_index (arr, i);
g_autoptr (WpProperties) props = wp_proxy_node_get_properties (node);
WpProxy *node = g_ptr_array_index (arr, i);
g_autoptr (WpProperties) props = wp_proxy_get_properties (node);
if (g_strcmp0 (wp_properties_get (props, "media.class"), "Audio/Source") != 0)
continue;
g_print (" node id: %u\n", wp_proxy_get_global_id (WP_PROXY (node)));
g_print (" node id: %u\n", wp_proxy_get_global_id (node));
dict = wp_properties_peek_dict (props);
spa_dict_for_each (item, dict) {
@@ -202,13 +202,13 @@ device_node_props (WpObjectManager * om, struct WpCliData * d)
g_print ("Playback device nodes:\n");
for (i = 0; i < arr->len; i++) {
WpProxyNode *node = g_ptr_array_index (arr, i);
g_autoptr (WpProperties) props = wp_proxy_node_get_properties (node);
WpProxy *node = g_ptr_array_index (arr, i);
g_autoptr (WpProperties) props = wp_proxy_get_properties (node);
if (g_strcmp0 (wp_properties_get (props, "media.class"), "Audio/Sink") != 0)
continue;
g_print (" node id: %u\n", wp_proxy_get_global_id (WP_PROXY (node)));
g_print (" node id: %u\n", wp_proxy_get_global_id (node));
dict = wp_properties_peek_dict (props);
spa_dict_for_each (item, dict) {