2016-06-28 12:21:56 +02:00
|
|
|
/* Spa
|
|
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Copyright © 2018 Wim Taymans
|
2016-06-28 12:21:56 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2016-06-28 12:21:56 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2016-06-28 12:21:56 +02:00
|
|
|
*/
|
|
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
#include <errno.h>
|
2016-06-28 12:21:56 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2019-10-25 15:01:02 +02:00
|
|
|
#include <spa/support/plugin.h>
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/support/log.h>
|
2019-10-03 16:20:12 +02:00
|
|
|
#include <spa/support/cpu.h>
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/utils/list.h>
|
2019-06-21 13:31:34 +02:00
|
|
|
#include <spa/utils/names.h>
|
2021-05-18 11:36:13 +10:00
|
|
|
#include <spa/utils/string.h>
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/node/node.h>
|
2019-05-20 10:14:00 +02:00
|
|
|
#include <spa/node/utils.h>
|
2017-11-21 19:34:37 +01:00
|
|
|
#include <spa/node/io.h>
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/param/audio/format-utils.h>
|
2018-08-25 12:08:29 +02:00
|
|
|
#include <spa/param/param.h>
|
2018-08-13 17:17:23 +02:00
|
|
|
#include <spa/pod/filter.h>
|
2017-11-09 17:07:04 +01:00
|
|
|
|
2017-11-23 16:55:32 +01:00
|
|
|
#include "mix-ops.h"
|
2017-06-27 17:48:34 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
#define NAME "audiomixer"
|
|
|
|
|
|
2019-10-24 15:26:59 +02:00
|
|
|
#define MAX_SAMPLES 8192
|
2017-04-03 14:56:04 +02:00
|
|
|
#define MAX_BUFFERS 64
|
2016-06-28 12:21:56 +02:00
|
|
|
#define MAX_PORTS 128
|
|
|
|
|
|
2017-11-23 16:55:32 +01:00
|
|
|
#define PORT_DEFAULT_VOLUME 1.0
|
|
|
|
|
#define PORT_DEFAULT_MUTE false
|
|
|
|
|
|
|
|
|
|
struct port_props {
|
|
|
|
|
double volume;
|
|
|
|
|
int32_t mute;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void port_props_reset(struct port_props *props)
|
|
|
|
|
{
|
|
|
|
|
props->volume = PORT_DEFAULT_VOLUME;
|
|
|
|
|
props->mute = PORT_DEFAULT_MUTE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct buffer {
|
2019-01-07 18:14:04 +01:00
|
|
|
uint32_t id;
|
2017-10-31 16:01:26 +01:00
|
|
|
struct spa_list link;
|
2017-05-25 16:23:13 +02:00
|
|
|
bool outstanding;
|
2017-10-31 16:01:26 +01:00
|
|
|
|
|
|
|
|
struct spa_buffer *outbuf;
|
|
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
struct spa_meta_header *h;
|
2017-05-25 13:28:15 +02:00
|
|
|
};
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct port {
|
2019-02-14 17:08:46 +01:00
|
|
|
uint32_t direction;
|
2018-03-09 12:30:54 +01:00
|
|
|
uint32_t id;
|
2017-06-27 17:48:34 +02:00
|
|
|
|
2017-11-23 16:55:32 +01:00
|
|
|
struct port_props props;
|
|
|
|
|
|
2017-11-21 19:34:37 +01:00
|
|
|
struct spa_io_buffers *io;
|
2017-11-23 16:55:32 +01:00
|
|
|
double *io_volume;
|
|
|
|
|
int32_t *io_mute;
|
2017-04-08 20:33:54 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
uint64_t info_all;
|
2017-05-25 16:23:13 +02:00
|
|
|
struct spa_port_info info;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct spa_param_info params[5];
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2019-04-10 17:52:42 +02:00
|
|
|
unsigned int valid:1;
|
|
|
|
|
unsigned int have_format:1;
|
2017-06-27 17:48:34 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
struct buffer buffers[MAX_BUFFERS];
|
|
|
|
|
uint32_t n_buffers;
|
2017-04-08 20:33:54 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
struct spa_list queue;
|
|
|
|
|
size_t queued_bytes;
|
2017-05-25 13:28:15 +02:00
|
|
|
};
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct impl {
|
2017-05-25 16:23:13 +02:00
|
|
|
struct spa_handle handle;
|
|
|
|
|
struct spa_node node;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
struct spa_log *log;
|
2019-10-03 16:20:12 +02:00
|
|
|
struct spa_cpu *cpu;
|
|
|
|
|
uint32_t cpu_flags;
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2019-10-03 16:20:12 +02:00
|
|
|
struct mix_ops ops;
|
2017-06-27 17:48:34 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
uint64_t info_all;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct spa_node_info info;
|
|
|
|
|
struct spa_param_info params[8];
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook_list hooks;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-01-07 18:14:04 +01:00
|
|
|
uint32_t port_count;
|
|
|
|
|
uint32_t last_port;
|
2017-05-25 16:23:13 +02:00
|
|
|
struct port in_ports[MAX_PORTS];
|
|
|
|
|
struct port out_ports[1];
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
bool have_format;
|
2017-06-27 17:48:34 +02:00
|
|
|
int n_formats;
|
2017-05-25 16:23:13 +02:00
|
|
|
struct spa_audio_info format;
|
2017-10-31 16:01:26 +01:00
|
|
|
uint32_t bpf;
|
2017-06-27 17:48:34 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
bool started;
|
2016-06-28 12:21:56 +02:00
|
|
|
};
|
|
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
#define CHECK_FREE_IN_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) < MAX_PORTS && !this->in_ports[(p)].valid)
|
|
|
|
|
#define CHECK_IN_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) < MAX_PORTS && this->in_ports[(p)].valid)
|
2016-10-03 19:43:42 +02:00
|
|
|
#define CHECK_OUT_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
|
|
|
|
|
#define CHECK_PORT(this,d,p) (CHECK_OUT_PORT(this,d,p) || CHECK_IN_PORT (this,d,p))
|
2017-06-27 17:48:34 +02:00
|
|
|
#define GET_IN_PORT(this,p) (&this->in_ports[p])
|
|
|
|
|
#define GET_OUT_PORT(this,p) (&this->out_ports[p])
|
|
|
|
|
#define GET_PORT(this,d,p) (d == SPA_DIRECTION_INPUT ? GET_IN_PORT(this,p) : GET_OUT_PORT(this,p))
|
2016-10-03 19:43:42 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_enum_params(void *object, int seq,
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t id, uint32_t start, uint32_t num,
|
2019-02-25 12:29:57 +01:00
|
|
|
const struct spa_pod *filter)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOTSUP;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
2017-11-13 17:57:38 +01:00
|
|
|
const struct spa_pod *param)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOTSUP;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
|
2018-10-23 12:31:41 +02:00
|
|
|
{
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_send_command(void *object, const struct spa_command *command)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(command != NULL, -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2018-08-24 10:53:09 +02:00
|
|
|
switch (SPA_NODE_COMMAND_ID(command)) {
|
|
|
|
|
case SPA_NODE_COMMAND_Start:
|
2017-05-25 16:23:13 +02:00
|
|
|
this->started = true;
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2018-08-24 10:53:09 +02:00
|
|
|
case SPA_NODE_COMMAND_Pause:
|
2017-05-25 16:23:13 +02:00
|
|
|
this->started = false;
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOTSUP;
|
2018-08-23 17:47:57 +02:00
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
static void emit_node_info(struct impl *this, bool full)
|
2019-02-27 16:43:01 +01:00
|
|
|
{
|
2021-05-25 15:22:13 +02:00
|
|
|
uint64_t old = full ? this->info.change_mask : 0;
|
2019-03-01 12:00:42 +01:00
|
|
|
if (full)
|
|
|
|
|
this->info.change_mask = this->info_all;
|
|
|
|
|
if (this->info.change_mask) {
|
|
|
|
|
spa_node_emit_info(&this->hooks, &this->info);
|
2021-05-25 15:22:13 +02:00
|
|
|
this->info.change_mask = old;
|
2019-02-27 16:43:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
static void emit_port_info(struct impl *this, struct port *port, bool full)
|
2019-02-14 17:08:46 +01:00
|
|
|
{
|
2021-05-25 15:22:13 +02:00
|
|
|
uint64_t old = full ? port->info.change_mask : 0;
|
2019-03-01 12:00:42 +01:00
|
|
|
if (full)
|
|
|
|
|
port->info.change_mask = port->info_all;
|
|
|
|
|
if (port->info.change_mask) {
|
|
|
|
|
spa_node_emit_port_info(&this->hooks,
|
|
|
|
|
port->direction, port->id, &port->info);
|
2021-05-25 15:22:13 +02:00
|
|
|
port->info.change_mask = old;
|
2019-02-14 17:08:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_add_listener(void *object,
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook *listener,
|
|
|
|
|
const struct spa_node_events *events,
|
|
|
|
|
void *data)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook_list save;
|
2019-02-14 17:08:46 +01:00
|
|
|
uint32_t i;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
emit_node_info(this, true);
|
|
|
|
|
emit_port_info(this, GET_OUT_PORT(this, 0), true);
|
2019-02-14 17:08:46 +01:00
|
|
|
for (i = 0; i < this->last_port; i++) {
|
|
|
|
|
if (this->in_ports[i].valid)
|
2019-03-01 12:00:42 +01:00
|
|
|
emit_port_info(this, GET_IN_PORT(this, i), true);
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_hook_list_join(&this->hooks, &save);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_set_callbacks(void *object,
|
2019-03-01 12:00:42 +01:00
|
|
|
const struct spa_node_callbacks *callbacks,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id,
|
2019-02-18 13:22:46 +01:00
|
|
|
const struct spa_dict *props)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-06-27 17:48:34 +02:00
|
|
|
struct port *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_FREE_IN_PORT(this, direction, port_id), -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-02-14 17:08:46 +01:00
|
|
|
port = GET_IN_PORT(this, port_id);
|
2017-06-27 17:48:34 +02:00
|
|
|
port->valid = true;
|
2019-02-14 17:08:46 +01:00
|
|
|
port->direction = SPA_DIRECTION_INPUT;
|
2018-03-09 12:30:54 +01:00
|
|
|
port->id = port_id;
|
2017-11-23 16:55:32 +01:00
|
|
|
|
|
|
|
|
port_props_reset(&port->props);
|
|
|
|
|
port->io_volume = &port->props.volume;
|
|
|
|
|
port->io_mute = &port->props.mute;
|
|
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
spa_list_init(&port->queue);
|
2019-03-01 12:00:42 +01:00
|
|
|
port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
|
|
|
|
|
SPA_PORT_CHANGE_MASK_PARAMS;
|
2019-02-14 17:08:46 +01:00
|
|
|
port->info = SPA_PORT_INFO_INIT();
|
2019-08-01 15:28:20 +02:00
|
|
|
port->info.flags = SPA_PORT_FLAG_REMOVABLE |
|
2019-02-14 17:40:01 +01:00
|
|
|
SPA_PORT_FLAG_OPTIONAL |
|
|
|
|
|
SPA_PORT_FLAG_IN_PLACE;
|
2019-02-27 16:43:01 +01:00
|
|
|
port->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
|
|
|
|
|
port->params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);
|
|
|
|
|
port->params[2] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ);
|
|
|
|
|
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
|
|
|
|
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
|
|
|
|
port->info.params = port->params;
|
|
|
|
|
port->info.n_params = 5;
|
2017-06-27 17:48:34 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
this->port_count++;
|
2017-06-28 16:53:10 +02:00
|
|
|
if (this->last_port <= port_id)
|
|
|
|
|
this->last_port = port_id + 1;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2020-04-22 12:47:18 +02:00
|
|
|
spa_log_debug(this->log, NAME " %p: add port %d", this, port_id);
|
2019-03-01 12:00:42 +01:00
|
|
|
emit_port_info(this, port, true);
|
2017-07-03 17:34:30 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-06-27 17:48:34 +02:00
|
|
|
struct port *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_IN_PORT(this, direction, port_id), -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-02-14 17:08:46 +01:00
|
|
|
port = GET_IN_PORT(this, port_id);
|
2017-04-08 20:33:54 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
this->port_count--;
|
2017-06-27 17:48:34 +02:00
|
|
|
if (port->have_format && this->have_format) {
|
|
|
|
|
if (--this->n_formats == 0)
|
|
|
|
|
this->have_format = false;
|
|
|
|
|
}
|
|
|
|
|
spa_memzero(port, sizeof(struct port));
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-06-28 16:53:10 +02:00
|
|
|
if (port_id == this->last_port + 1) {
|
2017-06-28 16:33:11 +02:00
|
|
|
int i;
|
|
|
|
|
|
2017-06-28 16:53:10 +02:00
|
|
|
for (i = this->last_port; i >= 0; i--)
|
2017-06-28 16:33:11 +02:00
|
|
|
if (GET_IN_PORT (this, i)->valid)
|
|
|
|
|
break;
|
|
|
|
|
|
2017-06-28 16:53:10 +02:00
|
|
|
this->last_port = i + 1;
|
2017-06-28 16:33:11 +02:00
|
|
|
}
|
2020-04-22 12:47:18 +02:00
|
|
|
spa_log_debug(this->log, NAME " %p: remove port %d", this, port_id);
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_node_emit_port_info(&this->hooks, direction, port_id, NULL);
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int port_enum_formats(void *object,
|
2017-11-07 17:39:31 +01:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t index,
|
2017-11-09 17:07:04 +01:00
|
|
|
struct spa_pod **param,
|
2017-11-07 17:39:31 +01:00
|
|
|
struct spa_pod_builder *builder)
|
|
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
switch (index) {
|
2017-05-25 16:23:13 +02:00
|
|
|
case 0:
|
2018-01-18 15:41:47 +01:00
|
|
|
if (this->have_format) {
|
2019-01-16 11:05:12 +01:00
|
|
|
*param = spa_pod_builder_add_object(builder,
|
2018-08-27 15:03:11 +02:00
|
|
|
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_audio),
|
|
|
|
|
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
|
|
|
|
SPA_FORMAT_AUDIO_format, SPA_POD_Id(this->format.info.raw.format),
|
|
|
|
|
SPA_FORMAT_AUDIO_rate, SPA_POD_Int(this->format.info.raw.rate),
|
|
|
|
|
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(this->format.info.raw.channels));
|
2018-01-18 15:41:47 +01:00
|
|
|
} else {
|
2019-01-16 11:05:12 +01:00
|
|
|
*param = spa_pod_builder_add_object(builder,
|
2018-08-27 15:03:11 +02:00
|
|
|
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_audio),
|
|
|
|
|
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
|
|
|
|
SPA_FORMAT_AUDIO_format, SPA_POD_CHOICE_ENUM_Int(3,
|
2018-09-05 16:41:07 +02:00
|
|
|
SPA_AUDIO_FORMAT_S16,
|
|
|
|
|
SPA_AUDIO_FORMAT_S16,
|
|
|
|
|
SPA_AUDIO_FORMAT_F32),
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_FORMAT_AUDIO_rate, SPA_POD_CHOICE_RANGE_Int(44100, 1, INT32_MAX),
|
|
|
|
|
SPA_FORMAT_AUDIO_channels, SPA_POD_CHOICE_RANGE_Int(2, 1, INT32_MAX));
|
2018-01-18 15:41:47 +01:00
|
|
|
}
|
2017-05-25 16:23:13 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
return 1;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_enum_params(void *object, int seq,
|
2019-02-20 17:51:05 +01:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t start, uint32_t num,
|
2019-02-25 12:29:57 +01:00
|
|
|
const struct spa_pod *filter)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-11-08 11:22:42 +01:00
|
|
|
struct port *port;
|
2017-11-09 17:07:04 +01:00
|
|
|
struct spa_pod *param;
|
2017-11-14 10:17:45 +01:00
|
|
|
struct spa_pod_builder b = { 0 };
|
|
|
|
|
uint8_t buffer[1024];
|
2019-02-25 12:29:57 +01:00
|
|
|
struct spa_result_node_params result;
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t count = 0;
|
2017-11-09 17:07:04 +01:00
|
|
|
int res;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2019-02-20 17:51:05 +01:00
|
|
|
spa_return_val_if_fail(num != 0, -EINVAL);
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-11-08 11:22:42 +01:00
|
|
|
port = GET_PORT(this, direction, port_id);
|
|
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
result.id = id;
|
2019-02-20 17:51:05 +01:00
|
|
|
result.next = start;
|
2017-11-09 17:07:04 +01:00
|
|
|
next:
|
2019-02-25 12:29:57 +01:00
|
|
|
result.index = result.next++;
|
|
|
|
|
|
2017-11-14 10:17:45 +01:00
|
|
|
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
switch (id) {
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_EnumFormat:
|
2019-05-20 16:11:23 +02:00
|
|
|
if ((res = port_enum_formats(this, direction, port_id,
|
2019-02-25 12:29:57 +01:00
|
|
|
result.index, ¶m, &b)) <= 0)
|
2017-11-09 17:07:04 +01:00
|
|
|
return res;
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_Format:
|
2018-08-29 15:53:26 +02:00
|
|
|
if (!port->have_format)
|
|
|
|
|
return -EIO;
|
2019-02-25 12:29:57 +01:00
|
|
|
if (result.index > 0)
|
2018-08-29 15:53:26 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
param = spa_format_audio_raw_build(&b, id, &this->format.info.raw);
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_Buffers:
|
2017-11-08 11:22:42 +01:00
|
|
|
if (!port->have_format)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2019-02-25 12:29:57 +01:00
|
|
|
if (result.index > 0)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-01-16 11:05:12 +01:00
|
|
|
param = spa_pod_builder_add_object(&b,
|
2018-08-27 15:03:11 +02:00
|
|
|
SPA_TYPE_OBJECT_ParamBuffers, id,
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(1, 1, MAX_BUFFERS),
|
|
|
|
|
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
|
|
|
|
|
SPA_PARAM_BUFFERS_size, SPA_POD_CHOICE_RANGE_Int(
|
2019-10-24 15:26:59 +02:00
|
|
|
MAX_SAMPLES * this->bpf,
|
2018-09-05 16:41:07 +02:00
|
|
|
16 * this->bpf,
|
2019-10-24 15:26:59 +02:00
|
|
|
INT32_MAX),
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(0),
|
|
|
|
|
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_Meta:
|
2019-02-25 12:29:57 +01:00
|
|
|
switch (result.index) {
|
2017-11-07 17:39:31 +01:00
|
|
|
case 0:
|
2019-01-16 11:05:12 +01:00
|
|
|
param = spa_pod_builder_add_object(&b,
|
2018-08-27 15:03:11 +02:00
|
|
|
SPA_TYPE_OBJECT_ParamMeta, id,
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header),
|
|
|
|
|
SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header)));
|
2017-11-07 17:39:31 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_IO:
|
2019-02-25 12:29:57 +01:00
|
|
|
switch (result.index) {
|
2017-11-23 16:55:32 +01:00
|
|
|
case 0:
|
2019-01-16 11:05:12 +01:00
|
|
|
param = spa_pod_builder_add_object(&b,
|
2018-08-27 15:03:11 +02:00
|
|
|
SPA_TYPE_OBJECT_ParamIO, id,
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_PARAM_IO_id, SPA_POD_Id(SPA_IO_Buffers),
|
|
|
|
|
SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_buffers)));
|
2017-11-23 16:55:32 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-08-28 18:16:41 +02:00
|
|
|
break;
|
2018-08-23 17:47:57 +02:00
|
|
|
default:
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOENT;
|
2018-08-23 17:47:57 +02:00
|
|
|
}
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
2017-11-09 17:07:04 +01:00
|
|
|
goto next;
|
|
|
|
|
|
2019-06-03 16:08:42 +02:00
|
|
|
spa_node_emit_result(&this->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result);
|
2019-02-20 17:51:05 +01:00
|
|
|
|
|
|
|
|
if (++count != num)
|
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int clear_buffers(struct impl *this, struct port *port)
|
|
|
|
|
{
|
|
|
|
|
if (port->n_buffers > 0) {
|
2020-04-22 12:47:18 +02:00
|
|
|
spa_log_debug(this->log, NAME " %p: clear buffers %p", this, port);
|
2017-11-07 17:39:31 +01:00
|
|
|
port->n_buffers = 0;
|
|
|
|
|
spa_list_init(&port->queue);
|
|
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int port_set_format(void *object,
|
2017-11-07 17:39:31 +01:00
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t flags,
|
2017-11-13 17:57:38 +01:00
|
|
|
const struct spa_pod *format)
|
2017-11-07 17:39:31 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-11-07 17:39:31 +01:00
|
|
|
struct port *port;
|
2018-08-29 14:50:58 +02:00
|
|
|
int res;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
port = GET_PORT(this, direction, port_id);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
if (format == NULL) {
|
2017-06-27 17:48:34 +02:00
|
|
|
if (port->have_format) {
|
|
|
|
|
port->have_format = false;
|
|
|
|
|
if (--this->n_formats == 0)
|
|
|
|
|
this->have_format = false;
|
|
|
|
|
clear_buffers(this, port);
|
|
|
|
|
}
|
2017-05-25 16:23:13 +02:00
|
|
|
} else {
|
2017-11-07 17:39:31 +01:00
|
|
|
struct spa_audio_info info = { 0 };
|
|
|
|
|
|
2018-08-29 14:50:58 +02:00
|
|
|
if ((res = spa_format_parse(format, &info.media_type, &info.media_subtype)) < 0)
|
|
|
|
|
return res;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
|
|
|
|
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
if (this->have_format) {
|
|
|
|
|
if (memcmp(&info, &this->format, sizeof(struct spa_audio_info)))
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2017-06-27 17:48:34 +02:00
|
|
|
} else {
|
2019-10-03 16:20:12 +02:00
|
|
|
this->ops.fmt = info.info.raw.format;
|
|
|
|
|
this->ops.n_channels = info.info.raw.channels;
|
|
|
|
|
this->ops.cpu_flags = this->cpu_flags;
|
|
|
|
|
|
|
|
|
|
if ((res = mix_ops_init(&this->ops)) < 0)
|
|
|
|
|
return res;
|
2017-10-31 16:01:26 +01:00
|
|
|
|
|
|
|
|
this->have_format = true;
|
|
|
|
|
this->format = info;
|
2017-06-27 17:48:34 +02:00
|
|
|
}
|
|
|
|
|
if (!port->have_format) {
|
|
|
|
|
this->n_formats++;
|
|
|
|
|
port->have_format = true;
|
2020-04-22 12:47:18 +02:00
|
|
|
spa_log_debug(this->log, NAME " %p: set format on port %d", this, port_id);
|
2017-06-27 17:48:34 +02:00
|
|
|
}
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
2019-03-01 12:00:42 +01:00
|
|
|
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
2019-02-27 16:43:01 +01:00
|
|
|
if (port->have_format) {
|
|
|
|
|
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
|
|
|
|
|
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
|
|
|
|
|
} else {
|
|
|
|
|
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
|
|
|
|
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
|
|
|
|
}
|
2019-03-01 12:00:42 +01:00
|
|
|
emit_port_info(this, port, false);
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_set_param(void *object,
|
2017-11-07 17:39:31 +01:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t flags,
|
2017-11-13 17:57:38 +01:00
|
|
|
const struct spa_pod *param)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-10-31 16:01:26 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2017-10-31 16:01:26 +01:00
|
|
|
|
2018-08-25 12:08:29 +02:00
|
|
|
if (id == SPA_PARAM_Format) {
|
2019-05-20 16:11:23 +02:00
|
|
|
return port_set_format(this, direction, port_id, flags, param);
|
2017-10-31 16:01:26 +01:00
|
|
|
}
|
2017-11-07 17:39:31 +01:00
|
|
|
else
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOENT;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_use_buffers(void *object,
|
2017-05-25 16:23:13 +02:00
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
2019-08-01 15:28:20 +02:00
|
|
|
uint32_t flags,
|
2017-05-25 16:23:13 +02:00
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t n_buffers)
|
2016-08-02 16:34:44 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-05-25 16:23:13 +02:00
|
|
|
struct port *port;
|
|
|
|
|
uint32_t i;
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
port = GET_PORT(this, direction, port_id);
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(port->have_format, -EIO);
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2020-04-22 12:47:18 +02:00
|
|
|
spa_log_debug(this->log, NAME " %p: use buffers %d on port %d", this, n_buffers, port_id);
|
2017-12-01 10:12:43 +01:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
clear_buffers(this, port);
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
for (i = 0; i < n_buffers; i++) {
|
|
|
|
|
struct buffer *b;
|
|
|
|
|
struct spa_data *d = buffers[i]->datas;
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
b = &port->buffers[i];
|
2019-01-07 18:14:04 +01:00
|
|
|
b->id = i;
|
2017-05-25 16:23:13 +02:00
|
|
|
b->outbuf = buffers[i];
|
2017-10-24 13:01:13 +02:00
|
|
|
b->outstanding = (direction == SPA_DIRECTION_INPUT);
|
2018-08-23 17:47:57 +02:00
|
|
|
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
|
2017-11-02 16:51:26 +01:00
|
|
|
|
2019-10-16 12:23:42 +02:00
|
|
|
if (d[0].data == NULL) {
|
2017-06-06 09:10:42 +02:00
|
|
|
spa_log_error(this->log, NAME " %p: invalid memory on buffer %p", this,
|
2017-05-25 16:23:13 +02:00
|
|
|
buffers[i]);
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
|
|
|
|
if (!b->outstanding)
|
2017-10-24 12:58:10 +02:00
|
|
|
spa_list_append(&port->queue, &b->link);
|
2017-12-01 10:12:43 +01:00
|
|
|
|
|
|
|
|
port->queued_bytes = 0;
|
|
|
|
|
if (port->io)
|
|
|
|
|
*port->io = SPA_IO_BUFFERS_INIT;
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
|
|
|
|
port->n_buffers = n_buffers;
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-08-02 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_set_io(void *object,
|
2017-11-21 19:34:37 +01:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
2017-11-22 14:30:04 +01:00
|
|
|
uint32_t id, void *data, size_t size)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-05-25 16:23:13 +02:00
|
|
|
struct port *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
port = GET_PORT(this, direction, port_id);
|
2017-11-21 19:34:37 +01:00
|
|
|
|
2018-08-28 18:16:41 +02:00
|
|
|
switch (id) {
|
|
|
|
|
case SPA_IO_Buffers:
|
2017-11-22 14:30:04 +01:00
|
|
|
port->io = data;
|
2018-08-28 18:16:41 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-11-21 19:34:37 +01:00
|
|
|
return -ENOENT;
|
2018-08-28 18:16:41 +02:00
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
static void recycle_buffer(struct impl *this, uint32_t id)
|
2017-04-03 16:54:44 +02:00
|
|
|
{
|
2017-06-27 17:48:34 +02:00
|
|
|
struct port *port = GET_OUT_PORT(this, 0);
|
2017-05-25 16:23:13 +02:00
|
|
|
struct buffer *b = &port->buffers[id];
|
2017-04-08 20:33:54 +02:00
|
|
|
|
2018-03-08 10:07:44 +01:00
|
|
|
if (!b->outstanding)
|
2017-05-25 16:23:13 +02:00
|
|
|
return;
|
2017-04-08 20:33:54 +02:00
|
|
|
|
2017-10-24 12:58:10 +02:00
|
|
|
spa_list_append(&port->queue, &b->link);
|
2017-05-25 16:23:13 +02:00
|
|
|
b->outstanding = false;
|
|
|
|
|
spa_log_trace(this->log, NAME " %p: recycle buffer %d", this, id);
|
2017-04-03 16:54:44 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-04-03 16:54:44 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL);
|
2017-04-03 16:54:44 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
recycle_buffer(this, buffer_id);
|
2017-04-03 16:54:44 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOTSUP;
|
2016-11-07 18:23:09 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:17:47 +02:00
|
|
|
static inline void
|
2017-11-23 16:55:32 +01:00
|
|
|
add_port_data(struct impl *this, void *out, size_t outsize, struct port *port, int layer)
|
2017-04-03 14:56:04 +02:00
|
|
|
{
|
2017-05-25 16:23:13 +02:00
|
|
|
size_t insize;
|
|
|
|
|
struct buffer *b;
|
2017-11-21 12:30:15 +01:00
|
|
|
uint32_t index, offset, len1, len2, maxsize;
|
|
|
|
|
struct spa_data *d;
|
2017-11-15 17:25:36 +01:00
|
|
|
void *data;
|
2017-11-23 16:55:32 +01:00
|
|
|
double volume = *port->io_volume;
|
|
|
|
|
bool mute = *port->io_mute;
|
2019-10-03 16:20:12 +02:00
|
|
|
const void *s0[2], *s1[2];
|
|
|
|
|
uint32_t n_src;
|
2017-05-25 16:23:13 +02:00
|
|
|
|
|
|
|
|
b = spa_list_first(&port->queue, struct buffer, link);
|
|
|
|
|
|
2017-11-21 12:30:15 +01:00
|
|
|
d = b->outbuf->datas;
|
2017-11-15 17:25:36 +01:00
|
|
|
|
2017-11-21 12:30:15 +01:00
|
|
|
maxsize = d[0].maxsize;
|
|
|
|
|
data = d[0].data;
|
|
|
|
|
|
|
|
|
|
insize = SPA_MIN(d[0].chunk->size, maxsize);
|
2017-11-02 16:51:26 +01:00
|
|
|
outsize = SPA_MIN(outsize, insize);
|
2017-10-31 16:01:26 +01:00
|
|
|
|
2017-11-21 12:30:15 +01:00
|
|
|
index = d[0].chunk->offset + (insize - port->queued_bytes);
|
2017-11-15 17:25:36 +01:00
|
|
|
offset = index % maxsize;
|
2017-10-31 16:01:26 +01:00
|
|
|
|
2017-11-16 16:31:03 +01:00
|
|
|
len1 = SPA_MIN(outsize, maxsize - offset);
|
2017-11-23 16:55:32 +01:00
|
|
|
len2 = outsize - len1;
|
|
|
|
|
|
2019-10-03 16:20:12 +02:00
|
|
|
n_src = 0;
|
|
|
|
|
if (layer > 0) {
|
|
|
|
|
s0[n_src] = out;
|
2021-05-06 13:41:44 +10:00
|
|
|
s1[n_src] = SPA_PTROFF(out, len1, void);
|
2019-10-03 16:20:12 +02:00
|
|
|
n_src++;
|
2017-11-23 16:55:32 +01:00
|
|
|
}
|
2021-05-06 13:41:44 +10:00
|
|
|
s0[n_src] = SPA_PTROFF(data, offset, void);
|
2019-10-03 16:20:12 +02:00
|
|
|
s1[n_src] = data;
|
|
|
|
|
n_src++;
|
2017-11-23 16:55:32 +01:00
|
|
|
|
2019-10-03 16:20:12 +02:00
|
|
|
if (volume < 0.001 || mute) {
|
|
|
|
|
/* silence, do nothing */
|
2017-11-23 16:55:32 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2019-10-03 16:20:12 +02:00
|
|
|
mix_ops_process(&this->ops, out, s0, n_src, len1);
|
2017-11-23 16:55:32 +01:00
|
|
|
if (len2 > 0)
|
2021-05-06 13:41:44 +10:00
|
|
|
mix_ops_process(&this->ops, SPA_PTROFF(out, len1, void), s1, n_src, len2);
|
2017-11-23 16:55:32 +01:00
|
|
|
}
|
2017-05-25 16:23:13 +02:00
|
|
|
port->queued_bytes -= outsize;
|
|
|
|
|
|
2017-11-21 12:30:15 +01:00
|
|
|
if (port->queued_bytes == 0) {
|
2018-03-09 12:30:54 +01:00
|
|
|
spa_log_trace(this->log, NAME " %p: return buffer %d on port %d %zd",
|
2019-01-07 18:14:04 +01:00
|
|
|
this, b->id, port->id, outsize);
|
|
|
|
|
port->io->buffer_id = b->id;
|
2017-05-25 16:23:13 +02:00
|
|
|
spa_list_remove(&b->link);
|
|
|
|
|
b->outstanding = true;
|
|
|
|
|
} else {
|
2018-03-09 12:30:54 +01:00
|
|
|
spa_log_trace(this->log, NAME " %p: keeping buffer %d on port %d %zd %zd",
|
2019-01-07 18:14:04 +01:00
|
|
|
this, b->id, port->id, port->queued_bytes, outsize);
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
2017-04-03 14:56:04 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
static int mix_output(struct impl *this, size_t n_bytes)
|
2017-04-12 10:40:17 +02:00
|
|
|
{
|
2017-05-25 16:23:13 +02:00
|
|
|
struct buffer *outbuf;
|
2019-01-07 18:14:04 +01:00
|
|
|
uint32_t i, layer;
|
2017-05-25 16:23:13 +02:00
|
|
|
struct port *outport;
|
2017-11-21 19:34:37 +01:00
|
|
|
struct spa_io_buffers *outio;
|
2017-05-25 16:23:13 +02:00
|
|
|
struct spa_data *od;
|
2017-11-21 12:30:15 +01:00
|
|
|
uint32_t avail, index, maxsize, len1, len2, offset;
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
outport = GET_OUT_PORT(this, 0);
|
|
|
|
|
outio = outport->io;
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2017-11-03 12:26:16 +01:00
|
|
|
if (spa_list_is_empty(&outport->queue)) {
|
|
|
|
|
spa_log_trace(this->log, NAME " %p: out of buffers", this);
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EPIPE;
|
2017-11-03 12:26:16 +01:00
|
|
|
}
|
2017-05-25 16:23:13 +02:00
|
|
|
|
|
|
|
|
outbuf = spa_list_first(&outport->queue, struct buffer, link);
|
|
|
|
|
spa_list_remove(&outbuf->link);
|
|
|
|
|
outbuf->outstanding = true;
|
|
|
|
|
|
|
|
|
|
od = outbuf->outbuf->datas;
|
2017-11-15 17:25:36 +01:00
|
|
|
maxsize = od[0].maxsize;
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2017-11-21 12:30:15 +01:00
|
|
|
avail = maxsize;
|
|
|
|
|
index = 0;
|
2017-11-02 16:51:26 +01:00
|
|
|
n_bytes = SPA_MIN(n_bytes, avail);
|
2017-10-31 16:01:26 +01:00
|
|
|
|
2017-11-16 16:31:03 +01:00
|
|
|
offset = index % maxsize;
|
|
|
|
|
len1 = SPA_MIN(n_bytes, maxsize - offset);
|
|
|
|
|
len2 = n_bytes - len1;
|
2017-10-31 16:01:26 +01:00
|
|
|
|
|
|
|
|
spa_log_trace(this->log, NAME " %p: dequeue output buffer %d %zd %d %d %d",
|
2019-01-07 18:14:04 +01:00
|
|
|
this, outbuf->id, n_bytes, offset, len1, len2);
|
2017-10-31 16:01:26 +01:00
|
|
|
|
2017-06-28 16:33:11 +02:00
|
|
|
for (layer = 0, i = 0; i < this->last_port; i++) {
|
2017-06-27 17:48:34 +02:00
|
|
|
struct port *in_port = GET_IN_PORT(this, i);
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
if (in_port->io == NULL || in_port->n_buffers == 0)
|
2017-05-25 16:23:13 +02:00
|
|
|
continue;
|
|
|
|
|
|
2017-11-23 16:55:32 +01:00
|
|
|
if (in_port->queued_bytes == 0) {
|
2017-05-25 16:23:13 +02:00
|
|
|
spa_log_warn(this->log, NAME " %p: underrun stream %d", this, i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-11-23 16:55:32 +01:00
|
|
|
|
2021-05-06 13:41:44 +10:00
|
|
|
add_port_data(this, SPA_PTROFF(od[0].data, offset, void), len1, in_port, layer);
|
2017-10-31 16:01:26 +01:00
|
|
|
if (len2 > 0)
|
2017-11-23 16:55:32 +01:00
|
|
|
add_port_data(this, od[0].data, len2, in_port, layer);
|
2017-10-31 16:01:26 +01:00
|
|
|
layer++;
|
|
|
|
|
}
|
2017-11-02 16:51:26 +01:00
|
|
|
|
2017-11-21 12:30:15 +01:00
|
|
|
od[0].chunk->offset = index;
|
|
|
|
|
od[0].chunk->size = n_bytes;
|
|
|
|
|
od[0].chunk->stride = 0;
|
2017-10-31 16:01:26 +01:00
|
|
|
|
2019-01-07 18:14:04 +01:00
|
|
|
outio->buffer_id = outbuf->id;
|
2019-09-16 12:55:23 +02:00
|
|
|
outio->status = SPA_STATUS_HAVE_DATA;
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2019-09-16 12:55:23 +02:00
|
|
|
return SPA_STATUS_HAVE_DATA;
|
2017-04-12 10:40:17 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_process(void *object)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2017-06-27 17:48:34 +02:00
|
|
|
struct port *outport;
|
2017-11-21 19:34:37 +01:00
|
|
|
struct spa_io_buffers *outio;
|
2019-01-07 18:14:04 +01:00
|
|
|
uint32_t i;
|
2017-05-25 16:23:13 +02:00
|
|
|
size_t min_queued = SIZE_MAX;
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
outport = GET_OUT_PORT(this, 0);
|
|
|
|
|
outio = outport->io;
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(outio != NULL, -EIO);
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2018-03-09 12:30:54 +01:00
|
|
|
spa_log_trace(this->log, NAME " %p: status %d", this, outio->status);
|
|
|
|
|
|
2019-09-16 12:55:23 +02:00
|
|
|
if (outio->status == SPA_STATUS_HAVE_DATA)
|
2018-03-08 10:07:44 +01:00
|
|
|
goto done;
|
2017-05-25 16:23:13 +02:00
|
|
|
|
|
|
|
|
/* recycle */
|
2017-08-27 09:16:03 +02:00
|
|
|
if (outio->buffer_id < outport->n_buffers) {
|
2017-06-27 17:48:34 +02:00
|
|
|
recycle_buffer(this, outio->buffer_id);
|
|
|
|
|
outio->buffer_id = SPA_ID_INVALID;
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
2018-07-31 12:23:35 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
/* produce more output if possible */
|
2017-06-28 16:33:11 +02:00
|
|
|
for (i = 0; i < this->last_port; i++) {
|
2017-06-27 17:48:34 +02:00
|
|
|
struct port *inport = GET_IN_PORT(this, i);
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
if (inport->io == NULL || inport->n_buffers == 0)
|
2017-05-25 16:23:13 +02:00
|
|
|
continue;
|
|
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
if (inport->queued_bytes < min_queued)
|
|
|
|
|
min_queued = inport->queued_bytes;
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
|
|
|
|
if (min_queued != SIZE_MAX && min_queued > 0) {
|
2018-03-09 12:30:54 +01:00
|
|
|
outio->status = mix_output(this, min_queued);
|
2017-05-25 16:23:13 +02:00
|
|
|
} else {
|
|
|
|
|
/* take requested output range and apply to input */
|
2017-06-28 16:33:11 +02:00
|
|
|
for (i = 0; i < this->last_port; i++) {
|
2017-06-27 17:48:34 +02:00
|
|
|
struct port *inport = GET_IN_PORT(this, i);
|
2017-11-21 19:34:37 +01:00
|
|
|
struct spa_io_buffers *inio;
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
if ((inio = inport->io) == NULL || inport->n_buffers == 0)
|
2017-05-25 16:23:13 +02:00
|
|
|
continue;
|
|
|
|
|
|
2018-01-30 14:53:38 +01:00
|
|
|
spa_log_trace(this->log, NAME " %p: port %d queued %zd, res %d", this,
|
|
|
|
|
i, inport->queued_bytes, inio->status);
|
|
|
|
|
|
2018-03-09 12:30:54 +01:00
|
|
|
if (inport->queued_bytes == 0) {
|
2019-09-16 12:55:23 +02:00
|
|
|
inio->status = SPA_STATUS_NEED_DATA;
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-16 12:55:23 +02:00
|
|
|
outio->status = SPA_STATUS_NEED_DATA;
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
2018-03-08 10:07:44 +01:00
|
|
|
done:
|
2018-03-09 12:30:54 +01:00
|
|
|
return outio->status;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static const struct spa_node_methods impl_node = {
|
|
|
|
|
SPA_VERSION_NODE_METHODS,
|
2019-03-01 12:00:42 +01:00
|
|
|
.add_listener = impl_node_add_listener,
|
|
|
|
|
.set_callbacks = impl_node_set_callbacks,
|
2019-02-14 17:08:46 +01:00
|
|
|
.enum_params = impl_node_enum_params,
|
|
|
|
|
.set_param = impl_node_set_param,
|
|
|
|
|
.set_io = impl_node_set_io,
|
|
|
|
|
.send_command = impl_node_send_command,
|
|
|
|
|
.add_port = impl_node_add_port,
|
|
|
|
|
.remove_port = impl_node_remove_port,
|
|
|
|
|
.port_enum_params = impl_node_port_enum_params,
|
|
|
|
|
.port_set_param = impl_node_port_set_param,
|
|
|
|
|
.port_use_buffers = impl_node_port_use_buffers,
|
|
|
|
|
.port_set_io = impl_node_port_set_io,
|
|
|
|
|
.port_reuse_buffer = impl_node_port_reuse_buffer,
|
|
|
|
|
.process = impl_node_process,
|
2016-06-28 12:21:56 +02:00
|
|
|
};
|
|
|
|
|
|
2019-12-19 13:15:10 +01:00
|
|
|
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-25 16:23:13 +02:00
|
|
|
struct impl *this;
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(interface != NULL, -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
this = (struct impl *) handle;
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2021-05-18 11:36:13 +10:00
|
|
|
if (spa_streq(type, SPA_TYPE_INTERFACE_Node))
|
2017-05-25 16:23:13 +02:00
|
|
|
*interface = &this->node;
|
|
|
|
|
else
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOENT;
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
static int impl_clear(struct spa_handle *handle)
|
2016-09-01 10:04:25 +02:00
|
|
|
{
|
2019-10-03 16:20:12 +02:00
|
|
|
struct impl *this;
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
this = (struct impl *) handle;
|
|
|
|
|
|
|
|
|
|
mix_ops_free(&this->ops);
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-09-01 10:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-09 10:06:17 +02:00
|
|
|
static size_t
|
|
|
|
|
impl_get_size(const struct spa_handle_factory *factory,
|
|
|
|
|
const struct spa_dict *params)
|
|
|
|
|
{
|
|
|
|
|
return sizeof(struct impl);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-25 16:23:13 +02:00
|
|
|
impl_init(const struct spa_handle_factory *factory,
|
|
|
|
|
struct spa_handle *handle,
|
|
|
|
|
const struct spa_dict *info,
|
|
|
|
|
const struct spa_support *support,
|
|
|
|
|
uint32_t n_support)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-25 16:23:13 +02:00
|
|
|
struct impl *this;
|
2017-06-27 17:48:34 +02:00
|
|
|
struct port *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
2016-07-13 18:29:55 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
handle->get_interface = impl_get_interface;
|
|
|
|
|
handle->clear = impl_clear;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
this = (struct impl *) handle;
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2019-12-19 13:15:10 +01:00
|
|
|
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
|
|
|
|
|
this->cpu = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU);
|
|
|
|
|
|
2019-10-03 16:20:12 +02:00
|
|
|
if (this->cpu)
|
|
|
|
|
this->cpu_flags = spa_cpu_get_flags(this->cpu);
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_hook_list_init(&this->hooks);
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
this->node.iface = SPA_INTERFACE_INIT(
|
|
|
|
|
SPA_TYPE_INTERFACE_Node,
|
|
|
|
|
SPA_VERSION_NODE,
|
|
|
|
|
&impl_node, this);
|
2019-02-27 16:43:01 +01:00
|
|
|
this->info = SPA_NODE_INFO_INIT();
|
|
|
|
|
this->info.max_input_ports = MAX_PORTS;
|
|
|
|
|
this->info.max_output_ports = 1;
|
|
|
|
|
this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS;
|
2019-08-06 12:45:20 +02:00
|
|
|
this->info.flags = SPA_NODE_FLAG_IN_DYNAMIC_PORTS |
|
2019-02-27 16:43:01 +01:00
|
|
|
SPA_NODE_FLAG_RT;
|
|
|
|
|
this->info.params = this->params;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
port = GET_OUT_PORT(this, 0);
|
2017-06-28 16:33:11 +02:00
|
|
|
port->valid = true;
|
2019-02-14 17:08:46 +01:00
|
|
|
port->direction = SPA_DIRECTION_OUTPUT;
|
2018-03-09 12:30:54 +01:00
|
|
|
port->id = 0;
|
2019-02-27 16:43:01 +01:00
|
|
|
port->info = SPA_PORT_INFO_INIT();
|
|
|
|
|
port->info.change_mask |= SPA_PORT_CHANGE_MASK_FLAGS;
|
2019-08-01 15:28:20 +02:00
|
|
|
port->info.flags = SPA_PORT_FLAG_NO_REF;
|
2019-02-27 16:43:01 +01:00
|
|
|
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
|
|
|
|
port->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
|
|
|
|
|
port->params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);
|
|
|
|
|
port->params[2] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ);
|
|
|
|
|
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
|
|
|
|
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
|
|
|
|
port->info.params = port->params;
|
|
|
|
|
port->info.n_params = 5;
|
|
|
|
|
|
2017-06-27 17:48:34 +02:00
|
|
|
spa_list_init(&port->queue);
|
|
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-07-13 18:29:55 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
static const struct spa_interface_info impl_interfaces[] = {
|
2018-08-27 15:03:11 +02:00
|
|
|
{SPA_TYPE_INTERFACE_Node,},
|
2016-07-13 18:29:55 +02:00
|
|
|
};
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-25 16:23:13 +02:00
|
|
|
impl_enum_interface_info(const struct spa_handle_factory *factory,
|
|
|
|
|
const struct spa_interface_info **info,
|
2017-11-13 09:41:41 +01:00
|
|
|
uint32_t *index)
|
2016-07-13 18:29:55 +02:00
|
|
|
{
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(info != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(index != NULL, -EINVAL);
|
2017-05-25 16:23:13 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
switch (*index) {
|
2017-05-25 16:23:13 +02:00
|
|
|
case 0:
|
2017-11-13 09:41:41 +01:00
|
|
|
*info = &impl_interfaces[*index];
|
2017-05-25 16:23:13 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-05-25 16:23:13 +02:00
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
(*index)++;
|
|
|
|
|
return 1;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2016-07-13 18:29:55 +02:00
|
|
|
|
2017-05-25 16:23:13 +02:00
|
|
|
const struct spa_handle_factory spa_audiomixer_factory = {
|
2017-06-14 18:32:39 +02:00
|
|
|
SPA_VERSION_HANDLE_FACTORY,
|
2019-06-21 13:31:34 +02:00
|
|
|
SPA_NAME_AUDIO_MIXER,
|
2017-05-25 16:23:13 +02:00
|
|
|
NULL,
|
2018-04-09 10:06:17 +02:00
|
|
|
impl_get_size,
|
2017-05-25 16:23:13 +02:00
|
|
|
impl_init,
|
|
|
|
|
impl_enum_interface_info,
|
2016-07-13 18:29:55 +02:00
|
|
|
};
|