Meta: rework ringbuffer meta

ringbuffer: remove size and mask from the ringbuffer, we have that
elsewhere in the user of the ringbuffer.
Remove the buffer data offset and size fields and replace with a
ringbuffer. We then have a ringbuffer in all buffer data, which
simplifies things.
We can now remove the ringbuffer metadata.
This commit is contained in:
Wim Taymans 2017-11-15 17:25:36 +01:00
parent 49d8f6792e
commit 2923b623b3
27 changed files with 199 additions and 374 deletions

View file

@ -10,6 +10,7 @@
#define MAX_VALUE 0x10000
struct spa_ringbuffer rb;
uint32_t size;
uint8_t *data;
static int fill_int_array(int *array, int start, int count)
@ -47,7 +48,7 @@ static void *reader_start(void *arg)
uint32_t index;
if (spa_ringbuffer_get_read_index(&rb, &index) >= ARRAY_SIZE * sizeof(int)) {
spa_ringbuffer_read_data(&rb, data, index & rb.mask, b,
spa_ringbuffer_read_data(&rb, data, size, index & (size - 1), b,
ARRAY_SIZE * sizeof(int));
if (!cmp_array(a, b, ARRAY_SIZE)) {
@ -78,7 +79,7 @@ static void *writer_start(void *arg)
uint32_t index;
if (spa_ringbuffer_get_write_index(&rb, &index) >= ARRAY_SIZE * sizeof(int)) {
spa_ringbuffer_write_data(&rb, data, index & rb.mask, a,
spa_ringbuffer_write_data(&rb, data, size, index & (size - 1), a,
ARRAY_SIZE * sizeof(int));
spa_ringbuffer_write_update(&rb, index + ARRAY_SIZE * sizeof(int));
@ -91,8 +92,6 @@ static void *writer_start(void *arg)
int main(int argc, char *argv[])
{
int size;
printf("starting ringbuffer stress test\n");
sscanf(argv[1], "%d", &size);
@ -100,7 +99,7 @@ int main(int argc, char *argv[])
printf("buffer size (bytes): %d\n", size);
printf("array size (bytes): %ld\n", sizeof(int) * ARRAY_SIZE);
spa_ringbuffer_init(&rb, size);
spa_ringbuffer_init(&rb);
data = malloc(size);
pthread_t reader_thread, writer_thread;

View file

@ -171,8 +171,7 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int
b->datas[0].maxsize = size;
b->datas[0].data = malloc(size);
b->datas[0].chunk = &b->chunks[0];
b->datas[0].chunk->offset = 0;
b->datas[0].chunk->size = size;
spa_ringbuffer_set_avail(&b->datas[0].chunk->area, size);
b->datas[0].chunk->stride = 0;
}
}

View file

@ -182,8 +182,7 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int
b->datas[0].maxsize = size;
b->datas[0].data = malloc(size);
b->datas[0].chunk = &b->chunks[0];
b->datas[0].chunk->offset = 0;
b->datas[0].chunk->size = size;
spa_ringbuffer_init(&b->datas[0].chunk->area);
b->datas[0].chunk->stride = 0;
}
}

View file

@ -167,8 +167,7 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int
b->datas[0].maxsize = size;
b->datas[0].data = malloc(size);
b->datas[0].chunk = &b->chunks[0];
b->datas[0].chunk->offset = 0;
b->datas[0].chunk->size = size;
spa_ringbuffer_set_avail(&b->datas[0].chunk->area, size);
b->datas[0].chunk->stride = 0;
}
}

View file

@ -85,7 +85,6 @@ struct buffer {
struct spa_buffer buffer;
struct spa_meta metas[2];
struct spa_meta_header header;
struct spa_meta_ringbuffer rb;
struct spa_data datas[1];
struct spa_chunk chunks[1];
};
@ -143,11 +142,6 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int
b->metas[0].data = &b->header;
b->metas[0].size = sizeof(b->header);
spa_ringbuffer_init(&b->rb.ringbuffer, size);
b->metas[1].type = data->type.meta.Ringbuffer;
b->metas[1].data = &b->rb;
b->metas[1].size = sizeof(b->rb);
b->datas[0].type = data->type.data.MemPtr;
b->datas[0].flags = 0;
b->datas[0].fd = -1;
@ -155,8 +149,7 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int
b->datas[0].maxsize = size;
b->datas[0].data = malloc(size);
b->datas[0].chunk = &b->chunks[0];
b->datas[0].chunk->offset = 0;
b->datas[0].chunk->size = size;
spa_ringbuffer_set_avail(&b->datas[0].chunk->area, 0);
b->datas[0].chunk->stride = 0;
}
}

View file

@ -235,8 +235,7 @@ static void on_source_have_output(void *_data)
datas[0].mapoffset = 0;
datas[0].maxsize = sstride * 240;
datas[0].data = sdata;
datas[0].chunk->offset = 0;
datas[0].chunk->size = sstride * 240;
spa_ringbuffer_set_avail(&datas[0].chunk->area, sstride * 240);
datas[0].chunk->stride = sstride;
} else {
if (SDL_LockTexture(data->texture, NULL, &ddata, &dstride) < 0) {
@ -376,8 +375,7 @@ static int alloc_buffers(struct data *data)
b->datas[0].maxsize = stride * 240;
b->datas[0].data = ptr;
b->datas[0].chunk = &b->chunks[0];
b->datas[0].chunk->offset = 0;
b->datas[0].chunk->size = stride * 240;
spa_ringbuffer_set_avail(&b->datas[0].chunk->area, stride * 240);
b->datas[0].chunk->stride = stride;
}
data->n_buffers = MAX_BUFFERS;