From b8f6e99537071d81ddeb1d28eebacbee17f3f7e0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 9 Jun 2016 13:06:35 +0200 Subject: [PATCH] Add plugin API Add plugin api, define a factory and methods for introspecting interfaces. --- pinos/spi/defs.h | 1 + pinos/spi/node.h | 116 ++++++++------------------- pinos/spi/plugin.h | 132 +++++++++++++++++++++++++++++++ pinos/tests/alsa-utils.c | 2 +- pinos/tests/spi-alsa-sink.c | 87 +++++++++++---------- pinos/tests/spi-audiotestsrc.c | 136 ++++++++++++++++---------------- pinos/tests/spi-plugins.h | 7 +- pinos/tests/spi-volume.c | 138 +++++++++++++++++---------------- pinos/tests/test-node.c | 48 ++++++------ 9 files changed, 386 insertions(+), 281 deletions(-) create mode 100644 pinos/spi/plugin.h diff --git a/pinos/spi/defs.h b/pinos/spi/defs.h index 4805ecf82..c1e256ade 100644 --- a/pinos/spi/defs.h +++ b/pinos/spi/defs.h @@ -50,6 +50,7 @@ typedef enum { SPI_RESULT_INVALID_FORMAT_PARAMS = -19, SPI_RESULT_FORMAT_INCOMPLETE = -20, SPI_RESULT_INVALID_ARGUMENTS = -21, + SPI_RESULT_UNKNOWN_INTERFACE = -22, } SpiResult; typedef enum { diff --git a/pinos/spi/node.h b/pinos/spi/node.h index ed6a20b1d..e863611b8 100644 --- a/pinos/spi/node.h +++ b/pinos/spi/node.h @@ -27,6 +27,7 @@ extern "C" { typedef struct _SpiNode SpiNode; #include +#include #include #include #include @@ -89,31 +90,20 @@ typedef struct { /** * SpiEventCallback: - * @node: a #SpiNode emiting the event + * @node: a #SpiHandle emiting the event * @event: the event that was emited * @user_data: user data provided when registering the callback * * This will be called when an out-of-bound event is notified * on @node. */ -typedef void (*SpiEventCallback) (SpiNode *node, +typedef void (*SpiEventCallback) (SpiHandle *handle, SpiEvent *event, void *user_data); -/** - * SpiInterfaceInfo: - * @interface_id: the id of the interface, can be used to get the interface - * @name: name of the interface - * @description: Human readable description of the interface. - * - * This structure lists the information about available interfaces on - * objects. - */ -typedef struct { - uint32_t interface_id; - const char *name; - const char *description; -} SpiInterfaceInfo; +#define SPI_INTERFACE_ID_NODE 0 +#define SPI_INTERFACE_ID_NODE_NAME "Node interface" +#define SPI_INTERFACE_ID_NODE_DESCRIPTION "Main processing node interface" /** * SpiNode: @@ -121,16 +111,12 @@ typedef struct { * The main processing nodes. */ struct _SpiNode { - /* user_data that can be set by the application */ - void * user_data; - /* the total size of this node. This can be used to expand this * structure in the future */ size_t size; - /** * SpiNode::get_params: - * @node: a #SpiNode + * @handle: a #SpiHandle * @props: a location for a #SpiParams pointer * * Get the configurable parameters of @node. @@ -144,11 +130,11 @@ struct _SpiNode { * #SPI_RESULT_NOT_IMPLEMENTED when there are no properties * implemented on @node */ - SpiResult (*get_params) (SpiNode *node, + SpiResult (*get_params) (SpiHandle *handle, SpiParams **props); /** * SpiNode::set_params: - * @node: a #SpiNode + * @handle: a #SpiHandle * @props: a #SpiParams * * Set the configurable parameters in @node. @@ -168,11 +154,11 @@ struct _SpiNode { * #SPI_RESULT_WRONG_PARAM_TYPE when a property has the wrong * type. */ - SpiResult (*set_params) (SpiNode *node, + SpiResult (*set_params) (SpiHandle *handle, const SpiParams *props); /** * SpiNode::send_command: - * @node: a #SpiNode + * @handle: a #SpiHandle * @command: a #SpiCommand * * Send a command to @node. @@ -182,11 +168,11 @@ struct _SpiNode { * #SPI_RESULT_NOT_IMPLEMENTED when this node can't process commands * #SPI_RESULT_INVALID_COMMAND @command is an invalid command */ - SpiResult (*send_command) (SpiNode *node, + SpiResult (*send_command) (SpiHandle *handle, SpiCommand *command); /** * SpiNode::set_event_callback: - * @node: a #SpiNode + * @handle: a #SpiHandle * @callback: a callback * @user_data: user data passed in the callback * @@ -199,12 +185,12 @@ struct _SpiNode { * Returns: #SPI_RESULT_OK on success * #SPI_RESULT_INVALID_ARGUMENTS when node is %NULL */ - SpiResult (*set_event_callback) (SpiNode *node, + SpiResult (*set_event_callback) (SpiHandle *handle, SpiEventCallback callback, void *user_data); /** * SpiNode::get_n_ports: - * @node: a #SpiNode + * @handle: a #SpiHandle * @n_input_ports: location to hold the number of input ports or %NULL * @max_input_ports: location to hold the maximum number of input ports or %NULL * @n_output_ports: location to hold the number of output ports or %NULL @@ -216,14 +202,14 @@ struct _SpiNode { * Returns: #SPI_RESULT_OK on success * #SPI_RESULT_INVALID_ARGUMENTS when node is %NULL */ - SpiResult (*get_n_ports) (SpiNode *node, + SpiResult (*get_n_ports) (SpiHandle *handle, unsigned int *n_input_ports, unsigned int *max_input_ports, unsigned int *n_output_ports, unsigned int *max_output_ports); /** * SpiNode::get_port_ids: - * @node: a #SpiNode + * @handle: a #SpiHandle * @n_input_ports: size of the @input_ids array * @input_ids: array to store the input stream ids * @n_output_ports: size of the @output_ids array @@ -235,21 +221,21 @@ struct _SpiNode { * Returns: #SPI_RESULT_OK on success * #SPI_RESULT_INVALID_ARGUMENTS when node is %NULL */ - SpiResult (*get_port_ids) (SpiNode *node, + SpiResult (*get_port_ids) (SpiHandle *handle, unsigned int n_input_ports, uint32_t *input_ids, unsigned int n_output_ports, uint32_t *output_ids); - SpiResult (*add_port) (SpiNode *node, + SpiResult (*add_port) (SpiHandle *handle, SpiDirection direction, uint32_t *port_id); - SpiResult (*remove_port) (SpiNode *node, + SpiResult (*remove_port) (SpiHandle *handle, uint32_t port_id); /** * SpiNode::enum_port_formats: - * @node: a #SpiNode + * @handle: a #SpiHandle * @port_id: the port to query * @index: the format index to retrieve * @format: pointer to a format @@ -268,13 +254,13 @@ struct _SpiNode { * #SPI_RESULT_ENUM_END when no format exists for @index * */ - SpiResult (*enum_port_formats) (SpiNode *node, + SpiResult (*enum_port_formats) (SpiHandle *handle, uint32_t port_id, unsigned int index, SpiParams **format); /** * SpiNode::set_port_format: - * @node: a #SpiNode + * @handle: a #SpiHandle * @port_id: the port to configure * @format: a #SpiParam with the format * @@ -291,13 +277,13 @@ struct _SpiNode { * #SPI_RESULT_WRONG_PARAM_TYPE when the type of size of a parameter * is not correct. */ - SpiResult (*set_port_format) (SpiNode *node, + SpiResult (*set_port_format) (SpiHandle *handle, uint32_t port_id, int test_only, const SpiParams *format); /** * SpiNode::get_port_format: - * @node: a #SpiNode + * @handle: a #SpiHandle * @port_id: the port to query * @format: a pointer to a location to hold the #SpiParam * @@ -309,28 +295,28 @@ struct _SpiNode { * #SPI_RESULT_INVALID_PORT when @port_id is not valid * #SPI_RESULT_INVALID_NO_FORMAT when no format was set */ - SpiResult (*get_port_format) (SpiNode *node, + SpiResult (*get_port_format) (SpiHandle *handle, uint32_t port_id, const SpiParams **format); - SpiResult (*get_port_info) (SpiNode *node, + SpiResult (*get_port_info) (SpiHandle *handle, uint32_t port_id, SpiPortInfo *info); - SpiResult (*get_port_params) (SpiNode *node, + SpiResult (*get_port_params) (SpiHandle *handle, uint32_t port_id, SpiParams **params); - SpiResult (*set_port_params) (SpiNode *node, + SpiResult (*set_port_params) (SpiHandle *handle, uint32_t port_id, const SpiParams *params); - SpiResult (*get_port_status) (SpiNode *node, + SpiResult (*get_port_status) (SpiHandle *handle, uint32_t port_id, SpiPortStatus *status); /** * SpiNode::push_port_input: - * @node: a #SpiNode + * @handle: a #SpiHandle * @n_info: number of #SpiInputInfo in @info * @info: array of #SpiInputInfo * @@ -344,12 +330,12 @@ struct _SpiNode { * @info. * #SPI_RESULT_HAVE_ENOUGH_INPUT when output can be produced. */ - SpiResult (*push_port_input) (SpiNode *node, + SpiResult (*push_port_input) (SpiHandle *handle, unsigned int n_info, SpiInputInfo *info); /** * SpiNode::pull_port_output: - * @node: a #SpiNode + * @handle: a #SpiHandle * @n_info: number of #SpiOutputInfo in @info * @info: array of #SpiOutputInfo * @@ -369,43 +355,9 @@ struct _SpiNode { * #SPI_RESULT_NEED_MORE_INPUT when no output can be produced * because more input is needed. */ - SpiResult (*pull_port_output) (SpiNode *node, + SpiResult (*pull_port_output) (SpiHandle *handle, unsigned int n_info, SpiOutputInfo *info); - - - /** - * SpiNode::enum_interface_info: - * @node: a #SpiNode - * @index: the interface index - * @info: result to hold SpiInterfaceInfo. - * - * Get the interface provided by @node at @index. - * - * Returns: #SPI_RESULT_OK on success - * #SPI_RESULT_NOT_IMPLEMENTED when there are no extensions - * #SPI_RESULT_INVALID_ARGUMENTS when node or info is %NULL - * #SPI_RESULT_ENUM_END when there are no more infos - */ - SpiResult (*enum_interface_info) (SpiNode *node, - unsigned int index, - const SpiInterfaceInfo **info); - /** - * SpiNode::enum_interface_info: - * @node: a #SpiNode - * @index: the interface index - * @info: result to hold SpiInterfaceInfo. - * - * Get the interface provided by @node at @index. - * - * Returns: #SPI_RESULT_OK on success - * #SPI_RESULT_NOT_IMPLEMENTED when there are no extensions - * #SPI_RESULT_INVALID_ARGUMENTS when node or info is %NULL - * #SPI_RESULT_ENUM_END when there are no more infos - */ - SpiResult (*get_interface) (SpiNode *node, - uint32_t interface_id, - void **interface); }; #ifdef __cplusplus diff --git a/pinos/spi/plugin.h b/pinos/spi/plugin.h new file mode 100644 index 000000000..5f5f3f2ac --- /dev/null +++ b/pinos/spi/plugin.h @@ -0,0 +1,132 @@ +/* Simple Plugin Interface + * 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 __SPI_PLUGIN_H__ +#define __SPI_PLUGIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef struct _SpiHandle SpiHandle; +typedef struct _SpiHandleFactory SpiHandleFactory; + +struct _SpiHandle { + /* user_data that can be set by the application */ + void * user_data; + /** + * SpiHandle::get_interface: + * @handle: a #SpiHandle + * @interface_id: the interface id + * @interface: result to hold the interface. + * + * Get the interface provided by @handle with @interface_id. + * + * Returns: #SPI_RESULT_OK on success + * #SPI_RESULT_NOT_IMPLEMENTED when there are no extensions + * #SPI_RESULT_INVALID_ARGUMENTS when handle or info is %NULL + */ + SpiResult (*get_interface) (SpiHandle *handle, + uint32_t interface_id, + void **interface); +}; + +/** + * SpiInterfaceInfo: + * @interface_id: the id of the interface, can be used to get the interface + * @name: name of the interface + * @description: Human readable description of the interface. + * + * This structure lists the information about available interfaces on + * handles. + */ +typedef struct { + uint32_t interface_id; + const char *name; + const char *description; +} SpiInterfaceInfo; + +struct _SpiHandleFactory { + /** + * SpiHandleFactory::name + * + * The name + */ + const char * name; + /** + * SpiHandleFactory::info + * + * Extra information about the handles of this factory. + */ + const SpiParams * info; + + /** + * SpiHandleFactory::instantiate + * @factory: a #SpiHandleFactory + * @handle: a pointer to hold the result + * + * Make an instance of this factory. + * + * Returns: #SPI_RESULT_OK on success + * #SPI_RESULT_NOT_IMPLEMENTED when an instance can't be made + * #SPI_RESULT_INVALID_ARGUMENTS when factory or handle are %NULL + */ + SpiResult (*instantiate) (SpiHandleFactory *factory, + SpiHandle **handle); + /** + * SpiHandle::enum_interface_info: + * @factory: a #SpiHandleFactory + * @index: the interface index + * @info: result to hold SpiInterfaceInfo. + * + * Get the interface information at @index. + * + * Returns: #SPI_RESULT_OK on success + * #SPI_RESULT_NOT_IMPLEMENTED when there are no interfaces + * #SPI_RESULT_INVALID_ARGUMENTS when handle or info is %NULL + * #SPI_RESULT_ENUM_END when there are no more infos + */ + SpiResult (*enum_interface_info) (SpiHandleFactory *factory, + unsigned int index, + const SpiInterfaceInfo **info); +}; + + +/** + * spi_enum_handle_factory: + * @index: the index to enumerate + * @factory: a location to hold the factory result + * + * The main entry point in a plugin. + * + * Returns: #SPI_RESULT_OK on success + * #SPI_RESULT_INVALID_ARGUMENTS when factory is %NULL + * #SPI_RESULT_ENUM_END when there are no more factories + */ +SpiResult spi_enum_handle_factory (unsigned int index, + const SpiHandleFactory **factory); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPI_PLUGIN_H__ */ diff --git a/pinos/tests/alsa-utils.c b/pinos/tests/alsa-utils.c index 897bad94f..8479d0bd3 100644 --- a/pinos/tests/alsa-utils.c +++ b/pinos/tests/alsa-utils.c @@ -272,7 +272,7 @@ direct_loop (void *user_data) buffer->data[0].data = (uint8_t *)my_areas[0].addr + (offset * sizeof (uint16_t) * 2); buffer->data[0].size = frames * sizeof (uint16_t) * 2; - this->event_cb (&this->node, &event,this->user_data); + this->event_cb (&this->handle, &event,this->user_data); spi_buffer_unref ((SpiBuffer *)event.data); } diff --git a/pinos/tests/spi-alsa-sink.c b/pinos/tests/spi-alsa-sink.c index 2650692d6..2c56bea92 100644 --- a/pinos/tests/spi-alsa-sink.c +++ b/pinos/tests/spi-alsa-sink.c @@ -87,7 +87,8 @@ struct _ALSABuffer { }; struct _SpiALSASink { - SpiNode node; + SpiHandle handle; + SpiNode node; SpiALSASinkParams params; @@ -288,7 +289,7 @@ get_param (const SpiParams *params, static SpiResult -spi_alsa_sink_node_get_params (SpiNode *node, +spi_alsa_sink_node_get_params (SpiHandle *node, SpiParams **params) { static SpiALSASinkParams p; @@ -304,7 +305,7 @@ spi_alsa_sink_node_get_params (SpiNode *node, } static SpiResult -spi_alsa_sink_node_set_params (SpiNode *node, +spi_alsa_sink_node_set_params (SpiHandle *node, const SpiParams *params) { SpiALSASink *this = (SpiALSASink *) node; @@ -345,7 +346,7 @@ spi_alsa_sink_node_set_params (SpiNode *node, } static SpiResult -spi_alsa_sink_node_send_command (SpiNode *node, +spi_alsa_sink_node_send_command (SpiHandle *node, SpiCommand *command) { SpiALSASink *this = (SpiALSASink *) node; @@ -408,7 +409,7 @@ spi_alsa_sink_node_send_command (SpiNode *node, } static SpiResult -spi_alsa_sink_node_set_event_callback (SpiNode *node, +spi_alsa_sink_node_set_event_callback (SpiHandle *node, SpiEventCallback event, void *user_data) { @@ -424,7 +425,7 @@ spi_alsa_sink_node_set_event_callback (SpiNode *node, } static SpiResult -spi_alsa_sink_node_get_n_ports (SpiNode *node, +spi_alsa_sink_node_get_n_ports (SpiHandle *node, unsigned int *n_input_ports, unsigned int *max_input_ports, unsigned int *n_output_ports, @@ -446,7 +447,7 @@ spi_alsa_sink_node_get_n_ports (SpiNode *node, } static SpiResult -spi_alsa_sink_node_get_port_ids (SpiNode *node, +spi_alsa_sink_node_get_port_ids (SpiHandle *node, unsigned int n_input_ports, uint32_t *input_ids, unsigned int n_output_ports, @@ -463,7 +464,7 @@ spi_alsa_sink_node_get_port_ids (SpiNode *node, static SpiResult -spi_alsa_sink_node_add_port (SpiNode *node, +spi_alsa_sink_node_add_port (SpiHandle *node, SpiDirection direction, uint32_t *port_id) { @@ -471,7 +472,7 @@ spi_alsa_sink_node_add_port (SpiNode *node, } static SpiResult -spi_alsa_sink_node_remove_port (SpiNode *node, +spi_alsa_sink_node_remove_port (SpiHandle *node, uint32_t port_id) { return SPI_RESULT_NOT_IMPLEMENTED; @@ -757,7 +758,7 @@ get_format_param (const SpiParams *params, static SpiResult -spi_alsa_sink_node_enum_port_formats (SpiNode *node, +spi_alsa_sink_node_enum_port_formats (SpiHandle *node, uint32_t port_id, unsigned int index, SpiParams **format) @@ -796,7 +797,7 @@ spi_alsa_sink_node_enum_port_formats (SpiNode *node, } static SpiResult -spi_alsa_sink_node_set_port_format (SpiNode *node, +spi_alsa_sink_node_set_port_format (SpiHandle *node, uint32_t port_id, int test_only, const SpiParams *format) @@ -871,7 +872,7 @@ spi_alsa_sink_node_set_port_format (SpiNode *node, } static SpiResult -spi_alsa_sink_node_get_port_format (SpiNode *node, +spi_alsa_sink_node_get_port_format (SpiHandle *node, uint32_t port_id, const SpiParams **format) { @@ -892,7 +893,7 @@ spi_alsa_sink_node_get_port_format (SpiNode *node, } static SpiResult -spi_alsa_sink_node_get_port_info (SpiNode *node, +spi_alsa_sink_node_get_port_info (SpiHandle *node, uint32_t port_id, SpiPortInfo *info) { @@ -908,7 +909,7 @@ spi_alsa_sink_node_get_port_info (SpiNode *node, } static SpiResult -spi_alsa_sink_node_get_port_params (SpiNode *node, +spi_alsa_sink_node_get_port_params (SpiHandle *node, uint32_t port_id, SpiParams **params) { @@ -916,7 +917,7 @@ spi_alsa_sink_node_get_port_params (SpiNode *node, } static SpiResult -spi_alsa_sink_node_set_port_params (SpiNode *node, +spi_alsa_sink_node_set_port_params (SpiHandle *node, uint32_t port_id, const SpiParams *params) { @@ -924,7 +925,7 @@ spi_alsa_sink_node_set_port_params (SpiNode *node, } static SpiResult -spi_alsa_sink_node_get_port_status (SpiNode *node, +spi_alsa_sink_node_get_port_status (SpiHandle *node, uint32_t port_id, SpiPortStatus *status) { @@ -940,7 +941,7 @@ spi_alsa_sink_node_get_port_status (SpiNode *node, } static SpiResult -spi_alsa_sink_node_push_port_input (SpiNode *node, +spi_alsa_sink_node_push_port_input (SpiHandle *node, unsigned int n_info, SpiInputInfo *info) { @@ -983,7 +984,7 @@ spi_alsa_sink_node_push_port_input (SpiNode *node, } static SpiResult -spi_alsa_sink_node_pull_port_output (SpiNode *node, +spi_alsa_sink_node_pull_port_output (SpiHandle *node, unsigned int n_info, SpiOutputInfo *info) { @@ -991,31 +992,43 @@ spi_alsa_sink_node_pull_port_output (SpiNode *node, } static SpiResult -spi_alsa_sink_node_enum_interface_info (SpiNode *node, - unsigned int index, - const SpiInterfaceInfo **info) - +spi_alsa_sink_get_interface (SpiHandle *handle, + uint32_t interface_id, + void **interface) { - return SPI_RESULT_NOT_IMPLEMENTED; -} + SpiALSASink *this = (SpiALSASink *) handle; -static SpiResult -spi_alsa_sink_node_get_interface (SpiNode *node, - uint32_t interface_id, - void **interface) -{ - return SPI_RESULT_NOT_IMPLEMENTED; + if (handle == NULL || interface == NULL) + return SPI_RESULT_INVALID_ARGUMENTS; + + switch (interface_id) { + case SPI_INTERFACE_ID_NODE: + *interface = &this->node; + break; + default: + return SPI_RESULT_UNKNOWN_INTERFACE; + } + return SPI_RESULT_OK; } -SpiNode * +SpiHandle * spi_alsa_sink_new (void) { + SpiHandle *handle; SpiNode *node; SpiALSASink *this; - node = calloc (1, sizeof (SpiALSASink)); + handle = calloc (1, sizeof (SpiALSASink)); + handle->get_interface = spi_alsa_sink_get_interface; + this = (SpiALSASink *) handle; + this->params.param.enum_param_info = enum_param_info; + this->params.param.set_param = set_param; + this->params.param.get_param = get_param; + reset_alsa_sink_params (&this->params); + + node = &this->node; node->get_params = spi_alsa_sink_node_get_params; node->set_params = spi_alsa_sink_node_set_params; node->send_command = spi_alsa_sink_node_send_command; @@ -1033,14 +1046,6 @@ spi_alsa_sink_new (void) node->get_port_status = spi_alsa_sink_node_get_port_status; node->push_port_input = spi_alsa_sink_node_push_port_input; node->pull_port_output = spi_alsa_sink_node_pull_port_output; - node->enum_interface_info = spi_alsa_sink_node_enum_interface_info; - node->get_interface = spi_alsa_sink_node_get_interface; - this = (SpiALSASink *) node; - this->params.param.enum_param_info = enum_param_info; - this->params.param.set_param = set_param; - this->params.param.get_param = get_param; - reset_alsa_sink_params (&this->params); - - return node; + return handle; } diff --git a/pinos/tests/spi-audiotestsrc.c b/pinos/tests/spi-audiotestsrc.c index 50f7ec458..b27e30558 100644 --- a/pinos/tests/spi-audiotestsrc.c +++ b/pinos/tests/spi-audiotestsrc.c @@ -43,6 +43,7 @@ typedef struct { } SpiAudioTestSrcFormat; struct _SpiAudioTestSrc { + SpiHandle handle; SpiNode node; SpiAudioTestSrcParams params; @@ -219,12 +220,12 @@ reset_audiotestsrc_params (SpiAudioTestSrcParams *params) } static SpiResult -spi_audiotestsrc_node_get_params (SpiNode *node, - SpiParams **params) +spi_audiotestsrc_node_get_params (SpiHandle *handle, + SpiParams **params) { - SpiAudioTestSrc *this = (SpiAudioTestSrc *) node; + SpiAudioTestSrc *this = (SpiAudioTestSrc *) handle; - if (node == NULL || params == NULL) + if (handle == NULL || params == NULL) return SPI_RESULT_INVALID_ARGUMENTS; memcpy (&this->tmp_params, &this->params, sizeof (this->tmp_params)); @@ -234,16 +235,16 @@ spi_audiotestsrc_node_get_params (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_set_params (SpiNode *node, +spi_audiotestsrc_node_set_params (SpiHandle *handle, const SpiParams *params) { - SpiAudioTestSrc *this = (SpiAudioTestSrc *) node; + SpiAudioTestSrc *this = (SpiAudioTestSrc *) handle; SpiAudioTestSrcParams *p = &this->params; SpiParamType type; size_t size; const void *value; - if (node == NULL) + if (handle == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (params == NULL) { @@ -270,12 +271,12 @@ spi_audiotestsrc_node_set_params (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_send_command (SpiNode *node, +spi_audiotestsrc_node_send_command (SpiHandle *handle, SpiCommand *command) { - SpiAudioTestSrc *this = (SpiAudioTestSrc *) node; + SpiAudioTestSrc *this = (SpiAudioTestSrc *) handle; - if (node == NULL || command == NULL) + if (handle == NULL || command == NULL) return SPI_RESULT_INVALID_ARGUMENTS; switch (command->type) { @@ -293,7 +294,7 @@ spi_audiotestsrc_node_send_command (SpiNode *node, event.data = NULL; event.size = 0; - this->event_cb (node, &event, this->user_data); + this->event_cb (handle, &event, this->user_data); } break; @@ -308,7 +309,7 @@ spi_audiotestsrc_node_send_command (SpiNode *node, event.data = NULL; event.size = 0; - this->event_cb (node, &event, this->user_data); + this->event_cb (handle, &event, this->user_data); } break; @@ -323,13 +324,13 @@ spi_audiotestsrc_node_send_command (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_set_event_callback (SpiNode *node, +spi_audiotestsrc_node_set_event_callback (SpiHandle *handle, SpiEventCallback event, void *user_data) { - SpiAudioTestSrc *this = (SpiAudioTestSrc *) node; + SpiAudioTestSrc *this = (SpiAudioTestSrc *) handle; - if (node == NULL) + if (handle == NULL) return SPI_RESULT_INVALID_ARGUMENTS; this->event_cb = event; @@ -339,13 +340,13 @@ spi_audiotestsrc_node_set_event_callback (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_get_n_ports (SpiNode *node, +spi_audiotestsrc_node_get_n_ports (SpiHandle *handle, unsigned int *n_input_ports, unsigned int *max_input_ports, unsigned int *n_output_ports, unsigned int *max_output_ports) { - if (node == NULL) + if (handle == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (n_input_ports) @@ -361,13 +362,13 @@ spi_audiotestsrc_node_get_n_ports (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_get_port_ids (SpiNode *node, +spi_audiotestsrc_node_get_port_ids (SpiHandle *handle, unsigned int n_input_ports, uint32_t *input_ids, unsigned int n_output_ports, uint32_t *output_ids) { - if (node == NULL || input_ids == NULL || output_ids == NULL) + if (handle == NULL || input_ids == NULL || output_ids == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (n_output_ports > 0) @@ -378,7 +379,7 @@ spi_audiotestsrc_node_get_port_ids (SpiNode *node, static SpiResult -spi_audiotestsrc_node_add_port (SpiNode *node, +spi_audiotestsrc_node_add_port (SpiHandle *handle, SpiDirection direction, uint32_t *port_id) { @@ -386,7 +387,7 @@ spi_audiotestsrc_node_add_port (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_remove_port (SpiNode *node, +spi_audiotestsrc_node_remove_port (SpiHandle *handle, uint32_t port_id) { return SPI_RESULT_NOT_IMPLEMENTED; @@ -601,14 +602,14 @@ get_format_param (const SpiParams *params, static SpiResult -spi_audiotestsrc_node_enum_port_formats (SpiNode *node, +spi_audiotestsrc_node_enum_port_formats (SpiHandle *handle, uint32_t port_id, unsigned int index, SpiParams **format) { static SpiAudioTestSrcFormat fmt; - if (node == NULL || format == NULL) + if (handle == NULL || format == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (port_id != 0) @@ -631,18 +632,18 @@ spi_audiotestsrc_node_enum_port_formats (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_set_port_format (SpiNode *node, +spi_audiotestsrc_node_set_port_format (SpiHandle *handle, uint32_t port_id, int test_only, const SpiParams *format) { - SpiAudioTestSrc *this = (SpiAudioTestSrc *) node; + SpiAudioTestSrc *this = (SpiAudioTestSrc *) handle; SpiParamType type; size_t size; const void *value; SpiAudioTestSrcFormat *fmt; - if (node == NULL) + if (handle == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (port_id != 0) @@ -705,13 +706,13 @@ spi_audiotestsrc_node_set_port_format (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_get_port_format (SpiNode *node, +spi_audiotestsrc_node_get_port_format (SpiHandle *handle, uint32_t port_id, const SpiParams **format) { - SpiAudioTestSrc *this = (SpiAudioTestSrc *) node; + SpiAudioTestSrc *this = (SpiAudioTestSrc *) handle; - if (node == NULL || format == NULL) + if (handle == NULL || format == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (port_id != 0) @@ -726,11 +727,11 @@ spi_audiotestsrc_node_get_port_format (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_get_port_info (SpiNode *node, +spi_audiotestsrc_node_get_port_info (SpiHandle *handle, uint32_t port_id, SpiPortInfo *info) { - if (node == NULL || info == NULL) + if (handle == NULL || info == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (port_id != 0) @@ -743,15 +744,15 @@ spi_audiotestsrc_node_get_port_info (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_get_port_params (SpiNode *node, - uint32_t port_id, - SpiParams **params) +spi_audiotestsrc_node_get_port_params (SpiHandle *handle, + uint32_t port_id, + SpiParams **params) { return SPI_RESULT_NOT_IMPLEMENTED; } static SpiResult -spi_audiotestsrc_node_set_port_params (SpiNode *node, +spi_audiotestsrc_node_set_port_params (SpiHandle *handle, uint32_t port_id, const SpiParams *params) { @@ -759,13 +760,13 @@ spi_audiotestsrc_node_set_port_params (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_get_port_status (SpiNode *node, +spi_audiotestsrc_node_get_port_status (SpiHandle *handle, uint32_t port_id, SpiPortStatus *status) { - SpiAudioTestSrc *this = (SpiAudioTestSrc *) node; + SpiAudioTestSrc *this = (SpiAudioTestSrc *) handle; - if (node == NULL || status == NULL) + if (handle == NULL || status == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (port_id != 0) @@ -780,7 +781,7 @@ spi_audiotestsrc_node_get_port_status (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_push_port_input (SpiNode *node, +spi_audiotestsrc_node_push_port_input (SpiHandle *handle, unsigned int n_info, SpiInputInfo *info) { @@ -788,17 +789,17 @@ spi_audiotestsrc_node_push_port_input (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_pull_port_output (SpiNode *node, +spi_audiotestsrc_node_pull_port_output (SpiHandle *handle, unsigned int n_info, SpiOutputInfo *info) { - SpiAudioTestSrc *this = (SpiAudioTestSrc *) node; + SpiAudioTestSrc *this = (SpiAudioTestSrc *) handle; size_t j, size; uint8_t *ptr; unsigned int i; bool have_error = false; - if (node == NULL || n_info == 0 || info == NULL) + if (handle == NULL || n_info == 0 || info == NULL) return SPI_RESULT_INVALID_ARGUMENTS; for (i = 0; i < n_info; i++) { @@ -835,31 +836,42 @@ spi_audiotestsrc_node_pull_port_output (SpiNode *node, } static SpiResult -spi_audiotestsrc_node_enum_interface_info (SpiNode *node, - unsigned int index, - const SpiInterfaceInfo **info) - +spi_audiotestsrc_get_interface (SpiHandle *handle, + uint32_t interface_id, + void **interface) { + SpiAudioTestSrc *this = (SpiAudioTestSrc *) handle; + + if (handle == NULL || interface == NULL) + return SPI_RESULT_INVALID_ARGUMENTS; + + switch (interface_id) { + case SPI_INTERFACE_ID_NODE: + *interface = &this->node; + break; + default: + return SPI_RESULT_UNKNOWN_INTERFACE; + } return SPI_RESULT_NOT_IMPLEMENTED; } -static SpiResult -spi_audiotestsrc_node_get_interface (SpiNode *node, - uint32_t interface_id, - void **interface) -{ - return SPI_RESULT_NOT_IMPLEMENTED; -} - - -SpiNode * +SpiHandle * spi_audiotestsrc_new (void) { + SpiHandle *handle; SpiNode *node; SpiAudioTestSrc *this; - node = calloc (1, sizeof (SpiAudioTestSrc)); + handle = calloc (1, sizeof (SpiAudioTestSrc)); + handle->get_interface = spi_audiotestsrc_get_interface; + this = (SpiAudioTestSrc *) handle; + this->params.param.enum_param_info = enum_param_info; + this->params.param.set_param = set_param; + this->params.param.get_param = get_param; + reset_audiotestsrc_params (&this->params); + + node = &this->node; node->get_params = spi_audiotestsrc_node_get_params; node->set_params = spi_audiotestsrc_node_set_params; node->send_command = spi_audiotestsrc_node_send_command; @@ -877,14 +889,6 @@ spi_audiotestsrc_new (void) node->get_port_status = spi_audiotestsrc_node_get_port_status; node->push_port_input = spi_audiotestsrc_node_push_port_input; node->pull_port_output = spi_audiotestsrc_node_pull_port_output; - node->enum_interface_info = spi_audiotestsrc_node_enum_interface_info; - node->get_interface = spi_audiotestsrc_node_get_interface; - this = (SpiAudioTestSrc *) node; - this->params.param.enum_param_info = enum_param_info; - this->params.param.set_param = set_param; - this->params.param.get_param = get_param; - reset_audiotestsrc_params (&this->params); - - return node; + return handle; } diff --git a/pinos/tests/spi-plugins.h b/pinos/tests/spi-plugins.h index 98b14dcd6..534cf9c29 100644 --- a/pinos/tests/spi-plugins.h +++ b/pinos/tests/spi-plugins.h @@ -16,7 +16,8 @@ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ +#include -SpiNode * spi_volume_new (void); -SpiNode * spi_audiotestsrc_new (void); -SpiNode * spi_alsa_sink_new (void); +SpiHandle * spi_volume_new (void); +SpiHandle * spi_audiotestsrc_new (void); +SpiHandle * spi_alsa_sink_new (void); diff --git a/pinos/tests/spi-volume.c b/pinos/tests/spi-volume.c index c282989e3..4f4c3729a 100644 --- a/pinos/tests/spi-volume.c +++ b/pinos/tests/spi-volume.c @@ -43,7 +43,8 @@ typedef struct { } SpiVolumeFormat; struct _SpiVolume { - SpiNode node; + SpiHandle handle; + SpiNode node; SpiVolumeParams params; SpiVolumeParams tmp_params; @@ -187,12 +188,12 @@ reset_volume_params (SpiVolumeParams *params) } static SpiResult -spi_volume_node_get_params (SpiNode *node, +spi_volume_node_get_params (SpiHandle *handle, SpiParams **params) { - SpiVolume *this = (SpiVolume *) node; + SpiVolume *this = (SpiVolume *) handle; - if (node == NULL || params == NULL) + if (handle == NULL || params == NULL) return SPI_RESULT_INVALID_ARGUMENTS; memcpy (&this->tmp_params, &this->params, sizeof (this->tmp_params)); @@ -202,16 +203,16 @@ spi_volume_node_get_params (SpiNode *node, } static SpiResult -spi_volume_node_set_params (SpiNode *node, +spi_volume_node_set_params (SpiHandle *handle, const SpiParams *params) { - SpiVolume *this = (SpiVolume *) node; + SpiVolume *this = (SpiVolume *) handle; SpiVolumeParams *p = &this->params; SpiParamType type; size_t size; const void *value; - if (node == NULL) + if (handle == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (params == NULL) { @@ -233,12 +234,12 @@ spi_volume_node_set_params (SpiNode *node, } static SpiResult -spi_volume_node_send_command (SpiNode *node, +spi_volume_node_send_command (SpiHandle *handle, SpiCommand *command) { - SpiVolume *this = (SpiVolume *) node; + SpiVolume *this = (SpiVolume *) handle; - if (node == NULL || command == NULL) + if (handle == NULL || command == NULL) return SPI_RESULT_INVALID_ARGUMENTS; switch (command->type) { @@ -256,7 +257,7 @@ spi_volume_node_send_command (SpiNode *node, event.data = NULL; event.size = 0; - this->event_cb (node, &event, this->user_data); + this->event_cb (handle, &event, this->user_data); } break; @@ -271,7 +272,7 @@ spi_volume_node_send_command (SpiNode *node, event.data = NULL; event.size = 0; - this->event_cb (node, &event, this->user_data); + this->event_cb (handle, &event, this->user_data); } break; @@ -286,13 +287,13 @@ spi_volume_node_send_command (SpiNode *node, } static SpiResult -spi_volume_node_set_event_callback (SpiNode *node, +spi_volume_node_set_event_callback (SpiHandle *handle, SpiEventCallback event, void *user_data) { - SpiVolume *this = (SpiVolume *) node; + SpiVolume *this = (SpiVolume *) handle; - if (node == NULL) + if (handle == NULL) return SPI_RESULT_INVALID_ARGUMENTS; this->event_cb = event; @@ -302,13 +303,13 @@ spi_volume_node_set_event_callback (SpiNode *node, } static SpiResult -spi_volume_node_get_n_ports (SpiNode *node, +spi_volume_node_get_n_ports (SpiHandle *handle, unsigned int *n_input_ports, unsigned int *max_input_ports, unsigned int *n_output_ports, unsigned int *max_output_ports) { - if (node == NULL) + if (handle == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (n_input_ports) @@ -324,13 +325,13 @@ spi_volume_node_get_n_ports (SpiNode *node, } static SpiResult -spi_volume_node_get_port_ids (SpiNode *node, +spi_volume_node_get_port_ids (SpiHandle *handle, unsigned int n_input_ports, uint32_t *input_ids, unsigned int n_output_ports, uint32_t *output_ids) { - if (node == NULL) + if (handle == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (n_input_ports > 0 && input_ids) @@ -343,7 +344,7 @@ spi_volume_node_get_port_ids (SpiNode *node, static SpiResult -spi_volume_node_add_port (SpiNode *node, +spi_volume_node_add_port (SpiHandle *handle, SpiDirection direction, uint32_t *port_id) { @@ -351,7 +352,7 @@ spi_volume_node_add_port (SpiNode *node, } static SpiResult -spi_volume_node_remove_port (SpiNode *node, +spi_volume_node_remove_port (SpiHandle *handle, uint32_t port_id) { return SPI_RESULT_NOT_IMPLEMENTED; @@ -566,14 +567,14 @@ get_format_param (const SpiParams *params, static SpiResult -spi_volume_node_enum_port_formats (SpiNode *node, +spi_volume_node_enum_port_formats (SpiHandle *handle, uint32_t port_id, unsigned int index, SpiParams **format) { static SpiVolumeFormat fmt; - if (node == NULL || format == NULL) + if (handle == NULL || format == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (port_id != 0) @@ -596,18 +597,18 @@ spi_volume_node_enum_port_formats (SpiNode *node, } static SpiResult -spi_volume_node_set_port_format (SpiNode *node, +spi_volume_node_set_port_format (SpiHandle *handle, uint32_t port_id, int test_only, const SpiParams *format) { - SpiVolume *this = (SpiVolume *) node; + SpiVolume *this = (SpiVolume *) handle; SpiParamType type; size_t size; const void *value; SpiVolumeFormat *fmt; - if (node == NULL || format == NULL) + if (handle == NULL || format == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (port_id != 0) @@ -670,13 +671,13 @@ spi_volume_node_set_port_format (SpiNode *node, } static SpiResult -spi_volume_node_get_port_format (SpiNode *node, +spi_volume_node_get_port_format (SpiHandle *handle, uint32_t port_id, const SpiParams **format) { - SpiVolume *this = (SpiVolume *) node; + SpiVolume *this = (SpiVolume *) handle; - if (node == NULL || format == NULL) + if (handle == NULL || format == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (port_id != 0) @@ -691,11 +692,11 @@ spi_volume_node_get_port_format (SpiNode *node, } static SpiResult -spi_volume_node_get_port_info (SpiNode *node, +spi_volume_node_get_port_info (SpiHandle *handle, uint32_t port_id, SpiPortInfo *info) { - if (node == NULL || info == NULL) + if (handle == NULL || info == NULL) return SPI_RESULT_INVALID_ARGUMENTS; switch (port_id) { @@ -715,7 +716,7 @@ spi_volume_node_get_port_info (SpiNode *node, } static SpiResult -spi_volume_node_get_port_params (SpiNode *node, +spi_volume_node_get_port_params (SpiHandle *handle, uint32_t port_id, SpiParams **params) { @@ -723,7 +724,7 @@ spi_volume_node_get_port_params (SpiNode *node, } static SpiResult -spi_volume_node_set_port_params (SpiNode *node, +spi_volume_node_set_port_params (SpiHandle *handle, uint32_t port_id, const SpiParams *params) { @@ -731,14 +732,14 @@ spi_volume_node_set_port_params (SpiNode *node, } static SpiResult -spi_volume_node_get_port_status (SpiNode *node, +spi_volume_node_get_port_status (SpiHandle *handle, uint32_t port_id, SpiPortStatus *status) { - SpiVolume *this = (SpiVolume *) node; + SpiVolume *this = (SpiVolume *) handle; SpiPortStatusFlags flags = 0; - if (node == NULL || status == NULL) + if (handle == NULL || status == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (!this->have_format) @@ -762,18 +763,18 @@ spi_volume_node_get_port_status (SpiNode *node, } static SpiResult -spi_volume_node_push_port_input (SpiNode *node, +spi_volume_node_push_port_input (SpiHandle *handle, unsigned int n_info, SpiInputInfo *info) { - SpiVolume *this = (SpiVolume *) node; + SpiVolume *this = (SpiVolume *) handle; SpiBuffer *buffer; SpiEvent *event; unsigned int i; bool have_error = false; bool have_enough = false; - if (node == NULL || n_info == 0 || info == NULL) + if (handle == NULL || n_info == 0 || info == NULL) return SPI_RESULT_INVALID_ARGUMENTS; for (i = 0; i < n_info; i++) { @@ -825,18 +826,18 @@ spi_volume_node_push_port_input (SpiNode *node, #define MIN(a,b) ((a) < (b) ? (a) : (b)) static SpiResult -spi_volume_node_pull_port_output (SpiNode *node, +spi_volume_node_pull_port_output (SpiHandle *handle, unsigned int n_info, SpiOutputInfo *info) { - SpiVolume *this = (SpiVolume *) node; + SpiVolume *this = (SpiVolume *) handle; unsigned int si, di, i, n_samples, n_bytes, soff, doff ; SpiBuffer *sbuf, *dbuf; SpiData *sd, *dd; uint16_t *src, *dst; double volume; - if (node == NULL || n_info == 0 || info == NULL) + if (handle == NULL || n_info == 0 || info == NULL) return SPI_RESULT_INVALID_ARGUMENTS; if (info->port_id != 1) @@ -903,30 +904,43 @@ spi_volume_node_pull_port_output (SpiNode *node, } static SpiResult -spi_volume_node_enum_interface_info (SpiNode *node, - unsigned int index, - const SpiInterfaceInfo **info) - +spi_volume_get_interface (SpiHandle *handle, + uint32_t interface_id, + void **interface) { - return SPI_RESULT_NOT_IMPLEMENTED; + SpiVolume *this = (SpiVolume *) handle; + + if (handle == NULL || interface == 0) + return SPI_RESULT_INVALID_ARGUMENTS; + + switch (interface_id) { + case SPI_INTERFACE_ID_NODE: + *interface = &this->node; + break; + default: + return SPI_RESULT_UNKNOWN_INTERFACE; + + } + return SPI_RESULT_OK; } -static SpiResult -spi_volume_node_get_interface (SpiNode *node, - uint32_t interface_id, - void **interface) -{ - return SPI_RESULT_NOT_IMPLEMENTED; -} - -SpiNode * +SpiHandle * spi_volume_new (void) { + SpiHandle *handle; SpiNode *node; SpiVolume *this; - node = calloc (1, sizeof (SpiVolume)); + handle = calloc (1, sizeof (SpiVolume)); + handle->get_interface = spi_volume_get_interface; + this = (SpiVolume *) handle; + this->params.param.enum_param_info = enum_param_info; + this->params.param.set_param = set_param; + this->params.param.get_param = get_param; + reset_volume_params (&this->params); + + node = &this->node; node->get_params = spi_volume_node_get_params; node->set_params = spi_volume_node_set_params; node->send_command = spi_volume_node_send_command; @@ -944,14 +958,6 @@ spi_volume_new (void) node->get_port_status = spi_volume_node_get_port_status; node->push_port_input = spi_volume_node_push_port_input; node->pull_port_output = spi_volume_node_pull_port_output; - node->enum_interface_info = spi_volume_node_enum_interface_info; - node->get_interface = spi_volume_node_get_interface; - this = (SpiVolume *) node; - this->params.param.enum_param_info = enum_param_info; - this->params.param.set_param = set_param; - this->params.param.get_param = get_param; - reset_volume_params (&this->params); - - return node; + return handle; } diff --git a/pinos/tests/test-node.c b/pinos/tests/test-node.c index c0047f451..b95c2c98b 100644 --- a/pinos/tests/test-node.c +++ b/pinos/tests/test-node.c @@ -26,8 +26,10 @@ #include "spi-plugins.h" typedef struct { - SpiNode *src; - SpiNode *sink; + SpiNode *src_node; + SpiNode *sink_node; + SpiHandle *src; + SpiHandle *sink; } AppData; static void @@ -145,32 +147,32 @@ print_params (const SpiParams *params, int print_ranges) } static void -inspect_node (SpiNode *node) +inspect_node (SpiNode *node, SpiHandle *handle) { SpiResult res; SpiParams *params; unsigned int n_input, max_input, n_output, max_output, i; SpiParams *format; - if ((res = node->get_params (node, ¶ms)) < 0) + if ((res = node->get_params (handle, ¶ms)) < 0) printf ("got error %d\n", res); else print_params (params, 1); - if ((res = node->get_n_ports (node, &n_input, &max_input, &n_output, &max_output)) < 0) + if ((res = node->get_n_ports (handle, &n_input, &max_input, &n_output, &max_output)) < 0) printf ("got error %d\n", res); else printf ("supported ports %d %d %d %d\n", n_input, max_input, n_output, max_output); for (i = 0; ; i++) { - if ((res = node->enum_port_formats (node, 0, i, &format)) < 0) { + if ((res = node->enum_port_formats (handle, 0, i, &format)) < 0) { if (res != SPI_RESULT_ENUM_END) printf ("got error %d\n", res); break; } print_params (format, 1); } - if ((res = node->get_port_params (node, 0, ¶ms)) < 0) + if ((res = node->get_port_params (handle, 0, ¶ms)) < 0) printf ("get_port_params error: %d\n", res); else printf ("got params %p\n", params); @@ -183,7 +185,7 @@ set_format (AppData *data) SpiResult res; uint32_t val; - if ((res = data->src->enum_port_formats (data->src, 0, 0, &format)) < 0) + if ((res = data->src_node->enum_port_formats (data->src, 0, 0, &format)) < 0) printf ("got error %d\n", res); printf ("setting format\n"); @@ -199,9 +201,9 @@ set_format (AppData *data) if ((res = format->set_param (format, 4, SPI_PARAM_TYPE_UINT32, 4, &val)) < 0) printf ("got error %d\n", res); - if ((res = data->src->set_port_format (data->src, 0, 0, format)) < 0) + if ((res = data->src_node->set_port_format (data->src, 0, 0, format)) < 0) printf ("set format failed: %d\n", res); - if ((res = data->sink->set_port_format (data->sink, 0, 0, format)) < 0) + if ((res = data->sink_node->set_port_format (data->sink, 0, 0, format)) < 0) printf ("set format failed: %d\n", res); } @@ -358,7 +360,7 @@ run_volume (SpiNode *node) #endif static void -on_event (SpiNode *node, SpiEvent *event, void *user_data) +on_event (SpiHandle *handle, SpiEvent *event, void *user_data) { AppData *data = user_data; @@ -377,7 +379,7 @@ on_event (SpiNode *node, SpiEvent *event, void *user_data) oinfo.buffer = buf; oinfo.event = NULL; - if ((res = data->src->pull_port_output (data->src, 1, &oinfo)) < 0) + if ((res = data->src_node->pull_port_output (data->src, 1, &oinfo)) < 0) printf ("got error %d\n", res); iinfo.port_id = 0; @@ -385,7 +387,7 @@ on_event (SpiNode *node, SpiEvent *event, void *user_data) iinfo.buffer = oinfo.buffer; iinfo.event = oinfo.event; - if ((res = data->sink->push_port_input (data->sink, 1, &iinfo)) < 0) + if ((res = data->sink_node->push_port_input (data->sink, 1, &iinfo)) < 0) printf ("got error %d\n", res); break; } @@ -404,14 +406,14 @@ run_async_sink (AppData *data) set_format (data); cmd.type = SPI_COMMAND_START; - if ((res = data->sink->send_command (data->sink, &cmd)) < 0) + if ((res = data->sink_node->send_command (data->sink, &cmd)) < 0) printf ("got error %d\n", res); printf ("sleeping for 10 seconds\n"); sleep (10); cmd.type = SPI_COMMAND_STOP; - if ((res = data->sink->send_command (data->sink, &cmd)) < 0) + if ((res = data->sink_node->send_command (data->sink, &cmd)) < 0) printf ("got error %d\n", res); } @@ -422,9 +424,10 @@ setup_source (AppData *data) SpiResult res; data->src = spi_audiotestsrc_new (); + data->src->get_interface (data->src, SPI_INTERFACE_ID_NODE, (void **)&data->src_node); cmd.type = SPI_COMMAND_ACTIVATE; - if ((res = data->src->send_command (data->src, &cmd)) < 0) + if ((res = data->src_node->send_command (data->src, &cmd)) < 0) printf ("got error %d\n", res); } @@ -436,19 +439,20 @@ setup_sink (AppData *data) SpiParams *params; data->sink = spi_alsa_sink_new (); + data->sink->get_interface (data->sink, SPI_INTERFACE_ID_NODE, (void **)&data->sink_node); - data->sink->set_event_callback (data->sink, on_event, data); + data->sink_node->set_event_callback (data->sink, on_event, data); - if ((res = data->sink->get_params (data->sink, ¶ms)) < 0) + if ((res = data->sink_node->get_params (data->sink, ¶ms)) < 0) printf ("got get_params error %d\n", res); params->set_param (params, 0, SPI_PARAM_TYPE_STRING, strlen ("hw:1")+1, "hw:1"); - if ((res = data->sink->set_params (data->sink, params)) < 0) + if ((res = data->sink_node->set_params (data->sink, params)) < 0) printf ("got set_params error %d\n", res); cmd.type = SPI_COMMAND_ACTIVATE; - if ((res = data->sink->send_command (data->sink, &cmd)) < 0) + if ((res = data->sink_node->send_command (data->sink, &cmd)) < 0) printf ("got error %d\n", res); } @@ -465,10 +469,10 @@ main (int argc, char *argv[]) run_async_sink (&data); cmd.type = SPI_COMMAND_DEACTIVATE; - if ((res = data.sink->send_command (data.sink, &cmd)) < 0) + if ((res = data.sink_node->send_command (data.sink, &cmd)) < 0) printf ("got error %d\n", res); cmd.type = SPI_COMMAND_DEACTIVATE; - if ((res = data.src->send_command (data.src, &cmd)) < 0) + if ((res = data.src_node->send_command (data.src, &cmd)) < 0) printf ("got error %d\n", res); return 0;