mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-25 06:59:57 -05:00
Add mapper
Ger rid of static ids for interfaces and replace with something we can register dynamically Implement logger.
This commit is contained in:
parent
a68e5d5124
commit
fc4fd1424a
43 changed files with 997 additions and 360 deletions
|
|
@ -36,6 +36,10 @@
|
|||
#define PINOS_SPA_ALSA_MONITOR_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_SPA_ALSA_MONITOR, PinosSpaALSAMonitorPrivate))
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
struct _PinosSpaALSAMonitorPrivate
|
||||
{
|
||||
PinosDaemon *daemon;
|
||||
|
|
@ -43,6 +47,8 @@ struct _PinosSpaALSAMonitorPrivate
|
|||
SpaHandle *handle;
|
||||
SpaMonitor *monitor;
|
||||
|
||||
URI uri;
|
||||
|
||||
GSource *watch_source;
|
||||
|
||||
unsigned int n_poll;
|
||||
|
|
@ -61,7 +67,7 @@ enum
|
|||
G_DEFINE_TYPE (PinosSpaALSAMonitor, pinos_spa_alsa_monitor, G_TYPE_OBJECT);
|
||||
|
||||
static SpaResult
|
||||
make_handle (SpaHandle **handle, const char *lib, const char *name, const SpaDict *info)
|
||||
make_handle (PinosDaemon *daemon, SpaHandle **handle, const char *lib, const char *name, const SpaDict *info)
|
||||
{
|
||||
SpaResult res;
|
||||
void *hnd, *state = NULL;
|
||||
|
|
@ -88,7 +94,7 @@ make_handle (SpaHandle **handle, const char *lib, const char *name, const SpaDic
|
|||
continue;
|
||||
|
||||
*handle = g_malloc0 (factory->size);
|
||||
if ((res = spa_handle_factory_init (factory, *handle, info, NULL, 0)) < 0) {
|
||||
if ((res = spa_handle_factory_init (factory, *handle, info, daemon->support, daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -110,11 +116,15 @@ add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
|
|||
g_debug ("alsa-monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
||||
|
||||
handle = calloc (1, item->factory->size);
|
||||
if ((res = spa_handle_factory_init (item->factory, handle, item->info, NULL, 0)) < 0) {
|
||||
if ((res = spa_handle_factory_init (item->factory,
|
||||
handle,
|
||||
item->info,
|
||||
priv->daemon->support,
|
||||
priv->daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, SPA_INTERFACE_ID_NODE, &iface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (handle, priv->uri.node, &iface)) < 0) {
|
||||
g_error ("can't get MONITOR interface: %d", res);
|
||||
return;
|
||||
}
|
||||
|
|
@ -240,6 +250,8 @@ monitor_constructed (GObject * object)
|
|||
|
||||
G_OBJECT_CLASS (pinos_spa_alsa_monitor_parent_class)->constructed (object);
|
||||
|
||||
priv->uri.node = spa_id_map_get_id (priv->daemon->map, SPA_NODE_URI);
|
||||
|
||||
while (TRUE) {
|
||||
SpaMonitorItem *item;
|
||||
|
||||
|
|
@ -365,15 +377,18 @@ pinos_spa_alsa_monitor_new (PinosDaemon *daemon)
|
|||
SpaResult res;
|
||||
void *iface;
|
||||
|
||||
if ((res = make_handle (&handle,
|
||||
"build/spa/plugins/alsa/libspa-alsa.so",
|
||||
"alsa-monitor",
|
||||
NULL)) < 0) {
|
||||
if ((res = make_handle (daemon, &handle,
|
||||
"build/spa/plugins/alsa/libspa-alsa.so",
|
||||
"alsa-monitor",
|
||||
NULL)) < 0) {
|
||||
g_error ("can't create alsa-monitor: %d", res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface (handle, SPA_INTERFACE_ID_MONITOR, &iface)) < 0) {
|
||||
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_MONITOR_URI),
|
||||
&iface)) < 0) {
|
||||
g_free (handle);
|
||||
g_error ("can't get MONITOR interface: %d", res);
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ enum {
|
|||
G_DEFINE_TYPE (PinosSpaAudioTestSrc, pinos_spa_audiotestsrc, PINOS_TYPE_NODE);
|
||||
|
||||
static SpaResult
|
||||
make_node (SpaNode **node, const char *lib, const char *name)
|
||||
make_node (PinosDaemon *daemon, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaHandle *handle;
|
||||
SpaResult res;
|
||||
|
|
@ -69,11 +69,17 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
|||
continue;
|
||||
|
||||
handle = calloc (1, factory->size);
|
||||
if ((res = spa_handle_factory_init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||
if ((res = spa_handle_factory_init (factory,
|
||||
handle,
|
||||
NULL,
|
||||
daemon->support,
|
||||
daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, SPA_INTERFACE_ID_NODE, &iface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_NODE_URI),
|
||||
&iface)) < 0) {
|
||||
g_error ("can't get interface %d", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -177,7 +183,8 @@ pinos_spa_audiotestsrc_new (PinosDaemon *daemon,
|
|||
SpaNode *n;
|
||||
SpaResult res;
|
||||
|
||||
if ((res = make_node (&n,
|
||||
if ((res = make_node (daemon,
|
||||
&n,
|
||||
"build/spa/plugins/audiotestsrc/libspa-audiotestsrc.so",
|
||||
"audiotestsrc")) < 0) {
|
||||
g_error ("can't create audiotestsrc: %d", res);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@
|
|||
#define PINOS_SPA_V4L2_MONITOR_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_SPA_V4L2_MONITOR, PinosSpaV4l2MonitorPrivate))
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
struct _PinosSpaV4l2MonitorPrivate
|
||||
{
|
||||
PinosDaemon *daemon;
|
||||
|
|
@ -43,6 +47,8 @@ struct _PinosSpaV4l2MonitorPrivate
|
|||
SpaHandle *handle;
|
||||
SpaMonitor *monitor;
|
||||
|
||||
URI uri;
|
||||
|
||||
GSource *watch_source;
|
||||
|
||||
unsigned int n_poll;
|
||||
|
|
@ -61,7 +67,7 @@ enum
|
|||
G_DEFINE_TYPE (PinosSpaV4l2Monitor, pinos_spa_v4l2_monitor, G_TYPE_OBJECT);
|
||||
|
||||
static SpaResult
|
||||
make_handle (SpaHandle **handle, const char *lib, const char *name, const SpaDict *info)
|
||||
make_handle (PinosDaemon *daemon, SpaHandle **handle, const char *lib, const char *name, const SpaDict *info)
|
||||
{
|
||||
SpaResult res;
|
||||
void *hnd, *state = NULL;
|
||||
|
|
@ -88,7 +94,7 @@ make_handle (SpaHandle **handle, const char *lib, const char *name, const SpaDic
|
|||
continue;
|
||||
|
||||
*handle = g_malloc0 (factory->size);
|
||||
if ((res = spa_handle_factory_init (factory, *handle, info, NULL, 0)) < 0) {
|
||||
if ((res = spa_handle_factory_init (factory, *handle, info, daemon->support, daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -110,12 +116,16 @@ add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
|
|||
g_debug ("v4l2-monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
||||
|
||||
handle = calloc (1, item->factory->size);
|
||||
if ((res = spa_handle_factory_init (item->factory, handle, item->info, NULL, 0)) < 0) {
|
||||
if ((res = spa_handle_factory_init (item->factory,
|
||||
handle,
|
||||
item->info,
|
||||
priv->daemon->support,
|
||||
priv->daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, SPA_INTERFACE_ID_NODE, &iface)) < 0) {
|
||||
g_error ("can't get MONITOR interface: %d", res);
|
||||
if ((res = spa_handle_get_interface (handle, priv->uri.node, &iface)) < 0) {
|
||||
g_error ("can't get NODE interface: %d", res);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -240,6 +250,8 @@ monitor_constructed (GObject * object)
|
|||
|
||||
G_OBJECT_CLASS (pinos_spa_v4l2_monitor_parent_class)->constructed (object);
|
||||
|
||||
priv->uri.node = spa_id_map_get_id (priv->daemon->map, SPA_NODE_URI);
|
||||
|
||||
while (TRUE) {
|
||||
SpaMonitorItem *item;
|
||||
|
||||
|
|
@ -365,15 +377,18 @@ pinos_spa_v4l2_monitor_new (PinosDaemon *daemon)
|
|||
SpaResult res;
|
||||
void *iface;
|
||||
|
||||
if ((res = make_handle (&handle,
|
||||
"build/spa/plugins/v4l2/libspa-v4l2.so",
|
||||
"v4l2-monitor",
|
||||
NULL)) < 0) {
|
||||
if ((res = make_handle (daemon,
|
||||
&handle,
|
||||
"build/spa/plugins/v4l2/libspa-v4l2.so",
|
||||
"v4l2-monitor",
|
||||
NULL)) < 0) {
|
||||
g_error ("can't create v4l2-monitor: %d", res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface (handle, SPA_INTERFACE_ID_MONITOR, &iface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_MONITOR_URI),
|
||||
&iface)) < 0) {
|
||||
g_free (handle);
|
||||
g_error ("can't get MONITOR interface: %d", res);
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ enum {
|
|||
G_DEFINE_TYPE (PinosSpaVideoTestSrc, pinos_spa_videotestsrc, PINOS_TYPE_NODE);
|
||||
|
||||
static SpaResult
|
||||
make_node (SpaNode **node, const char *lib, const char *name)
|
||||
make_node (PinosDaemon *daemon, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaHandle *handle;
|
||||
SpaResult res;
|
||||
|
|
@ -68,11 +68,13 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
|||
continue;
|
||||
|
||||
handle = calloc (1, factory->size);
|
||||
if ((res = factory->init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||
if ((res = factory->init (factory, handle, NULL, daemon->support, daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
if ((res = handle->get_interface (handle, SPA_INTERFACE_ID_NODE, &iface)) < 0) {
|
||||
if ((res = handle->get_interface (handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_NODE_URI),
|
||||
&iface)) < 0) {
|
||||
g_error ("can't get interface %d", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -148,7 +150,8 @@ pinos_spa_videotestsrc_new (PinosDaemon *daemon,
|
|||
SpaNode *n;
|
||||
SpaResult res;
|
||||
|
||||
if ((res = make_node (&n,
|
||||
if ((res = make_node (daemon,
|
||||
&n,
|
||||
"build/spa/plugins/videotestsrc/libspa-videotestsrc.so",
|
||||
"videotestsrc")) < 0) {
|
||||
g_error ("can't create videotestsrc: %d", res);
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ pinos_client_node_init (PinosClientNode * node)
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
make_node (SpaNode **node, const char *lib, const char *name)
|
||||
make_node (PinosDaemon *daemon, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaHandle *handle;
|
||||
SpaResult res;
|
||||
|
|
@ -257,11 +257,17 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
|||
continue;
|
||||
|
||||
handle = calloc (1, factory->size);
|
||||
if ((res = factory->init (factory, handle, NULL, NULL, 0)) < 0) {
|
||||
if ((res = factory->init (factory,
|
||||
handle,
|
||||
NULL,
|
||||
daemon->support,
|
||||
daemon->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
if ((res = handle->get_interface (handle, SPA_INTERFACE_ID_NODE, &iface)) < 0) {
|
||||
if ((res = handle->get_interface (handle,
|
||||
spa_id_map_get_id (daemon->map, SPA_NODE_URI),
|
||||
&iface)) < 0) {
|
||||
g_error ("can't get interface %d", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -293,7 +299,8 @@ pinos_client_node_new (PinosDaemon *daemon,
|
|||
|
||||
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
|
||||
|
||||
if ((res = make_node (&n,
|
||||
if ((res = make_node (daemon,
|
||||
&n,
|
||||
"build/spa/plugins/remote/libspa-remote.so",
|
||||
"proxy")) < 0) {
|
||||
g_error ("can't create proxy: %d", res);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixfdlist.h>
|
||||
|
|
@ -55,6 +56,9 @@ struct _PinosDaemonPrivate
|
|||
PinosProperties *properties;
|
||||
|
||||
GHashTable *node_factories;
|
||||
|
||||
SpaSupport support[2];
|
||||
SpaLog log;
|
||||
};
|
||||
|
||||
enum
|
||||
|
|
@ -65,6 +69,7 @@ enum
|
|||
PROP_OBJECT_PATH,
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
handle_client_appeared (PinosClient *client, gpointer user_data)
|
||||
{
|
||||
|
|
@ -825,6 +830,43 @@ pinos_daemon_class_init (PinosDaemonClass * klass)
|
|||
|
||||
}
|
||||
|
||||
static void
|
||||
do_logv (SpaLog *log,
|
||||
SpaLogLevel level,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt,
|
||||
va_list args)
|
||||
|
||||
{
|
||||
char text[16*1024], location[128];
|
||||
static const char *levels[] = {
|
||||
"NONE",
|
||||
"ERROR",
|
||||
"WARN",
|
||||
"INFO",
|
||||
"TRACE",
|
||||
};
|
||||
vsnprintf (text, sizeof(text), fmt, args);
|
||||
snprintf (location, sizeof(location), "%s:%i %s()", file, line, func);
|
||||
fprintf(stderr, "[%s][%s] %s", levels[level], location, text);
|
||||
}
|
||||
|
||||
static void
|
||||
do_log (SpaLog *log,
|
||||
SpaLogLevel level,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, fmt);
|
||||
do_logv (log, level, file, line, func, fmt, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_daemon_init (PinosDaemon * daemon)
|
||||
{
|
||||
|
|
@ -842,6 +884,23 @@ pinos_daemon_init (PinosDaemon * daemon)
|
|||
g_free,
|
||||
g_object_unref);
|
||||
priv->loop = pinos_rtloop_new();
|
||||
|
||||
priv->log.handle = NULL;
|
||||
priv->log.size = sizeof (SpaLog);
|
||||
priv->log.info = NULL;
|
||||
priv->log.level = SPA_LOG_LEVEL_INFO;
|
||||
priv->log.log = do_log;
|
||||
priv->log.logv = do_logv;
|
||||
|
||||
daemon->map = spa_id_map_get_default();
|
||||
daemon->log = &priv->log;
|
||||
|
||||
priv->support[0].uri = SPA_ID_MAP_URI;
|
||||
priv->support[0].data = daemon->map;
|
||||
priv->support[1].uri = SPA_LOG_URI;
|
||||
priv->support[1].data = daemon->log;
|
||||
daemon->support = priv->support;
|
||||
daemon->n_support = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ typedef struct _PinosDaemon PinosDaemon;
|
|||
typedef struct _PinosDaemonClass PinosDaemonClass;
|
||||
typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
|
||||
|
||||
#include <spa/include/spa/plugin.h>
|
||||
#include <spa/include/spa/log.h>
|
||||
#include <spa/include/spa/id-map.h>
|
||||
#include <pinos/server/node.h>
|
||||
#include <pinos/server/node-factory.h>
|
||||
#include <pinos/client/properties.h>
|
||||
|
|
@ -49,6 +52,12 @@ typedef struct _PinosDaemonPrivate PinosDaemonPrivate;
|
|||
struct _PinosDaemon {
|
||||
GObject object;
|
||||
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaSupport *support;
|
||||
unsigned int n_support;
|
||||
|
||||
PinosDaemonPrivate *priv;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -658,7 +658,9 @@ pinos_node_set_property (GObject *_object,
|
|||
{
|
||||
void *iface;
|
||||
this->node = g_value_get_pointer (value);
|
||||
if (this->node->handle->get_interface (this->node->handle, SPA_INTERFACE_ID_CLOCK, &iface) >= 0)
|
||||
if (this->node->handle->get_interface (this->node->handle,
|
||||
spa_id_map_get_id (priv->daemon->map, SPA_CLOCK_URI),
|
||||
&iface) >= 0)
|
||||
this->clock = iface;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue