mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Add fd to the data
Add the fd to the SpaData so that we can noth use the fd and the mmapped memory when we want instead of needing to mmap again in the plugin. various cleanups
This commit is contained in:
parent
b8f693ceea
commit
06765a2dea
15 changed files with 158 additions and 179 deletions
|
|
@ -317,7 +317,7 @@ spa_alsa_sink_node_port_set_format (SpaNode *node,
|
|||
|
||||
if (format == NULL) {
|
||||
this->have_format = false;
|
||||
this->have_buffers = false;
|
||||
this->n_buffers = 0;
|
||||
update_state (this, SPA_NODE_STATE_CONFIGURE);
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -328,7 +328,7 @@ spa_alsa_sink_node_port_set_format (SpaNode *node,
|
|||
if (spa_alsa_set_format (this, &this->current_format, false) < 0)
|
||||
return SPA_RESULT_ERROR;
|
||||
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
this->info.maxbuffering = -1;
|
||||
this->info.latency = -1;
|
||||
this->info.n_params = 1;
|
||||
|
|
|
|||
|
|
@ -318,14 +318,11 @@ recycle_buffer (SpaALSASource *this, uint32_t buffer_id)
|
|||
static SpaResult
|
||||
spa_alsa_clear_buffers (SpaALSASource *this)
|
||||
{
|
||||
if (!this->have_buffers)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
SPA_QUEUE_INIT (&this->free);
|
||||
SPA_QUEUE_INIT (&this->ready);
|
||||
this->n_buffers = 0;
|
||||
this->have_buffers = false;
|
||||
|
||||
if (this->n_buffers > 0) {
|
||||
SPA_QUEUE_INIT (&this->free);
|
||||
SPA_QUEUE_INIT (&this->ready);
|
||||
this->n_buffers = 0;
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -360,11 +357,11 @@ spa_alsa_source_node_port_set_format (SpaNode *node,
|
|||
if (spa_alsa_set_format (this, &this->current_format, flags) < 0)
|
||||
return SPA_RESULT_ERROR;
|
||||
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS |
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
||||
SPA_PORT_INFO_FLAG_LIVE;
|
||||
this->info.maxbuffering = this->buffer_frames * this->frame_size;
|
||||
this->info.latency = (this->period_frames * SPA_NSEC_PER_SEC) / this->rate;
|
||||
this->info.n_params = 1;
|
||||
this->info.n_params = 2;
|
||||
this->info.params = this->params;
|
||||
this->params[0] = &this->param_buffers.param;
|
||||
this->param_buffers.param.type = SPA_ALLOC_PARAM_TYPE_BUFFERS;
|
||||
|
|
@ -374,6 +371,10 @@ spa_alsa_source_node_port_set_format (SpaNode *node,
|
|||
this->param_buffers.min_buffers = 1;
|
||||
this->param_buffers.max_buffers = 32;
|
||||
this->param_buffers.align = 16;
|
||||
this->params[1] = &this->param_meta.param;
|
||||
this->param_meta.param.type = SPA_ALLOC_PARAM_TYPE_META_ENABLE;
|
||||
this->param_meta.param.size = sizeof (this->param_meta);
|
||||
this->param_meta.type = SPA_META_TYPE_HEADER;
|
||||
this->info.features = NULL;
|
||||
|
||||
this->have_format = true;
|
||||
|
|
@ -468,23 +469,35 @@ spa_alsa_source_node_port_use_buffers (SpaNode *node,
|
|||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
if (this->have_buffers) {
|
||||
if (this->n_buffers > 0) {
|
||||
if ((res = spa_alsa_clear_buffers (this)) < 0)
|
||||
return res;
|
||||
}
|
||||
if (n_buffers > 0) {
|
||||
for (i = 0; i < n_buffers; i++) {
|
||||
SpaALSABuffer *b = &this->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->outstanding = false;
|
||||
b->next = NULL;
|
||||
SPA_QUEUE_PUSH_TAIL (&this->free, SpaALSABuffer, next, b);
|
||||
}
|
||||
this->n_buffers = n_buffers;
|
||||
this->have_buffers = true;
|
||||
}
|
||||
for (i = 0; i < n_buffers; i++) {
|
||||
SpaALSABuffer *b = &this->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->outstanding = false;
|
||||
|
||||
if (this->have_buffers)
|
||||
b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER);
|
||||
|
||||
switch (buffers[i]->datas[0].type) {
|
||||
case SPA_DATA_TYPE_MEMFD:
|
||||
case SPA_DATA_TYPE_DMABUF:
|
||||
case SPA_DATA_TYPE_MEMPTR:
|
||||
if (buffers[i]->datas[0].data == NULL) {
|
||||
fprintf (stderr, "alsa-source: need mapped memory\n");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
b->next = NULL;
|
||||
SPA_QUEUE_PUSH_TAIL (&this->free, SpaALSABuffer, next, b);
|
||||
}
|
||||
this->n_buffers = n_buffers;
|
||||
|
||||
if (this->n_buffers > 0)
|
||||
update_state (this, SPA_NODE_STATE_PAUSED);
|
||||
else
|
||||
update_state (this, SPA_NODE_STATE_READY);
|
||||
|
|
@ -512,7 +525,7 @@ spa_alsa_source_node_port_alloc_buffers (SpaNode *node,
|
|||
|
||||
this = (SpaALSASource *) node->handle;
|
||||
|
||||
if (!this->have_format)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
|
|
@ -609,7 +622,7 @@ spa_alsa_source_node_port_reuse_buffer (SpaNode *node,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (!this->have_buffers)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
if (buffer_id >= this->n_buffers)
|
||||
|
|
|
|||
|
|
@ -310,6 +310,7 @@ mmap_read (SpaALSAState *state)
|
|||
snd_htimestamp_t htstamp = { 0, 0 };
|
||||
int64_t now;
|
||||
uint8_t *dest = NULL;
|
||||
size_t destsize;
|
||||
|
||||
snd_pcm_status_alloca(&status);
|
||||
|
||||
|
|
@ -327,12 +328,15 @@ mmap_read (SpaALSAState *state)
|
|||
if (b == NULL) {
|
||||
fprintf (stderr, "no more buffers\n");
|
||||
} else {
|
||||
dest = b->ptr;
|
||||
dest = SPA_MEMBER (b->outbuf->datas[0].data, b->outbuf->datas[0].offset, void);
|
||||
destsize = b->outbuf->datas[0].size;
|
||||
|
||||
if (b->h) {
|
||||
b->h->seq = state->sample_count;
|
||||
b->h->pts = state->last_monotonic;
|
||||
b->h->dts_offset = 0;
|
||||
}
|
||||
avail = SPA_MIN (avail, destsize / state->frame_size);
|
||||
}
|
||||
|
||||
state->sample_count += avail;
|
||||
|
|
@ -439,7 +443,7 @@ spa_alsa_start (SpaALSAState *state)
|
|||
if (spa_alsa_open (state) < 0)
|
||||
return -1;
|
||||
|
||||
if (!state->have_buffers)
|
||||
if (state->n_buffers == 0)
|
||||
return -1;
|
||||
|
||||
CHECK (set_swparams (state), "swparams");
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ typedef struct {
|
|||
struct _SpaALSABuffer {
|
||||
SpaBuffer *outbuf;
|
||||
SpaMetaHeader *h;
|
||||
void *ptr;
|
||||
bool outstanding;
|
||||
SpaALSABuffer *next;
|
||||
};
|
||||
|
|
@ -82,11 +81,11 @@ struct _SpaALSAState {
|
|||
size_t frame_size;
|
||||
|
||||
SpaPortInfo info;
|
||||
SpaAllocParam *params[1];
|
||||
SpaAllocParam *params[2];
|
||||
SpaAllocParamBuffers param_buffers;
|
||||
SpaAllocParamMetaEnable param_meta;
|
||||
SpaPortStatus status;
|
||||
|
||||
bool have_buffers;
|
||||
SpaALSABuffer buffers[MAX_BUFFERS];
|
||||
unsigned int n_buffers;
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ struct _SpaAudioTestSrc {
|
|||
SpaFormatAudio current_format;
|
||||
size_t bpf;
|
||||
|
||||
bool have_buffers;
|
||||
ATSBuffer buffers[MAX_BUFFERS];
|
||||
unsigned int n_buffers;
|
||||
|
||||
|
|
@ -356,7 +355,7 @@ spa_audiotestsrc_node_send_command (SpaNode *node,
|
|||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
if (!this->have_buffers)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
if (this->started)
|
||||
|
|
@ -380,7 +379,7 @@ spa_audiotestsrc_node_send_command (SpaNode *node,
|
|||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
if (!this->have_buffers)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
if (!this->started)
|
||||
|
|
@ -528,10 +527,9 @@ spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
|
|||
static SpaResult
|
||||
clear_buffers (SpaAudioTestSrc *this)
|
||||
{
|
||||
if (this->have_buffers) {
|
||||
if (this->n_buffers > 0) {
|
||||
fprintf (stderr, "audiotestsrc %p: clear buffers\n", this);
|
||||
this->n_buffers = 0;
|
||||
this->have_buffers = false;
|
||||
SPA_QUEUE_INIT (&this->empty);
|
||||
SPA_QUEUE_INIT (&this->ready);
|
||||
}
|
||||
|
|
@ -665,6 +663,7 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
|
|||
uint32_t n_buffers)
|
||||
{
|
||||
SpaAudioTestSrc *this;
|
||||
unsigned int i;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -679,44 +678,35 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
|
|||
|
||||
clear_buffers (this);
|
||||
|
||||
if (buffers != NULL && n_buffers != 0) {
|
||||
unsigned int i, j;
|
||||
for (i = 0; i < n_buffers; i++) {
|
||||
ATSBuffer *b;
|
||||
SpaData *d = buffers[i]->datas;
|
||||
|
||||
for (i = 0; i < n_buffers; i++) {
|
||||
ATSBuffer *b;
|
||||
SpaData *d = buffers[i]->datas;
|
||||
SpaMeta *m = buffers[i]->metas;
|
||||
b = &this->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->outstanding = true;
|
||||
b->h = spa_buffer_find_meta (buffers[i], SPA_META_TYPE_HEADER);
|
||||
|
||||
b = &this->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->outstanding = true;
|
||||
b->h = NULL;
|
||||
|
||||
for (j = 0; j < buffers[i]->n_metas; j++) {
|
||||
switch (m[j].type) {
|
||||
case SPA_META_TYPE_HEADER:
|
||||
b->h = m[j].data;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (d[0].type) {
|
||||
case SPA_DATA_TYPE_MEMPTR:
|
||||
case SPA_DATA_TYPE_MEMFD:
|
||||
case SPA_DATA_TYPE_DMABUF:
|
||||
if (d[0].data == NULL) {
|
||||
fprintf (stderr, "audiotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffers[i]->n_datas < 1 || d[0].type != SPA_DATA_TYPE_MEMPTR) {
|
||||
fprintf (stderr, "audiotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);
|
||||
b->size = d[0].size;
|
||||
b->next = NULL;
|
||||
SPA_QUEUE_PUSH_TAIL (&this->empty, ATSBuffer, next, b);
|
||||
b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);
|
||||
b->size = d[0].size;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this->n_buffers = n_buffers;
|
||||
this->have_buffers = true;
|
||||
b->next = NULL;
|
||||
SPA_QUEUE_PUSH_TAIL (&this->empty, ATSBuffer, next, b);
|
||||
}
|
||||
this->n_buffers = n_buffers;
|
||||
|
||||
if (this->have_buffers) {
|
||||
if (this->n_buffers > 0) {
|
||||
update_state (this, SPA_NODE_STATE_PAUSED);
|
||||
} else {
|
||||
update_state (this, SPA_NODE_STATE_READY);
|
||||
|
|
@ -747,7 +737,7 @@ spa_audiotestsrc_node_port_alloc_buffers (SpaNode *node,
|
|||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
if (!this->have_buffers)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
|
|
@ -848,7 +838,7 @@ spa_audiotestsrc_node_port_reuse_buffer (SpaNode *node,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (!this->have_buffers)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
if (buffer_id >= this->n_buffers)
|
||||
|
|
|
|||
|
|
@ -753,8 +753,8 @@ spa_proxy_node_port_use_buffers (SpaNode *node,
|
|||
am.port_id = port_id;
|
||||
am.mem_id = n_mem;
|
||||
am.type = d->type;
|
||||
am.fd_index = spa_control_builder_add_fd (&builder, SPA_PTR_TO_INT (d->data), false);
|
||||
am.flags = 0;
|
||||
am.fd_index = spa_control_builder_add_fd (&builder, d->fd, false);
|
||||
am.flags = d->flags;
|
||||
am.offset = d->offset;
|
||||
am.size = d->maxsize;
|
||||
spa_control_builder_add_cmd (&builder, SPA_CONTROL_CMD_ADD_MEM, &am);
|
||||
|
|
|
|||
|
|
@ -55,10 +55,9 @@ struct _V4l2Buffer {
|
|||
SpaBuffer *outbuf;
|
||||
SpaMetaHeader *h;
|
||||
bool outstanding;
|
||||
bool allocated;
|
||||
struct v4l2_buffer v4l2_buffer;
|
||||
V4l2Buffer *next;
|
||||
void *ptr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
typedef struct _V4l2Format V4l2Format;
|
||||
|
|
|
|||
|
|
@ -106,12 +106,13 @@ spa_v4l2_clear_buffers (SpaV4l2Source *this)
|
|||
fprintf (stderr, "v4l2: queueing outstanding buffer %p\n", b);
|
||||
spa_v4l2_buffer_recycle (this, i);
|
||||
}
|
||||
if (b->ptr) {
|
||||
munmap (b->ptr, b->size);
|
||||
b->ptr = NULL;
|
||||
if (b->allocated) {
|
||||
if (b->outbuf->datas[0].data)
|
||||
munmap (b->outbuf->datas[0].data, b->outbuf->datas[0].maxsize);
|
||||
if (b->outbuf->datas[0].fd != -1)
|
||||
close (b->outbuf->datas[0].fd);
|
||||
b->outbuf->datas[0].type = SPA_DATA_TYPE_INVALID;
|
||||
}
|
||||
if (b->outbuf->datas[0].type == SPA_DATA_TYPE_DMABUF)
|
||||
close (SPA_PTR_TO_INT (b->outbuf->datas[0].data));
|
||||
}
|
||||
|
||||
CLEAR(reqbuf);
|
||||
|
|
@ -893,18 +894,6 @@ v4l2_on_fd_events (SpaPollNotifyData *data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void *
|
||||
find_meta_data (SpaBuffer *b, SpaMetaType type)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < b->n_metas; i++)
|
||||
if (b->metas[i].type == type)
|
||||
return b->metas[i].data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static SpaResult
|
||||
spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffers)
|
||||
{
|
||||
|
|
@ -949,8 +938,8 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
|
|||
b = &state->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->outstanding = true;
|
||||
b->h = find_meta_data (b->outbuf, SPA_META_TYPE_HEADER);
|
||||
b->ptr = NULL;
|
||||
b->allocated = false;
|
||||
b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER);
|
||||
|
||||
fprintf (stderr, "v4l2: import buffer %p\n", buffers[i]);
|
||||
|
||||
|
|
@ -966,27 +955,16 @@ spa_v4l2_use_buffers (SpaV4l2Source *this, SpaBuffer **buffers, uint32_t n_buffe
|
|||
b->v4l2_buffer.index = i;
|
||||
switch (d[0].type) {
|
||||
case SPA_DATA_TYPE_MEMPTR:
|
||||
case SPA_DATA_TYPE_MEMFD:
|
||||
if (d[0].data == NULL) {
|
||||
fprintf (stderr, "v4l2: need mmaped memory\n");
|
||||
continue;
|
||||
}
|
||||
b->v4l2_buffer.m.userptr = (unsigned long) SPA_MEMBER (d[0].data, d[0].offset, void *);
|
||||
b->v4l2_buffer.length = d[0].size;
|
||||
break;
|
||||
case SPA_DATA_TYPE_MEMFD:
|
||||
b->v4l2_buffer.length = d[0].size;
|
||||
b->ptr = mmap (NULL,
|
||||
d[0].maxsize,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
SPA_PTR_TO_INT (d[0].data),
|
||||
0);
|
||||
if (b->ptr == MAP_FAILED) {
|
||||
perror ("mmap");
|
||||
b->ptr = NULL;
|
||||
continue;
|
||||
}
|
||||
b->size = d[0].maxsize;
|
||||
b->v4l2_buffer.m.userptr = (unsigned long) SPA_MEMBER (b->ptr, d[0].offset, void *);
|
||||
break;
|
||||
case SPA_DATA_TYPE_DMABUF:
|
||||
b->v4l2_buffer.m.fd = SPA_PTR_TO_INT (d[0].data);
|
||||
b->v4l2_buffer.m.fd = d[0].fd;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -1043,8 +1021,8 @@ mmap_init (SpaV4l2Source *this,
|
|||
b = &state->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->outstanding = true;
|
||||
b->h = find_meta_data (b->outbuf, SPA_META_TYPE_HEADER);
|
||||
b->ptr = NULL;
|
||||
b->allocated = true;
|
||||
b->h = spa_buffer_find_meta (b->outbuf, SPA_META_TYPE_HEADER);
|
||||
|
||||
CLEAR (b->v4l2_buffer);
|
||||
b->v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
|
@ -1074,9 +1052,11 @@ mmap_init (SpaV4l2Source *this,
|
|||
continue;
|
||||
}
|
||||
d[0].type = SPA_DATA_TYPE_DMABUF;
|
||||
d[0].data = SPA_INT_TO_PTR (expbuf.fd);
|
||||
d[0].fd = expbuf.fd;
|
||||
d[0].data = NULL;
|
||||
} else {
|
||||
d[0].type = SPA_DATA_TYPE_MEMPTR;
|
||||
d[0].fd = -1;
|
||||
d[0].data = mmap (NULL,
|
||||
b->v4l2_buffer.length,
|
||||
PROT_READ,
|
||||
|
|
@ -1087,8 +1067,6 @@ mmap_init (SpaV4l2Source *this,
|
|||
perror ("mmap");
|
||||
continue;
|
||||
}
|
||||
b->ptr = d[0].data;
|
||||
b->size = b->v4l2_buffer.length;
|
||||
}
|
||||
spa_v4l2_buffer_recycle (this, i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,6 @@ struct _SpaVideoTestSrc {
|
|||
SpaFormatVideo current_format;
|
||||
size_t bpp;
|
||||
|
||||
bool have_buffers;
|
||||
VTSBuffer buffers[MAX_BUFFERS];
|
||||
unsigned int n_buffers;
|
||||
|
||||
|
|
@ -304,7 +303,7 @@ spa_videotestsrc_node_send_command (SpaNode *node,
|
|||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
if (!this->have_buffers)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
if (this->started)
|
||||
|
|
@ -328,7 +327,7 @@ spa_videotestsrc_node_send_command (SpaNode *node,
|
|||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
if (!this->have_buffers)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
if (!this->started)
|
||||
|
|
@ -476,10 +475,9 @@ spa_videotestsrc_node_port_enum_formats (SpaNode *node,
|
|||
static SpaResult
|
||||
clear_buffers (SpaVideoTestSrc *this)
|
||||
{
|
||||
if (this->have_buffers) {
|
||||
if (this->n_buffers > 0) {
|
||||
fprintf (stderr, "videotestsrc %p: clear buffers\n", this);
|
||||
this->n_buffers = 0;
|
||||
this->have_buffers = false;
|
||||
SPA_QUEUE_INIT (&this->empty);
|
||||
SPA_QUEUE_INIT (&this->ready);
|
||||
}
|
||||
|
|
@ -614,6 +612,7 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node,
|
|||
uint32_t n_buffers)
|
||||
{
|
||||
SpaVideoTestSrc *this;
|
||||
unsigned int i;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -627,47 +626,36 @@ spa_videotestsrc_node_port_use_buffers (SpaNode *node,
|
|||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
clear_buffers (this);
|
||||
if (buffers != NULL && n_buffers != 0) {
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0; i < n_buffers; i++) {
|
||||
VTSBuffer *b = &this->buffers[i];
|
||||
SpaData *d = buffers[i]->datas;
|
||||
SpaMeta *m = buffers[i]->metas;
|
||||
for (i = 0; i < n_buffers; i++) {
|
||||
VTSBuffer *b = &this->buffers[i];
|
||||
SpaData *d = buffers[i]->datas;
|
||||
|
||||
b = &this->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->outstanding = true;
|
||||
b->h = NULL;
|
||||
b = &this->buffers[i];
|
||||
b->outbuf = buffers[i];
|
||||
b->outstanding = true;
|
||||
b->h = spa_buffer_find_meta (buffers[i], SPA_META_TYPE_HEADER);
|
||||
|
||||
for (j = 0; j < buffers[i]->n_metas; j++) {
|
||||
switch (m[j].type) {
|
||||
case SPA_META_TYPE_HEADER:
|
||||
b->h = m[j].data;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (d[0].type) {
|
||||
case SPA_DATA_TYPE_MEMPTR:
|
||||
case SPA_DATA_TYPE_MEMFD:
|
||||
case SPA_DATA_TYPE_DMABUF:
|
||||
if (d[0].data == NULL) {
|
||||
fprintf (stderr, "videotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (d[0].type != SPA_DATA_TYPE_MEMPTR) {
|
||||
fprintf (stderr, "videotestsrc %p: invalid memory on buffer %p\n", this, buffers[i]);
|
||||
continue;
|
||||
}
|
||||
b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);
|
||||
b->stride = d[0].stride;
|
||||
|
||||
b->next = NULL;
|
||||
SPA_QUEUE_PUSH_TAIL (&this->empty, VTSBuffer, next, b);
|
||||
b->ptr = SPA_MEMBER (d[0].data, d[0].offset, void);
|
||||
b->stride = d[0].stride;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this->n_buffers = n_buffers;
|
||||
this->have_buffers = true;
|
||||
this->info.flags |= SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
} else {
|
||||
this->info.flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
b->next = NULL;
|
||||
SPA_QUEUE_PUSH_TAIL (&this->empty, VTSBuffer, next, b);
|
||||
}
|
||||
this->n_buffers = n_buffers;
|
||||
|
||||
if (this->have_buffers) {
|
||||
if (this->n_buffers > 0) {
|
||||
update_state (this, SPA_NODE_STATE_PAUSED);
|
||||
} else {
|
||||
update_state (this, SPA_NODE_STATE_READY);
|
||||
|
|
@ -686,7 +674,6 @@ spa_videotestsrc_node_port_alloc_buffers (SpaNode *node,
|
|||
uint32_t *n_buffers)
|
||||
{
|
||||
SpaVideoTestSrc *this;
|
||||
unsigned int i;
|
||||
|
||||
if (node == NULL || node->handle == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -699,15 +686,10 @@ spa_videotestsrc_node_port_alloc_buffers (SpaNode *node,
|
|||
if (!this->have_format)
|
||||
return SPA_RESULT_NO_FORMAT;
|
||||
|
||||
if (!this->have_buffers)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
*n_buffers = SPA_MIN (*n_buffers, this->n_buffers);
|
||||
|
||||
for (i = 0; i < *n_buffers; i++)
|
||||
buffers[i] = this->buffers[i].outbuf;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -804,7 +786,7 @@ spa_videotestsrc_node_port_reuse_buffer (SpaNode *node,
|
|||
if (port_id != 0)
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
if (!this->have_buffers)
|
||||
if (this->n_buffers == 0)
|
||||
return SPA_RESULT_NO_BUFFERS;
|
||||
|
||||
if (buffer_id >= this->n_buffers)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue