Commit 0d21d633 authored by Wim Taymans's avatar Wim Taymans
Browse files

WIP object model change

Work on cleanup
parent c25ccbb4
......@@ -46,7 +46,7 @@ void pinos_log_logv (SpaLogLevel level,
#if __STDC_VERSION__ >= 199901L
#define pinos_log_logc(lev,...) \
if (SPA_UNLIKELY (lev >= pinos_log_level)) \
if (SPA_UNLIKELY (lev <= pinos_log_level)) \
pinos_log_log(lev,__VA_ARGS__)
#define pinos_log_error(...) pinos_log_logc(SPA_LOG_LEVEL_ERROR,__FILE__,__LINE__,__func__,__VA_ARGS__)
......
......@@ -20,7 +20,7 @@
#ifndef __PINOS_PROPERTIES_H__
#define __PINOS_PROPERTIES_H__
#include <glib.h>
#include <glib-object.h>
G_BEGIN_DECLS
......
......@@ -74,8 +74,8 @@ void pinos_transport_free (PinosTransport *trans);
SpaResult pinos_transport_get_info (PinosTransport *trans,
PinosTransportInfo *info);
SpaResult pinos_transport_add_event (PinosTransport *trans,
SpaNodeEvent *event);
SpaResult pinos_transport_add_event (PinosTransport *trans,
SpaNodeEvent *event);
SpaResult pinos_transport_next_event (PinosTransport *trans,
SpaNodeEvent *event);
......
......@@ -30,12 +30,10 @@ const char * pinos_split_walk (const char *str,
const char *delimiter,
size_t *len,
const char **state);
char ** pinos_split_strv (const char *str,
const char *delimiter,
int max_tokens,
int *n_tokens);
void pinos_free_strv (char **str);
#ifdef __cplusplus
......
......@@ -71,8 +71,7 @@ add_item (PinosSpaMonitor *this, SpaMonitorItem *item)
return;
}
if ((res = spa_handle_get_interface (handle, impl->core->registry.uri.spa_clock, &clock_iface)) < 0) {
pinos_log_error ("can't get CLOCK interface: %d", res);
return;
pinos_log_info ("no CLOCK interface: %d", res);
}
if (item->info) {
......
......@@ -30,7 +30,6 @@
#include <sys/eventfd.h>
#include "pinos/client/pinos.h"
#include "pinos/client/enumtypes.h"
#include "pinos/client/private.h"
#include "pinos/client/connection.h"
#include "pinos/client/serialize.h"
......@@ -40,7 +39,6 @@
#include "pinos/server/client-node.h"
#include "spa/include/spa/node.h"
#include "spa/lib/memfd-wrappers.h"
#define MAX_INPUTS 64
#define MAX_OUTPUTS 64
......
......@@ -30,7 +30,6 @@ typedef struct
guint id;
PinosClient1 *iface;
gchar *object_path;
GList *objects;
} PinosClientImpl;
......@@ -191,24 +190,5 @@ pinos_client_destroy (PinosClient * client)
pinos_properties_free (client->properties);
g_clear_object (&impl->iface);
free (impl->object_path);
free (impl);
}
/**
* pinos_client_get_object_path:
* @client: a #PinosClient
*
* Get the object path of @client.
*
* Returns: the object path of @client
*/
const gchar *
pinos_client_get_object_path (PinosClient *client)
{
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, this);
g_return_val_if_fail (client, NULL);
return impl->object_path;
}
......@@ -54,8 +54,6 @@ PinosClient * pinos_client_new (PinosCore *core,
PinosProperties *properties);
void pinos_client_destroy (PinosClient *client);
const gchar * pinos_client_get_object_path (PinosClient *client);
void pinos_client_add_object (PinosClient *client,
PinosObject *object);
......
......@@ -65,6 +65,8 @@ pinos_core_new (PinosMainLoop *main_loop)
pinos_signal_init (&this->port_removed);
pinos_signal_init (&this->port_unlinked);
pinos_signal_init (&this->link_state_changed);
pinos_signal_init (&this->node_unlink);
pinos_signal_init (&this->node_unlink_done);
return this;
}
......
......@@ -98,7 +98,10 @@ struct _PinosCore {
PinosPort *port));
PINOS_SIGNAL (link_state_changed, (PinosListener *listener,
PinosLink *link));
PINOS_SIGNAL (node_unlink, (PinosListener *listener,
PinosNode *node));
PINOS_SIGNAL (node_unlink_done, (PinosListener *listener,
PinosNode *node));
};
PinosCore * pinos_core_new (PinosMainLoop *main_loop);
......
......@@ -64,8 +64,8 @@ static void try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *daemon
static PinosClient *
sender_get_client (PinosDaemon *daemon,
const gchar *sender,
gboolean create)
const char *sender,
bool create)
{
PinosDaemonImpl *impl = SPA_CONTAINER_OF (daemon, PinosDaemonImpl, this);
PinosClient *client;
......@@ -77,11 +77,11 @@ sender_get_client (PinosDaemon *daemon,
return client;
}
static gboolean
static bool
handle_create_node (PinosDaemon1 *interface,
GDBusMethodInvocation *invocation,
const gchar *arg_factory_name,
const gchar *arg_name,
const char *arg_factory_name,
const char *arg_name,
GVariant *arg_properties,
gpointer user_data)
{
......@@ -90,7 +90,7 @@ handle_create_node (PinosDaemon1 *interface,
PinosNodeFactory *factory;
PinosNode *node;
PinosClient *client;
const gchar *sender, *object_path;
const char *sender, *object_path;
PinosProperties *props;
sender = g_dbus_method_invocation_get_sender (invocation);
......@@ -163,12 +163,12 @@ on_link_state_changed (PinosListener *listener,
switch (state) {
case PINOS_LINK_STATE_ERROR:
{
pinos_log_debug ("daemon %p: link %p: state error: %s", impl, link, link->error->message);
pinos_log_debug ("daemon %p: link %p: state error: %s", impl, link, link->error);
if (link->input && link->input->node)
pinos_node_report_error (link->input->node, g_error_copy (link->error));
pinos_node_report_error (link->input->node, strdup (link->error));
if (link->output && link->output->node)
pinos_node_report_error (link->output->node, g_error_copy (link->error));
pinos_node_report_error (link->output->node, strdup (link->error));
break;
}
......@@ -204,7 +204,7 @@ try_link_port (PinosNode *node, PinosPort *port, PinosDaemon *this)
//PinosClient *client;
PinosProperties *props;
const char *path;
GError *error = NULL;
char *error = NULL;
PinosLink *link;
props = node->properties;
......@@ -272,15 +272,13 @@ static void
on_node_created (PinosNode *node,
PinosDaemonImpl *impl)
{
GList *ports, *walk;
PinosPort *port;
ports = pinos_node_get_ports (node, PINOS_DIRECTION_INPUT);
for (walk = ports; walk; walk = g_list_next (walk))
on_port_added (&impl->port_added, node, walk->data);
spa_list_for_each (port, &node->input_ports, link)
on_port_added (&impl->port_added, node, port);
ports = pinos_node_get_ports (node, PINOS_DIRECTION_OUTPUT);
for (walk = ports; walk; walk = g_list_next (walk))
on_port_added (&impl->port_added, node, walk->data);
spa_list_for_each (port, &node->output_ports, link)
on_port_added (&impl->port_added, node, port);
}
static void
......@@ -317,13 +315,12 @@ static void
on_node_removed (PinosDaemon *daemon, PinosNode *node)
{
pinos_log_debug ("daemon %p: node %p removed", daemon, node);
g_signal_handlers_disconnect_by_data (node, daemon);
}
static gboolean
static bool
handle_create_client_node (PinosDaemon1 *interface,
GDBusMethodInvocation *invocation,
const gchar *arg_name,
const char *arg_name,
GVariant *arg_properties,
gpointer user_data)
{
......@@ -404,7 +401,7 @@ export_server_object (PinosDaemon *daemon,
static void
bus_acquired_handler (GDBusConnection *connection,
const gchar *name,
const char *name,
gpointer user_data)
{
PinosDaemonImpl *impl = user_data;
......@@ -417,14 +414,14 @@ bus_acquired_handler (GDBusConnection *connection,
static void
name_acquired_handler (GDBusConnection *connection,
const gchar *name,
const char *name,
gpointer user_data)
{
}
static void
name_lost_handler (GDBusConnection *connection,
const gchar *name,
const char *name,
gpointer user_data)
{
PinosDaemonImpl *impl = user_data;
......@@ -547,11 +544,11 @@ pinos_daemon_find_port (PinosDaemon *daemon,
PinosPort *other_port,
const char *name,
PinosProperties *props,
GPtrArray *format_filters,
GError **error)
SpaFormat **format_filters,
char **error)
{
PinosPort *best = NULL;
gboolean have_name;
bool have_name;
PinosNode *n;
g_return_val_if_fail (daemon, NULL);
......@@ -575,10 +572,7 @@ pinos_daemon_find_port (PinosDaemon *daemon,
}
}
if (best == NULL) {
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_NOT_FOUND,
"No matching Node found");
asprintf (error, "No matching Node found");
}
return best;
}
......
......@@ -20,9 +20,9 @@
#ifndef __PINOS_DAEMON_H__
#define __PINOS_DAEMON_H__
#include <glib-object.h>
G_BEGIN_DECLS
#ifdef __cplusplus
extern "C" {
#endif
#define PINOS_DAEMON_URI "http://pinos.org/ns/daemon"
#define PINOS_DAEMON_PREFIX PINOS_DAEMON_URI "#"
......@@ -32,6 +32,7 @@ typedef struct _PinosDaemon PinosDaemon;
#include <pinos/client/properties.h>
#include <pinos/server/core.h>
#include <pinos/server/node.h>
#include <pinos/server/port.h>
/**
* PinosDaemon:
......@@ -39,8 +40,8 @@ typedef struct _PinosDaemon PinosDaemon;
* Pinos daemon object class.
*/
struct _PinosDaemon {
PinosCore *core;
SpaList list;
PinosCore *core;
SpaList list;
PinosGlobal *global;
PinosProperties *properties;
......@@ -60,13 +61,15 @@ void pinos_daemon_destroy (PinosDaemon *daemon);
#define pinos_daemon_start(d) (d)->start(d)
#define pinos_daemon_stop(d) (d)->stop(d)
PinosPort * pinos_daemon_find_port (PinosDaemon *daemon,
PinosPort *other_port,
const char *name,
PinosProperties *props,
GPtrArray *format_filter,
GError **error);
PinosPort * pinos_daemon_find_port (PinosDaemon *daemon,
PinosPort *other_port,
const char *name,
PinosProperties *props,
SpaFormat **format_filter,
char **error);
G_END_DECLS
#ifdef __cplusplus
}
#endif
#endif /* __PINOS_DAEMON_H__ */
......@@ -26,15 +26,13 @@
#include <limits.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <pthread.h>
#include "spa/include/spa/ringbuffer.h"
#include "pinos/client/log.h"
#include "pinos/client/rtkit.h"
#include "pinos/server/data-loop.h"
#define PINOS_DATA_LOOP_GET_PRIVATE(loop) \
(G_TYPE_INSTANCE_GET_PRIVATE ((loop), PINOS_TYPE_DATA_LOOP, PinosDataLoopPrivate))
#define DATAS_SIZE (4096 * 8)
typedef struct {
......@@ -127,7 +125,6 @@ loop (void *user_data)
SpaPollNotifyData ndata;
unsigned int n_idle = 0;
int r;
struct timespec ts;
/* prepare */
for (i = 0; i < impl->n_poll; i++) {
......@@ -202,9 +199,6 @@ loop (void *user_data)
continue;
}
// clock_gettime (CLOCK_MONOTONIC, &ts);
// fprintf (stderr, "%llu\n", SPA_TIMESPEC_TO_TIME (&ts));
/* after */
for (i = 0; i < impl->n_poll; i++) {
SpaPollItem *p = &impl->poll[i];
......@@ -420,7 +414,7 @@ pinos_data_loop_destroy (PinosDataLoop * loop)
PinosDataLoopImpl *impl = SPA_CONTAINER_OF (loop, PinosDataLoopImpl, this);
pinos_log_debug ("data-loop %p: destroy", impl);
stop_thread (impl, FALSE);
stop_thread (impl, false);
close (impl->fds[0].fd);
free (impl);
}
......
......@@ -20,9 +20,9 @@
#ifndef __PINOS_DATA_LOOP_H__
#define __PINOS_DATA_LOOP_H__
#include <glib-object.h>
G_BEGIN_DECLS
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/include/spa/poll.h>
......@@ -42,6 +42,8 @@ void pinos_data_loop_destroy (PinosDataLoop *loop);
bool pinos_data_loop_in_thread (PinosDataLoop *loop);
G_END_DECLS
#ifdef __cplusplus
}
#endif
#endif /* __PINOS_DATA_LOOP_H__ */
......@@ -42,7 +42,7 @@ typedef struct
PinosLink1 *iface;
GPtrArray *format_filter;
SpaFormat **format_filter;
PinosProperties *properties;
PinosListener input_port_destroy;
......@@ -50,7 +50,7 @@ typedef struct
PinosListener output_port_destroy;
PinosListener output_async_complete;
gboolean allocated;
bool allocated;
PinosMemblock buffer_mem;
SpaBuffer **buffers;
unsigned int n_buffers;
......@@ -60,7 +60,8 @@ static void
pinos_link_update_state (PinosLink *link, PinosLinkState state)
{
if (state != link->state) {
g_clear_error (&link->error);
free (link->error);
link->error = NULL;
pinos_log_debug ("link %p: update state %s -> %s", link,
pinos_link_state_as_string (link->state),
pinos_link_state_as_string (state));
......@@ -70,12 +71,12 @@ pinos_link_update_state (PinosLink *link, PinosLinkState state)
}
static void
pinos_link_report_error (PinosLink *link, GError *error)
pinos_link_report_error (PinosLink *link, char *error)
{
g_clear_error (&link->error);
free (link->error);
link->error = error;
link->state = PINOS_LINK_STATE_ERROR;
pinos_log_debug ("link %p: got error state %s", link, error->message);
pinos_log_debug ("link %p: got error state %s", link, error);
pinos_signal_emit (&link->core->link_state_changed, link);
}
......@@ -85,7 +86,7 @@ do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
SpaResult res;
SpaFormat *filter = NULL, *format;
void *istate = NULL, *ostate = NULL;
GError *error = NULL;
char *error = NULL;
if (in_state != SPA_NODE_STATE_CONFIGURE && out_state != SPA_NODE_STATE_CONFIGURE)
return SPA_RESULT_OK;
......@@ -98,15 +99,12 @@ do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
again:
if ((res = spa_node_port_enum_formats (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
this->input->port_id,
&filter,
NULL,
&istate)) < 0) {
if (res == SPA_RESULT_ENUM_END && istate != NULL) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_FORMAT_NEGOTIATION,
"error input enum formats: %d", res);
asprintf (&error, "error input enum formats: %d", res);
goto error;
}
}
......@@ -115,7 +113,7 @@ again:
if ((res = spa_node_port_enum_formats (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
this->output->port_id,
&format,
filter,
&ostate)) < 0) {
......@@ -123,10 +121,7 @@ again:
ostate = NULL;
goto again;
}
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_FORMAT_NEGOTIATION,
"error output enum formats: %d", res);
asprintf (&error, "error output enum formats: %d", res);
goto error;
}
pinos_log_debug ("Got filtered:");
......@@ -136,24 +131,18 @@ again:
/* only input needs format */
if ((res = spa_node_port_get_format (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
this->output->port_id,
(const SpaFormat **)&format)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_FORMAT_NEGOTIATION,
"error get output format: %d", res);
asprintf (&error, "error get output format: %d", res);
goto error;
}
} else if (out_state == SPA_NODE_STATE_CONFIGURE && in_state > SPA_NODE_STATE_CONFIGURE) {
/* only output needs format */
if ((res = spa_node_port_get_format (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
this->input->port_id,
(const SpaFormat **)&format)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_FORMAT_NEGOTIATION,
"error get input format: %d", res);
asprintf (&error, "error get input format: %d", res);
goto error;
}
} else
......@@ -166,26 +155,20 @@ again:
pinos_log_debug ("link %p: doing set format on output", this);
if ((res = spa_node_port_set_format (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
this->output->port_id,
SPA_PORT_FORMAT_FLAG_NEAREST,
format)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_FORMAT_NEGOTIATION,
"error set output format: %d", res);
asprintf (&error, "error set output format: %d", res);
goto error;
}
} else if (in_state == SPA_NODE_STATE_CONFIGURE) {
pinos_log_debug ("link %p: doing set format on input", this);
if ((res = spa_node_port_set_format (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
this->input->port_id,
SPA_PORT_FORMAT_FLAG_NEAREST,
format)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_FORMAT_NEGOTIATION,
"error set input format: %d", res);
asprintf (&error, "error set input format: %d", res);
goto error;
}
}
......@@ -231,7 +214,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
SpaResult res;
const SpaPortInfo *iinfo, *oinfo;
SpaPortInfoFlags in_flags, out_flags;
GError *error = NULL;
char *error = NULL;
if (in_state != SPA_NODE_STATE_READY && out_state != SPA_NODE_STATE_READY)
return SPA_RESULT_OK;
......@@ -242,22 +225,16 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
/* find out what's possible */
if ((res = spa_node_port_get_info (this->output->node->node,
SPA_DIRECTION_OUTPUT,
this->output->port,
this->output->port_id,
&oinfo)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_BUFFER_ALLOCATION,
"error get output port info: %d", res);
asprintf (&error, "error get output port info: %d", res);
goto error;
}
if ((res = spa_node_port_get_info (this->input->node->node,
SPA_DIRECTION_INPUT,
this->input->port,
this->input->port_id,
&iinfo)) < 0) {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_BUFFER_ALLOCATION,
"error get input port info: %d", res);
asprintf (&error, "error get input port info: %d", res);
goto error;
}
spa_debug_port_info (oinfo);
......@@ -290,10 +267,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
out_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
in_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
} else {
g_set_error (&error,
PINOS_ERROR,
PINOS_ERROR_BUFFER_ALLOCATION,
"no common buffer alloc found");
asprintf (&error, "no common buffer alloc found");
res = SPA_RESULT_ERROR;
goto error;
}
......@@ -309,7 +283,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
if (impl->buffers == NULL) {
SpaAllocParamBuffers *in_alloc, *out_alloc;
SpaAllocParamMetaEnableRingbuffer *in_me, *out_me;
guint max_buffers;
unsigned int max_buffers;
size_t minsize, stride, blocks;
in_me = find_meta_enable (iinfo, SPA_META_TYPE_RINGBUFFER);
......@@ -349,10 +323,10 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
impl->allocated = FALSE;
pinos_log_debug ("reusing %d output buffers %p", impl->n_buffers, impl->buffers);
} else {
guint i, j;
unsigned int i, j;
size_t hdr_size, buf_size, arr_size;
void *p;
guint n_metas, n_datas;
unsigned int n_metas, n_datas;
n_metas = 0;
n_datas = 1;
......@@ -388,7 +362,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
SpaBuffer *b;
SpaData *d;
void *pd;
guint mi;
unsigned int mi;
b = impl->buffers[i] = SPA_MEMBER (p, buf_size * i, SpaBuffer);
......@@ -446,13 +420,10 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
if (out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) {
if ((res = spa_node_port_alloc_buffers (this->output->node->node,
SPA_DIRECTION_OUTPUT,