lib: initial version of the WpSessionItem interfaces

This commit is contained in:
George Kiagiadakis 2020-03-16 17:43:07 +02:00
parent 32dd485649
commit 374c3dc9e2
4 changed files with 436 additions and 0 deletions

View file

@ -17,6 +17,7 @@ wp_lib_sources = files(
'proxy.c',
'session.c',
'session-item.c',
'si-interfaces.c',
'spa-props.c',
'transition.c',
)
@ -41,6 +42,7 @@ wp_lib_headers = files(
'proxy.h',
'session.h',
'session-item.h',
'si-interfaces.h',
'transition.h',
'wp.h',
)

287
lib/wp/si-interfaces.c Normal file
View file

@ -0,0 +1,287 @@
/* WirePlumber
*
* Copyright © 2020 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
/**
* SECTION: WpSiInterfaces
* @title: WpSessionItem Interfaces
*/
#include "si-interfaces.h"
/**
* WpSiEndpoint:
*
* An interface for session items that implement a PipeWire endpoint.
*/
G_DEFINE_INTERFACE (WpSiEndpoint, wp_si_endpoint, WP_TYPE_SESSION_ITEM)
static void
wp_si_endpoint_default_init (WpSiEndpointInterface * iface)
{
}
/**
* wp_si_endpoint_get_name: (virtual get_name)
* @self: the session item
*
* Returns: (transfer none): the name of the endpoint
*/
const gchar *
wp_si_endpoint_get_name (WpSiEndpoint * self)
{
g_return_val_if_fail (WP_IS_SI_ENDPOINT (self), NULL);
g_return_val_if_fail (WP_SI_ENDPOINT_GET_IFACE (self)->get_name, NULL);
return WP_SI_ENDPOINT_GET_IFACE (self)->get_name (self);
}
/**
* wp_si_endpoint_get_media_class: (virtual get_media_class)
* @self: the session item
*
* Returns: (transfer none): the media class of the endpoint
*/
const gchar *
wp_si_endpoint_get_media_class (WpSiEndpoint * self)
{
g_return_val_if_fail (WP_IS_SI_ENDPOINT (self), NULL);
g_return_val_if_fail (WP_SI_ENDPOINT_GET_IFACE (self)->get_media_class, NULL);
return WP_SI_ENDPOINT_GET_IFACE (self)->get_media_class (self);
}
/**
* wp_si_endpoint_get_direction: (virtual get_direction)
* @self: the session item
*
* Returns: the direction of the endpoint
*/
WpDirection
wp_si_endpoint_get_direction (WpSiEndpoint * self)
{
g_return_val_if_fail (WP_IS_SI_ENDPOINT (self), 0);
g_return_val_if_fail (WP_SI_ENDPOINT_GET_IFACE (self)->get_direction, 0);
return WP_SI_ENDPOINT_GET_IFACE (self)->get_direction (self);
}
/**
* wp_si_endpoint_get_priority: (virtual get_priority)
* @self: the session item
*
* Returns: the priority of the endpoint
*/
guint
wp_si_endpoint_get_priority (WpSiEndpoint * self)
{
g_return_val_if_fail (WP_IS_SI_ENDPOINT (self), 0);
g_return_val_if_fail (WP_SI_ENDPOINT_GET_IFACE (self)->get_priority, 0);
return WP_SI_ENDPOINT_GET_IFACE (self)->get_priority (self);
}
/**
* wp_si_endpoint_get_properties: (virtual get_properties)
* @self: the session item
*
* Returns: (transfer full): the properties of the endpoint
*/
WpProperties *
wp_si_endpoint_get_properties (WpSiEndpoint * self)
{
g_return_val_if_fail (WP_IS_SI_ENDPOINT (self), NULL);
g_return_val_if_fail (WP_SI_ENDPOINT_GET_IFACE (self)->get_properties, NULL);
return WP_SI_ENDPOINT_GET_IFACE (self)->get_properties (self);
}
/**
* wp_si_endpoint_get_n_streams: (virtual get_n_streams)
* @self: the session item
*
* Returns: the number of streams in the endpoint
*/
guint
wp_si_endpoint_get_n_streams (WpSiEndpoint * self)
{
g_return_val_if_fail (WP_IS_SI_ENDPOINT (self), 0);
g_return_val_if_fail (WP_SI_ENDPOINT_GET_IFACE (self)->get_n_streams, 0);
return WP_SI_ENDPOINT_GET_IFACE (self)->get_n_streams (self);
}
/**
* wp_si_endpoint_get_stream: (virtual get_stream)
* @self: the session item
* @index: the stream index, from 0 up to and excluding
* wp_si_endpoint_get_n_streams()
*
* Returns: (transfer none): the stream at @index
*/
WpSiStream *
wp_si_endpoint_get_stream (WpSiEndpoint * self, guint index)
{
g_return_val_if_fail (WP_IS_SI_ENDPOINT (self), NULL);
g_return_val_if_fail (WP_SI_ENDPOINT_GET_IFACE (self)->get_stream, NULL);
return WP_SI_ENDPOINT_GET_IFACE (self)->get_stream (self, index);
}
/**
* WpSiMultiEndpoint:
*
* An interface for session items that provide multiple PipeWire endpoints.
*
* This is useful for items that need to expose more than one endpoints while
* managing the same nodes underneath. For example, an audio playback device
* may have one input endpoint for sending audio to the device and one output
* endpoint for monitoring (exposing the adapter's monitor ports).
*
* If an item implements both #WpSiMultiEndpoint and #WpSiEndpoint, then the
* managing session will only inspect the #WpSiMultiEndpoint interface in
* order to determine which endpoints to export. Effectively this means that
* such an item should also include itself in the list of endpoints that
* it exposes through #WpSiMultiEndpoint in order to be exported to PipeWire.
*/
G_DEFINE_INTERFACE (WpSiMultiEndpoint, wp_si_multi_endpoint, WP_TYPE_SESSION_ITEM)
static void
wp_si_multi_endpoint_default_init (WpSiMultiEndpointInterface * iface)
{
}
/**
* wp_si_multi_endpoint_get_n_endpoints: (virtual get_n_endpoints)
* @self: the session item
*
* Returns: the number of endpoints exposed by this item
*/
guint
wp_si_multi_endpoint_get_n_endpoints (WpSiMultiEndpoint * self)
{
g_return_val_if_fail (WP_IS_SI_MULTI_ENDPOINT (self), 0);
g_return_val_if_fail (WP_SI_MULTI_ENDPOINT_GET_IFACE (self)->get_n_endpoints, 0);
return WP_SI_MULTI_ENDPOINT_GET_IFACE (self)->get_n_endpoints (self);
}
/**
* wp_si_multi_endpoint_get_endpoint: (virtual get_endpoint)
* @self: the session item
* @index: the endpoint index, from 0 up to and excluding
* wp_si_multi_endpoint_get_n_endpoints()
*
* Returns: (transfer none): the endpoint at @index
*/
WpSiEndpoint *
wp_si_multi_endpoint_get_endpoint (WpSiMultiEndpoint * self, guint index)
{
g_return_val_if_fail (WP_IS_SI_MULTI_ENDPOINT (self), NULL);
g_return_val_if_fail (WP_SI_MULTI_ENDPOINT_GET_IFACE (self)->get_endpoint, NULL);
return WP_SI_MULTI_ENDPOINT_GET_IFACE (self)->get_endpoint (self, index);
}
/**
* WpSiStream:
*
* An interface for session items that provide a PipeWire endpoint stream.
*/
G_DEFINE_INTERFACE (WpSiStream, wp_si_stream, WP_TYPE_SESSION_ITEM)
static void
wp_si_stream_default_init (WpSiStreamInterface * iface)
{
}
/**
* wp_si_stream_get_name: (virtual get_name)
* @self: the session item
*
* Returns: (transfer none): the name of the stream
*/
const gchar *
wp_si_stream_get_name (WpSiStream * self)
{
g_return_val_if_fail (WP_IS_SI_STREAM (self), NULL);
g_return_val_if_fail (WP_SI_STREAM_GET_IFACE (self)->get_name, NULL);
return WP_SI_STREAM_GET_IFACE (self)->get_name (self);
}
/**
* wp_si_stream_get_properties: (virtual get_properties)
* @self: the session item
*
* Returns: (transfer full): the properties of the stream
*/
WpProperties *
wp_si_stream_get_properties (WpSiStream * self)
{
g_return_val_if_fail (WP_IS_SI_STREAM (self), NULL);
g_return_val_if_fail (WP_SI_STREAM_GET_IFACE (self)->get_properties, NULL);
return WP_SI_STREAM_GET_IFACE (self)->get_properties (self);
}
/**
* wp_si_stream_get_parent_endpoint: (virtual get_parent_endpoint)
* @self: the session item
*
* Returns: (transfer none): the endpoint that this stream belongs to
*/
WpSiEndpoint *
wp_si_stream_get_parent_endpoint (WpSiStream * self)
{
g_return_val_if_fail (WP_IS_SI_STREAM (self), NULL);
g_return_val_if_fail (WP_SI_STREAM_GET_IFACE (self)->get_parent_endpoint, NULL);
return WP_SI_STREAM_GET_IFACE (self)->get_parent_endpoint (self);
}
/**
* WpSiLink:
*
* An interface for session items that provide a PipeWire endpoint link.
*/
G_DEFINE_INTERFACE (WpSiLink, wp_si_link, WP_TYPE_SESSION_ITEM)
static void
wp_si_link_default_init (WpSiLinkInterface * iface)
{
}
/**
* wp_si_link_get_out_stream: (virtual get_out_stream)
* @self: the session item
*
* Returns: (transfer none): the output stream that is linked by this link
*/
WpSiStream *
wp_si_link_get_out_stream (WpSiLink * self)
{
g_return_val_if_fail (WP_IS_SI_LINK (self), NULL);
g_return_val_if_fail (WP_SI_LINK_GET_IFACE (self)->get_out_stream, NULL);
return WP_SI_LINK_GET_IFACE (self)->get_out_stream (self);
}
/**
* wp_si_link_get_in_stream: (virtual get_in_stream)
* @self: the session item
*
* Returns: (transfer none): the input stream that is linked by this link
*/
WpSiStream *
wp_si_link_get_in_stream (WpSiLink * self)
{
g_return_val_if_fail (WP_IS_SI_LINK (self), NULL);
g_return_val_if_fail (WP_SI_LINK_GET_IFACE (self)->get_in_stream, NULL);
return WP_SI_LINK_GET_IFACE (self)->get_in_stream (self);
}

146
lib/wp/si-interfaces.h Normal file
View file

@ -0,0 +1,146 @@
/* WirePlumber
*
* Copyright © 2020 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#ifndef __WIREPLUMBER_SI_INTERFACES_H__
#define __WIREPLUMBER_SI_INTERFACES_H__
#include "session-item.h"
#include "properties.h"
#include "endpoint.h"
G_BEGIN_DECLS
typedef struct _WpSiStream WpSiStream;
/**
* WP_TYPE_SI_ENDPOINT:
*
* The #WpSiEndpoint #GType
*/
#define WP_TYPE_SI_ENDPOINT (wp_si_endpoint_get_type ())
WP_API
G_DECLARE_INTERFACE (WpSiEndpoint, wp_si_endpoint,
WP, SI_ENDPOINT, WpSessionItem)
struct _WpSiEndpointInterface
{
GTypeInterface interface;
const gchar * (*get_name) (WpSiEndpoint * self);
const gchar * (*get_media_class) (WpSiEndpoint * self);
const gchar * (*get_role) (WpSiEndpoint * self);
WpDirection (*get_direction) (WpSiEndpoint * self);
guint (*get_priority) (WpSiEndpoint * self);
WpProperties * (*get_properties) (WpSiEndpoint * self);
guint (*get_n_streams) (WpSiEndpoint * self);
WpSiStream * (*get_stream) (WpSiEndpoint * self, guint index);
};
WP_API
const gchar * wp_si_endpoint_get_name (WpSiEndpoint * self);
WP_API
const gchar * wp_si_endpoint_get_media_class (WpSiEndpoint * self);
WP_API
WpDirection wp_si_endpoint_get_direction (WpSiEndpoint * self);
WP_API
guint wp_si_endpoint_get_priority (WpSiEndpoint * self);
WP_API
WpProperties * wp_si_endpoint_get_properties (WpSiEndpoint * self);
WP_API
guint wp_si_endpoint_get_n_streams (WpSiEndpoint * self);
WP_API
WpSiStream * wp_si_endpoint_get_stream (WpSiEndpoint * self, guint index);
/**
* WP_TYPE_SI_MULTI_ENDPOINT:
*
* The #WpSiMultiEndpoint #GType
*/
#define WP_TYPE_SI_MULTI_ENDPOINT (wp_si_multi_endpoint_get_type ())
WP_API
G_DECLARE_INTERFACE (WpSiMultiEndpoint, wp_si_multi_endpoint,
WP, SI_MULTI_ENDPOINT, WpSessionItem)
struct _WpSiMultiEndpointInterface
{
GTypeInterface interface;
guint (*get_n_endpoints) (WpSiMultiEndpoint * self);
WpSiEndpoint * (*get_endpoint) (WpSiMultiEndpoint * self, guint index);
};
WP_API
guint wp_si_multi_endpoint_get_n_endpoints (WpSiMultiEndpoint * self);
WP_API
WpSiEndpoint * wp_si_multi_endpoint_get_endpoint (WpSiMultiEndpoint * self,
guint index);
/**
* WP_TYPE_SI_STREAM:
*
* The #WpSiStream #GType
*/
#define WP_TYPE_SI_STREAM (wp_si_stream_get_type ())
WP_API
G_DECLARE_INTERFACE (WpSiStream, wp_si_stream,
WP, SI_STREAM, WpSessionItem)
struct _WpSiStreamInterface
{
GTypeInterface interface;
const gchar * (*get_name) (WpSiStream * self);
WpProperties * (*get_properties) (WpSiStream * self);
WpSiEndpoint * (*get_parent_endpoint) (WpSiStream * self);
};
WP_API
const gchar * wp_si_stream_get_name (WpSiStream * self);
WP_API
WpProperties * wp_si_stream_get_properties (WpSiStream * self);
WP_API
WpSiEndpoint * wp_si_stream_get_parent_endpoint (WpSiStream * self);
/**
* WP_TYPE_SI_LINK:
*
* The #WpSiLink #GType
*/
#define WP_TYPE_SI_LINK (wp_si_link_get_type ())
WP_API
G_DECLARE_INTERFACE (WpSiLink, wp_si_link,
WP, SI_LINK, WpSessionItem)
struct _WpSiLinkInterface
{
GTypeInterface interface;
WpSiStream * (*get_out_stream) (WpSiLink * self);
WpSiStream * (*get_in_stream) (WpSiLink * self);
};
WP_API
WpSiStream * wp_si_link_get_out_stream (WpSiLink * self);
WP_API
WpSiStream * wp_si_link_get_in_stream (WpSiLink * self);
G_END_DECLS
#endif

View file

@ -24,5 +24,6 @@
#include "proxy.h"
#include "session.h"
#include "session-item.h"
#include "si-interfaces.h"
#include "transition.h"
#include "wpenums.h"