diff --git a/pinos/client/ringbuffer.c b/pinos/client/ringbuffer.c index 644b9db11..906a7528f 100644 --- a/pinos/client/ringbuffer.c +++ b/pinos/client/ringbuffer.c @@ -31,7 +31,6 @@ #include #include -#include #define PINOS_RINGBUFFER_GET_PRIVATE(rb) \ (G_TYPE_INSTANCE_GET_PRIVATE ((rb), PINOS_TYPE_RINGBUFFER, PinosRingbufferPrivate)) diff --git a/spa/include/spa/node-command.h b/spa/include/spa/node-command.h index 1e0139ff5..c9e728e66 100644 --- a/spa/include/spa/node-command.h +++ b/spa/include/spa/node-command.h @@ -50,9 +50,9 @@ typedef enum { } SpaNodeCommandType; struct _SpaNodeCommand { - SpaNodeCommandType type; - void *data; - size_t size; + SpaNodeCommandType type; + void *data; + size_t size; }; /** diff --git a/spa/include/spa/node.h b/spa/include/spa/node.h index c4d943527..72418bb81 100644 --- a/spa/include/spa/node.h +++ b/spa/include/spa/node.h @@ -532,9 +532,9 @@ struct _SpaNode { * Returns: #SPA_RESULT_OK on success * #SPA_RESULT_INVALID_ARGUMENTS when node is %NULL */ - SpaResult (*port_reuse_buffer) (SpaNode *node, - uint32_t port_id, - uint32_t buffer_id); + SpaResult (*port_reuse_buffer) (SpaNode *node, + uint32_t port_id, + uint32_t buffer_id); SpaResult (*port_push_event) (SpaNode *node, SpaDirection direction, diff --git a/spa/include/spa/port.h b/spa/include/spa/port.h index a94ee4a2a..c6f896a1f 100644 --- a/spa/include/spa/port.h +++ b/spa/include/spa/port.h @@ -132,13 +132,17 @@ SpaPortInfo * spa_port_info_copy_into (void *dest, const SpaPortInfo *info); /** * SpaPortStatusFlags: * @SPA_PORT_STATUS_FLAG_NONE: no status flags + * @SPA_PORT_STATUS_FLAG_HAVE_FORMAT: port has a format + * @SPA_PORT_STATUS_FLAG_HAVE_BUFFERS: port has buffers * @SPA_PORT_STATUS_FLAG_HAVE_OUTPUT: port has output * @SPA_PORT_STATUS_FLAG_NEED_INPUT: port needs input */ typedef enum { SPA_PORT_STATUS_FLAG_NONE = 0, - SPA_PORT_STATUS_FLAG_HAVE_OUTPUT = 1 << 0, - SPA_PORT_STATUS_FLAG_NEED_INPUT = 1 << 1, + SPA_PORT_STATUS_FLAG_HAVE_FORMAT = 1 << 0, + SPA_PORT_STATUS_FLAG_HAVE_BUFFERS = 1 << 1, + SPA_PORT_STATUS_FLAG_HAVE_OUTPUT = 1 << 2, + SPA_PORT_STATUS_FLAG_NEED_INPUT = 1 << 3, } SpaPortStatusFlags; /** diff --git a/spa/include/spa/ringbuffer.h b/spa/include/spa/ringbuffer.h index 9900696c9..14555edfd 100644 --- a/spa/include/spa/ringbuffer.h +++ b/spa/include/spa/ringbuffer.h @@ -50,20 +50,190 @@ struct _SpaRingbuffer { size_t size_mask; }; -SpaResult spa_ringbuffer_init (SpaRingbuffer *rbuf, - size_t size); +/** + * spa_ringbuffer_init: + * @rbuf: a #SpaRingbuffer + * @data: pointer to an array + * @size: the number of elements in @data + * + * Initialize a #SpaRingbuffer with @data and @size. + * When size is a power of 2, size_mask will be set with the mask to + * efficiently wrap around the indexes. + */ +static inline void +spa_ringbuffer_init (SpaRingbuffer *rbuf, + size_t size) +{ + rbuf->size = size; + rbuf->readindex = 0; + rbuf->writeindex = 0; + if ((size & (size - 1)) == 0) + rbuf->size_mask = size - 1; + else + rbuf->size_mask = 0; +} -SpaResult spa_ringbuffer_clear (SpaRingbuffer *rbuf); +/** + * spa_ringbuffer_clear: + * @rbuf: a #SpaRingbuffer + * + * Clear @rbuf + */ +static inline void +spa_ringbuffer_clear (SpaRingbuffer *rbuf) +{ + rbuf->readindex = 0; + rbuf->writeindex = 0; +} -SpaResult spa_ringbuffer_get_read_areas (SpaRingbuffer *rbuf, - SpaRingbufferArea areas[2]); -SpaResult spa_ringbuffer_read_advance (SpaRingbuffer *rbuf, - ssize_t len); +/** + * spa_ringbuffer_get_read_areas: + * @rbuf: a #SpaRingbuffer + * @areas: an array of #SpaRingbufferArea + * + * Fill @areas with pointers to read from. The total amount of + * bytes that can be read can be obtained by summing the areas len fields. + */ +static inline void +spa_ringbuffer_get_read_areas (SpaRingbuffer *rbuf, + SpaRingbufferArea areas[2]) +{ + size_t avail, end, w, r; -SpaResult spa_ringbuffer_get_write_areas (SpaRingbuffer *rbuf, - SpaRingbufferArea areas[2]); -SpaResult spa_ringbuffer_write_advance (SpaRingbuffer *rbuf, - ssize_t len); + w = rbuf->writeindex; + r = rbuf->readindex; + + if (w > r) { + avail = w - r; + } else { + avail = (w - r + rbuf->size); + avail = (rbuf->size_mask ? avail & rbuf->size_mask : avail % rbuf->size); + } + end = r + avail; + + areas[0].offset = r; + areas[1].offset = 0; + + if (end > rbuf->size) { + areas[0].len = rbuf->size - r; + areas[1].len = end - rbuf->size; + } else { + areas[0].len = avail; + areas[1].len = 0; + } +} + +static inline size_t +spa_ringbuffer_get_read_offset (SpaRingbuffer *rbuf, + size_t *offset) +{ + size_t avail, w, r; + + w = rbuf->writeindex; + r = rbuf->readindex; + + if (w > r) { + avail = w - r; + } else { + avail = (w - r + rbuf->size); + avail = (rbuf->size_mask ? avail & rbuf->size_mask : avail % rbuf->size); + } + *offset = r; + return avail; +} + +/** + * spa_ringbuffer_read_advance: + * @rbuf: a #SpaRingbuffer + * @len: number of bytes to advance + * + * Advance the read pointer by @len + */ +static inline void +spa_ringbuffer_read_advance (SpaRingbuffer *rbuf, + ssize_t len) +{ + size_t tmp = rbuf->readindex + len; + rbuf->readindex = (rbuf->size_mask ? tmp & rbuf->size_mask : tmp % rbuf->size); +} + +/** + * spa_ringbuffer_get_write_areas: + * @rbuf: a #SpaRingbuffer + * @areas: an array of #SpaRingbufferArea + * + * Fill @areas with pointers to write to. The total amount of + * bytes that can be written can be obtained by summing the areas len fields. + */ +static inline void +spa_ringbuffer_get_write_areas (SpaRingbuffer *rbuf, + SpaRingbufferArea areas[2]) +{ + size_t avail, end, w, r; + + w = rbuf->writeindex; + r = rbuf->readindex; + + if (w > r) { + avail = (r - w + rbuf->size); + avail = (rbuf->size_mask ? avail & rbuf->size_mask : avail % rbuf->size); + } else if (w < r) { + avail = r - w; + } else { + avail = rbuf->size; + } + avail -= 1; + end = w + avail; + + areas[0].offset = w; + areas[1].offset = 0; + + if (end > rbuf->size) { + areas[0].len = rbuf->size - w; + areas[1].len = end - rbuf->size; + } else { + areas[0].len = avail; + areas[1].len = 0; + } +} + +static inline size_t +spa_ringbuffer_get_write_offset (SpaRingbuffer *rbuf, + size_t *offset) +{ + size_t avail, w, r; + + w = rbuf->writeindex; + r = rbuf->readindex; + + if (w > r) { + avail = (r - w + rbuf->size); + avail = (rbuf->size_mask ? avail & rbuf->size_mask : avail % rbuf->size); + } else if (w < r) { + avail = r - w; + } else { + avail = rbuf->size; + } + avail -= 1; + *offset = w; + return avail; +} + +/** + * spa_ringbuffer_write_advance: + * @rbuf: a #SpaRingbuffer + * @len: number of bytes to advance + * + * Advance the write pointer by @len + * + */ +static inline void +spa_ringbuffer_write_advance (SpaRingbuffer *rbuf, + ssize_t len) +{ + size_t tmp = rbuf->writeindex + len; + rbuf->writeindex = (rbuf->size_mask ? tmp & rbuf->size_mask : tmp % rbuf->size); +} #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/lib/meson.build b/spa/lib/meson.build index 32197f90d..7205ac954 100644 --- a/spa/lib/meson.build +++ b/spa/lib/meson.build @@ -6,7 +6,6 @@ spalib_sources = ['audio-raw.c', 'mapper.c', 'port.c', 'props.c', - 'ringbuffer.c', 'video-raw.c'] spalib = shared_library('spa-lib', diff --git a/spa/lib/ringbuffer.c b/spa/lib/ringbuffer.c deleted file mode 100644 index 548c9a34f..000000000 --- a/spa/lib/ringbuffer.c +++ /dev/null @@ -1,186 +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. - */ - -#include - -/** - * spa_ringbuffer_init: - * @rbuf: a #SpaRingbuffer - * @data: pointer to an array - * @size: the number of elements in @data - * - * Initialize a #SpaRingbuffer with @data and @size. - * When size is a power of 2, size_mask will be set with the mask to - * efficiently wrap around the indexes. - * - * Returns: #SPA_RESULT_OK on success - * #SPA_RESULT_INVALID_ARGUMENTS when data or rbuf is %NULL - */ -SpaResult -spa_ringbuffer_init (SpaRingbuffer *rbuf, - size_t size) -{ - if (rbuf == NULL || size == 0) - return SPA_RESULT_INVALID_ARGUMENTS; - - rbuf->size = size; - rbuf->readindex = 0; - rbuf->writeindex = 0; - if ((size & (size - 1)) == 0) - rbuf->size_mask = size - 1; - else - rbuf->size_mask = 0; - - return SPA_RESULT_OK; -} - -/** - * spa_ringbuffer_clear: - * @rbuf: a #SpaRingbuffer - * - * Clear @rbuf - * - * Returns: #SPA_RESULT_OK - */ -SpaResult -spa_ringbuffer_clear (SpaRingbuffer *rbuf) -{ - rbuf->readindex = 0; - rbuf->writeindex = 0; - return SPA_RESULT_OK; -} - -/** - * spa_ringbuffer_get_read_areas: - * @rbuf: a #SpaRingbuffer - * @areas: an array of #SpaRingbufferArea - * - * Fill @areas with pointers to read from. The total amount of - * bytes that can be read can be obtained by summing the areas len fields. - * - * Returns: #SPA_RESULT_OK - */ -SpaResult -spa_ringbuffer_get_read_areas (SpaRingbuffer *rbuf, - SpaRingbufferArea areas[2]) -{ - size_t avail, end, w, r; - - w = rbuf->writeindex; - r = rbuf->readindex; - - if (w > r) { - avail = w - r; - } else { - avail = (w - r + rbuf->size); - avail = (rbuf->size_mask ? avail & rbuf->size_mask : avail % rbuf->size); - } - end = r + avail; - - areas[0].offset = r; - areas[1].offset = 0; - - if (end > rbuf->size) { - areas[0].len = rbuf->size - r; - areas[1].len = end - rbuf->size; - } else { - areas[0].len = avail; - areas[1].len = 0; - } - return SPA_RESULT_OK; -} - -/** - * spa_ringbuffer_read_advance: - * @rbuf: a #SpaRingbuffer - * @len: number of bytes to advance - * - * Advance the read pointer by @len - * - * Returns: #SPA_RESULT_OK - */ -SpaResult -spa_ringbuffer_read_advance (SpaRingbuffer *rbuf, - ssize_t len) -{ - size_t tmp = rbuf->readindex + len; - rbuf->readindex = (rbuf->size_mask ? tmp & rbuf->size_mask : tmp % rbuf->size); - return SPA_RESULT_OK; -} - -/** - * spa_ringbuffer_get_write_areas: - * @rbuf: a #SpaRingbuffer - * @areas: an array of #SpaRingbufferArea - * - * Fill @areas with pointers to write to. The total amount of - * bytes that can be written can be obtained by summing the areas len fields. - * - * Returns: #SPA_RESULT_OK - */ -SpaResult -spa_ringbuffer_get_write_areas (SpaRingbuffer *rbuf, - SpaRingbufferArea areas[2]) -{ - size_t avail, end, w, r; - - w = rbuf->writeindex; - r = rbuf->readindex; - - if (w > r) { - avail = (r - w + rbuf->size); - avail = (rbuf->size_mask ? avail & rbuf->size_mask : avail % rbuf->size); - } else if (w < r) { - avail = r - w; - } else { - avail = rbuf->size; - } - avail -= 1; - end = w + avail; - - areas[0].offset = w; - areas[1].offset = 0; - - if (end > rbuf->size) { - areas[0].len = rbuf->size - w; - areas[1].len = end - rbuf->size; - } else { - areas[0].len = avail; - areas[1].len = 0; - } - return SPA_RESULT_OK; -} - -/** - * spa_ringbuffer_write_advance: - * @rbuf: a #SpaRingbuffer - * @len: number of bytes to advance - * - * Advance the write pointer by @len - * - * Returns: #SPA_RESULT_OK - */ -SpaResult -spa_ringbuffer_write_advance (SpaRingbuffer *rbuf, - ssize_t len) -{ - size_t tmp = rbuf->writeindex + len; - rbuf->writeindex = (rbuf->size_mask ? tmp & rbuf->size_mask : tmp % rbuf->size); - return SPA_RESULT_OK; -} diff --git a/spa/tools/spa-inspect.c b/spa/tools/spa-inspect.c index 5da43857a..86268a786 100644 --- a/spa/tools/spa-inspect.c +++ b/spa/tools/spa-inspect.c @@ -78,13 +78,16 @@ inspect_node (SpaNode *node) else spa_debug_props (props, true); - if ((res = spa_node_get_n_ports (node, &n_input, &max_input, &n_output, &max_output)) < 0) + if ((res = spa_node_get_n_ports (node, &n_input, &max_input, &n_output, &max_output)) < 0) { printf ("can't get n_ports: %d\n", res); - else - printf ("supported ports %d %d %d %d\n", n_input, max_input, n_output, max_output); + return; + } + printf ("supported ports:\n"); + printf ("input ports: %d/%d\n", n_input, max_input); + printf ("output ports: %d/%d\n", n_output, max_output); in_ports = alloca (n_input * sizeof (uint32_t)); - out_ports = alloca (n_input * sizeof (uint32_t)); + out_ports = alloca (n_output * sizeof (uint32_t)); if ((res = spa_node_get_port_ids (node, n_input, in_ports, n_output, out_ports)) < 0) printf ("can't get port ids: %d\n", res); @@ -93,6 +96,7 @@ inspect_node (SpaNode *node) printf (" input port: %08x\n", in_ports[i]); inspect_port (node, SPA_DIRECTION_INPUT, in_ports[i]); } + for (i = 0; i < n_output; i++) { printf (" output port: %08x\n", out_ports[i]); inspect_port (node, SPA_DIRECTION_OUTPUT, out_ports[i]);