mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
cleanups
Remove some unused things. Work on shutdown.
This commit is contained in:
parent
9485bd77e7
commit
463954a299
17 changed files with 166 additions and 99 deletions
|
|
@ -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 *
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 ());
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue