stream: improve stream API

Simplify the stream API. make just 2 methods to queue and dequeue
buffers. Make just one callback when new buffers can be dequeued.
Add support for driver nodes such as the video-src.
Pass a pw_buffer structure to add/remove_buffer and make it possible
to attach metadata to it. This makes it a lot easier to implement
the gstreamer pipewire pool.
Call the stream process function from the main loop and use a lockfree
ringbuffer to pass buffers between the threads. Make it possible to
also call process from the RT thread.
unmap the buffer data when needed.
This commit is contained in:
Wim Taymans 2018-03-22 16:40:27 +01:00
parent 97547d726f
commit f9ceedb714
11 changed files with 451 additions and 508 deletions

View file

@ -71,7 +71,7 @@ struct data {
static void on_timeout(void *userdata, uint64_t expirations)
{
struct data *data = userdata;
uint32_t id;
struct pw_buffer *b;
struct spa_buffer *buf;
int i, j;
uint8_t *p, *map;
@ -79,13 +79,12 @@ static void on_timeout(void *userdata, uint64_t expirations)
pw_log_trace("timeout");
id = pw_stream_get_empty_buffer(data->stream);
if (id == SPA_ID_INVALID) {
b = pw_stream_dequeue_buffer(data->stream);
if (b == NULL) {
pw_log_warn("out of buffers");
return;
}
buf = pw_stream_peek_buffer(data->stream, id);
buf = b->buffer;
if (buf->datas[0].type == data->t->data.MemFd ||
buf->datas[0].type == data->t->data.DmaBuf) {
@ -129,7 +128,7 @@ static void on_timeout(void *userdata, uint64_t expirations)
buf->datas[0].chunk->size = buf->datas[0].maxsize;
pw_stream_send_buffer(data->stream, id);
pw_stream_queue_buffer(data->stream, b);
}
static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum pw_stream_state state,
@ -240,7 +239,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remo
pw_stream_connect(data->stream,
PW_DIRECTION_OUTPUT,
NULL, PW_STREAM_FLAG_NONE,
NULL, PW_STREAM_FLAG_DRIVER,
params, 1);
break;
}