mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaBuffer SpaBuffer;
|
||||
|
||||
#define SPA_BUFFER_URI "http://spaplug.in/ns/buffer"
|
||||
#define SPA_BUFFER_PREFIX SPA_BUFFER_URI "#"
|
||||
|
||||
/**
|
||||
* SpaMetaType:
|
||||
* @SPA_META_TYPE_INVALID: invalid metadata, should be ignored
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaClock SpaClock;
|
||||
|
||||
#define SPA_CLOCK_URI "http://spaplug.in/ns/clock"
|
||||
#define SPA_CLOCK_PREFIX SPA_CLOCK_URI "#"
|
||||
|
||||
/**
|
||||
* SpaClockState:
|
||||
* @SPA_CLOCK_STATE_STOPPED: the clock is stopped
|
||||
|
|
@ -42,10 +45,6 @@ typedef enum {
|
|||
#include <spa/plugin.h>
|
||||
#include <spa/props.h>
|
||||
|
||||
#define SPA_INTERFACE_ID_CLOCK 1
|
||||
#define SPA_INTERFACE_ID_CLOCK_NAME "Clock interface"
|
||||
#define SPA_INTERFACE_ID_CLOCK_DESCRIPTION "Clock interface"
|
||||
|
||||
/**
|
||||
* SpaClock:
|
||||
*
|
||||
|
|
|
|||
68
spa/include/spa/id-map.h
Normal file
68
spa/include/spa/id-map.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_ID_MAP_H__
|
||||
#define __SPA_ID_MAP_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _SpaIDMap SpaIDMap;
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/plugin.h>
|
||||
|
||||
#define SPA_ID_MAP_URI "http://spaplug.in/ns/id-map"
|
||||
|
||||
/**
|
||||
* SpaIDMap:
|
||||
*
|
||||
* Maps between uri and its id
|
||||
*/
|
||||
struct _SpaIDMap {
|
||||
/* pointer to the handle owning this interface */
|
||||
SpaHandle *handle;
|
||||
/* the total size of this structure. This can be used to expand this
|
||||
* structure in the future */
|
||||
size_t size;
|
||||
/**
|
||||
* SpaIDMap::info
|
||||
*
|
||||
* Extra information about the map
|
||||
*/
|
||||
const SpaDict *info;
|
||||
|
||||
uint32_t (*get_id) (SpaIDMap *map,
|
||||
const char *uri);
|
||||
|
||||
const char * (*get_uri) (SpaIDMap *map,
|
||||
uint32_t id);
|
||||
};
|
||||
|
||||
#define spa_id_map_get_id(n,...) (n)->get_id((n),__VA_ARGS__)
|
||||
#define spa_id_map_get_uri(n,...) (n)->get_uri((n),__VA_ARGS__)
|
||||
|
||||
SpaIDMap * spa_id_map_get_default (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_ID_MAP_H__ */
|
||||
|
|
@ -26,16 +26,14 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaLog SpaLog;
|
||||
|
||||
#define SPA_LOG_URI "http://spaplug.in/ns/log"
|
||||
#define SPA_LOG_PREFIX SPA_LOG_URI "#"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/plugin.h>
|
||||
|
||||
#define SPA_SUPPORT_ID_LOG 3
|
||||
#define SPA_INTERFACE_ID_LOG 3
|
||||
#define SPA_INTERFACE_ID_LOG_NAME "Log interface"
|
||||
#define SPA_INTERFACE_ID_LOG_DESCRIPTION "Log interface"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SPA_LOG_LEVEL_NONE = 0,
|
||||
|
|
@ -114,7 +112,7 @@ struct _SpaLog {
|
|||
#if __STDC_VERSION__ >= 199901L
|
||||
|
||||
#define spa_log_log(l,lev,...) \
|
||||
if ((l) && (l)->level > lev) \
|
||||
if ((l) && (l)->level >= lev) \
|
||||
(l)->log((l),lev,__VA_ARGS__)
|
||||
|
||||
#define spa_log_error(l,...) spa_log_log(l,SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__)
|
||||
|
|
@ -128,7 +126,7 @@ struct _SpaLog {
|
|||
#define SPA_LOG_FUNC(name,lev) \
|
||||
static inline void spa_log_##name (SpaLog *l, const char *format, ...) \
|
||||
{ \
|
||||
if ((l) && (l)->level > lev) { \
|
||||
if ((l) && (l)->level >= lev) { \
|
||||
va_list varargs; \
|
||||
va_start (varargs, format); \
|
||||
(l)->logv((l),lev,__FILE__,__LINE__,__func__,format,varargs); \
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaMonitor SpaMonitor;
|
||||
|
||||
#define SPA_MONITOR_URI "http://spaplug.in/ns/monitor"
|
||||
#define SPA_MONITOR_PREFIX SPA_MONITOR_URI "#"
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/dict.h>
|
||||
#include <spa/plugin.h>
|
||||
|
|
@ -95,10 +98,6 @@ typedef void (*SpaMonitorEventCallback) (SpaMonitor *monitor,
|
|||
SpaMonitorEvent *event,
|
||||
void *user_data);
|
||||
|
||||
#define SPA_INTERFACE_ID_MONITOR 2
|
||||
#define SPA_INTERFACE_ID_MONITOR_NAME "Monitor interface"
|
||||
#define SPA_INTERFACE_ID_MONITOR_DESCRIPTION "Device Monitor interface"
|
||||
|
||||
/**
|
||||
* SpaMonitor:
|
||||
*
|
||||
|
|
|
|||
|
|
@ -29,6 +29,16 @@ typedef struct _SpaNodeCommand SpaNodeCommand;
|
|||
#include <spa/defs.h>
|
||||
#include <spa/clock.h>
|
||||
|
||||
#define SPA_NODE_COMMAND_URI "http://spaplug.in/ns/node-command"
|
||||
#define SPA_NODE_COMMAND_PREFIX SPA_NODE_COMMAND_URI "#"
|
||||
|
||||
#define SPA_NODE_COMMAND__Pause SPA_NODE_COMMAND_PREFIX "Pause"
|
||||
#define SPA_NODE_COMMAND__Start SPA_NODE_COMMAND_PREFIX "Start"
|
||||
#define SPA_NODE_COMMAND__Flush SPA_NODE_COMMAND_PREFIX "Flush"
|
||||
#define SPA_NODE_COMMAND__Drain SPA_NODE_COMMAND_PREFIX "Drain"
|
||||
#define SPA_NODE_COMMAND__Marker SPA_NODE_COMMAND_PREFIX "Marker"
|
||||
#define SPA_NODE_COMMAND__ClockUpdate SPA_NODE_COMMAND_PREFIX "ClockUpdate"
|
||||
|
||||
typedef enum {
|
||||
SPA_NODE_COMMAND_INVALID = 0,
|
||||
SPA_NODE_COMMAND_PAUSE,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,22 @@ typedef struct _SpaNodeEvent SpaNodeEvent;
|
|||
#include <spa/poll.h>
|
||||
#include <spa/node.h>
|
||||
|
||||
#define SPA_NODE_EVENT_URI "http://spaplug.in/ns/node-event"
|
||||
#define SPA_NODE_EVENT_PREFIX SPA_NODE_EVENT_URI "#"
|
||||
|
||||
#define SPA_NODE_EVENT__AsyncComplete SPA_NODE_EVENT_PREFIX "AsyncComplete"
|
||||
#define SPA_NODE_EVENT__HaveOutput SPA_NODE_EVENT_PREFIX "HaveOutput"
|
||||
#define SPA_NODE_EVENT__NeedInput SPA_NODE_EVENT_PREFIX "NeedInput"
|
||||
#define SPA_NODE_EVENT__ReuseBuffer SPA_NODE_EVENT_PREFIX "ReuseBuffer"
|
||||
#define SPA_NODE_EVENT__AddPoll SPA_NODE_EVENT_PREFIX "AddPoll"
|
||||
#define SPA_NODE_EVENT__UpdatePoll SPA_NODE_EVENT_PREFIX "UpdatePoll"
|
||||
#define SPA_NODE_EVENT__RemovePoll SPA_NODE_EVENT_PREFIX "RemovePoll"
|
||||
#define SPA_NODE_EVENT__Drained SPA_NODE_EVENT_PREFIX "Drained"
|
||||
#define SPA_NODE_EVENT__Marker SPA_NODE_EVENT_PREFIX "Marker"
|
||||
#define SPA_NODE_EVENT__Error SPA_NODE_EVENT_PREFIX "Error"
|
||||
#define SPA_NODE_EVENT__Buffering SPA_NODE_EVENT_PREFIX "Buffering"
|
||||
#define SPA_NODE_EVENT__RequestClockUpdate SPA_NODE_EVENT_PREFIX "RequestClockUpdate"
|
||||
|
||||
/**
|
||||
* SpaEventType:
|
||||
* @SPA_NODE_EVENT_TYPE_INVALID: invalid event, should be ignored
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaNode SpaNode;
|
||||
|
||||
#define SPA_NODE_URI "http://spaplug.in/ns/node"
|
||||
#define SPA_NODE_PREFIX SPA_NODE_URI "#"
|
||||
|
||||
/**
|
||||
* SpaNodeState:
|
||||
* @SPA_NODE_STATE_INIT: the node is initializing
|
||||
|
|
@ -139,10 +142,6 @@ typedef void (*SpaNodeEventCallback) (SpaNode *node,
|
|||
SpaNodeEvent *event,
|
||||
void *user_data);
|
||||
|
||||
#define SPA_INTERFACE_ID_NODE 0
|
||||
#define SPA_INTERFACE_ID_NODE_NAME "Node interface"
|
||||
#define SPA_INTERFACE_ID_NODE_DESCRIPTION "Main processing node interface"
|
||||
|
||||
/**
|
||||
* SpaNode:
|
||||
*
|
||||
|
|
|
|||
|
|
@ -65,30 +65,26 @@ struct _SpaHandle {
|
|||
|
||||
/**
|
||||
* SpaInterfaceInfo:
|
||||
* @interface_id: the id of the interface, can be used to get the interface
|
||||
* @name: name of the interface
|
||||
* @description: Human readable description of the interface.
|
||||
* @uri: the uri of the interface, can be used to get the interface
|
||||
*
|
||||
* This structure lists the information about available interfaces on
|
||||
* handles.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t interface_id;
|
||||
const char *name;
|
||||
const char *description;
|
||||
const char *uri;
|
||||
} SpaInterfaceInfo;
|
||||
|
||||
/**
|
||||
* SpaSupport:
|
||||
* @support_id: the id of the support item
|
||||
* @uri: the uri of the support item
|
||||
* @data: specific data for the item
|
||||
*
|
||||
* Extra supporting infrastructure passed to the init() function of
|
||||
* a factory. It can be extra information or interfaces such as logging.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t support_id;
|
||||
void *data;
|
||||
const char *uri;
|
||||
void *data;
|
||||
} SpaSupport;
|
||||
|
||||
struct _SpaHandleFactory {
|
||||
|
|
@ -133,7 +129,7 @@ struct _SpaHandleFactory {
|
|||
SpaResult (*init) (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -29,6 +29,13 @@ typedef struct _SpaAllocParam SpaAllocParam;
|
|||
#include <spa/defs.h>
|
||||
#include <spa/buffer.h>
|
||||
|
||||
#define SPA_ALLOC_PARAM_URI "http://spaplug.in/ns/alloc-param"
|
||||
#define SPA_ALLOC_PARAM_PREFIX SPA_ALLOC_PARAM_URI "#"
|
||||
|
||||
#define SPA_ALLOC_PARAM__Buffers SPA_ALLOC_PARAM_PREFIX "Buffers"
|
||||
#define SPA_ALLOC_PARAM__MetaEnable SPA_ALLOC_PARAM_PREFIX "MetaEnable"
|
||||
#define SPA_ALLOC_PARAM__VideoPadding SPA_ALLOC_PARAM_PREFIX "VideoPadding"
|
||||
|
||||
/**
|
||||
* SpaAllocParamType:
|
||||
* @SPA_ALLOC_PARAM_TYPE_INVALID: invalid type, should be ignored
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaProps SpaProps;
|
||||
|
||||
#define SPA_PROPS_URI "http://spaplug.in/ns/props"
|
||||
#define SPA_PROPS_PREFIX SPA_PROPS_URI "#"
|
||||
|
||||
#include <string.h>
|
||||
#include <spa/defs.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaQueue SpaQueue;
|
||||
|
||||
#define SPA_QUEUE_URI "http://spaplug.in/ns/queue"
|
||||
#define SPA_QUEUE_PREFIX SPA_QUEUE_URI "#"
|
||||
|
||||
#include <spa/defs.h>
|
||||
|
||||
struct _SpaQueue {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaRingbuffer SpaRingbuffer;
|
||||
|
||||
#define SPA_RINGBUFFER_URI "http://spaplug.in/ns/ringbuffer"
|
||||
#define SPA_RINGBUFFER_PREFIX SPA_RINGBUFFER_URI "#"
|
||||
|
||||
#include <spa/defs.h>
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
89
spa/lib/mapper.c
Normal file
89
spa/lib/mapper.c
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/buffer.h>
|
||||
#include <spa/clock.h>
|
||||
#include <spa/format.h>
|
||||
#include <spa/monitor.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/node-command.h>
|
||||
#include <spa/node-event.h>
|
||||
#include <spa/port.h>
|
||||
#include <spa/props.h>
|
||||
#include <spa/queue.h>
|
||||
#include <spa/ringbuffer.h>
|
||||
#include <spa/debug.h>
|
||||
|
||||
static const char *uris[] = {
|
||||
NULL,
|
||||
SPA_ID_MAP_URI,
|
||||
SPA_LOG_URI,
|
||||
SPA_BUFFER_URI,
|
||||
SPA_CLOCK_URI,
|
||||
SPA_MONITOR_URI,
|
||||
SPA_NODE_URI,
|
||||
SPA_NODE_COMMAND_URI,
|
||||
SPA_NODE_EVENT_URI,
|
||||
SPA_ALLOC_PARAM_URI,
|
||||
SPA_PROPS_URI,
|
||||
SPA_QUEUE_URI,
|
||||
SPA_RINGBUFFER_URI,
|
||||
};
|
||||
|
||||
static uint32_t
|
||||
id_map_get_id (SpaIDMap *map, const char *uri)
|
||||
{
|
||||
if (uri != NULL) {
|
||||
unsigned int i;
|
||||
for (i = 1; i < SPA_N_ELEMENTS (uris); i++) {
|
||||
if (strcmp (uris[i], uri) == 0)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
id_map_get_uri (SpaIDMap *map, uint32_t id)
|
||||
{
|
||||
if (id < SPA_N_ELEMENTS (uris))
|
||||
return uris[id];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const SpaIDMap default_map = {
|
||||
NULL,
|
||||
sizeof (SpaIDMap),
|
||||
NULL,
|
||||
id_map_get_id,
|
||||
id_map_get_uri,
|
||||
};
|
||||
|
||||
SpaIDMap *
|
||||
spa_id_map_get_default (void)
|
||||
{
|
||||
return (SpaIDMap *) &default_map;
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ spalib_sources = ['audio-raw.c',
|
|||
'control.c',
|
||||
'debug.c',
|
||||
'format.c',
|
||||
'mapper.c',
|
||||
'port.c',
|
||||
'props.c',
|
||||
'ringbuffer.c',
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include <libudev.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/poll.h>
|
||||
#include <spa/monitor.h>
|
||||
#include <spa/debug.h>
|
||||
|
|
@ -41,10 +43,18 @@ typedef struct {
|
|||
SpaDictItem info_items[32];
|
||||
} ALSAItem;
|
||||
|
||||
typedef struct {
|
||||
uint32_t monitor;
|
||||
} URI;
|
||||
|
||||
struct _SpaALSAMonitor {
|
||||
SpaHandle handle;
|
||||
SpaMonitor monitor;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaMonitorEventCallback event_cb;
|
||||
void *user_data;
|
||||
|
||||
|
|
@ -360,13 +370,11 @@ spa_alsa_monitor_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaALSAMonitor *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_MONITOR:
|
||||
*interface = &this->monitor;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.monitor)
|
||||
*interface = &this->monitor;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -380,10 +388,11 @@ static SpaResult
|
|||
alsa_monitor_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaALSAMonitor *this;
|
||||
unsigned int i;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -392,6 +401,19 @@ alsa_monitor_init (const SpaHandleFactory *factory,
|
|||
handle->clear = alsa_monitor_clear,
|
||||
|
||||
this = (SpaALSAMonitor *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.monitor = spa_id_map_get_id (this->map, SPA_MONITOR_URI);
|
||||
|
||||
this->monitor = alsamonitor;
|
||||
this->monitor.handle = handle;
|
||||
|
||||
|
|
@ -400,10 +422,7 @@ alsa_monitor_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo alsa_monitor_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_MONITOR,
|
||||
SPA_INTERFACE_ID_MONITOR_NAME,
|
||||
SPA_INTERFACE_ID_MONITOR_DESCRIPTION,
|
||||
},
|
||||
{ SPA_MONITOR_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -579,13 +579,11 @@ spa_alsa_sink_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaALSASink *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -599,10 +597,11 @@ static SpaResult
|
|||
alsa_sink_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaALSASink *this;
|
||||
unsigned int i;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -611,6 +610,19 @@ alsa_sink_init (const SpaHandleFactory *factory,
|
|||
handle->clear = alsa_sink_clear;
|
||||
|
||||
this = (SpaALSASink *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
|
||||
this->node = alsasink_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
|
|
@ -627,10 +639,7 @@ alsa_sink_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo alsa_sink_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
{ SPA_NODE_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -485,7 +485,7 @@ spa_alsa_source_node_port_use_buffers (SpaNode *node,
|
|||
case SPA_DATA_TYPE_DMABUF:
|
||||
case SPA_DATA_TYPE_MEMPTR:
|
||||
if (buffers[i]->datas[0].data == NULL) {
|
||||
fprintf (stderr, "alsa-source: need mapped memory\n");
|
||||
spa_log_error (this->log, "alsa-source: need mapped memory\n");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
|
@ -729,16 +729,13 @@ spa_alsa_source_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaALSASource *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
case SPA_INTERFACE_ID_CLOCK:
|
||||
*interface = &this->clock;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else if (interface_id == this->uri.clock)
|
||||
*interface = &this->clock;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -752,7 +749,7 @@ static SpaResult
|
|||
alsa_source_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaALSASource *this;
|
||||
|
|
@ -765,6 +762,20 @@ alsa_source_init (const SpaHandleFactory *factory,
|
|||
handle->clear = alsa_source_clear;
|
||||
|
||||
this = (SpaALSASource *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
|
||||
|
||||
this->node = alsasource_node;
|
||||
this->node.handle = handle;
|
||||
this->clock = alsasource_clock;
|
||||
|
|
@ -790,14 +801,8 @@ alsa_source_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo alsa_source_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
{ SPA_INTERFACE_ID_CLOCK,
|
||||
SPA_INTERFACE_ID_CLOCK_NAME,
|
||||
SPA_INTERFACE_ID_CLOCK_DESCRIPTION,
|
||||
},
|
||||
{ SPA_NODE_URI, },
|
||||
{ SPA_CLOCK_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@
|
|||
|
||||
#include "alsa-utils.h"
|
||||
|
||||
static int verbose = 0; /* verbose flag */
|
||||
|
||||
#define CHECK(s,msg) if ((err = (s)) < 0) { printf (msg ": %s\n", snd_strerror(err)); return err; }
|
||||
#define CHECK(s,msg) if ((err = (s)) < 0) { spa_log_error (state->log, msg ": %s\n", snd_strerror(err)); return err; }
|
||||
|
||||
static int
|
||||
spa_alsa_open (SpaALSAState *state)
|
||||
|
|
@ -24,7 +22,7 @@ spa_alsa_open (SpaALSAState *state)
|
|||
|
||||
CHECK (snd_output_stdio_attach (&state->output, stderr, 0), "attach failed");
|
||||
|
||||
printf ("ALSA device open '%s'\n", props->device);
|
||||
spa_log_info (state->log, "ALSA device open '%s'\n", props->device);
|
||||
CHECK (snd_pcm_open (&state->hndl,
|
||||
props->device,
|
||||
state->stream,
|
||||
|
|
@ -46,7 +44,7 @@ spa_alsa_close (SpaALSAState *state)
|
|||
if (!state->opened)
|
||||
return 0;
|
||||
|
||||
printf ("Playback device closing\n");
|
||||
spa_log_info (state->log, "Playback device closing\n");
|
||||
CHECK (snd_pcm_close (state->hndl), "close failed");
|
||||
|
||||
state->opened = false;
|
||||
|
|
@ -134,14 +132,14 @@ spa_alsa_set_format (SpaALSAState *state, SpaFormatAudio *fmt, SpaPortFormatFlag
|
|||
|
||||
/* set the sample format */
|
||||
format = spa_alsa_format_to_alsa (info->format);
|
||||
printf ("Stream parameters are %iHz, %s, %i channels\n", info->rate, snd_pcm_format_name(format), info->channels);
|
||||
spa_log_info (state->log, "Stream parameters are %iHz, %s, %i channels\n", info->rate, snd_pcm_format_name(format), info->channels);
|
||||
CHECK (snd_pcm_hw_params_set_format (hndl, params, format), "set_format");
|
||||
|
||||
/* set the count of channels */
|
||||
rchannels = info->channels;
|
||||
CHECK (snd_pcm_hw_params_set_channels_near (hndl, params, &rchannels), "set_channels");
|
||||
if (rchannels != info->channels) {
|
||||
fprintf (stderr, "Channels doesn't match (requested %u, get %u\n", info->channels, rchannels);
|
||||
spa_log_info (state->log, "Channels doesn't match (requested %u, get %u\n", info->channels, rchannels);
|
||||
if (flags & SPA_PORT_FORMAT_FLAG_NEAREST)
|
||||
info->channels = rchannels;
|
||||
else
|
||||
|
|
@ -152,7 +150,7 @@ spa_alsa_set_format (SpaALSAState *state, SpaFormatAudio *fmt, SpaPortFormatFlag
|
|||
rrate = info->rate;
|
||||
CHECK (snd_pcm_hw_params_set_rate_near (hndl, params, &rrate, 0), "set_rate_near");
|
||||
if (rrate != info->rate) {
|
||||
fprintf (stderr, "Rate doesn't match (requested %iHz, get %iHz)\n", info->rate, rrate);
|
||||
spa_log_info (state->log, "Rate doesn't match (requested %iHz, get %iHz)\n", info->rate, rrate);
|
||||
if (flags & SPA_PORT_FORMAT_FLAG_NEAREST)
|
||||
info->rate = rrate;
|
||||
else
|
||||
|
|
@ -220,14 +218,12 @@ set_swparams (SpaALSAState *state)
|
|||
* Underrun and suspend recovery
|
||||
*/
|
||||
static int
|
||||
xrun_recovery (snd_pcm_t *hndl, int err)
|
||||
xrun_recovery (SpaALSAState *state, snd_pcm_t *hndl, int err)
|
||||
{
|
||||
if (verbose)
|
||||
printf("stream recovery\n");
|
||||
if (err == -EPIPE) { /* under-run */
|
||||
err = snd_pcm_prepare(hndl);
|
||||
if (err < 0)
|
||||
printf("Can't recovery from underrun, prepare failed: %s\n", snd_strerror(err));
|
||||
spa_log_error (state->log, "Can't recovery from underrun, prepare failed: %s\n", snd_strerror(err));
|
||||
return 0;
|
||||
} else if (err == -ESTRPIPE) {
|
||||
while ((err = snd_pcm_resume(hndl)) == -EAGAIN)
|
||||
|
|
@ -235,7 +231,7 @@ xrun_recovery (snd_pcm_t *hndl, int err)
|
|||
if (err < 0) {
|
||||
err = snd_pcm_prepare(hndl);
|
||||
if (err < 0)
|
||||
printf("Can't recovery from suspend, prepare failed: %s\n", snd_strerror(err));
|
||||
spa_log_error (state->log, "Can't recovery from suspend, prepare failed: %s\n", snd_strerror(err));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -265,8 +261,8 @@ mmap_write (SpaALSAState *state)
|
|||
const snd_pcm_channel_area_t *my_areas;
|
||||
|
||||
if ((avail = snd_pcm_avail_update (hndl)) < 0) {
|
||||
if ((err = xrun_recovery (hndl, avail)) < 0) {
|
||||
printf ("Write error: %s\n", snd_strerror (err));
|
||||
if ((err = xrun_recovery (state, hndl, avail)) < 0) {
|
||||
spa_log_error (state->log, "Write error: %s\n", snd_strerror (err));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -275,8 +271,8 @@ mmap_write (SpaALSAState *state)
|
|||
while (size > 0) {
|
||||
frames = size;
|
||||
if ((err = snd_pcm_mmap_begin (hndl, &my_areas, &offset, &frames)) < 0) {
|
||||
if ((err = xrun_recovery(hndl, err)) < 0) {
|
||||
printf("MMAP begin avail error: %s\n", snd_strerror(err));
|
||||
if ((err = xrun_recovery (state, hndl, err)) < 0) {
|
||||
spa_log_error (state->log, "MMAP begin avail error: %s\n", snd_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -287,8 +283,8 @@ mmap_write (SpaALSAState *state)
|
|||
|
||||
commitres = snd_pcm_mmap_commit (hndl, offset, frames);
|
||||
if (commitres < 0 || (snd_pcm_uframes_t)commitres != frames) {
|
||||
if ((err = xrun_recovery (hndl, commitres >= 0 ? -EPIPE : commitres)) < 0) {
|
||||
printf("MMAP commit error: %s\n", snd_strerror(err));
|
||||
if ((err = xrun_recovery (state, hndl, commitres >= 0 ? -EPIPE : commitres)) < 0) {
|
||||
spa_log_error (state->log, "MMAP commit error: %s\n", snd_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -326,7 +322,7 @@ mmap_read (SpaALSAState *state)
|
|||
|
||||
SPA_QUEUE_POP_HEAD (&state->free, SpaALSABuffer, next, b);
|
||||
if (b == NULL) {
|
||||
fprintf (stderr, "no more buffers\n");
|
||||
spa_log_warn (state->log, "no more buffers\n");
|
||||
} else {
|
||||
dest = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void);
|
||||
destsize = b->outbuf->datas[0].size;
|
||||
|
|
@ -345,8 +341,8 @@ mmap_read (SpaALSAState *state)
|
|||
while (size > 0) {
|
||||
frames = size;
|
||||
if ((err = snd_pcm_mmap_begin (hndl, &my_areas, &offset, &frames)) < 0) {
|
||||
if ((err = xrun_recovery(hndl, err)) < 0) {
|
||||
printf("MMAP begin avail error: %s\n", snd_strerror (err));
|
||||
if ((err = xrun_recovery (state, hndl, err)) < 0) {
|
||||
spa_log_error (state->log, "MMAP begin avail error: %s\n", snd_strerror (err));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -364,8 +360,8 @@ mmap_read (SpaALSAState *state)
|
|||
|
||||
commitres = snd_pcm_mmap_commit (hndl, offset, frames);
|
||||
if (commitres < 0 || (snd_pcm_uframes_t)commitres != frames) {
|
||||
if ((err = xrun_recovery (hndl, commitres >= 0 ? -EPIPE : commitres)) < 0) {
|
||||
printf("MMAP commit error: %s\n", snd_strerror(err));
|
||||
if ((err = xrun_recovery (state, hndl, commitres >= 0 ? -EPIPE : commitres)) < 0) {
|
||||
spa_log_error (state->log, "MMAP commit error: %s\n", snd_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -409,12 +405,12 @@ alsa_on_fd_events (SpaPollNotifyData *data)
|
|||
if (snd_pcm_state (hndl) == SND_PCM_STATE_XRUN ||
|
||||
snd_pcm_state (hndl) == SND_PCM_STATE_SUSPENDED) {
|
||||
err = snd_pcm_state (hndl) == SND_PCM_STATE_XRUN ? -EPIPE : -ESTRPIPE;
|
||||
if ((err = xrun_recovery (hndl, err)) < 0) {
|
||||
printf ("error: %s\n", snd_strerror (err));
|
||||
if ((err = xrun_recovery (state, hndl, err)) < 0) {
|
||||
spa_log_error (state->log, "error: %s\n", snd_strerror (err));
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
printf("Wait for poll failed\n");
|
||||
spa_log_error (state->log, "Wait for poll failed\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -451,11 +447,11 @@ spa_alsa_start (SpaALSAState *state)
|
|||
snd_pcm_dump (state->hndl, state->output);
|
||||
|
||||
if ((state->poll.n_fds = snd_pcm_poll_descriptors_count (state->hndl)) <= 0) {
|
||||
printf ("Invalid poll descriptors count\n");
|
||||
spa_log_error (state->log, "Invalid poll descriptors count\n");
|
||||
return state->poll.n_fds;
|
||||
}
|
||||
if ((err = snd_pcm_poll_descriptors (state->hndl, (struct pollfd *)state->fds, state->poll.n_fds)) < 0) {
|
||||
printf ("Unable to obtain poll descriptors for playback: %s\n", snd_strerror(err));
|
||||
spa_log_error (state->log, "Unable to obtain poll descriptors for playback: %s\n", snd_strerror(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ extern "C" {
|
|||
|
||||
#include <asoundlib.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/queue.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/audio/format.h>
|
||||
|
|
@ -54,11 +56,20 @@ struct _SpaALSABuffer {
|
|||
SpaALSABuffer *next;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
uint32_t clock;
|
||||
} URI;
|
||||
|
||||
struct _SpaALSAState {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
SpaClock clock;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
snd_pcm_stream_t stream;
|
||||
snd_output_t *output;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/audio/format.h>
|
||||
|
||||
|
|
@ -62,10 +64,18 @@ typedef struct {
|
|||
SpaBuffer *buffer;
|
||||
} SpaAudioMixerPort;
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
struct _SpaAudioMixer {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaAudioMixerProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
|
|
@ -692,7 +702,7 @@ spa_audiomixer_node_port_pull_output (SpaNode *node,
|
|||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
if ((info[i].status = mix_data (this, &info[i])) < 0) {
|
||||
printf ("error mixing: %d\n", info[i].status);
|
||||
spa_log_error (this->log, "error mixing: %d\n", info[i].status);
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -760,13 +770,11 @@ spa_audiomixer_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaAudioMixer *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -780,10 +788,11 @@ static SpaResult
|
|||
spa_audiomixer_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaAudioMixer *this;
|
||||
unsigned int i;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -792,6 +801,19 @@ spa_audiomixer_init (const SpaHandleFactory *factory,
|
|||
handle->clear = spa_audiomixer_clear;
|
||||
|
||||
this = (SpaAudioMixer *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
|
||||
this->node = audiomixer_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
|
|
@ -807,10 +829,7 @@ spa_audiomixer_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo audiomixer_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
{ SPA_NODE_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@
|
|||
#include <sys/timerfd.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/queue.h>
|
||||
#include <spa/audio/format.h>
|
||||
|
|
@ -55,11 +57,20 @@ struct _ATSBuffer {
|
|||
size_t size;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
uint32_t clock;
|
||||
} URI;
|
||||
|
||||
struct _SpaAudioTestSrc {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
SpaClock clock;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaAudioTestSrcProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
|
|
@ -528,7 +539,7 @@ static SpaResult
|
|||
clear_buffers (SpaAudioTestSrc *this)
|
||||
{
|
||||
if (this->n_buffers > 0) {
|
||||
fprintf (stderr, "audiotestsrc %p: clear buffers\n", this);
|
||||
spa_log_info (this->log, "audiotestsrc %p: clear buffers\n", this);
|
||||
this->n_buffers = 0;
|
||||
SPA_QUEUE_INIT (&this->empty);
|
||||
SPA_QUEUE_INIT (&this->ready);
|
||||
|
|
@ -692,7 +703,7 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
|
|||
case SPA_DATA_TYPE_MEMFD:
|
||||
case SPA_DATA_TYPE_DMABUF:
|
||||
if (d[0].data == NULL) {
|
||||
fprintf (stderr, "audiotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
|
||||
spa_log_error (this->log, "audiotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
|
||||
continue;
|
||||
}
|
||||
b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);
|
||||
|
|
@ -957,16 +968,13 @@ spa_audiotestsrc_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaAudioTestSrc *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
case SPA_INTERFACE_ID_CLOCK:
|
||||
*interface = &this->clock;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else if (interface_id == this->uri.clock)
|
||||
*interface = &this->clock;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -989,10 +997,11 @@ static SpaResult
|
|||
audiotestsrc_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaAudioTestSrc *this;
|
||||
unsigned int i;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -1001,6 +1010,20 @@ audiotestsrc_init (const SpaHandleFactory *factory,
|
|||
handle->clear = audiotestsrc_clear;
|
||||
|
||||
this = (SpaAudioTestSrc *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
|
||||
|
||||
this->node = audiotestsrc_node;
|
||||
this->node.handle = handle;
|
||||
this->clock = audiotestsrc_clock;
|
||||
|
|
@ -1041,14 +1064,8 @@ audiotestsrc_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo audiotestsrc_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
{ SPA_INTERFACE_ID_CLOCK,
|
||||
SPA_INTERFACE_ID_CLOCK_NAME,
|
||||
SPA_INTERFACE_ID_CLOCK_DESCRIPTION,
|
||||
},
|
||||
{ SPA_NODE_URI, },
|
||||
{ SPA_CLOCK_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/video/format.h>
|
||||
|
||||
|
|
@ -58,10 +60,18 @@ typedef struct {
|
|||
SpaPortStatus status;
|
||||
} SpaFFMpegPort;
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
struct _SpaFFMpegDec {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaFFMpegDecProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
|
|
@ -537,24 +547,39 @@ spa_ffmpeg_dec_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaFFMpegDec *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
SpaResult
|
||||
spa_ffmpeg_dec_init (SpaHandle *handle)
|
||||
spa_ffmpeg_dec_init (SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaFFMpegDec *this;
|
||||
unsigned int i;
|
||||
|
||||
handle->get_interface = spa_ffmpeg_dec_get_interface;
|
||||
|
||||
this = (SpaFFMpegDec *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
|
||||
this->node = ffmpeg_dec_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/video/format.h>
|
||||
|
||||
|
|
@ -63,10 +65,19 @@ typedef struct {
|
|||
SpaPortStatus status;
|
||||
} SpaFFMpegPort;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
struct _SpaFFMpegEnc {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaFFMpegEncProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
|
|
@ -545,24 +556,39 @@ spa_ffmpeg_enc_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaFFMpegEnc *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
SpaResult
|
||||
spa_ffmpeg_enc_init (SpaHandle *handle)
|
||||
spa_ffmpeg_enc_init (SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaFFMpegEnc *this;
|
||||
unsigned int i;
|
||||
|
||||
handle->get_interface = spa_ffmpeg_enc_get_interface;
|
||||
|
||||
this = (SpaFFMpegEnc *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
|
||||
this->node = ffmpeg_enc_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
|
|
|
|||
|
|
@ -25,40 +25,38 @@
|
|||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
|
||||
SpaResult spa_ffmpeg_dec_init (SpaHandle *handle);
|
||||
SpaResult spa_ffmpeg_enc_init (SpaHandle *handle);
|
||||
SpaResult spa_ffmpeg_dec_init (SpaHandle *handle, const SpaDict *info, const SpaSupport *support, unsigned int n_support);
|
||||
SpaResult spa_ffmpeg_enc_init (SpaHandle *handle, const SpaDict *info, const SpaSupport *support, unsigned int n_support);
|
||||
|
||||
static SpaResult
|
||||
ffmpeg_dec_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
return spa_ffmpeg_dec_init (handle);
|
||||
return spa_ffmpeg_dec_init (handle, info, support, n_support);
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
ffmpeg_enc_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
return spa_ffmpeg_enc_init (handle);
|
||||
return spa_ffmpeg_enc_init (handle, info, support, n_support);
|
||||
}
|
||||
|
||||
static const SpaInterfaceInfo ffmpeg_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
{ SPA_NODE_URI,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@
|
|||
#include <spa/control.h>
|
||||
#include <spa/debug.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/queue.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/queue.h>
|
||||
#include "../lib/memfd-wrappers.h"
|
||||
|
||||
|
|
@ -88,10 +89,18 @@ typedef struct {
|
|||
SpaQueue ready;
|
||||
} SpaProxyPort;
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
struct _SpaProxy {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaProxyProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
|
|
@ -176,7 +185,7 @@ static SpaResult
|
|||
clear_buffers (SpaProxy *this, SpaProxyPort *port)
|
||||
{
|
||||
if (port->n_buffers) {
|
||||
fprintf (stderr, "proxy %p: clear buffers\n", this);
|
||||
spa_log_info (this->log, "proxy %p: clear buffers\n", this);
|
||||
|
||||
munmap (port->buffer_mem_ptr, port->buffer_mem_size);
|
||||
close (port->buffer_mem_fd);
|
||||
|
|
@ -273,7 +282,7 @@ spa_proxy_node_send_command (SpaNode *node,
|
|||
spa_control_builder_end (&builder, &control);
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control %d\n", this, res);
|
||||
spa_log_error (this->log, "proxy %p: error writing control %d\n", this, res);
|
||||
|
||||
spa_control_clear (&control);
|
||||
|
||||
|
|
@ -295,7 +304,7 @@ spa_proxy_node_send_command (SpaNode *node,
|
|||
spa_control_builder_end (&builder, &control);
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control %d\n", this, res);
|
||||
spa_log_error (this->log, "proxy %p: error writing control %d\n", this, res);
|
||||
|
||||
spa_control_clear (&control);
|
||||
break;
|
||||
|
|
@ -421,7 +430,7 @@ do_update_port (SpaProxy *this,
|
|||
}
|
||||
|
||||
if (!port->valid) {
|
||||
fprintf (stderr, "proxy %p: adding port %d\n", this, pu->port_id);
|
||||
spa_log_info (this->log, "proxy %p: adding port %d\n", this, pu->port_id);
|
||||
port->format = NULL;
|
||||
port->valid = true;
|
||||
|
||||
|
|
@ -462,7 +471,7 @@ do_uninit_port (SpaProxy *this,
|
|||
{
|
||||
SpaProxyPort *port;
|
||||
|
||||
fprintf (stderr, "proxy %p: removing port %d\n", this, port_id);
|
||||
spa_log_info (this->log, "proxy %p: removing port %d\n", this, port_id);
|
||||
if (direction == SPA_DIRECTION_INPUT) {
|
||||
port = &this->in_ports[port_id];
|
||||
this->n_inputs--;
|
||||
|
|
@ -581,7 +590,7 @@ spa_proxy_node_port_set_format (SpaNode *node,
|
|||
spa_control_builder_end (&builder, &control);
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control\n", this);
|
||||
spa_log_error (this->log, "proxy %p: error writing control\n", this);
|
||||
|
||||
spa_control_clear (&control);
|
||||
|
||||
|
|
@ -709,7 +718,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
fprintf (stderr, "proxy %p: use buffers %p %u\n", this, buffers, n_buffers);
|
||||
spa_log_info (this->log, "proxy %p: use buffers %p %u\n", this, buffers, n_buffers);
|
||||
|
||||
if (!CHECK_PORT (this, direction, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
|
@ -770,7 +779,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
default:
|
||||
b->buffer.datas[j].type = SPA_DATA_TYPE_INVALID;
|
||||
b->buffer.datas[j].data = 0;
|
||||
fprintf (stderr, "invalid memory type %d\n", d->type);
|
||||
spa_log_error (this->log, "invalid memory type %d\n", d->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -783,7 +792,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
port->buffer_mem_fd = memfd_create ("spa-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
||||
|
||||
if (ftruncate (port->buffer_mem_fd, size) < 0) {
|
||||
fprintf (stderr, "Failed to truncate temporary file: %s\n", strerror (errno));
|
||||
spa_log_error (this->log, "Failed to truncate temporary file: %s\n", strerror (errno));
|
||||
close (port->buffer_mem_fd);
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
|
@ -791,7 +800,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
{
|
||||
unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
|
||||
if (fcntl (port->buffer_mem_fd, F_ADD_SEALS, seals) == -1) {
|
||||
fprintf (stderr, "Failed to add seals: %s\n", strerror (errno));
|
||||
spa_log_error (this->log, "Failed to add seals: %s\n", strerror (errno));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -848,7 +857,7 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
spa_control_builder_end (&builder, &control);
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control\n", this);
|
||||
spa_log_error (this->log, "proxy %p: error writing control\n", this);
|
||||
|
||||
spa_control_clear (&control);
|
||||
|
||||
|
|
@ -897,7 +906,7 @@ copy_meta_in (SpaProxy *this, SpaProxyPort *port, uint32_t buffer_id)
|
|||
for (i = 0; i < b->outbuf->n_datas; i++) {
|
||||
b->outbuf->datas[i].size = b->buffer.datas[i].size;
|
||||
if (b->outbuf->datas[i].type == SPA_DATA_TYPE_MEMPTR) {
|
||||
fprintf (stderr, "memcpy in %zd\n", b->buffer.datas[i].size);
|
||||
spa_log_info (this->log, "memcpy in %zd\n", b->buffer.datas[i].size);
|
||||
memcpy (b->outbuf->datas[i].data, b->datas[i].data, b->buffer.datas[i].size);
|
||||
}
|
||||
}
|
||||
|
|
@ -917,7 +926,7 @@ copy_meta_out (SpaProxy *this, SpaProxyPort *port, uint32_t buffer_id)
|
|||
for (i = 0; i < b->outbuf->n_datas; i++) {
|
||||
b->buffer.datas[i].size = b->outbuf->datas[i].size;
|
||||
if (b->datas[i].type == SPA_DATA_TYPE_MEMPTR) {
|
||||
fprintf (stderr, "memcpy out %zd\n", b->outbuf->datas[i].size);
|
||||
spa_log_info (this->log, "memcpy out %zd\n", b->outbuf->datas[i].size);
|
||||
memcpy (b->datas[i].data, b->outbuf->datas[i].data, b->outbuf->datas[i].size);
|
||||
}
|
||||
}
|
||||
|
|
@ -948,7 +957,7 @@ spa_proxy_node_port_push_input (SpaNode *node,
|
|||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
if (!CHECK_IN_PORT (this, SPA_DIRECTION_INPUT, info[i].port_id)) {
|
||||
printf ("invalid port %d\n", info[i].port_id);
|
||||
spa_log_warn (this->log, "invalid port %d\n", info[i].port_id);
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
have_error = true;
|
||||
continue;
|
||||
|
|
@ -986,7 +995,7 @@ spa_proxy_node_port_push_input (SpaNode *node,
|
|||
return SPA_RESULT_HAVE_ENOUGH_INPUT;
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control\n", this);
|
||||
spa_log_error (this->log, "proxy %p: error writing control\n", this);
|
||||
|
||||
spa_control_clear (&control);
|
||||
|
||||
|
|
@ -1011,7 +1020,7 @@ spa_proxy_node_port_pull_output (SpaNode *node,
|
|||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, info[i].port_id)) {
|
||||
fprintf (stderr, "invalid port %u\n", info[i].port_id);
|
||||
spa_log_warn (this->log, "invalid port %u\n", info[i].port_id);
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
have_error = true;
|
||||
continue;
|
||||
|
|
@ -1072,7 +1081,7 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
|
|||
spa_control_builder_end (&builder, &control);
|
||||
|
||||
if ((res = spa_control_write (&control, this->fds[0].fd)) < 0)
|
||||
fprintf (stderr, "proxy %p: error writing control %d\n", this, res);
|
||||
spa_log_error (this->log, "proxy %p: error writing control %d\n", this, res);
|
||||
|
||||
spa_control_clear (&control);
|
||||
|
||||
|
|
@ -1085,12 +1094,16 @@ spa_proxy_node_port_push_event (SpaNode *node,
|
|||
uint32_t port_id,
|
||||
SpaNodeEvent *event)
|
||||
{
|
||||
SpaProxy *this;
|
||||
|
||||
if (node == NULL || node->handle == NULL || event == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = (SpaProxy *) node->handle;
|
||||
|
||||
switch (event->type) {
|
||||
default:
|
||||
fprintf (stderr, "unhandled event %d\n", event->type);
|
||||
spa_log_warn (this->log, "unhandled event %d\n", event->type);
|
||||
break;
|
||||
}
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
|
|
@ -1141,7 +1154,7 @@ parse_control (SpaProxy *this,
|
|||
case SPA_CONTROL_CMD_SET_FORMAT:
|
||||
case SPA_CONTROL_CMD_SET_PROPERTY:
|
||||
case SPA_CONTROL_CMD_NODE_COMMAND:
|
||||
fprintf (stderr, "proxy %p: got unexpected control %d\n", this, cmd);
|
||||
spa_log_error (this->log, "proxy %p: got unexpected control %d\n", this, cmd);
|
||||
break;
|
||||
|
||||
case SPA_CONTROL_CMD_NODE_UPDATE:
|
||||
|
|
@ -1156,7 +1169,7 @@ parse_control (SpaProxy *this,
|
|||
if (nu.change_mask & SPA_CONTROL_CMD_NODE_UPDATE_MAX_OUTPUTS)
|
||||
this->max_outputs = nu.max_output_ports;
|
||||
|
||||
fprintf (stderr, "proxy %p: got node update %d, max_in %u, max_out %u\n", this, cmd,
|
||||
spa_log_info (this->log, "proxy %p: got node update %d, max_in %u, max_out %u\n", this, cmd,
|
||||
this->max_inputs, this->max_outputs);
|
||||
|
||||
break;
|
||||
|
|
@ -1167,7 +1180,7 @@ parse_control (SpaProxy *this,
|
|||
SpaControlCmdPortUpdate pu;
|
||||
bool remove;
|
||||
|
||||
fprintf (stderr, "proxy %p: got port update %d\n", this, cmd);
|
||||
spa_log_info (this->log, "proxy %p: got port update %d\n", this, cmd);
|
||||
if (spa_control_iter_parse_cmd (&it, &pu) < 0)
|
||||
break;
|
||||
|
||||
|
|
@ -1186,7 +1199,7 @@ parse_control (SpaProxy *this,
|
|||
|
||||
case SPA_CONTROL_CMD_PORT_STATUS_CHANGE:
|
||||
{
|
||||
fprintf (stderr, "proxy %p: command not implemented %d\n", this, cmd);
|
||||
spa_log_warn (this->log, "proxy %p: command not implemented %d\n", this, cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1198,7 +1211,7 @@ parse_control (SpaProxy *this,
|
|||
if (spa_control_iter_parse_cmd (&it, &sc) < 0)
|
||||
break;
|
||||
|
||||
fprintf (stderr, "proxy %p: got node state change %d -> %d\n", this, old, sc.state);
|
||||
spa_log_info (this->log, "proxy %p: got node state change %d -> %d\n", this, old, sc.state);
|
||||
this->node.state = sc.state;
|
||||
if (old == SPA_NODE_STATE_INIT)
|
||||
send_async_complete (this, 0, SPA_RESULT_OK);
|
||||
|
|
@ -1227,7 +1240,7 @@ parse_control (SpaProxy *this,
|
|||
port = cmd.direction == SPA_DIRECTION_INPUT ? &this->in_ports[cmd.port_id] : &this->out_ports[cmd.port_id];
|
||||
|
||||
if (port->buffer_id != SPA_ID_INVALID)
|
||||
fprintf (stderr, "proxy %p: unprocessed buffer: %d\n", this, port->buffer_id);
|
||||
spa_log_warn (this->log, "proxy %p: unprocessed buffer: %d\n", this, port->buffer_id);
|
||||
|
||||
copy_meta_in (this, port, cmd.buffer_id);
|
||||
|
||||
|
|
@ -1263,7 +1276,7 @@ proxy_on_fd_events (SpaPollNotifyData *data)
|
|||
int fds[16];
|
||||
|
||||
if ((res = spa_control_read (&control, data->fds[0].fd, buf, 1024, fds, 16)) < 0) {
|
||||
fprintf (stderr, "proxy %p: failed to read control: %d\n", this, res);
|
||||
spa_log_error (this->log, "proxy %p: failed to read control: %d\n", this, res);
|
||||
return 0;
|
||||
}
|
||||
parse_control (this, &control);
|
||||
|
|
@ -1310,14 +1323,11 @@ spa_proxy_get_interface (SpaHandle *handle,
|
|||
if (handle == NULL || interface == 0)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -1348,10 +1358,11 @@ static SpaResult
|
|||
proxy_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaProxy *this;
|
||||
unsigned int i;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -1360,6 +1371,19 @@ proxy_init (const SpaHandleFactory *factory,
|
|||
handle->clear = proxy_clear;
|
||||
|
||||
this = (SpaProxy *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
|
||||
this->node = proxy_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
|
|
@ -1384,10 +1408,7 @@ proxy_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo proxy_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
{ SPA_NODE_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include <libudev.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/poll.h>
|
||||
#include <spa/monitor.h>
|
||||
#include <spa/debug.h>
|
||||
|
|
@ -41,10 +43,18 @@ typedef struct {
|
|||
SpaDictItem info_items[32];
|
||||
} V4l2Item;
|
||||
|
||||
typedef struct {
|
||||
uint32_t monitor;
|
||||
} URI;
|
||||
|
||||
struct _SpaV4l2Monitor {
|
||||
SpaHandle handle;
|
||||
SpaMonitor monitor;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaMonitorEventCallback event_cb;
|
||||
void *user_data;
|
||||
|
||||
|
|
@ -331,13 +341,11 @@ spa_v4l2_monitor_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaV4l2Monitor *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_MONITOR:
|
||||
*interface = &this->monitor;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.monitor)
|
||||
*interface = &this->monitor;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -351,10 +359,11 @@ static SpaResult
|
|||
v4l2_monitor_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaV4l2Monitor *this;
|
||||
unsigned int i;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -363,6 +372,19 @@ v4l2_monitor_init (const SpaHandleFactory *factory,
|
|||
handle->clear = v4l2_monitor_clear,
|
||||
|
||||
this = (SpaV4l2Monitor *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.monitor = spa_id_map_get_id (this->map, SPA_MONITOR_URI);
|
||||
|
||||
this->monitor = v4l2monitor;
|
||||
this->monitor.handle = handle;
|
||||
|
||||
|
|
@ -371,10 +393,7 @@ v4l2_monitor_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo v4l2_monitor_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_MONITOR,
|
||||
SPA_INTERFACE_ID_MONITOR_NAME,
|
||||
SPA_INTERFACE_ID_MONITOR_DESCRIPTION,
|
||||
},
|
||||
{ SPA_MONITOR_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#include <spa/debug.h>
|
||||
#include <spa/queue.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
|
||||
typedef struct _SpaV4l2Source SpaV4l2Source;
|
||||
|
||||
|
|
@ -79,6 +80,13 @@ struct _V4l2Format {
|
|||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
uint32_t clock;
|
||||
} URI;
|
||||
|
||||
typedef struct {
|
||||
SpaLog *log;
|
||||
|
||||
bool export_buf;
|
||||
bool started;
|
||||
|
||||
|
|
@ -112,8 +120,6 @@ typedef struct {
|
|||
SpaAllocParamMetaEnable param_meta;
|
||||
SpaPortStatus status;
|
||||
|
||||
SpaLog *log;
|
||||
|
||||
int64_t last_ticks;
|
||||
int64_t last_monotonic;
|
||||
} SpaV4l2State;
|
||||
|
|
@ -123,6 +129,10 @@ struct _SpaV4l2Source {
|
|||
SpaNode node;
|
||||
SpaClock clock;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaV4l2SourceProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
|
|
@ -808,16 +818,13 @@ spa_v4l2_source_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaV4l2Source *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
case SPA_INTERFACE_ID_CLOCK:
|
||||
*interface = &this->clock;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else if (interface_id == this->uri.clock)
|
||||
*interface = &this->clock;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -831,7 +838,7 @@ static SpaResult
|
|||
v4l2_source_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaV4l2Source *this;
|
||||
|
|
@ -844,6 +851,20 @@ v4l2_source_init (const SpaHandleFactory *factory,
|
|||
handle->clear = v4l2_source_clear,
|
||||
|
||||
this = (SpaV4l2Source *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
|
||||
|
||||
this->node = v4l2source_node;
|
||||
this->node.handle = handle;
|
||||
this->clock = v4l2source_clock;
|
||||
|
|
@ -854,7 +875,7 @@ v4l2_source_init (const SpaHandleFactory *factory,
|
|||
|
||||
SPA_QUEUE_INIT (&this->state[0].ready);
|
||||
|
||||
this->state[0].log = NULL;
|
||||
this->state[0].log = this->log;
|
||||
this->state[0].info.flags = SPA_PORT_INFO_FLAG_LIVE;
|
||||
this->state[0].status.flags = SPA_PORT_STATUS_FLAG_NONE;
|
||||
|
||||
|
|
@ -874,14 +895,8 @@ v4l2_source_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo v4l2_source_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
{ SPA_INTERFACE_ID_CLOCK,
|
||||
SPA_INTERFACE_ID_CLOCK_NAME,
|
||||
SPA_INTERFACE_ID_CLOCK_DESCRIPTION,
|
||||
},
|
||||
{ SPA_NODE_URI, },
|
||||
{ SPA_CLOCK_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@
|
|||
#include <sys/timerfd.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/queue.h>
|
||||
#include <spa/video/format.h>
|
||||
|
|
@ -38,6 +40,11 @@
|
|||
#define STATE_GET_IMAGE_SIZE(this) \
|
||||
(this->bpp * STATE_GET_IMAGE_WIDTH(this) * STATE_GET_IMAGE_HEIGHT(this))
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
uint32_t clock;
|
||||
} URI;
|
||||
|
||||
typedef struct _SpaVideoTestSrc SpaVideoTestSrc;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -63,6 +70,10 @@ struct _SpaVideoTestSrc {
|
|||
SpaNode node;
|
||||
SpaClock clock;
|
||||
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
URI uri;
|
||||
|
||||
SpaVideoTestSrcProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
|
|
@ -476,7 +487,7 @@ static SpaResult
|
|||
clear_buffers (SpaVideoTestSrc *this)
|
||||
{
|
||||
if (this->n_buffers > 0) {
|
||||
fprintf (stderr, "videotestsrc %p: clear buffers\n", this);
|
||||
spa_log_info (this->log, "videotestsrc %p: clear buffers\n", this);
|
||||
this->n_buffers = 0;
|
||||
SPA_QUEUE_INIT (&this->empty);
|
||||
SPA_QUEUE_INIT (&this->ready);
|
||||
|
|
@ -641,7 +652,7 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node,
|
|||
case SPA_DATA_TYPE_MEMFD:
|
||||
case SPA_DATA_TYPE_DMABUF:
|
||||
if (d[0].data == NULL) {
|
||||
fprintf (stderr, "videotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
|
||||
spa_log_error (this->log, "videotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
|
||||
continue;
|
||||
}
|
||||
b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);
|
||||
|
|
@ -905,16 +916,13 @@ spa_videotestsrc_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaVideoTestSrc *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
case SPA_INTERFACE_ID_CLOCK:
|
||||
*interface = &this->clock;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else if (interface_id == this->uri.clock)
|
||||
*interface = &this->clock;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -937,10 +945,11 @@ static SpaResult
|
|||
videotestsrc_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaVideoTestSrc *this;
|
||||
unsigned int i;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -949,6 +958,20 @@ videotestsrc_init (const SpaHandleFactory *factory,
|
|||
handle->clear = videotestsrc_clear;
|
||||
|
||||
this = (SpaVideoTestSrc *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
|
||||
|
||||
this->node = videotestsrc_node;
|
||||
this->node.handle = handle;
|
||||
this->clock = videotestsrc_clock;
|
||||
|
|
@ -989,14 +1012,8 @@ videotestsrc_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo videotestsrc_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
{ SPA_INTERFACE_ID_CLOCK,
|
||||
SPA_INTERFACE_ID_CLOCK_NAME,
|
||||
SPA_INTERFACE_ID_CLOCK_DESCRIPTION,
|
||||
},
|
||||
{ SPA_NODE_URI, },
|
||||
{ SPA_CLOCK_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/audio/format.h>
|
||||
|
||||
|
|
@ -40,10 +42,18 @@ typedef struct {
|
|||
SpaBuffer *buffer;
|
||||
} SpaVolumePort;
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
struct _SpaVolume {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaVolumeProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
|
|
@ -656,14 +666,11 @@ spa_volume_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaVolume *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -677,10 +684,11 @@ static SpaResult
|
|||
volume_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaVolume *this;
|
||||
unsigned int i;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -689,6 +697,19 @@ volume_init (const SpaHandleFactory *factory,
|
|||
handle->clear = volume_clear;
|
||||
|
||||
this = (SpaVolume *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
|
||||
this->node = volume_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
|
|
@ -709,10 +730,7 @@ volume_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo volume_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
{ SPA_NODE_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/video/format.h>
|
||||
|
||||
|
|
@ -67,10 +69,18 @@ typedef struct {
|
|||
uint32_t ready_count;
|
||||
} SpaXvState;
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
struct _SpaXvSink {
|
||||
SpaHandle handle;
|
||||
SpaNode node;
|
||||
|
||||
URI uri;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaXvSinkProps props[2];
|
||||
|
||||
SpaNodeEventCallback event_cb;
|
||||
|
|
@ -538,13 +548,11 @@ spa_xv_sink_get_interface (SpaHandle *handle,
|
|||
|
||||
this = (SpaXvSink *) handle;
|
||||
|
||||
switch (interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
*interface = &this->node;
|
||||
break;
|
||||
default:
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
}
|
||||
if (interface_id == this->uri.node)
|
||||
*interface = &this->node;
|
||||
else
|
||||
return SPA_RESULT_UNKNOWN_INTERFACE;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -558,10 +566,11 @@ static SpaResult
|
|||
xv_sink_init (const SpaHandleFactory *factory,
|
||||
SpaHandle *handle,
|
||||
const SpaDict *info,
|
||||
const SpaSupport **support,
|
||||
const SpaSupport *support,
|
||||
unsigned int n_support)
|
||||
{
|
||||
SpaXvSink *this;
|
||||
unsigned int i;
|
||||
|
||||
if (factory == NULL || handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -570,6 +579,19 @@ xv_sink_init (const SpaHandleFactory *factory,
|
|||
handle->clear = xv_sink_clear;
|
||||
|
||||
this = (SpaXvSink *) handle;
|
||||
|
||||
for (i = 0; i < n_support; i++) {
|
||||
if (strcmp (support[i].uri, SPA_ID_MAP_URI) == 0)
|
||||
this->map = support[i].data;
|
||||
else if (strcmp (support[i].uri, SPA_LOG_URI) == 0)
|
||||
this->log = support[i].data;
|
||||
}
|
||||
if (this->map == NULL) {
|
||||
spa_log_error (this->log, "an id-map is needed");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
|
||||
|
||||
this->node = xvsink_node;
|
||||
this->node.handle = handle;
|
||||
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
||||
|
|
@ -584,10 +606,7 @@ xv_sink_init (const SpaHandleFactory *factory,
|
|||
|
||||
static const SpaInterfaceInfo xv_sink_interfaces[] =
|
||||
{
|
||||
{ SPA_INTERFACE_ID_NODE,
|
||||
SPA_INTERFACE_ID_NODE_NAME,
|
||||
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
||||
},
|
||||
{ SPA_NODE_URI, },
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
|
|||
|
|
@ -27,8 +27,14 @@
|
|||
#include <poll.h>
|
||||
|
||||
#include <spa/node.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/audio/format.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
typedef struct {
|
||||
SpaNode *sink;
|
||||
SpaNode *mix;
|
||||
|
|
@ -40,10 +46,16 @@ typedef struct {
|
|||
SpaPollFd fds[16];
|
||||
unsigned int n_fds;
|
||||
SpaPollItem poll;
|
||||
|
||||
SpaSupport support[2];
|
||||
unsigned int n_support;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
URI uri;
|
||||
} AppData;
|
||||
|
||||
static SpaResult
|
||||
make_node (SpaNode **node, const char *lib, const char *name)
|
||||
make_node (AppData *data, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaHandle *handle;
|
||||
SpaResult res;
|
||||
|
|
@ -74,11 +86,11 @@ 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, data->support, data->n_support)) < 0) {
|
||||
printf ("can't make factory instance: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, SPA_INTERFACE_ID_NODE, &iface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (handle, data->uri.node, &iface)) < 0) {
|
||||
printf ("can't get interface %d\n", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -179,7 +191,7 @@ make_nodes (AppData *data)
|
|||
SpaProps *props;
|
||||
SpaPropValue value;
|
||||
|
||||
if ((res = make_node (&data->sink, "spa/plugins/alsa/libspa-alsa.so", "alsa-sink")) < 0) {
|
||||
if ((res = make_node (data, &data->sink, "spa/plugins/alsa/libspa-alsa.so", "alsa-sink")) < 0) {
|
||||
printf ("can't create alsa-sink: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -196,17 +208,17 @@ make_nodes (AppData *data)
|
|||
printf ("got set_props error %d\n", res);
|
||||
|
||||
|
||||
if ((res = make_node (&data->mix, "spa/plugins/audiomixer/libspa-audiomixer.so", "audiomixer")) < 0) {
|
||||
if ((res = make_node (data, &data->mix, "spa/plugins/audiomixer/libspa-audiomixer.so", "audiomixer")) < 0) {
|
||||
printf ("can't create audiomixer: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
spa_node_set_event_callback (data->mix, on_mix_event, data);
|
||||
|
||||
if ((res = make_node (&data->source1, "spa/plugins/audiotestsrc/libspa-audiotestsrc.so", "audiotestsrc")) < 0) {
|
||||
if ((res = make_node (data, &data->source1, "spa/plugins/audiotestsrc/libspa-audiotestsrc.so", "audiotestsrc")) < 0) {
|
||||
printf ("can't create audiotestsrc: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
if ((res = make_node (&data->source2, "spa/plugins/audiotestsrc/libspa-audiotestsrc.so", "audiotestsrc")) < 0) {
|
||||
if ((res = make_node (data, &data->source2, "spa/plugins/audiotestsrc/libspa-audiotestsrc.so", "audiotestsrc")) < 0) {
|
||||
printf ("can't create audiotestsrc: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -342,6 +354,13 @@ main (int argc, char *argv[])
|
|||
AppData data;
|
||||
SpaResult res;
|
||||
|
||||
data.map = spa_id_map_get_default();
|
||||
data.support[0].uri = SPA_ID_MAP_URI;
|
||||
data.support[0].data = data.map;
|
||||
data.n_support = 1;
|
||||
|
||||
data.uri.node = spa_id_map_get_id (data.map, SPA_NODE_URI);
|
||||
|
||||
if ((res = make_nodes (&data)) < 0) {
|
||||
printf ("can't make nodes: %d\n", res);
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/debug.h>
|
||||
#include <spa/video/format.h>
|
||||
|
|
@ -42,6 +44,10 @@ typedef struct {
|
|||
SpaData datas[1];
|
||||
} SDLBuffer;
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
} URI;
|
||||
|
||||
typedef struct {
|
||||
SpaNode *source;
|
||||
|
||||
|
|
@ -60,10 +66,16 @@ typedef struct {
|
|||
SpaBuffer *bp[MAX_BUFFERS];
|
||||
SDLBuffer buffers[MAX_BUFFERS];
|
||||
unsigned int n_buffers;
|
||||
|
||||
SpaSupport support[2];
|
||||
unsigned int n_support;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
URI uri;
|
||||
} AppData;
|
||||
|
||||
static SpaResult
|
||||
make_node (SpaNode **node, const char *lib, const char *name)
|
||||
make_node (AppData *data, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaHandle *handle;
|
||||
SpaResult res;
|
||||
|
|
@ -98,7 +110,7 @@ make_node (SpaNode **node, const char *lib, const char *name)
|
|||
printf ("can't make factory instance: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, SPA_INTERFACE_ID_NODE, &iface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (handle, data->uri.node, &iface)) < 0) {
|
||||
printf ("can't get interface %d\n", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -199,7 +211,7 @@ make_nodes (AppData *data, const char *device)
|
|||
SpaProps *props;
|
||||
SpaPropValue value;
|
||||
|
||||
if ((res = make_node (&data->source, "spa/plugins/v4l2/libspa-v4l2.so", "v4l2-source")) < 0) {
|
||||
if ((res = make_node (data, &data->source, "spa/plugins/v4l2/libspa-v4l2.so", "v4l2-source")) < 0) {
|
||||
printf ("can't create v4l2-source: %d\n", res);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -419,6 +431,14 @@ main (int argc, char *argv[])
|
|||
|
||||
data.use_buffer = true;
|
||||
|
||||
data.map = spa_id_map_get_default ();
|
||||
|
||||
data.support[0].uri = SPA_ID_MAP_URI;
|
||||
data.support[0].data = data.map;
|
||||
data.n_support = 1;
|
||||
|
||||
data.uri.node = spa_id_map_get_id (data.map, SPA_NODE_URI);
|
||||
|
||||
if (SDL_Init (SDL_INIT_VIDEO) < 0) {
|
||||
printf ("can't initialize SDL: %s\n", SDL_GetError ());
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -23,9 +23,24 @@
|
|||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/log.h>
|
||||
#include <spa/node.h>
|
||||
#include <spa/debug.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
uint32_t clock;
|
||||
} URI;
|
||||
|
||||
typedef struct {
|
||||
URI uri;
|
||||
|
||||
SpaSupport support[2];
|
||||
unsigned int n_support;
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
} AppData;
|
||||
|
||||
static void
|
||||
inspect_port (SpaNode *node, SpaDirection direction, uint32_t port_id)
|
||||
|
|
@ -86,7 +101,7 @@ inspect_node (SpaNode *node)
|
|||
}
|
||||
|
||||
static void
|
||||
inspect_factory (const SpaHandleFactory *factory)
|
||||
inspect_factory (AppData *data, const SpaHandleFactory *factory)
|
||||
{
|
||||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
|
|
@ -101,7 +116,7 @@ inspect_factory (const SpaHandleFactory *factory)
|
|||
printf (" none\n");
|
||||
|
||||
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, data->support, data->n_support)) < 0) {
|
||||
printf ("can't make factory instance: %d\n", res);
|
||||
return;
|
||||
}
|
||||
|
|
@ -110,6 +125,7 @@ inspect_factory (const SpaHandleFactory *factory)
|
|||
|
||||
while (true) {
|
||||
const SpaInterfaceInfo *info;
|
||||
uint32_t interface_id;
|
||||
|
||||
if ((res = spa_handle_factory_enum_interface_info (factory, &info, &state)) < 0) {
|
||||
if (res == SPA_RESULT_ENUM_END)
|
||||
|
|
@ -117,27 +133,26 @@ inspect_factory (const SpaHandleFactory *factory)
|
|||
else
|
||||
printf ("can't enumerate interfaces: %d\n", res);
|
||||
}
|
||||
printf (" interface: (%d) '%s' : '%s'\n", info->interface_id, info->name, info->description);
|
||||
printf (" interface: '%s'\n", info->uri);
|
||||
|
||||
if ((res = spa_handle_get_interface (handle, info->interface_id, &interface)) < 0) {
|
||||
interface_id = spa_id_map_get_id (data->map, info->uri);
|
||||
|
||||
if ((res = spa_handle_get_interface (handle, interface_id, &interface)) < 0) {
|
||||
printf ("can't get interface: %d\n", res);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (info->interface_id) {
|
||||
case SPA_INTERFACE_ID_NODE:
|
||||
inspect_node (interface);
|
||||
break;
|
||||
default:
|
||||
printf ("skipping unknown interface\n");
|
||||
break;
|
||||
}
|
||||
if (interface_id == data->uri.node)
|
||||
inspect_node (interface);
|
||||
else
|
||||
printf ("skipping unknown interface\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
AppData data;
|
||||
SpaResult res;
|
||||
void *handle;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
|
|
@ -148,6 +163,18 @@ main (int argc, char *argv[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
data.map = spa_id_map_get_default();
|
||||
data.log = NULL;
|
||||
|
||||
data.support[0].uri = SPA_ID_MAP_URI;
|
||||
data.support[0].data = data.map;
|
||||
data.support[1].uri = SPA_LOG_URI;
|
||||
data.support[1].data = data.log;
|
||||
data.n_support = 2;
|
||||
|
||||
data.uri.node = spa_id_map_get_id (data.map, SPA_NODE_URI);
|
||||
data.uri.clock = spa_id_map_get_id (data.map, SPA_CLOCK_URI);
|
||||
|
||||
if ((handle = dlopen (argv[1], RTLD_NOW)) == NULL) {
|
||||
printf ("can't load %s\n", argv[1]);
|
||||
return -1;
|
||||
|
|
@ -165,7 +192,7 @@ main (int argc, char *argv[])
|
|||
printf ("can't enumerate factories: %d\n", res);
|
||||
break;
|
||||
}
|
||||
inspect_factory (factory);
|
||||
inspect_factory (&data, factory);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -25,10 +25,34 @@
|
|||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <spa/log.h>
|
||||
#include <spa/id-map.h>
|
||||
#include <spa/monitor.h>
|
||||
#include <spa/poll.h>
|
||||
#include <spa/debug.h>
|
||||
|
||||
typedef struct {
|
||||
uint32_t monitor;
|
||||
} URI;
|
||||
|
||||
typedef struct {
|
||||
URI uri;
|
||||
|
||||
SpaIDMap *map;
|
||||
SpaLog *log;
|
||||
|
||||
SpaSupport support[2];
|
||||
unsigned int n_support;
|
||||
|
||||
unsigned int n_poll;
|
||||
SpaPollItem poll[16];
|
||||
|
||||
bool rebuild_fds;
|
||||
SpaPollFd fds[16];
|
||||
unsigned int n_fds;
|
||||
} AppData;
|
||||
|
||||
|
||||
static void
|
||||
inspect_item (SpaMonitorItem *item)
|
||||
{
|
||||
|
|
@ -38,21 +62,12 @@ inspect_item (SpaMonitorItem *item)
|
|||
spa_debug_dict (item->info);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
unsigned int n_poll;
|
||||
SpaPollItem poll[16];
|
||||
|
||||
bool rebuild_fds;
|
||||
SpaPollFd fds[16];
|
||||
unsigned int n_fds;
|
||||
} PollData;
|
||||
|
||||
static void
|
||||
on_monitor_event (SpaMonitor *monitor,
|
||||
SpaMonitorEvent *event,
|
||||
void *user_data)
|
||||
{
|
||||
PollData *data = user_data;
|
||||
AppData *data = user_data;
|
||||
|
||||
switch (event->type) {
|
||||
case SPA_MONITOR_EVENT_TYPE_ADDED:
|
||||
|
|
@ -97,11 +112,10 @@ on_monitor_event (SpaMonitor *monitor,
|
|||
}
|
||||
|
||||
static void
|
||||
handle_monitor (SpaMonitor *monitor)
|
||||
handle_monitor (AppData *data, SpaMonitor *monitor)
|
||||
{
|
||||
SpaResult res;
|
||||
void *state = NULL;
|
||||
PollData data = { 0, };
|
||||
|
||||
if (monitor->info)
|
||||
spa_debug_dict (monitor->info);
|
||||
|
|
@ -124,23 +138,23 @@ handle_monitor (SpaMonitor *monitor)
|
|||
int i, j, r;
|
||||
|
||||
/* rebuild */
|
||||
if (data.rebuild_fds) {
|
||||
data.n_fds = 0;
|
||||
for (i = 0; i < data.n_poll; i++) {
|
||||
SpaPollItem *p = &data.poll[i];
|
||||
if (data->rebuild_fds) {
|
||||
data->n_fds = 0;
|
||||
for (i = 0; i < data->n_poll; i++) {
|
||||
SpaPollItem *p = &data->poll[i];
|
||||
|
||||
if (!p->enabled)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < p->n_fds; j++)
|
||||
data.fds[data.n_fds + j] = p->fds[j];
|
||||
p->fds = &data.fds[data.n_fds];
|
||||
data.n_fds += p->n_fds;
|
||||
data->fds[data->n_fds + j] = p->fds[j];
|
||||
p->fds = &data->fds[data->n_fds];
|
||||
data->n_fds += p->n_fds;
|
||||
}
|
||||
data.rebuild_fds = false;
|
||||
data->rebuild_fds = false;
|
||||
}
|
||||
|
||||
r = poll ((struct pollfd *) data.fds, data.n_fds, -1);
|
||||
r = poll ((struct pollfd *) data->fds, data->n_fds, -1);
|
||||
if (r < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
|
|
@ -152,8 +166,8 @@ handle_monitor (SpaMonitor *monitor)
|
|||
}
|
||||
|
||||
/* after */
|
||||
for (i = 0; i < data.n_poll; i++) {
|
||||
SpaPollItem *p = &data.poll[i];
|
||||
for (i = 0; i < data->n_poll; i++) {
|
||||
SpaPollItem *p = &data->poll[i];
|
||||
|
||||
if (p->enabled && p->after_cb) {
|
||||
ndata.fds = p->fds;
|
||||
|
|
@ -168,11 +182,23 @@ handle_monitor (SpaMonitor *monitor)
|
|||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
AppData data;
|
||||
SpaResult res;
|
||||
void *handle;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
void *fstate = NULL;
|
||||
|
||||
data.map = spa_id_map_get_default ();
|
||||
data.log = NULL;
|
||||
|
||||
data.support[0].uri = SPA_ID_MAP_URI;
|
||||
data.support[0].data = data.map;
|
||||
data.support[1].uri = SPA_LOG_URI;
|
||||
data.support[1].data = data.log;
|
||||
data.n_support = 2;
|
||||
|
||||
data.uri.monitor = spa_id_map_get_id (data.map, SPA_MONITOR_URI);
|
||||
|
||||
if (argc < 2) {
|
||||
printf ("usage: %s <plugin.so>\n", argv[0]);
|
||||
return -1;
|
||||
|
|
@ -206,21 +232,21 @@ main (int argc, char *argv[])
|
|||
break;
|
||||
}
|
||||
|
||||
if (info->interface_id == SPA_INTERFACE_ID_MONITOR) {
|
||||
if (!strcmp (info->uri, SPA_MONITOR_URI)) {
|
||||
SpaHandle *handle;
|
||||
void *interface;
|
||||
|
||||
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, data.support, data.n_support)) < 0) {
|
||||
printf ("can't make factory instance: %d\n", res);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((res = spa_handle_get_interface (handle, info->interface_id, &interface)) < 0) {
|
||||
if ((res = spa_handle_get_interface (handle, data.uri.monitor, &interface)) < 0) {
|
||||
printf ("can't get interface: %d\n", res);
|
||||
continue;
|
||||
}
|
||||
handle_monitor (interface);
|
||||
handle_monitor (&data, interface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue