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>
|
|
|
|
|
|
|
|
|
|
#include <spa/node.h>
|
2016-07-05 17:58:34 +02:00
|
|
|
#include <spa/audio/format.h>
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
#define MAX_PORTS 128
|
|
|
|
|
|
|
|
|
|
typedef struct _SpaAudioMixer SpaAudioMixer;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
SpaProps props;
|
|
|
|
|
} SpaAudioMixerProps;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
SpaProps prop;
|
|
|
|
|
} SpaAudioMixerPortProps;
|
|
|
|
|
|
|
|
|
|
typedef struct _MixerBuffer MixerBuffer;
|
|
|
|
|
|
|
|
|
|
struct _MixerBuffer {
|
|
|
|
|
SpaBuffer buffer;
|
|
|
|
|
SpaMeta meta[1];
|
|
|
|
|
SpaMetaHeader header;
|
|
|
|
|
SpaData data[1];
|
|
|
|
|
uint16_t samples[4096];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
bool valid;
|
2016-07-30 20:35:34 +02:00
|
|
|
bool have_format;
|
2016-08-26 19:22:50 +02:00
|
|
|
SpaFormatAudio format[2];
|
2016-07-07 09:30:18 +02:00
|
|
|
SpaAudioMixerPortProps props[2];
|
2016-06-28 12:21:56 +02:00
|
|
|
SpaPortInfo info;
|
|
|
|
|
SpaPortStatus status;
|
|
|
|
|
size_t buffer_index;
|
|
|
|
|
size_t buffer_offset;
|
|
|
|
|
size_t buffer_queued;
|
|
|
|
|
MixerBuffer mix;
|
2016-07-30 20:35:34 +02:00
|
|
|
|
|
|
|
|
SpaBuffer **buffers;
|
|
|
|
|
unsigned int n_buffers;
|
|
|
|
|
SpaBuffer *buffer;
|
2016-06-28 12:21:56 +02:00
|
|
|
} SpaAudioMixerPort;
|
|
|
|
|
|
|
|
|
|
struct _SpaAudioMixer {
|
|
|
|
|
SpaHandle handle;
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaNode node;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-07-07 09:30:18 +02:00
|
|
|
SpaAudioMixerProps props[2];
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
SpaNodeEventCallback 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];
|
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 const SpaPropInfo prop_info[] =
|
|
|
|
|
{
|
|
|
|
|
{ PROP_ID_LAST, },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
reset_audiomixer_props (SpaAudioMixerProps *props)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL || props == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
2016-07-07 09:30:18 +02:00
|
|
|
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
|
|
|
|
|
*props = &this->props[0].props;
|
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_set_props (SpaNode *node,
|
2016-06-28 12:21:56 +02:00
|
|
|
const SpaProps *props)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
SpaAudioMixerProps *p;
|
2016-06-28 12:21:56 +02:00
|
|
|
SpaResult res;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
p = &this->props[1];
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
if (props == NULL) {
|
|
|
|
|
reset_audiomixer_props (p);
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
2016-09-29 18:18:59 +02:00
|
|
|
res = spa_props_copy_values (props, &p->props);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2016-09-06 16:43:37 +02:00
|
|
|
spa_audiomixer_node_send_command (SpaNode *node,
|
|
|
|
|
SpaNodeCommand *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-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL || command == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
switch (command->type) {
|
2016-09-06 16:43:37 +02:00
|
|
|
case SPA_NODE_COMMAND_INVALID:
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_COMMAND;
|
|
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
case SPA_NODE_COMMAND_START:
|
2016-09-22 08:55:30 +02:00
|
|
|
update_state (this, SPA_NODE_STATE_STREAMING);
|
2016-06-28 12:21:56 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
case SPA_NODE_COMMAND_PAUSE:
|
2016-09-22 08:55:30 +02:00
|
|
|
update_state (this, SPA_NODE_STATE_PAUSED);
|
2016-06-28 12:21:56 +02:00
|
|
|
break;
|
|
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
case SPA_NODE_COMMAND_FLUSH:
|
|
|
|
|
case SPA_NODE_COMMAND_DRAIN:
|
|
|
|
|
case SPA_NODE_COMMAND_MARKER:
|
2016-09-09 16:05:58 +02:00
|
|
|
case SPA_NODE_COMMAND_CLOCK_UPDATE:
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-09-06 16:43:37 +02:00
|
|
|
spa_audiomixer_node_set_event_callback (SpaNode *node,
|
|
|
|
|
SpaNodeEventCallback event,
|
|
|
|
|
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-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
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,
|
2016-06-28 12:21:56 +02:00
|
|
|
unsigned int *n_input_ports,
|
|
|
|
|
unsigned int *max_input_ports,
|
|
|
|
|
unsigned int *n_output_ports,
|
|
|
|
|
unsigned int *max_output_ports)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == 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,
|
2016-06-28 12:21:56 +02:00
|
|
|
unsigned int n_input_ports,
|
|
|
|
|
uint32_t *input_ids,
|
|
|
|
|
unsigned int n_output_ports,
|
|
|
|
|
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-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
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-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
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++;
|
|
|
|
|
|
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-10-03 19:43:42 +02:00
|
|
|
this->in_ports[port_id].status.flags = SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
this->out_ports[0].status.flags &= ~SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
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;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (!CHECK_IN_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
|
|
|
this->in_ports[port_id].valid = false;
|
2016-06-28 12:21:56 +02:00
|
|
|
this->port_count--;
|
2016-10-03 19:43:42 +02:00
|
|
|
if (this->in_ports[port_id].buffer) {
|
|
|
|
|
this->in_ports[port_id].buffer = NULL;
|
2016-06-28 12:21:56 +02:00
|
|
|
this->port_queued--;
|
|
|
|
|
}
|
|
|
|
|
if (this->port_count == this->port_queued)
|
2016-10-03 19:43:42 +02:00
|
|
|
this->out_ports[0].status.flags |= SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
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_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,
|
|
|
|
|
void **state)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
SpaAudioMixerPort *port;
|
2016-07-15 18:22:29 +02:00
|
|
|
int index;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
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-07-15 18:22:29 +02:00
|
|
|
index = (*state == NULL ? 0 : *(int*)state);
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
switch (index) {
|
|
|
|
|
case 0:
|
2016-08-26 19:22:50 +02:00
|
|
|
spa_format_audio_init (SPA_MEDIA_TYPE_AUDIO,
|
|
|
|
|
SPA_MEDIA_SUBTYPE_RAW,
|
|
|
|
|
&port->format[0]);
|
2016-06-28 12:21:56 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
}
|
2016-07-30 20:35:34 +02:00
|
|
|
*format = &port->format[0].format;
|
2016-07-28 21:19:20 +02:00
|
|
|
*(int*)state = ++index;
|
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_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
|
|
|
SpaResult res;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL || format == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
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;
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 19:22:50 +02:00
|
|
|
if ((res = spa_format_audio_parse (format, &port->format[1])) < 0)
|
2016-06-28 12:21:56 +02:00
|
|
|
return res;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
port->have_format = true;
|
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-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL || format == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
*format = &port->format[1].format;
|
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-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL || info == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_port_get_status (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 SpaPortStatus **status)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
SpaAudioMixerPort *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL || status == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
*status = &port->status;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-08 20:12:56 +02:00
|
|
|
static SpaResult
|
2016-09-06 16:43:37 +02:00
|
|
|
spa_audiomixer_node_port_push_input (SpaNode *node,
|
|
|
|
|
unsigned int n_info,
|
|
|
|
|
SpaPortInputInfo *info)
|
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
|
|
|
unsigned int i;
|
|
|
|
|
bool have_error = false;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (this->out_ports[0].status.flags & SPA_PORT_STATUS_FLAG_HAVE_OUTPUT)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_HAVE_ENOUGH_INPUT;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_info; i++) {
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaBuffer *buffer;
|
|
|
|
|
SpaAudioMixerPort *port;
|
2016-06-28 12:21:56 +02:00
|
|
|
int idx = info[i].port_id;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (!CHECK_IN_PORT (this, SPA_DIRECTION_INPUT, idx)) {
|
2016-06-28 12:21:56 +02:00
|
|
|
info[i].status = SPA_RESULT_INVALID_PORT;
|
|
|
|
|
have_error = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-10-03 19:43:42 +02:00
|
|
|
port = &this->in_ports[idx];
|
2016-08-02 16:34:44 +02:00
|
|
|
buffer = port->buffers[info[i].buffer_id];
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
if (buffer == NULL) {
|
2016-06-28 12:21:56 +02:00
|
|
|
info[i].status = SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
have_error = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buffer) {
|
2016-07-30 20:35:34 +02:00
|
|
|
if (!port->have_format) {
|
2016-06-28 12:21:56 +02:00
|
|
|
info[i].status = SPA_RESULT_NO_FORMAT;
|
|
|
|
|
have_error = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (port->buffer != NULL) {
|
2016-06-28 12:21:56 +02:00
|
|
|
info[i].status = SPA_RESULT_HAVE_ENOUGH_INPUT;
|
|
|
|
|
have_error = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-10-03 19:43:42 +02:00
|
|
|
port->buffer = buffer;
|
|
|
|
|
port->buffer_queued = 0;
|
|
|
|
|
port->buffer_index = 0;
|
|
|
|
|
port->buffer_offset = 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
this->port_queued++;
|
|
|
|
|
|
|
|
|
|
if (this->port_queued == this->port_count)
|
2016-10-03 19:43:42 +02:00
|
|
|
this->out_ports[0].status.flags |= SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
info[i].status = SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
if (have_error)
|
|
|
|
|
return SPA_RESULT_ERROR;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2016-09-06 16:43:37 +02:00
|
|
|
pull_port (SpaAudioMixer *this, uint32_t port_id, SpaPortOutputInfo *info, size_t pull_size)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-09-06 16:43:37 +02:00
|
|
|
SpaNodeEvent event;
|
|
|
|
|
SpaNodeEventNeedInput ni;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-09-06 16:43:37 +02:00
|
|
|
event.type = SPA_NODE_EVENT_TYPE_NEED_INPUT;
|
2016-08-29 18:31:53 +02:00
|
|
|
event.size = sizeof (ni);
|
|
|
|
|
event.data = ∋
|
|
|
|
|
ni.port_id = port_id;
|
2016-07-30 20:35:34 +02:00
|
|
|
this->event_cb (&this->node, &event, this->user_data);
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_port_data (SpaAudioMixer *this, SpaBuffer *out, SpaAudioMixerPort *port)
|
|
|
|
|
{
|
|
|
|
|
int i, oi = 0;
|
|
|
|
|
uint8_t *op, *ip;
|
|
|
|
|
size_t os, is, chunk;
|
2016-09-29 18:18:59 +02:00
|
|
|
SpaData *odatas = out->datas;
|
|
|
|
|
SpaData *idatas = port->buffer->datas;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
op = ip = NULL;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
if (op == NULL) {
|
2016-09-29 18:18:59 +02:00
|
|
|
op = (uint8_t*)odatas[oi].data + odatas[oi].offset;
|
|
|
|
|
os = odatas[oi].size;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
if (ip == NULL) {
|
2016-09-29 18:18:59 +02:00
|
|
|
ip = (uint8_t*)idatas[port->buffer_index].data + idatas[port->buffer_index].offset;
|
|
|
|
|
is = idatas[port->buffer_index].size;
|
2016-06-28 12:21:56 +02:00
|
|
|
ip += port->buffer_offset;
|
|
|
|
|
is -= port->buffer_offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chunk = os < is ? os : is;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < chunk; i++)
|
|
|
|
|
op[i] += ip[i];
|
|
|
|
|
|
|
|
|
|
if ((is -= chunk) == 0) {
|
|
|
|
|
if (++port->buffer_index == port->buffer->n_datas) {
|
|
|
|
|
port->buffer = NULL;
|
|
|
|
|
port->status.flags = SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
2016-10-03 19:43:42 +02:00
|
|
|
this->out_ports[0].status.flags &= ~SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
2016-06-28 12:21:56 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
port->buffer_offset = 0;
|
|
|
|
|
ip = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
port->buffer_offset += chunk;
|
|
|
|
|
}
|
|
|
|
|
port->buffer_queued -= chunk;
|
|
|
|
|
|
|
|
|
|
if ((os -= chunk) == 0) {
|
|
|
|
|
if (++oi == out->n_datas)
|
|
|
|
|
break;
|
|
|
|
|
op = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-09-06 16:43:37 +02:00
|
|
|
mix_data (SpaAudioMixer *this, SpaPortOutputInfo *info)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
|
|
|
|
int i, min_size, min_port, pull_size;
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaBuffer *buf;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
if (info->port_id != 0)
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2016-08-24 16:26:58 +02:00
|
|
|
pull_size = 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
min_size = 0;
|
|
|
|
|
min_port = 0;
|
2016-10-03 19:43:42 +02:00
|
|
|
for (i = 0; i < MAX_PORTS; i++) {
|
|
|
|
|
if (!this->in_ports[i].valid)
|
2016-06-28 12:21:56 +02:00
|
|
|
continue;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (this->in_ports[i].buffer == NULL) {
|
2016-09-06 16:43:37 +02:00
|
|
|
if (pull_size && info->flags & SPA_PORT_OUTPUT_FLAG_PULL) {
|
2016-06-28 12:21:56 +02:00
|
|
|
pull_port (this, i, info, pull_size);
|
|
|
|
|
}
|
2016-10-03 19:43:42 +02:00
|
|
|
if (this->in_ports[i].buffer == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_NEED_MORE_INPUT;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (min_size == 0 || this->in_ports[i].buffer_queued < min_size) {
|
|
|
|
|
min_size = this->in_ports[i].buffer_queued;
|
2016-06-28 12:21:56 +02:00
|
|
|
min_port = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (min_port == 0)
|
|
|
|
|
return SPA_RESULT_NEED_MORE_INPUT;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
buf = this->in_ports[min_port].buffer;
|
2016-08-02 16:34:44 +02:00
|
|
|
info->buffer_id = buf->id;
|
2016-10-03 19:43:42 +02:00
|
|
|
this->in_ports[min_port].buffer = NULL;
|
|
|
|
|
this->in_ports[min_port].status.flags = SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
|
|
|
|
this->out_ports[0].status.flags &= ~SPA_PORT_STATUS_FLAG_HAVE_OUTPUT;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
for (i = 0; i < MAX_PORTS; i++) {
|
|
|
|
|
if (!this->in_ports[i].valid || this->in_ports[i].buffer == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
continue;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
add_port_data (this, buf, &this->in_ports[i]);
|
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_port_pull_output (SpaNode *node,
|
|
|
|
|
unsigned int n_info,
|
|
|
|
|
SpaPortOutputInfo *info)
|
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
|
|
|
int i;
|
|
|
|
|
bool have_error = false;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioMixer *) node->handle;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, info->port_id))
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
port = &this->out_ports[info->port_id];
|
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;
|
|
|
|
|
|
|
|
|
|
// if (!(this->ports[0].status.flags & SPA_PORT_STATUS_FLAG_HAVE_OUTPUT))
|
|
|
|
|
// return SPA_RESULT_NEED_MORE_INPUT;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_info; i++) {
|
|
|
|
|
if ((info[i].status = mix_data (this, &info[i])) < 0) {
|
|
|
|
|
printf ("error mixing: %d\n", info[i].status);
|
|
|
|
|
have_error = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (have_error)
|
|
|
|
|
return SPA_RESULT_ERROR;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
static SpaResult
|
|
|
|
|
spa_audiomixer_node_port_reuse_buffer (SpaNode *node,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t buffer_id)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
static SpaResult
|
2016-09-06 16:43:37 +02:00
|
|
|
spa_audiomixer_node_port_push_event (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-09-06 16:43:37 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaNodeEvent *event)
|
2016-07-30 20:35:34 +02:00
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static const SpaNode audiomixer_node = {
|
2016-07-30 20:35:34 +02:00
|
|
|
NULL,
|
2016-06-28 12:21:56 +02:00
|
|
|
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,
|
|
|
|
|
spa_audiomixer_node_port_get_status,
|
|
|
|
|
spa_audiomixer_node_port_push_input,
|
|
|
|
|
spa_audiomixer_node_port_pull_output,
|
2016-10-03 19:43:42 +02:00
|
|
|
spa_audiomixer_node_port_reuse_buffer,
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiomixer_node_port_push_event,
|
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;
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
switch (interface_id) {
|
|
|
|
|
case SPA_INTERFACE_ID_NODE:
|
2016-07-30 20:35:34 +02:00
|
|
|
*interface = &this->node;
|
2016-06-28 12:21:56 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return SPA_RESULT_UNKNOWN_INTERFACE;
|
|
|
|
|
}
|
|
|
|
|
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-05 21:05:22 +02:00
|
|
|
const SpaSupport **support,
|
|
|
|
|
unsigned int n_support)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
|
|
|
|
SpaAudioMixer *this;
|
|
|
|
|
|
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-07-30 20:35:34 +02:00
|
|
|
this->node = audiomixer_node;
|
|
|
|
|
this->node.handle = handle;
|
2016-07-07 09:30:18 +02:00
|
|
|
this->props[1].props.n_prop_info = PROP_ID_LAST;
|
|
|
|
|
this->props[1].props.prop_info = prop_info;
|
|
|
|
|
reset_audiomixer_props (&this->props[1]);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
this->out_ports[0].valid = true;
|
|
|
|
|
this->out_ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS |
|
|
|
|
|
SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
|
|
|
|
SPA_PORT_INFO_FLAG_NO_REF;
|
2016-07-13 18:29:55 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const SpaInterfaceInfo audiomixer_interfaces[] =
|
|
|
|
|
{
|
|
|
|
|
{ SPA_INTERFACE_ID_NODE,
|
|
|
|
|
SPA_INTERFACE_ID_NODE_NAME,
|
|
|
|
|
SPA_INTERFACE_ID_NODE_DESCRIPTION,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
audiomixer_enum_interface_info (const SpaHandleFactory *factory,
|
2016-07-15 18:22:29 +02:00
|
|
|
const SpaInterfaceInfo **info,
|
|
|
|
|
void **state)
|
2016-07-13 18:29:55 +02:00
|
|
|
{
|
2016-07-15 18:22:29 +02:00
|
|
|
int index;
|
2016-07-13 18:29:55 +02:00
|
|
|
|
2016-07-15 18:22:29 +02:00
|
|
|
if (factory == NULL || info == NULL || state == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
2016-07-13 18:29:55 +02:00
|
|
|
|
2016-07-15 18:22:29 +02:00
|
|
|
index = (*state == NULL ? 0 : *(int*)state);
|
|
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
|
case 0:
|
|
|
|
|
*info = &audiomixer_interfaces[index];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
}
|
|
|
|
|
*(int*)state = ++index;
|
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,
|
|
|
|
|
};
|