mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
WIP change object model
This commit is contained in:
parent
190f01d88e
commit
c25ccbb4ba
44 changed files with 1557 additions and 2525 deletions
|
|
@ -1,16 +1,12 @@
|
|||
pinos_module_spa_headers = [
|
||||
'spa-alsa-monitor.h',
|
||||
'spa-audiotestsrc.h',
|
||||
'spa-v4l2-monitor.h',
|
||||
'spa-videotestsrc.h',
|
||||
'spa-node.h',
|
||||
'spa-monitor.h',
|
||||
]
|
||||
|
||||
pinos_module_spa_sources = [
|
||||
'module.c',
|
||||
'spa-alsa-monitor.c',
|
||||
'spa-audiotestsrc.c',
|
||||
'spa-v4l2-monitor.c',
|
||||
'spa-videotestsrc.c',
|
||||
'spa-node.c',
|
||||
'spa-monitor.c',
|
||||
]
|
||||
|
||||
pinos_module_spa_c_args = [
|
||||
|
|
|
|||
|
|
@ -21,20 +21,26 @@
|
|||
#include <server/daemon.h>
|
||||
#include <server/module.h>
|
||||
|
||||
#include "spa-alsa-monitor.h"
|
||||
#include "spa-v4l2-monitor.h"
|
||||
#include "spa-audiotestsrc.h"
|
||||
#include "spa-videotestsrc.h"
|
||||
#include "spa-monitor.h"
|
||||
#include "spa-node.h"
|
||||
|
||||
gboolean pinos__module_init (PinosModule *module, const gchar * args);
|
||||
bool pinos__module_init (PinosModule *module, const char * args);
|
||||
|
||||
G_MODULE_EXPORT gboolean
|
||||
pinos__module_init (PinosModule * module, G_GNUC_UNUSED const gchar * args)
|
||||
G_MODULE_EXPORT bool
|
||||
pinos__module_init (PinosModule * module, const char * args)
|
||||
{
|
||||
pinos_spa_alsa_monitor_new (module->core);
|
||||
pinos_spa_v4l2_monitor_new (module->core);
|
||||
pinos_spa_audiotestsrc_new (module->core, "audiotestsrc", NULL);
|
||||
pinos_spa_videotestsrc_new (module->core, "videotestsrc", NULL);
|
||||
pinos_spa_monitor_load (module->core, "build/spa/plugins/alsa/libspa-alsa.so", "alsa-monitor", args);
|
||||
pinos_spa_monitor_load (module->core, "build/spa/plugins/v4l2/libspa-v4l2.so", "v4l2-monitor", args);
|
||||
pinos_spa_node_load (module->core,
|
||||
"build/spa/plugins/audiotestsrc/libspa-audiotestsrc.so",
|
||||
"audiotestsrc",
|
||||
"audiotestsrc",
|
||||
NULL, args);
|
||||
pinos_spa_node_load (module->core,
|
||||
"build/spa/plugins/videotestsrc/libspa-videotestsrc.so",
|
||||
"videotestsrc",
|
||||
"videotestsrc",
|
||||
NULL, args);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,251 +0,0 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2015 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 <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <spa/include/spa/node.h>
|
||||
#include <spa/include/spa/monitor.h>
|
||||
#include <pinos/client/log.h>
|
||||
#include <pinos/server/node.h>
|
||||
|
||||
#include "spa-alsa-monitor.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PinosSpaALSAMonitor this;
|
||||
|
||||
PinosObject object;
|
||||
|
||||
PinosCore *core;
|
||||
|
||||
SpaHandle *handle;
|
||||
|
||||
GHashTable *nodes;
|
||||
} PinosSpaALSAMonitorImpl;
|
||||
|
||||
static SpaResult
|
||||
make_handle (PinosCore *core, SpaHandle **handle, const char *lib, const char *name, const SpaDict *info)
|
||||
{
|
||||
SpaResult res;
|
||||
void *hnd, *state = NULL;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
|
||||
if ((hnd = dlopen (lib, RTLD_NOW)) == NULL) {
|
||||
g_error ("can't load %s: %s", lib, dlerror());
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if ((enum_func = dlsym (hnd, "spa_enum_handle_factory")) == NULL) {
|
||||
g_error ("can't find enum function");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const SpaHandleFactory *factory;
|
||||
|
||||
if ((res = enum_func (&factory, &state)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
g_error ("can't enumerate factories: %d", res);
|
||||
break;
|
||||
}
|
||||
if (strcmp (factory->name, name))
|
||||
continue;
|
||||
|
||||
*handle = g_malloc0 (factory->size);
|
||||
if ((res = spa_handle_factory_init (factory, *handle, info, core->support, core->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
static void
|
||||
add_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
|
||||
{
|
||||
PinosSpaALSAMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaALSAMonitorImpl, this);
|
||||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
PinosNode *node;
|
||||
void *node_iface, *clock_iface;
|
||||
PinosProperties *props = NULL;
|
||||
|
||||
pinos_log_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,
|
||||
impl->core->support,
|
||||
impl->core->n_support)) < 0) {
|
||||
g_error ("can't make factory instance: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, impl->core->registry.uri.spa_node, &node_iface)) < 0) {
|
||||
g_error ("can't get NODE interface: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle, impl->core->registry.uri.spa_clock, &clock_iface)) < 0) {
|
||||
pinos_log_debug ("can't get CLOCK interface: %d", res);
|
||||
clock_iface = NULL;
|
||||
}
|
||||
|
||||
if (item->info) {
|
||||
unsigned int i;
|
||||
|
||||
props = pinos_properties_new (NULL, NULL);
|
||||
|
||||
for (i = 0; i < item->info->n_items; i++)
|
||||
pinos_properties_set (props,
|
||||
item->info->items[i].key,
|
||||
item->info->items[i].value);
|
||||
}
|
||||
|
||||
node = pinos_node_new (impl->core,
|
||||
item->factory->name,
|
||||
node_iface,
|
||||
clock_iface,
|
||||
props);
|
||||
|
||||
g_hash_table_insert (impl->nodes, strdup (item->id), node);
|
||||
}
|
||||
|
||||
static void
|
||||
remove_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item)
|
||||
{
|
||||
PinosSpaALSAMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaALSAMonitorImpl, this);
|
||||
PinosNode *node;
|
||||
|
||||
pinos_log_debug ("alsa-monitor %p: remove: \"%s\" (%s)", this, item->name, item->id);
|
||||
|
||||
node = g_hash_table_lookup (impl->nodes, item->id);
|
||||
if (node) {
|
||||
pinos_node_destroy (node);
|
||||
g_hash_table_remove (impl->nodes, item->id);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_monitor_event (SpaMonitor *monitor,
|
||||
SpaMonitorEvent *event,
|
||||
void *user_data)
|
||||
{
|
||||
PinosSpaALSAMonitorImpl *impl = SPA_CONTAINER_OF (monitor, PinosSpaALSAMonitorImpl, this);
|
||||
PinosSpaALSAMonitor *this = &impl->this;
|
||||
|
||||
switch (event->type) {
|
||||
case SPA_MONITOR_EVENT_TYPE_ADDED:
|
||||
{
|
||||
SpaMonitorItem *item = (SpaMonitorItem *) event;
|
||||
add_item (this, item);
|
||||
break;
|
||||
}
|
||||
case SPA_MONITOR_EVENT_TYPE_REMOVED:
|
||||
{
|
||||
SpaMonitorItem *item = (SpaMonitorItem *) event;
|
||||
remove_item (this, item);
|
||||
}
|
||||
case SPA_MONITOR_EVENT_TYPE_CHANGED:
|
||||
{
|
||||
SpaMonitorItem *item = (SpaMonitorItem *) event;
|
||||
pinos_log_debug ("alsa-monitor %p: changed: \"%s\"", this, item->name);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
monitor_destroy (PinosObject * object)
|
||||
{
|
||||
PinosSpaALSAMonitorImpl *impl = SPA_CONTAINER_OF (object, PinosSpaALSAMonitorImpl, object);
|
||||
PinosSpaALSAMonitor *this = &impl->this;
|
||||
|
||||
pinos_log_debug ("spa-monitor %p: destroy", this);
|
||||
|
||||
spa_handle_clear (impl->handle);
|
||||
free (impl->handle);
|
||||
|
||||
g_hash_table_unref (impl->nodes);
|
||||
free (impl);
|
||||
}
|
||||
|
||||
PinosSpaALSAMonitor *
|
||||
pinos_spa_alsa_monitor_new (PinosCore *core)
|
||||
{
|
||||
PinosSpaALSAMonitorImpl *impl;
|
||||
PinosSpaALSAMonitor *this;
|
||||
SpaHandle *handle;
|
||||
SpaResult res;
|
||||
void *iface;
|
||||
void *state = NULL;
|
||||
|
||||
if ((res = make_handle (core, &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,
|
||||
core->registry.uri.spa_monitor,
|
||||
&iface)) < 0) {
|
||||
free (handle);
|
||||
pinos_log_error ("can't get MONITOR interface: %d", res);
|
||||
return NULL;
|
||||
}
|
||||
impl = calloc (1, sizeof (PinosSpaALSAMonitorImpl));
|
||||
impl->core = core;
|
||||
this = &impl->this;
|
||||
this->monitor = iface;
|
||||
|
||||
pinos_object_init (&impl->object,
|
||||
impl->core->registry.uri.monitor,
|
||||
this,
|
||||
monitor_destroy);
|
||||
|
||||
impl->nodes = g_hash_table_new_full (g_str_hash,
|
||||
g_str_equal,
|
||||
free,
|
||||
NULL);
|
||||
|
||||
while (true) {
|
||||
SpaMonitorItem *item;
|
||||
|
||||
if ((res = spa_monitor_enum_items (this->monitor, &item, &state)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
pinos_log_debug ("spa_monitor_enum_items: got error %d\n", res);
|
||||
break;
|
||||
}
|
||||
add_item (this, item);
|
||||
}
|
||||
spa_monitor_set_event_callback (this->monitor, on_monitor_event, impl);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2015 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 __PINOS_SPA_ALSA_MONITOR_H__
|
||||
#define __PINOS_SPA_ALSA_MONITOR_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
|
||||
#include <spa/include/spa/monitor.h>
|
||||
#include <pinos/server/daemon.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _PinosSpaALSAMonitor PinosSpaALSAMonitor;
|
||||
|
||||
struct _PinosSpaALSAMonitor {
|
||||
SpaMonitor *monitor;
|
||||
};
|
||||
|
||||
PinosSpaALSAMonitor * pinos_spa_alsa_monitor_new (PinosCore *core);
|
||||
void pinos_spa_alsa_monitor_destroy (PinosSpaALSAMonitor *monitor);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_SPA_ALSA_MONITOR_H__ */
|
||||
|
|
@ -1,207 +0,0 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2015 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 <string.h>
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <spa/include/spa/node.h>
|
||||
|
||||
#include "spa-audiotestsrc.h"
|
||||
|
||||
#define PINOS_SPA_AUDIOTESTSRC_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_SPA_AUDIOTESTSRC, PinosSpaAudioTestSrcPrivate))
|
||||
|
||||
struct _PinosSpaAudioTestSrcPrivate
|
||||
{
|
||||
PinosRingbuffer *ringbuffer;
|
||||
|
||||
SpaHandle *handle;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PinosSpaAudioTestSrc, pinos_spa_audiotestsrc, PINOS_TYPE_NODE);
|
||||
|
||||
static SpaResult
|
||||
make_node (PinosDaemon *daemon, SpaHandle **handle, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaResult res;
|
||||
void *hnd, *state = NULL;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
|
||||
if ((hnd = dlopen (lib, RTLD_NOW)) == NULL) {
|
||||
g_error ("can't load %s: %s", lib, dlerror());
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if ((enum_func = dlsym (hnd, "spa_enum_handle_factory")) == NULL) {
|
||||
g_error ("can't find enum function");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const SpaHandleFactory *factory;
|
||||
void *iface;
|
||||
|
||||
if ((res = enum_func (&factory, &state)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
g_error ("can't enumerate factories: %d", res);
|
||||
break;
|
||||
}
|
||||
if (strcmp (factory->name, name))
|
||||
continue;
|
||||
|
||||
*handle = calloc (1, factory->size);
|
||||
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,
|
||||
daemon->registry.uri.spa_node,
|
||||
&iface)) < 0) {
|
||||
g_error ("can't get interface %d", res);
|
||||
return res;
|
||||
}
|
||||
*node = iface;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
static void
|
||||
setup_node (PinosSpaAudioTestSrc *this)
|
||||
{
|
||||
#if 0
|
||||
PinosNode *node = PINOS_NODE (this);
|
||||
SpaResult res;
|
||||
SpaProps *props;
|
||||
SpaPropValue value;
|
||||
|
||||
if ((res = spa_node_get_props (node->node, &props)) < 0)
|
||||
pinos_log_debug ("got get_props error %d", res);
|
||||
|
||||
if ((res = spa_node_set_props (node->node, props)) < 0)
|
||||
pinos_log_debug ("got set_props error %d", res);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
src_constructed (GObject * object)
|
||||
{
|
||||
PinosSpaAudioTestSrc *src = PINOS_SPA_AUDIOTESTSRC (object);
|
||||
|
||||
setup_node (src);
|
||||
|
||||
G_OBJECT_CLASS (pinos_spa_audiotestsrc_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
src_finalize (GObject * object)
|
||||
{
|
||||
PinosSpaAudioTestSrc *src = PINOS_SPA_AUDIOTESTSRC (object);
|
||||
PinosSpaAudioTestSrcPrivate *priv = src->priv;
|
||||
|
||||
pinos_log_debug ("audiotestsrc %p: dispose", src);
|
||||
spa_handle_clear (priv->handle);
|
||||
g_free (priv->handle);
|
||||
|
||||
G_OBJECT_CLASS (pinos_spa_audiotestsrc_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_spa_audiotestsrc_class_init (PinosSpaAudioTestSrcClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosSpaAudioTestSrcPrivate));
|
||||
|
||||
gobject_class->constructed = src_constructed;
|
||||
gobject_class->finalize = src_finalize;
|
||||
gobject_class->get_property = get_property;
|
||||
gobject_class->set_property = set_property;
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_spa_audiotestsrc_init (PinosSpaAudioTestSrc * this)
|
||||
{
|
||||
this->priv = PINOS_SPA_AUDIOTESTSRC_GET_PRIVATE (this);
|
||||
}
|
||||
|
||||
PinosNode *
|
||||
pinos_spa_audiotestsrc_new (PinosDaemon *daemon,
|
||||
const gchar *name,
|
||||
PinosProperties *properties)
|
||||
{
|
||||
PinosNode *node;
|
||||
SpaNode *n;
|
||||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
|
||||
if ((res = make_node (daemon,
|
||||
&handle,
|
||||
&n,
|
||||
"build/spa/plugins/audiotestsrc/libspa-audiotestsrc.so",
|
||||
"audiotestsrc")) < 0) {
|
||||
g_error ("can't create audiotestsrc: %d", res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node = g_object_new (PINOS_TYPE_SPA_AUDIOTESTSRC,
|
||||
"daemon", daemon,
|
||||
"name", name,
|
||||
"properties", properties,
|
||||
"node", n,
|
||||
NULL);
|
||||
|
||||
PINOS_SPA_AUDIOTESTSRC (node)->priv->handle = handle;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2015 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 __PINOS_SPA_AUDIOTESTSRC_H__
|
||||
#define __PINOS_SPA_AUDIOTESTSRC_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <client/pinos.h>
|
||||
#include <server/node.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
PinosNode * pinos_spa_audiotestsrc_new (PinosCore *core,
|
||||
const gchar *name,
|
||||
PinosProperties *properties);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_SPA_AUDIOTESTSRC_H__ */
|
||||
|
|
@ -31,70 +31,23 @@
|
|||
#include <pinos/client/log.h>
|
||||
#include <pinos/server/node.h>
|
||||
|
||||
#include "spa-v4l2-monitor.h"
|
||||
#include "spa-monitor.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PinosSpaV4l2Monitor this;
|
||||
|
||||
PinosObject object;
|
||||
PinosSpaMonitor this;
|
||||
|
||||
PinosCore *core;
|
||||
|
||||
SpaHandle *handle;
|
||||
void *hnd;
|
||||
|
||||
GHashTable *nodes;
|
||||
} PinosSpaV4l2MonitorImpl;
|
||||
|
||||
static SpaResult
|
||||
make_handle (PinosCore *core,
|
||||
SpaHandle **handle,
|
||||
const char *lib,
|
||||
const char *name,
|
||||
const SpaDict *info)
|
||||
{
|
||||
SpaResult res;
|
||||
void *hnd, *state = NULL;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
|
||||
if ((hnd = dlopen (lib, RTLD_NOW)) == NULL) {
|
||||
pinos_log_error ("can't load %s: %s", lib, dlerror());
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if ((enum_func = dlsym (hnd, "spa_enum_handle_factory")) == NULL) {
|
||||
pinos_log_error ("can't find enum function");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const SpaHandleFactory *factory;
|
||||
|
||||
if ((res = enum_func (&factory, &state)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
pinos_log_error ("can't enumerate factories: %d", res);
|
||||
break;
|
||||
}
|
||||
if (strcmp (factory->name, name))
|
||||
continue;
|
||||
|
||||
*handle = calloc (1, factory->size);
|
||||
if ((res = spa_handle_factory_init (factory,
|
||||
*handle,
|
||||
info,
|
||||
core->support,
|
||||
core->n_support)) < 0) {
|
||||
pinos_log_error ("can't make factory instance: %d", res);
|
||||
return res;
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
} PinosSpaMonitorImpl;
|
||||
|
||||
static void
|
||||
add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
|
||||
add_item (PinosSpaMonitor *this, SpaMonitorItem *item)
|
||||
{
|
||||
PinosSpaV4l2MonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaV4l2MonitorImpl, this);
|
||||
PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this);
|
||||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
PinosNode *node;
|
||||
|
|
@ -102,7 +55,7 @@ add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
|
|||
void *clock_iface;
|
||||
PinosProperties *props = NULL;
|
||||
|
||||
pinos_log_debug ("v4l2-monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
||||
pinos_log_debug ("monitor %p: add: \"%s\" (%s)", this, item->name, item->id);
|
||||
|
||||
handle = calloc (1, item->factory->size);
|
||||
if ((res = spa_handle_factory_init (item->factory,
|
||||
|
|
@ -143,12 +96,12 @@ add_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
|
|||
}
|
||||
|
||||
static void
|
||||
remove_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item)
|
||||
remove_item (PinosSpaMonitor *this, SpaMonitorItem *item)
|
||||
{
|
||||
PinosSpaV4l2MonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaV4l2MonitorImpl, this);
|
||||
PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (this, PinosSpaMonitorImpl, this);
|
||||
PinosNode *node;
|
||||
|
||||
pinos_log_debug ("v4l2-monitor %p: remove: \"%s\" (%s)", this, item->name, item->id);
|
||||
pinos_log_debug ("monitor %p: remove: \"%s\" (%s)", this, item->name, item->id);
|
||||
|
||||
node = g_hash_table_lookup (impl->nodes, item->id);
|
||||
if (node) {
|
||||
|
|
@ -162,7 +115,7 @@ on_monitor_event (SpaMonitor *monitor,
|
|||
SpaMonitorEvent *event,
|
||||
void *user_data)
|
||||
{
|
||||
PinosSpaV4l2Monitor *this = user_data;
|
||||
PinosSpaMonitor *this = user_data;
|
||||
|
||||
switch (event->type) {
|
||||
case SPA_MONITOR_EVENT_TYPE_ADDED:
|
||||
|
|
@ -179,7 +132,7 @@ on_monitor_event (SpaMonitor *monitor,
|
|||
case SPA_MONITOR_EVENT_TYPE_CHANGED:
|
||||
{
|
||||
SpaMonitorItem *item = (SpaMonitorItem *) event;
|
||||
pinos_log_debug ("v4l2-monitor %p: changed: \"%s\"", this, item->name);
|
||||
pinos_log_debug ("monitor %p: changed: \"%s\"", this, item->name);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -187,64 +140,74 @@ on_monitor_event (SpaMonitor *monitor,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
monitor_destroy (PinosObject * object)
|
||||
PinosSpaMonitor *
|
||||
pinos_spa_monitor_load (PinosCore *core,
|
||||
const char *lib,
|
||||
const char *factory_name,
|
||||
const char *args)
|
||||
{
|
||||
PinosSpaV4l2MonitorImpl *impl = SPA_CONTAINER_OF (object, PinosSpaV4l2MonitorImpl, object);
|
||||
PinosSpaV4l2Monitor *this = &impl->this;
|
||||
|
||||
pinos_log_debug ("spa-monitor %p: dispose", this);
|
||||
spa_handle_clear (impl->handle);
|
||||
free (impl->handle);
|
||||
g_hash_table_unref (impl->nodes);
|
||||
free (impl);
|
||||
}
|
||||
|
||||
|
||||
PinosSpaV4l2Monitor *
|
||||
pinos_spa_v4l2_monitor_new (PinosCore *core)
|
||||
{
|
||||
PinosSpaV4l2MonitorImpl *impl;
|
||||
PinosSpaV4l2Monitor *this;
|
||||
PinosSpaMonitorImpl *impl;
|
||||
PinosSpaMonitor *this;
|
||||
SpaHandle *handle;
|
||||
SpaResult res;
|
||||
void *iface;
|
||||
void *state = NULL;
|
||||
void *hnd, *state = NULL;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
const SpaHandleFactory *factory;
|
||||
|
||||
if ((res = make_handle (core,
|
||||
&handle,
|
||||
"build/spa/plugins/v4l2/libspa-v4l2.so",
|
||||
"v4l2-monitor",
|
||||
NULL)) < 0) {
|
||||
pinos_log_error ("can't create v4l2-monitor: %d", res);
|
||||
if ((hnd = dlopen (lib, RTLD_NOW)) == NULL) {
|
||||
pinos_log_error ("can't load %s: %s", lib, dlerror());
|
||||
return NULL;
|
||||
}
|
||||
if ((enum_func = dlsym (hnd, "spa_enum_handle_factory")) == NULL) {
|
||||
pinos_log_error ("can't find enum function");
|
||||
goto no_symbol;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if ((res = enum_func (&factory, &state)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
pinos_log_error ("can't enumerate factories: %d", res);
|
||||
goto enum_failed;
|
||||
}
|
||||
if (strcmp (factory->name, factory_name) == 0)
|
||||
break;
|
||||
}
|
||||
handle = calloc (1, factory->size);
|
||||
if ((res = spa_handle_factory_init (factory,
|
||||
handle,
|
||||
NULL,
|
||||
core->support,
|
||||
core->n_support)) < 0) {
|
||||
pinos_log_error ("can't make factory instance: %d", res);
|
||||
goto init_failed;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
core->registry.uri.spa_monitor,
|
||||
&iface)) < 0) {
|
||||
free (handle);
|
||||
pinos_log_error ("can't get MONITOR interface: %d", res);
|
||||
return NULL;
|
||||
goto interface_failed;
|
||||
}
|
||||
|
||||
impl = calloc (1, sizeof (PinosSpaV4l2MonitorImpl));
|
||||
impl = calloc (1, sizeof (PinosSpaMonitorImpl));
|
||||
impl->core = core;
|
||||
|
||||
pinos_object_init (&impl->object,
|
||||
core->registry.uri.monitor,
|
||||
impl,
|
||||
monitor_destroy);
|
||||
impl->hnd = hnd;
|
||||
|
||||
this = &impl->this;
|
||||
pinos_signal_init (&this->destroy_signal);
|
||||
this->monitor = iface;
|
||||
this->lib = strdup (lib);
|
||||
this->factory_name = strdup (factory_name);
|
||||
this->handle = handle;
|
||||
|
||||
impl->nodes = g_hash_table_new_full (g_str_hash,
|
||||
g_str_equal,
|
||||
g_free,
|
||||
g_object_unref);
|
||||
free,
|
||||
NULL);
|
||||
|
||||
while (TRUE) {
|
||||
state = NULL;
|
||||
while (true) {
|
||||
SpaMonitorItem *item;
|
||||
SpaResult res;
|
||||
|
||||
|
|
@ -257,7 +220,32 @@ pinos_spa_v4l2_monitor_new (PinosCore *core)
|
|||
}
|
||||
spa_monitor_set_event_callback (this->monitor, on_monitor_event, this);
|
||||
|
||||
pinos_registry_add_object (&core->registry, &impl->object);
|
||||
|
||||
return this;
|
||||
|
||||
interface_failed:
|
||||
spa_handle_clear (handle);
|
||||
init_failed:
|
||||
free (handle);
|
||||
enum_failed:
|
||||
no_symbol:
|
||||
dlclose (hnd);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
pinos_spa_monitor_destroy (PinosSpaMonitor * monitor)
|
||||
{
|
||||
PinosSpaMonitorImpl *impl = SPA_CONTAINER_OF (monitor, PinosSpaMonitorImpl, this);
|
||||
|
||||
pinos_log_debug ("spa-monitor %p: dispose", impl);
|
||||
pinos_signal_emit (&monitor->destroy_signal, monitor);
|
||||
|
||||
spa_handle_clear (monitor->handle);
|
||||
free (monitor->handle);
|
||||
free (monitor->lib);
|
||||
free (monitor->factory_name);
|
||||
g_hash_table_unref (impl->nodes);
|
||||
dlclose (impl->hnd);
|
||||
free (impl);
|
||||
}
|
||||
|
|
@ -17,26 +17,36 @@
|
|||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PINOS_SPA_V4L2_MONITOR_H__
|
||||
#define __PINOS_SPA_V4L2_MONITOR_H__
|
||||
#ifndef __PINOS_SPA_MONITOR_H__
|
||||
#define __PINOS_SPA_MONITOR_H__
|
||||
|
||||
#include <pinos/server/core.h>
|
||||
#include <spa/include/spa/monitor.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _PinosSpaV4l2Monitor PinosSpaV4l2Monitor;
|
||||
typedef struct _PinosSpaMonitor PinosSpaMonitor;
|
||||
|
||||
struct _PinosSpaV4l2Monitor {
|
||||
struct _PinosSpaMonitor {
|
||||
SpaMonitor *monitor;
|
||||
|
||||
char *lib;
|
||||
char *factory_name;
|
||||
SpaHandle *handle;
|
||||
|
||||
PINOS_SIGNAL (destroy_signal, (PinosListener *listener, PinosSpaMonitor *monitor));
|
||||
};
|
||||
|
||||
PinosSpaV4l2Monitor * pinos_spa_v4l2_monitor_new (PinosCore *core);
|
||||
void pinos_spa_v4l2_monitor_destroy (PinosSpaV4l2Monitor *monitor);
|
||||
PinosSpaMonitor * pinos_spa_monitor_load (PinosCore *core,
|
||||
const char *lib,
|
||||
const char *factory_name,
|
||||
const char *args);
|
||||
void pinos_spa_monitor_destroy (PinosSpaMonitor *monitor);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PINOS_SPA_V4L2_MONITOR_H__ */
|
||||
#endif /* __PINOS_SPA_MONITOR_H__ */
|
||||
138
pinos/modules/spa/spa-node.c
Normal file
138
pinos/modules/spa/spa-node.c
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2015 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 <string.h>
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <spa/include/spa/node.h>
|
||||
|
||||
#include "spa-node.h"
|
||||
|
||||
typedef struct {
|
||||
PinosSpaNode this;
|
||||
PinosCore *core;
|
||||
|
||||
void *hnd;
|
||||
} PinosSpaNodeImpl;
|
||||
|
||||
PinosSpaNode *
|
||||
pinos_spa_node_load (PinosCore *core,
|
||||
const char *lib,
|
||||
const char *factory_name,
|
||||
const char *name,
|
||||
PinosProperties *properties,
|
||||
const char *args)
|
||||
{
|
||||
PinosSpaNode *this;
|
||||
PinosSpaNodeImpl *impl;
|
||||
SpaNode *spa_node;
|
||||
SpaClock *spa_clock;
|
||||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
void *hnd, *state = NULL;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
const SpaHandleFactory *factory;
|
||||
void *iface;
|
||||
|
||||
if ((hnd = dlopen (lib, RTLD_NOW)) == NULL) {
|
||||
pinos_log_error ("can't load %s: %s", lib, dlerror());
|
||||
return NULL;
|
||||
}
|
||||
if ((enum_func = dlsym (hnd, "spa_enum_handle_factory")) == NULL) {
|
||||
pinos_log_error ("can't find enum function");
|
||||
goto no_symbol;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if ((res = enum_func (&factory, &state)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
pinos_log_error ("can't enumerate factories: %d", res);
|
||||
goto enum_failed;
|
||||
}
|
||||
if (strcmp (factory->name, factory_name) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
handle = calloc (1, factory->size);
|
||||
if ((res = spa_handle_factory_init (factory,
|
||||
handle,
|
||||
NULL,
|
||||
core->support,
|
||||
core->n_support)) < 0) {
|
||||
pinos_log_error ("can't make factory instance: %d", res);
|
||||
goto init_failed;
|
||||
}
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
core->registry.uri.spa_node,
|
||||
&iface)) < 0) {
|
||||
pinos_log_error ("can't get interface %d", res);
|
||||
goto interface_failed;
|
||||
}
|
||||
spa_node = iface;
|
||||
|
||||
if ((res = spa_handle_get_interface (handle,
|
||||
core->registry.uri.spa_clock,
|
||||
&iface)) < 0) {
|
||||
iface = NULL;
|
||||
}
|
||||
spa_clock = iface;
|
||||
|
||||
impl = calloc (1, sizeof (PinosSpaNodeImpl));
|
||||
impl->core = core;
|
||||
impl->hnd = hnd;
|
||||
this = &impl->this;
|
||||
this->node = pinos_node_new (core,
|
||||
name,
|
||||
spa_node,
|
||||
spa_clock,
|
||||
properties);
|
||||
this->lib = strdup (lib);
|
||||
this->factory_name = strdup (factory_name);
|
||||
this->handle = handle;
|
||||
|
||||
return this;
|
||||
|
||||
interface_failed:
|
||||
spa_handle_clear (handle);
|
||||
init_failed:
|
||||
free (handle);
|
||||
enum_failed:
|
||||
no_symbol:
|
||||
dlclose (hnd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
pinos_spa_node_destroy (PinosSpaNode * node)
|
||||
{
|
||||
PinosSpaNodeImpl *impl = SPA_CONTAINER_OF (node, PinosSpaNodeImpl, this);
|
||||
|
||||
pinos_log_debug ("spa-node %p: destroy", impl);
|
||||
pinos_signal_emit (&node->destroy_signal, node);
|
||||
|
||||
pinos_node_destroy (node->node);
|
||||
|
||||
spa_handle_clear (node->handle);
|
||||
free (node->handle);
|
||||
free (node->lib);
|
||||
free (node->factory_name);
|
||||
dlclose (impl->hnd);
|
||||
free (impl);
|
||||
}
|
||||
52
pinos/modules/spa/spa-node.h
Normal file
52
pinos/modules/spa/spa-node.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2015 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 __PINOS_SPA_NODE_H__
|
||||
#define __PINOS_SPA_NODE_H__
|
||||
|
||||
#include <server/core.h>
|
||||
#include <server/node.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef struct _PinosSpaNode PinosSpaNode;
|
||||
|
||||
struct _PinosSpaNode {
|
||||
PinosNode *node;
|
||||
|
||||
char *lib;
|
||||
char *factory_name;
|
||||
SpaHandle *handle;
|
||||
PINOS_SIGNAL (destroy_signal, (PinosListener *listener,
|
||||
PinosSpaNode *node));
|
||||
};
|
||||
|
||||
PinosSpaNode * pinos_spa_node_load (PinosCore *core,
|
||||
const char *lib,
|
||||
const char *factory_name,
|
||||
const char *name,
|
||||
PinosProperties *properties,
|
||||
const char *args);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PINOS_SPA_NODE_H__ */
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2016 Axis Communications AB
|
||||
*
|
||||
* 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 <dlfcn.h>
|
||||
|
||||
#include <spa/include/spa/node.h>
|
||||
#include <spa/include/spa/video/format.h>
|
||||
|
||||
#include "spa-videotestsrc.h"
|
||||
|
||||
#define PINOS_SPA_VIDEOTESTSRC_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_SPA_VIDEOTESTSRC, PinosSpaVideoTestSrcPrivate))
|
||||
|
||||
struct _PinosSpaVideoTestSrcPrivate
|
||||
{
|
||||
SpaHandle *handle;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PinosSpaVideoTestSrc, pinos_spa_videotestsrc, PINOS_TYPE_NODE);
|
||||
|
||||
static SpaResult
|
||||
make_node (PinosDaemon *daemon, SpaHandle **handle, SpaNode **node, const char *lib, const char *name)
|
||||
{
|
||||
SpaResult res;
|
||||
void *hnd, *state = NULL;
|
||||
SpaEnumHandleFactoryFunc enum_func;
|
||||
|
||||
if ((hnd = dlopen (lib, RTLD_NOW)) == NULL) {
|
||||
g_error ("can't load %s: %s", lib, dlerror());
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if ((enum_func = dlsym (hnd, "spa_enum_handle_factory")) == NULL) {
|
||||
g_error ("can't find enum function");
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const SpaHandleFactory *factory;
|
||||
void *iface;
|
||||
|
||||
if ((res = enum_func (&factory, &state)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
g_error ("can't enumerate factories: %d", res);
|
||||
break;
|
||||
}
|
||||
if (strcmp (factory->name, name))
|
||||
continue;
|
||||
|
||||
*handle = calloc (1, factory->size);
|
||||
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,
|
||||
daemon->registry.uri.spa_node,
|
||||
&iface)) < 0) {
|
||||
g_error ("can't get interface %d", res);
|
||||
return res;
|
||||
}
|
||||
*node = iface;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
source_finalize (GObject * object)
|
||||
{
|
||||
PinosSpaVideoTestSrc *source = PINOS_SPA_VIDEOTESTSRC (object);
|
||||
PinosSpaVideoTestSrcPrivate *priv = source->priv;
|
||||
|
||||
g_debug ("spa-source %p: dispose", source);
|
||||
spa_handle_clear (priv->handle);
|
||||
g_free (priv->handle);
|
||||
|
||||
G_OBJECT_CLASS (pinos_spa_videotestsrc_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_spa_videotestsrc_class_init (PinosSpaVideoTestSrcClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosSpaVideoTestSrcPrivate));
|
||||
|
||||
gobject_class->finalize = source_finalize;
|
||||
gobject_class->get_property = get_property;
|
||||
gobject_class->set_property = set_property;
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_spa_videotestsrc_init (PinosSpaVideoTestSrc * source)
|
||||
{
|
||||
source->priv = PINOS_SPA_VIDEOTESTSRC_GET_PRIVATE (source);
|
||||
}
|
||||
|
||||
PinosNode *
|
||||
pinos_spa_videotestsrc_new (PinosDaemon *daemon,
|
||||
const gchar *name,
|
||||
PinosProperties *properties)
|
||||
{
|
||||
PinosNode *node;
|
||||
SpaNode *n;
|
||||
SpaResult res;
|
||||
SpaHandle *handle;
|
||||
|
||||
if ((res = make_node (daemon,
|
||||
&handle,
|
||||
&n,
|
||||
"build/spa/plugins/videotestsrc/libspa-videotestsrc.so",
|
||||
"videotestsrc")) < 0) {
|
||||
g_error ("can't create videotestsrc: %d", res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node = g_object_new (PINOS_TYPE_SPA_VIDEOTESTSRC,
|
||||
"daemon", daemon,
|
||||
"name", name,
|
||||
"properties", properties,
|
||||
"node", n,
|
||||
NULL);
|
||||
|
||||
PINOS_SPA_VIDEOTESTSRC (node)->priv->handle = handle;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/* Pinos
|
||||
* Copyright (C) 2016 Axis Communications AB
|
||||
*
|
||||
* 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 __PINOS_SPA_VIDEOTESTSRC_H__
|
||||
#define __PINOS_SPA_VIDEOTESTSRC_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <client/pinos.h>
|
||||
#include <server/node.h>
|
||||
|
||||
typedef struct _PinosSpaVideoTestSrc PinosSpaVideoTestSrc;
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct _PinosSpaVideoTestSrc {
|
||||
PinosNode *node;
|
||||
};
|
||||
|
||||
PinosSpaVideoTestSrc * pinos_spa_videotestsrc_new (PinosCore *core,
|
||||
const gchar *name,
|
||||
PinosProperties *properties);
|
||||
void pinos_spa_videotestsrc_destroy (PinosSpaVideoTestSrc *src);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __PINOS_SPA_VIDEOTESTSRC_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue