mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
Optimize transport some more
We can optimize the transport some more if we allow the host to configure the area used for transfering buffers. We can then also place the current status in the area and avoid calling get_status(). We can also allocate this area in shared memory, avoiding a memcpy in the client-node.
This commit is contained in:
parent
b774b99db5
commit
e88a376d7c
21 changed files with 903 additions and 989 deletions
|
|
@ -32,7 +32,7 @@
|
|||
typedef struct _SpaALSAState SpaALSASink;
|
||||
|
||||
static const char default_device[] = "default";
|
||||
static const uint32_t default_buffer_time = 10000;
|
||||
static const uint32_t default_buffer_time = 4000;
|
||||
static const uint32_t default_period_time = 1000;
|
||||
static const bool default_period_event = 0;
|
||||
|
||||
|
|
@ -590,88 +590,31 @@ spa_alsa_sink_node_port_alloc_buffers (SpaNode *node,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_get_status (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
spa_alsa_sink_node_port_set_input (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortInput *input)
|
||||
{
|
||||
SpaALSASink *this;
|
||||
|
||||
if (node == NULL || status == NULL)
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (node, SpaALSASink, node);
|
||||
|
||||
if (!CHECK_PORT (this, direction, port_id))
|
||||
if (!CHECK_PORT (this, SPA_DIRECTION_INPUT, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
*status = &this->status;
|
||||
this->io = input;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaPortInputInfo *info)
|
||||
spa_alsa_sink_node_port_set_output (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortOutput *output)
|
||||
{
|
||||
SpaALSASink *this;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
|
||||
if (node == NULL || n_info == 0 || info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (node, SpaALSASink, node);
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
SpaALSABuffer *b;
|
||||
|
||||
if (info[i].port_id != 0) {
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
if (!this->have_format) {
|
||||
info[i].status = SPA_RESULT_NO_FORMAT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (info[i].buffer_id >= this->n_buffers) {
|
||||
info[i].status = SPA_RESULT_INVALID_BUFFER_ID;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
b = &this->buffers[info[i].buffer_id];
|
||||
if (!b->outstanding) {
|
||||
info[i].status = SPA_RESULT_INVALID_BUFFER_ID;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
if (this->ringbuffer) {
|
||||
this->ringbuffer->outstanding = true;
|
||||
this->ringbuffer = b;
|
||||
} else {
|
||||
b->next = NULL;
|
||||
SPA_QUEUE_PUSH_TAIL (&this->ready, SpaALSABuffer, next, b);
|
||||
}
|
||||
b->outstanding = false;
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
}
|
||||
if (have_error)
|
||||
return SPA_RESULT_ERROR;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaPortOutputInfo *info)
|
||||
{
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -721,6 +664,55 @@ spa_alsa_sink_node_port_send_command (SpaNode *node,
|
|||
return res;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_process_input (SpaNode *node)
|
||||
{
|
||||
SpaALSASink *this;
|
||||
SpaPortInput *input;
|
||||
SpaALSABuffer *b;
|
||||
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (node, SpaALSASink, node);
|
||||
|
||||
if ((input = this->io) == NULL)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
if (!this->have_format) {
|
||||
input->status = SPA_RESULT_NO_FORMAT;
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if (input->buffer_id >= this->n_buffers) {
|
||||
input->status = SPA_RESULT_INVALID_BUFFER_ID;
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
b = &this->buffers[input->buffer_id];
|
||||
if (!b->outstanding) {
|
||||
input->status = SPA_RESULT_INVALID_BUFFER_ID;
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
if (this->ringbuffer) {
|
||||
this->ringbuffer->outstanding = true;
|
||||
this->ringbuffer = b;
|
||||
} else {
|
||||
b->next = NULL;
|
||||
SPA_QUEUE_PUSH_TAIL (&this->ready, SpaALSABuffer, next, b);
|
||||
}
|
||||
b->outstanding = false;
|
||||
input->status = SPA_RESULT_OK;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_sink_node_process_output (SpaNode *node)
|
||||
{
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
}
|
||||
|
||||
|
||||
static const SpaNode alsasink_node = {
|
||||
sizeof (SpaNode),
|
||||
|
|
@ -742,11 +734,12 @@ static const SpaNode alsasink_node = {
|
|||
spa_alsa_sink_node_port_set_props,
|
||||
spa_alsa_sink_node_port_use_buffers,
|
||||
spa_alsa_sink_node_port_alloc_buffers,
|
||||
spa_alsa_sink_node_port_get_status,
|
||||
spa_alsa_sink_node_port_push_input,
|
||||
spa_alsa_sink_node_port_pull_output,
|
||||
spa_alsa_sink_node_port_set_input,
|
||||
spa_alsa_sink_node_port_set_output,
|
||||
spa_alsa_sink_node_port_reuse_buffer,
|
||||
spa_alsa_sink_node_port_send_command,
|
||||
spa_alsa_sink_node_process_input,
|
||||
spa_alsa_sink_node_process_output,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -815,8 +808,6 @@ alsa_sink_init (const SpaHandleFactory *factory,
|
|||
this->stream = SND_PCM_STREAM_PLAYBACK;
|
||||
reset_alsa_sink_props (&this->props[1]);
|
||||
|
||||
this->status.flags = SPA_PORT_STATUS_FLAG_NONE;
|
||||
|
||||
for (i = 0; info && i < info->n_items; i++) {
|
||||
if (!strcmp (info->items[i].key, "alsa.card")) {
|
||||
snprintf (this->props[1].device, 63, "hw:%s", info->items[i].value);
|
||||
|
|
|
|||
|
|
@ -631,80 +631,31 @@ spa_alsa_source_node_port_alloc_buffers (SpaNode *node,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_source_node_port_get_status (SpaNode *node,
|
||||
SpaDirection direction,
|
||||
uint32_t port_id,
|
||||
const SpaPortStatus **status)
|
||||
{
|
||||
SpaALSASource *this;
|
||||
|
||||
if (node == NULL || status == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
|
||||
|
||||
if (!CHECK_PORT (this, direction, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
*status = &this->status;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_source_node_port_push_input (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaPortInputInfo *info)
|
||||
spa_alsa_source_node_port_set_input (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortInput *input)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_source_node_port_pull_output (SpaNode *node,
|
||||
unsigned int n_info,
|
||||
SpaPortOutputInfo *info)
|
||||
spa_alsa_source_node_port_set_output (SpaNode *node,
|
||||
uint32_t port_id,
|
||||
SpaPortOutput *output)
|
||||
{
|
||||
SpaALSASource *this;
|
||||
unsigned int i;
|
||||
bool have_error = false;
|
||||
|
||||
if (node == NULL || n_info == 0 || info == NULL)
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
|
||||
|
||||
for (i = 0; i < n_info; i++) {
|
||||
SpaALSABuffer *b;
|
||||
if (!CHECK_PORT (this, SPA_DIRECTION_OUTPUT, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (info[i].port_id != 0) {
|
||||
info[i].status = SPA_RESULT_INVALID_PORT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!this->have_format) {
|
||||
info[i].status = SPA_RESULT_NO_FORMAT;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
SPA_QUEUE_POP_HEAD (&this->ready, SpaALSABuffer, next, b);
|
||||
if (b == NULL) {
|
||||
info[i].status = SPA_RESULT_UNEXPECTED;
|
||||
have_error = true;
|
||||
continue;
|
||||
}
|
||||
b->outstanding = true;
|
||||
|
||||
info[i].buffer_id = b->outbuf->id;
|
||||
info[i].status = SPA_RESULT_OK;
|
||||
spa_log_trace (this->log, "pull buffer %u", b->outbuf->id);
|
||||
}
|
||||
if (have_error)
|
||||
return SPA_RESULT_ERROR;
|
||||
this->io = output;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -773,6 +724,46 @@ spa_alsa_source_node_port_send_command (SpaNode *node,
|
|||
return res;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_source_node_process_input (SpaNode *node)
|
||||
{
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
spa_alsa_source_node_process_output (SpaNode *node)
|
||||
{
|
||||
SpaALSASource *this;
|
||||
SpaPortOutput *output;
|
||||
SpaALSABuffer *b;
|
||||
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
|
||||
|
||||
output = this->io;
|
||||
|
||||
if (!this->have_format) {
|
||||
output->status = SPA_RESULT_NO_FORMAT;
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
SPA_QUEUE_POP_HEAD (&this->ready, SpaALSABuffer, next, b);
|
||||
if (b == NULL) {
|
||||
output->status = SPA_RESULT_UNEXPECTED;
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
b->outstanding = true;
|
||||
|
||||
output->buffer_id = b->outbuf->id;
|
||||
output->status = SPA_RESULT_OK;
|
||||
|
||||
spa_log_trace (this->log, "pull buffer %u", b->outbuf->id);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static const SpaNode alsasource_node = {
|
||||
sizeof (SpaNode),
|
||||
NULL,
|
||||
|
|
@ -793,11 +784,12 @@ static const SpaNode alsasource_node = {
|
|||
spa_alsa_source_node_port_set_props,
|
||||
spa_alsa_source_node_port_use_buffers,
|
||||
spa_alsa_source_node_port_alloc_buffers,
|
||||
spa_alsa_source_node_port_get_status,
|
||||
spa_alsa_source_node_port_push_input,
|
||||
spa_alsa_source_node_port_pull_output,
|
||||
spa_alsa_source_node_port_set_input,
|
||||
spa_alsa_source_node_port_set_output,
|
||||
spa_alsa_source_node_port_reuse_buffer,
|
||||
spa_alsa_source_node_port_send_command,
|
||||
spa_alsa_source_node_process_input,
|
||||
spa_alsa_source_node_process_output,
|
||||
};
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -916,8 +908,6 @@ alsa_source_init (const SpaHandleFactory *factory,
|
|||
this->stream = SND_PCM_STREAM_CAPTURE;
|
||||
reset_alsa_props (&this->props[1]);
|
||||
|
||||
this->status.flags = SPA_PORT_STATUS_FLAG_NEED_INPUT;
|
||||
|
||||
for (i = 0; info && i < info->n_items; i++) {
|
||||
if (!strcmp (info->items[i].key, "alsa.card")) {
|
||||
snprintf (this->props[1].device, 63, "hw:%s", info->items[i].value);
|
||||
|
|
|
|||
|
|
@ -371,10 +371,11 @@ mmap_write (SpaALSAState *state)
|
|||
snd_pcm_sframes_t avail;
|
||||
snd_pcm_uframes_t offset, frames, size;
|
||||
const snd_pcm_channel_area_t *my_areas;
|
||||
snd_pcm_status_t *status;
|
||||
SpaNodeEventNeedInput ni;
|
||||
|
||||
#if 0
|
||||
snd_pcm_status_t *status;
|
||||
|
||||
snd_pcm_status_alloca (&status);
|
||||
|
||||
if ((err = snd_pcm_status (hndl, status)) < 0) {
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ struct _SpaALSAState {
|
|||
SpaAllocParamBuffers param_buffers;
|
||||
SpaAllocParamMetaEnable param_meta;
|
||||
SpaAllocParamMetaEnableRingbuffer param_meta_rb;
|
||||
SpaPortStatus status;
|
||||
void *io;
|
||||
|
||||
SpaALSABuffer buffers[MAX_BUFFERS];
|
||||
unsigned int n_buffers;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue