mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-09 07:28:41 +02:00
lib: implement a wp_init() function
This commit is contained in:
parent
2e781ce607
commit
66a0bf6093
23 changed files with 125 additions and 69 deletions
|
|
@ -280,9 +280,6 @@ wp_core_class_init (WpCoreClass * klass)
|
|||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
|
||||
pw_init (NULL, NULL);
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
object_class->constructed = wp_core_constructed;
|
||||
object_class->dispose = wp_core_dispose;
|
||||
object_class->finalize = wp_core_finalize;
|
||||
|
|
@ -326,17 +323,6 @@ wp_core_class_init (WpCoreClass * klass)
|
|||
signals[SIGNAL_DISCONNECTED] = g_signal_new ("disconnected",
|
||||
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
/* ensure WpProxy subclasses are loaded, which is needed to be able
|
||||
to autodetect the GType of proxies created through wp_proxy_new_global() */
|
||||
g_type_ensure (WP_TYPE_CLIENT);
|
||||
g_type_ensure (WP_TYPE_DEVICE);
|
||||
g_type_ensure (WP_TYPE_ENDPOINT);
|
||||
g_type_ensure (WP_TYPE_ENDPOINT_STREAM);
|
||||
g_type_ensure (WP_TYPE_LINK);
|
||||
g_type_ensure (WP_TYPE_NODE);
|
||||
g_type_ensure (WP_TYPE_PORT);
|
||||
g_type_ensure (WP_TYPE_SESSION);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -401,8 +401,8 @@ static struct spa_log wp_spa_log = {
|
|||
.level = SPA_LOG_LEVEL_INFO,
|
||||
};
|
||||
|
||||
void
|
||||
wp_install_glib_pw_log (void)
|
||||
struct spa_log *
|
||||
wp_spa_log_get_instance (void)
|
||||
{
|
||||
pw_log_set (&wp_spa_log);
|
||||
return &wp_spa_log;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,8 +79,10 @@ void wp_log_structured_standard (const gchar *log_domain,
|
|||
#define wp_trace_boxed(type, object, ...) \
|
||||
wp_log (WP_LOG_LEVEL_TRACE, type, object, __VA_ARGS__)
|
||||
|
||||
struct spa_log;
|
||||
|
||||
WP_API
|
||||
void wp_install_glib_pw_log (void);
|
||||
struct spa_log * wp_spa_log_get_instance (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ wp_lib_sources = files(
|
|||
'spa-props.c',
|
||||
'spa-type.c',
|
||||
'transition.c',
|
||||
'wp.c',
|
||||
)
|
||||
|
||||
wp_lib_headers = files(
|
||||
|
|
|
|||
|
|
@ -344,17 +344,6 @@ wp_session_class_init (WpSessionClass * klass)
|
|||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
||||
|
||||
/* Register custom wireplumber session types */
|
||||
wp_spa_type_register (WP_SPA_TYPE_TABLE_PROPS,
|
||||
"Wp:Session:Default:Endpoint:Audio:Source",
|
||||
"wp-session-default-endpoint-audio-source");
|
||||
wp_spa_type_register (WP_SPA_TYPE_TABLE_PROPS,
|
||||
"Wp:Session:Default:Endpoint:Audio:Sink",
|
||||
"wp-session-default-endpoint-audio-sink");
|
||||
wp_spa_type_register (WP_SPA_TYPE_TABLE_PROPS,
|
||||
"Wp:Session:Default:Endpoint:Video:Source",
|
||||
"wp-session-default-endpoint-video-source");
|
||||
|
||||
object_class->finalize = wp_session_finalize;
|
||||
|
||||
proxy_class->pw_iface_type = PW_TYPE_INTERFACE_Session;
|
||||
|
|
|
|||
83
lib/wp/wp.c
Normal file
83
lib/wp/wp.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2020 Collabora Ltd.
|
||||
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "wp.h"
|
||||
#include <pipewire/pipewire.h>
|
||||
|
||||
/**
|
||||
* SECTION: wp
|
||||
* @title: Library Initialization
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* WpInitFlags:
|
||||
* @WP_INIT_PIPEWIRE: Initializes libpipewire by calling `pw_init()`
|
||||
* @WP_INIT_SPA_TYPES: Initializes WirePlumber's SPA types integration,
|
||||
* required for using #WpSpaPod among other things
|
||||
* @WP_INIT_SET_PW_LOG: Enables redirecting debug log messages from
|
||||
* libpipewire to GLib's logging system, by installing WirePlumber's
|
||||
* implementation of `struct spa_log` (see wp_spa_log_get_instance())
|
||||
* with `pw_log_set()`
|
||||
* @WP_INIT_SET_GLIB_LOG: Installs WirePlumber's debug log handler,
|
||||
* wp_log_writer_default(), on GLib with g_log_set_writer_func()
|
||||
* @WP_INIT_ALL: Enables all of the above
|
||||
*
|
||||
* See wp_init()
|
||||
*/
|
||||
|
||||
/**
|
||||
* wp_init:
|
||||
* @flags: initialization flags
|
||||
*
|
||||
* Initializes WirePlumber and PipeWire underneath. @flags can modify
|
||||
* which parts are initialized, in cases where you want to handle part
|
||||
* of this initialization externally.
|
||||
*/
|
||||
void
|
||||
wp_init (WpInitFlags flags)
|
||||
{
|
||||
if (flags & WP_INIT_SET_PW_LOG)
|
||||
pw_log_set (wp_spa_log_get_instance ());
|
||||
|
||||
if (flags & WP_INIT_SET_GLIB_LOG)
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
|
||||
/* a dummy message, to initialize the logging system */
|
||||
wp_message ("WirePlumber initializing");
|
||||
|
||||
if (flags & WP_INIT_PIPEWIRE)
|
||||
pw_init (NULL, NULL);
|
||||
|
||||
if (flags & WP_INIT_SPA_TYPES) {
|
||||
wp_spa_type_init (TRUE);
|
||||
|
||||
/* Register custom wireplumber session types */
|
||||
wp_spa_type_register (WP_SPA_TYPE_TABLE_PROPS,
|
||||
"Wp:Session:Default:Endpoint:Audio:Source",
|
||||
"wp-session-default-endpoint-audio-source");
|
||||
wp_spa_type_register (WP_SPA_TYPE_TABLE_PROPS,
|
||||
"Wp:Session:Default:Endpoint:Audio:Sink",
|
||||
"wp-session-default-endpoint-audio-sink");
|
||||
wp_spa_type_register (WP_SPA_TYPE_TABLE_PROPS,
|
||||
"Wp:Session:Default:Endpoint:Video:Source",
|
||||
"wp-session-default-endpoint-video-source");
|
||||
}
|
||||
|
||||
/* ensure WpProxy subclasses are loaded, which is needed to be able
|
||||
to autodetect the GType of proxies created through wp_proxy_new_global() */
|
||||
g_type_ensure (WP_TYPE_CLIENT);
|
||||
g_type_ensure (WP_TYPE_DEVICE);
|
||||
g_type_ensure (WP_TYPE_ENDPOINT);
|
||||
g_type_ensure (WP_TYPE_ENDPOINT_LINK);
|
||||
g_type_ensure (WP_TYPE_ENDPOINT_STREAM);
|
||||
g_type_ensure (WP_TYPE_LINK);
|
||||
g_type_ensure (WP_TYPE_NODE);
|
||||
g_type_ensure (WP_TYPE_PORT);
|
||||
g_type_ensure (WP_TYPE_SESSION);
|
||||
}
|
||||
20
lib/wp/wp.h
20
lib/wp/wp.h
|
|
@ -6,6 +6,9 @@
|
|||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef __WIREPLUMBER_WP_H__
|
||||
#define __WIREPLUMBER_WP_H__
|
||||
|
||||
#include "base-endpoint.h"
|
||||
#include "client.h"
|
||||
#include "configuration.h"
|
||||
|
|
@ -36,3 +39,20 @@
|
|||
#include "spa-type.h"
|
||||
#include "transition.h"
|
||||
#include "wpenums.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
WP_INIT_PIPEWIRE = (1<<0),
|
||||
WP_INIT_SPA_TYPES = (1<<1),
|
||||
WP_INIT_SET_PW_LOG = (1<<2),
|
||||
WP_INIT_SET_GLIB_LOG = (1<<3),
|
||||
WP_INIT_ALL = 0xf,
|
||||
} WpInitFlags;
|
||||
|
||||
WP_API
|
||||
void wp_init (WpInitFlags flags);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ main (gint argc, gchar **argv)
|
|||
g_autoptr (GPtrArray) sessions = NULL;
|
||||
const gchar *configuration_path;
|
||||
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
context = g_option_context_new ("- PipeWire Session/Policy Manager");
|
||||
g_option_context_add_main_entries (context, entries, NULL);
|
||||
|
|
|
|||
|
|
@ -58,9 +58,6 @@ wp_base_test_fixture_setup (WpBaseTestFixture * self, WpBaseTestFlags flags)
|
|||
{
|
||||
g_autoptr (WpProperties) props = NULL;
|
||||
|
||||
/* ensure types are loaded */
|
||||
g_type_ensure (WP_TYPE_CORE);
|
||||
|
||||
/* init test server */
|
||||
wp_test_server_setup (&self->server);
|
||||
|
||||
|
|
|
|||
|
|
@ -418,8 +418,7 @@ main (gint argc, gchar *argv[])
|
|||
g_auto (AppData) data = {0};
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
if (argc > 1)
|
||||
data.alsa_device = argv[1];
|
||||
|
|
|
|||
|
|
@ -197,8 +197,7 @@ int
|
|||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/modules/config-endpoint/simple", TestConfigEndpointFixture,
|
||||
NULL, config_endpoint_setup, simple, config_endpoint_teardown);
|
||||
|
|
|
|||
|
|
@ -379,8 +379,7 @@ int
|
|||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/modules/config-policy/playback", TestConfigPolicyFixture,
|
||||
NULL, config_policy_setup, playback, config_policy_teardown);
|
||||
|
|
|
|||
|
|
@ -74,8 +74,7 @@ int
|
|||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/modules/config-static-nodes/basic",
|
||||
TestConfigStaticNodesFixture, NULL,
|
||||
|
|
|
|||
|
|
@ -193,8 +193,7 @@ gint
|
|||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/wp/dbus/basic", TestDbusFixture, NULL,
|
||||
test_dbus_setup, test_dbus_basic, test_dbus_teardown);
|
||||
|
|
|
|||
|
|
@ -352,8 +352,7 @@ gint
|
|||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
/* configure-activate */
|
||||
|
||||
|
|
|
|||
|
|
@ -370,8 +370,7 @@ gint
|
|||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
/* data */
|
||||
|
||||
|
|
|
|||
|
|
@ -426,8 +426,7 @@ gint
|
|||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/modules/si-standard-link/main",
|
||||
TestFixture, NULL,
|
||||
|
|
|
|||
|
|
@ -490,8 +490,7 @@ gint
|
|||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/wp/endpoint/basic", TestEndpointFixture, NULL,
|
||||
test_endpoint_setup, test_endpoint_basic, test_endpoint_teardown);
|
||||
|
|
|
|||
|
|
@ -196,8 +196,7 @@ gint
|
|||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/wp/proxy/basic", TestProxyFixture, NULL,
|
||||
test_proxy_setup, test_proxy_basic, test_proxy_teardown);
|
||||
|
|
|
|||
|
|
@ -510,7 +510,7 @@ gint
|
|||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add_func ("/wp/session-item/flags", test_flags);
|
||||
g_test_add_func ("/wp/session-item/configuration", test_configuration);
|
||||
|
|
|
|||
|
|
@ -311,8 +311,7 @@ gint
|
|||
main (gint argc, gchar *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
g_test_add ("/wp/session/basic", TestSessionFixture, NULL,
|
||||
test_session_setup, test_session_basic, test_session_teardown);
|
||||
|
|
|
|||
|
|
@ -257,6 +257,7 @@ int
|
|||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
|
||||
g_test_add_func ("/wp/spa_props/set_get", test_spa_props_set_get);
|
||||
g_test_add_func ("/wp/spa_props/build_all", test_spa_props_build_all);
|
||||
|
|
|
|||
|
|
@ -275,19 +275,7 @@ main (gint argc, gchar **argv)
|
|||
g_autoptr (WpObjectManager) om = NULL;
|
||||
g_autoptr (GMainLoop) loop = NULL;
|
||||
|
||||
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
||||
|
||||
/* Register custom wireplumber session types */
|
||||
wp_spa_type_init (TRUE);
|
||||
wp_spa_type_register (WP_SPA_TYPE_TABLE_BASIC,
|
||||
"Wp:Session:Default:Endpoint:Audio:Source",
|
||||
"wp-session-default-endpoint-audio-source");
|
||||
wp_spa_type_register (WP_SPA_TYPE_TABLE_BASIC,
|
||||
"Wp:Session:Default:Endpoint:Audio:Sink",
|
||||
"wp-session-default-endpoint-audio-sink");
|
||||
wp_spa_type_register (WP_SPA_TYPE_TABLE_BASIC,
|
||||
"Wp:Session:Default:Endpoint:Video:Source",
|
||||
"wp-session-default-endpoint-video-source");
|
||||
wp_init (WP_INIT_ALL);
|
||||
|
||||
context = g_option_context_new ("- PipeWire Session/Policy Manager Helper CLI");
|
||||
g_option_context_add_main_entries (context, entries, NULL);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue