From d0f95fc323194fc462ffa10bb0ca43bc48432bf2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 9 Nov 2016 12:57:51 +0100 Subject: [PATCH] Remove SpaQueue, use SpaList instead --- pinos/client/array.h | 2 +- pinos/client/signal.h | 12 ++-- pinos/client/stream.c | 8 +-- pinos/server/client-node.c | 4 -- pinos/server/client.c | 4 +- pinos/server/daemon.c | 27 +++++---- pinos/server/link.c | 5 +- pinos/server/main-loop.c | 36 +++++------- pinos/server/node.c | 4 +- {pinos/client => spa/include/spa}/list.h | 54 +++++++++--------- spa/include/spa/queue.h | 72 ------------------------ spa/lib/mapper.c | 13 ----- spa/plugins/alsa/alsa-sink.c | 9 +-- spa/plugins/alsa/alsa-source.c | 17 +++--- spa/plugins/alsa/alsa-utils.c | 21 +++---- spa/plugins/alsa/alsa-utils.h | 8 +-- spa/plugins/audiotestsrc/audiotestsrc.c | 37 ++++++------ spa/plugins/v4l2/v4l2-source.c | 18 ++++-- spa/plugins/v4l2/v4l2-utils.c | 3 +- spa/plugins/videotestsrc/videotestsrc.c | 36 ++++++------ 20 files changed, 153 insertions(+), 237 deletions(-) rename {pinos/client => spa/include/spa}/list.h (53%) delete mode 100644 spa/include/spa/queue.h diff --git a/pinos/client/array.h b/pinos/client/array.h index fa4801597..ed981f269 100644 --- a/pinos/client/array.h +++ b/pinos/client/array.h @@ -42,7 +42,7 @@ struct _PinosArray { #define pinos_array_get_unchecked(a,idx,t) pinos_array_get_unchecked_s(a,idx,sizeof(t),t) #define pinos_array_check_index(a,idx,t) pinos_array_check_index_s(a,idx,sizeof(t)) -#define PINOS_ARRAY_FOREACH(pos, array) \ +#define pinos_array_for_each(pos, array) \ for (pos = (array)->data; \ (const char *) pos < ((const char *) (array)->data + (array)->size); \ (pos)++) diff --git a/pinos/client/signal.h b/pinos/client/signal.h index 1d42573e3..11ad8f1a9 100644 --- a/pinos/client/signal.h +++ b/pinos/client/signal.h @@ -20,7 +20,7 @@ #ifndef __PINOS_SIGNAL_H__ #define __PINOS_SIGNAL_H__ -#include +#include #ifdef __cplusplus extern "C" { @@ -30,26 +30,26 @@ typedef struct _PinosSignal PinosSignal; typedef struct _PinosListener PinosListener; struct _PinosListener { - PinosList link; + SpaList link; void (*notify) (PinosListener *listener, void *data); void *user_data; }; struct _PinosSignal { - PinosList listeners; + SpaList listeners; }; static inline void pinos_signal_init (PinosSignal *signal) { - pinos_list_init (&signal->listeners); + spa_list_init (&signal->listeners); } static inline void pinos_signal_add (PinosSignal *signal, PinosListener *listener) { - pinos_list_insert (signal->listeners.prev, &listener->link); + spa_list_insert (signal->listeners.prev, &listener->link); } static inline void @@ -58,7 +58,7 @@ pinos_signal_emit (PinosSignal *signal, { PinosListener *l, *next; - PINOS_LIST_FOREACH_SAFE (l, next, &signal->listeners, link) + spa_list_for_each_safe (l, next, &signal->listeners, link) l->notify (l, data); } diff --git a/pinos/client/stream.c b/pinos/client/stream.c index 148d60127..a8443556f 100644 --- a/pinos/client/stream.c +++ b/pinos/client/stream.c @@ -142,7 +142,7 @@ clear_buffers (PinosStream *stream) PinosStreamPrivate *priv = stream->priv; BufferId *bid; - PINOS_ARRAY_FOREACH (bid, &priv->buffer_ids) { + pinos_array_for_each (bid, &priv->buffer_ids) { g_signal_emit (stream, signals[SIGNAL_REMOVE_BUFFER], 0, bid->id); bid->buf = NULL; } @@ -730,7 +730,7 @@ find_mem (PinosStream *stream, uint32_t id) PinosStreamPrivate *priv = stream->priv; MemId *mid; - PINOS_ARRAY_FOREACH (mid, &priv->mem_ids) { + pinos_array_for_each (mid, &priv->mem_ids) { if (mid->id == id) return mid; } @@ -747,7 +747,7 @@ find_buffer (PinosStream *stream, uint32_t id) } else { BufferId *bid; - PINOS_ARRAY_FOREACH (bid, &priv->buffer_ids) { + pinos_array_for_each (bid, &priv->buffer_ids) { if (bid->id == id) return bid; } @@ -1706,7 +1706,7 @@ pinos_stream_get_empty_buffer (PinosStream *stream) priv = stream->priv; g_return_val_if_fail (priv->direction == SPA_DIRECTION_OUTPUT, FALSE); - PINOS_ARRAY_FOREACH (bid, &priv->buffer_ids) { + pinos_array_for_each (bid, &priv->buffer_ids) { if (!bid->used) return bid->id; } diff --git a/pinos/server/client-node.c b/pinos/server/client-node.c index 0e30f32d3..309e5ac07 100644 --- a/pinos/server/client-node.c +++ b/pinos/server/client-node.c @@ -40,7 +40,6 @@ #include "pinos/server/client-node.h" #include "spa/include/spa/node.h" -#include "spa/include/spa/queue.h" #include "spa/lib/memfd-wrappers.h" #define MAX_INPUTS 64 @@ -87,8 +86,6 @@ typedef struct { uint32_t buffer_mem_id; PinosMemblock buffer_mem; - - SpaQueue ready; } SpaProxyPort; struct _SpaProxy @@ -169,7 +166,6 @@ clear_buffers (SpaProxy *this, SpaProxyPort *port) pinos_memblock_free (&port->buffer_mem); port->n_buffers = 0; - SPA_QUEUE_INIT (&port->ready); } return SPA_RESULT_OK; } diff --git a/pinos/server/client.c b/pinos/server/client.c index f3059d67f..a0c1fa4d3 100644 --- a/pinos/server/client.c +++ b/pinos/server/client.c @@ -211,7 +211,6 @@ pinos_client_dispose (GObject * object) g_list_free_full (copy, g_object_unref); g_list_free (priv->objects); - pinos_registry_remove_object (&priv->daemon->registry, &client->object); client_unregister_object (client); G_OBJECT_CLASS (pinos_client_parent_class)->dispose (object); @@ -224,6 +223,9 @@ pinos_client_finalize (GObject * object) PinosClientPrivate *priv = client->priv; pinos_log_debug ("client %p: finalize", client); + + pinos_registry_remove_object (&priv->daemon->registry, &client->object); + g_clear_object (&priv->daemon); g_clear_object (&priv->iface); g_free (priv->sender); diff --git a/pinos/server/daemon.c b/pinos/server/daemon.c index 282148142..cbeb4106b 100644 --- a/pinos/server/daemon.c +++ b/pinos/server/daemon.c @@ -735,8 +735,8 @@ pinos_daemon_get_property (GObject *_object, GValue *value, GParamSpec *pspec) { - PinosDaemon *daemon = PINOS_DAEMON (_object); - PinosDaemonPrivate *priv = daemon->priv; + PinosDaemon *this = PINOS_DAEMON (_object); + PinosDaemonPrivate *priv = this->priv; switch (prop_id) { case PROP_PROPERTIES: @@ -752,7 +752,7 @@ pinos_daemon_get_property (GObject *_object, break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (daemon, prop_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec); break; } } @@ -763,8 +763,8 @@ pinos_daemon_set_property (GObject *_object, const GValue *value, GParamSpec *pspec) { - PinosDaemon *daemon = PINOS_DAEMON (_object); - PinosDaemonPrivate *priv = daemon->priv; + PinosDaemon *this = PINOS_DAEMON (_object); + PinosDaemonPrivate *priv = this->priv; switch (prop_id) { case PROP_PROPERTIES: @@ -774,7 +774,7 @@ pinos_daemon_set_property (GObject *_object, break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (daemon, prop_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID (this, prop_id, pspec); break; } } @@ -811,7 +811,6 @@ pinos_daemon_dispose (GObject * object) pinos_daemon_stop (this); - pinos_registry_remove_object (&this->registry, &this->object); G_OBJECT_CLASS (pinos_daemon_parent_class)->dispose (object); } @@ -819,10 +818,13 @@ pinos_daemon_dispose (GObject * object) static void pinos_daemon_finalize (GObject * object) { - PinosDaemon *daemon = PINOS_DAEMON_CAST (object); - PinosDaemonPrivate *priv = daemon->priv; + PinosDaemon *this = PINOS_DAEMON_CAST (object); + PinosDaemonPrivate *priv = this->priv; pinos_log_debug ("daemon %p: finalize", object); + + pinos_registry_remove_object (&this->registry, &this->object); + g_clear_object (&priv->server_manager); g_clear_object (&priv->iface); g_clear_object (&priv->data_loop); @@ -888,11 +890,12 @@ pinos_daemon_init (PinosDaemon * daemon) g_signal_connect (priv->iface, "handle-create-node", (GCallback) handle_create_node, daemon); g_signal_connect (priv->iface, "handle-create-client-node", (GCallback) handle_create_client_node, daemon); - priv->object_added.notify = on_registry_object_added; - priv->object_removed.notify = on_registry_object_removed; - pinos_registry_init (&daemon->registry); + + priv->object_added.notify = on_registry_object_added; pinos_signal_add (&daemon->registry.object_added, &priv->object_added); + + priv->object_removed.notify = on_registry_object_removed; pinos_signal_add (&daemon->registry.object_removed, &priv->object_removed); priv->server_manager = g_dbus_object_manager_server_new (PINOS_DBUS_OBJECT_PREFIX); diff --git a/pinos/server/link.c b/pinos/server/link.c index 2c6e20b56..08c4e609b 100644 --- a/pinos/server/link.c +++ b/pinos/server/link.c @@ -882,8 +882,6 @@ pinos_link_dispose (GObject * object) if (this->output) pinos_port_unlink (this->output, this); - pinos_registry_remove_object (&priv->daemon->registry, &this->object); - link_unregister_object (this); pinos_main_loop_defer_cancel (priv->main_loop, this, 0); @@ -898,6 +896,9 @@ pinos_link_finalize (GObject * object) PinosLinkPrivate *priv = this->priv; pinos_log_debug ("link %p: finalize", this); + + pinos_registry_remove_object (&priv->daemon->registry, &this->object); + g_clear_object (&priv->daemon); g_clear_object (&priv->iface); g_free (priv->object_path); diff --git a/pinos/server/main-loop.c b/pinos/server/main-loop.c index df2a24df8..f98669245 100644 --- a/pinos/server/main-loop.c +++ b/pinos/server/main-loop.c @@ -25,7 +25,7 @@ #include -#include "spa/include/spa/queue.h" +#include "spa/include/spa/list.h" #include "spa/include/spa/ringbuffer.h" #include "pinos/client/log.h" #include "pinos/server/main-loop.h" @@ -54,7 +54,7 @@ struct _WorkItem { PinosDeferFunc func; gpointer *data; GDestroyNotify notify; - WorkItem *next; + SpaList list; }; struct _PinosMainLoopPrivate @@ -70,7 +70,7 @@ struct _PinosMainLoopPrivate SpaPollFd fds[1]; SpaPollItem wakeup; - SpaQueue work; + SpaList work; WorkItem *free_list; gulong work_id; @@ -315,7 +315,7 @@ pinos_main_loop_finalize (GObject * obj) pinos_log_debug ("main-loop %p: finalize", this); - g_slice_free_chain (WorkItem, priv->free_list, next); + g_slice_free_chain (WorkItem, priv->free_list, list.next); G_OBJECT_CLASS (pinos_main_loop_parent_class)->finalize (obj); } @@ -359,7 +359,7 @@ pinos_main_loop_init (PinosMainLoop * this) this->poll.remove_item = do_remove_item; this->poll.invoke = do_invoke; - SPA_QUEUE_INIT (&priv->work); + spa_list_init (&priv->work); spa_ringbuffer_init (&priv->buffer, DATAS_SIZE); } @@ -383,22 +383,15 @@ static gboolean process_work_queue (PinosMainLoop *this) { PinosMainLoopPrivate *priv = this->priv; - WorkItem *prev, *item, *next; + WorkItem *item, *tmp; priv->work_id = 0; - for (item = priv->work.head, prev = NULL; item; prev = item, item = next) { - next = item->next; - + spa_list_for_each_safe (item, tmp, &priv->work, list) { if (item->seq != SPA_ID_INVALID) continue; - if (priv->work.tail == item) - priv->work.tail = prev; - if (prev == NULL) - priv->work.head = next; - else - prev->next = next; + spa_list_remove (&item->list); if (item->func) { pinos_log_debug ("main-loop %p: process work item %p", this, item->obj); @@ -407,10 +400,8 @@ process_work_queue (PinosMainLoop *this) if (item->notify) item->notify (item->data); - item->next = priv->free_list; + item->list.next = &priv->free_list->list; priv->free_list = item; - - item = prev; } return FALSE; } @@ -432,7 +423,7 @@ pinos_main_loop_defer (PinosMainLoop *loop, if (priv->free_list) { item = priv->free_list; - priv->free_list = item->next; + priv->free_list = SPA_CONTAINER_OF (item->list.next, WorkItem, list); } else { item = g_slice_new (WorkItem); } @@ -441,7 +432,6 @@ pinos_main_loop_defer (PinosMainLoop *loop, item->func = func; item->data = data; item->notify = notify; - item->next = NULL; if (SPA_RESULT_IS_ASYNC (res)) { item->seq = SPA_RESULT_ASYNC_SEQ (res); @@ -453,7 +443,7 @@ pinos_main_loop_defer (PinosMainLoop *loop, have_work = TRUE; pinos_log_debug ("main-loop %p: defer object %p", loop, obj); } - SPA_QUEUE_PUSH_TAIL (&priv->work, WorkItem, next, item); + spa_list_insert (priv->work.prev, &item->list); if (priv->work_id == 0 && have_work) priv->work_id = g_idle_add ((GSourceFunc) process_work_queue, loop); @@ -473,7 +463,7 @@ pinos_main_loop_defer_cancel (PinosMainLoop *loop, g_return_if_fail (PINOS_IS_MAIN_LOOP (loop)); priv = loop->priv; - for (item = priv->work.head; item; item = item->next) { + spa_list_for_each (item, &priv->work, list) { if ((id == 0 || item->id == id) && (obj == NULL || item->obj == obj)) { pinos_log_debug ("main-loop %p: cancel defer %d for object %p", loop, item->seq, item->obj); item->seq = SPA_ID_INVALID; @@ -498,7 +488,7 @@ pinos_main_loop_defer_complete (PinosMainLoop *loop, g_return_val_if_fail (PINOS_IS_MAIN_LOOP (loop), FALSE); priv = loop->priv; - for (item = priv->work.head; item; item = item->next) { + spa_list_for_each (item, &priv->work, list) { if (item->obj == obj && item->seq == seq) { pinos_log_debug ("main-loop %p: found defered %d for object %p", loop, seq, obj); item->seq = SPA_ID_INVALID; diff --git a/pinos/server/node.c b/pinos/server/node.c index 6cdf4a59f..c7d22b2a1 100644 --- a/pinos/server/node.c +++ b/pinos/server/node.c @@ -708,7 +708,6 @@ pinos_node_dispose (GObject * obj) pinos_log_debug ("node %p: dispose", node); pinos_node_set_state (node, PINOS_NODE_STATE_SUSPENDED); - pinos_registry_remove_object (&priv->daemon->registry, &node->object); node_unregister_object (node); pinos_main_loop_defer_cancel (priv->main_loop, node, 0); @@ -723,6 +722,9 @@ pinos_node_finalize (GObject * obj) PinosNodePrivate *priv = node->priv; pinos_log_debug ("node %p: finalize", node); + + pinos_registry_remove_object (&priv->daemon->registry, &node->object); + g_clear_object (&priv->daemon); g_clear_object (&priv->iface); g_clear_object (&priv->data_loop); diff --git a/pinos/client/list.h b/spa/include/spa/list.h similarity index 53% rename from pinos/client/list.h rename to spa/include/spa/list.h index 80bf71ce3..b2fdc5526 100644 --- a/pinos/client/list.h +++ b/spa/include/spa/list.h @@ -17,32 +17,32 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PINOS_LIST_H__ -#define __PINOS_LIST_H__ +#ifndef __SPA_LIST_H__ +#define __SPA_LIST_H__ #ifdef __cplusplus extern "C" { #endif -typedef struct _PinosList PinosList; +typedef struct _SpaList SpaList; #include -struct _PinosList { - PinosList *next; - PinosList *prev; +struct _SpaList { + SpaList *next; + SpaList *prev; }; static inline void -pinos_list_init (PinosList *list) +spa_list_init (SpaList *list) { list->next = list; list->prev = list; } static inline void -pinos_list_insert (PinosList *list, - PinosList *elem) +spa_list_insert (SpaList *list, + SpaList *elem) { elem->prev = list; elem->next = list->next; @@ -51,33 +51,35 @@ pinos_list_insert (PinosList *list, } static inline void -pinos_list_remove (PinosList *elem) +spa_list_remove (SpaList *elem) { elem->prev->next = elem->next; elem->next->prev = elem->prev; - elem->next = NULL; - elem->prev = NULL; } -#define PINOS_CONTAINER_OF(ptr, sample, member) \ - (__typeof__(sample))((char *)(ptr) - \ - offsetof(__typeof__(*sample), member)) +#define spa_list_is_empty(l) ((l)->next == (l)) -#define PINOS_LIST_FOREACH(pos, head, member) \ - for (pos = PINOS_CONTAINER_OF((head)->next, pos, member); \ - &pos->member != (head); \ - pos = PINOS_CONTAINER_OF(pos->member.next, pos, member)) +#define spa_list_first(head, type, member) \ + SPA_CONTAINER_OF((head)->next, type, member) -#define PINOS_LIST_FOREACH_SAFE(pos, tmp, head, member) \ - for (pos = PINOS_CONTAINER_OF((head)->next, pos, member), \ - tmp = PINOS_CONTAINER_OF((pos)->member.next, tmp, member); \ - &pos->member != (head); \ - pos = tmp, \ - tmp = PINOS_CONTAINER_OF(pos->member.next, tmp, member)) +#define spa_list_last(item, type, member) \ + SPA_CONTAINER_OF((head)->prev, type, member) + +#define spa_list_for_each(pos, head, member) \ + for (pos = SPA_CONTAINER_OF((head)->next, __typeof__(*pos), member); \ + &pos->member != (head); \ + pos = SPA_CONTAINER_OF(pos->member.next, __typeof__(*pos), member)) + +#define spa_list_for_each_safe(pos, tmp, head, member) \ + for (pos = SPA_CONTAINER_OF((head)->next, __typeof__(*pos), member), \ + tmp = SPA_CONTAINER_OF((pos)->member.next, __typeof__(*tmp), member); \ + &pos->member != (head); \ + pos = tmp, \ + tmp = SPA_CONTAINER_OF(pos->member.next, __typeof__(*tmp), member)) #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* __PINOS_LIST_H__ */ +#endif /* __SPA_LIST_H__ */ diff --git a/spa/include/spa/queue.h b/spa/include/spa/queue.h deleted file mode 100644 index ca504160d..000000000 --- a/spa/include/spa/queue.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Simple Plugin API - * Copyright (C) 2016 Wim Taymans - * - * 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 __SPA_QUEUE_H__ -#define __SPA_QUEUE_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _SpaQueue SpaQueue; - -#define SPA_QUEUE_URI "http://spaplug.in/ns/queue" -#define SPA_QUEUE_PREFIX SPA_QUEUE_URI "#" - -#include - -struct _SpaQueue { - void *head, *tail; - unsigned int length; -}; - -#define SPA_QUEUE_INIT(q) \ - do { \ - (q)->head = (q)->tail = NULL; \ - (q)->length = 0; \ - } while (0); - -#define SPA_QUEUE_PUSH_TAIL(q,t,next,i) \ - do { \ - if ((q)->tail) \ - ((t*)(q)->tail)->next = (i); \ - (q)->tail = (i); \ - if ((q)->head == NULL) \ - (q)->head = (i); \ - (q)->length++; \ - } while (0); - -#define SPA_QUEUE_PEEK_HEAD(q,t,i) \ - ((i) = (t*)((q)->head)); - -#define SPA_QUEUE_POP_HEAD(q,t,next,i) \ - do { \ - if (((i) = (t*)((q)->head)) == NULL) \ - break; \ - (q)->head = (i)->next; \ - if ((q)->head == NULL) \ - (q)->tail = NULL; \ - (q)->length--; \ - } while (0); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __SPA_QUEUE_H__ */ diff --git a/spa/lib/mapper.c b/spa/lib/mapper.c index f7d286927..cac4f17e0 100644 --- a/spa/lib/mapper.c +++ b/spa/lib/mapper.c @@ -23,19 +23,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index d97b3adff..85471228b 100644 --- a/spa/plugins/alsa/alsa-sink.c +++ b/spa/plugins/alsa/alsa-sink.c @@ -33,7 +33,7 @@ typedef struct _SpaALSAState SpaALSASink; static const char default_device[] = "default"; static const uint32_t default_buffer_time = 4000; -static const uint32_t default_period_time = 1000; +static const uint32_t default_period_time = 500; static const bool default_period_event = 0; static void @@ -366,7 +366,7 @@ static SpaResult spa_alsa_clear_buffers (SpaALSASink *this) { if (this->n_buffers > 0) { - SPA_QUEUE_INIT (&this->ready); + spa_list_init (&this->ready); this->n_buffers = 0; this->ringbuffer = NULL; } @@ -698,8 +698,7 @@ spa_alsa_sink_node_process_input (SpaNode *node) this->ringbuffer->outstanding = true; this->ringbuffer = b; } else { - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->ready, SpaALSABuffer, next, b); + spa_list_insert (this->ready.prev, &b->list); } b->outstanding = false; input->status = SPA_RESULT_OK; @@ -808,6 +807,8 @@ alsa_sink_init (const SpaHandleFactory *factory, this->stream = SND_PCM_STREAM_PLAYBACK; reset_alsa_sink_props (&this->props[1]); + spa_list_init (&this->ready); + for (i = 0; info && i < info->n_items; i++) { if (!strcmp (info->items[i].key, "alsa.card")) { snprintf (this->props[1].device, 63, "hw:%s", info->items[i].value); diff --git a/spa/plugins/alsa/alsa-source.c b/spa/plugins/alsa/alsa-source.c index 8be486f7d..3886058e4 100644 --- a/spa/plugins/alsa/alsa-source.c +++ b/spa/plugins/alsa/alsa-source.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -408,16 +408,15 @@ recycle_buffer (SpaALSASource *this, uint32_t buffer_id) return; b->outstanding = false; - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->free, SpaALSABuffer, next, b); + spa_list_insert (this->free.prev, &b->list); } static SpaResult spa_alsa_clear_buffers (SpaALSASource *this) { if (this->n_buffers > 0) { - SPA_QUEUE_INIT (&this->free); - SPA_QUEUE_INIT (&this->ready); + spa_list_init (&this->free); + spa_list_init (&this->ready); this->n_buffers = 0; } return SPA_RESULT_OK; @@ -591,8 +590,7 @@ spa_alsa_source_node_port_use_buffers (SpaNode *node, default: break; } - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->free, SpaALSABuffer, next, b); + spa_list_insert (this->free.prev, &b->list); } this->n_buffers = n_buffers; @@ -749,11 +747,12 @@ spa_alsa_source_node_process_output (SpaNode *node) return SPA_RESULT_ERROR; } - SPA_QUEUE_POP_HEAD (&this->ready, SpaALSABuffer, next, b); - if (b == NULL) { + if (spa_list_is_empty (&this->ready)) { output->status = SPA_RESULT_UNEXPECTED; return SPA_RESULT_ERROR; } + b = spa_list_first (&this->ready, SpaALSABuffer, list); + spa_list_remove (&b->list); b->outstanding = true; output->buffer_id = b->outbuf->id; diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index d929aa9e2..4071c9a1c 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -280,13 +280,12 @@ pull_frames_queue (SpaALSAState *state, snd_pcm_uframes_t offset, snd_pcm_uframes_t frames) { - SpaALSABuffer *b; - - SPA_QUEUE_PEEK_HEAD (&state->ready, SpaALSABuffer, b); - - if (b) { + if (!spa_list_is_empty (&state->ready)) { uint8_t *src, *dst; size_t n_bytes; + SpaALSABuffer *b; + + b = spa_list_first (&state->ready, SpaALSABuffer, list); src = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset + state->ready_offset, uint8_t); dst = SPA_MEMBER (my_areas[0].addr, offset * state->frame_size, uint8_t); @@ -299,7 +298,7 @@ pull_frames_queue (SpaALSAState *state, if (state->ready_offset >= b->outbuf->datas[0].size) { SpaNodeEventReuseBuffer rb; - SPA_QUEUE_POP_HEAD (&state->ready, SpaALSABuffer, next, b); + spa_list_remove (&b->list); b->outstanding = true; rb.event.type = SPA_NODE_EVENT_TYPE_REUSE_BUFFER; @@ -448,10 +447,13 @@ mmap_read (SpaALSAState *state) state->last_ticks = state->sample_count * SPA_USEC_PER_SEC / state->rate; state->last_monotonic = now; - SPA_QUEUE_POP_HEAD (&state->free, SpaALSABuffer, next, b); - if (b == NULL) { + if (spa_list_is_empty (&state->free)) { + b = NULL; spa_log_warn (state->log, "no more buffers"); } else { + b = spa_list_first (&state->free, SpaALSABuffer, list); + spa_list_remove (&b->list); + dest = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void); destsize = b->outbuf->datas[0].size; @@ -496,8 +498,7 @@ mmap_read (SpaALSAState *state) d = b->outbuf->datas; d[0].size = avail * state->frame_size; - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&state->ready, SpaALSABuffer, next, b); + spa_list_insert (state->ready.prev, &b->list); ho.event.type = SPA_NODE_EVENT_TYPE_HAVE_OUTPUT; ho.event.size = sizeof (ho); diff --git a/spa/plugins/alsa/alsa-utils.h b/spa/plugins/alsa/alsa-utils.h index bf2977f1e..b6f7fdf1a 100644 --- a/spa/plugins/alsa/alsa-utils.h +++ b/spa/plugins/alsa/alsa-utils.h @@ -30,7 +30,7 @@ extern "C" { #include #include -#include +#include #include #include #include @@ -55,7 +55,7 @@ struct _SpaALSABuffer { SpaMetaHeader *h; SpaMetaRingbuffer *rb; bool outstanding; - SpaALSABuffer *next; + SpaList list; }; typedef struct { @@ -109,8 +109,8 @@ struct _SpaALSAState { bool use_ringbuffer; SpaALSABuffer *ringbuffer; - SpaQueue free; - SpaQueue ready; + SpaList free; + SpaList ready; size_t ready_offset; bool started; diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index a17d58d53..774cec2c3 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -52,10 +52,10 @@ typedef struct _ATSBuffer ATSBuffer; struct _ATSBuffer { SpaBuffer *outbuf; bool outstanding; - ATSBuffer *next; SpaMetaHeader *h; void *ptr; size_t size; + SpaList list; }; typedef struct { @@ -102,8 +102,8 @@ struct _SpaAudioTestSrc { uint64_t elapsed_time; uint64_t sample_count; - SpaQueue empty; - SpaQueue ready; + SpaList empty; + SpaList ready; }; #define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0) @@ -266,12 +266,13 @@ audiotestsrc_on_output (SpaPollNotifyData *data) SpaAudioTestSrc *this = data->user_data; ATSBuffer *b; - SPA_QUEUE_POP_HEAD (&this->empty, ATSBuffer, next, b); - if (b == NULL) { + if (spa_list_is_empty (&this->empty)) { if (!this->props[1].live) update_poll_enabled (this, false); return 0; } + b = spa_list_first (&this->empty, ATSBuffer, list); + spa_list_remove (&b->list); fill_buffer (this, b); @@ -296,8 +297,7 @@ audiotestsrc_on_output (SpaPollNotifyData *data) timerfd_settime (this->fds[0].fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL); } - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->ready, ATSBuffer, next, b); + spa_list_insert (this->ready.prev, &b->list); send_have_output (this); return 0; @@ -530,8 +530,8 @@ clear_buffers (SpaAudioTestSrc *this) if (this->n_buffers > 0) { spa_log_info (this->log, "audiotestsrc %p: clear buffers", this); this->n_buffers = 0; - SPA_QUEUE_INIT (&this->empty); - SPA_QUEUE_INIT (&this->ready); + spa_list_init (&this->empty); + spa_list_init (&this->ready); } return SPA_RESULT_OK; } @@ -701,8 +701,7 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node, default: break; } - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->empty, ATSBuffer, next, b); + spa_list_insert (this->empty.prev, &b->list); } this->n_buffers = n_buffers; @@ -799,10 +798,9 @@ spa_audiotestsrc_node_port_reuse_buffer (SpaNode *node, return SPA_RESULT_OK; b->outstanding = false; - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->empty, ATSBuffer, next, b); + spa_list_insert (this->empty.prev, &b->list); - if (this->empty.length == 1 && !this->props[1].live) + if (!this->props[1].live) update_poll_enabled (this, true); return SPA_RESULT_OK; @@ -837,11 +835,12 @@ spa_audiotestsrc_node_process_output (SpaNode *node) if ((output = this->output) == NULL) return SPA_RESULT_OK; - SPA_QUEUE_POP_HEAD (&this->ready, ATSBuffer, next, b); - if (b == NULL) { + if (spa_list_is_empty (&this->ready)) { output->status = SPA_RESULT_UNEXPECTED; return SPA_RESULT_ERROR; } + b = spa_list_first (&this->ready, ATSBuffer, list); + spa_list_remove (&b->list); b->outstanding = true; output->buffer_id = b->outbuf->id; @@ -1007,8 +1006,8 @@ audiotestsrc_init (const SpaHandleFactory *factory, this->props[1].props.prop_info = prop_info; reset_audiotestsrc_props (&this->props[1]); - SPA_QUEUE_INIT (&this->empty); - SPA_QUEUE_INIT (&this->ready); + spa_list_init (&this->empty); + spa_list_init (&this->ready); this->fds[0].fd = timerfd_create (CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); this->fds[0].events = POLLIN | POLLPRI | POLLERR; diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index 30e761cbe..f9b9e7c0d 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -60,7 +60,8 @@ struct _V4l2Buffer { bool outstanding; bool allocated; struct v4l2_buffer v4l2_buffer; - V4l2Buffer *next; +// V4l2Buffer *next; + SpaList list; }; typedef struct _V4l2Format V4l2Format; @@ -112,7 +113,7 @@ typedef struct { V4l2Buffer buffers[MAX_BUFFERS]; unsigned int n_buffers; - SpaQueue ready; + SpaList ready; SpaPollFd fds[1]; SpaPollItem poll; @@ -854,11 +855,17 @@ spa_v4l2_source_node_process_output (SpaNode *node) return SPA_RESULT_ERROR; } - SPA_QUEUE_POP_HEAD (&state->ready, V4l2Buffer, next, b); + if (spa_list_is_empty (&state->ready)) { + output->status = SPA_RESULT_UNEXPECTED; + return SPA_RESULT_ERROR; + } + + b = spa_list_first (&state->ready, V4l2Buffer, list); if (b == NULL) { output->status = SPA_RESULT_UNEXPECTED; return SPA_RESULT_ERROR; } + spa_list_remove (&b->list); b->outstanding = true; output->buffer_id = b->outbuf->id; @@ -1021,7 +1028,8 @@ v4l2_source_init (const SpaHandleFactory *factory, this->props[1].props.prop_info = prop_info; reset_v4l2_source_props (&this->props[1]); - SPA_QUEUE_INIT (&this->state[0].ready); + spa_list_init (&this->state[0].ready); +// SPA_QUEUE_INIT (&this->state[0].ready); this->state[0].log = this->log; this->state[0].info.flags = SPA_PORT_INFO_FLAG_LIVE; diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index a5a4d41e7..9fbf02449 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -885,8 +885,7 @@ mmap_read (SpaV4l2Source *this) d = b->outbuf->datas; d[0].size = buf.bytesused; - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&state->ready, V4l2Buffer, next, b); + spa_list_insert (state->ready.prev, &b->list); return SPA_RESULT_OK; } diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index fbc71ba82..a29349bd8 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -60,10 +60,10 @@ typedef struct _VTSBuffer VTSBuffer; struct _VTSBuffer { SpaBuffer *outbuf; bool outstanding; - VTSBuffer *next; SpaMetaHeader *h; void *ptr; size_t stride; + SpaList list; }; struct _SpaVideoTestSrc { @@ -104,8 +104,8 @@ struct _SpaVideoTestSrc { uint64_t elapsed_time; uint64_t frame_count; - SpaQueue empty; - SpaQueue ready; + SpaList empty; + SpaList ready; }; #define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0) @@ -213,12 +213,13 @@ videotestsrc_on_output (SpaPollNotifyData *data) SpaVideoTestSrc *this = data->user_data; VTSBuffer *b; - SPA_QUEUE_POP_HEAD (&this->empty, VTSBuffer, next, b); - if (b == NULL) { + if (spa_list_is_empty (&this->empty)) { if (!this->props[1].live) update_poll_enabled (this, false); return 0; } + b = spa_list_first (&this->empty, VTSBuffer, list); + spa_list_remove (&b->list); fill_buffer (this, b); @@ -243,8 +244,7 @@ videotestsrc_on_output (SpaPollNotifyData *data) timerfd_settime (this->fds[0].fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL); } - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->ready, VTSBuffer, next, b); + spa_list_insert (this->ready.prev, &b->list); send_have_output (this); return 0; @@ -477,8 +477,8 @@ clear_buffers (SpaVideoTestSrc *this) if (this->n_buffers > 0) { spa_log_info (this->log, "videotestsrc %p: clear buffers", this); this->n_buffers = 0; - SPA_QUEUE_INIT (&this->empty); - SPA_QUEUE_INIT (&this->ready); + spa_list_init (&this->empty); + spa_list_init (&this->ready); } return SPA_RESULT_OK; } @@ -649,8 +649,7 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node, default: break; } - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->empty, VTSBuffer, next, b); + spa_list_insert (this->empty.prev, &b->list); } this->n_buffers = n_buffers; @@ -746,10 +745,9 @@ spa_videotestsrc_node_port_reuse_buffer (SpaNode *node, return SPA_RESULT_OK; b->outstanding = false; - b->next = NULL; - SPA_QUEUE_PUSH_TAIL (&this->empty, VTSBuffer, next, b); + spa_list_insert (this->empty.prev, &b->list); - if (this->empty.length == 1 && !this->props[1].live) + if (!this->props[1].live) update_poll_enabled (this, true); return SPA_RESULT_OK; @@ -790,11 +788,11 @@ spa_videotestsrc_node_process_output (SpaNode *node) return SPA_RESULT_ERROR; } - SPA_QUEUE_POP_HEAD (&this->ready, VTSBuffer, next, b); - if (b == NULL) { + if (spa_list_is_empty (&this->ready)) { output->status = SPA_RESULT_UNEXPECTED; return SPA_RESULT_ERROR; } + b = spa_list_first (&this->ready, VTSBuffer, list); b->outstanding = true; output->buffer_id = b->outbuf->id; @@ -956,8 +954,8 @@ videotestsrc_init (const SpaHandleFactory *factory, this->props[1].props.prop_info = prop_info; reset_videotestsrc_props (&this->props[1]); - SPA_QUEUE_INIT (&this->empty); - SPA_QUEUE_INIT (&this->ready); + spa_list_init (&this->empty); + spa_list_init (&this->ready); this->fds[0].fd = timerfd_create (CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); this->fds[0].events = POLLIN | POLLPRI | POLLERR;