summaryrefslogtreecommitdiffstats
path: root/src/bufferq.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bufferq.c')
-rw-r--r--src/bufferq.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/bufferq.c b/src/bufferq.c
index 1965dda..bafcaa1 100644
--- a/src/bufferq.c
+++ b/src/bufferq.c
@@ -1,10 +1,14 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <string.h>
#include "malloc.h"
#include "macro.h"
#include "bufferq.h"
-#define SA_BUFFERQ_ITEM_CONCAT_DATA(x) ((void*) (uint8_t*) (x) + SA_ALIGN(sizeof(sa_bufferq_item_t)))
+#define SA_BUFFERQ_ITEM_CONCAT_DATA(x) ((void*) ((uint8_t*) (x) + SA_ALIGN(sizeof(sa_bufferq_item_t))))
int sa_bufferq_init(sa_bufferq_t *q, unsigned nchannels, size_t sample_size) {
sa_assert(q);
@@ -23,7 +27,7 @@ int sa_bufferq_init(sa_bufferq_t *q, unsigned nchannels, size_t sample_size) {
q->items = NULL;
return SA_ERROR_OOM;
}
-
+
return SA_SUCCESS;
}
@@ -33,7 +37,7 @@ void sa_bufferq_done(sa_bufferq_t *q) {
for (u = 0; u < q->nchannels; u++) {
sa_bufferq_item_t *i;
-
+
while ((i = q->items[u])) {
SA_LLIST_REMOVE(sa_bufferq_item_t, bufferq, q->items[u], i);
sa_free(i);
@@ -62,7 +66,7 @@ static sa_bufferq_item_t* bufferq_item_new(const void *d, int64_t idx, size_t si
if (!(i = sa_new(sa_bufferq_item_t, 1)))
return NULL;
-
+
i->data = (void*) d;
}
@@ -77,7 +81,7 @@ static sa_bufferq_item_t* bufferq_item_new(const void *d, int64_t idx, size_t si
static sa_bufferq_item_t* bufferq_item_make_writable(sa_bufferq_item_t *i) {
void *d;
sa_assert(i);
-
+
if (i->type == SA_BUFFERQ_ITEM_CONCATENATED || i->type == SA_BUFFERQ_ITEM_DYNAMIC)
return i;
@@ -91,7 +95,7 @@ static sa_bufferq_item_t* bufferq_item_make_writable(sa_bufferq_item_t *i) {
static void bufferq_item_free(sa_bufferq_item_t *i) {
sa_assert(i);
-
+
if (i->type == SA_BUFFERQ_ITEM_DYNAMIC)
sa_free(i->data);
sa_free(i);
@@ -100,7 +104,7 @@ static void bufferq_item_free(sa_bufferq_item_t *i) {
int sa_bufferq_push(sa_bufferq_t *q, unsigned channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence, sa_bufferq_item_type_t type) {
int64_t idx;
sa_bufferq_item_t *i, *j, *n;
-
+
sa_assert(q);
switch (whence) {
@@ -122,11 +126,11 @@ int sa_bufferq_push(sa_bufferq_t *q, unsigned channel, const void *data, size_t
if (l > nbytes)
l = nbytes;
-
+
idx += l;
- data += l;
+ data = (const uint8_t*) data + l;
nbytes -= l;
-
+
}
/* Allocate the new entry */
@@ -142,7 +146,7 @@ int sa_bufferq_push(sa_bufferq_t *q, unsigned channel, const void *data, size_t
i->size = idx - i->idx;
i = i->bufferq_next;
}
-
+
/* Insert the entry */
if (i)
SA_LLIST_INSERT_BEFORE(sa_bufferq_item_t, bufferq, q->items[channel], i, j);
@@ -154,14 +158,14 @@ int sa_bufferq_push(sa_bufferq_t *q, unsigned channel, const void *data, size_t
q->last[channel] = j;
}
-
+
/* Now kick all the entries that overlap entirely with our new entry */
for (i = j->bufferq_next; i && i->idx + i->size < j->idx + j->size ; i = n) {
n = i->bufferq_next;
SA_LLIST_REMOVE(sa_bufferq_item_t, bufferq, q->items[channel], i);
bufferq_item_free(i);
}
-
+
q->write_index = idx + nbytes;
if (q->write_index > q->end_index)
@@ -176,7 +180,7 @@ void sa_bufferq_get(sa_bufferq_t *q, void *i[], size_t *bytes) {
sa_assert(q);
*bytes = 0;
-
+
for (u = 0; u < q->nchannels; u++) {
if (q->items[u]) {
@@ -198,14 +202,14 @@ void sa_bufferq_get(sa_bufferq_t *q, void *i[], size_t *bytes) {
i[u] = (uint8_t*) q->items[u]->data + q->read_index - q->items[u]->idx;
l = q->items[u]->size - (q->read_index - q->items[u]->idx);
-
+
if (first) {
*bytes = l;
first = 0;
} else
*bytes = l < *bytes ? l : *bytes;
}
-
+
} else
i[u] = NULL;
}
@@ -214,16 +218,16 @@ void sa_bufferq_get(sa_bufferq_t *q, void *i[], size_t *bytes) {
void sa_bufferq_drop(sa_bufferq_t *q, int64_t bytes) {
unsigned u;
-
+
sa_assert(q);
q->read_index += bytes;
for (u = 0; u < q->nchannels; u++) {
sa_bufferq_item_t *i;
-
+
i = q->items[u];
-
+
while (i && q->read_index >= i->idx + i->size) {
sa_bufferq_item_t *n = i->bufferq_next;
@@ -258,7 +262,7 @@ int sa_bufferq_realloc(sa_bufferq_t *q) {
* return without doing anything, hence let's at least
* drop the reference to the statically allocated
* data */
-
+
i->size = 0;
i->data = SA_BUFFERQ_ITEM_CONCAT_DATA(i);
i->type = SA_BUFFERQ_ITEM_CONCATENATED;