node: Add id to set_io

Make it possible to configure multiple io areas on a port by giving
an id to set_io.
Add some types to enumerate the supported ids
Make an area to exchange buffers and one to specify pull ranges.
The idea is to make more area types for controlable properties.
Implement enumeration of IO areas in volume.
This commit is contained in:
Wim Taymans 2017-11-21 19:34:37 +01:00
parent 4288a634f4
commit 8efea3e1ea
40 changed files with 583 additions and 208 deletions

View file

@ -27,6 +27,7 @@ extern "C" {
#include <spa/utils/defs.h>
#include <spa/utils/list.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#ifndef spa_debug
#define spa_debug(...)
@ -74,7 +75,7 @@ struct spa_graph_port {
enum spa_direction direction; /**< port direction */
uint32_t port_id; /**< port id */
uint32_t flags; /**< port flags */
struct spa_port_io *io; /**< io area of the port */
struct spa_io_buffers *io; /**< io area of the port */
struct spa_graph_port *peer; /**< peer */
void *scheduler_data; /**< scheduler private data */
};
@ -127,7 +128,7 @@ spa_graph_port_init(struct spa_graph_port *port,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
struct spa_port_io *io)
struct spa_io_buffers *io)
{
spa_debug("port %p init type %d id %d", port, direction, port_id);
port->direction = direction;

View file

@ -31,6 +31,7 @@ spa_node_headers = [
'node/command.h',
'node/event.h',
'node/node.h',
'node/io.h',
]
install_headers(spa_node_headers,
@ -41,6 +42,7 @@ spa_param_headers = [
'param/props.h',
'param/buffers.h',
'param/meta.h',
'param/io.h',
'param/format.h',
'param/format-utils.h',
]

89
spa/include/spa/node/io.h Normal file
View file

@ -0,0 +1,89 @@
/* Simple Plugin API
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* 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_IO_H__
#define __SPA_IO_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/support/type-map.h>
/** Base for IO structures to interface with node ports */
#define SPA_TYPE__IO SPA_TYPE_POINTER_BASE "IO"
#define SPA_TYPE_IO_BASE SPA_TYPE__IO ":"
/** Base for control structures */
#define SPA_TYPE_IO__Control SPA_TYPE_IO_BASE "Control"
#define SPA_TYPE_IO_CONTROL_BASE SPA_TYPE_IO__Control ":"
/** Base for controlable properties */
#define SPA_TYPE_IO__Prop SPA_TYPE_IO_BASE "Prop"
#define SPA_TYPE_IO_PROP_BASE SPA_TYPE_IO__Prop ":"
/** An io area to exchange buffers with a port */
#define SPA_TYPE_IO__Buffers SPA_TYPE_IO_BASE "Buffers"
/** Buffers IO area
*
* IO information for a port on a node. This is allocated
* by the host and configured on all ports for which IO is requested.
*/
struct spa_io_buffers {
#define SPA_STATUS_OK 0
#define SPA_STATUS_NEED_BUFFER 1
#define SPA_STATUS_HAVE_BUFFER 2
#define SPA_STATUS_FORMAT_CHANGED 3
#define SPA_STATUS_PORTS_CHANGED 4
#define SPA_STATUS_PARAM_CHANGED 5
int32_t status; /**< the status code */
uint32_t buffer_id; /**< a buffer id */
};
#define SPA_IO_BUFFERS_INIT (struct spa_io_buffers) { SPA_STATUS_OK, SPA_ID_INVALID, }
/** Information about requested range */
#define SPA_TYPE_IO_CONTROL__Range SPA_TYPE_IO_CONTROL_BASE "Range"
/** A range, suitable for input ports that can suggest a range to output ports */
struct spa_io_control_range {
uint64_t offset; /**< offset in range */
uint32_t min_size; /**< minimum size of data */
uint32_t max_size; /**< maximum size of data */
};
struct spa_type_io {
uint32_t Buffers;
uint32_t ControlRange;
};
static inline void spa_type_io_map(struct spa_type_map *map, struct spa_type_io *type)
{
if (type->Buffers == 0) {
type->Buffers = spa_type_map_get_id(map, SPA_TYPE_IO__Buffers);
type->ControlRange = spa_type_map_get_id(map, SPA_TYPE_IO_CONTROL__Range);
}
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_IO_H__ */

View file

@ -38,32 +38,6 @@ struct spa_node;
#include <spa/node/event.h>
#include <spa/node/command.h>
/** A range */
struct spa_range {
uint64_t offset; /**< offset in range */
uint32_t min_size; /**< minimum size of data */
uint32_t max_size; /**< maximum size of data */
};
/** Port IO area
*
* IO information for a port on a node. This is allocated
* by the host and configured on all ports for which IO is requested.
*/
struct spa_port_io {
#define SPA_STATUS_OK 0
#define SPA_STATUS_NEED_BUFFER 1
#define SPA_STATUS_HAVE_BUFFER 2
#define SPA_STATUS_FORMAT_CHANGED 3
#define SPA_STATUS_PORTS_CHANGED 4
#define SPA_STATUS_PARAM_CHANGED 5
int32_t status; /**< the status code */
uint32_t buffer_id; /**< a buffer id */
struct spa_range range; /**< the requested range */
};
#define SPA_PORT_IO_INIT (struct spa_port_io) { SPA_STATUS_OK, SPA_ID_INVALID, }
/**
* Port information structure
*
@ -350,6 +324,7 @@ struct spa_node {
* \param node a #struct spa_node
* \param direction a #enum spa_direction
* \param port_id the port to configure
* \param id the parameter id to set
* \param flags optional flags
* \param param a #struct spa_pod with the parameter to set
* \return 0 on success
@ -372,16 +347,19 @@ struct spa_node {
/**
* Tell the port to use the given buffers
*
* The port should also have a spa_io_buffers io area configured to exchange
* the buffers with the port.
*
* For an input port, all the buffers will remain dequeued. Once a buffer
* has been pushed on a port with port_push_input, it should not be reused
* until the reuse_buffer event is notified or when the buffer has been
* returned in the spa_port_io of the port.
* returned in the spa_io_buffers of the port.
*
* For output ports, all buffers will be queued in the port. When process_input
* or process_output return SPA_STATUS_HAVE_BUFFER, buffers are available in
* one or more of the spa_port_io areas.
* one or more of the spa_io_buffers areas.
* When a buffer can be reused, port_reuse_buffer() should be called or the
* buffer_id should be placed in the spa_port_io area before calling
* buffer_id should be placed in the spa_io_buffers area before calling
* process_output.
*
* Passing NULL as \a buffers will remove the reference that the port has
@ -404,6 +382,9 @@ struct spa_node {
/**
* Tell the port to allocate memory for \a buffers.
*
* The port should also have a spa_io_buffers io area configured to exchange
* the buffers with the port.
*
* \a buffers should contain an array of pointers to buffers. The data
* in the buffers should point to an array of at least 1 data entry
* with a 0 type that will be filled by this function.
@ -439,23 +420,28 @@ struct spa_node {
uint32_t *n_buffers);
/**
* Configure the given io structure on \a port_id. This
* structure is allocated by the host and is used to query the state
* of the port and exchange buffers with the port.
* Configure the given memory area with \a id on \a port_id. This
* structure is allocated by the host and is used to exchange
* data and parameters with the port.
*
* Setting an \a io of NULL will disable the port.
* Setting an \a io of NULL will disable the port io.
*
* This function must be called from the main thread.
*
* \param direction a spa_direction
* \param port_id a port id
* \param io a spa_port_io
* \param id the id of the io area, the available ids can be
* enumerated with the port parameters.
* \param io a io area memory
* \return 0 on success
* -EINVAL when node is NULL the port is not valid
* -ENOENT when \id is unknown
*/
int (*port_set_io) (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_port_io *io);
uint32_t id,
void *io);
/**
* Tell an output port to reuse a buffer.

View file

@ -0,0 +1,61 @@
/* Simple Plugin API
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* 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_PARAM_IO_H__
#define __SPA_PARAM_IO_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/defs.h>
#include <spa/param/param.h>
#include <spa/support/type-map.h>
#define SPA_TYPE_PARAM__IO SPA_TYPE_PARAM_BASE "IO"
#define SPA_TYPE_PARAM_IO_BASE SPA_TYPE_PARAM__IO ":"
#define SPA_TYPE_PARAM_IO__id SPA_TYPE_PARAM_IO_BASE "id"
#define SPA_TYPE_PARAM_IO__size SPA_TYPE_PARAM_IO_BASE "size"
#define SPA_TYPE_PARAM_IO__propId SPA_TYPE_PARAM_IO_BASE "propId"
struct spa_type_param_io {
uint32_t IO;
uint32_t id;
uint32_t size;
uint32_t propId;
};
static inline void
spa_type_param_io_map(struct spa_type_map *map,
struct spa_type_param_io *type)
{
if (type->IO == 0) {
type->IO = spa_type_map_get_id(map, SPA_TYPE_PARAM__IO);
type->id = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__id);
type->size = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__size);
type->propId = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__propId);
}
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_PARAM_IO_H__ */

View file

@ -59,6 +59,9 @@ extern "C" {
/** The supported metadata */
#define SPA_TYPE_PARAM_ID__Meta SPA_TYPE_PARAM_ID_BASE "Meta"
/** The supported io types */
#define SPA_TYPE_PARAM_ID__IO SPA_TYPE_PARAM_ID_BASE "IO"
struct spa_type_param {
uint32_t idList; /**< id of the list param */
uint32_t List; /**< list object type */
@ -68,6 +71,7 @@ struct spa_type_param {
uint32_t idFormat; /**< id to get/set format parameter */
uint32_t idBuffers; /**< id to enumerate buffer requirements */
uint32_t idMeta; /**< id to enumerate supported metadata */
uint32_t idIO; /**< id to enumerate supported io types */
};
static inline void
@ -83,6 +87,7 @@ spa_type_param_map(struct spa_type_map *map,
type->idFormat = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__Format);
type->idBuffers = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__Buffers);
type->idMeta = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__Meta);
type->idIO = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__IO);
}
}