diff --git a/pinos/modules/spa/spa-alsa-monitor.c b/pinos/modules/spa/spa-alsa-monitor.c index 20bf43872..62f54b862 100644 --- a/pinos/modules/spa/spa-alsa-monitor.c +++ b/pinos/modules/spa/spa-alsa-monitor.c @@ -49,11 +49,6 @@ struct _PinosSpaALSAMonitorPrivate URI uri; - GSource *watch_source; - - unsigned int n_poll; - SpaPollItem poll[16]; - GHashTable *nodes; }; @@ -165,30 +160,12 @@ remove_item (PinosSpaALSAMonitor *this, SpaMonitorItem *item) } } -static gboolean -poll_event (GIOChannel *source, - GIOCondition condition, - gpointer user_data) -{ - PinosSpaALSAMonitor *this = user_data; - PinosSpaALSAMonitorPrivate *priv = this->priv; - SpaPollNotifyData data; - - data.user_data = priv->poll[0].user_data; - data.fds = priv->poll[0].fds; - data.n_fds = priv->poll[0].n_fds; - priv->poll[0].after_cb (&data); - - return TRUE; -} - static void on_monitor_event (SpaMonitor *monitor, SpaMonitorEvent *event, void *user_data) { PinosSpaALSAMonitor *this = user_data; - PinosSpaALSAMonitorPrivate *priv = this->priv; switch (event->type) { case SPA_MONITOR_EVENT_TYPE_ADDED: @@ -208,31 +185,6 @@ on_monitor_event (SpaMonitor *monitor, g_debug ("alsa-monitor %p: changed: \"%s\"", this, item->name); break; } - case SPA_MONITOR_EVENT_TYPE_ADD_POLL: - { - SpaPollItem *item = event->data; - GIOChannel *channel; - - priv->poll[priv->n_poll] = *item; - priv->n_poll++; - - channel = g_io_channel_unix_new (item->fds[0].fd); - priv->watch_source = g_io_create_watch (channel, G_IO_IN); - g_io_channel_unref (channel); - g_source_set_callback (priv->watch_source, (GSourceFunc) poll_event, this, NULL); - g_source_attach (priv->watch_source, g_main_context_get_thread_default ()); - g_source_unref (priv->watch_source); - break; - } - case SPA_MONITOR_EVENT_TYPE_UPDATE_POLL: - break; - case SPA_MONITOR_EVENT_TYPE_REMOVE_POLL: - { - priv->n_poll--; - g_source_destroy (priv->watch_source); - priv->watch_source = NULL; - break; - } default: break; } diff --git a/pinos/modules/spa/spa-v4l2-monitor.c b/pinos/modules/spa/spa-v4l2-monitor.c index 9d7d947da..8d8170cfd 100644 --- a/pinos/modules/spa/spa-v4l2-monitor.c +++ b/pinos/modules/spa/spa-v4l2-monitor.c @@ -49,11 +49,6 @@ struct _PinosSpaV4l2MonitorPrivate URI uri; - GSource *watch_source; - - unsigned int n_poll; - SpaPollItem poll[16]; - GHashTable *nodes; }; @@ -165,30 +160,12 @@ remove_item (PinosSpaV4l2Monitor *this, SpaMonitorItem *item) } } -static gboolean -poll_event (GIOChannel *source, - GIOCondition condition, - gpointer user_data) -{ - PinosSpaV4l2Monitor *this = user_data; - PinosSpaV4l2MonitorPrivate *priv = this->priv; - SpaPollNotifyData data; - - data.user_data = priv->poll[0].user_data; - data.fds = priv->poll[0].fds; - data.n_fds = priv->poll[0].n_fds; - priv->poll[0].after_cb (&data); - - return TRUE; -} - static void on_monitor_event (SpaMonitor *monitor, SpaMonitorEvent *event, void *user_data) { PinosSpaV4l2Monitor *this = user_data; - PinosSpaV4l2MonitorPrivate *priv = this->priv; switch (event->type) { case SPA_MONITOR_EVENT_TYPE_ADDED: @@ -208,31 +185,6 @@ on_monitor_event (SpaMonitor *monitor, g_debug ("v4l2-monitor %p: changed: \"%s\"", this, item->name); break; } - case SPA_MONITOR_EVENT_TYPE_ADD_POLL: - { - SpaPollItem *item = event->data; - GIOChannel *channel; - - priv->poll[priv->n_poll] = *item; - priv->n_poll++; - - channel = g_io_channel_unix_new (item->fds[0].fd); - priv->watch_source = g_io_create_watch (channel, G_IO_IN); - g_io_channel_unref (channel); - g_source_set_callback (priv->watch_source, (GSourceFunc) poll_event, this, NULL); - g_source_attach (priv->watch_source, g_main_context_get_thread_default ()); - g_source_unref (priv->watch_source); - break; - } - case SPA_MONITOR_EVENT_TYPE_UPDATE_POLL: - break; - case SPA_MONITOR_EVENT_TYPE_REMOVE_POLL: - { - priv->n_poll--; - g_source_destroy (priv->watch_source); - priv->watch_source = NULL; - break; - } default: break; } diff --git a/pinos/server/daemon.c b/pinos/server/daemon.c index 6a99304be..1be90d68c 100644 --- a/pinos/server/daemon.c +++ b/pinos/server/daemon.c @@ -57,8 +57,9 @@ struct _PinosDaemonPrivate GHashTable *node_factories; - SpaSupport support[3]; + SpaSupport support[4]; SpaLog log; + SpaPoll main_loop; }; enum @@ -868,6 +869,69 @@ do_log (SpaLog *log, va_end (args); } +typedef struct { + PinosDaemonPrivate *priv; + SpaPollItem item; +} PollData; + +static gboolean +poll_event (GIOChannel *source, + GIOCondition condition, + gpointer user_data) +{ + PollData *data = user_data; + SpaPollNotifyData d; + + d.user_data = data->item.user_data; + d.fds = data->item.fds; + d.n_fds = data->item.n_fds; + data->item.after_cb (&d); + + return TRUE; +} + +static SpaResult +do_add_item (SpaPoll *poll, + SpaPollItem *item) +{ + PinosDaemonPrivate *priv = SPA_CONTAINER_OF (poll, PinosDaemonPrivate, main_loop); + GIOChannel *channel; + GSource *source; + PollData data; + + channel = g_io_channel_unix_new (item->fds[0].fd); + source = g_io_create_watch (channel, G_IO_IN); + g_io_channel_unref (channel); + + data.priv = priv; + data.item = *item; + + g_source_set_callback (source, (GSourceFunc) poll_event, g_slice_dup (PollData, &data) , NULL); + item->id = g_source_attach (source, g_main_context_get_thread_default ()); + g_source_unref (source); + + return SPA_RESULT_OK; +} + +static SpaResult +do_update_item (SpaPoll *poll, + SpaPollItem *item) +{ + return SPA_RESULT_OK; +} + +static SpaResult +do_remove_item (SpaPoll *poll, + SpaPollItem *item) +{ + GSource *source; + + source = g_main_context_find_source_by_id (g_main_context_get_thread_default (), item->id); + g_source_destroy (source); + + return SPA_RESULT_OK; +} + static void pinos_daemon_init (PinosDaemon * daemon) { @@ -886,6 +950,14 @@ pinos_daemon_init (PinosDaemon * daemon) g_object_unref); priv->loop = pinos_rtloop_new(); + priv->main_loop.handle = NULL; + priv->main_loop.size = sizeof (SpaPoll); + priv->main_loop.info = NULL; + priv->main_loop.info = NULL; + priv->main_loop.add_item = do_add_item; + priv->main_loop.update_item = do_update_item; + priv->main_loop.remove_item = do_remove_item; + priv->log.handle = NULL; priv->log.size = sizeof (SpaLog); priv->log.info = NULL; @@ -902,8 +974,10 @@ pinos_daemon_init (PinosDaemon * daemon) priv->support[1].data = daemon->log; priv->support[2].uri = SPA_POLL__DataLoop; priv->support[2].data = &priv->loop->poll; + priv->support[3].uri = SPA_POLL__MainLoop; + priv->support[3].data = &priv->main_loop; daemon->support = priv->support; - daemon->n_support = 3; + daemon->n_support = 4; } /** diff --git a/spa/include/spa/monitor.h b/spa/include/spa/monitor.h index f76d7ac86..065b82204 100644 --- a/spa/include/spa/monitor.h +++ b/spa/include/spa/monitor.h @@ -65,18 +65,12 @@ typedef struct { * @SPA_MONITOR_EVENT_TYPE_ADDED: an item was added, data points to #SpaMonitorItem * @SPA_MONITOR_EVENT_TYPE_REMOVED: an item was removed, data points to #SpaMonitorItem * @SPA_MONITOR_EVENT_TYPE_CHANGED: an item was changed, data points to #SpaMonitorItem - * @SPA_MONITOR_EVENT_TYPE_ADD_POLL: add fd for polling, data points to #SpaPollItem - * @SPA_MONITOR_EVENT_TYPE_UPDATE_POLL: update fd for polling, data points to #SpaPollItem - * @SPA_MONITOR_EVENT_TYPE_REMOVE_POLL: remov fd for polling, data points to #SpaPollItem */ typedef enum { SPA_MONITOR_EVENT_TYPE_INVALID = 0, SPA_MONITOR_EVENT_TYPE_ADDED, SPA_MONITOR_EVENT_TYPE_REMOVED, SPA_MONITOR_EVENT_TYPE_CHANGED, - SPA_MONITOR_EVENT_TYPE_ADD_POLL, - SPA_MONITOR_EVENT_TYPE_UPDATE_POLL, - SPA_MONITOR_EVENT_TYPE_REMOVE_POLL, } SpaMonitorEventType; typedef struct { diff --git a/spa/include/spa/node-event.h b/spa/include/spa/node-event.h index 5f6fe515a..5f78e43f9 100644 --- a/spa/include/spa/node-event.h +++ b/spa/include/spa/node-event.h @@ -41,6 +41,7 @@ typedef struct _SpaNodeEvent SpaNodeEvent; #define SPA_NODE_EVENT__Marker SPA_NODE_EVENT_PREFIX "Marker" #define SPA_NODE_EVENT__Error SPA_NODE_EVENT_PREFIX "Error" #define SPA_NODE_EVENT__Buffering SPA_NODE_EVENT_PREFIX "Buffering" +#define SPA_NODE_EVENT__RequestRefresh SPA_NODE_EVENT_PREFIX "RequestRefresh" #define SPA_NODE_EVENT__RequestClockUpdate SPA_NODE_EVENT_PREFIX "RequestClockUpdate" /** @@ -82,10 +83,6 @@ typedef struct { SpaResult res; } SpaNodeEventAsyncComplete; -typedef struct { - SpaNodeState state; -} SpaNodeEventStateChange; - typedef struct { uint32_t port_id; } SpaNodeEventHaveOutput; diff --git a/spa/plugins/alsa/alsa-monitor.c b/spa/plugins/alsa/alsa-monitor.c index 3fdce63a0..470550720 100644 --- a/spa/plugins/alsa/alsa-monitor.c +++ b/spa/plugins/alsa/alsa-monitor.c @@ -54,6 +54,7 @@ struct _SpaALSAMonitor { URI uri; SpaIDMap *map; SpaLog *log; + SpaPoll *main_loop; SpaMonitorEventCallback event_cb; void *user_data; @@ -245,7 +246,6 @@ spa_alsa_monitor_set_event_callback (SpaMonitor *monitor, { SpaResult res; SpaALSAMonitor *this; - SpaMonitorEvent event; if (monitor == NULL || monitor->handle == NULL) return SPA_RESULT_INVALID_ARGUMENTS; @@ -269,11 +269,6 @@ spa_alsa_monitor_set_event_callback (SpaMonitor *monitor, udev_monitor_enable_receiving (this->umonitor); this->fd = udev_monitor_get_fd (this->umonitor);; - - event.type = SPA_MONITOR_EVENT_TYPE_ADD_POLL; - event.data = &this->poll; - event.size = sizeof (this->poll); - this->fds[0].fd = this->fd; this->fds[0].events = POLLIN | POLLPRI | POLLERR; this->fds[0].revents = 0; @@ -286,12 +281,9 @@ spa_alsa_monitor_set_event_callback (SpaMonitor *monitor, this->poll.before_cb = NULL; this->poll.after_cb = alsa_on_fd_events; this->poll.user_data = this; - this->event_cb (&this->monitor, &event, this->user_data); + spa_poll_add_item (this->main_loop, &this->poll); } else { - event.type = SPA_MONITOR_EVENT_TYPE_REMOVE_POLL; - event.data = &this->poll; - event.size = sizeof (this->poll); - this->event_cb (&this->monitor, &event, this->user_data); + spa_poll_remove_item (this->main_loop, &this->poll); } return SPA_RESULT_OK; @@ -407,11 +399,17 @@ alsa_monitor_init (const SpaHandleFactory *factory, this->map = support[i].data; else if (strcmp (support[i].uri, SPA_LOG_URI) == 0) this->log = support[i].data; + else if (strcmp (support[i].uri, SPA_POLL__MainLoop) == 0) + this->main_loop = support[i].data; } if (this->map == NULL) { spa_log_error (this->log, "an id-map is needed"); return SPA_RESULT_ERROR; } + if (this->main_loop == NULL) { + spa_log_error (this->log, "a main-loop is needed"); + return SPA_RESULT_ERROR; + } this->uri.monitor = spa_id_map_get_id (this->map, SPA_MONITOR_URI); this->monitor = alsamonitor; diff --git a/spa/plugins/v4l2/v4l2-monitor.c b/spa/plugins/v4l2/v4l2-monitor.c index 398545594..30aa68461 100644 --- a/spa/plugins/v4l2/v4l2-monitor.c +++ b/spa/plugins/v4l2/v4l2-monitor.c @@ -54,6 +54,7 @@ struct _SpaV4l2Monitor { URI uri; SpaIDMap *map; SpaLog *log; + SpaPoll *main_loop; SpaMonitorEventCallback event_cb; void *user_data; @@ -216,7 +217,6 @@ spa_v4l2_monitor_set_event_callback (SpaMonitor *monitor, { SpaResult res; SpaV4l2Monitor *this; - SpaMonitorEvent event; if (monitor == NULL || monitor->handle == NULL) return SPA_RESULT_INVALID_ARGUMENTS; @@ -241,10 +241,6 @@ spa_v4l2_monitor_set_event_callback (SpaMonitor *monitor, udev_monitor_enable_receiving (this->umonitor); this->fd = udev_monitor_get_fd (this->umonitor);; - event.type = SPA_MONITOR_EVENT_TYPE_ADD_POLL; - event.data = &this->poll; - event.size = sizeof (this->poll); - this->fds[0].fd = this->fd; this->fds[0].events = POLLIN | POLLPRI | POLLERR; this->fds[0].revents = 0; @@ -257,12 +253,9 @@ spa_v4l2_monitor_set_event_callback (SpaMonitor *monitor, this->poll.before_cb = NULL; this->poll.after_cb = v4l2_on_fd_events; this->poll.user_data = this; - this->event_cb (&this->monitor, &event, this->user_data); + spa_poll_add_item (this->main_loop, &this->poll); } else { - event.type = SPA_MONITOR_EVENT_TYPE_REMOVE_POLL; - event.data = &this->poll; - event.size = sizeof (this->poll); - this->event_cb (&this->monitor, &event, this->user_data); + spa_poll_remove_item (this->main_loop, &this->poll); } return SPA_RESULT_OK; @@ -378,11 +371,17 @@ v4l2_monitor_init (const SpaHandleFactory *factory, this->map = support[i].data; else if (strcmp (support[i].uri, SPA_LOG_URI) == 0) this->log = support[i].data; + else if (strcmp (support[i].uri, SPA_POLL__MainLoop) == 0) + this->main_loop = support[i].data; } if (this->map == NULL) { spa_log_error (this->log, "an id-map is needed"); return SPA_RESULT_ERROR; } + if (this->main_loop == NULL) { + spa_log_error (this->log, "a main-loop is needed"); + return SPA_RESULT_ERROR; + } this->uri.monitor = spa_id_map_get_id (this->map, SPA_MONITOR_URI); this->monitor = v4l2monitor; diff --git a/spa/tools/spa-monitor.c b/spa/tools/spa-monitor.c index ab2d8caa4..a418aca4c 100644 --- a/spa/tools/spa-monitor.c +++ b/spa/tools/spa-monitor.c @@ -40,8 +40,9 @@ typedef struct { SpaIDMap *map; SpaLog *log; + SpaPoll main_loop; - SpaSupport support[2]; + SpaSupport support[3]; unsigned int n_support; unsigned int n_poll; @@ -67,8 +68,6 @@ on_monitor_event (SpaMonitor *monitor, SpaMonitorEvent *event, void *user_data) { - AppData *data = user_data; - switch (event->type) { case SPA_MONITOR_EVENT_TYPE_ADDED: { @@ -91,26 +90,37 @@ on_monitor_event (SpaMonitor *monitor, inspect_item (item); break; } - case SPA_MONITOR_EVENT_TYPE_ADD_POLL: - { - SpaPollItem *item = event->data; - - data->poll[data->n_poll] = *item; - data->n_poll++; - if (item->n_fds) - data->rebuild_fds = true; - break; - } - - case SPA_MONITOR_EVENT_TYPE_UPDATE_POLL: - break; - case SPA_MONITOR_EVENT_TYPE_REMOVE_POLL: - break; default: break; } } +static SpaResult +do_add_item (SpaPoll *poll, + SpaPollItem *item) +{ + AppData *data = SPA_CONTAINER_OF (poll, AppData, main_loop); + + data->poll[data->n_poll] = *item; + data->n_poll++; + if (item->n_fds) + data->rebuild_fds = true; + + return SPA_RESULT_OK; +} +static SpaResult +do_update_item (SpaPoll *poll, + SpaPollItem *item) +{ + return SPA_RESULT_OK; +} + +static SpaResult +do_remove_item (SpaPoll *poll, + SpaPollItem *item) +{ + return SPA_RESULT_OK; +} static void handle_monitor (AppData *data, SpaMonitor *monitor) { @@ -182,7 +192,7 @@ handle_monitor (AppData *data, SpaMonitor *monitor) int main (int argc, char *argv[]) { - AppData data; + AppData data = { 0 }; SpaResult res; void *handle; SpaEnumHandleFactoryFunc enum_func; @@ -190,12 +200,20 @@ main (int argc, char *argv[]) data.map = spa_id_map_get_default (); data.log = NULL; + data.main_loop.handle = NULL; + data.main_loop.size = sizeof (SpaPoll); + data.main_loop.info = NULL; + data.main_loop.add_item = do_add_item; + data.main_loop.update_item = do_update_item; + data.main_loop.remove_item = do_remove_item; data.support[0].uri = SPA_ID_MAP_URI; data.support[0].data = data.map; data.support[1].uri = SPA_LOG_URI; data.support[1].data = data.log; - data.n_support = 2; + data.support[2].uri = SPA_POLL__MainLoop; + data.support[2].data = &data.main_loop; + data.n_support = 3; data.uri.monitor = spa_id_map_get_id (data.map, SPA_MONITOR_URI);