2016-06-28 12:21:56 +02:00
|
|
|
/* Spa
|
|
|
|
|
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2016-10-07 13:14:32 +02:00
|
|
|
#include <spa/log.h>
|
2017-04-03 14:56:04 +02:00
|
|
|
#include <spa/list.h>
|
2017-03-24 11:40:58 +01:00
|
|
|
#include <spa/type-map.h>
|
2016-06-28 12:21:56 +02:00
|
|
|
#include <spa/node.h>
|
2017-03-21 16:50:44 +01:00
|
|
|
#include <spa/audio/format-utils.h>
|
2016-11-03 19:41:53 +01:00
|
|
|
#include <lib/props.h>
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
#define MAX_BUFFERS 64
|
2016-06-28 12:21:56 +02:00
|
|
|
#define MAX_PORTS 128
|
|
|
|
|
|
|
|
|
|
typedef struct _SpaAudioMixer SpaAudioMixer;
|
|
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
typedef struct {
|
|
|
|
|
SpaBuffer *outbuf;
|
|
|
|
|
bool outstanding;
|
|
|
|
|
SpaMetaHeader *h;
|
|
|
|
|
void *ptr;
|
|
|
|
|
size_t size;
|
|
|
|
|
SpaList link;
|
|
|
|
|
} MixerBuffer;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
bool valid;
|
2016-07-30 20:35:34 +02:00
|
|
|
bool have_format;
|
2017-02-24 09:28:18 +01:00
|
|
|
SpaAudioInfo format;
|
2016-06-28 12:21:56 +02:00
|
|
|
SpaPortInfo info;
|
2017-04-03 14:56:04 +02:00
|
|
|
|
|
|
|
|
SpaPortIO *io;
|
|
|
|
|
MixerBuffer buffers[MAX_BUFFERS];
|
|
|
|
|
uint32_t n_buffers;
|
|
|
|
|
SpaList queue;
|
|
|
|
|
size_t queued_offset;
|
|
|
|
|
size_t queued_bytes;
|
2016-06-28 12:21:56 +02:00
|
|
|
} SpaAudioMixerPort;
|
|
|
|
|
|
2016-10-07 13:14:32 +02:00
|
|
|
typedef struct {
|
|
|
|
|
uint32_t node;
|
2017-03-24 18:11:11 +01:00
|
|
|
SpaTypeMediaType media_type;
|
|
|
|
|
SpaTypeMediaSubtype media_subtype;
|
|
|
|
|
SpaTypeFormatAudio format_audio;
|
2017-03-24 11:40:58 +01:00
|
|
|
SpaTypeCommandNode command_node;
|
|
|
|
|
} Type;
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2017-03-23 12:38:00 +01:00
|
|
|
static inline void
|
2017-03-24 11:40:58 +01:00
|
|
|
init_type (Type *type, SpaTypeMap *map)
|
2017-03-23 12:38:00 +01:00
|
|
|
{
|
2017-03-24 11:40:58 +01:00
|
|
|
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
|
2017-03-24 18:11:11 +01:00
|
|
|
spa_type_media_type_map (map, &type->media_type);
|
|
|
|
|
spa_type_media_subtype_map (map, &type->media_subtype);
|
|
|
|
|
spa_type_format_audio_map (map, &type->format_audio);
|
2017-03-24 11:40:58 +01:00
|
|
|
spa_type_command_node_map (map, &type->command_node);
|
2017-03-23 12:38:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
struct _SpaAudioMixer {
|
|
|
|
|
SpaHandle handle;
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaNode node;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
Type type;
|
|
|
|
|
SpaTypeMap *map;
|
2016-10-07 13:14:32 +02:00
|
|
|
SpaLog *log;
|
|
|
|
|
|
2017-03-23 21:15:52 +01:00
|
|
|
SpaEventNodeCallback event_cb;
|
2016-06-28 12:21:56 +02:00
|
|
|
void *user_data;
|
|
|
|
|
|
|
|
|
|
int port_count;
|
|
|
|
|
int port_queued;
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaAudioMixerPort in_ports[MAX_PORTS];
|
|
|
|
|
SpaAudioMixerPort out_ports[1];
|
2017-04-03 14:56:04 +02:00
|
|
|
|
|
|
|
|
#define STATE_ERROR 0
|
|
|
|
|
#define STATE_IN 1
|
|
|
|
|
#define STATE_OUT 2
|
|
|
|
|
int state;
|
2016-06-28 12:21:56 +02:00
|
|
|
};
|
|
|
|
|
|
2016-10-03 19:43:42 +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)
|
|
|
|
|
#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))
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
enum {
|
|
|
|
|
PROP_ID_LAST,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_get_props (SpaNode *node,
|
2016-06-28 12:21:56 +02:00
|
|
|
SpaProps **props)
|
|
|
|
|
{
|
2017-02-28 10:48:53 +01:00
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_set_props (SpaNode *node,
|
2016-06-28 12:21:56 +02:00
|
|
|
const SpaProps *props)
|
|
|
|
|
{
|
2017-02-28 10:48:53 +01:00
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-22 08:55:30 +02:00
|
|
|
static void
|
|
|
|
|
update_state (SpaAudioMixer *this, SpaNodeState state)
|
|
|
|
|
{
|
|
|
|
|
this->node.state = state;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static SpaResult
|
2017-03-22 10:04:24 +01:00
|
|
|
spa_audiomixer_node_send_command (SpaNode *node,
|
|
|
|
|
SpaCommand *command)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
if (node == NULL || command == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
|
2017-03-22 10:04:24 +01:00
|
|
|
update_state (this, SPA_NODE_STATE_STREAMING);
|
|
|
|
|
}
|
2017-03-24 11:40:58 +01:00
|
|
|
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
|
2017-03-22 10:04:24 +01:00
|
|
|
update_state (this, SPA_NODE_STATE_PAUSED);
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2017-03-22 10:04:24 +01:00
|
|
|
else
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-09-06 16:43:37 +02:00
|
|
|
spa_audiomixer_node_set_event_callback (SpaNode *node,
|
2017-03-23 21:15:52 +01:00
|
|
|
SpaEventNodeCallback event,
|
2016-09-06 16:43:37 +02:00
|
|
|
void *user_data)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
if (node == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
this->event_cb = event;
|
|
|
|
|
this->user_data = user_data;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_get_n_ports (SpaNode *node,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t *n_input_ports,
|
|
|
|
|
uint32_t *max_input_ports,
|
|
|
|
|
uint32_t *n_output_ports,
|
|
|
|
|
uint32_t *max_output_ports)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-10-12 17:27:29 +02:00
|
|
|
if (node == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
|
|
|
|
if (n_input_ports)
|
|
|
|
|
*n_input_ports = 0;
|
|
|
|
|
if (max_input_ports)
|
|
|
|
|
*max_input_ports = MAX_PORTS;
|
2016-10-03 19:43:42 +02:00
|
|
|
if (n_output_ports)
|
|
|
|
|
*n_output_ports = 1;
|
2016-06-28 12:21:56 +02:00
|
|
|
if (max_output_ports)
|
|
|
|
|
*max_output_ports = 1;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_get_port_ids (SpaNode *node,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_input_ports,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t *input_ids,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_output_ports,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t *output_ids)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
int i, idx;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
if (node == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
if (input_ids) {
|
2016-09-30 19:56:41 +02:00
|
|
|
for (i = 0, idx = 0; i < MAX_PORTS && idx < n_input_ports; i++) {
|
2016-10-03 19:43:42 +02:00
|
|
|
if (this->in_ports[i].valid)
|
2016-06-28 12:21:56 +02:00
|
|
|
input_ids[idx++] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (n_output_ports > 0 && output_ids)
|
2016-10-03 19:43:42 +02:00
|
|
|
output_ids[0] = 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_add_port (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-07-30 20:35:34 +02:00
|
|
|
uint32_t port_id)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
if (node == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (!CHECK_FREE_IN_PORT (this, direction, port_id))
|
2016-07-30 20:35:34 +02:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
this->in_ports[port_id].valid = true;
|
2016-06-28 12:21:56 +02:00
|
|
|
this->port_count++;
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_list_init (&this->in_ports[port_id].queue);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
this->in_ports[port_id].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
2016-07-30 20:35:34 +02:00
|
|
|
SPA_PORT_INFO_FLAG_REMOVABLE |
|
|
|
|
|
SPA_PORT_INFO_FLAG_OPTIONAL |
|
|
|
|
|
SPA_PORT_INFO_FLAG_IN_PLACE;
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_remove_port (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
2017-04-03 14:56:04 +02:00
|
|
|
SpaPortIO *io;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
if (node == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-11-07 18:23:09 +01:00
|
|
|
if (!CHECK_IN_PORT (this, SPA_DIRECTION_INPUT, port_id))
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
this->in_ports[port_id].valid = false;
|
2016-06-28 12:21:56 +02:00
|
|
|
this->port_count--;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
io = this->in_ports[port_id].io;
|
|
|
|
|
if (io && io->buffer_id) {
|
2016-06-28 12:21:56 +02:00
|
|
|
this->port_queued--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_port_enum_formats (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id,
|
2016-07-15 18:22:29 +02:00
|
|
|
SpaFormat **format,
|
|
|
|
|
const SpaFormat *filter,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t index)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-02-01 08:58:21 +01:00
|
|
|
if (node == NULL || format == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
}
|
2017-02-24 09:28:18 +01:00
|
|
|
*format = NULL;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
static SpaResult
|
|
|
|
|
clear_buffers (SpaAudioMixer *this, SpaAudioMixerPort *port)
|
|
|
|
|
{
|
|
|
|
|
if (port->n_buffers > 0) {
|
|
|
|
|
spa_log_info (this->log, "audio-mixer %p: clear buffers", this);
|
|
|
|
|
port->n_buffers = 0;
|
|
|
|
|
spa_list_init (&port->queue);
|
|
|
|
|
}
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_port_set_format (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-07-18 10:35:02 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaPortFormatFlags flags,
|
|
|
|
|
const SpaFormat *format)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
SpaAudioMixerPort *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
if (node == NULL || format == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0];
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
if (format == NULL) {
|
2016-07-30 20:35:34 +02:00
|
|
|
port->have_format = false;
|
2017-04-03 14:56:04 +02:00
|
|
|
clear_buffers (this, port);
|
2017-03-24 18:11:11 +01:00
|
|
|
} else {
|
|
|
|
|
SpaAudioInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
|
|
|
|
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-24 18:11:11 +01:00
|
|
|
if (info.media_type != this->type.media_type.audio ||
|
|
|
|
|
info.media_subtype != this->type.media_subtype.raw)
|
|
|
|
|
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-24 18:11:11 +01:00
|
|
|
if (!spa_format_audio_raw_parse (format, &info.info.raw, &this->type.format_audio))
|
|
|
|
|
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-24 18:11:11 +01:00
|
|
|
port->format = info;
|
|
|
|
|
port->have_format = true;
|
|
|
|
|
}
|
2017-04-03 14:56:04 +02:00
|
|
|
|
|
|
|
|
if (port->have_format) {
|
|
|
|
|
update_state (this, SPA_NODE_STATE_READY);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
update_state (this, SPA_NODE_STATE_CONFIGURE);
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_port_get_format (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
const SpaFormat **format)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
SpaAudioMixerPort *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
if (node == NULL || format == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0];
|
2016-07-30 20:35:34 +02:00
|
|
|
|
|
|
|
|
if (!port->have_format)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_NO_FORMAT;
|
|
|
|
|
|
2017-02-24 09:28:18 +01:00
|
|
|
*format = NULL;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_port_get_info (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
const SpaPortInfo **info)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
SpaAudioMixerPort *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
if (node == NULL || info == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[0];
|
2016-07-30 20:35:34 +02:00
|
|
|
*info = &port->info;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-10-03 19:43:42 +02:00
|
|
|
spa_audiomixer_node_port_get_props (SpaNode *node,
|
|
|
|
|
SpaDirection direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaProps **props)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_port_set_props (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
const SpaProps *props)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-02 16:34:44 +02:00
|
|
|
static SpaResult
|
|
|
|
|
spa_audiomixer_node_port_use_buffers (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-08-02 16:34:44 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaBuffer **buffers,
|
|
|
|
|
uint32_t n_buffers)
|
|
|
|
|
{
|
2017-04-03 14:56:04 +02:00
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
SpaAudioMixerPort *port;
|
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
|
|
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
|
|
|
|
|
|
|
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail (port->have_format, SPA_RESULT_NO_FORMAT);
|
|
|
|
|
|
|
|
|
|
clear_buffers (this, port);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_buffers; i++) {
|
|
|
|
|
MixerBuffer *b;
|
|
|
|
|
SpaData *d = buffers[i]->datas;
|
|
|
|
|
|
|
|
|
|
b = &port->buffers[i];
|
|
|
|
|
b->outbuf = buffers[i];
|
|
|
|
|
b->outstanding = true;
|
|
|
|
|
b->h = spa_buffer_find_meta (buffers[i], SPA_META_TYPE_HEADER);
|
|
|
|
|
|
|
|
|
|
switch (d[0].type) {
|
|
|
|
|
case SPA_DATA_TYPE_MEMPTR:
|
|
|
|
|
case SPA_DATA_TYPE_MEMFD:
|
|
|
|
|
case SPA_DATA_TYPE_DMABUF:
|
|
|
|
|
if (d[0].data == NULL) {
|
|
|
|
|
spa_log_error (this->log, "volume %p: invalid memory on buffer %p", this, buffers[i]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
b->ptr = d[0].data;
|
|
|
|
|
b->size = d[0].maxsize;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
spa_list_insert (port->queue.prev, &b->link);
|
|
|
|
|
}
|
|
|
|
|
port->n_buffers = n_buffers;
|
|
|
|
|
|
|
|
|
|
if (port->n_buffers > 0) {
|
|
|
|
|
update_state (this, SPA_NODE_STATE_PAUSED);
|
|
|
|
|
} else {
|
|
|
|
|
update_state (this, SPA_NODE_STATE_READY);
|
|
|
|
|
}
|
|
|
|
|
return SPA_RESULT_OK;
|
2016-08-02 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
spa_audiomixer_node_port_alloc_buffers (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-08-02 16:34:44 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaAllocParam **params,
|
|
|
|
|
uint32_t n_params,
|
|
|
|
|
SpaBuffer **buffers,
|
|
|
|
|
uint32_t *n_buffers)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static SpaResult
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_audiomixer_node_port_set_io (SpaNode *node,
|
|
|
|
|
SpaDirection direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaPortIO *io)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
|
|
|
|
SpaAudioMixer *this;
|
2017-04-03 14:56:04 +02:00
|
|
|
SpaAudioMixerPort *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-11-07 18:23:09 +01:00
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
|
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
|
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
2016-11-07 18:23:09 +01:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
port->io = io;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-08 20:12:56 +02:00
|
|
|
static SpaResult
|
2016-11-07 18:23:09 +01:00
|
|
|
spa_audiomixer_node_port_reuse_buffer (SpaNode *node,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t buffer_id)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
spa_audiomixer_node_port_send_command (SpaNode *node,
|
|
|
|
|
SpaDirection direction,
|
|
|
|
|
uint32_t port_id,
|
2017-03-22 10:04:24 +01:00
|
|
|
SpaCommand *command)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
static void
|
|
|
|
|
add_port_data (SpaAudioMixer *this, MixerBuffer *out, SpaAudioMixerPort *port)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
uint8_t *op, *ip;
|
|
|
|
|
size_t os, is, chunk;
|
|
|
|
|
MixerBuffer *b = spa_list_first (&port->queue, MixerBuffer, link);
|
|
|
|
|
|
|
|
|
|
op = out->ptr;
|
|
|
|
|
os = out->size;
|
|
|
|
|
ip = SPA_MEMBER (b->ptr, port->queued_offset + b->outbuf->datas[0].chunk->offset, void);
|
|
|
|
|
is = b->outbuf->datas[0].chunk->size - port->queued_offset;
|
|
|
|
|
|
|
|
|
|
chunk = SPA_MIN (os, is);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < chunk; i++)
|
|
|
|
|
op[i] += ip[i];
|
|
|
|
|
|
|
|
|
|
port->queued_offset += chunk;
|
|
|
|
|
port->queued_bytes -= chunk;
|
|
|
|
|
|
|
|
|
|
if (chunk == is) {
|
|
|
|
|
spa_log_trace (this->log, "audiomixer %p: return buffer %d on port %p", this, b->outbuf->id, port);
|
|
|
|
|
port->io->buffer_id = b->outbuf->id;
|
|
|
|
|
spa_list_remove (&b->link);
|
|
|
|
|
b->outstanding = true;
|
|
|
|
|
port->queued_offset = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 18:23:09 +01:00
|
|
|
static SpaResult
|
|
|
|
|
spa_audiomixer_node_process_input (SpaNode *node)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t i;
|
2017-04-03 14:56:04 +02:00
|
|
|
SpaAudioMixerPort *outport;
|
|
|
|
|
size_t min_queued = -1;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (this->state == STATE_OUT)
|
|
|
|
|
return SPA_RESULT_HAVE_OUTPUT;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
outport = &this->out_ports[0];
|
|
|
|
|
spa_return_val_if_fail (outport->io != NULL, SPA_RESULT_ERROR);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-11-07 18:23:09 +01:00
|
|
|
for (i = 0; i < MAX_PORTS; i++) {
|
|
|
|
|
SpaAudioMixerPort *port = &this->in_ports[i];
|
2017-04-03 14:56:04 +02:00
|
|
|
SpaPortIO *input;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (!port->valid || (input = port->io) == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
continue;
|
|
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (input->buffer_id != SPA_ID_INVALID) {
|
|
|
|
|
MixerBuffer *b = &port->buffers[input->buffer_id];
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (spa_list_is_empty (&port->queue)) {
|
|
|
|
|
port->queued_bytes = 0;
|
|
|
|
|
port->queued_offset = 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_log_trace (this->log, "audiomixer %p: queue buffer %d on port %p", this, b->outbuf->id, port);
|
|
|
|
|
spa_list_insert (port->queue.prev, &b->link);
|
|
|
|
|
b->outstanding = false;
|
|
|
|
|
port->queued_bytes += b->size;
|
|
|
|
|
input->buffer_id = SPA_ID_INVALID;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2017-04-03 14:56:04 +02:00
|
|
|
if (min_queued == -1 || port->queued_bytes < min_queued)
|
|
|
|
|
min_queued = port->queued_bytes;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
input->status = SPA_RESULT_OK;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (min_queued != -1) {
|
|
|
|
|
MixerBuffer *outbuf;
|
|
|
|
|
SpaPortIO *output;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (spa_list_is_empty (&outport->queue))
|
|
|
|
|
return SPA_RESULT_OUT_OF_BUFFERS;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
outbuf = spa_list_first (&outport->queue, MixerBuffer, link);
|
|
|
|
|
spa_list_remove (&outbuf->link);
|
|
|
|
|
spa_log_trace (this->log, "audiomixer %p: dequeue output buffer %d", this, outbuf->outbuf->id);
|
|
|
|
|
outbuf->outstanding = true;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
for (i = 0; i < MAX_PORTS; i++) {
|
|
|
|
|
SpaAudioMixerPort *port = &this->in_ports[i];
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (!port->valid || port->io == NULL ||
|
|
|
|
|
spa_list_is_empty (&port->queue))
|
|
|
|
|
continue;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
add_port_data (this, outbuf, port);
|
|
|
|
|
}
|
|
|
|
|
output = outport->io;
|
|
|
|
|
output->buffer_id = outbuf->outbuf->id;
|
|
|
|
|
output->state = SPA_RESULT_OK;
|
|
|
|
|
this->state = STATE_OUT;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2017-04-03 14:56:04 +02:00
|
|
|
return this->state == STATE_IN ? SPA_RESULT_NEED_INPUT : SPA_RESULT_HAVE_OUTPUT;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-11-07 18:23:09 +01:00
|
|
|
spa_audiomixer_node_process_output (SpaNode *node)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
SpaAudioMixerPort *port;
|
2017-04-03 14:56:04 +02:00
|
|
|
SpaPortIO *output;
|
|
|
|
|
int i;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioMixer, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-11-07 18:23:09 +01:00
|
|
|
port = &this->out_ports[0];
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_return_val_if_fail (port->io != NULL, SPA_RESULT_ERROR);
|
|
|
|
|
output = port->io;
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_return_val_if_fail (port->have_format, SPA_RESULT_NO_FORMAT);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
for (i = 0; i < MAX_PORTS; i++) {
|
|
|
|
|
SpaPortIO *input;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (!this->in_ports[i].valid || (input = this->in_ports[i].io) == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
input->flags = output->flags;
|
|
|
|
|
input->range = output->range;
|
|
|
|
|
}
|
|
|
|
|
if (output->buffer_id != SPA_ID_INVALID) {
|
|
|
|
|
MixerBuffer *b = &port->buffers[output->buffer_id];
|
|
|
|
|
if (b->outstanding) {
|
|
|
|
|
spa_list_insert (port->queue.prev, &b->link);
|
|
|
|
|
b->outstanding = false;
|
|
|
|
|
spa_log_trace (this->log, "audiomixer %p: recycle buffer %d", this, b->outbuf->id);
|
|
|
|
|
}
|
|
|
|
|
output->buffer_id = SPA_ID_INVALID;
|
|
|
|
|
}
|
|
|
|
|
this->state = STATE_IN;
|
|
|
|
|
return SPA_RESULT_NEED_INPUT;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const SpaNode audiomixer_node = {
|
|
|
|
|
sizeof (SpaNode),
|
2016-09-15 17:51:34 +02:00
|
|
|
NULL,
|
2016-09-05 16:23:40 +02:00
|
|
|
SPA_NODE_STATE_INIT,
|
2016-06-28 12:21:56 +02:00
|
|
|
spa_audiomixer_node_get_props,
|
|
|
|
|
spa_audiomixer_node_set_props,
|
|
|
|
|
spa_audiomixer_node_send_command,
|
|
|
|
|
spa_audiomixer_node_set_event_callback,
|
|
|
|
|
spa_audiomixer_node_get_n_ports,
|
|
|
|
|
spa_audiomixer_node_get_port_ids,
|
|
|
|
|
spa_audiomixer_node_add_port,
|
|
|
|
|
spa_audiomixer_node_remove_port,
|
2016-07-08 20:12:56 +02:00
|
|
|
spa_audiomixer_node_port_enum_formats,
|
|
|
|
|
spa_audiomixer_node_port_set_format,
|
|
|
|
|
spa_audiomixer_node_port_get_format,
|
|
|
|
|
spa_audiomixer_node_port_get_info,
|
|
|
|
|
spa_audiomixer_node_port_get_props,
|
|
|
|
|
spa_audiomixer_node_port_set_props,
|
|
|
|
|
spa_audiomixer_node_port_use_buffers,
|
|
|
|
|
spa_audiomixer_node_port_alloc_buffers,
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_audiomixer_node_port_set_io,
|
2016-10-03 19:43:42 +02:00
|
|
|
spa_audiomixer_node_port_reuse_buffer,
|
2016-10-21 14:57:01 +02:00
|
|
|
spa_audiomixer_node_port_send_command,
|
2016-11-07 18:23:09 +01:00
|
|
|
spa_audiomixer_node_process_input,
|
|
|
|
|
spa_audiomixer_node_process_output,
|
2016-06-28 12:21:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
spa_audiomixer_get_interface (SpaHandle *handle,
|
|
|
|
|
uint32_t interface_id,
|
2016-07-30 20:35:34 +02:00
|
|
|
void **interface)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
if (handle == NULL || interface == 0)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) handle;
|
|
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
if (interface_id == this->type.node)
|
2016-10-07 13:14:32 +02:00
|
|
|
*interface = &this->node;
|
|
|
|
|
else
|
|
|
|
|
return SPA_RESULT_UNKNOWN_INTERFACE;
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-01 10:04:25 +02:00
|
|
|
static SpaResult
|
|
|
|
|
spa_audiomixer_clear (SpaHandle *handle)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-13 18:29:55 +02:00
|
|
|
static SpaResult
|
|
|
|
|
spa_audiomixer_init (const SpaHandleFactory *factory,
|
2016-09-15 11:49:34 +02:00
|
|
|
SpaHandle *handle,
|
2016-10-05 17:43:11 +02:00
|
|
|
const SpaDict *info,
|
2016-10-07 13:14:32 +02:00
|
|
|
const SpaSupport *support,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_support)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
|
|
|
|
SpaAudioMixer *this;
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t i;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-07-13 18:29:55 +02:00
|
|
|
if (factory == NULL || handle == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
handle->get_interface = spa_audiomixer_get_interface;
|
2016-09-01 10:04:25 +02:00
|
|
|
handle->clear = spa_audiomixer_clear;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
this = (SpaAudioMixer *) handle;
|
2016-10-07 13:14:32 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < n_support; i++) {
|
2017-03-24 11:40:58 +01:00
|
|
|
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
|
2016-10-07 13:14:32 +02:00
|
|
|
this->map = support[i].data;
|
2017-03-24 11:40:58 +01:00
|
|
|
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
|
2016-10-07 13:14:32 +02:00
|
|
|
this->log = support[i].data;
|
|
|
|
|
}
|
|
|
|
|
if (this->map == NULL) {
|
|
|
|
|
spa_log_error (this->log, "an id-map is needed");
|
|
|
|
|
return SPA_RESULT_ERROR;
|
|
|
|
|
}
|
2017-03-24 11:40:58 +01:00
|
|
|
init_type (&this->type, this->map);
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this->node = audiomixer_node;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
this->out_ports[0].valid = true;
|
2017-04-03 14:56:04 +02:00
|
|
|
this->out_ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
2016-10-03 19:43:42 +02:00
|
|
|
SPA_PORT_INFO_FLAG_NO_REF;
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_list_init (&this->out_ports[0].queue);
|
|
|
|
|
|
2016-07-13 18:29:55 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const SpaInterfaceInfo audiomixer_interfaces[] =
|
|
|
|
|
{
|
2017-03-23 21:15:52 +01:00
|
|
|
{ SPA_TYPE__Node, },
|
2016-07-13 18:29:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
audiomixer_enum_interface_info (const SpaHandleFactory *factory,
|
2016-07-15 18:22:29 +02:00
|
|
|
const SpaInterfaceInfo **info,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t index)
|
2016-07-13 18:29:55 +02:00
|
|
|
{
|
2017-02-01 08:58:21 +01:00
|
|
|
if (factory == NULL || info == NULL)
|
2016-07-15 18:22:29 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
2016-07-13 18:29:55 +02:00
|
|
|
|
2016-07-15 18:22:29 +02:00
|
|
|
switch (index) {
|
|
|
|
|
case 0:
|
|
|
|
|
*info = &audiomixer_interfaces[index];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
}
|
2016-07-13 18:29:55 +02:00
|
|
|
return SPA_RESULT_OK;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2016-07-13 18:29:55 +02:00
|
|
|
|
|
|
|
|
const SpaHandleFactory spa_audiomixer_factory =
|
|
|
|
|
{ "audiomixer",
|
|
|
|
|
NULL,
|
|
|
|
|
sizeof (SpaAudioMixer),
|
|
|
|
|
spa_audiomixer_init,
|
|
|
|
|
audiomixer_enum_interface_info,
|
|
|
|
|
};
|