2016-06-28 12:21:56 +02:00
|
|
|
/* Spa ALSA Sink
|
|
|
|
|
* 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 <stddef.h>
|
|
|
|
|
|
|
|
|
|
#include <asoundlib.h>
|
|
|
|
|
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/node/node.h>
|
|
|
|
|
#include <spa/param/audio/format.h>
|
|
|
|
|
|
2017-11-09 17:07:04 +01:00
|
|
|
#include <lib/pod.h>
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
#define NAME "alsa-sink"
|
|
|
|
|
|
2016-09-19 09:16:58 +02:00
|
|
|
#include "alsa-utils.h"
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) == 0)
|
|
|
|
|
|
2017-06-06 13:30:34 +02:00
|
|
|
static const char default_device[] = "hw:0";
|
2017-09-07 19:55:22 +02:00
|
|
|
static const uint32_t default_min_latency = 128;
|
2017-10-31 15:59:08 +01:00
|
|
|
static const uint32_t default_max_latency = 1024;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static void reset_props(struct props *props)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
strncpy(props->device, default_device, 64);
|
|
|
|
|
props->min_latency = default_min_latency;
|
2017-10-31 15:59:08 +01:00
|
|
|
props->max_latency = default_max_latency;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
static int impl_node_enum_params(struct spa_node *node,
|
|
|
|
|
uint32_t id, uint32_t *index,
|
|
|
|
|
const struct spa_pod_object *filter,
|
|
|
|
|
struct spa_pod_builder *builder)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
2017-11-08 11:22:42 +01:00
|
|
|
struct type *t;
|
2017-11-09 17:07:04 +01:00
|
|
|
struct spa_pod *param;
|
2017-11-13 12:30:48 +01:00
|
|
|
struct spa_pod_builder_state state;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(index != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2017-11-08 11:22:42 +01:00
|
|
|
t = &this->type;
|
|
|
|
|
|
2017-11-13 12:30:48 +01:00
|
|
|
spa_pod_builder_get_state(builder, &state);
|
2017-11-09 17:07:04 +01:00
|
|
|
|
|
|
|
|
next:
|
2017-11-08 11:22:42 +01:00
|
|
|
if (id == t->param.idList) {
|
|
|
|
|
if (*index > 0)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-08 11:22:42 +01:00
|
|
|
|
2017-11-09 17:07:04 +01:00
|
|
|
param = spa_pod_builder_object(builder,
|
2017-11-08 11:22:42 +01:00
|
|
|
id, t->param.List,
|
|
|
|
|
":", t->param.listId, "I", t->param.idProps);
|
|
|
|
|
}
|
|
|
|
|
else if (id == t->param.idProps) {
|
|
|
|
|
struct props *p = &this->props;
|
|
|
|
|
|
|
|
|
|
if (*index > 0)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-09 17:07:04 +01:00
|
|
|
param = spa_pod_builder_object(builder,
|
|
|
|
|
id, t->props,
|
|
|
|
|
":", t->prop_device, "S", p->device, sizeof(p->device),
|
|
|
|
|
":", t->prop_device_name, "S-r", p->device_name, sizeof(p->device_name),
|
|
|
|
|
":", t->prop_card_name, "S-r", p->card_name, sizeof(p->card_name),
|
|
|
|
|
":", t->prop_min_latency, "ir", p->min_latency,
|
|
|
|
|
2, 1, INT32_MAX,
|
|
|
|
|
":", t->prop_max_latency, "ir", p->max_latency,
|
|
|
|
|
2, 1, INT32_MAX);
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
else
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOENT;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-08 11:22:42 +01:00
|
|
|
(*index)++;
|
|
|
|
|
|
2017-11-13 12:30:48 +01:00
|
|
|
spa_pod_builder_reset(builder, &state);
|
2017-11-09 17:07:04 +01:00
|
|
|
if (spa_pod_filter(builder, param, (struct spa_pod*)filter) < 0)
|
|
|
|
|
goto next;
|
|
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 1;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
|
|
|
|
|
const struct spa_pod_object *param)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
2017-11-08 11:22:42 +01:00
|
|
|
struct type *t;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2017-11-08 11:22:42 +01:00
|
|
|
t = &this->type;
|
|
|
|
|
|
|
|
|
|
if (id == t->param.idProps) {
|
|
|
|
|
struct props *p = &this->props;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
if (param == NULL) {
|
2017-11-08 11:22:42 +01:00
|
|
|
reset_props(p);
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
spa_pod_object_parse(param,
|
2017-11-08 11:22:42 +01:00
|
|
|
":", t->prop_device, "?S", p->device, sizeof(p->device),
|
|
|
|
|
":", t->prop_min_latency, "?i", &p->min_latency, NULL);
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2017-11-07 17:39:31 +01:00
|
|
|
else
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOENT;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-25 19:52:31 +02:00
|
|
|
static int do_send_done(struct spa_loop *loop, bool async, uint32_t seq, size_t size, const void *data, void *user_data)
|
2016-10-28 16:56:33 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this = user_data;
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-08-06 06:42:26 +02:00
|
|
|
this->callbacks->done(this->callbacks_data, seq, *(int*)data);
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-10-28 16:56:33 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-25 19:52:31 +02:00
|
|
|
static int do_command(struct spa_loop *loop, bool async, uint32_t seq, size_t size, const void *data, void *user_data)
|
2016-10-28 16:56:33 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this = user_data;
|
|
|
|
|
int res;
|
2017-07-25 19:52:31 +02:00
|
|
|
const struct spa_command *cmd = data;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
if (SPA_COMMAND_TYPE(cmd) == this->type.command_node.Start ||
|
|
|
|
|
SPA_COMMAND_TYPE(cmd) == this->type.command_node.Pause) {
|
|
|
|
|
res = spa_node_port_send_command(&this->node, SPA_DIRECTION_INPUT, 0, cmd);
|
|
|
|
|
} else
|
2017-11-13 09:41:41 +01:00
|
|
|
res = -ENOTSUP;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
if (async) {
|
|
|
|
|
spa_loop_invoke(this->main_loop,
|
2017-06-09 17:24:18 +02:00
|
|
|
do_send_done,
|
|
|
|
|
seq,
|
|
|
|
|
sizeof(res),
|
|
|
|
|
&res,
|
2017-06-26 10:41:19 +02:00
|
|
|
false,
|
2017-05-26 08:05:01 +02:00
|
|
|
this);
|
|
|
|
|
}
|
|
|
|
|
return res;
|
2016-10-28 16:56:33 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-25 19:52:31 +02:00
|
|
|
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(command != NULL, -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start ||
|
|
|
|
|
SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
|
|
|
|
|
if (!this->have_format)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2017-05-26 08:05:01 +02:00
|
|
|
if (this->n_buffers == 0)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2016-07-06 19:43:37 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
return spa_loop_invoke(this->data_loop,
|
|
|
|
|
do_command,
|
|
|
|
|
++this->seq,
|
|
|
|
|
SPA_POD_SIZE(command),
|
|
|
|
|
command,
|
2017-06-26 10:41:19 +02:00
|
|
|
false,
|
2017-05-26 08:05:01 +02:00
|
|
|
this);
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
} else
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOTSUP;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-26 08:05:01 +02:00
|
|
|
impl_node_set_callbacks(struct spa_node *node,
|
2017-06-18 19:48:31 +02:00
|
|
|
const struct spa_node_callbacks *callbacks,
|
2017-08-06 06:42:26 +02:00
|
|
|
void *data)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-06-14 18:32:39 +02:00
|
|
|
this->callbacks = callbacks;
|
2017-08-06 06:42:26 +02:00
|
|
|
this->callbacks_data = data;
|
2016-06-28 12:21:56 +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
|
2017-05-26 08:05:01 +02:00
|
|
|
impl_node_get_n_ports(struct spa_node *node,
|
|
|
|
|
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
|
|
|
{
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
if (n_input_ports)
|
|
|
|
|
*n_input_ports = 1;
|
|
|
|
|
if (max_input_ports)
|
|
|
|
|
*max_input_ports = 1;
|
|
|
|
|
if (n_output_ports)
|
|
|
|
|
*n_output_ports = 0;
|
|
|
|
|
if (max_output_ports)
|
|
|
|
|
*max_output_ports = 0;
|
|
|
|
|
|
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
|
2017-05-26 08:05:01 +02:00
|
|
|
impl_node_get_port_ids(struct spa_node *node,
|
|
|
|
|
uint32_t n_input_ports,
|
|
|
|
|
uint32_t *input_ids,
|
|
|
|
|
uint32_t n_output_ports,
|
|
|
|
|
uint32_t *output_ids)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (n_input_ports > 0 && input_ids != NULL)
|
|
|
|
|
input_ids[0] = 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
|
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
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static int impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
|
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
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-11-07 17:39:31 +01:00
|
|
|
impl_node_port_get_info(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction, uint32_t port_id, const struct spa_port_info **info)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(info != NULL, -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
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-07 17:39:31 +01:00
|
|
|
*info = &this->info;
|
|
|
|
|
|
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
|
2017-11-07 17:39:31 +01:00
|
|
|
impl_node_port_enum_params(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t *index,
|
|
|
|
|
const struct spa_pod_object *filter,
|
|
|
|
|
struct spa_pod_builder *builder)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
2017-11-07 17:39:31 +01:00
|
|
|
struct type *t;
|
2017-11-09 17:07:04 +01:00
|
|
|
struct spa_pod *param;
|
2017-11-13 12:30:48 +01:00
|
|
|
struct spa_pod_builder_state state;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(index != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2017-11-07 17:39:31 +01:00
|
|
|
t = &this->type;
|
2016-07-30 20:35:34 +02:00
|
|
|
|
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-13 12:30:48 +01:00
|
|
|
spa_pod_builder_get_state(builder, &state);
|
2017-11-13 09:41:41 +01:00
|
|
|
|
2017-11-09 17:07:04 +01:00
|
|
|
next:
|
2017-11-08 11:22:42 +01:00
|
|
|
if (id == t->param.idList) {
|
|
|
|
|
uint32_t list[] = { t->param.idEnumFormat,
|
|
|
|
|
t->param.idFormat,
|
|
|
|
|
t->param.idBuffers,
|
|
|
|
|
t->param.idMeta };
|
|
|
|
|
|
|
|
|
|
if (*index < SPA_N_ELEMENTS(list))
|
2017-11-09 17:07:04 +01:00
|
|
|
param = spa_pod_builder_object(builder, id, t->param.List,
|
2017-11-08 11:22:42 +01:00
|
|
|
":", t->param.listId, "I", list[*index]);
|
|
|
|
|
else
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-08 11:22:42 +01:00
|
|
|
}
|
|
|
|
|
else if (id == t->param.idEnumFormat) {
|
2017-11-13 09:41:41 +01:00
|
|
|
printf("%d\n", *index);
|
2017-11-07 20:28:07 +01:00
|
|
|
return spa_alsa_enum_format(this, index, filter, builder);
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
else if (id == t->param.idFormat) {
|
2017-11-09 17:07:04 +01:00
|
|
|
if (!this->have_format)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2017-11-09 17:07:04 +01:00
|
|
|
if (*index > 0)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-09 17:07:04 +01:00
|
|
|
|
|
|
|
|
param = spa_pod_builder_object(builder,
|
|
|
|
|
t->param.idFormat, t->format,
|
|
|
|
|
"I", t->media_type.audio,
|
|
|
|
|
"I", t->media_subtype.raw,
|
|
|
|
|
":", t->format_audio.format, "I", this->current_format.info.raw.format,
|
|
|
|
|
":", t->format_audio.rate, "i", this->current_format.info.raw.rate,
|
|
|
|
|
":", t->format_audio.channels, "i", this->current_format.info.raw.channels);
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
else if (id == t->param.idBuffers) {
|
2017-11-08 11:22:42 +01:00
|
|
|
if (!this->have_format)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2017-11-07 17:39:31 +01:00
|
|
|
if (*index > 0)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2017-11-09 17:07:04 +01:00
|
|
|
param = spa_pod_builder_object(builder,
|
2017-11-10 13:36:14 +01:00
|
|
|
id, t->param_buffers.Buffers,
|
|
|
|
|
":", t->param_buffers.size, "iru", this->props.min_latency * this->frame_size,
|
|
|
|
|
2, this->props.min_latency * this->frame_size,
|
|
|
|
|
INT32_MAX,
|
|
|
|
|
":", t->param_buffers.stride, "i", 0,
|
|
|
|
|
":", t->param_buffers.buffers, "ir", 2,
|
2017-11-07 17:39:31 +01:00
|
|
|
2, 2, MAX_BUFFERS,
|
2017-11-10 13:36:14 +01:00
|
|
|
":", t->param_buffers.align, "i", 16);
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
else if (id == t->param.idMeta) {
|
2017-11-08 11:22:42 +01:00
|
|
|
if (!this->have_format)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2017-11-08 11:22:42 +01:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
switch (*index) {
|
|
|
|
|
case 0:
|
2017-11-09 17:07:04 +01:00
|
|
|
param = spa_pod_builder_object(builder,
|
2017-11-10 13:36:14 +01:00
|
|
|
id, t->param_meta.Meta,
|
|
|
|
|
":", t->param_meta.type, "I", t->meta.Header,
|
|
|
|
|
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
|
2017-11-07 17:39:31 +01:00
|
|
|
break;
|
|
|
|
|
case 1:
|
2017-11-09 17:07:04 +01:00
|
|
|
param = spa_pod_builder_object(builder,
|
2017-11-10 13:36:14 +01:00
|
|
|
id, t->param_meta.Meta,
|
|
|
|
|
":", t->param_meta.type, "I", t->meta.Ringbuffer,
|
|
|
|
|
":", t->param_meta.size, "i", sizeof(struct spa_meta_ringbuffer),
|
|
|
|
|
":", t->param_meta.ringbufferSize, "iru",
|
2017-11-07 17:39:31 +01:00
|
|
|
this->props.max_latency * this->frame_size,
|
|
|
|
|
2, this->props.min_latency * this->frame_size,
|
|
|
|
|
this->period_frames * this->frame_size,
|
2017-11-10 13:36:14 +01:00
|
|
|
":", t->param_meta.ringbufferStride, "i", 0,
|
|
|
|
|
":", t->param_meta.ringbufferBlocks, "i", 1,
|
|
|
|
|
":", t->param_meta.ringbufferAlign, "i", 16);
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOENT;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
|
|
|
|
(*index)++;
|
|
|
|
|
|
2017-11-13 12:30:48 +01:00
|
|
|
spa_pod_builder_reset(builder, &state);
|
2017-11-09 17:07:04 +01:00
|
|
|
if (spa_pod_filter(builder, param, (struct spa_pod*)filter) < 0)
|
|
|
|
|
goto next;
|
|
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 1;
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int clear_buffers(struct state *this)
|
|
|
|
|
{
|
|
|
|
|
if (this->n_buffers > 0) {
|
|
|
|
|
spa_list_init(&this->ready);
|
|
|
|
|
this->n_buffers = 0;
|
|
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int port_set_format(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t flags,
|
|
|
|
|
const struct spa_pod_object *format)
|
|
|
|
|
{
|
|
|
|
|
struct state *this = SPA_CONTAINER_OF(node, struct state, node);
|
|
|
|
|
int err;
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (format == NULL) {
|
|
|
|
|
spa_log_info(this->log, "clear format");
|
|
|
|
|
spa_alsa_pause(this, false);
|
|
|
|
|
clear_buffers(this);
|
|
|
|
|
spa_alsa_close(this);
|
|
|
|
|
this->have_format = false;
|
|
|
|
|
} else {
|
2017-11-07 17:39:31 +01:00
|
|
|
struct spa_audio_info info = { 0 };
|
|
|
|
|
|
2017-11-08 15:48:31 +01:00
|
|
|
if ((err = spa_pod_object_parse(format,
|
2017-11-07 17:39:31 +01:00
|
|
|
"I", &info.media_type,
|
2017-11-08 15:48:31 +01:00
|
|
|
"I", &info.media_subtype)) < 0)
|
|
|
|
|
return err;
|
2017-03-24 18:11:11 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (info.media_type != this->type.media_type.audio ||
|
|
|
|
|
info.media_subtype != this->type.media_subtype.raw)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2017-03-24 18:11:11 +01:00
|
|
|
|
2017-09-21 18:57:41 +02:00
|
|
|
if (spa_format_audio_raw_parse(format, &info.info.raw, &this->type.format_audio) < 0)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2017-03-24 18:11:11 +01:00
|
|
|
|
2017-10-26 15:13:33 +02:00
|
|
|
if ((err = spa_alsa_set_format(this, &info, flags)) < 0)
|
|
|
|
|
return err;
|
2017-03-24 18:11:11 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this->current_format = info;
|
|
|
|
|
this->have_format = true;
|
|
|
|
|
}
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (this->have_format) {
|
|
|
|
|
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | SPA_PORT_INFO_FLAG_LIVE;
|
|
|
|
|
this->info.rate = this->rate;
|
|
|
|
|
}
|
2016-06-28 12:21:56 +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
|
2017-11-07 17:39:31 +01:00
|
|
|
impl_node_port_set_param(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t flags,
|
|
|
|
|
const struct spa_pod_object *param)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
2017-09-21 18:57:41 +02:00
|
|
|
struct type *t;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2017-09-21 18:57:41 +02:00
|
|
|
t = &this->type;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
if (id == t->param.idFormat) {
|
|
|
|
|
return port_set_format(node, direction, port_id, flags, param);
|
2017-05-26 08:05:01 +02: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
|
2017-05-26 08:05:01 +02:00
|
|
|
impl_node_port_use_buffers(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers)
|
2016-07-08 20:12:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
|
|
|
|
int i;
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2017-04-04 09:00:49 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_log_info(this->log, "use buffers %d", n_buffers);
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (!this->have_format)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (n_buffers == 0) {
|
|
|
|
|
spa_alsa_pause(this, false);
|
|
|
|
|
clear_buffers(this);
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
for (i = 0; i < n_buffers; i++) {
|
|
|
|
|
struct buffer *b = &this->buffers[i];
|
2017-09-07 19:55:22 +02:00
|
|
|
uint32_t type;
|
2017-04-26 18:42:50 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
b->outbuf = buffers[i];
|
|
|
|
|
b->outstanding = true;
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
b->h = spa_buffer_find_meta(b->outbuf, this->type.meta.Header);
|
|
|
|
|
b->rb = spa_buffer_find_meta(b->outbuf, this->type.meta.Ringbuffer);
|
2017-04-26 18:42:50 +02:00
|
|
|
|
2017-09-07 19:55:22 +02:00
|
|
|
type = buffers[i]->datas[0].type;
|
2017-05-26 08:05:01 +02:00
|
|
|
if ((type == this->type.data.MemFd ||
|
|
|
|
|
type == this->type.data.DmaBuf ||
|
|
|
|
|
type == this->type.data.MemPtr) && buffers[i]->datas[0].data == NULL) {
|
|
|
|
|
spa_log_error(this->log, NAME " %p: need mapped memory", this);
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this->n_buffers = n_buffers;
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-07-08 20:12:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-26 08:05:01 +02:00
|
|
|
impl_node_port_alloc_buffers(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
2017-11-07 17:39:31 +01:00
|
|
|
struct spa_pod_object **params,
|
2017-05-26 18:19:51 +02:00
|
|
|
uint32_t n_params,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t *n_buffers)
|
2016-07-08 20:12:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(buffers != NULL, -EINVAL);
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2017-04-04 09:00:49 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (!this->have_format)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2016-08-24 16:26:58 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOTSUP;
|
2016-07-08 20:12:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-26 08:05:01 +02:00
|
|
|
impl_node_port_set_io(struct spa_node *node, enum spa_direction direction, uint32_t port_id, struct spa_port_io *io)
|
2016-08-02 16:34:44 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this->io = io;
|
2016-08-02 16:34:44 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-07-30 20:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
|
2016-10-03 19:43:42 +02:00
|
|
|
{
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOTSUP;
|
2016-10-03 19:43:42 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-26 08:05:01 +02:00
|
|
|
impl_node_port_send_command(struct spa_node *node,
|
2017-07-25 19:52:31 +02:00
|
|
|
enum spa_direction direction, uint32_t port_id, const struct spa_command *command)
|
2016-10-03 19:43:42 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
|
|
|
|
int res;
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2016-10-28 16:56:33 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
|
|
|
|
|
res = spa_alsa_pause(this, false);
|
|
|
|
|
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
|
|
|
|
|
res = spa_alsa_start(this, false);
|
|
|
|
|
} else
|
2017-11-13 09:41:41 +01:00
|
|
|
res = -ENOTSUP;
|
2017-03-22 10:04:24 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
return res;
|
2016-10-03 19:43:42 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static int impl_node_process_input(struct spa_node *node)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *this;
|
|
|
|
|
struct spa_port_io *input;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = SPA_CONTAINER_OF(node, struct state, node);
|
|
|
|
|
input = this->io;
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(input != NULL, -EIO);
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
if (input->status == SPA_STATUS_HAVE_BUFFER && input->buffer_id < this->n_buffers) {
|
2017-05-26 08:05:01 +02:00
|
|
|
struct buffer *b = &this->buffers[input->buffer_id];
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (!b->outstanding) {
|
|
|
|
|
spa_log_warn(this->log, NAME " %p: buffer %u in use", this, input->buffer_id);
|
2017-11-13 09:41:41 +01:00
|
|
|
input->status = -EINVAL;
|
|
|
|
|
return -EINVAL;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_log_trace(this->log, NAME " %p: queue buffer %u", this, input->buffer_id);
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-10-24 12:58:10 +02:00
|
|
|
spa_list_append(&this->ready, &b->link);
|
2017-05-26 08:05:01 +02:00
|
|
|
b->outstanding = false;
|
|
|
|
|
input->buffer_id = SPA_ID_INVALID;
|
2017-11-13 09:41:41 +01:00
|
|
|
input->status = SPA_STATUS_OK;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
return SPA_STATUS_OK;
|
2016-11-07 18:23:09 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static int impl_node_process_output(struct spa_node *node)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOTSUP;
|
2016-11-07 18:23:09 +01:00
|
|
|
}
|
|
|
|
|
|
2017-09-07 19:55:22 +02:00
|
|
|
static const struct spa_dict_item node_info_items[] = {
|
|
|
|
|
{ "media.class", "Audio/Sink" },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct spa_dict node_info = {
|
|
|
|
|
SPA_N_ELEMENTS(node_info_items),
|
|
|
|
|
node_info_items
|
|
|
|
|
};
|
2016-10-03 19:43:42 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static const struct spa_node impl_node = {
|
2017-06-14 18:32:39 +02:00
|
|
|
SPA_VERSION_NODE,
|
2017-09-07 19:55:22 +02:00
|
|
|
&node_info,
|
2017-11-07 17:39:31 +01:00
|
|
|
impl_node_enum_params,
|
|
|
|
|
impl_node_set_param,
|
2017-05-26 08:05:01 +02:00
|
|
|
impl_node_send_command,
|
|
|
|
|
impl_node_set_callbacks,
|
|
|
|
|
impl_node_get_n_ports,
|
|
|
|
|
impl_node_get_port_ids,
|
|
|
|
|
impl_node_add_port,
|
|
|
|
|
impl_node_remove_port,
|
|
|
|
|
impl_node_port_get_info,
|
|
|
|
|
impl_node_port_enum_params,
|
|
|
|
|
impl_node_port_set_param,
|
|
|
|
|
impl_node_port_use_buffers,
|
|
|
|
|
impl_node_port_alloc_buffers,
|
|
|
|
|
impl_node_port_set_io,
|
|
|
|
|
impl_node_port_reuse_buffer,
|
|
|
|
|
impl_node_port_send_command,
|
|
|
|
|
impl_node_process_input,
|
|
|
|
|
impl_node_process_output,
|
2016-06-28 12:21:56 +02:00
|
|
|
};
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct state *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-26 08:05:01 +02:00
|
|
|
this = (struct state *) handle;
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (interface_id == this->type.node)
|
|
|
|
|
*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-26 08:05:01 +02:00
|
|
|
static int impl_clear(struct spa_handle *handle)
|
2016-09-01 10:04:25 +02:00
|
|
|
{
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-09-01 10:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-26 08:05:01 +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-26 08:05:01 +02:00
|
|
|
struct state *this;
|
|
|
|
|
uint32_t i;
|
|
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
handle->get_interface = impl_get_interface;
|
|
|
|
|
handle->clear = impl_clear;
|
|
|
|
|
|
|
|
|
|
this = (struct state *) handle;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_support; i++) {
|
|
|
|
|
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
|
|
|
|
|
this->map = support[i].data;
|
|
|
|
|
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
|
|
|
|
|
this->log = support[i].data;
|
|
|
|
|
else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0)
|
|
|
|
|
this->data_loop = support[i].data;
|
|
|
|
|
else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
|
|
|
|
this->main_loop = support[i].data;
|
|
|
|
|
}
|
|
|
|
|
if (this->map == NULL) {
|
|
|
|
|
spa_log_error(this->log, "a type-map is needed");
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
if (this->data_loop == NULL) {
|
|
|
|
|
spa_log_error(this->log, "a data loop is needed");
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
if (this->main_loop == NULL) {
|
|
|
|
|
spa_log_error(this->log, "a main loop is needed");
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
init_type(&this->type, this->map);
|
|
|
|
|
|
|
|
|
|
this->node = impl_node;
|
|
|
|
|
this->stream = SND_PCM_STREAM_PLAYBACK;
|
|
|
|
|
reset_props(&this->props);
|
|
|
|
|
|
|
|
|
|
spa_list_init(&this->ready);
|
|
|
|
|
|
|
|
|
|
for (i = 0; info && i < info->n_items; i++) {
|
|
|
|
|
if (!strcmp(info->items[i].key, "alsa.card")) {
|
|
|
|
|
snprintf(this->props.device, 63, "%s", info->items[i].value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2016-07-13 18:29:55 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
static const struct spa_interface_info impl_interfaces[] = {
|
|
|
|
|
{SPA_TYPE__Node,},
|
2016-07-13 18:29:55 +02:00
|
|
|
};
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-26 08:05:01 +02:00
|
|
|
impl_enum_interface_info(const struct spa_handle_factory *factory,
|
2017-11-13 09:41:41 +01:00
|
|
|
const struct spa_interface_info **info, 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-26 08:05:01 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
switch (*index) {
|
2017-05-26 08:05:01 +02:00
|
|
|
case 0:
|
2017-11-13 09:41:41 +01:00
|
|
|
*info = &impl_interfaces[*index];
|
2017-05-26 08:05:01 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
(*index)++;
|
|
|
|
|
return 1;
|
2016-07-13 18:29:55 +02:00
|
|
|
}
|
|
|
|
|
|
2017-09-07 19:55:22 +02:00
|
|
|
static const struct spa_dict_item info_items[] = {
|
|
|
|
|
{ "factory.author", "Wim Taymans <wim.taymans@gmail.com>" },
|
|
|
|
|
{ "factory.description", "Play audio with the alsa API" },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct spa_dict info = {
|
|
|
|
|
SPA_N_ELEMENTS(info_items),
|
|
|
|
|
info_items
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
const struct spa_handle_factory spa_alsa_sink_factory = {
|
2017-06-14 18:32:39 +02:00
|
|
|
SPA_VERSION_HANDLE_FACTORY,
|
2017-05-26 08:05:01 +02:00
|
|
|
NAME,
|
2017-09-07 19:55:22 +02:00
|
|
|
&info,
|
2017-05-26 08:05:01 +02:00
|
|
|
sizeof(struct state),
|
|
|
|
|
impl_init,
|
|
|
|
|
impl_enum_interface_info,
|
2016-07-13 18:29:55 +02:00
|
|
|
};
|