mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
a2dp: cleanups
This commit is contained in:
parent
f6ace8a000
commit
a78617c6a8
2 changed files with 211 additions and 116 deletions
|
|
@ -57,16 +57,16 @@ struct props {
|
||||||
|
|
||||||
struct buffer {
|
struct buffer {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
unsigned int outstanding:1;
|
||||||
struct spa_buffer *buf;
|
struct spa_buffer *buf;
|
||||||
struct spa_meta_header *h;
|
struct spa_meta_header *h;
|
||||||
bool outstanding;
|
|
||||||
struct spa_list link;
|
struct spa_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct port {
|
struct port {
|
||||||
bool have_format;
|
|
||||||
struct spa_audio_info current_format;
|
struct spa_audio_info current_format;
|
||||||
int frame_size;
|
int frame_size;
|
||||||
|
unsigned int have_format:1;
|
||||||
|
|
||||||
uint64_t info_all;
|
uint64_t info_all;
|
||||||
struct spa_port_info info;
|
struct spa_port_info info;
|
||||||
|
|
@ -75,7 +75,7 @@ struct port {
|
||||||
struct spa_param_info params[8];
|
struct spa_param_info params[8];
|
||||||
|
|
||||||
struct buffer buffers[MAX_BUFFERS];
|
struct buffer buffers[MAX_BUFFERS];
|
||||||
unsigned int n_buffers;
|
uint32_t n_buffers;
|
||||||
|
|
||||||
struct spa_list free;
|
struct spa_list free;
|
||||||
struct spa_list ready;
|
struct spa_list ready;
|
||||||
|
|
@ -87,8 +87,6 @@ struct impl {
|
||||||
struct spa_handle handle;
|
struct spa_handle handle;
|
||||||
struct spa_node node;
|
struct spa_node node;
|
||||||
|
|
||||||
uint32_t seq;
|
|
||||||
|
|
||||||
struct spa_log *log;
|
struct spa_log *log;
|
||||||
struct spa_loop *main_loop;
|
struct spa_loop *main_loop;
|
||||||
struct spa_loop *data_loop;
|
struct spa_loop *data_loop;
|
||||||
|
|
@ -107,7 +105,6 @@ struct impl {
|
||||||
|
|
||||||
struct port port;
|
struct port port;
|
||||||
|
|
||||||
unsigned int opened:1;
|
|
||||||
unsigned int started:1;
|
unsigned int started:1;
|
||||||
unsigned int slaved:1;
|
unsigned int slaved:1;
|
||||||
|
|
||||||
|
|
@ -239,11 +236,6 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool is_slaved(struct impl *this)
|
|
||||||
{
|
|
||||||
return this->position && this->clock && this->position->clock.id != this->clock->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int set_timers(struct impl *this)
|
static int set_timers(struct impl *this)
|
||||||
{
|
{
|
||||||
struct itimerspec ts;
|
struct itimerspec ts;
|
||||||
|
|
@ -276,6 +268,11 @@ static int do_reslave(struct spa_loop *loop,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool is_slaved(struct impl *this)
|
||||||
|
{
|
||||||
|
return this->position && this->clock && this->position->clock.id != this->clock->id;
|
||||||
|
}
|
||||||
|
|
||||||
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
|
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
|
|
@ -1188,6 +1185,7 @@ impl_node_port_set_param(struct spa_node *node,
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
struct port *port;
|
struct port *port;
|
||||||
|
int res;
|
||||||
|
|
||||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
|
|
@ -1195,11 +1193,15 @@ impl_node_port_set_param(struct spa_node *node,
|
||||||
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
|
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
|
||||||
port = &this->port;
|
port = &this->port;
|
||||||
|
|
||||||
if (id == SPA_PARAM_Format) {
|
switch (id) {
|
||||||
return port_set_format(this, port, flags, param);
|
case SPA_PARAM_Format:
|
||||||
|
res = port_set_format(this, port, flags, param);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res = -ENOENT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
return res;
|
||||||
return -ENOENT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,32 @@ struct props {
|
||||||
|
|
||||||
struct buffer {
|
struct buffer {
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
unsigned int outstanding:1;
|
||||||
struct spa_buffer *buf;
|
struct spa_buffer *buf;
|
||||||
struct spa_meta_header *h;
|
struct spa_meta_header *h;
|
||||||
bool outstanding;
|
|
||||||
struct spa_list link;
|
struct spa_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct port {
|
||||||
|
struct spa_audio_info current_format;
|
||||||
|
int frame_size;
|
||||||
|
unsigned int have_format:1;
|
||||||
|
|
||||||
|
uint64_t info_all;
|
||||||
|
struct spa_port_info info;
|
||||||
|
struct spa_io_buffers *io;
|
||||||
|
struct spa_io_range *range;
|
||||||
|
struct spa_param_info params[8];
|
||||||
|
|
||||||
|
struct buffer buffers[MAX_BUFFERS];
|
||||||
|
uint32_t n_buffers;
|
||||||
|
|
||||||
|
struct spa_list free;
|
||||||
|
struct spa_list ready;
|
||||||
|
|
||||||
|
size_t ready_offset;
|
||||||
|
};
|
||||||
|
|
||||||
struct impl {
|
struct impl {
|
||||||
struct spa_handle handle;
|
struct spa_handle handle;
|
||||||
struct spa_node node;
|
struct spa_node node;
|
||||||
|
|
@ -75,37 +95,28 @@ struct impl {
|
||||||
const struct spa_node_callbacks *callbacks;
|
const struct spa_node_callbacks *callbacks;
|
||||||
void *callbacks_data;
|
void *callbacks_data;
|
||||||
|
|
||||||
|
uint64_t info_all;
|
||||||
|
struct spa_node_info info;
|
||||||
|
struct spa_param_info params[8];
|
||||||
struct props props;
|
struct props props;
|
||||||
|
|
||||||
struct spa_bt_transport *transport;
|
struct spa_bt_transport *transport;
|
||||||
struct spa_hook transport_listener;
|
struct spa_hook transport_listener;
|
||||||
|
|
||||||
bool have_format;
|
struct port port;
|
||||||
struct spa_audio_info current_format;
|
|
||||||
int frame_size;
|
|
||||||
|
|
||||||
uint64_t info_all;
|
unsigned int started:1;
|
||||||
struct spa_node_info info;
|
unsigned int slaved:1;
|
||||||
struct spa_param_info params[8];
|
|
||||||
uint64_t port_info_all;
|
|
||||||
struct spa_port_info port_info;
|
|
||||||
struct spa_param_info port_params[8];
|
|
||||||
struct spa_io_buffers *io;
|
|
||||||
|
|
||||||
struct buffer buffers[MAX_BUFFERS];
|
|
||||||
unsigned int n_buffers;
|
|
||||||
|
|
||||||
struct spa_list free;
|
|
||||||
struct spa_list ready;
|
|
||||||
|
|
||||||
uint32_t sample_count;
|
|
||||||
|
|
||||||
bool started;
|
|
||||||
struct spa_source source;
|
struct spa_source source;
|
||||||
|
|
||||||
|
struct spa_io_clock *clock;
|
||||||
|
struct spa_io_position *position;
|
||||||
|
|
||||||
sbc_t sbc;
|
sbc_t sbc;
|
||||||
uint8_t buffer_read[4096];
|
uint8_t buffer_read[4096];
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
|
uint32_t sample_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NAME "a2dp-source"
|
#define NAME "a2dp-source"
|
||||||
|
|
@ -200,8 +211,47 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_reslave(struct spa_loop *loop,
|
||||||
|
bool async,
|
||||||
|
uint32_t seq,
|
||||||
|
const void *data,
|
||||||
|
size_t size,
|
||||||
|
void *user_data)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool is_slaved(struct impl *this)
|
||||||
|
{
|
||||||
|
return this->position && this->clock && this->position->clock.id != this->clock->id;
|
||||||
|
}
|
||||||
|
|
||||||
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
|
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
|
||||||
{
|
{
|
||||||
|
struct impl *this;
|
||||||
|
bool slaved;
|
||||||
|
|
||||||
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||||
|
|
||||||
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
|
|
||||||
|
switch (id) {
|
||||||
|
case SPA_IO_Clock:
|
||||||
|
this->clock = data;
|
||||||
|
break;
|
||||||
|
case SPA_IO_Position:
|
||||||
|
this->position = data;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
slaved = is_slaved(this);
|
||||||
|
if (this->started && slaved != this->slaved) {
|
||||||
|
spa_log_debug(this->log, "a2dp-source %p: reslave %d->%d", this, this->slaved, slaved);
|
||||||
|
this->slaved = slaved;
|
||||||
|
spa_loop_invoke(this->data_loop, do_reslave, 0, NULL, 0, true, this);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,23 +286,24 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reset_buffers(struct impl *this)
|
static void reset_buffers(struct port *port)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
spa_list_init(&this->free);
|
spa_list_init(&port->free);
|
||||||
spa_list_init(&this->ready);
|
spa_list_init(&port->ready);
|
||||||
|
|
||||||
for (i = 0; i < this->n_buffers; i++) {
|
for (i = 0; i < port->n_buffers; i++) {
|
||||||
struct buffer *b = &this->buffers[i];
|
struct buffer *b = &port->buffers[i];
|
||||||
spa_list_append(&this->free, &b->link);
|
spa_list_append(&port->free, &b->link);
|
||||||
b->outstanding = true;
|
b->outstanding = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decode_sbc_data(struct impl *this, uint8_t *src, size_t src_size)
|
static void decode_sbc_data(struct impl *this, uint8_t *src, size_t src_size)
|
||||||
{
|
{
|
||||||
const ssize_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
|
const ssize_t header_size = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
|
||||||
|
struct port *port = &this->port;
|
||||||
struct buffer *buffer;
|
struct buffer *buffer;
|
||||||
struct spa_data *data;
|
struct spa_data *data;
|
||||||
uint8_t *dest;
|
uint8_t *dest;
|
||||||
|
|
@ -268,19 +319,18 @@ static void decode_sbc_data(struct impl *this, uint8_t *src, size_t src_size)
|
||||||
src_size -= header_size;
|
src_size -= header_size;
|
||||||
|
|
||||||
/* check if we have a new buffer */
|
/* check if we have a new buffer */
|
||||||
if (spa_list_is_empty(&this->free)) {
|
if (spa_list_is_empty(&port->free)) {
|
||||||
spa_log_warn(this->log, "no more buffers available, dropping data...");
|
spa_log_warn(this->log, "no more buffers available, dropping data...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the buffer */
|
/* get the buffer */
|
||||||
buffer = spa_list_first(&this->free, struct buffer, link);
|
buffer = spa_list_first(&port->free, struct buffer, link);
|
||||||
|
|
||||||
/* remove the the buffer from the list */
|
/* remove the the buffer from the list */
|
||||||
spa_list_remove(&buffer->link);
|
spa_list_remove(&buffer->link);
|
||||||
|
|
||||||
/* update the outstanding flag */
|
/* update the outstanding flag */
|
||||||
buffer->outstanding = false;
|
buffer->outstanding = true;
|
||||||
|
|
||||||
/* set the header */
|
/* set the header */
|
||||||
if (buffer->h) {
|
if (buffer->h) {
|
||||||
|
|
@ -320,14 +370,15 @@ static void decode_sbc_data(struct impl *this, uint8_t *src, size_t src_size)
|
||||||
/* set the decoded data */
|
/* set the decoded data */
|
||||||
data[0].chunk->offset = 0;
|
data[0].chunk->offset = 0;
|
||||||
data[0].chunk->size = data[0].maxsize - dest_size;
|
data[0].chunk->size = data[0].maxsize - dest_size;
|
||||||
data[0].chunk->stride = this->frame_size;
|
data[0].chunk->stride = port->frame_size;
|
||||||
|
|
||||||
/* update the sample count */
|
/* update the sample count */
|
||||||
this->sample_count += data[0].chunk->size / this->frame_size;
|
this->sample_count += data[0].chunk->size / port->frame_size;
|
||||||
|
|
||||||
/* add the buffer to the queue */
|
/* add the buffer to the queue */
|
||||||
spa_log_debug(this->log, "data decoded successfully for buffer_id=%d", buffer->id);
|
spa_log_debug(this->log, "data decoded successfully for buffer_id=%d", buffer->id);
|
||||||
spa_list_append(&this->ready, &buffer->link);
|
spa_list_append(&port->ready, &buffer->link);
|
||||||
|
|
||||||
this->callbacks->ready(this->callbacks_data, SPA_STATUS_HAVE_BUFFER);
|
this->callbacks->ready(this->callbacks_data, SPA_STATUS_HAVE_BUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,7 +463,7 @@ static int do_start(struct impl *this)
|
||||||
if (setsockopt(this->transport->fd, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)) < 0)
|
if (setsockopt(this->transport->fd, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)) < 0)
|
||||||
spa_log_warn(this->log, "SO_PRIORITY failed: %m");
|
spa_log_warn(this->log, "SO_PRIORITY failed: %m");
|
||||||
|
|
||||||
reset_buffers(this);
|
reset_buffers(&this->port);
|
||||||
|
|
||||||
this->source.data = this;
|
this->source.data = this;
|
||||||
this->source.fd = this->transport->fd;
|
this->source.fd = this->transport->fd;
|
||||||
|
|
@ -468,18 +519,20 @@ static int do_stop(struct impl *this)
|
||||||
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
|
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
|
struct port *port;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||||
spa_return_val_if_fail(command != NULL, -EINVAL);
|
spa_return_val_if_fail(command != NULL, -EINVAL);
|
||||||
|
|
||||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
|
port = &this->port;
|
||||||
|
|
||||||
switch (SPA_NODE_COMMAND_ID(command)) {
|
switch (SPA_NODE_COMMAND_ID(command)) {
|
||||||
case SPA_NODE_COMMAND_Start:
|
case SPA_NODE_COMMAND_Start:
|
||||||
if (!this->have_format)
|
if (!port->have_format)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
if (this->n_buffers == 0)
|
if (port->n_buffers == 0)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
if ((res = do_start(this)) < 0)
|
if ((res = do_start(this)) < 0)
|
||||||
|
|
@ -507,18 +560,18 @@ static void emit_node_info(struct impl *this, bool full)
|
||||||
if (this->info.change_mask) {
|
if (this->info.change_mask) {
|
||||||
this->info.props = &SPA_DICT_INIT_ARRAY(node_info_items);
|
this->info.props = &SPA_DICT_INIT_ARRAY(node_info_items);
|
||||||
spa_node_emit_info(&this->hooks, &this->info);
|
spa_node_emit_info(&this->hooks, &this->info);
|
||||||
this->port_info.change_mask = 0;
|
this->info.change_mask = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void emit_port_info(struct impl *this, bool full)
|
static void emit_port_info(struct impl *this, struct port *port, bool full)
|
||||||
{
|
{
|
||||||
if (full)
|
if (full)
|
||||||
this->port_info.change_mask = this->port_info_all;
|
port->info.change_mask = port->info_all;
|
||||||
if (this->port_info.change_mask) {
|
if (port->info.change_mask) {
|
||||||
spa_node_emit_port_info(&this->hooks,
|
spa_node_emit_port_info(&this->hooks,
|
||||||
SPA_DIRECTION_OUTPUT, 0, &this->port_info);
|
SPA_DIRECTION_OUTPUT, 0, &port->info);
|
||||||
this->port_info.change_mask = 0;
|
port->info.change_mask = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -537,7 +590,7 @@ impl_node_add_listener(struct spa_node *node,
|
||||||
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
|
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
|
||||||
|
|
||||||
emit_node_info(this, true);
|
emit_node_info(this, true);
|
||||||
emit_port_info(this, true);
|
emit_port_info(this, &this->port, true);
|
||||||
|
|
||||||
spa_hook_list_join(&this->hooks, &save);
|
spa_hook_list_join(&this->hooks, &save);
|
||||||
|
|
||||||
|
|
@ -580,6 +633,7 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
||||||
{
|
{
|
||||||
|
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
|
struct port *port;
|
||||||
struct spa_pod *param;
|
struct spa_pod *param;
|
||||||
struct spa_pod_builder b = { 0 };
|
struct spa_pod_builder b = { 0 };
|
||||||
uint8_t buffer[1024];
|
uint8_t buffer[1024];
|
||||||
|
|
@ -591,6 +645,9 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
||||||
|
|
||||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
|
|
||||||
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||||
|
port = &this->port;
|
||||||
|
|
||||||
result.id = id;
|
result.id = id;
|
||||||
result.next = start;
|
result.next = start;
|
||||||
next:
|
next:
|
||||||
|
|
@ -645,16 +702,16 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SPA_PARAM_Format:
|
case SPA_PARAM_Format:
|
||||||
if (!this->have_format)
|
if (!port->have_format)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
if (result.index > 0)
|
if (result.index > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw);
|
param = spa_format_audio_raw_build(&b, id, &port->current_format.info.raw);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SPA_PARAM_Buffers:
|
case SPA_PARAM_Buffers:
|
||||||
if (!this->have_format)
|
if (!port->have_format)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
if (result.index > 0)
|
if (result.index > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -664,8 +721,8 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
||||||
/* 8 buffers are enough to make sure we always have one available when decoding */
|
/* 8 buffers are enough to make sure we always have one available when decoding */
|
||||||
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 8, MAX_BUFFERS),
|
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 8, MAX_BUFFERS),
|
||||||
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
|
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
|
||||||
SPA_PARAM_BUFFERS_size, SPA_POD_Int(this->props.max_latency * this->frame_size),
|
SPA_PARAM_BUFFERS_size, SPA_POD_Int(this->props.max_latency * port->frame_size),
|
||||||
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(this->frame_size),
|
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->frame_size),
|
||||||
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
|
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -700,29 +757,27 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int clear_buffers(struct impl *this)
|
static int clear_buffers(struct impl *this, struct port *port)
|
||||||
{
|
{
|
||||||
do_stop(this);
|
do_stop(this);
|
||||||
if (this->n_buffers > 0) {
|
if (port->n_buffers > 0) {
|
||||||
spa_list_init(&this->free);
|
spa_list_init(&port->free);
|
||||||
spa_list_init(&this->ready);
|
spa_list_init(&port->ready);
|
||||||
this->n_buffers = 0;
|
port->n_buffers = 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int port_set_format(struct spa_node *node,
|
static int port_set_format(struct impl *this, struct port *port,
|
||||||
enum spa_direction direction, uint32_t port_id,
|
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
const struct spa_pod *format)
|
const struct spa_pod *format)
|
||||||
{
|
{
|
||||||
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (format == NULL) {
|
if (format == NULL) {
|
||||||
spa_log_info(this->log, "clear format");
|
spa_log_info(this->log, "clear format");
|
||||||
clear_buffers(this);
|
clear_buffers(this, port);
|
||||||
this->have_format = false;
|
port->have_format = false;
|
||||||
} else {
|
} else {
|
||||||
struct spa_audio_info info = { 0 };
|
struct spa_audio_info info = { 0 };
|
||||||
|
|
||||||
|
|
@ -736,11 +791,25 @@ static int port_set_format(struct spa_node *node,
|
||||||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
this->frame_size = info.info.raw.channels * 2;
|
port->frame_size = info.info.raw.channels * 2;
|
||||||
this->current_format = info;
|
port->current_format = info;
|
||||||
this->have_format = true;
|
port->have_format = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
||||||
|
if (port->have_format) {
|
||||||
|
port->info.change_mask |= SPA_PORT_CHANGE_MASK_FLAGS;
|
||||||
|
port->info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS | SPA_PORT_FLAG_LIVE;
|
||||||
|
port->info.change_mask |= SPA_PORT_CHANGE_MASK_RATE;
|
||||||
|
port->info.rate = SPA_FRACTION(1, port->current_format.info.raw.rate);
|
||||||
|
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
|
||||||
|
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
|
||||||
|
} else {
|
||||||
|
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
||||||
|
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
||||||
|
}
|
||||||
|
emit_port_info(this, port, false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -750,15 +819,25 @@ impl_node_port_set_param(struct spa_node *node,
|
||||||
uint32_t id, uint32_t flags,
|
uint32_t id, uint32_t flags,
|
||||||
const struct spa_pod *param)
|
const struct spa_pod *param)
|
||||||
{
|
{
|
||||||
|
struct impl *this;
|
||||||
|
struct port *port;
|
||||||
|
int res;
|
||||||
|
|
||||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||||
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
|
|
||||||
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
|
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
|
||||||
|
port = &this->port;
|
||||||
|
|
||||||
if (id == SPA_PARAM_Format) {
|
switch (id) {
|
||||||
return port_set_format(node, direction, port_id, flags, param);
|
case SPA_PARAM_Format:
|
||||||
|
res = port_set_format(this, port, flags, param);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res = -ENOENT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
return res;
|
||||||
return -ENOENT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -767,6 +846,7 @@ impl_node_port_use_buffers(struct spa_node *node,
|
||||||
uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers)
|
uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
|
struct port *port;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||||
|
|
@ -774,21 +854,21 @@ impl_node_port_use_buffers(struct spa_node *node,
|
||||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
|
|
||||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||||
|
port = &this->port;
|
||||||
|
|
||||||
spa_log_info(this->log, "use buffers %d", n_buffers);
|
spa_log_info(this->log, "use buffers %d", n_buffers);
|
||||||
|
|
||||||
if (!this->have_format)
|
if (!port->have_format)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
clear_buffers(this);
|
clear_buffers(this, port);
|
||||||
|
|
||||||
for (i = 0; i < n_buffers; i++) {
|
for (i = 0; i < n_buffers; i++) {
|
||||||
struct buffer *b = &this->buffers[i];
|
struct buffer *b = &port->buffers[i];
|
||||||
struct spa_data *d = buffers[i]->datas;
|
struct spa_data *d = buffers[i]->datas;
|
||||||
|
|
||||||
b->buf = buffers[i];
|
b->buf = buffers[i];
|
||||||
b->id = i;
|
b->id = i;
|
||||||
b->outstanding = true;
|
|
||||||
|
|
||||||
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
|
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
|
||||||
|
|
||||||
|
|
@ -798,9 +878,10 @@ impl_node_port_use_buffers(struct spa_node *node,
|
||||||
spa_log_error(this->log, NAME " %p: need mapped memory", this);
|
spa_log_error(this->log, NAME " %p: need mapped memory", this);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
spa_list_append(&this->free, &b->link);
|
spa_list_append(&port->free, &b->link);
|
||||||
|
b->outstanding = false;
|
||||||
}
|
}
|
||||||
this->n_buffers = n_buffers;
|
port->n_buffers = n_buffers;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -815,6 +896,7 @@ impl_node_port_alloc_buffers(struct spa_node *node,
|
||||||
uint32_t *n_buffers)
|
uint32_t *n_buffers)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
|
struct port *port;
|
||||||
|
|
||||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||||
spa_return_val_if_fail(buffers != NULL, -EINVAL);
|
spa_return_val_if_fail(buffers != NULL, -EINVAL);
|
||||||
|
|
@ -822,8 +904,9 @@ impl_node_port_alloc_buffers(struct spa_node *node,
|
||||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
|
|
||||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||||
|
port = &this->port;
|
||||||
|
|
||||||
if (!this->have_format)
|
if (!port->have_format)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
|
@ -837,16 +920,18 @@ impl_node_port_set_io(struct spa_node *node,
|
||||||
void *data, size_t size)
|
void *data, size_t size)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
|
struct port *port;
|
||||||
|
|
||||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||||
|
|
||||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
|
|
||||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||||
|
port = &this->port;
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case SPA_IO_Buffers:
|
case SPA_IO_Buffers:
|
||||||
this->io = data;
|
port->io = data;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
@ -854,34 +939,36 @@ impl_node_port_set_io(struct spa_node *node,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void recycle_buffer(struct impl *this, uint32_t buffer_id)
|
static void recycle_buffer(struct impl *this, struct port *port, uint32_t buffer_id)
|
||||||
{
|
{
|
||||||
struct buffer *b = &this->buffers[buffer_id];
|
struct buffer *b = &port->buffers[buffer_id];
|
||||||
|
|
||||||
if (!b->outstanding) {
|
if (b->outstanding) {
|
||||||
spa_log_trace(this->log, NAME " %p: recycle buffer %u", this, buffer_id);
|
spa_log_trace(this->log, NAME " %p: recycle buffer %u", this, buffer_id);
|
||||||
spa_list_append(&this->free, &b->link);
|
spa_list_append(&port->free, &b->link);
|
||||||
b->outstanding = true;
|
b->outstanding = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
|
static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
|
struct port *port;
|
||||||
|
|
||||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||||
|
|
||||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
|
|
||||||
spa_return_val_if_fail(port_id == 0, -EINVAL);
|
spa_return_val_if_fail(port_id == 0, -EINVAL);
|
||||||
|
port = &this->port;
|
||||||
|
|
||||||
if (this->n_buffers == 0)
|
if (port->n_buffers == 0)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
if (buffer_id >= this->n_buffers)
|
if (buffer_id >= port->n_buffers)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
recycle_buffer(this, buffer_id);
|
recycle_buffer(this, port, buffer_id);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -889,13 +976,16 @@ static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id,
|
||||||
static int impl_node_process(struct spa_node *node)
|
static int impl_node_process(struct spa_node *node)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
|
struct port *port;
|
||||||
struct spa_io_buffers *io;
|
struct spa_io_buffers *io;
|
||||||
struct buffer *b;
|
struct buffer *b;
|
||||||
|
|
||||||
/* get IO */
|
/* get IO */
|
||||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||||
|
|
||||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||||
io = this->io;
|
port = &this->port;
|
||||||
|
io = port->io;
|
||||||
spa_return_val_if_fail(io != NULL, -EIO);
|
spa_return_val_if_fail(io != NULL, -EIO);
|
||||||
|
|
||||||
/* don't do anything if IO does not need a buffer */
|
/* don't do anything if IO does not need a buffer */
|
||||||
|
|
@ -904,23 +994,24 @@ static int impl_node_process(struct spa_node *node)
|
||||||
|
|
||||||
/* Recycle previously played buffer */
|
/* Recycle previously played buffer */
|
||||||
if (io->buffer_id != SPA_ID_INVALID &&
|
if (io->buffer_id != SPA_ID_INVALID &&
|
||||||
io->buffer_id < this->n_buffers) {
|
io->buffer_id < port->n_buffers) {
|
||||||
spa_log_debug(this->log, "recycling buffer_id=%d", io->buffer_id);
|
spa_log_debug(this->log, "recycling buffer_id=%d", io->buffer_id);
|
||||||
recycle_buffer(this, io->buffer_id);
|
recycle_buffer(this, port, io->buffer_id);
|
||||||
io->buffer_id = SPA_ID_INVALID;
|
io->buffer_id = SPA_ID_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we have new buffers in the queue */
|
/* Check if we have new buffers in the queue */
|
||||||
if (spa_list_is_empty(&this->ready))
|
if (spa_list_is_empty(&port->ready))
|
||||||
return SPA_STATUS_OK;
|
return SPA_STATUS_HAVE_BUFFER;
|
||||||
|
|
||||||
/* Pop the new buffer from the queue */
|
/* Pop the new buffer from the queue */
|
||||||
b = spa_list_first(&this->ready, struct buffer, link);
|
b = spa_list_first(&port->ready, struct buffer, link);
|
||||||
spa_list_remove(&b->link);
|
spa_list_remove(&b->link);
|
||||||
|
|
||||||
/* Set the new buffer in IO to be played */
|
/* Set the new buffer in IO to be played */
|
||||||
io->buffer_id = b->id;
|
io->buffer_id = b->id;
|
||||||
io->status = SPA_STATUS_HAVE_BUFFER;
|
io->status = SPA_STATUS_HAVE_BUFFER;
|
||||||
|
|
||||||
return SPA_STATUS_HAVE_BUFFER;
|
return SPA_STATUS_HAVE_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -992,6 +1083,7 @@ impl_init(const struct spa_handle_factory *factory,
|
||||||
uint32_t n_support)
|
uint32_t n_support)
|
||||||
{
|
{
|
||||||
struct impl *this;
|
struct impl *this;
|
||||||
|
struct port *port;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
||||||
|
|
@ -1036,24 +1128,25 @@ impl_init(const struct spa_handle_factory *factory,
|
||||||
this->info.n_params = 2;
|
this->info.n_params = 2;
|
||||||
|
|
||||||
/* set the port info */
|
/* set the port info */
|
||||||
this->port_info_all = SPA_PORT_CHANGE_MASK_FLAGS |
|
port = &this->port;
|
||||||
|
port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
|
||||||
SPA_PORT_CHANGE_MASK_PARAMS;
|
SPA_PORT_CHANGE_MASK_PARAMS;
|
||||||
this->port_info = SPA_PORT_INFO_INIT();
|
port->info = SPA_PORT_INFO_INIT();
|
||||||
this->port_info.change_mask = SPA_PORT_CHANGE_MASK_FLAGS;
|
port->info.change_mask = SPA_PORT_CHANGE_MASK_FLAGS;
|
||||||
this->port_info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS |
|
port->info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS |
|
||||||
SPA_PORT_FLAG_LIVE |
|
SPA_PORT_FLAG_LIVE |
|
||||||
SPA_PORT_FLAG_TERMINAL;
|
SPA_PORT_FLAG_TERMINAL;
|
||||||
this->port_params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
|
port->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
|
||||||
this->port_params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);
|
port->params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);
|
||||||
this->port_params[2] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ);
|
port->params[2] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ);
|
||||||
this->port_params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
||||||
this->port_params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
||||||
this->port_info.params = this->port_params;
|
port->info.params = port->params;
|
||||||
this->port_info.n_params = 5;
|
port->info.n_params = 5;
|
||||||
|
|
||||||
/* Init the buffer lists */
|
/* Init the buffer lists */
|
||||||
spa_list_init(&this->ready);
|
spa_list_init(&port->ready);
|
||||||
spa_list_init(&this->free);
|
spa_list_init(&port->free);
|
||||||
|
|
||||||
for (i = 0; info && i < info->n_items; i++) {
|
for (i = 0; info && i < info->n_items; i++) {
|
||||||
if (strcmp(info->items[i].key, "bluez5.transport") == 0)
|
if (strcmp(info->items[i].key, "bluez5.transport") == 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue