Remove some unused things.
Work on shutdown.
This commit is contained in:
Wim Taymans 2016-09-01 10:04:25 +02:00
parent 9485bd77e7
commit 463954a299
17 changed files with 166 additions and 99 deletions

View file

@ -35,21 +35,6 @@
#define PINOS_SPA_ALSA_SINK_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_SPA_ALSA_SINK, PinosSpaAlsaSinkPrivate))
typedef struct {
PinosSpaAlsaSink *sink;
PinosPort *port;
} SinkPortData;
typedef struct {
guint32 id;
guint32 type;
int fd;
guint64 offset;
guint64 size;
void *data;
} MemBlock;
struct _PinosSpaAlsaSinkPrivate
{
PinosProperties *props;
@ -61,10 +46,6 @@ struct _PinosSpaAlsaSinkPrivate
gboolean running;
pthread_t thread;
GHashTable *mem_ids;
GList *ports;
};
enum {
@ -216,6 +197,14 @@ on_sink_event (SpaNode *node, SpaEvent *event, void *user_data)
}
break;
}
case SPA_EVENT_TYPE_REMOVE_POLL:
{
if (priv->running) {
priv->running = false;
pthread_join (priv->thread, NULL);
}
break;
}
case SPA_EVENT_TYPE_STATE_CHANGE:
{
SpaEventStateChange *sc = event->data;
@ -252,25 +241,32 @@ setup_node (PinosSpaAlsaSink *this)
}
static void
stop_pipeline (PinosSpaAlsaSink *sink)
pause_pipeline (PinosSpaAlsaSink *sink)
{
PinosNode *node = PINOS_NODE (sink);
PinosSpaAlsaSinkPrivate *priv = sink->priv;
SpaResult res;
SpaCommand cmd;
g_debug ("spa-alsa-sink %p: stopping pipeline", sink);
if (priv->running) {
priv->running = false;
pthread_join (priv->thread, NULL);
}
g_debug ("spa-alsa-sink %p: pausing pipeline", sink);
cmd.type = SPA_COMMAND_PAUSE;
if ((res = spa_node_send_command (node->node, &cmd)) < 0)
g_debug ("got error %d", res);
}
static void
suspend_pipeline (PinosSpaAlsaSink *this)
{
PinosNode *node = PINOS_NODE (this);
SpaResult res;
g_debug ("spa-alsa-sink %p: suspend pipeline", this);
if ((res = spa_node_port_set_format (node->node, 0, 0, NULL)) < 0) {
g_warning ("error unset format output: %d", res);
}
}
static void
destroy_pipeline (PinosSpaAlsaSink *sink)
{
@ -287,13 +283,14 @@ set_state (PinosNode *node,
switch (state) {
case PINOS_NODE_STATE_SUSPENDED:
suspend_pipeline (this);
break;
case PINOS_NODE_STATE_INITIALIZING:
break;
case PINOS_NODE_STATE_IDLE:
stop_pipeline (this);
pause_pipeline (this);
break;
case PINOS_NODE_STATE_RUNNING:
@ -335,8 +332,7 @@ set_property (GObject *object,
static void
on_activate (PinosPort *port, gpointer user_data)
{
SinkPortData *data = user_data;
PinosNode *node = PINOS_NODE (data->sink);
PinosNode *node = user_data;
g_debug ("port %p: activate", port);
@ -346,26 +342,12 @@ on_activate (PinosPort *port, gpointer user_data)
static void
on_deactivate (PinosPort *port, gpointer user_data)
{
SinkPortData *data = user_data;
PinosNode *node = PINOS_NODE (data->sink);
PinosNode *node = user_data;
g_debug ("port %p: deactivate", port);
pinos_node_report_idle (node);
}
static void
free_sink_port_data (SinkPortData *data)
{
g_slice_free (SinkPortData, data);
}
static void
free_mem_block (MemBlock *b)
{
munmap (b->data, b->size);
g_slice_free (MemBlock, b);
}
static gboolean
on_received_buffer (PinosPort *port,
uint32_t buffer_id,
@ -421,46 +403,26 @@ add_port (PinosNode *node,
GError **error)
{
PinosSpaAlsaSink *sink = PINOS_SPA_ALSA_SINK (node);
PinosSpaAlsaSinkPrivate *priv = sink->priv;
SinkPortData *data;
PinosPort *port;
data = g_slice_new0 (SinkPortData);
data->sink = sink;
data->port = PINOS_NODE_CLASS (pinos_spa_alsa_sink_parent_class)
port = PINOS_NODE_CLASS (pinos_spa_alsa_sink_parent_class)
->add_port (node, id, error);
pinos_port_set_received_cb (data->port, on_received_buffer, on_received_event, sink, NULL);
pinos_port_set_received_cb (port, on_received_buffer, on_received_event, sink, NULL);
g_debug ("connecting signals");
g_signal_connect (data->port, "activate", (GCallback) on_activate, data);
g_signal_connect (data->port, "deactivate", (GCallback) on_deactivate, data);
g_signal_connect (port, "activate", (GCallback) on_activate, sink);
g_signal_connect (port, "deactivate", (GCallback) on_deactivate, sink);
priv->ports = g_list_append (priv->ports, data);
return data->port;
return port;
}
static gboolean
remove_port (PinosNode *node,
PinosPort *port)
{
PinosSpaAlsaSink *sink = PINOS_SPA_ALSA_SINK (node);
PinosSpaAlsaSinkPrivate *priv = sink->priv;
GList *walk;
for (walk = priv->ports; walk; walk = g_list_next (walk)) {
SinkPortData *data = walk->data;
if (data->port == port) {
free_sink_port_data (data);
priv->ports = g_list_delete_link (priv->ports, walk);
break;
}
}
if (priv->ports == NULL)
pinos_node_report_idle (node);
return TRUE;
return PINOS_NODE_CLASS (pinos_spa_alsa_sink_parent_class)
->remove_port (node, port);
}
static void
@ -481,7 +443,6 @@ sink_finalize (GObject * object)
destroy_pipeline (sink);
pinos_properties_free (priv->props);
g_hash_table_unref (priv->mem_ids);
G_OBJECT_CLASS (pinos_spa_alsa_sink_parent_class)->finalize (object);
}
@ -507,11 +468,8 @@ pinos_spa_alsa_sink_class_init (PinosSpaAlsaSinkClass * klass)
static void
pinos_spa_alsa_sink_init (PinosSpaAlsaSink * sink)
{
PinosSpaAlsaSinkPrivate *priv;
priv = sink->priv = PINOS_SPA_ALSA_SINK_GET_PRIVATE (sink);
PinosSpaAlsaSinkPrivate *priv = sink->priv = PINOS_SPA_ALSA_SINK_GET_PRIVATE (sink);
priv->props = pinos_properties_new (NULL, NULL);
priv->mem_ids = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) free_mem_block);
}
PinosNode *

View file

@ -46,8 +46,6 @@ struct _PinosSpaV4l2SourcePrivate
gboolean running;
pthread_t thread;
GBytes *format;
};
enum {
@ -143,13 +141,13 @@ on_source_event (SpaNode *node, SpaEvent *event, void *user_data)
{
SpaOutputInfo info[1] = { 0, };
SpaResult res;
GList *walk;
GList *ports, *walk;
if ((res = spa_node_port_pull_output (node, 1, info)) < 0)
g_debug ("spa-v4l2-source %p: got pull error %d, %d", this, res, info[0].status);
walk = pinos_node_get_ports (PINOS_NODE (this));
for (; walk; walk = g_list_next (walk)) {
ports = pinos_node_get_ports (PINOS_NODE (this));
for (walk = ports; walk; walk = g_list_next (walk)) {
PinosPort *port = walk->data;
GError *error = NULL;
@ -158,6 +156,7 @@ on_source_event (SpaNode *node, SpaEvent *event, void *user_data)
g_clear_error (&error);
}
}
g_list_free (ports);
break;
}
@ -351,11 +350,15 @@ source_constructed (GObject * object)
static void
source_finalize (GObject * object)
{
PinosNode *node = PINOS_NODE (object);
PinosSpaV4l2Source *source = PINOS_SPA_V4L2_SOURCE (object);
g_debug ("spa-source %p: dispose", source);
destroy_pipeline (source);
spa_handle_clear (node->node->handle);
g_free (node->node->handle);
G_OBJECT_CLASS (pinos_spa_v4l2_source_parent_class)->finalize (object);
}

View file

@ -27,7 +27,7 @@
#include <fcntl.h>
#include <dlfcn.h>
#include <poll.h>
#include <sys/eventfd.h>
#include <gio/gunixfdlist.h>
@ -220,6 +220,13 @@ loop (void *user_data)
g_debug ("client-node %p: select timeout", this);
break;
}
if (priv->fds[0].revents & POLLIN) {
uint64_t u;
if (read (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t))
g_warning ("client-node %p: failed to read fd", strerror (errno));
break;
}
if (priv->poll.after_cb) {
ndata.fds = priv->poll.fds;
ndata.n_fds = priv->poll.n_fds;
@ -241,7 +248,7 @@ start_thread (PinosClientNode *this)
if (!priv->running) {
priv->running = true;
if ((err = pthread_create (&priv->thread, NULL, loop, this)) != 0) {
g_debug ("client-node %p: can't create thread", strerror (err));
g_warning ("client-node %p: can't create thread", strerror (err));
priv->running = false;
}
}
@ -253,6 +260,11 @@ stop_thread (PinosClientNode *this)
PinosClientNodePrivate *priv = this->priv;
if (priv->running) {
uint64_t u = 1;
if (write (priv->fds[0].fd, &u, sizeof(uint64_t)) != sizeof(uint64_t))
g_warning ("client-node %p: failed to write fd", strerror (errno));
priv->running = false;
pthread_join (priv->thread, NULL);
}
@ -305,6 +317,7 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
PinosPort *port = walk->data;
pinos_port_activate (port);
}
g_list_free (ports);
}
default:
break;
@ -314,11 +327,12 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
case SPA_EVENT_TYPE_ADD_POLL:
{
SpaPollItem *poll = event->data;
unsigned int i;
priv->poll = *poll;
priv->fds[0] = poll->fds[0];
priv->n_fds = 1;
priv->poll.fds = priv->fds;
priv->poll.fds = &priv->fds[priv->n_fds];
for (i = 0; i < poll->n_fds; i++)
priv->fds[priv->n_fds++] = poll->fds[i];
start_thread (this);
break;
@ -406,6 +420,7 @@ pinos_client_node_dispose (GObject * object)
PinosClientNode *this = PINOS_CLIENT_NODE (object);
g_debug ("client-node %p: dispose", this);
stop_thread (this);
G_OBJECT_CLASS (pinos_client_node_parent_class)->dispose (object);
}
@ -413,10 +428,17 @@ pinos_client_node_dispose (GObject * object)
static void
pinos_client_node_finalize (GObject * object)
{
PinosNode *node = PINOS_NODE (object);
PinosClientNode *this = PINOS_CLIENT_NODE (object);
PinosClientNodePrivate *priv = this->priv;
g_debug ("client-node %p: finalize", this);
g_clear_object (&priv->sockets[0]);
g_clear_object (&priv->sockets[1]);
spa_handle_clear (node->node->handle);
g_free (node->node->handle);
G_OBJECT_CLASS (pinos_client_node_parent_class)->finalize (object);
}
@ -424,11 +446,17 @@ static void
pinos_client_node_constructed (GObject * object)
{
PinosClientNode *this = PINOS_CLIENT_NODE (object);
PinosClientNodePrivate *priv = this->priv;
g_debug ("client-node %p: constructed", this);
G_OBJECT_CLASS (pinos_client_node_parent_class)->constructed (object);
priv->fds[0].fd = eventfd (0, 0);
priv->fds[0].events = POLLIN | POLLPRI | POLLERR;
priv->fds[0].revents = 0;
priv->n_fds = 1;
setup_node (this);
}

View file

@ -209,6 +209,7 @@ pinos_client_dispose (GObject * object)
g_debug ("client %p: dispose", client);
copy = g_list_copy (priv->objects);
g_list_free_full (copy, g_object_unref);
g_list_free (priv->objects);
client_unregister_object (client);

View file

@ -248,6 +248,7 @@ handle_create_client_node (PinosDaemon1 *interface,
sender,
arg_name,
props);
pinos_properties_free (props);
socket = pinos_client_node_get_socket_pair (PINOS_CLIENT_NODE (node), &error);
if (socket == NULL)
@ -265,6 +266,7 @@ handle_create_client_node (PinosDaemon1 *interface,
fdlist = g_unix_fd_list_new ();
fdidx = g_unix_fd_list_append (fdlist, g_socket_get_fd (socket), &error);
g_object_unref (socket);
g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,
g_variant_new ("(oh)", object_path, fdidx), fdlist);
@ -532,7 +534,7 @@ pinos_daemon_find_port (PinosDaemon *daemon,
{
PinosDaemonPrivate *priv;
PinosPort *best = NULL;
GList *nodes, *ports;
GList *nodes, *ports, *walk;
gboolean have_name, created_port = FALSE;
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
@ -557,8 +559,9 @@ pinos_daemon_find_port (PinosDaemon *daemon,
node_found = TRUE;
}
for (ports = pinos_node_get_ports (n); ports; ports = g_list_next (ports)) {
PinosPort *p = ports->data;
ports = pinos_node_get_ports (n);
for (walk = ports; walk; walk = g_list_next (walk)) {
PinosPort *p = walk->data;
PinosDirection dir;
g_object_get (p, "direction", &dir, NULL);
@ -572,6 +575,8 @@ pinos_daemon_find_port (PinosDaemon *daemon,
break;
}
}
g_list_free (ports);
if (best == NULL && node_found) {
guint id;

View file

@ -572,6 +572,8 @@ pinos_link_dispose (GObject * object)
g_debug ("link %p: dispose", this);
do_pause (this);
g_signal_handlers_disconnect_by_data (priv->input, this);
g_signal_handlers_disconnect_by_data (priv->output, this);
g_signal_handlers_disconnect_by_data (priv->input->node, this);

View file

@ -191,6 +191,7 @@ find_module (const gchar * path, const gchar *name)
if (g_file_test (newpath, G_FILE_TEST_IS_DIR)) {
filename = find_module (newpath, name);
}
g_free (newpath);
if (filename != NULL)
break;
@ -263,6 +264,8 @@ pinos_module_load (PinosDaemon * daemon,
g_debug ("trying to load module: %s (%s)", name, filename);
gmodule = g_module_open (filename, G_MODULE_BIND_LOCAL);
g_free (filename);
if (gmodule == NULL) {
g_set_error (err, PINOS_MODULE_ERROR, PINOS_MODULE_ERROR_LOADING,
"Failed to open module: %s", g_module_error ());

View file

@ -390,6 +390,7 @@ node_unregister_object (PinosNode *node)
g_debug ("node %p: unregister object %s", node, priv->object_path);
pinos_daemon_unexport (priv->daemon, priv->object_path);
g_clear_pointer (&priv->object_path, g_free);
pinos_daemon_remove_node (priv->daemon, node);
}

View file

@ -48,8 +48,21 @@ struct _SpaHandle {
SpaResult (*get_interface) (SpaHandle *handle,
uint32_t interface_id,
void **interface);
/**
* SpaHandle::clear
* @handle: a pointer to memory
*
* Clean up the memory of @handle. After this, @handle should not be used
* anymore.
*
* Returns: #SPA_RESULT_OK on success
*/
SpaResult (*clear) (SpaHandle *handle);
};
#define spa_handle_get_interface(h,...) (h)->get_interface((h),__VA_ARGS__)
#define spa_handle_clear(h) (h)->clear((h))
/**
* SpaInterfaceInfo:
* @interface_id: the id of the interface, can be used to get the interface
@ -99,6 +112,7 @@ struct _SpaHandleFactory {
*/
SpaResult (*init) (const SpaHandleFactory *factory,
SpaHandle *handle);
/**
* SpaHandle::enum_interface_info:
* @factory: a #SpaHandleFactory
@ -117,6 +131,9 @@ struct _SpaHandleFactory {
void **state);
};
#define spa_handle_factory_init(h,...) (h)->init((h),__VA_ARGS__)
#define spa_handle_factory_enum_interface_info(h,...) (h)->enum_interface_info((h),__VA_ARGS__)
/**
* SpaEnumHandleFactoryFunc:
* @factory: a location to hold the factory result

View file

@ -149,7 +149,7 @@ spa_memory_alloc_with_fd (uint32_t pool_id, void *data, size_t size)
if (!(mem = spa_memory_alloc (pool_id)))
return NULL;
#if 0
#if 1
{
char filename[] = "/dev/shm/spa-tmpfile.XXXXXX";
mem->fd = mkostemp (filename, O_CLOEXEC);
@ -176,7 +176,7 @@ spa_memory_alloc_with_fd (uint32_t pool_id, void *data, size_t size)
return NULL;
}
}
#if 1
#if 0
{
unsigned int seals;

View file

@ -678,6 +678,12 @@ spa_alsa_sink_get_interface (SpaHandle *handle,
return SPA_RESULT_OK;
}
static SpaResult
alsa_sink_clear (SpaHandle *handle)
{
return SPA_RESULT_OK;
}
static SpaResult
alsa_sink_init (const SpaHandleFactory *factory,
SpaHandle *handle)
@ -688,6 +694,7 @@ alsa_sink_init (const SpaHandleFactory *factory,
return SPA_RESULT_INVALID_ARGUMENTS;
handle->get_interface = spa_alsa_sink_get_interface;
handle->clear = alsa_sink_clear;
this = (SpaALSASink *) handle;
this->node = alsasink_node;

View file

@ -770,6 +770,12 @@ spa_audiomixer_get_interface (SpaHandle *handle,
return SPA_RESULT_OK;
}
static SpaResult
spa_audiomixer_clear (SpaHandle *handle)
{
return SPA_RESULT_OK;
}
static SpaResult
spa_audiomixer_init (const SpaHandleFactory *factory,
SpaHandle *handle)
@ -780,6 +786,7 @@ spa_audiomixer_init (const SpaHandleFactory *factory,
return SPA_RESULT_INVALID_ARGUMENTS;
handle->get_interface = spa_audiomixer_get_interface;
handle->clear = spa_audiomixer_clear;
this = (SpaAudioMixer *) handle;
this->node = audiomixer_node;

View file

@ -555,6 +555,12 @@ spa_audiotestsrc_get_interface (SpaHandle *handle,
return SPA_RESULT_OK;
}
static SpaResult
audiotestsrc_clear (SpaHandle *handle)
{
return SPA_RESULT_OK;
}
static SpaResult
audiotestsrc_init (const SpaHandleFactory *factory,
SpaHandle *handle)
@ -565,6 +571,7 @@ audiotestsrc_init (const SpaHandleFactory *factory,
return SPA_RESULT_INVALID_ARGUMENTS;
handle->get_interface = spa_audiotestsrc_get_interface;
handle->clear = audiotestsrc_clear;
this = (SpaAudioTestSrc *) handle;
this->node = audiotestsrc_node;

View file

@ -1121,8 +1121,14 @@ spa_proxy_get_interface (SpaHandle *handle,
}
static SpaResult
proxy_instantiate (const SpaHandleFactory *factory,
SpaHandle *handle)
proxy_clear (SpaHandle *handle)
{
return SPA_RESULT_OK;
}
static SpaResult
proxy_init (const SpaHandleFactory *factory,
SpaHandle *handle)
{
SpaProxy *this;
@ -1130,6 +1136,7 @@ proxy_instantiate (const SpaHandleFactory *factory,
return SPA_RESULT_INVALID_ARGUMENTS;
handle->get_interface = spa_proxy_get_interface;
handle->clear = proxy_clear;
this = (SpaProxy *) handle;
this->node = proxy_node;
@ -1189,6 +1196,6 @@ const SpaHandleFactory spa_proxy_factory =
{ "proxy",
NULL,
sizeof (SpaProxy),
proxy_instantiate,
proxy_init,
proxy_enum_interface_info,
};

View file

@ -763,6 +763,12 @@ spa_v4l2_source_get_interface (SpaHandle *handle,
return SPA_RESULT_OK;
}
static SpaResult
v4l2_source_clear (SpaHandle *handle)
{
return SPA_RESULT_OK;
}
static SpaResult
v4l2_source_init (const SpaHandleFactory *factory,
SpaHandle *handle)
@ -773,6 +779,7 @@ v4l2_source_init (const SpaHandleFactory *factory,
return SPA_RESULT_INVALID_ARGUMENTS;
handle->get_interface = spa_v4l2_source_get_interface;
handle->clear = v4l2_source_clear,
this = (SpaV4l2Source *) handle;
this->node = v4l2source_node;

View file

@ -667,8 +667,14 @@ spa_volume_get_interface (SpaHandle *handle,
}
static SpaResult
volume_instantiate (const SpaHandleFactory *factory,
SpaHandle *handle)
volume_clear (SpaHandle *handle)
{
return SPA_RESULT_OK;
}
static SpaResult
volume_init (const SpaHandleFactory *factory,
SpaHandle *handle)
{
SpaVolume *this;
@ -676,6 +682,7 @@ volume_instantiate (const SpaHandleFactory *factory,
return SPA_RESULT_INVALID_ARGUMENTS;
handle->get_interface = spa_volume_get_interface;
handle->clear = volume_clear;
this = (SpaVolume *) handle;
this->node = volume_node;
@ -732,6 +739,6 @@ const SpaHandleFactory spa_volume_factory =
{ "volume",
NULL,
sizeof (SpaVolume),
volume_instantiate,
volume_init,
volume_enum_interface_info,
};

View file

@ -545,6 +545,12 @@ spa_xv_sink_get_interface (SpaHandle *handle,
return SPA_RESULT_OK;
}
static SpaResult
xv_sink_clear (SpaHandle *handle)
{
return SPA_RESULT_OK;
}
static SpaResult
xv_sink_init (const SpaHandleFactory *factory,
SpaHandle *handle)
@ -555,6 +561,7 @@ xv_sink_init (const SpaHandleFactory *factory,
return SPA_RESULT_INVALID_ARGUMENTS;
handle->get_interface = spa_xv_sink_get_interface;
handle->clear = xv_sink_clear;
this = (SpaXvSink *) handle;
this->node = xvsink_node;